我正在查看一个较旧的问题,该代码已修复此代码:
但由于某种原因它不起作用。是否有任何可用的JSON文件可以确保我可以测试?
我尝试使用three.js编辑器(ship.js)导出的船的json,它似乎没有显示任何东西 - 实际上,它不会“击中”我设置的警报,表示问题可能是json文件的加载问题?
<html>
<head></head>
<body>
<script src="three.min.js"></script>
<script>
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( "ship.js", function( geometry ) {
//var geometry = new THREE.CubeGeometry(5,10,5);
mesh = new THREE.Mesh( geometry, new THREE.MeshNormalMaterial() );
mesh.scale.set( 10, 10, 10 );
mesh.position.y = 0;
mesh.position.x = 0;
scene.add( mesh );
alert("hit");
} );
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;
mesh.rotation.y += 0.05;
renderer.render( scene, camera );
}
</script>
</body>
</html>