<head>
<title> SceneJS Test</title>
<script type="text/javascript" src="resources/scenejs.js"></script>
</head>
我想使用 SceneJS 在画布场景上随机分布立方体。由于这个库有很大的学习曲线,我自己检查了几个例子并开始编码。我做了一些代码,无法说服自己错误在哪里:
<body onload = "main()" bgcolor="white">
<canvas id="theCanvas" width="720" height="405">
</canvas>
<script type="text/javascript">
main = function({
N = 10;
var canvas = document.getElementById("theCanvas");
var sceneName = "theScene";
SceneJS.createScene({
id: sceneName,
canvasId: canvas,
nodes: [{
type:"library",
id:"mylib",
nodes:[]
},
// Viewing transform specifies eye position, looking at the origin by default
{
id:"lookat",
type: "lookAt",
eye : { x: 0.0, y: 1.0, z: 80.0 },
up : { z: 1.0 },
look:{x:0,y:0,z:0},
nodes: [
/* Camera describes the projection*/
{
type: "camera",
optics: {
type: "perspective",
fovy : 45.0,
aspect : 720/405,
near : 0.10,
far : 10000.0
},
nodes: [
{
type: "rotate",
id: "pitch",
angle: 0.0,
x : 1.0,
nodes: [
{
type: "rotate",
id: "yaw",
angle: 0.0,
y : 1.0,
}
]
}
]
}
]
}
]
});
var scale = 100;
var scene = SceneJS.scene(sceneName);
for(var i=0; i<N; i++)
{
scene.add("node",{
type:"translate",
x:(Math.random()-0.5)* scale,
y:(Math.random()-0.5)* scale,
z:(Math.random()-0.5)* scale,
nodes:[{
type: "cube",
id: "cube"+i
}]
});
}
});
</script>
</body>
我请求有人指出我的错误在哪里,我会非常感谢你。我只能在浏览器中看到空白屏幕:(