Hello Guys,
Here is my code for fbx loader,
<script src="js/jquery.js"></script>
<script src="js/three.js"></script>
<script src="js/libs/inflate.min.js" type="text/javascript"></script>
<script src="js/FBXLoader.js"></script>
<script src="js/orbitcontrols.js"></script>
< script >
var scene, camera, renderer,mesh, light,container,geometry,controls;
var mixers=[];
var clock = new THREE.Clock();
function init()
{
container = document.createElement( 'div' );
document.body.appendChild( container );
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.set(20,10,0);
camera.rotation.set(20,20,0);
// scene.position.set(20,10,0);
scene.rotation.set(20,0,0);
camera.position.set(0,30,0);
camera.up = new THREE.Vector3(0,0,1);
camera.lookAt(new THREE.Vector3(50,0,0));
scene.add(camera);
var gridHelper = new THREE.GridHelper( 200, 50);
scene.add( gridHelper );
var manager = new THREE.LoadingManager();
manager.onProgress = function( item, loaded, total ) {
console.log( item, loaded, total );
};
var loader = new THREE.FBXLoader( manager );
loader.load( 'model/DigestiveAnimation.fbx', function( object ) {
object.position.set(0,0,0);
scene.add(object);
}, onProgress, onError );
renderer = new THREE.WebGLRenderer();
if ( !renderer.extensions.get( 'WEBGL_depth_texture' ) ) { console.log("Your browser does not support WEBGL_depth_texture, Try Different Browser !!"); }
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.target.set( 0, 12, 0 );
controls.enableKeys=false;
controls.update();
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);
animate();
}
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 );
};
function animate() {
requestAnimationFrame( animate );
/* if ( mixers.length > 0 ) {
for ( var i = 0; i < mixers.length; i ++ ) {
mixers[ i ].update( clock.getDelta() );
}
}*/
render();
}
function render() {
renderer.render( scene, camera );
}
jQuery(document).ready(function(){
init();
});
< /script >
Issue is whenever I am create cube or circle it is set center in screen.
but my fbx model is not set center is screen.
I have added gridhelper to identify issue and set correct position but i found that
my model is in air when loaded in scene. means there is vertical distance between object and grid helper. I have try to set it in center positioning.
but such i have to set every time position for each model. that is not feasible, I want to make function which set object in center. no matter which object is called.
Regards,