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

Fix OBJLoader to support more than three vertices in one face #10917

Closed
wants to merge 1 commit into from

Conversation

yqrashawn
Copy link

Reference to #10438 and http://stackoverflow.com/questions/41154498/threejs-some-material-texture-faces-triangles-not-rendering/41257937#41257937

Though it should be done at the exporter side to make 3 vertices per face. Some application (ArichCAD) do not have that option.
I saw there's some triangulation code in OBJLoader already for supporting 4 vertices per face. So update a little to support more.


for ( var j = 2; j < ivs.length; j ++ ) {

this.addVertex( ivs[ 0 ], ivs[ j - 1 ], ivs[ j ] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see this builds triangles by connecting each neighbouring pair of face vertices with the first vertex. So I believe this only works for convex faces ? And can potentially produce very high aspect ratio triangles ?
Is three ok with zero area triangles (when the three vertices are colinear) ?

Copy link
Author

@yqrashawn yqrashawn Mar 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I believe this only works for convex faces ? And can potentially produce very high aspect ratio triangles ?

Yes. The former OBJLoader connect neighboring pair of vertices with last vertex.

Is three ok with zero area triangles (when the three vertices are colinear) ?

I think the model editor need to take care of this. (broken model)

@mrdoob
Copy link
Owner

mrdoob commented Mar 2, 2017

Could you remove the builds from the PR?

@yqrashawn
Copy link
Author

@mrdoob Of course, done.


}

state.addFace( vs, us, ns );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered the performance here? Have you ran tests how much this slows down different sized obj file loads. This seems to throw out out a lot of the tuning that has been done to make common obj load faster.

You are doing a secondary regexp exec (that I tried to minimize to the bone) var rawdata = /^f\s+/.exec( line );. Then slicing, splitting and doing multiple for loops.

Surely this slows down the exporter for the common case users? Isn't there another way to make a separate code path for just the > 3 vertices case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell from my earlier testing the slow parts in the loader are array manipulations. This adds a bunch more. Just wondering about the loader perf impact here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't considered performance issue. The regexp should only do once. It should be optimized. I'll try my best.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah once per f line, but potentially hundreds of thousands of lines for large files. Everything adds up. Temp arrays will trash GC etc.

Consedering what this tries to fix afaik is rather rare, it seems bad to put a perf penalty for all the apps out there that use obj as their assets.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonnenauha, how were you doing your performance testing? IMO this is a pretty valuable change and it would be worth getting it right.

@mrdoob
Copy link
Owner

mrdoob commented Aug 10, 2017

Ended up merging #11871, which was similar to this PR but a bit simpler.

@mrdoob mrdoob closed this Aug 10, 2017
@mrdoob
Copy link
Owner

mrdoob commented Aug 10, 2017

Many thanks for the PR though! Would be curious to know if the current version of the OBJLoader loads those ArichCAD files properly.

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

Successfully merging this pull request may close these issues.

5 participants