This is my first time experimenting with Three.js and Require js. I'm trying to load an Obj and Mtl file using the OBJMTLoader. I get timeout errors in 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' );
}
};
// var onError = function ( xhr ) {
// };
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 );
}
});
I used this generator for my three js experiment https://github.com/timmywil/generator-threejs
Try to rename your .obj file as .txt Try to load the file as .txt
'/obj/Shoes_Air_Jordans_4.txt'
EDIT:
You should also open it not in local. Threejs obj loader cannot load files in local. Use a software as hfs or load your html file on a domain
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.