只是看不到导入到three.js场景中的模型。几何体看起来很好,但无论我应用什么材质,模型都不会显示。
我刚接触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 );
}
发布于 2012-12-01 10:11:49
在模型完成加载之前将网格添加到场景中。
移动线条
scene.add( mesh );
传入加载器回调函数。
发布于 2014-03-17 06:01:59
我认为这可能会帮助任何寻找更准确答案的人:
loader.onLoadComplete=function(){scene.add( mesh )}
此外,有关完整的加载器参考,请参阅此处:
https://threejs.org/docs/index.html#api/loaders/Loader
希望这能有所帮助。
发布于 2017-10-15 07:30:03
animate()
也应该在回调函数中,以删除控制台错误。
https://stackoverflow.com/questions/13655092
复制相似问题