forked from xeolabs/xeogl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera_flight.html
175 lines (134 loc) · 5.03 KB
/
camera_flight.html
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE html>
<html lang="en">
<head>
<title>xeogl Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<script src="../build/xeogl.js"></script>
<link href="css/styles.css" rel="stylesheet"/>
<script src="js/libs/dat.gui.min.js"></script>
<body>
<div id="info">
<h1><a href="../docs/classes/CameraFlightAnimation.html" target="_parent">CameraFlightAnimation</a> - flying or
jumping to
random targets</h1>
</div>
<div id="dat-gui-container">
</div>
<script>
//------------------------------------------------------------------
// Create some random meshes
//------------------------------------------------------------------
var numMeshes = 400;
var meshes = [];
var mesh;
var cylinder = new xeogl.CylinderGeometry();
var material = new xeogl.PhongMaterial({
diffuseMap: new xeogl.Texture({
src: "textures/diffuse/uvGrid2.jpg"
})
});
for (var i = 0; i < numMeshes; i++) {
var s = Math.random() * 5;
mesh = new xeogl.Mesh({
geometry: cylinder,
material: material,
scale: [2, 1 + Math.random() * 3, 2],
rotation: [Math.random() * 360, Math.random() * 360, Math.random() * 360],
position: [Math.random() * 100 - 50, Math.random() * 100 - 50, Math.random() * 100 - 50]
});
meshes.push(mesh)
}
//------------------------------------------------------------------
// Periodically fly or jump to next target
//------------------------------------------------------------------
var targetType = "mesh";
var fly = true;
var duration = 2.0;
var fit = true;
var fitFOV = 45;
var spin = true;
var cameraFlight = new xeogl.CameraFlightAnimation();
function next() {
xeogl.scheduleTask(function () {
cameraFlight.duration = duration;
cameraFlight.fit = fit;
cameraFlight.fitFOV = fitFOV;
mesh = meshes[Math.floor(Math.random() * numMeshes)];
if (fly) {
switch (targetType) {
case "mesh":
cameraFlight.flyTo(mesh); // Not using completion callback - using timeout below
break;
case "mesh.aabb":
cameraFlight.flyTo(mesh.aabb); // Not using completion callback - using timeout below
break;
}
} else {
switch (targetType) {
case "mesh":
cameraFlight.jumpTo(mesh);
break;
case "mesh.aabb":
cameraFlight.jumpTo(mesh.aabb);
break;
}
}
setTimeout(next, (duration + 1) * 1500);
});
}
next();
//------------------------------------------------------------------
// Slowly the eye position about the look position.
//------------------------------------------------------------------
mesh.scene.on("tick", function () {
if (spin) {
var camera = mesh.scene.camera;
camera.orbitYaw(0.1);
camera.orbitPitch(0.07);
}
});
//------------------------------------------------------------------
// Allow camera interaction, if permitted by CameraFlightAnimation
//------------------------------------------------------------------
new xeogl.CameraControl();
//------------------------------------------------------------------
// GUI
//------------------------------------------------------------------
var Menu = function () {
this.message = "xeogl.CameraFlightAnimation";
this["projection"] = mesh.scene.camera.projection;
this["target"] = targetType;
this["fly"] = fly;
this["duration"] = duration;
this["fit"] = fit;
this["fitFOV"] = fitFOV;
this["spin"] = spin;
var self = this;
var update = function () {
mesh.scene.camera.projection = self["projection"];
targetType = self["target"];
fly = !!self["fly"];
duration = self["duration"];
fit = !!self["fit"];
fitFOV = self["fitFOV"];
spin = self["spin"];
requestAnimationFrame(update);
};
update();
};
var gui = new dat.GUI({autoPlace: false});
document.getElementById('dat-gui-container').appendChild(gui.domElement);
var menu = new Menu();
var folder = gui.addFolder('xeogl.CameraFlightAnimation');
folder.add(menu, 'projection', ["perspective", "ortho", "frustum"]);
folder.add(menu, 'target', ["mesh", "mesh.aabb"]);
folder.add(menu, 'fly', fly);
folder.add(menu, 'duration', 0.1, 10.0);
folder.add(menu, 'fit', fit);
folder.add(menu, 'fitFOV', 5, 160);
folder.add(menu, 'spin', spin);
folder.open();
</script>
</body>
</html>