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

Objects and Groups behave differently #15

Open
johannesvollmer opened this issue Sep 16, 2019 · 3 comments
Open

Objects and Groups behave differently #15

johannesvollmer opened this issue Sep 16, 2019 · 3 comments

Comments

@johannesvollmer
Copy link

johannesvollmer commented Sep 16, 2019

Hi!

As assumed in line 655,

tobj/src/lib.rs

Line 655 in 023076f

// Just treating object and group tags identically. Should there be different behavior

Objects and groups are not the same and should, in theory, be handled differently.

Probably, only few people will need it. Nevertheless, I'll describe the difference here. You will have to decide on your own if that distinction is important enough to be implemented.

Objects

The code currently treats objects as expected. For objects, each name starts a new object and closes the old one. Two objects with the same name will result in two different objects that happen to have the same name.

Groups

In the code, groups are handled the same way as objects. Instead, groups should be treated as collections, accumulating data from anywhere in the OBJ file, as many times as desired. As a result, a group name appearing twice in a file should not result in two distinct groups, but instead the result should be a single group containing the geometry of both parts.

Summarizing: Duplicate objects stay separated, duplicate groups should be merged.

Cheers!

@Twinklebear
Copy link
Owner

Thanks @johannesvollmer , this is interesting! I didn't know about this difference between the two, I haven't seen a file that uses this duplicate group merging functionality. I'll leave this issue open in case someone else finds that this causes a loading bug for them, but it seems like a relatively rare use case so for now I'll leave the code as is.

@johannesvollmer
Copy link
Author

To be honest, I too have never seen such a file in my life 😁

@sunjay
Copy link

sunjay commented Jan 7, 2020

Just ran into this while loading OBJ files. An interesting consequence of this is that it can become impossible to get the name of the object if there are no faces before the first group.

Example file: https://github.com/ProtoArt/spritec/blob/28bf3b8b84a0c86e646d3b2d598be983a2e7c167/samples/bigboi/obj/bigboi_000001.obj

In this example file, we have something like this:

# Blender v2.81 (sub 16) OBJ File: 'bigboi.blend'
# www.blender.org
mtllib bigboi_000001.mtl
o Icosphere_bigboi
v 1.701308 0.850645 0.432616
v 1.051475 0.525738 -1.132616
...
g Icosphere_bigboi_torso
usemtl torso
s 1
f 220/1/1 231/2/2 14/3/3
f 232/4/4 9/5/5 16/6/6
...

All the vertices are defined at the object level, but none of the faces show up until the first group. The code below means that name will be overwritten with the name of the group and it won't be possible to get the object name.

tobj/src/lib.rs

Lines 655 to 673 in e3d93b4

// Just treating object and group tags identically. Should there be different behavior
// for them?
Some("o") | Some("g") => {
// If we were already parsing an object then a new object name
// signals the end of the current one, so push it onto our list of objects
if !tmp_faces.is_empty() {
models.push(Model::new(export_faces(&tmp_pos,
&tmp_texcoord,
&tmp_normal,
&tmp_faces,
mat_id),
name));
tmp_faces.clear();
}
name = line[1..].trim().to_owned();
if name.is_empty() {
name = "unnamed_object".to_owned();
}
}

This isn't a huge deal for what I'm working on right now, but it definitely would have been nice to be able to get a tobj::Mesh that exposes its own name and a groups: Vec<tobj::Mesh> field.

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

No branches or pull requests

3 participants