scenejs_on_rails 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/app/controllers/scenejs_controller.rb +53 -0
  4. data/app/views/scenejs/get_scenejs_data.html.erb +3 -0
  5. data/lib/scenejs_on_rails.rb +1 -1
  6. data/lib/scenejs_on_rails/rails.rb +5 -0
  7. data/lib/scenejs_on_rails/version.rb +1 -1
  8. data/vendor/assets/javascripts/scenejs.js +17307 -0
  9. data/vendor/assets/javascripts/scenejs_extras/gui.js +478 -0
  10. data/vendor/assets/javascripts/scenejs_extras/gui/README.md +4 -0
  11. data/vendor/assets/javascripts/scenejs_extras/gui/dat.gui.min.js +94 -0
  12. data/vendor/assets/javascripts/scenejs_extras/gui/gui.js +385 -0
  13. data/vendor/assets/javascripts/scenejs_lib/cityBuilder.js +457 -0
  14. data/vendor/assets/javascripts/scenejs_lib/dat.gui.min.js +94 -0
  15. data/vendor/assets/javascripts/scenejs_lib/gl-matrix-min.js +28 -0
  16. data/vendor/assets/javascripts/scenejs_lib/gl-matrix.js +4078 -0
  17. data/vendor/assets/javascripts/scenejs_lib/require.js +36 -0
  18. data/vendor/assets/javascripts/scenejs_lib/requireConfig.js +18 -0
  19. data/vendor/assets/javascripts/scenejs_lib/requireWrapperEnd.js +1 -0
  20. data/vendor/assets/javascripts/scenejs_lib/requireWrapperStart.js +2 -0
  21. data/vendor/assets/javascripts/scenejs_lib/stats.min.js +6 -0
  22. data/vendor/assets/javascripts/scenejs_lib/sylvester.js +1 -0
  23. data/vendor/assets/javascripts/scenejs_lib/webgl-debug-utils.js +839 -0
  24. data/vendor/assets/javascripts/scenejs_plugins/geometry/boundary.js +59 -0
  25. data/vendor/assets/javascripts/scenejs_plugins/geometry/box.js +72 -0
  26. data/vendor/assets/javascripts/scenejs_plugins/geometry/plane.js +126 -0
  27. data/vendor/assets/javascripts/scenejs_plugins/geometry/quad.js +37 -0
  28. data/vendor/assets/javascripts/scenejs_plugins/geometry/skybox.js +86 -0
  29. data/vendor/assets/javascripts/scenejs_plugins/geometry/sphere.js +82 -0
  30. data/vendor/assets/javascripts/scenejs_plugins/geometry/teapot.js +5853 -0
  31. data/vendor/assets/javascripts/scenejs_plugins/geometry/torus.js +139 -0
  32. data/vendor/assets/javascripts/scenejs_plugins/geometry/vectorText.js +1499 -0
  33. data/vendor/assets/javascripts/scenejs_plugins/geometry/wobblyBox.js +44 -0
  34. data/vendor/assets/javascripts/scenejs_plugins/lib/canvas2image.js +198 -0
  35. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullEngine.js +810 -0
  36. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullSystem.js +185 -0
  37. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullSystemPool.js +174 -0
  38. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullWorker.js +142 -0
  39. data/vendor/assets/javascripts/scenejs_plugins/lib/gl-matrix-min.js +28 -0
  40. data/vendor/assets/javascripts/scenejs_plugins/lib/jquery-1.8.3.min.js +2 -0
  41. data/vendor/assets/javascripts/scenejs_plugins/lib/k3d.js +1029 -0
  42. data/vendor/assets/javascripts/scenejs_plugins/lib/physics/jiglib.all.min.js +3 -0
  43. data/vendor/assets/javascripts/scenejs_plugins/lib/physics/physics.js +223 -0
  44. data/vendor/assets/javascripts/scenejs_plugins/lib/physics/worker.js +330 -0
  45. data/vendor/assets/javascripts/scenejs_plugins/node/alpha/orbitTracking.js +295 -0
  46. data/vendor/assets/javascripts/scenejs_plugins/node/alpha/orbitTrackingTarget.js +43 -0
  47. data/vendor/assets/javascripts/scenejs_plugins/node/backgrounds/gradient.js +148 -0
  48. data/vendor/assets/javascripts/scenejs_plugins/node/cameras/orbit.js +172 -0
  49. data/vendor/assets/javascripts/scenejs_plugins/node/cameras/pickFlyOrbit.js +409 -0
  50. data/vendor/assets/javascripts/scenejs_plugins/node/canvas/capture.js +107 -0
  51. data/vendor/assets/javascripts/scenejs_plugins/node/demos/color.js +30 -0
  52. data/vendor/assets/javascripts/scenejs_plugins/node/demos/redTeapot.js +52 -0
  53. data/vendor/assets/javascripts/scenejs_plugins/node/demos/spinningTeapot.js +43 -0
  54. data/vendor/assets/javascripts/scenejs_plugins/node/effects/crt.js +36 -0
  55. data/vendor/assets/javascripts/scenejs_plugins/node/effects/fog.js +159 -0
  56. data/vendor/assets/javascripts/scenejs_plugins/node/effects/snowyPeaks.js +50 -0
  57. data/vendor/assets/javascripts/scenejs_plugins/node/effects/wobble.js +42 -0
  58. data/vendor/assets/javascripts/scenejs_plugins/node/effects/xray.js +126 -0
  59. data/vendor/assets/javascripts/scenejs_plugins/node/frustum/body.js +112 -0
  60. data/vendor/assets/javascripts/scenejs_plugins/node/frustum/cull.js +42 -0
  61. data/vendor/assets/javascripts/scenejs_plugins/node/frustum/lod.js +125 -0
  62. data/vendor/assets/javascripts/scenejs_plugins/node/heightmaps/custom.js +185 -0
  63. data/vendor/assets/javascripts/scenejs_plugins/node/import/3ds.js +91 -0
  64. data/vendor/assets/javascripts/scenejs_plugins/node/import/md2.js +139 -0
  65. data/vendor/assets/javascripts/scenejs_plugins/node/import/obj.js +100 -0
  66. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building.js +352 -0
  67. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/HighRiseGlass.jpg +0 -0
  68. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/HighRiseGlassSpecular.jpg +0 -0
  69. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/highrise-windows.jpg +0 -0
  70. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/pixelcity_windows7.jpg +0 -0
  71. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/city.js +26 -0
  72. data/vendor/assets/javascripts/scenejs_plugins/node/objects/plants/ghostTree.js +387 -0
  73. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth.js +168 -0
  74. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-lights.gif +0 -0
  75. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-specular.gif +0 -0
  76. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-specular.jpg +0 -0
  77. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth.jpg +0 -0
  78. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earthbump.jpg +0 -0
  79. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earthclouds.jpg +0 -0
  80. data/vendor/assets/javascripts/scenejs_plugins/node/objects/toys/drinkingBird.js +632 -0
  81. data/vendor/assets/javascripts/scenejs_plugins/node/objects/vehicles/tank.js +77670 -0
  82. data/vendor/assets/javascripts/scenejs_plugins/node/objects/vehicles/tank.js~ +77636 -0
  83. data/vendor/assets/javascripts/scenejs_plugins/node/physics/body.js +85 -0
  84. data/vendor/assets/javascripts/scenejs_plugins/node/physics/box.js +30 -0
  85. data/vendor/assets/javascripts/scenejs_plugins/node/physics/material.js +35 -0
  86. data/vendor/assets/javascripts/scenejs_plugins/node/physics/plane.js +47 -0
  87. data/vendor/assets/javascripts/scenejs_plugins/node/physics/sphere.js +32 -0
  88. data/vendor/assets/javascripts/scenejs_plugins/node/physics/system.js +44 -0
  89. data/vendor/assets/javascripts/scenejs_plugins/node/physics/teapot.js +29 -0
  90. data/vendor/assets/javascripts/scenejs_plugins/node/prims/boundary.js +73 -0
  91. data/vendor/assets/javascripts/scenejs_plugins/node/prims/box.js +87 -0
  92. data/vendor/assets/javascripts/scenejs_plugins/node/prims/cylinder.js +186 -0
  93. data/vendor/assets/javascripts/scenejs_plugins/node/prims/grid.js +47 -0
  94. data/vendor/assets/javascripts/scenejs_plugins/node/prims/plane.js +137 -0
  95. data/vendor/assets/javascripts/scenejs_plugins/node/prims/quad.js +43 -0
  96. data/vendor/assets/javascripts/scenejs_plugins/node/prims/sphere.js +107 -0
  97. data/vendor/assets/javascripts/scenejs_plugins/node/prims/teapot.js +5846 -0
  98. data/vendor/assets/javascripts/scenejs_plugins/node/prims/torus.js +149 -0
  99. data/vendor/assets/javascripts/scenejs_plugins/node/prims/vectorText.js +1508 -0
  100. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/clouds.js +19 -0
  101. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/cloudySea.js +19 -0
  102. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/custom.js +150 -0
  103. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/grimmNight.js +19 -0
  104. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/interstellarClouds.js +19 -0
  105. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/miramarClouds.js +19 -0
  106. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/stormyDays.js +19 -0
  107. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/clouds.jpg +0 -0
  108. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/cloudySea.jpg +0 -0
  109. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/grimmNight.jpg +0 -0
  110. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/interstellarClouds.jpg +0 -0
  111. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/miramarClouds.jpg +0 -0
  112. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/stormyDays.jpg +0 -0
  113. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/violentDays.jpg +0 -0
  114. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/violentDays.js +19 -0
  115. data/vendor/assets/javascripts/scenejs_plugins/texture/image.js +67 -0
  116. data/vendor/assets/javascripts/scenejs_plugins/texture/video.js +105 -0
  117. metadata +113 -1
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Orbiting camera node type
3
+ *
4
+ * Usage example
5
+ * -------------
6
+ *
7
+ * someNode.addNode({
8
+ * type: "cameras/orbit",
9
+ * eye:{ x: y:0 },
10
+ * look:{ y:0 },
11
+ * yaw: 340,,
12
+ * pitch: -20,
13
+ * zoom: 350,
14
+ * zoomSensitivity:10.0,
15
+ * });
16
+ *
17
+ * The camera is initially positioned at the given 'eye' and 'look', then the distance of 'eye' is zoomed out
18
+ * away from 'look' by the amount given in 'zoom', and then 'eye' is rotated by 'yaw' and 'pitch'.
19
+ *
20
+ */
21
+ SceneJS.Types.addType("cameras/orbit", {
22
+
23
+ construct:function (params) {
24
+
25
+ var lookat = this.addNode({
26
+ type:"lookAt",
27
+
28
+ // A plugin node type is responsible for attaching specified
29
+ // child nodes within itself
30
+ nodes:params.nodes
31
+ });
32
+
33
+ var yaw = params.yaw || 0;
34
+ var pitch = params.pitch || 0;
35
+ var zoom = params.zoom || 10;
36
+ var minPitch = params.minPitch;
37
+ var maxPitch = params.maxPitch;
38
+ var zoomSensitivity = params.zoomSensitivity || 1.0;
39
+
40
+ var lastX;
41
+ var lastY;
42
+ var dragging = false;
43
+
44
+ var eye = params.eye || { x:0, y:0, z:0 };
45
+ var look = params.look || { x:0, y:0, z:0};
46
+
47
+ lookat.set({
48
+ eye:{ x:eye.x, y:eye.y, z:-zoom },
49
+ look:{ x:look.x, y:look.y, z:look.z },
50
+ up:{ x:0, y:1, z:0 }
51
+ });
52
+
53
+ update();
54
+
55
+ var canvas = this.getScene().getCanvas();
56
+
57
+ canvas.addEventListener('mousedown', mouseDown, true);
58
+ canvas.addEventListener('mousemove', mouseMove, true);
59
+ canvas.addEventListener('mouseup', mouseUp, true);
60
+ canvas.addEventListener('touchstart', touchStart, true);
61
+ canvas.addEventListener('touchmove', touchMove, true);
62
+ canvas.addEventListener('touchend', touchEnd, true);
63
+ canvas.addEventListener('mousewheel', mouseWheel, true);
64
+ canvas.addEventListener('DOMMouseScroll', mouseWheel, true);
65
+
66
+ function mouseDown(event) {
67
+ lastX = event.clientX;
68
+ lastY = event.clientY;
69
+ dragging = true;
70
+ }
71
+
72
+ function touchStart(event) {
73
+ lastX = event.targetTouches[0].clientX;
74
+ lastY = event.targetTouches[0].clientY;
75
+ dragging = true;
76
+ }
77
+
78
+ function mouseUp() {
79
+ dragging = false;
80
+ }
81
+
82
+ function touchEnd() {
83
+ dragging = false;
84
+ }
85
+
86
+ function mouseMove(event) {
87
+ var posX = event.clientX;
88
+ var posY = event.clientY;
89
+ actionMove(posX, posY);
90
+ }
91
+
92
+ function touchMove(event) {
93
+ var posX = event.targetTouches[0].clientX;
94
+ var posY = event.targetTouches[0].clientY;
95
+ actionMove(posX, posY);
96
+ }
97
+
98
+ function actionMove(posX, posY) {
99
+ if (dragging) {
100
+
101
+ yaw -= (posX - lastX) * 0.1;
102
+ pitch -= (posY - lastY) * 0.1;
103
+
104
+ update();
105
+
106
+ lastX = posX;
107
+ lastY = posY;
108
+ }
109
+ }
110
+
111
+ function mouseWheel(event) {
112
+ var delta = 0;
113
+ if (!event) event = window.event;
114
+ if (event.wheelDelta) {
115
+ delta = event.wheelDelta / 120;
116
+ if (window.opera) delta = -delta;
117
+ } else if (event.detail) {
118
+ delta = -event.detail / 3;
119
+ }
120
+ if (delta) {
121
+ if (delta < 0) {
122
+ zoom -= zoomSensitivity;
123
+ } else {
124
+ zoom += zoomSensitivity;
125
+ }
126
+ }
127
+ if (event.preventDefault) {
128
+ event.preventDefault();
129
+ }
130
+ event.returnValue = false;
131
+ update();
132
+
133
+ }
134
+
135
+ function update() {
136
+
137
+ if (minPitch != undefined && pitch < minPitch) {
138
+ pitch = minPitch;
139
+ }
140
+
141
+ if (maxPitch != undefined && pitch > maxPitch) {
142
+ pitch = maxPitch;
143
+ }
144
+
145
+ var eye = [0, 0, zoom];
146
+ var look = [0, 0, 0];
147
+ var up = [0, 1, 0];
148
+
149
+ // TODO: These references are to private SceneJS math methods, which are not part of API
150
+
151
+ var eyeVec = SceneJS_math_subVec3(eye, look, []);
152
+ var axis = SceneJS_math_cross3Vec3(up, eyeVec, []);
153
+
154
+ var pitchMat = SceneJS_math_rotationMat4v(pitch * 0.0174532925, axis);
155
+ var yawMat = SceneJS_math_rotationMat4v(yaw * 0.0174532925, up);
156
+
157
+ var eye3 = SceneJS_math_transformPoint3(pitchMat, eye);
158
+ eye3 = SceneJS_math_transformPoint3(yawMat, eye3);
159
+
160
+ lookat.setEye({x:eye3[0], y:eye3[1], z:eye3[2] });
161
+ }
162
+ },
163
+
164
+ setLook: function(l) {
165
+
166
+
167
+ },
168
+
169
+ destruct:function () {
170
+ // TODO: remove mouse handlers
171
+ }
172
+ });
@@ -0,0 +1,409 @@
1
+ /**
2
+ * Camera that flies to ray-picked point on scene object
3
+ *
4
+ * Usage example
5
+ * -------------
6
+ *
7
+ * someNode.addNode({
8
+ * type: "cameras/pickFlyOrbit",
9
+ * eye:{ x: y:0 },
10
+ * look:{ y:0 },
11
+ * yaw: 340,,
12
+ * pitch: -20,
13
+ * zoom: 350,
14
+ * zoomSensitivity:10.0,
15
+ * showCursor: true
16
+ * });
17
+ *
18
+ * The camera is initially positioned at the given 'eye' and 'look', then the distance of 'eye' is zoomed out
19
+ * away from 'look' by the amount given in 'zoom', and then 'eye' is rotated by 'yaw' and 'pitch'.
20
+ *
21
+ */
22
+ require([
23
+ SceneJS.getConfigs("pluginPath") + "/lib/gl-matrix-min.js"
24
+ ],
25
+ function (glmat, jquery) {
26
+
27
+ // Create target indicator div
28
+
29
+ var label = (function () {
30
+ var text;
31
+ var body = document.getElementsByTagName("body")[0];
32
+ var div = document.createElement('div');
33
+
34
+ var style = div.style;
35
+ style.display = "none";
36
+ style.position = "absolute";
37
+ style["font-family"] = "Helvetica";
38
+ style["font-size"] = "14px";
39
+ style.padding = "5px";
40
+ style.margin = "4px";
41
+ style["padding-left"] = "12px";
42
+ style["border"] = "1px solid #000055";
43
+ style.color = "black";
44
+ style.background = "#AAFFAA";
45
+ style.opacity = "0.8";
46
+ style["border-radius"] = "3px";
47
+ style["-moz-border-radius"] = "3px";
48
+ style["box-shadow"] = "3px 3px 3px #444444";
49
+ style.left = "0";
50
+ style.top = "0";
51
+ style.height = "auto";
52
+ style.width = "auto";
53
+ div.innerHTML += 'Foo';
54
+ body.appendChild(div);
55
+ return {
56
+
57
+ // Shows label, but only if text has been set
58
+ setShown:function (shown) {
59
+ style.display = shown && text ? "" : "none";
60
+ },
61
+
62
+ // Sets canvas position of label
63
+ setPos:function (pos) {
64
+ style.left = "" + pos.x + "px";
65
+ style.top = "" + pos.y + "px";
66
+ },
67
+
68
+ // Sets text in label
69
+ setText:function (t) {
70
+ text = t;
71
+ div.innerHTML = "<span>" + text + "</span>";
72
+ }
73
+ }
74
+ })();
75
+
76
+ SceneJS.Types.addType("cameras/pickFlyOrbit", {
77
+
78
+ construct:function (params) {
79
+
80
+ var lookat = this.addNode({
81
+ type:"lookAt",
82
+
83
+ nodes:[
84
+ {
85
+ type:"name",
86
+ name:"noname",
87
+
88
+ // A plugin node type is responsible for attaching specified
89
+ // child nodes within itself
90
+ nodes:params.nodes
91
+ }
92
+ ]
93
+ });
94
+
95
+ var indicatorPos;
96
+ var indicatorVis;
97
+ var indicatorSize;
98
+
99
+ if (params.showCursor) {
100
+
101
+ // Red sphere to indicate current point-of-interest. We'll update the
102
+ // position of this whenever a new 3D position has been ray-picked.
103
+ // This will be the position about which we'll orbit.
104
+
105
+ // Sphere position, with a ID so we can update this node:
106
+ indicatorPos = lookat.addNode({
107
+ type:"translate",
108
+ id:"__spherePOI"
109
+ });
110
+
111
+ indicatorVis = indicatorPos.addNode({
112
+ type:"flags",
113
+ flags:{
114
+ enabled:false,
115
+ transparent:true,
116
+ specular:true,
117
+ diffuse:false
118
+ }
119
+ });
120
+
121
+ var cursorSize = params.cursorSize || 1;
122
+
123
+ indicatorSize = indicatorVis.addNode({
124
+ type:"scale",
125
+ id:"__sphereSize",
126
+ x:cursorSize,
127
+ y:cursorSize,
128
+ z:cursorSize,
129
+ nodes:[
130
+ {
131
+ type:"material",
132
+ color:{ r:0.4, g:1.0, b:0.4 },
133
+ specularColor:{ r:1.0, g:1.0, b:1.0 },
134
+ emit:0.2,
135
+ nodes:[
136
+ {
137
+ type:"style",
138
+ lineWidth:2,
139
+ nodes:[
140
+
141
+ // Sphere primitive implemented by plugin at
142
+ // http://scenejs.org/api/latest/plugins/node/prims/sphere.js
143
+ {
144
+ type:"prims/sphere"
145
+ }
146
+ ]
147
+ }
148
+ ]
149
+ }
150
+ ]
151
+ });
152
+
153
+ this.getScene().getNode("__sphereSize", function (n) {
154
+ n.on("rendered",
155
+ function (event) {
156
+ label.setPos(event.getCanvasPos());
157
+ });
158
+ });
159
+ }
160
+
161
+ var eye = params.eye || { x:0, y:0, z:0 };
162
+ var look = params.look || { x:0, y:0, z:0};
163
+ var zoom = params.zoom || 100;
164
+ var zoomSensitivity = params.zoomSensitivity || 1.0;
165
+
166
+ lookat.set({
167
+ eye:{ x:eye.x, y:eye.y, z:eye.z},
168
+ look:{ x:look.x, y:look.y, z:look.z },
169
+ up:{ x:0, y:1, z:0 }
170
+ });
171
+
172
+ var canvas = this.getScene().getCanvas();
173
+
174
+ canvas.addEventListener('mousedown', mouseDown, true);
175
+ canvas.addEventListener('mouseup', mouseUp, true);
176
+ canvas.addEventListener('touchstart', touchStart, true);
177
+ canvas.addEventListener('touchend', touchEnd, true);
178
+ canvas.addEventListener('mousemove', mouseMove, true);
179
+ canvas.addEventListener('touchmove', touchMove, true);
180
+ canvas.addEventListener('mousewheel', mouseWheel, true);
181
+ canvas.addEventListener('DOMMouseScroll', mouseWheel, true);
182
+
183
+ var downX;
184
+ var downY;
185
+ var lastX;
186
+ var lastY;
187
+ var dragging;
188
+
189
+ var yaw = params.yaw || 0;
190
+ var pitch = params.pitch || 0;
191
+
192
+ var startPivot;
193
+ var currentPivot = glmat.vec3.fromValues(look.x || 0, look.y || 0, look.z || 0);
194
+ var endPivot = glmat.vec3.fromValues(look.x || 0, look.y || 0, look.z || 0);
195
+
196
+ var flightStartTime = null;
197
+ var flightDist;
198
+ var flightDuration;
199
+ var flying = false;
200
+ var orbiting = true;
201
+
202
+ function mouseDown(event) {
203
+ lastX = downX = event.clientX;
204
+ lastY = downY = event.clientY;
205
+ dragging = true;
206
+ }
207
+
208
+ function touchStart(event) {
209
+ lastX = downX = event.targetTouches[0].clientX;
210
+ lastY = downY = event.targetTouches[0].clientY;
211
+ dragging = true;
212
+ }
213
+
214
+ function mouseUp(event) {
215
+
216
+ if (dragging && closeEnough(event.clientX, downX) && closeEnough(event.clientY, downY)) {
217
+ pick(event.clientX, event.clientY);
218
+ }
219
+ dragging = false;
220
+ }
221
+
222
+ function closeEnough(x, y) {
223
+ return (x > y) ? (x - y < 5) : (y - x < 5);
224
+ }
225
+
226
+ function touchEnd(event) {
227
+ if (dragging && event.targetTouches[0].clientX == downX && event.targetTouches[0].clientY == downY) {
228
+ pick(event.targetTouches[0].clientX, event.targetTouches[0].clientY);
229
+ }
230
+ dragging = false;
231
+ }
232
+
233
+ function mouseMove(event) {
234
+ var posX = event.clientX;
235
+ var posY = event.clientY;
236
+ actionMove(posX, posY);
237
+ }
238
+
239
+ function touchMove(event) {
240
+ var posX = event.targetTouches[0].clientX;
241
+ var posY = event.targetTouches[0].clientY;
242
+ actionMove(posX, posY);
243
+ }
244
+
245
+ function actionMove(posX, posY) {
246
+ if (dragging) {
247
+ yaw += (posX - lastX) * 0.1;
248
+ pitch -= (posY - lastY) * 0.1;
249
+ orbiting = true;
250
+ }
251
+ lastX = posX;
252
+ lastY = posY;
253
+ }
254
+
255
+ function mouseWheel(event) {
256
+ var delta = 0;
257
+ if (!event) event = window.event;
258
+ if (event.wheelDelta) {
259
+ delta = event.wheelDelta / 120;
260
+ if (window.opera) delta = -delta;
261
+ } else if (event.detail) {
262
+ delta = -event.detail / 3;
263
+ }
264
+ if (delta) {
265
+ if (delta < 0) {
266
+ zoom -= zoomSensitivity;
267
+ } else {
268
+ zoom += zoomSensitivity;
269
+ }
270
+ }
271
+ if (event.preventDefault) {
272
+ event.preventDefault();
273
+ }
274
+ event.returnValue = false;
275
+ orbiting = true;
276
+ }
277
+
278
+ function pick(canvasX, canvasY) {
279
+ scene.pick(canvasX, canvasY, { rayPick:true });
280
+ }
281
+
282
+ var scene = this.getScene();
283
+
284
+ scene.on("pick",
285
+ function (hit) {
286
+
287
+ // Some plugins wrap things in this name to
288
+ // avoid them being picked, such as skyboxes
289
+ if (hit.name == "__SceneJS_dontPickMe") {
290
+ return;
291
+ }
292
+
293
+ startPivot = glmat.vec3.fromValues(currentPivot[0], currentPivot[1], currentPivot[2]);
294
+ endPivot = hit.worldPos;
295
+
296
+ if (indicatorVis) {
297
+ indicatorVis.setEnabled(true);
298
+ indicatorPos.setXYZ({x:endPivot[0], y:endPivot[1], z:endPivot[2] });
299
+ label.setShown(true);
300
+ }
301
+
302
+ var vec = glmat.vec3.create();
303
+ glmat.vec3.sub(vec, endPivot, startPivot);
304
+
305
+ flightDist = glmat.vec3.length(vec);
306
+ flightStartTime = null;
307
+ flightDuration = 1000.0 * ((flightDist / 1000) + 1); // extra seconds to ensure arrival
308
+ flying = true;
309
+
310
+ label.setText("[ " + Math.round(endPivot[0]) + ", " + Math.round(endPivot[1]) + ", " + Math.round(endPivot[2]) + " ]");
311
+ });
312
+
313
+ scene.on("tick",
314
+ function () {
315
+
316
+ if (flying) {
317
+
318
+ if (flightStartTime == null) {
319
+ flightStartTime = (new Date()).getTime();
320
+ }
321
+
322
+ var timeNow = (new Date()).getTime();
323
+ var timeElapsed = timeNow - flightStartTime;
324
+
325
+ if (timeElapsed >= flightDuration) {
326
+ flying = false;
327
+ flying = false;
328
+ flightStartTime = null;
329
+
330
+ // Hide pick indicator
331
+ if (indicatorVis) {
332
+ // indicatorVis.setEnabled(false);
333
+ // label.setShown(false);
334
+ }
335
+ } else {
336
+
337
+ var easedTime = easeOut((timeNow - flightStartTime) / flightDuration, 0, 1, 1);
338
+
339
+ // Continue flight
340
+ // Find new pivot point, interpolated on path towards new point
341
+
342
+ glmat.vec3.lerp(currentPivot, startPivot, endPivot, easedTime);
343
+
344
+ // Need to rotate lookat
345
+ orbiting = true;
346
+ }
347
+ }
348
+
349
+
350
+ if (orbiting) {
351
+
352
+ // Update location of point-of-interest indicator
353
+ if (indicatorVis) {
354
+ indicatorVis.setEnabled(true);
355
+ label.setShown(true);
356
+ }
357
+
358
+ var eye = glmat.vec3.fromValues(0, 0, zoom);
359
+ var look = glmat.vec3.fromValues(currentPivot[0], currentPivot[1], currentPivot[2]);
360
+ // var up = glmat.vec3.fromValues(0, 1, 0);
361
+
362
+ var eyeVec = glmat.vec3.create();
363
+ glmat.vec3.sub(eyeVec, eye, look);
364
+
365
+ var mat = glmat.mat4.create();
366
+
367
+ glmat.mat4.rotateY(mat, mat, -yaw * 0.0174532925);
368
+ glmat.mat4.rotateX(mat, mat, -pitch * 0.0174532925);
369
+
370
+ var eye3 = glmat.vec3.create();
371
+
372
+ glmat.vec3.transformMat4(eye3, eye, mat);
373
+
374
+ // Update view transform
375
+ lookat.setLook({x:look[0], y:look[1], z:look[2] });
376
+ lookat.setEye({x:look[0] - eye3[0], y:look[1] - eye3[1], z:look[2] - eye3[2] });
377
+
378
+ // Rotate complete
379
+ orbiting = false;
380
+
381
+ if (indicatorVis) {
382
+ setTimeout(function () {
383
+ indicatorVis.setEnabled(false);
384
+ label.setShown(false);
385
+ }, 2000);
386
+ }
387
+ }
388
+ });
389
+ },
390
+
391
+ destruct:function () {
392
+ // TODO: remove mouse handlers
393
+ }
394
+ });
395
+
396
+
397
+ function easeOut(t, b, c, d) {
398
+ var ts = (t /= d) * t;
399
+ var tc = ts * t;
400
+ return b + c * (-1 * ts * ts + 4 * tc + -6 * ts + 4 * t);
401
+ }
402
+
403
+ function easeIn(t, b, c, d) {
404
+ var ts = (t /= d) * t;
405
+ var tc = ts * t;
406
+ return b + c * (tc * ts);
407
+ }
408
+
409
+ });