0

这是一个简单矩形框的示例 json 文件。

{

    "metadata" :
    {
        "formatVersion" : 3.1,
        "sourceFile"    : "BOX.obj",
        "generatedBy"   : "OBJConverter",
        "vertices"      : 8,
        "faces"         : 6,
        "normals"       : 6,
        "colors"        : 0,
        "uvs"           : 4,
        "materials"     : 1
    },

    "scale" : 1.000000,

    "materials": [  {
    "DbgColor" : 15658734,
    "DbgIndex" : 0,
    "DbgName" : "wire_135110008",
    "colorAmbient" : [0.0, 0.0, 0.0],
    "colorDiffuse" : [0.5294, 0.4314, 0.0314],
    "colorSpecular" : [0.35, 0.35, 0.35],
    "illumination" : 2,
    "specularCoef" : 32.0,
    "transparency" : 1.0
    }],

    "vertices": [-0.069100,0.041400,0.069200,-0.069100,0.041400,0.040600,-0.028100,0.041400,0.040600,-0.028100,0.041400,0.069200,-0.069100,0.077200,0.069200,-0.028100,0.077200,0.069200,-0.028100,0.077200,0.040600,-0.069100,0.077200,0.040600],

    "morphTargets": [],

    "morphColors": [],

    "normals": [0,-1,-0,0,1,-0,0,0,1,1,0,-0,0,0,-1,-1,0,-0],

    "colors": [],

    "uvs": [[1,0,1,1,0,1,0,0]],

    "faces": [43,0,1,2,3,0,0,1,2,3,0,0,0,0,43,4,5,6,7,0,3,0,1,2,1,1,1,1,43,0,3,5,4,0,3,0,1,2,2,2,2,2,43,3,2,6,5,0,3,0,1,2,3,3,3,3,43,2,1,7,6,0,3,0,1,2,4,4,4,4,43,1,0,4,7,0,3,0,1,2,5,5,5,5]

}

这是我加载上面的盒子的代码(没有为加载的盒子设置位置声明):

var jsonLoader = new THREE.BinaryLoader();
jsonLoader.load('models/demo/BOX.js', function (geometry, materials) {
    var faceMaterial = new THREE.MeshFaceMaterial(materials);
    box = new THREE.Mesh(geometry, faceMaterial);

    // Add mesh to the scene
    box.scale.set(10, 10, 10);
    scene.add(box);
});

加载后我试图获得它的原始位置,但我遇到了问题。我得到的职位$('#info').html(box.position.x + ', ' + box.position.y + ', ' + box.position.z);总是0, 0, 0。(#info 是一个显示结果的 div 元素)。
有人可以帮我在加载后获得盒子(或任何其他模型)的原始位置,而无需手动设置其位置吗?
谢谢!

4

1 回答 1

1

您可以这样做box.computeBoundingSphere ();,然后 box.boundingSphere.center 将包含模型的中心。此外,您可以使用computeBoundingBox().

于 2013-05-28T17:24:40.343 回答