以下の私のコード。コメントを外し
object.rotation.y += ( targetRotation - object.rotation.y ) * 0.05;
たりrender()
機能animate()
したりすると、"Uncaught ReferenceError: object is not defined "
エラーが発生します。
私は何でも試しました、私のanimate()
関数はローダーコールバックにもあります、three.jsを古いバージョンに変更しようとしました(現在r59を使用しています)、varobject = event.content;
がそれを解決することを望みましたが、効果はありません.
「クリックしてマウスを動かしてモデルを回転させる」という使いやすさを追加したいのですが、立方体の場合は問題ありません。
しかし、それは私の *obj では機能しません。
ヘルプ?=)
var scene, camera, renderer, loader, ambient, directionalLight;
var windowHalfX = 300;
var windowHalfY = 145;
var targetRotation = 0;
var targetRotationOnMouseDown = 0;
var mouseX = 0;
var mouseXOnMouseDown = 0;
init();
function init() {
container = document.createElement( 'div' );
document.getElementById("3dbox").appendChild(container);
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 45, 600 / 290, 0.1, 1000 );
//camera.position.set( -15, 10, 15 );
renderer = new THREE.WebGLRenderer();
renderer.setSize( 600, 290 );
container.appendChild( renderer.domElement );
// MODEL
var loader = new THREE.OBJMTLLoader();
loader.addEventListener( 'load', function ( event ) {
var object = event.content;
scene.add( object );
animate();
});
loader.load( '<?php bloginfo('template_directory'); ?>/obj/female02.obj', '<?php bloginfo('template_directory'); ?>/obj/female02.mtl' );
camera.position.z = 100;
camera.position.y = 10;
ambient = new THREE.AmbientLight( 0x101030 );
scene.add( ambient );
directionalLight = new THREE.DirectionalLight( 0xffeedd );
directionalLight.position.set( 0, 0, 1 );
scene.add( directionalLight );
document.addEventListener( 'mousedown', onDocumentMouseDown, false );
document.addEventListener( 'touchstart', onDocumentTouchStart, false );
document.addEventListener( 'touchmove', onDocumentTouchMove, false );
}
function render() {
//object.rotation.y += ( targetRotation - object.rotation.y ) * 0.05;
renderer.render(scene, camera);
}
function animate() {
//object.rotation.y += ( targetRotation - object.rotation.y ) * 0.05;
requestAnimationFrame( animate );
render();
}
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;
}
}