mirror of
https://github.com/glest/glest-source.git
synced 2025-08-21 15:41:24 +02:00
- bugfixes for G3D viewer (but applies to general texture loading in game also) we now handle better scenarios where binary or model are in different working directories
This commit is contained in:
@@ -310,7 +310,7 @@ void MainWindow::OnChangeColor(wxCommandEvent &event) {
|
|||||||
void MainWindow::onMenuFileLoad(wxCommandEvent &event){
|
void MainWindow::onMenuFileLoad(wxCommandEvent &event){
|
||||||
try {
|
try {
|
||||||
string fileName;
|
string fileName;
|
||||||
fileDialog->SetWildcard(wxT("G3D files (*.g3d)|*.g3d"));
|
fileDialog->SetWildcard(wxT("G3D files (*.g3d)|*.g3d;*.G3D"));
|
||||||
fileDialog->SetMessage(wxT("Selecting Glest Model for current view."));
|
fileDialog->SetMessage(wxT("Selecting Glest Model for current view."));
|
||||||
|
|
||||||
if(fileDialog->ShowModal()==wxID_OK){
|
if(fileDialog->ShowModal()==wxID_OK){
|
||||||
@@ -467,6 +467,7 @@ void MainWindow::onMenuFileExit(wxCommandEvent &event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadModel(string path) {
|
void MainWindow::loadModel(string path) {
|
||||||
|
try {
|
||||||
if(path != "" && fileExists(path) == true) {
|
if(path != "" && fileExists(path) == true) {
|
||||||
this->modelPathList.push_back(path);
|
this->modelPathList.push_back(path);
|
||||||
}
|
}
|
||||||
@@ -489,6 +490,11 @@ void MainWindow::loadModel(string path) {
|
|||||||
}
|
}
|
||||||
SetTitle(ToUnicode(titlestring));
|
SetTitle(ToUnicode(titlestring));
|
||||||
}
|
}
|
||||||
|
catch(std::runtime_error e) {
|
||||||
|
std::cout << e.what() << std::endl;
|
||||||
|
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::loadParticle(string path) {
|
void MainWindow::loadParticle(string path) {
|
||||||
timer->Stop();
|
timer->Stop();
|
||||||
|
@@ -169,7 +169,7 @@ static inline T* readFromFileReaders(vector<FileReader<T> const *>* readers, con
|
|||||||
//try to assign file
|
//try to assign file
|
||||||
ifstream file(filepath.c_str(), ios::in | ios::binary);
|
ifstream file(filepath.c_str(), ios::in | ios::binary);
|
||||||
if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message?
|
if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message?
|
||||||
throw runtime_error("Could not open file " + filepath);
|
throw runtime_error("Could not open file [" + filepath + "]");
|
||||||
}
|
}
|
||||||
for (typename vector<FileReader<T> const *>::const_iterator i = readers->begin(); i != readers->end(); ++i) {
|
for (typename vector<FileReader<T> const *>::const_iterator i = readers->begin(); i != readers->end(); ++i) {
|
||||||
T* ret = NULL;
|
T* ret = NULL;
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
#include "interpolation.h"
|
#include "interpolation.h"
|
||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "platform_common.h"
|
||||||
|
|
||||||
#if defined(ENABLE_VBO_CODE)
|
#if defined(ENABLE_VBO_CODE)
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Platform;
|
using namespace Shared::Platform;
|
||||||
|
using namespace Shared::PlatformCommon;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -212,7 +214,11 @@ void Mesh::loadV2(const string &dir, FILE *f, TextureManager *textureManager,boo
|
|||||||
//texture
|
//texture
|
||||||
if(meshHeader.hasTexture && textureManager!=NULL){
|
if(meshHeader.hasTexture && textureManager!=NULL){
|
||||||
texturePaths[mtDiffuse]= toLower(reinterpret_cast<char*>(meshHeader.texName));
|
texturePaths[mtDiffuse]= toLower(reinterpret_cast<char*>(meshHeader.texName));
|
||||||
string texPath= dir+"/"+texturePaths[mtDiffuse];
|
string texPath= dir;
|
||||||
|
if(texPath != "") {
|
||||||
|
texPath += "/";
|
||||||
|
}
|
||||||
|
texPath += texturePaths[mtDiffuse];
|
||||||
|
|
||||||
textures[mtDiffuse]= static_cast<Texture2D*>(textureManager->getTexture(texPath));
|
textures[mtDiffuse]= static_cast<Texture2D*>(textureManager->getTexture(texPath));
|
||||||
if(textures[mtDiffuse]==NULL){
|
if(textures[mtDiffuse]==NULL){
|
||||||
@@ -266,7 +272,12 @@ void Mesh::loadV3(const string &dir, FILE *f, TextureManager *textureManager,boo
|
|||||||
//texture
|
//texture
|
||||||
if(!(meshHeader.properties & mp3NoTexture) && textureManager!=NULL){
|
if(!(meshHeader.properties & mp3NoTexture) && textureManager!=NULL){
|
||||||
texturePaths[mtDiffuse]= toLower(reinterpret_cast<char*>(meshHeader.texName));
|
texturePaths[mtDiffuse]= toLower(reinterpret_cast<char*>(meshHeader.texName));
|
||||||
string texPath= dir+"/"+texturePaths[mtDiffuse];
|
|
||||||
|
string texPath= dir;
|
||||||
|
if(texPath != "") {
|
||||||
|
texPath += "/";
|
||||||
|
}
|
||||||
|
texPath += texturePaths[mtDiffuse];
|
||||||
|
|
||||||
textures[mtDiffuse]= static_cast<Texture2D*>(textureManager->getTexture(texPath));
|
textures[mtDiffuse]= static_cast<Texture2D*>(textureManager->getTexture(texPath));
|
||||||
if(textures[mtDiffuse]==NULL){
|
if(textures[mtDiffuse]==NULL){
|
||||||
@@ -327,7 +338,11 @@ void Mesh::load(const string &dir, FILE *f, TextureManager *textureManager,bool
|
|||||||
readBytes = fread(cMapPath, mapPathSize, 1, f);
|
readBytes = fread(cMapPath, mapPathSize, 1, f);
|
||||||
string mapPath= toLower(reinterpret_cast<char*>(cMapPath));
|
string mapPath= toLower(reinterpret_cast<char*>(cMapPath));
|
||||||
|
|
||||||
string mapFullPath= dir + "/" + mapPath;
|
string mapFullPath= dir;
|
||||||
|
if(mapFullPath != "") {
|
||||||
|
mapFullPath += "/";
|
||||||
|
}
|
||||||
|
mapFullPath += mapPath;
|
||||||
|
|
||||||
textures[i]= static_cast<Texture2D*>(textureManager->getTexture(mapFullPath));
|
textures[i]= static_cast<Texture2D*>(textureManager->getTexture(mapFullPath));
|
||||||
if(textures[i]==NULL){
|
if(textures[i]==NULL){
|
||||||
@@ -574,18 +589,18 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
|
|||||||
try{
|
try{
|
||||||
FILE *f=fopen(path.c_str(),"rb");
|
FILE *f=fopen(path.c_str(),"rb");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
throw runtime_error("Error opening 3d model file");
|
printf("In [%s::%s] cannot load file = [%s]\n",__FILE__,__FUNCTION__,path.c_str());
|
||||||
|
throw runtime_error("Error opening g3d model file [" + path + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
string dir= cutLastFile(path);
|
string dir= extractDirectoryPathFromFile(path);
|
||||||
|
|
||||||
//file header
|
//file header
|
||||||
FileHeader fileHeader;
|
FileHeader fileHeader;
|
||||||
size_t readBytes = fread(&fileHeader, sizeof(FileHeader), 1, f);
|
size_t readBytes = fread(&fileHeader, sizeof(FileHeader), 1, f);
|
||||||
if(strncmp(reinterpret_cast<char*>(fileHeader.id), "G3D", 3) != 0) {
|
if(strncmp(reinterpret_cast<char*>(fileHeader.id), "G3D", 3) != 0) {
|
||||||
|
|
||||||
printf("In [%s::%s] file = [%s] fileheader.id = [%s][%c]\n",__FILE__,__FUNCTION__,path.c_str(),reinterpret_cast<char*>(fileHeader.id),fileHeader.id[0]);
|
printf("In [%s::%s] file = [%s] fileheader.id = [%s][%c]\n",__FILE__,__FUNCTION__,path.c_str(),reinterpret_cast<char*>(fileHeader.id),fileHeader.id[0]);
|
||||||
throw runtime_error("Not a valid S3D model");
|
throw runtime_error("Not a valid G3D model");
|
||||||
}
|
}
|
||||||
fileVersion= fileHeader.version;
|
fileVersion= fileHeader.version;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user