How do I rotate some moons around a planet with THREE.js?

后端 未结 2 2175
借酒劲吻你
借酒劲吻你 2020-12-14 15:32

I think this picture best explains my issue:

\"hooray

First I translate the box

2条回答
  •  长情又很酷
    2020-12-14 15:58

    There are several ways of doing what you want, but I think the easiest is like so:

    // parent
    parent = new THREE.Object3D();
    scene.add( parent );
    
    // pivots
    var pivot1 = new THREE.Object3D();
    var pivot2 = new THREE.Object3D();
    var pivot3 = new THREE.Object3D();
    
    pivot1.rotation.z = 0;
    pivot2.rotation.z = 2 * Math.PI / 3;
    pivot3.rotation.z = 4 * Math.PI / 3;
    
    parent.add( pivot1 );
    parent.add( pivot2 );
    parent.add( pivot3 );
    
    // mesh
    var mesh1 = new THREE.Mesh( geometry, material );
    var mesh2 = new THREE.Mesh( geometry, material );
    var mesh3 = new THREE.Mesh( geometry, material );
    
    mesh1.position.y = 5;
    mesh2.position.y = 5;
    mesh3.position.y = 5;
    
    pivot1.add( mesh1 );
    pivot2.add( mesh2 );
    pivot3.add( mesh3 );
    

    Then in your render loop:

    parent.rotation.z += 0.01;
    

    EDIT: updated fiddle: https://jsfiddle.net/edqf7ugc/

    three.js r.116

提交回复
热议问题