mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.08k stars 35.34k forks source link

OBJ loader bug with smoothing groups #8949

Closed Chaky74 closed 8 years ago

Chaky74 commented 8 years ago
Description of the problem

OBJ loader does not load/process/use smoothing groups in r76 and in r77. (haven't checked 74 nor 75) I'm not sure if newer loader version needs some extra property declared or not to use smoothing groups or not.

r73's OBJMTLLoader does load smoothing groups correctly.

Correction. Material shading is being set to THREE.FlatShading, instead of THREE.SmoothShading. That's what causes the 'loss' of smoothing groups. My guess is detection of smoothing groups in model is buggy.

Three.js version
mrdoob commented 8 years ago

/ping @jonnenauha

Chaky74 commented 8 years ago

I've just browsed through r77 OBJLoader.js... I think this issue is on on todo list written there:

todo Handle files that have varying smooth values for a set of faces inside one geometry...

My model is a single mesh with 8 smoothing groups.

jonnenauha commented 8 years ago

Hmm, I'm not sure where that todo list is. Can you link to it? I dont have any plans to implement this at the moment at least, have other stuff to tackle. Maybe it was a todo from someone else or I have just forgotten some todo comment :)

"smooth" is read per object/material basis. If you change the smooth value on/off mid object geometry declaration, it will not be read correctly to the vertex groups. Only thing that splits into multiple vertex groups now is material changed mid geometry declaration. If you have first material, then change the smooth, it should already work (in dev). But if its not changing material, just smooth, then it will use the last seen value.

Could you upload your obj and mtl, maybe I could take a look. Sounds like a fairly easy change. If the smooth is changed mid parsing, the current material should be cloned and smooth value changed. After that, it would automatically create the groups in the geometry with multi material.

Chaky74 commented 8 years ago

"Todo list" is in the OBJLoader.js, line 544-551

I "fixed" the issue by changing the shading property, after the object loaded. Seems ok to me that way.

Here's the offending file(s): https://www.dropbox.com/s/7du2268gjns8kck/Prsten20.obj?dl=0 https://www.dropbox.com/s/6a9qleuudkrywl2/Prsten20.mtl?dl=0

jonnenauha commented 8 years ago

Ah, it is my code comment indeed :) Thanks for the files, I might tackle this later.