I am delving into the world of Three.js and Require.js for the first time. My objective is to load an Obj and Mtl file using the OBJMTLoader. However, I have encountered timeout errors in the console with my current setup:
require({
baseUrl: 'js',
// three.js should have UMD support soon, but it currently does not
shim: {
'vendor/three': { exports: 'THREE' },
'vendor/MTLLoader': { exports: 'MTLLoader'},
'vendor/OBJMTLLoader': { deps: ['MTLLoader'], exports: 'OBJMTLLoader'}
}
}, [
'vendor/three',
'vendor/MTLLoader',
'vendor/OBJMTLLoader'
], function(THREE, OBJMTLLoader) {
var scene, camera, renderer;
var geometry, material, mesh;
init();
animate();
function init() {
scene = new THREE.Scene();
var WIDTH = window.innerWidth,
HEIGHT = window.innerHeight;
camera = new THREE.PerspectiveCamera(75, WIDTH / HEIGHT, 1, 20000);
camera.position.set(0,6,1000);
scene.add(camera);
window.addEventListener('resize', function() {
var WIDTH = window.innerWidth,
HEIGHT = window.innerHeight;
renderer.setSize(WIDTH, HEIGHT);
camera.aspect = WIDTH / HEIGHT;
camera.updateProjectionMatrix();
});
var light = new THREE.PointLight(0xffffff);
light.position.set(-100,200,100);
scene.add(light);
var onProgress = function ( xhr ) {
if ( xhr.lengthComputable ) {
var percentComplete = xhr.loaded / xhr.total * 100;
console.log( Math.round(percentComplete, 2) + '% downloaded' );
}
};
loader = new THREE.OBJMTLLoader();
loader.load( '/obj/Shoes_Air_Jordans_4.obj', '/obj/Shoes_Air_Jordans_4.mtl', function ( object ) {
object.position.y = - 80;
scene.add( object );
}, onProgress );
geometry = new THREE.BoxGeometry( 200, 200, 200 );
material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.WebGLRenderer({alpha:true});
renderer.setSize( WIDTH, HEIGHT );
renderer.setClearColor(0x333F47, 1);
document.body.appendChild( renderer.domElement );
}
function animate() {
requestAnimationFrame( animate );
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
renderer.render( scene, camera );
}
});
For this experiment with three.js, I used the following generator: https://github.com/timmywil/generator-threejs