使用three.js JSONLoader
只是看不到导入到three.js场景中的模型。 几何体看起来很好,但无论应用何种材质,模型都不会显示 我是WebGL新手,所以很难诊断,但我猜在JSONLoader回调过程中出现了一些问题 谢谢你的帮助使用three.js JSONLoader,json,import,three.js,loader,Json,Import,Three.js,Loader,只是看不到导入到three.js场景中的模型。 几何体看起来很好,但无论应用何种材质,模型都不会显示 我是WebGL新手,所以很难诊断,但我猜在JSONLoader回调过程中出现了一些问题 谢谢你的帮助 var camera, scene, renderer, mesh, loader; init(); animate(); function init() { camera = new THREE.PerspectiveCamera( 75, window.innerWidth /
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 );
进入加载器回调函数。认为这可能有助于搜索更准确答案的任何人:
loader.onLoadComplete=function(){scene.add( mesh )}
此外,有关完整的加载器参考,请参阅此处:
希望这能有所帮助。
animate()
也应该在回调函数中,以删除控制台错误。我知道它必须如此简单。感谢您花时间查看我的代码GitHub上的模型链接已断开-您能将其更新为新URL吗?模型js链接已断开