Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Three.js ThreeJS开门动画_Three.js - Fatal编程技术网

Three.js ThreeJS开门动画

Three.js ThreeJS开门动画,three.js,Three.js,我需要创建打开门的动画,为此我有门的加载模型,我需要旋转90度来打开它。现在我已经创建了一个提琴样本,但是门是围绕中心旋转的,我如何使它围绕侧轴旋转 var camera, scene, renderer; var mesh, pivot; init(); animate(); function init() { camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.0

我需要创建打开门的动画,为此我有门的加载模型,我需要旋转90度来打开它。现在我已经创建了一个提琴样本,但是门是围绕中心旋转的,我如何使它围绕侧轴旋转

var camera, scene, renderer;
var mesh, pivot;

init();
animate();

function init() {

    camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
    camera.position.z = 1;

    scene = new THREE.Scene();

    var material = new THREE.MeshNormalMaterial();
    material.side = THREE.DoubleSide;

    axis = new THREE.Mesh( new THREE.PlaneGeometry( 0.01, 0.6, 0.01 ), material );
    axis.position.set(0.4, 0, .20);
    scene.add( axis );

    var door = new THREE.Mesh( new THREE.PlaneGeometry( 0.2, 0.5, 0.2 ), material );
    door.position.set( 0, 0, 0 );
    axis.add(door);

    pivot = new THREE.Group();
    pivot.position.set( 0.0, 0.0, 0 );
    axis.add( pivot );
    pivot.add( door );

    scene.add( new THREE.AxesHelper() );

    renderer = new THREE.WebGLRenderer( { antialias: true } );
    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );

}

function animate() {

    requestAnimationFrame( animate );

        pivot.rotation.y += 0.01;

    renderer.render( scene, camera );

}

var摄像机、场景、渲染器;
var网格,枢轴;
init();
制作动画();
函数init(){
摄像头=新的三个透视摄像头(70,窗口内宽/窗口内高,0.01,10);
摄像机位置z=1;
场景=新的三个。场景();
var material=新的三个.MeshNormalMaterial();
material.side=3.DoubleSide;
轴=新三个网格(新三个平面几何体(0.01,0.6,0.01),材质);
轴位置设置(0.4,0.20);
场景。添加(轴);
var门=新三个网格(新三个平面几何体(0.2,0.5,0.2),材质);
门位置设置(0,0,0);
轴。添加(门);
pivot=新的三个组();
枢轴位置设置(0.0,0.0,0);
轴。添加(枢轴);
枢轴。添加(门);
scene.add(新的THREE.AxesHelper());
renderer=new THREE.WebGLRenderer({antialas:true});
renderer.setSize(window.innerWidth、window.innerHeight);
document.body.appendChild(renderer.doElement);
}
函数animate(){
请求动画帧(动画);
枢轴旋转y+=0.01;
渲染器。渲染(场景、摄影机);
}
正文{
保证金:0;
}

我认为这个答案是相关的,关于围绕其中心以外的点旋转对象:在您的情况下,您将围绕其铰链旋转门,因此在该位置选择一个点作为您的中心点。是的,我尝试了,它只在一个步骤上起作用,如果我在动画循环中进行旋转,只有第一步工作正常,从第二步开始,对象将从其原始位置移开。您能使用一个代替JSFIDLE的工具吗?