0

我正在尝试加载 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 模型中删除受影响的行:

在此处输入图像描述][1

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

4

1 回答 1

0

我通过将标准 obj 加载器更改为此https://github.com/maxogden/stl-obj-viewer解决了这个问题

于 2014-08-06T10:16:22.973 回答