mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-13 00:07:24 +00:00
io_3ds loads multiple layers correctly
This commit is contained in:
parent
992a2cfe42
commit
8b3e5a123c
BIN
sample/furniture.3ds
Normal file
BIN
sample/furniture.3ds
Normal file
Binary file not shown.
@ -45,12 +45,12 @@ void IOPlugin::reportWarning(const QString& warningMessage) const
|
||||
}
|
||||
}
|
||||
|
||||
void IOPlugin::wrongOpenFormat(const QString& format)
|
||||
void IOPlugin::wrongOpenFormat(const QString& format) const
|
||||
{
|
||||
throw MLException("Internal error: unknown open format " + format + " to " + pluginName() + " plugin.");
|
||||
}
|
||||
|
||||
void IOPlugin::wrongSaveFormat(const QString& format)
|
||||
void IOPlugin::wrongSaveFormat(const QString& format) const
|
||||
{
|
||||
throw MLException("Internal error: unknown save format " + format + " to " + pluginName() + " plugin.");
|
||||
}
|
||||
|
||||
@ -276,14 +276,14 @@ public:
|
||||
* (initPreOpenParameters, load...) whenever you receive as parameter a
|
||||
* format that is not supported by your plugin
|
||||
*/
|
||||
void wrongOpenFormat(const QString& format);
|
||||
void wrongOpenFormat(const QString& format) const;
|
||||
|
||||
/**
|
||||
* @brief call this function in any of the export functions
|
||||
* (exportMaskCapability, save...) whenever you receive as parameter a
|
||||
* format that is not supported by your plugin
|
||||
*/
|
||||
void wrongSaveFormat(const QString& format);
|
||||
void wrongSaveFormat(const QString& format) const;
|
||||
|
||||
/**
|
||||
* @brief The warningMessageString is invoked by the framework after the
|
||||
|
||||
@ -2410,6 +2410,7 @@ bool MainWindow::importMesh(QString fileName)
|
||||
return false;
|
||||
}
|
||||
|
||||
pCurrentIOPlugin->setLog(&meshDoc()->Log);
|
||||
RichParameterList prePar;
|
||||
pCurrentIOPlugin->initPreOpenParameter(extension,prePar);
|
||||
if(!prePar.isEmpty())
|
||||
|
||||
@ -75,28 +75,75 @@ void ExtraMeshIOPlugin::exportMaskCapability(const QString &format, int &capabil
|
||||
return;
|
||||
}
|
||||
|
||||
void ExtraMeshIOPlugin::initPreOpenParameter(
|
||||
unsigned int ExtraMeshIOPlugin::numberMeshesContainedInFile(
|
||||
const QString& format,
|
||||
RichParameterList& parameters)
|
||||
const QString& fileName) const
|
||||
{
|
||||
if (format.toUpper() == tr("3DS")) {
|
||||
parameters.addParam(RichBool(paramNames[SEPARATE_LAYERS], true, "Separate layers", "Import each mesh contained in the file as a separate layer"));
|
||||
Lib3dsFile *file = NULL;
|
||||
file = lib3ds_file_load(fileName.toStdString().c_str());
|
||||
if (!file)
|
||||
throw MLException("Malformed file.");
|
||||
// No nodes? Fabricate nodes to display all the meshes.
|
||||
if( !file->nodes && file->meshes) {
|
||||
Lib3dsMesh *mesh;
|
||||
Lib3dsNode *node;
|
||||
|
||||
for (mesh = file->meshes; mesh != NULL; mesh = mesh->next) {
|
||||
node = lib3ds_node_new_object();
|
||||
strcpy(node->name, mesh->name);
|
||||
node->parent_id = LIB3DS_NO_PARENT;
|
||||
lib3ds_file_insert_node(file, node);
|
||||
}
|
||||
}
|
||||
if( !file->nodes) {
|
||||
lib3ds_file_free(file);
|
||||
throw MLException("Malformed file.");
|
||||
}
|
||||
lib3ds_file_eval(file, 0);
|
||||
unsigned int i = 0;
|
||||
Lib3dsNode *p = file->nodes;
|
||||
while (p) {
|
||||
i++;
|
||||
p = p->next;
|
||||
}
|
||||
log("Expected meshes in file: " + std::to_string(i) );
|
||||
lib3ds_file_free(file);
|
||||
return i;
|
||||
}
|
||||
else {
|
||||
wrongOpenFormat(format);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ExtraMeshIOPlugin::open(
|
||||
const QString& formatName,
|
||||
const QString&,
|
||||
MeshModel&,
|
||||
int&,
|
||||
const RichParameterList&,
|
||||
CallBackPos*)
|
||||
{
|
||||
wrongOpenFormat(formatName);
|
||||
}
|
||||
|
||||
void ExtraMeshIOPlugin::open(
|
||||
const QString &formatName,
|
||||
const QString &fileName,
|
||||
MeshModel &m,
|
||||
int& mask,
|
||||
const RichParameterList& params,
|
||||
const std::list<MeshModel *>& meshList,
|
||||
std::list<int>& maskList,
|
||||
const RichParameterList&,
|
||||
CallBackPos *cb)
|
||||
{
|
||||
// initializing mask
|
||||
mask = 0;
|
||||
maskList.clear();
|
||||
for (unsigned int i = 0; i < meshList.size(); i++)
|
||||
maskList.push_back(0);
|
||||
|
||||
// initializing progress bar status
|
||||
if (cb != NULL) (*cb)(0, "Loading...");
|
||||
if (cb != nullptr)
|
||||
(*cb)(0, "Loading...");
|
||||
|
||||
QString errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: %2";
|
||||
//QString error_2MsgFormat = "Error encountered while loading file:\n\"%1\"\n\n File with more than a mesh.\n Load only the first!";
|
||||
@ -137,22 +184,18 @@ void ExtraMeshIOPlugin::open(
|
||||
|
||||
lib3ds_file_eval(file, 0);
|
||||
|
||||
bool singleLayer = true;
|
||||
if ( file->nodes->next) {
|
||||
singleLayer = params.getBool(paramNames[SEPARATE_LAYERS]);
|
||||
}
|
||||
|
||||
if (!singleLayer)
|
||||
{
|
||||
Lib3dsNode *p;
|
||||
mask = 0;
|
||||
int i=1;
|
||||
for (p=file->nodes; p!=0; p=p->next, ++i)
|
||||
auto iter = meshList.begin();
|
||||
auto miter = maskList.begin();
|
||||
for (p=file->nodes; p!=nullptr; p=p->next, ++iter, ++miter)
|
||||
{
|
||||
bool normalsUpdated = false;
|
||||
|
||||
MeshModel &mm = *m.parent->addNewMesh(qUtf8Printable(fileName), QString(p->name), false);
|
||||
if (cb != NULL) (*cb)(i, (QString("Loading Mesh ")+QString(p->name)).toStdString().c_str());
|
||||
MeshModel &mm = *(*iter);
|
||||
mm.setLabel(QString(p->name));
|
||||
if (cb != nullptr)
|
||||
(*cb)(i/meshList.size() * 100, (QString("Loading Mesh ")+QString(p->name)).toStdString().c_str());
|
||||
|
||||
vcg::tri::io::Importer3DS<CMeshO>::LoadMask(file, p, info);
|
||||
mm.Enable(info.mask);
|
||||
@ -166,7 +209,7 @@ void ExtraMeshIOPlugin::open(
|
||||
if(info.mask & vcg::tri::io::Mask::IOM_WEDGNORMAL)
|
||||
normalsUpdated = true;
|
||||
|
||||
mask |= info.mask;
|
||||
(*miter) |= info.mask;
|
||||
|
||||
// verify if texture files are present
|
||||
QString missingTextureFilesMsg = "The following texture files were not found:\n";
|
||||
@ -191,51 +234,6 @@ void ExtraMeshIOPlugin::open(
|
||||
if (!normalsUpdated)
|
||||
vcg::tri::UpdateNormal<CMeshO>::PerVertex(mm.cm); // updates normals
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool normalsUpdated = false;
|
||||
|
||||
vcg::tri::io::Importer3DS<CMeshO>::LoadMask(file, 0, info);
|
||||
m.Enable(info.mask);
|
||||
|
||||
int result = vcg::tri::io::Importer3DS<CMeshO>::Load(m.cm, file, 0, info);
|
||||
if (result != vcg::tri::io::Importer3DS<CMeshO>::E_NOERROR)
|
||||
{
|
||||
lib3ds_file_free(file);
|
||||
throw MLException("3DS Opening Error: " + errorMsgFormat.arg(fileName, vcg::tri::io::Importer3DS<CMeshO>::ErrorMsg(result)));
|
||||
}
|
||||
|
||||
if(info.mask & vcg::tri::io::Mask::IOM_WEDGNORMAL)
|
||||
normalsUpdated = true;
|
||||
|
||||
mask = info.mask;
|
||||
|
||||
|
||||
// verify if texture files are present
|
||||
QString missingTextureFilesMsg = "The following texture files were not found:\n";
|
||||
bool someTextureNotFound = false;
|
||||
for ( unsigned textureIdx = 0; textureIdx < m.cm.textures.size(); ++textureIdx)
|
||||
{
|
||||
FILE* pFile = fopen (m.cm.textures[textureIdx].c_str(), "r");
|
||||
if (pFile == nullptr)
|
||||
{
|
||||
missingTextureFilesMsg.append("\n");
|
||||
missingTextureFilesMsg.append(m.cm.textures[textureIdx].c_str());
|
||||
someTextureNotFound = true;
|
||||
}
|
||||
else {
|
||||
fclose (pFile);
|
||||
}
|
||||
}
|
||||
if (someTextureNotFound){
|
||||
reportWarning("Missing texture files: " + missingTextureFilesMsg);
|
||||
}
|
||||
|
||||
vcg::tri::UpdateBounding<CMeshO>::Box(m.cm); // updates bounding box
|
||||
if (!normalsUpdated)
|
||||
vcg::tri::UpdateNormal<CMeshO>::PerVertex(m.cm); // updates normals
|
||||
}
|
||||
|
||||
if (cb != NULL) (*cb)(99, "Done");
|
||||
|
||||
|
||||
@ -44,17 +44,26 @@ public:
|
||||
|
||||
void exportMaskCapability(const QString& format, int &capability, int &defaultBits) const;
|
||||
|
||||
void initPreOpenParameter(
|
||||
unsigned int numberMeshesContainedInFile(
|
||||
const QString& format,
|
||||
RichParameterList& parameters);
|
||||
const QString& fileName) const;
|
||||
|
||||
void open(const QString &formatName,
|
||||
void open(
|
||||
const QString &formatName,
|
||||
const QString &fileName,
|
||||
MeshModel& m,
|
||||
int& mask,
|
||||
const RichParameterList& params,
|
||||
vcg::CallBackPos *cb=0);
|
||||
|
||||
void open(
|
||||
const QString &formatName,
|
||||
const QString &fileName,
|
||||
const std::list<MeshModel *>& meshList,
|
||||
std::list<int>& maskList,
|
||||
const RichParameterList& params,
|
||||
vcg::CallBackPos *cb=0);
|
||||
|
||||
void save(
|
||||
const QString &formatName,
|
||||
const QString &fileName,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user