我正在尝试加载 JSON 模型并将其显示在画布上。但是屏幕上没有绘制任何内容。我试图在loader.load
回调中放置警报,但从未显示警报:从未调用回调。我想知道 JSON 文件是否有问题,我从这里下载了它:https ://livingvindonissa.googlecode.com/svn-history/r42/trunk/livingvindonissa/src/model/test/Teapot.json
这是代码:
<head>
<title> Teapot </title>
<style>
canvas {width:100%; height:100%; background-color: black}
body {background-color: white};
</style>
</head>
<body>
<h1 align="center"> Teapot </h1>
<script src="/Users/ramy/Documents/HTML/mrdoob-three.js-58e4622/build/three.min.js"></script>
<script type="text/javascript">
// Scene initialization
var scene= new THREE.Scene();
var camera= new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,0.1,1000);
var renderer= new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth,window.innerHeight);
document.body.appendChild(renderer.domElement);
camera.position.z= 50;
// Teapot creation
var teapot;
var loader= new THREE.JSONLoader();
loader.load("/Users/ramy/Documents/HTML/teapot.json",
function(geometry) {
var material= new THREE.MeshBasicMaterial({color:0x00ff00});
teapot= new THREE.Mesh(geometry,material);
scene.add(teapot);
render();
});
// Rendering
var render= function() {
requestAnimationFrame(render);
renderer.render(scene,camera);
}
</script>
</body>
</html>