Having trouble loading obj models and encountering a CoffeeScript error:
loader = new THREE.OBJLoader manager
if loadedModels.diamondRing == null
loader.load "obj/diamond/ring1.obj", (object) ->
object.traverse (child) ->
if child instanceof THREE.Mesh
child.material = silverMaterial.clone()
object.position.y = 10
object.scale.x = object.scale.z = object.scale.y = config.p1.size*0.05
object.userData.ring = true
combine.add object
loadedModels.diamondRing = combine.clone()
loader.load "obj/diamond/diamond1.obj", (object) ->
object.traverse (child) ->
if child instanceof THREE.Mesh
child.material = silverMaterial.clone()
object.position.y = 10
object.userData.diamond = true
object.scale.x = object.scale.z = object.scale.y = config.p1.sizeDiamond*0.075
combine.add object
An exception has been caught:
Uncaught TypeError: Cannot read property 'clone' of undefined obj.js:93
The error seems to be in the 'obj.js' file, specifically in the 'add_face' function on line 93:
function add_face( a, b, c, normals_inds ) {
if ( normals_inds === undefined ) {
geometry.faces.push( face3(
vertices[ parseVertexIndex( a ) ] - 1,
vertices[ parseVertexIndex( b ) ] - 1,
vertices[ parseVertexIndex( c ) ] - 1
) );
} else {
geometry.faces.push( face3(
vertices[ parseVertexIndex( a ) ] - 1,
vertices[ parseVertexIndex( b ) ] - 1,
vertices[ parseVertexIndex( c ) ] - 1,
[
-- line 93 --> normals[ parseNormalIndex( normals_inds[ 0 ] ) ].clone(),
normals[ parseNormalIndex( normals_inds[ 1 ] ) ].clone(),
normals[ parseNormalIndex( normals_inds[ 2 ] ) ].clone()
]
) );
}
}
The problem appears to be related to normals in the model data, but the exact cause is unclear. When reading the model, an issue arises on lines like:
f 6802//6802 6803//6803 6804//6804
Removing these lines from the obj model makes it appear normal in the 3D editor. Has anyone encountered a similar problem before?