Repository navigation
Expand file tree
/
Copy pathscene.html
More file actions
83 lines (73 loc) · 2.18 KB
/
Copy pathscene.html
File metadata and controls
83 lines (73 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE HTML>
<head>
<script src="../css3d.js"></script>
<style>
</style>
</head>
<body>
<img id="mouse" src="images/mouse.jpg"/>
<script>
//创建场景
var s = new C3D.Stage();
s.size(window.innerWidth, window.innerHeight).material({
color: "#cccccc"
}).update();
document.body.appendChild(s.el);
//创建场景
var scene = C3D.create({
type: 'sprite', position: [0, 0, -s.fov], children: [
{
type: 'plane',
el: document.getElementById('mouse'),
name: 'p1',
size: [100],
position: [100, 0, 0],
rotation: [45, 0, 0],
material: [{color: C3D.getRandomColor()}]
},
{
type: 'plane',
name: 'p2',
size: [100],
position: [-100, 0, 0],
rotation: [-45, 0, 0],
material: [{color: C3D.getRandomColor()}]
},
{
type: 'plane',
name: 'p3',
size: [100],
position: [0, 100, 0],
rotation: [0, 45, 0],
material: [{color: C3D.getRandomColor()}]
},
{
type: 'plane',
name: 'p4',
size: [100],
position: [0, -100, 0],
rotation: [0, -45, 0],
material: [{color: C3D.getRandomColor()}]
},
]
});
s.addChild(scene);
//响应屏幕调整尺寸
function resize() {
s.size(window.innerWidth, window.innerHeight).update();
// scene.position(0, 0, -s.fov).updateT();
}
window.onresize = function () {
resize();
};
resize();
//刷新场景
requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame;
function go() {
scene.rotate(0, 1, 0).updateT();
scene.p3.rotate(-1, 0, 0).updateT();
requestAnimationFrame(go);
}
requestAnimationFrame(go);
</script>
</body>