i am working on loading an external .GLTF model from https://sketchfab.com/3d-models/samsung-ativ-book-9-5e5725666200416cbf650ddce1f84eb4 . I validated this model at https://gltf-viewer.donmccurdy.com/ and the model works if i drag the whole folder. I tried exporting this model in three.js and i dont see anything rendered. I went through a couple of old posts about loading GLTF models and noticed an advice about making sure textures and models are in the same folder. In my case, i have my textures in different folder, would this be a problem? I tried making sure all the jpeg, bin and gltf files are in the same folder but i dont see anything rendering. My understanding is that .gltf file exported has the path to textures folder and will continue picking up the textures from this folder. Is there a different way to add textures for these models ?
Pasting my code for reference
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(5, window.innerWidth/window.innerHeight, 0.1, 5000 );
camera.position.z = 3;
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor('white');
document.body.appendChild( renderer.domElement );
window.addEventListener('resize', ()=>{
renderer.setSize( window.innerWidth, window.innerHeight );
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectMatrix();
})
var controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.25;
controls.enableZoom = true;
var ambient = new THREE.AmbientLight(0xffffff, 0.4);
scene.add(ambient);
var keyLight = new THREE.DirectionalLight(0xffffff, 2.5);
keyLight.position.set(-100, 0, 100);
var fillLight = new THREE.DirectionalLight(0xffffff, 2.5);
fillLight.position.set(100, 0, 100);
var backLight = new THREE.DirectionalLight(0xffffff, 1.0);
backLight.position.set(100, 0, -100).normalize();
var loader = new THREE.GLTFLoader();
loader.load('/examples/3d-obj-loader/assets//samsung_ativ_book_9/scene.gltf', function ( gltf ) {
var model = gltf.scene
scene.add( model );
}, undefined, function ( error ) {
console.error( error );
} );
var animate = function () {
requestAnimationFrame( animate );
controls.update();
renderer.render(scene, camera);
};
animate();