只是看不到导入到 three.js 场景中的模型。 几何图形看起来不错,但无论我应用什么 Material ,模型都不会显示。
我是 WebGL 的新手,所以我很难诊断,但我猜是 JSONLoader 回调期间出了点问题。
感谢大家的帮助。
var camera, scene, renderer, mesh, loader;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 1000;
scene = new THREE.Scene();
loader = new THREE.JSONLoader();
loader.load( "scripts/model.js", function( geometry ) {
mesh = new THREE.Mesh( geometry, new THREE.MeshNormalMaterial() );
mesh.scale.set( 10, 10, 10 );
mesh.position.y = 150;
mesh.position.x = 0;
} );
scene.add( mesh );
var ambientLight = new THREE.AmbientLight(0x555555);
scene.add(ambientLight);
var directionalLight = new THREE.DirectionalLight(0xffffff);
directionalLight.position.set(1, 1, 1).normalize();
scene.add(directionalLight);
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
requestAnimationFrame( animate );
mesh.rotation.x += 0.05;
renderer.render( scene, camera );
}
最佳答案
您在模型完成加载之前将网格添加到场景中。
移动线
scene.add( mesh );
进入加载器回调函数。
关于json - 使用three.js JSONLoader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13655092/