4

当我创建一个 JSON 模型并使用 THREE.JSONLoader.load 加载它时,它会毫无问题地加载,但是当我尝试从中创建一个变量并将数据包含在主脚本中时,THREE.JSONLoader.parse 调用会引发异常.

var lh_model = {
    "metadata" : { "formatVersion" : 3.1, ..., "morphTargets"  : 0 },
    "vertices": [
          0.001000,    0.001000,  -0.001000,
        102.616974,  -61.974983,  19.303007,
        102.108978,  -62.482986,  -7.620989,
        123.952972,  -49.274994,  -3.048992,
        123.952972,  -48.766994,  14.223002
    ],
    "uvs": [0.9458,0.5134,0.9419,0.5177,0.9513,0.5177,........],
    "faces": [ 0, 4, 1, 2 ],
    "morphTargets": []
}

var loader = new THREE.JSONLoader();
var geometry = loader.parse(lh_model);

load.parse 导致

Uncaught TypeError: Cannot read property 'length' of undefined

Three.js 深处某处的错误:

THREE.Mesh.prototype.updateMorphTargets = function () {

    if ( this.geometry.morphTargets.length > 0 ) {

当我采用其他人制作的工作示例(http://stemkoski.github.io/Three.js/Model.html)时,也会发生同样的情况。

我正在使用 Three.js r.58

4

1 回答 1

4

做这个

var loader = new THREE.JSONLoader();
var model = loader.parse( lh_model );

var mesh = new THREE.Mesh( model.geometry, new THREE.MeshBasicMaterial() );
scene.add( mesh );

如果您将材料添加到模型中,您将执行以下操作

var mesh = new THREE.Mesh( model.geometry, materials[ 0 ] );

三.js r.58

于 2013-06-14T14:36:48.810 回答