Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Examples Viewer Tutorial] Can't find a supported format #375

Closed
alanjfs opened this issue Sep 28, 2019 · 9 comments
Closed

[Examples Viewer Tutorial] Can't find a supported format #375

alanjfs opened this issue Sep 28, 2019 · 9 comments
Assignees
Milestone

Comments

@alanjfs
Copy link
Contributor

alanjfs commented Sep 28, 2019

Hi @mosra,

I'm enjoying learning about Magnum through your very well made example library, however I'm having some issues with the Examples Viewer.

Namely, the files I'm handing it doesn't appear to load.

examples_viewer.exe ship.obj
# Importing mesh 0                                                                                                   
# Trade::ObjImporter::mesh3D(): polygons are not supported                                                           
# Cannot load the mesh, skipping

Fair enough, assuming "polygon" means "quad", converting the model to triangles.

examples_viewer.exe shipTri.obj
# Importing mesh 0                                                                                                   
# Trade::ObjImporter::mesh3D(): unknown keyword                                                                      
# Cannot load the mesh, skipping 

Hm, allright. Maybe ZBrush is doing something different to the format that the ObjImporter doesn't like.

examples_viewer.exe shipMaya.obj
# Importing mesh 0                                                                                                   
# Cannot load the mesh, skipping

Hm, no message about why it didn't load this time. Maybe if I adjust the export settings?

image

examples_viewer.exe shipMayaAfter.obj
# Importing mesh 0                                                                                                   

Success! I made note of the description in the docs about not supporting automatic generation of normals and materials and figured maybe this was it.

This little adventure took me "out of the zone" in experiencing your set of tutorials, I think the tutorial could be improved by providing an example model. (Or if there is one, increase its visibility). You're welcome to have my ship model if you'd like; alternatively I was looking to find the model of Suzanne, like in the screenshot at the beginning of the tutorial. I think that would have been great, and I think it's open source as well?

The one I found (here) was in gltf format, which I thought would have worked, however..

examples_viewer.exe scene.gltf
PluginManager::Manager::load(): plugin GltfImporter is not static and was not found in C:/examples_viewer/build/Debug/magnum-d/importers                                                                   
Trade::AnySceneImporter::openFile(): cannot load GltfImporter plugin

And sure enough, there wasn't a plug-in by that name in there. Despite having gotten Magnum off of vcpkg magnum[*] (see #373) Also unsure which is mispelled, the error message or the documentation, referring to TinyGltfImporter as opposed to GlftImporter.

In any case, hope it helps, and great work!

@mosra
Copy link
Owner

mosra commented Sep 28, 2019

Hi!

uh, sorry about this, it's a common annoyance 😅 Let me explain a bit -- there's a set of builtin plugins inside this repository, which are very rudimentary just for the very basic formats (in particular, TGA and OBJ), deliberately own code with no external dependencies as that makes things simpler for commercial users (no need to deal with 3rd party licenses and stuff). The ObjImporter in particular is quite shitty tho and there are a few stale attempts to fix it (see e.g. #205), however right now it's everything but usable.

For actually usable plugins there's the magnum-plugins repository containing most of importers you'd need. A reasonable default set can be installed via vcpkg install magnum-plugins, glTF importer is there too (TinyGltfImporter), and AssimpImporter can load OBJs, glTF, FBX etc., but import quality for different formats varies wildly.

For TinyGltfImporter vs GltfImporter -- there's usually more than one plugin being able to open a particular format, allowing you to to make a choice (take an implementation that's tiny enough for a small web build, or take an implementation that's the fastest when you need to operate on big data, for example). This is explained in more detail in the plugin loading docs. I'll try to point that out in the viewer example better.

For a model, Blender's Suzanne is available in the examples repo, linking that from the example is a second TODO for me, then :) There's quite a lot of various magnum-* repos (physics integration, Python bindings...), so check the others out as well. (Third TODO for me is making those repos visible more.)

@mosra mosra added this to the 2019.0b milestone Sep 28, 2019
@mosra mosra self-assigned this Sep 28, 2019
@alanjfs
Copy link
Contributor Author

alanjfs commented Sep 29, 2019

Thanks for getting back!

there's a set of builtin plugins inside this repository, which are very rudimentary just for the very basic formats

I think that's perfectly reasonable. Personally, I'm happy to format my data to conform to the limitations of the importer, rather than complicate the importer(s) to handle more data. To benefit from that particular tutorial, I'd imagine the particular format used to import something isn't important; the important bits are getting to grips with the scene graph and plug-in mechanism in general.

With that in mind, perhaps it would suffice with a provided OBJ in text form?

box.obj

image

v -0.500000 -0.500000 0.500000
v 0.500000 -0.500000 0.500000
v -0.500000 0.500000 0.500000
v 0.500000 0.500000 0.500000
v -0.500000 0.500000 -0.500000
v 0.500000 0.500000 -0.500000
v -0.500000 -0.500000 -0.500000
v 0.500000 -0.500000 -0.500000
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.375000 0.250000
vt 0.625000 0.250000
vt 0.375000 0.500000
vt 0.625000 0.500000
vt 0.375000 0.750000
vt 0.625000 0.750000
vt 0.375000 1.000000
vt 0.625000 1.000000
vt 0.875000 0.000000
vt 0.875000 0.250000
vt 0.125000 0.000000
vt 0.125000 0.250000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 -1.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
f 1/1/1 2/2/2 3/3/3
f 3/3/3 2/2/2 4/4/4
f 3/3/5 4/4/6 5/5/7
f 5/5/7 4/4/6 6/6/8
f 5/5/9 6/6/10 7/7/11
f 7/7/11 6/6/10 8/8/12
f 7/7/13 8/8/14 1/9/15
f 1/9/15 8/8/14 2/10/16
f 2/2/17 8/11/18 4/4/19
f 4/4/19 8/11/18 6/12/20
f 7/13/21 1/1/22 5/14/23
f 5/14/23 1/1/22 3/3/24

From there, the reader would know that even if their custom file isn't working, they've at least followed the tutorial correctly. In my case, that took a while to figure out.

@mosra
Copy link
Owner

mosra commented Sep 29, 2019

Good point about providing just a cube so even the "core" ObjImporter works, will do that as well (fourth TODO for me). The best would be to have the builtin ObjImporter updated to not be so shitty (otherwise what would be the point of even having it), but .... too much to do, too little time, so I have to prioritize. Was thinking about providing the full Suzanne instead of just a box, but in a textual form it's over a megabyte, which is a bit excessive :D

I'll ping you back once I have the changes done, in case you'd have further suggestions -- you're providing a very valuable feedback, thank you!

@alanjfs
Copy link
Contributor Author

alanjfs commented Sep 30, 2019

You are most welcome. :) And don't hesitate to ask if you want help with any of your TODO items. I'd be happy to try and take a stab at this if you'd like.

@mosra
Copy link
Owner

mosra commented Oct 15, 2019

So, if you look at latest updates to the tutorials (I already dragged you through the less-shitty Getting Started Guide, thanks for the feedback on that), there's added sections about plugins:

And then, in the Viewer tutorial, it links to a plain OBJ cube and the Suzanne model as well, plus showing what you need to enable / build / install in order to view those: https://doc.magnum.graphics/magnum/examples-viewer.html#examples-viewer-compilation

@mosra
Copy link
Owner

mosra commented Oct 19, 2019

Closing as resolved via mosra/magnum-examples@6e02ad5.

@F1r3Hydr4nt
Copy link

F1r3Hydr4nt commented Jan 8, 2020

Sorry for retouching this but I have also encountered the .obj importer failing on quadstrips... Is there an assimp model viewer example?

Perhaps one might consider integrating tiny_obj_loader? I could help with some direction... Great abstraction by the way, thank you!

Would it be sufficient to change, in the case of quad indices primitive=MeshPrimitive::TriangleStrip; in ObjImporter?

@mosra
Copy link
Owner

mosra commented Jan 8, 2020

@freddiehonohan the builtin ObjImporter is frankly beyond shitty in its current state :) I'm planning to give it some love as part of #371, but right now you're best off just using Assimp. TinyObj is also somewhere on the TODO list, but the most effort goes into glTF support right now, this one is not really a priority. (If you'd like to contribute a plugin, you're most welcome -- just please wait until I finish #371 to avoid unnecessary work as the APIs will change quite a bit after that lands.)

Would it be sufficient to change

In the OBJ file it's not really strips, but rather a list of quads, and the plugin takes a shortcut and fails when encountering anything that's not a triangle. Fixing this single thing could be easy (by adding quad triangulation), but there's much more missing (like materials), which still make the ObjImporter quite useless.

Is there an assimp model viewer example?

It's the exact same code, you just need to build plugins with WITH_ASSIMPIMPORTER enabled (unless you have done that already). With the CMake subproject approach shown here, add this option before the add_subdirectory(magnum-plugins). Then, if you have the builtin ObjImporter disabled and not built / installed anywhere, it should fall back to Assimp. Alternatively, you can pass --importer AssimpImporter to force using Assimp for loading the model.

Hope this is detailed enough to help you :)

@F1r3Hydr4nt
Copy link

Ok great, thanks for the detailed instructions they should be a lot of help. I will let you know how I get on, thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants