GLTF Loader parsing issue
Closed this issue · 7 comments
Describe the bug
GLTF models are not parsed very well. There are some models that are rendered correctly, however most of the model set that I have are not rendered correctly. I think the reason for that is the "addItem" function. There is a callback function called "gltfCallback" and there happens a parsing process that takes all the meshes of the Object3d objects and merges the geometries and materials. I think that the if-else part that parses the geometries after materials are parsed is the problem.
Expected behavior
This is a screenshot that is obtained from a gltf viewer and this is how it is supposed to look like:
Screenshots
And this is what I see in the render. As you can see, newmaterials array (texture list) is updated correctly but not the newGeometry one (I guess).
The GLTF Loader itself is okay, when I directly add the model to the scene, it is quite fine. However, when the model is processed by the "addItem" function before an item object is created, this weird behavior happens. Obj models are loaded fine tho, there is no problem with them.
I also share the model that I am referencing for you to understand and repeat the experiment yourself. Any idea, how can I fix this ?
Thanks in advance !
I believe this issue was fixed long time ago. Yes you are right about the way the geometries are merged after the GLTF callback happens after loading. The geometries are processed into single geometry. OMG the nightmare is back. I am afraid there is a big amount of rework to be done the way the architechture handles loading of GLTF models. Maybe soon there needs to be some sort of Monkey patch to handle this issue.
Regards,
#0K
Thanks for your reply #OK. Maybe this work could relate to a radical change such that elimination of parsing the model into geometries such as BufferGeometries. Using the models as the outputs of the loader will do the job right ? Adding the models directly to the scene and also to the items list for the raycaster to intersect.
Well, I have been searching some ways to convert GLTF models into OBJs. It seems not that easy, I have found an open-source software named "assimp" that works with OpenGL and is used to render objects. It should also be able to convert GLTF models into OBJ ones but I have not still figured out how to work with it. Maybe this converter can be used in the code to prevent loosing the GLTF models.
Regards
Yes, the changes are huge to modify this logic. It would affect a lot of places including ray casting routines. What I did originally was just converting the typescript of the original project back to ES6. Otherwise, the framework idea or architecture remains the same.
Regarding your exploration of converting GLTF to Obj, there are good GLTF importers available now for Blender. Try using that. I don't have a link ATM, but will try to find it. I use that to often inspect the floorplan saved as GLTF from blueprint-js.
If you would ask me I would stick to using GLTF and avoid OBJ at all cost. Remember this issue is not going to be solved even after OBJ conversion is made. This is more of the conceptual bug in the way this framework is made. Again, I would stick with GLTF. In fact, GLTF is a very good idea.
A word of advice in using ASSIMP is AVOID AT ALL COST. I started my PhD using Assimp library for geometry processing and editing, but faced a lot of issues. If you would agree, blueprint-js is more of editing purposes like Blender or Meshlab. This demands the mesh connectivity and topology remains the same loaded into any software or library, however dirty it shall be. But Assimp is a library aimed at rendering than for geometry editing. Hence Assimp screws up your geometry and the connectivities. Assimp takes this decision to optimize the rendering runtime and I would say this is correct in doing that. But if the purpose is to inspect geometries and maintain synchronizations then Assimp is not a good choice. For example, assume in a scenario where you might extend the purpose of blueprint-js to something like CAD, CAM or costing per triangle, in this case you are compelled to use a solution that is not three-js based. Say we are using Blender for this purpose. Once you load the geometry that was processed by Assimp then you will notice differences between the mesh connectivity from the original leading to nightmarish days where you wonder what is wrong with your code (which is not the case). I had these issues using ASSIMP and hence I consciously stay away from using it.
Regards,
#0K
Hi #OK, thanks for filling all the info in. Yes, I do know there are some importer and exporter plug-in(s) and I have been actually using them to convert between models. However, the point is that I have more than 700 models to be converted. Manually, it will take forever to convert them using Blender or such.
Therefore, I have been researching for a way to develop a script to do it for me in a parallel or sequential manner.
So, at the end of the day, until this radical change is made, I think it is a good idea to have OBJs at least to have model to even render right ? I realize that GLTF is much better in terms of performance and structure comparing to OBJs but in this case OBJs are better than having nothing at all right ? For the moment. I really do not take into account the OBJ's structure being one large mesh which affects the performance and all that. For this reason, I do not see even how/why should I stick with GLTF ?
I will also take your advice and stay away from Assimp. Thanks for the tip that came before it is too late :)
Regards
Hello Can,
With Blender its easier to do with python scripts for automating this task. Let me know if I can help you with this.
Regards,
#0K
I would appreciate if you could fill me in on how to automatize converting the models from gtlf to obj on Blender. I cannot say I know much about Blender myself.
Thanks a lot.
Cheers
Hello Calvin,
I tired your model and found that there were of inner transforms for the child meshes. If you load it as it is then it renders well. If you go the geometry fusing way then it's jeopardized. So I am thinking if we should allow child meshes to have inner transforms? If I don't operate on the geometry level then there are other parts that go beserk. So it's necessary to freeze all the transformations of the child meshes before exporting as GLTF.
Regards,
#0K