-
Notifications
You must be signed in to change notification settings - Fork 34
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
Get replicated vertices when reading obj #48
Comments
Can you show me your code and the result? I don't see any wrong behavior of obj-rs with this input. |
My code is let input = BufReader::new(File::open("./bunny.obj").expect("Error when opening file"));
let model: Obj<Vertex, u32> = load_obj(input).expect("Error when loading model");
println!("Stats of the model:\nnum_vertices = {}, num_indices = {}", model.vertices.len(), model.indices.len()); And the result is
which is wrong, since there are not so many different vertices. |
I don't see any same vertices at all. Looks like all points have different position/normal combination. Can you more specifically let me know what points you expect to be merged? |
So then it's not a bug, but it just behave differently from what I expected, since I don't need normals in my case and expect vertices should not have the same positions. Then this becomes a feature request somehow. Is it possible for us to read obj file without normals? In my case, I will expect the length of the It will take a bit of time to de-duplicate vertices w.r.t positions with the current API, if we need to take numeric inaccuracies into account. |
Vertex should be a combination of position vector and normal vector to draw it properly with Modern graphics API. So we treat “v” of OBJ as “position vector”, not vertex, and treat “vn” as “normal vector”. And vertex is combination of “v” and “vn”. So if you have X number of “v” and Y number of “vn”, maximum number of vertex is X*Y. If you want to merge two vertices, both vertices must have same position vector and same normal vector. If one of them is different, they are different vertices and will be treated differently by shader. I’m closing this issue since there is no wrong behavior. Please let me know if you still think there is any kind of wrong or unexpected behavior. If you just want to parse OBJ file without transforming it into modern graphics API compatible format, take a look for the “raw” APIs which are also provided by obj-rs. |
You can ignore normal vectors. Take a look at this link: #39 (comment) I know it’s not documented very well. |
When I tried to use obj-rs to read my
bunny.obj
, I found that instead of giving triangles that share vertices, it gives me a bunch of triangles with their own vertices that has different indices. For example, I have two triangles (1,2,3 and 1,3,4) and 4 vertices, then I will expect theVec
of indices contains0,1,2,0,2,3
instead of0,1,2,3,4,5
. This behavior is abnormal, but I don't know if it's a bug for certain obj files.My bunny obj is as follows:
Click to expand!
The text was updated successfully, but these errors were encountered: