0
我正在关注“WebGL:启动和运行”一书。它使用Sim.js的第一个程序有点复杂,我很难识别每条指令的内容,而且我还没有找到任何可靠的Sim.js文档。所以我想写一个更简单的程序来了解它是如何工作的。Sim.js第一个程序:没有画在屏幕上
这个程序是从在第3章的代码,其中包括这两个文件“吸入”:
我试图编写一个基本上相同的程序,但构造一个没有纹理的简单球体。但可能有什么不对,因为屏幕上没有任何东西:我看到一个只有标题的空白页面。这是代码:
<!DOCTYPE html>
<html>
<head>
<title> Sim.js Test </title>
</head>
<body>
<h1 align="center"> Sim.js Test </h1>
<div id="container" width="400" height="400"> </div>
<script src="../Three.js-master/build/three.min.js"></script>
<script src= "../Sim.js-master/sim.js"> </script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="jquery.mousewheel.min.js"> </script>
<script type="text/javascript">
SphereApp= function() {
Sim.App.call(this);
}
SphereApp.prototype= new Sim.App();
SphereApp.prototype.init= function(param) {
Sim.App.prototype.init.call(this,param);
var sphere= new Sphere();
sphere.init();
this.addObject(sphere);
}
Sphere= function() {
Sim.Object.call(this);
}
Sphere.prototype= new Sim.Object();
Sphere.prototype.init = function() {
var object= new THREE.Mesh(new THREE.SphereGeometry(1,10,10), new THREE.MeshBasicMaterial({color:0xff0000}));
this.setObject3D(object);
}
Sphere.prototype.update= function() {
}
$(document).ready(function() {
var container= document.getElementById("container");
var app= new SphereApp();
app.init({container:container});
app.run();
});
</script>
</body>
</html>
您是否检查过浏览器控制台中的错误?你是否尝试过使用它来调试代码,或者添加'console.log()'消息来验证你的代码是否正在运行? – Pointy
没有控制台错误,我试图在$(document).ready之前添加一个alert函数,显示警告面板。 –