three.js 相对坐标的设置

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;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值