assimp / assimp

The official Open-Asset-Importer-Library Repository. Loads 40+ 3D-file-formats into one unified and clean data structure.
https://www.assimp.org
Other
10.33k stars 2.82k forks source link

Bug: OBJ - load material throw exception when material has user-defined description #5554

Closed plainliu closed 1 week ago

plainliu commented 3 weeks ago

Describe the bug ReadFile() throw exption and return nullptr when load obj.

To Reproduce There are lines in .mtl like:

Pccns 1-1
Prfl 0
...

when ObjFileMtlImporter::load() parse Pccns 1-1, first match char 'P', then match char 'c', then get next word "cns" in getFloatValue to parse

deadly error

Cannot parse string "cns" as a real number: does not start with digit or decimal point followed by digit.
Cannot parse string "fl" as a real number: does not start with digit or decimal point followed by digit.

Expected behavior The mtl file is created by a modified js OBJExporter, skip the line when parse failed

GitHubDragonFly commented 2 weeks ago

@plainliu those MTL lines almost look like coming from the custom OBJ Exporter that I have in my repository.

This document shows what I actually use for custom MTL entries.

If you are interested then take a look at customized Assimp I have made in my updates branch, especially the ObjFileMtlImporter.cpp file but don't limit your research to that file only.

My ASSIMP Viewer should be able to load your MTL + OBJ + Textures files. I think that my OBJ Viewer should be able to load those files as well.

kimkulling commented 1 week ago

Ah, these are special extensions for physical based realtime rendering.

plainliu commented 1 week ago

@GitHubDragonFly I tried to import my obj use updates branch, it still load failed. the branch parsed P-c-c not only P-c, so "cns" error become "ns" error. OBJ Viewer can load my obj, I dont know why.

and I have some other questions

plainliu commented 1 week ago

@kimkulling where can I get those special extensions? if not use them, importer return nullptr still is a question, I have fixed it on my local repo but not perfect way, and report the question here expecting fix it in this repo~~

GitHubDragonFly commented 1 week ago

@plainliu my OBJ Viewer is only looking for known entries and is ignoring the rest - that is probably why you can load your OBJ model.

I am not really keeping the updates branch up-to-date but have just updated it now to include a check for space in the MTL file, which might make it work with your model. This assimp fork on my end is archived for historical purposes and if anyone can find anything useful in that updates branch.

Maybe try loading your OBJ model again in my ASSIMP Viewer to see if it works now.

If you cannot compile the updates branch then just try updating the file(s) manually.

plainliu commented 1 week ago

@GitHubDragonFly Thanks, changes in function ObjFileMtlImporter::load() is what I what. also need skip \t.

I tried compile updates branch, function getNumComponentsInDataDefinition has errors

GitHubDragonFly commented 1 week ago

@plainliu maybe try compiling again.

I just updated ParsingUtils.h file and, even though it is a mix of old and new code, the updates branch did compile for me by using emscripten and mingw.

Would you also be able to actually test loading your OBJ+MTL+Texture files in my current ASSIMP Viewer just so I know whether it is working properly with your model.

plainliu commented 1 week ago

@GitHubDragonFly The updates branch compile & load my obj successfully now. ASSIMP Viewer loaded successfully too.

GitHubDragonFly commented 1 week ago

@plainliu thank you for testing.

Here is some more info about the updates branch just so you are aware:

Here is another topic in this forum that has some other info.