-
Notifications
You must be signed in to change notification settings - Fork 185
GLTF_Model_Viewer didn't get the right result? #74
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
Comments
Hello @sonygod The glTF loading and material assigning is honestly the weakest part of my repo here and the weakest area of my graphics knowledge. I am comfortable with the ray tracing and path tracing elements of the code base, but not so much with the glTF model loading and correct glTF material (especially many different textures in the glTF file) rendering parts. But regardless, I'll take a look and do my best to help you out, or at least point you in the right direction. Will be back hopefully soon 🙂 |
@sonygod Apparently, either the glTF model must have indices for all sections (components) of the model, or no indices at all. When I disabled this error check in the BufferGeometryUtils.js file, it loads the model, but it looks wrong - also, it gives a number of triangles that has a fractional component, like 4337.3333 - which should never happen. If everything loads correctly, the number of triangles is the number of vertex positions (x,y,z) divided by 9. This is because every triangle has 3 vertices, and every vertex has 3 components - x, y, and z. So that's 3 x 3 = 9 float numbers for each triangle. If the model's geometry.attributes.position.array.length is not divisible by 9, something is wrong at load time. How was this model created? What software was used? Can you verify that each triangle has 3 vertices? |
Hello, With the glTF model demos that I did write personally, I am able to load the classic Utah Teapot, Stanford Bunny, Stanford Dragon, and Damaged Helmet models, all in glTF or glb format. I think all these work because the original model file has 1 texture (or none) for the entire model, and more importantly, all the vertices in the original file are positioned exactly from the same origin. In other words, there are no groups of objects with their own model-space origins, there is only one model origin at the center of the entire model, and every triangle is listed in the file in relation to that same origin. Therefore, no extra work needs to be done on my part, because I just simply load in the exact triangle vertex positions, create the BVH acceleration structure, and then send everything to the GPU as a data texture where it can be ray traced against or rendered. If there are any extra components, or a modular model structure (that makes sense for an apartment building), I'm sorry to say that at this time, I do not know how to correctly load in such a glTF file, because of the groups, or parent and child matrices, that might affect the pure triangle vertex positions that are listed in the glTF file. My simple loading code is incorrectly just reading in all the vertices as they are listed in the raw glTF file, and trying to display them without first applying the possible matrix stacks to those raw vertices. As I mentioned in my first reply, glTF loading and multiple texture loading is the weak-point of my path tracing repo here. I do eventually want to be able to correctly load any arbitrary glTF file in the future, but it will take much more study and effort on my part to know how to handle such files. I hope I have explained the situation well enough. Again, apologies for not being able to help further. I would if I could, but this loading stuff is not my strongest area - far from it actually. I hope you are able to find a solution. Maybe somehow, combining/merging all the vertices into the same single model object inside your 3d model creation software? The textures still might not work, but at least the triangles would be displayed in their correct order and positions. -Erich |
@erichlof Hi, I think I have same issue, I want try renderer with my own model, but it not loading anything, error on acces child.geometry.index.cout. I don't know much about shader programming. But I using some code to recompute verticies position to world position (where are really rendered). When you world matrix of Object3D (mesh in this case) to vertex you will get him position in world space. So maybe you can apply this in shader, or we can write some algorithm, which will recompute positions of verticies and make every transform matrix indentity (no rotation/translation). You can send Matrix4 to shader or you can decompose this matrix, to translation, rotation and scale and send only these vectors. The code:
|
I also face this same issue trying to import gltf files with multiple materials and meshes. For ensuring vertices are all centered around same origin, would a tool like this help? Maybe flatten and then clearnodetransform? |
@kfarr I have been successful with a single model with 1 overarching material that covers the entire mesh, but I'm still working on extracting an arbritrary number of meshes that might make up a glTF scene. Whatever is used in the end, it must respect all of the relationships between parent and child matrices, which is tricky for me to understand - but I am studying it and trying to improve. 😅 |
@erichlof hey, how is that going |
GLTF_Model_Viewer didn't get the right result?
the origin gltf is
after import into gltf viewer?
and I add some code here?
is this code wrong or somthing else?
model is here.
rjh_test_1672042778000.zip
The text was updated successfully, but these errors were encountered: