[英]Rotating 3d object with texture issue
I'm trying to imitate http://threejs.org/examples/canvas_geometry_cube.html via using a 3d.obj file with a texture mapping. 我试图通过使用带有纹理映射的3d.obj文件来模仿http://threejs.org/examples/canvas_geometry_cube.html 。
But i keep receiving the following error plus the rotation is totally off. 但是我一直收到以下错误,而且旋转完全关闭。
Uncaught TypeError: Cannot read property 'rotation' of undefined 未捕获的TypeError:无法读取未定义的属性“旋转”
Full demo is here http://wunderfauks.com/test/examples/test.html 完整的演示在这里http://wunderfauks.com/test/examples/test.html
Where you assign the value for group
the code for loading has not executed yet and obj
does not have a value. 在为group
分配值的地方,尚未执行要加载的代码,并且obj
没有值。 Move those 10 lines of code inside your loading function. 将这10行代码移到加载函数中。
I've done it, if anyone needs to know you need to apply a matrix rotation. 我已经做到了,如果有人需要知道您需要应用矩阵旋转。
Here's an example. 这是一个例子。
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 );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.