OBJ Kd material attribute incorrectly converted to emission value
- Dominant language
- JavaScript
- Stars
- 1.9k
- Forks
- 311
- PR merge metrics
- No merged PRs in 30d
Description
Download the OBJ version of this free model: https://www.turbosquid.com/FullPreview/Index.cfm/ID/691507
When converted by obj2gltf and displayed using three.js's gltf loader, I get the result https://s26.postimg.org/6maqtr28p/bad_gltf.jpg
The materials are all very bright, there is no shading. This occurs because all materials' Kd values are used to set the emission, not the diffuse value.
Here is a snippet of the original material, .mtl file:
newmtl canopy2
Ns 25
d 0.8
illum 2
Kd 0.8 0.796863 0.793726
Ks 0 0 0
Ka 0.3 0.298824 0.297647
This gets converted to:
"canopy2": {
"technique": "technique1",
"values": {
"ambient": [
0.3,
0.298824,
0.297647,
1
],
"diffuse": [
0,
0,
0,
1
],
"emission": [
0.8,
0.796863,
0.793726,
0.8
],
"specular": [
0,
0,
0,
1
],
"shininess": 25,
"transparency": 1
}
},
Note how the emission is set, but diffuse is not. This gives the unshaded model view shown in https://s26.postimg.org/6maqtr28p/bad_gltf.jpg
My _guess_ is that perhaps the "illum 2", which is officially "2 Highlight on", is causing this. In practice, I would ignore "illum 2" - people misuse it. Or, perhaps it's the "d 0.8" value, which should be interpreted as 20% transparent, another factor missing from the translation. Whatever the case, the diffuse color is missing, emission is set instead, and that's incorrect.
Wavefront OBJ materials are a nightmare to interpret, so expect more bugs along these lines.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the conversion with the linked OBJ/MTL model and inspect how Kd, illum, and d are translated into material values. Done means the diffuse value is populated, emission is not incorrectly assigned from Kd, and the reported unshaded result is corrected; add a regression check if the repository has an applicable test location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100