[英]Three.js error with require
這是我第一次嘗試Three.js和Require js。 我正在嘗試使用OBJMTLoader加載Obj和Mtl文件。 我的當前設置在控制台中出現超時錯誤:
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 );
}
});
我將這個生成器用於我的三個js實驗https://github.com/timmywil/generator-threejs
嘗試將.obj文件重命名為.txt嘗試將文件加載為.txt
'/obj/Shoes_Air_Jordans_4.txt'
編輯:
您還應該不在本地打開它。 Threejs obj loader無法在本地加載文件。 使用軟件作為hfs或將您的html文件加載到域中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.