still trying to fix the problem
This commit is contained in:
@@ -44,58 +44,22 @@ void MainWindow::setupWindow()
|
||||
|
||||
void MainWindow::import(const char * path)
|
||||
{
|
||||
// variables
|
||||
std::vector<Model*>* tmp_models = nullptr;
|
||||
std::vector<TextureData*>* tmp_textures = new std::vector<TextureData*>;
|
||||
std::vector<std::string> tmp_texNames;
|
||||
BoundingBox tmp_bbox;
|
||||
|
||||
// model file
|
||||
try
|
||||
{
|
||||
MshFile file(path);
|
||||
|
||||
// Models
|
||||
std::vector<Model*>* tmp_models = file.getModels();
|
||||
|
||||
// Textures
|
||||
std::vector<std::string> tmp_texNames = file.getTextureNames();
|
||||
std::vector<QImage*>* tmp_textures = new std::vector<QImage*>;
|
||||
|
||||
std::string tmp_path = path;
|
||||
|
||||
while (tmp_path.back() != '/' && tmp_path.back() != '\\')
|
||||
tmp_path.pop_back();
|
||||
|
||||
for (auto& it : tmp_texNames)
|
||||
{
|
||||
QImage* tmp_image = new QImage;
|
||||
|
||||
std::string test = tmp_path + it;
|
||||
QString test2 = "D:\\workspaces\\Visual Studio 2015\\Projects\\OpenGL\\Release\\Msh\\texture32R.tga";
|
||||
|
||||
if (tmp_image->load(test2))
|
||||
tmp_textures->push_back(tmp_image);
|
||||
else
|
||||
{
|
||||
delete tmp_image;
|
||||
tmp_image = new QImage(1, 1, QImage::Format_RGB32);
|
||||
tmp_image->fill(Qt::red);
|
||||
tmp_textures->push_back(tmp_image);
|
||||
}
|
||||
}
|
||||
|
||||
// add a solid default color at the end (maybe there is an invalid index later)
|
||||
QImage* tmp_image = new QImage(1, 1, QImage::Format_RGB16);
|
||||
tmp_image->fill(Qt::red);
|
||||
tmp_textures->push_back(tmp_image);
|
||||
|
||||
tmp_texNames.clear();
|
||||
|
||||
// Bounding Box
|
||||
BoundingBox tmp_bbox = file.getBoundingBox();
|
||||
|
||||
OpenGlViewer* tmp_viewer = dynamic_cast<OpenGlViewer*>(centralWidget());
|
||||
|
||||
tmp_viewer->setData(tmp_models, tmp_textures, tmp_bbox);
|
||||
|
||||
tmp_models = file.getModels();
|
||||
tmp_texNames = file.getTextureNames();
|
||||
tmp_bbox = file.getBoundingBox();
|
||||
}
|
||||
catch (std::invalid_argument e)
|
||||
{
|
||||
//TODO:
|
||||
QMessageBox msg(this);
|
||||
msg.addButton(QMessageBox::Ok);
|
||||
msg.setText(QString::fromStdString(e.what()));
|
||||
@@ -103,7 +67,52 @@ void MainWindow::import(const char * path)
|
||||
msg.setWindowTitle("Open File Error");
|
||||
|
||||
msg.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
// parth to texture
|
||||
std::string tmp_path = path;
|
||||
while (tmp_path.back() != '/' && tmp_path.back() != '\\')
|
||||
tmp_path.pop_back();
|
||||
|
||||
// load all textures
|
||||
for (auto& texIt : tmp_texNames)
|
||||
{
|
||||
TextureData* new_data = new TextureData;
|
||||
try
|
||||
{
|
||||
TextureTGA tmp_texFile(std::string(tmp_path + texIt).c_str());
|
||||
|
||||
new_data->alpha = tmp_texFile.hasAlpha();
|
||||
new_data->width = tmp_texFile.getWidth();
|
||||
new_data->height = tmp_texFile.getHeight();
|
||||
new_data->data = tmp_texFile.getData();
|
||||
}
|
||||
catch (std::invalid_argument e)
|
||||
{
|
||||
new_data->alpha = true;
|
||||
new_data->width = 1;
|
||||
new_data->height = 1;
|
||||
new_data->data = new std::vector<std::uint8_t>({ 0, 0, 255, 255 });
|
||||
}
|
||||
|
||||
tmp_textures->push_back(new_data);
|
||||
}
|
||||
|
||||
// add a solid default color at the end (maybe there is an invalid index later)
|
||||
TextureData* new_data = new TextureData;
|
||||
new_data->alpha = true;
|
||||
new_data->width = 1;
|
||||
new_data->height = 1;
|
||||
new_data->data = new std::vector<std::uint8_t>({ 0, 0, 255, 255 });
|
||||
tmp_textures->push_back(new_data);
|
||||
|
||||
// clean up texture name list
|
||||
tmp_texNames.clear();
|
||||
|
||||
// give the data to the viewer
|
||||
OpenGlViewer* tmp_viewer = dynamic_cast<OpenGlViewer*>(centralWidget());
|
||||
tmp_viewer->setData(tmp_models, tmp_textures, tmp_bbox);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user