Mesh 好比一个包装工,它将『可视化的材质』粘合在一个『数学世界里的几何体』上,形成一个『可添加到场景的对象』。创建的材质和几何体可以多次使用(若需要)。而且,包装工不止一种,还有 Points(点集)、Line(线/虚线) 等。
通过父与子的关系可以将mesh们关联起来mesh_parent.add(mesh_child),子的position是相对于父的,即子的坐标系以父的位置为原点
相对坐标系(相关联物体)
测试demo: https://codepen.io/vidark/pen/JNNPPJ
// Sphere Mesh 1
sphereMesh1 = new THREE.Mesh(sphereGeometry1, sphereMaterial1);
sphereMesh1.position.set(0, 1, 0);
scene.add(sphereMesh1);
// Pivot point
pivotPoint = new THREE.Object3D();
sphereMesh1.add(pivotPoint);
// Sphere Mesh 2
sphereMesh2 = new THREE.Mesh(sphereGeometry2, sphereMaterial2);
// Position from pivot point to sphere 2
sphereMesh2.position.set(260, 4, 4);
// make the pivotpoint the sphere's parent.
pivotPoint.add(sphereMesh2);
// Renderer
} // End of init
// Animate
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
render();
}
// Mesh animation
function render() {
// Animating sphere 1
var time1 = Date.now() * 0.0005;
sphereMesh1.position.x = Math.cos( time1 * 10 ) * 2;
sphereMesh1.position.y = Math.cos( time1 * 7 ) * 3;
sphereMesh1.position.z = Math.cos( time1 * 8 ) * 4;
// Animating sphere 2 相对父节点坐标系
pivotPoint.position.x += 0.0001;
pivotPoint.position.y += 0.03;
pivotPoint.position.x += 0.0001;
}