【问题标题】:Rotating 3d object with texture issue旋转有纹理问题的 3d 对象
【发布时间】:2015-09-07 18:40:03
【问题描述】:

我在模仿http://threejs.org/examples/canvas_geometry_cube.html 通过使用带有纹理映射的 3d.obj 文件。

但我不断收到以下错误,而且旋转完全关闭。

未捕获的类型错误:无法读取未定义的属性“旋转”

完整的演示在这里http://wunderfauks.com/test/examples/test.html

【问题讨论】:

    标签: object 3d rotation three.js loader


    【解决方案1】:

    在为group 赋值的地方,加载代码尚未执行,obj 没有值。在加载函数中移动这 10 行代码。

    【讨论】:

    【解决方案2】:

    我已经完成了,如果有人需要知道您需要应用矩阵旋转。

    这是一个例子。

    function onWindowResize() {
    
        windowHalfX = window.innerWidth / 2;
        windowHalfY = window.innerHeight / 2;
    
        camera.aspect = window.innerWidth / window.innerHeight;
        camera.updateProjectionMatrix();
    
        renderer.setSize( window.innerWidth, window.innerHeight );
    }
    //
    function onDocumentMouseDown( event ) {
        event.preventDefault();
        document.addEventListener( 'mousemove', onDocumentMouseMove, false );
        document.addEventListener( 'mouseup', onDocumentMouseUp, false );
        document.addEventListener( 'mouseout', onDocumentMouseOut, false );
        mouseXOnMouseDown = event.clientX - windowHalfX;
        targetRotationOnMouseDown = targetRotation;
    }
    
    function onDocumentMouseMove( event ) {
        mouseX = event.clientX - windowHalfX;
        targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.02;
    }
    
    function onDocumentMouseUp( event ) {
        document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
        document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
        document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
    }
    
    function onDocumentMouseOut( event ) {
        document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
        document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
        document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
    }
    
    function onDocumentTouchStart( event ) {
        if ( event.touches.length === 1 ) {
            event.preventDefault();
            mouseXOnMouseDown = event.touches[ 0 ].pageX - windowHalfX;
            targetRotationOnMouseDown = targetRotation;
        }
    
    }
    
    function onDocumentTouchMove( event ) {
        if ( event.touches.length === 1 ) {
            event.preventDefault();
            mouseX = event.touches[ 0 ].pageX - windowHalfX;
            targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.05;
        }
    
    }
    
    function animate() {
        requestAnimationFrame( animate );
        render();
        stats.update();
    }
    
    function render() {
        //plane.rotation.y = group.rotation.y += ( targetRotation - group.rotation.y ) * 0.05;
    
        var rotation = new THREE.Matrix4().makeRotationY(Math.PI/2);
        var translation = new THREE.Matrix4().makeTranslation(0, 0, 0);
        rotation = group.rotation.y += (targetRotation - group.rotation.y);
        var transformation = new THREE.Matrix4().makeTranslation(0, 0, 0).makeRotationY(rotation * 0.01 * 0.3) ;
        group.applyMatrix(transformation);
        renderer.render( scene, camera );
    
    }
    

    【讨论】:

    • 您的render() 逻辑毫无意义。另外,您每秒实例化 3 x 60 = 180 Matrix4s。你需要能够解释每一行代码在做什么。
    猜你喜欢
    • 2013-04-02
    • 1970-01-01
    • 1970-01-01
    • 2012-06-26
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多