OBJ模型未在Three.JS中加载

时间:2014-07-16 19:24:26

标签: javascript coffeescript three.js 3d-model

我正在尝试加载obj模型,这是代码(CoffeeScript)

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 

但我抓到了异常:

Uncaught TypeError: Cannot read property 'clone' of undefined obj.js:93

其中obj.js - THREE.OBJLoader。

第93行的

放置了add_face函数:

    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()
                ]
            ) );

        }

    }

我认为法律问题,但我不知道究竟在哪里。 阅读模型问题发生在最后几行,如下:

 f 6802//6802 6803//6803 6804//6804

如果在obj模型中删除受影响的行:

enter image description here][1

在3d编辑器模型中看起来正常。 可能是有人遇到这样的问题。

1 个答案:

答案 0 :(得分:0)

我通过将标准obj加载器更改为此https://github.com/maxogden/stl-obj-viewer

来解决了这个问题