After attempting to load a glTF model with a 0,0,0
position, I noticed that it appears far from the origin.
Upon trying to rotate the glTF model, I observed that it spins around (indicated by blue dots) the origin instead of spinning from its center.
This seems to be related to a pivot issue. How can this be resolved?
var tree;
function loadGLTFCharacter(path, position){
// Load a glTF resource
loader.load(
// resource URL
path,
// called when the resource is loaded
function ( gltf ) {
gltf.scene.traverse( function( node ) {
if ( node.isMesh ) {
node.castShadow = true;
node.receiveShadow = true;
}
} );
gltf.scene.position.set(position.x, position.y, position.z);
tree = gltf.scene;
scene.add( tree );
gltf.animations; // Array<THREE.AnimationClip>
gltf.scene; // THREE.Group
gltf.scenes; // Array<THREE.Group>
gltf.cameras; // Array<THREE.Camera>
gltf.asset; // Object
},
// called while loading is progressing
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
}
loadGLTFCharacter('models/characters/tree_detailed.gltf', {x:0,y:0.2,z:0});