.wrl对象在axix上的Three.js旋转

问题描述

我试图在同一轴上旋转模型。 我正在使用.wrl模型来显示阴影。我在下面附上了代码以供参考。一切正常,模型会旋转,但希望限制上下旋转。我已经使用了planeGeometry来显示阴影。不确定orbitcontrols是否可以与相机一起在同一轴上旋转对象 预先感谢

function init() {
            camera = new THREE.PerspectiveCamera( 150,window.innerWidth / window.innerHeight,0.1,1e10 );
            var last = false;
            var quaternion = new THREE.Quaternion;
            var axis = new THREE.Vector3( 0,1,0 );
            camera.position.set(0,-55,0);
            camera.zoom = 5;
            camera.useQuaternion = true;
            camera.aspect = window.innerWidth / window.innerHeight;
            scene = new THREE.Scene();
            scene.add( camera );
            
            scene.background = new THREE.Color( 0xffffff );
        
            var d = 500;
            var dirLight = new THREE.DirectionalLight( 0xffffff );
            dirLight.position.set( -120,-150,250 );
            dirLight.castShadow = true;
            dirLight.shadow.camera.top = -100;
            dirLight.shadow.camera.bottom = 700;
            dirLight.shadow.camera.left = -200;
            dirLight.shadow.camera.right = d;
            dirLight.shadow.camera.near = 0.5;
            dirLight.shadow.camera.far = 15000;
        
            
            dirLight.shadowCameravisible = true;
            dirLight.shadowDarkness = 0.5;

        scene.add( dirLight );
        
        var ambientLight = new THREE.AmbientLight(0xffffff,0.5);
        scene.add(ambientLight);
            
            
            var planeGeometry = new THREE.PlaneBufferGeometry(window.innerWidth,window.innerHeight);
            planeGeometry.rotateX(Math.PI/2);
            var planeMaterial = new THREE.ShadowMaterial();
            planeMaterial.opacity = 0.4;
            var plane = new THREE.Mesh( planeGeometry,planeMaterial );
           
            plane.receiveShadow = true;
            scene.add( plane );
                        
            loader = new VrmlLoader();
            mtlloader = new MTLLoader();
            $('.content-wrapper').removeClass('container');
            loadAsset();
            
            renderer = new THREE.Webglrenderer();
            renderer.shadowMap.enabled = true; 
            renderer.shadowMap.type = THREE.PCFSoftShadowMap; 
            renderer.shadowMapEnabled =  true; 
            renderer.setPixelRatio( window.devicePixelRatio );
            renderer.setSize(window.innerWidth * 0.5,window.innerHeight * 0.5);
            renderer.domElement.id = 'canvas';
            
            
            renderer.domElement.addEventListener( 'mousedown',event => {

                last = new THREE.Vector2( event.clientX,event.clientY );
                console.log(last);
                });

            renderer.domElement.addEventListener( 'mousemove',event => {

            if( last ){

                    let delta = event.clientX - last.x;

                    camera.position.applyQuaternion( quaternion.setFromAxisAngle(
                    axis,Math.PI * 2 * (delta / innerWidth)
                        ));
                    camera.lookAt( scene.position );

                    last.set( event.clientX,event.clientY );

                    }
                    renderer.render( scene,camera );

                });

                renderer.domElement.addEventListener( 'mouseup',event => {
            last = false;

            });
            
            controls = new OrbitControls( camera,renderer.domElement,);
                scene.add( controls );


            renderer.render( scene,camera );

            document.getElementById("character").appendChild(renderer.domElement);
                
            var gui = new GUI( { width: 300 } );
            
        }
        
        

        function loadAsset(  ) {
            loader.load( '../public/themes/storefront/public/files/naked_body.wrl',function ( object ) {
                
                    var objname = "main_body";
                    object.name=objname;
                    //var model;
                    object.children[0].castShadow = true;
                    //object.children[0].receiveShadow = true;
                    object.receiveShadow = true;
                    object.castShadow = true;
                   $('#head').attr("extname",objname);
                    vrmlScene = object;
                    scene.add( object );

            });
        }
    function onWindowResize() {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize( window.innerWidth,window.innerHeight );
        }

        function animate() {
            
            requestAnimationFrame( animate );
            controls.update();
            renderer.render( scene,camera );
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)