javascript - Loop Rotation on any axis for a 3D obj Three js -


i trying make imported 3d object rotate continuously on axis classic cube, sphere etc.. don't work, not moving @ , don't understand why. here code:

var scene6, camera6, renderer6, light, shipmtl, shipobj;  function init() {     scene6 = new three.scene();     camera6 = new three.perspectivecamera(35, 1, 1, 1000);     camera6.position.z = 400;      //lights     light = new three.pointlight(0xffffff, 2, 0);     light.position.set(200, 100, 300);     scene6.add(light);       //3d model     shipmtl = new three.mtlloader();     shipmtl.load('../models/spacecraft1.mtl', function(materials) {         materials.preload();         shipobj = new three.objloader();         shipobj.setmaterials(materials);         shipobj.load('../models/spacecraft1.obj', function(object) {             object.scale.set(10, 10, 10);             object.rotation.x += .01;             scene6.add(object);         });     });      renderer6 = new three.webglrenderer({ canvas: document.getelementbyid('model'), antialias: true });     renderer6.setclearcolor(0x000000);     renderer6.setpixelratio(window.devicepixelratio);      animate6(); }  function animate6() {      requestanimationframe(animate6);     renderer6.render(scene6, camera6);  }  window.onload = init; 

thank help.

the rotation of object changed once : when model loaded.

if want continuously rotate it, need update rotation every frame. therefore, should move object.rotation.x += 0.01 line inside animate() function.

var scene6, camera6, renderer6, light, shipmtl, shipobj; var obj; // global reference model, once loaded  function init() {     scene6 = new three.scene();     camera6 = new three.perspectivecamera(35, 1, 1, 1000);     camera6.position.z = 400;      //lights     light = new three.pointlight(0xffffff, 2, 0);     light.position.set(200, 100, 300);     scene6.add(light);      //3d model     shipmtl = new three.mtlloader();     shipmtl.load('../models/spacecraft1.mtl', function(materials) {         materials.preload();         shipobj = new three.objloader();         shipobj.setmaterials(materials);         shipobj.load('../models/spacecraft1.obj', function(object) {             object.scale.set(10, 10, 10);             // no need change rotation here             obj = object; // put object global             scene6.add(object);         });     });      renderer6 = new three.webglrenderer({ canvas: document.getelementbyid('model'), antialias: true });     renderer6.setclearcolor(0x000000);     renderer6.setpixelratio(window.devicepixelratio);      animate6(); }  function animate6() {     requestanimationframe(animate6);      obj.rotation.x += 0.01;      renderer6.render(scene6, camera6); }  window.onload = init; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -