Object3D Axis Rotation

object3d

#1

Hello I am new in this 3d developement,

I have tried and create a code using some example,

My Code is as below

<html>
	<head>
	<meta charset="UTF-8">
	<title>3d Model Player</title>
	<script src="js/jquery.js" type="text/javascript"></script>
	<script src="js/three.js" type="text/javascript"></script>
	<script src="js/libs/inflate.min.js" type="text/javascript"></script>
	<script src="js/FBXLoader.js"></script>
	<script src="js/stats.min.js"></script>
	<script src="js/OrbitControls.js"></script>

	<style>
	.modelbox{background:#efefef; display:block; width:1000px; height:500px;}
	</style>
	</head>
	<body>
	<script>



var container, stats, controls;
var camera, scene, renderer, light;
var clock = new THREE.Clock();
var object1;
var center=null;
var boundingBox = new THREE.Box3();
var axisHelper = new THREE.AxisHelper(100);

var mixers = [];
init();
function init() {
  container = document.createElement( 'div' );
  document.body.appendChild( container );
  camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
  scene = new THREE.Scene();
  stats = new Stats();
  container.appendChild( stats.dom );
  var manager = new THREE.LoadingManager();
  manager.onProgress = function( item, loaded, total ) {
    console.log( item, loaded, total );
  };
  var onProgress = function( xhr ) {
    if ( xhr.lengthComputable ) {
      var percentComplete = xhr.loaded / xhr.total * 100;
      console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
    }
  };
  var onError = function( xhr ) {
    console.error( xhr );
  };
  var loader = new THREE.FBXLoader( manager );

  
  loader.load( 'model/DigestiveAnimation.fbx', function( object ) {
    object.mixer = new THREE.AnimationMixer( object );
    mixers.push( object.mixer );
    var action = object.mixer.clipAction( object.animations[ 0 ] );
    action.play();


		boundingBox.setFromObject( object );

	//object1 = new THREE.Box3().setFromObject(object);
    scene.add( object );

  }, onProgress, onError );
  
setTimeout(function(){
  var bbox = new THREE.Box3().setFromObject(scene);
  center = bbox.getCenter();
  var size = bbox.getSize();

   // update some controls properties
  
  controls.target.set(center.x, center.y, center.z);
   // position the camera  on the y axis
  camera.position.set(center.x, center.y - size.y, center.z);
  
  // fit FOV
  var dist = size.y / 2;
  var fov = 2 * Math.atan( size.z / ( 2 * dist ) ) * ( 180 / Math.PI );
  
  camera.fov = fov;
  
  camera.updateProjectionMatrix();
  controls.update();
}, 2000);

  renderer = new THREE.WebGLRenderer(  );

  if ( !renderer.extensions.get( 'WEBGL_depth_texture' ) ) {
	  alert("Your browser does not support WEBGL_depth_texture, Try Different Browser !!");
  }
  renderer.setPixelRatio( window.devicePixelRatio );
  renderer.setSize( window.innerWidth, window.innerHeight );
  renderer.setClearColor( 0x000000 );
  container.appendChild( renderer.domElement );
  // controls, camera
  controls = new THREE.OrbitControls( camera, renderer.domElement );
  controls.target.set( 0, 12, 0 );
  controls.enableKeys=false;
/*   controls.addEventListener('change', function() {
	//	var center = boundingBox.getCenter();
	//	controls.target = center;
	   render();
    });*/
  controls.update();
  window.addEventListener( 'resize', onWindowResize, false );
  light = new THREE.HemisphereLight(0xffffff, 0x444444, 1.0);
  light.position.set(0, 1, 0);
  scene.add(light);
  light = new THREE.DirectionalLight(0xffffff, 1.0);
  light.position.set(0, 1, 0);
  scene.add(light);
  scene.add(axisHelper);
  animate();
}
function onWindowResize() {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
  controls.update();
  renderer.setSize( window.innerWidth, window.innerHeight );
}
//
function animate() {
  requestAnimationFrame( animate );
  if ( mixers.length > 0 ) {
    for ( var i = 0; i < mixers.length; i ++ ) {
      mixers[ i ].update( clock.getDelta() );
    }
  }

  stats.update();
  render();
}
function render() {
  renderer.render( scene, camera );
}

</script>
	</body>
</html>

Can anybody guide me how to rotate model its axis after pan to lef -right, top-bottom,

Current it is rotation on first set position only, i want to update that axis on demand when pan model.

Thanks in advance.


#2

You can use the following methods to rotate an object around X, Y or Z axis.

.rotateX(), .rotateY(), .rotateZ()

It’s also possible to define an arbitrary axis and perform the rotation around it via .rotateOnAxis().

Example: https://jsfiddle.net/f2Lommf5/728/


#3

Thanks for reply,

Check jsfiddle but my requirement is that I must be able to pan the object left-right top-bottom and also can be rotate via mouse not auto.

can you have any guidance for this requirement ?


#4

@AmitTank That’s why it’s better to have separated logics for panning and rotating, and not rely on a single instance of controls.


#5

Before you start developing your own custom control from scratch, i suggest that you have a closer look to the predefined controls of three.js. The editor uses EditorControls and TransformControls in order to implement 3D editing.

These examples might be also interesting for you.


#6

Thanks @Mugen87 and @prisoner849, For your Kind Support.

Now will try controls myself