I have a gltf model in my scene that I want to rotate(in a specific direction) whenever there is inactivity for a certain amount of time. I’ve been researching this for a while and I only find help when the object is a cube and not an actual gltf file. Here is my code
var scene = new THREE.Scene();
// Load Camera Perspektive
var camera = new THREE.PerspectiveCamera( 100, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.set( 1, 1, 150 );//the position of the object x,y,z
// Load a Renderer
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
window.addEventListener('resize', function(){
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
})
// Load the Orbitcontroller
var controls = new THREE.OrbitControls( camera, renderer.domElement );
// Load Light
var ambientLight = new THREE.AmbientLight( 0x404040 );//provides light to an object
scene.add( ambientLight );
var directionalLight = new THREE.DirectionalLight( 0xffffff );//like the sun, light in specific direction
directionalLight.position.set( 0, 1, 1 ).normalize();
scene.add( directionalLight );
var loader = new THREE.GLTFLoader();
loader.load(
// resource URL
'models/gltf/head/glTF/scene.gltf',
// called when the resource is loaded
function ( gltf ) {
scene.add( gltf.scene );
},
// called when loading is in progresses
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
function animate(){
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();