How to add outline on child mesh in three js

╄→гoц情女王★ 提交于 2019-12-23 02:54:09

问题


I'd like to add outline to meshes. I followed the example 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);

It works fine, the position of outlineMesh is always same to target mesh. However, when I added the target mesh as child to other mesh, the position of outlineMesh is different to the target mesh. I thought it's because the target position is related to parent's coordinate, but the outlineMesh is still in the world coordinate.

Any idea how to make outline work for child mesh? Thank you very much!


回答1:


Just add the outlineMesh as a child of the target mesh, like so:

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



来源:https://stackoverflow.com/questions/23530879/how-to-add-outline-on-child-mesh-in-three-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!