如何在三个js中添加子网格上的轮廓

时间:2014-05-08 00:47:33

标签: javascript 3d three.js

我想在网格中添加大纲。我按照示例which created a new mesh using the same geometry, and scaled the mesh.

    var outlineMaterial = new THREE.MeshBasicMaterial({color: 0x00ffff, side: THREE.BackSide});
    this.outlineMesh = new THREE.Mesh(target.geometry, outlineMaterial);
    this.outlineMesh.quaternion = target.quaternion;
    this.outlineMesh.position = target.position;
    this.outlineMesh.scale.copy(target.scale);
    this.outlineMesh.scale.multiplyScalar(1.05);
    this.scene.add(this.outlineMesh);

它工作正常,outlineMesh的位置始终与目标网格相同。但是,当我将目标网格作为子网格添加到其他网格时,outlineMesh的位置与目标网格不同。我认为这是因为目标位置与父坐标相关,但outlineMesh仍然在世界坐标中。

知道如何为儿童网格做大纲工作吗?非常感谢你!

1 个答案:

答案 0 :(得分:4)

只需将outlineMesh添加为目标mesh的子项,就像这样:

var outlineMaterial = new THREE.MeshBasicMaterial( { color: 0x00ffff, side: THREE.BackSide } );
outlineMesh = new THREE.Mesh( geometry, outlineMaterial );
outlineMesh.scale.multiplyScalar( 1.05 );
mesh.add( outlineMesh );

three.js r.67