-
Notifications
You must be signed in to change notification settings - Fork 1
/
interaction-camera-navigation.js
463 lines (356 loc) · 12.1 KB
/
interaction-camera-navigation.js
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
var camera, controls;
// Constructor
SceneViewer = function()
{
Sim.App.call(this);
}
// Subclass Sim.App
SceneViewer.prototype = new Sim.App();
// Our custom initializer
SceneViewer.prototype.init = function(param)
{
// Call superclass init code to set up scene, renderer, default camera
Sim.App.prototype.init.call(this, param);
// Create a point light to show off the scene
var light = new THREE.PointLight( 0xffffff, 1, 200);
light.position.set(0, 20, 0);
this.scene.add(light);
light = new THREE.PointLight( 0xffffff, 1, 200);
light.position.set(0, 0, 0);
this.scene.add(light);
var amb = new THREE.AmbientLight( 0x808080, 1);
this.scene.add(amb);
this.camera.position.set(0.5, 1.5, 0.5);
this.camera.lookAt(this.root.position);
this.camera.near = 0.001;
this.root.rotation.y = -Math.PI / 2;
// Create the model and add it to our sim
var content = new Scene();
content.init();
this.addObject(content);
this.content = content;
this.createCameraControls();
document.addEventListener( 'dblclick', ondblclick, false );
}
SceneViewer.prototype.createCameraControls = function()
{
controls = new THREE.FirstPersonControls(this.camera);
controls.movementSpeed = 10;
controls.lookSpeed = 0.05;
// Allow tilt up/down
controls.lookVertical = true;
// Don't move camera without click
controls.activeLook = false;
// var controls = new THREE.DragControls( this.camera );
this.controls = controls;
this.clock = new THREE.Clock();
//Trackball controls
/*controls = new THREE.TrackballControls( this.camera, this.renderer.domElement );
controls.target.set(0,0,0);
var radius = SceneViewer.CAMERA_RADIUS;
controls.rotateSpeed = SceneViewer.ROTATE_SPEED;
controls.zoomSpeed = SceneViewer.ZOOM_SPEED;
controls.panSpeed = SceneViewer.PAN_SPEED;
controls.dynamicDampingFactor = SceneViewer.DAMPING_FACTOR;
controls.noZoom = true;
controls.noPan = false;
controls.staticMoving = false;
controls.minDistance = radius * SceneViewer.MIN_DISTANCE_FACTOR;
controls.maxDistance = radius * SceneViewer.MAX_DISTANCE_FACTOR;
this.controls = controls;*/
}
SceneViewer.prototype.update = function()
{
this.controls.update(this.clock.getDelta());
Sim.App.prototype.update.call(this);
//this.controls.update();
//Sim.App.prototype.update.call(this);
}
SceneViewer.CAMERA_START_Z = 22;
SceneViewer.CAMERA_RADIUS = 1;
SceneViewer.MIN_DISTANCE_FACTOR = 1.0;
SceneViewer.MAX_DISTANCE_FACTOR = 1.0;
SceneViewer.ROTATE_SPEED = 1.0;
SceneViewer.ZOOM_SPEED = 3;
SceneViewer.PAN_SPEED = 0.2;
SceneViewer.DAMPING_FACTOR = 0.6;
// Custom model class
Scene = function()
{
Sim.Object.call(this);
}
Scene.prototype = new Sim.Object();
Scene.prototype.init = function(param)
{
// Create an empty group to hold the content
var group = new THREE.Object3D;
// Tell the framework about our object
this.setObject3D(group);
this.addCuriosityPics();
this.addStars();
}
Scene.prototype.addCuriosityPics = function()
{
getLocationDataArray();
getImageDataArray();
if (getUrlVars()["id"])
{
var first = getUrlVars()["id"];
alert(first);
}
if (getUrlVars()["page"])
{
var second = getUrlVars()["page"];
alert(second);
}
var targetDate = null;
if (getUrlVars()["date"])
{
targetDate = getUrlVars()["date"];
}
//targetDate = "2012-09-17";
var targetDrive = null;
if (getUrlVars()["drive"])
{
targetDrive = getUrlVars()["drive"];
// console.log("Drive number from URL is: " + targetDrive)
}
var targetSite = null;
if (getUrlVars()["site"])
{
targetSite = getUrlVars()["site"];
// console.log("Site number from URL is: " + targetSite)
}
var MyMapArray = new Array();
var MyVector = null;
var tempImageIndex = 0;
var tempMapIndex = 0;
var counter = 0;
for ( var i=SiteLocation.length - 1; i >= 0; i--)
{
if (SiteLocation[i])
{
for (var j=SiteLocation[i].length - 1; j >= 0; j--)
{
if ( SiteLocation[i][j])
{
if ( SiteLocation[i][j].images)
{
for (var k=0; k < SiteLocation[i][j].images.length; k++)
{
if (true)// if (i == targetSite && j == targetDrive)
{
if ( SiteLocation[i][j].images[k].instrument != "FHAZ_RIGHT_A" && SiteLocation[i][j].images[k].instrument != "RHAZ_RIGHT_A" && SiteLocation[i][j].images[k].instrument != "NAV_RIGHT_A" && SiteLocation[i][j].images[k].instrument != "CHEMCAM_RMI" && SiteLocation[i][j].images[k].instrument != "CHEMCAM_LMI")
{
counter++;
MyMapArray[MyMapArray.length] = new THREE.Texture();
tempMapIndex = MyMapArray.length-1;
if ( SiteLocation[i][j].images[k].instrument == "FHAZ_LEFT_A"
||
SiteLocation[i][j].images[k].instrument == "FHAZ_RIGHT_A"
||
SiteLocation[i][j].images[k].instrument == "RHAZ_LEFT_A"
||
SiteLocation[i][j].images[k].instrument == "RHAZ_RIGHT_A" )
{
var MyMaterial = new THREE.MeshBasicMaterial({ map: MyMapArray[tempMapIndex],
transparent: true,
opacity: 0.0 });
var MyGeometry = new THREE.PlaneGeometry(2.5,2.5);
}
else
{
var MyMaterial = new THREE.MeshBasicMaterial({ map: MyMapArray[tempMapIndex],
transparent: true,
opacity: 0.0 });
var MyGeometry = new THREE.PlaneGeometry(1,1);
}
var MyPlane = new THREE.Mesh(MyGeometry, MyMaterial);
var MyQuaternion = SiteLocation[i][j].images[k].attitude;
var MyCameraPosition = SiteLocation[i][j].images[k].cameraPosition;
var tempNumberX = MyCameraPosition.x;
var tempNumberY = MyCameraPosition.y;
var tempNumberZ = MyCameraPosition.z;
MyCameraPosition.x = tempNumberY;
MyCameraPosition.y = -1*tempNumberZ;
MyCameraPosition.z = -1*tempNumberX;
var MyCameraVector = SiteLocation[i][j].images[k].cameraVector;
tempNumberX = MyCameraVector.x;
tempNumberY = MyCameraVector.y;
tempNumberZ = MyCameraVector.z;
MyCameraVector.x = tempNumberY;
MyCameraVector.y = -1*tempNumberZ;
MyCameraVector.z = -1*tempNumberX;
MyCameraVector.setLength(1);
MyVector = new THREE.Vector3( MyCameraPosition.x, MyCameraPosition.y, MyCameraPosition.z);
MyVector.addSelf(MyCameraVector);
var MyMarsLocation = new THREE.Vector3(
SiteLocation[i][j].x/100,
(-1)*SiteLocation[i][j].y/100,
(-1)*SiteLocation[i][j].z/100
)
MyPlane.position.set(MyVector.x, MyVector.y, MyVector.z);
var MyLookVector = MyCameraPosition;
MyPlane.rotationAutoUpdate = true;
MyPlane.lookAt(MyLookVector);
MyPlane.EOMsrcForImage = SiteLocation[i][j].images[k].urlList;
MyPlane.EOMutc = SiteLocation[i][j].images[k].utc;
MyPlane.EOMsol = SiteLocation[i][j].images[k].sol;
MyPlane.EOMsite = i;
MyPlane.EOMdrive = j;
MyPlane.visible = false;
this.object3D.add(MyPlane);
planeArr[planeArr.length] = MyPlane;
planeArr[planeArr.length-1].EOMmarsLocation = MyMarsLocation;
planeArr[planeArr.length-1].EOMinstrument = SiteLocation[i][j].images[k].instrument;
}
}
}
}
}
}
}
}
cameraLookAtVector = MyVector;
}
// Stars
Scene.prototype.addStars = function()
{
var radius = 50;
var starsGeometry = new THREE.Geometry();
for ( var i = 0; i < 1500; i ++ ) {
var vertex = new THREE.Vector3();
vertex.x = Math.random() * 2 - 1;
vertex.y = Math.random() * 2 - 1;
vertex.z = Math.random() * 2 - 1;
vertex.multiplyScalar( radius );
starsGeometry.vertices.push( vertex );
}
var stars,
starsMaterials = [
new THREE.ParticleBasicMaterial( { color: 0x555555, size: 2, sizeAttenuation: false } ),
new THREE.ParticleBasicMaterial( { color: 0x555555, size: 1, sizeAttenuation: false } ),
new THREE.ParticleBasicMaterial( { color: 0x333333, size: 2, sizeAttenuation: false } ),
new THREE.ParticleBasicMaterial( { color: 0x3a3a3a, size: 1, sizeAttenuation: false } ),
new THREE.ParticleBasicMaterial( { color: 0x1a1a1a, size: 2, sizeAttenuation: false } ),
new THREE.ParticleBasicMaterial( { color: 0x1a1a1a, size: 1, sizeAttenuation: false } )
];
for ( i = 10; i < 30; i ++ ) {
stars = new THREE.ParticleSystem( starsGeometry, starsMaterials[ i % 6 ] );
stars.rotation.x = Math.random() * 6;
stars.rotation.y = Math.random() * 6;
stars.rotation.z = Math.random() * 6;
var s = i * 10;
stars.scale.set( s, s, s );
stars.matrixAutoUpdate = false;
stars.updateMatrix();
this.object3D.add( stars );
}
}
Scene.CAMERA_START_Z = 25;
//Custom model class
Model = function()
{
Sim.Object.call(this);
}
Model.prototype = new Sim.Object();
Model.prototype.init = function(param)
{
var group = new THREE.Object3D;
var that = this;
var url = param.url || "";
if (!url)
return;
this.materials = param.materials;
var scale = param.scale || 1;
this.scale = new THREE.Vector3(scale, scale, scale);
var loader = new THREE.BinaryLoader();
loader.load( url, function( data ) {
that.handleLoaded(data) } );
// Tell the framework about our object
this.setObject3D(group);
}
Model.prototype.handleLoaded = function(data)
{
if (data instanceof THREE.Geometry)
{
var geometry = data;
var material = null;
if (this.materials)
{
material = new THREE.MeshFaceMaterial();
var i, len = this.materials.length;
for (i = 0; i < len; i++)
{
geometry.materials[i] = this.materials[i];
}
}
else
{
material = new THREE.MeshFaceMaterial();
}
mesh = new THREE.Mesh( geometry, material );
this.object3D.add( mesh );
this.object3D.scale.copy(this.scale);
}
}
function ondblclick( event )
{
/*
*
* This event will add a lightbox div which will lay on top of the canvas
* and view the specific image that the user clicked on. If they click a single time
* once more, then the lightbox div tag will get removed and they will be able to view
* the canvas completely once more.
*
*/
/*
*
* Create a ray object that will intersect any images from the location that the user double clicked.
*
*/
var vector = new THREE.Vector3( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeight ) * 2 + 1, 0.5 );
var projector = new THREE.Projector();
projector.unprojectVector( vector, camera );
var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
intersects = ray.intersectObjects( planeArrVisible );
/*
*
* The first image in the array that the ray created will get displayed.
*
*/
if ( intersects.length > 0 ) {
var src = intersects[0].object.EOMsrcForImage;
var imgH;
var imgW;
for (var i = 0; i < intersects.length; i++)
{
if (intersects[i].object.visible)
{
src = intersects[i].object.EOMsrcForImage;
imgW = (document.width - intersects[i].object.material.map.image.width)/2;
imgH = (document.height - intersects[i].object.material.map.image.height)/2;
if (imgW < 0)
imgW = 0;
if (imgH < 0)
imgH = 0;
$("#container").after('<div class="lightbox"><div class="img_container"><img class="centered" src="' + src + '" /></div></div>');
var imageInfo = intersects[i].object.material.map.image.height + 'x' + intersects[i].object.material.map.image.width + ' pixels<br> Instrument: ' + intersects[i].object.EOMinstrument +
'<br> Site: ' + intersects[i].object.EOMsite + '<br> Drive: ' + intersects[i].object.EOMdrive + '<br> UTC: ' + intersects[i].object.EOMutc + ' <br> Sol: ' + intersects[i].object.EOMsol;
$("#container").after('<div class="img_info"><h3><center>Image Data<hr></center></h3><p> Size: ' + imageInfo + '</p></div>');
$('.centered').css({
"margin-left": imgW + "px",
"margin-top": imgH + "px"
})
break;
}
}
/* Close the lightbox area */
if (!$.browser.msie) {
$("body").mouseup(function () {
$(".lightbox").remove();
$(".img_info").remove();
});
}
}
}