forked from smsithlord/JumpStart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sammy.html
543 lines (453 loc) · 17.3 KB
/
Sammy.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
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
<!-- Powered by the JumpStart Game Engine -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sammy</title>
<script src="engine/misc/appMenu.js"></script>
<!-- AltspaceVR SDK Core Includes -->
<script src="http://sdk.altvr.com/libs/three.js/r71/build/three.min.js"></script>
<script src="http://sdk.altvr.com/libs/three.js/r71/examples/js/loaders/OBJMTLLoader.js"></script>
<script src="http://sdk.altvr.com/libs/three.js/r71/examples/js/loaders/MTLLoader.js"></script>
<script src="http://sdk.altvr.com/libs/altspace.js/latest/altspace.min.js"></script>
<!-- JumpStart SDK Additional Includes -->
<script src="legacy/v1/FirebaseSync.js"></script>
<script src="legacy/v1/AltOBJMTLLoader.js"></script>
<!-- JumpStart Styles -->
<link rel="stylesheet" type="text/css" href="legacy/v1/myStyle.css">
</head>
<body>
<!-- JumpStart SDK Core Include -->
<script src="legacy/v1/JumpStart.js"></script>
<!-- Window-Level Event Callbacks -->
<script>
// Configure JumpStart. You really only need to list
// properties you want non-default values for.
var myOptions =
{
"legacyLoader": false,
"worldScale": 2.0,
"scaleWithEnclosure": true,
"showCrosshair": false,
"showCursorPlanes": false,
"camera":
{
"lookAtOrigin": true,
"position": new THREE.Vector3(-5.0, 10.0, 30.0),
"translation": new THREE.Vector3(40.0, 30.0, 180.0)
}/*,
"firebase":
{
"rootUrl": "https://jump-start.firebaseio.com/",
"appId": "JumpStart",
"suppressPersonalBrowser": true
}*/
};
JumpStart.setOptions(myOptions);
var g_sammy = null;
// Window-level callback for onPrecache event
function onPrecache()
{
if( JumpStart.personalBrowser )//|| !JumpStart.requestedRoomId )
{
JumpStart.doneCaching();
return;
}
// Precaching is important with networked apps!!
// Networked objects might get spawned before the
// local client gets the onReady window-level callback!!
// You can think of precaching sounds as synchronous (but it's not)
// JumpStart.precacheSound("sounds/JumpStart/trumpet");
// JumpStart.precacheSound("sounds/JumpStart/cashout");
// Precache any models that your app needs (asynchronous)
var myModels = [
"legacy/v1/models/Sammy/bugbody.obj",
"legacy/v1/models/Sammy/bugeyes.obj",
"legacy/v1/models/Sammy/bugdish.obj",
"legacy/v1/models/Sammy/bugrig.obj",
"legacy/v1/models/Sammy/bugrearleft.obj",
"legacy/v1/models/Sammy/bugmidleft.obj",
"legacy/v1/models/Sammy/bugfrontleft.obj",
"legacy/v1/models/Sammy/bugrearright.obj",
"legacy/v1/models/Sammy/bugmidright.obj",
"legacy/v1/models/Sammy/bugfrontright.obj"
];
JumpStart.loadModels(myModels).then(function() {
// All assets cached.
JumpStart.doneCaching();
});
}
// Window-level callback for onReady event
function onReady()
{
var jumpStartAppMenu = new JumpStartAppMenu("Sammy", "http://www.jumpstartsdk.com/live/Sammy.html", g_scene);
// if( !JumpStart.requestedRoomId )
// return;
// Do nothing if we are not in an enclosure yet.
if( JumpStart.personalBrowser )
{
var loadingRingElem = document.getElementById("loadingRing");
if( loadingRingElem )
{
loadingRingElem.parentNode.removeChild(loadingRingElem);
}
var loadingLogoElem = document.getElementById("loadingLogo");
if( loadingLogoElem )
{
loadingLogoElem.src = "legacy/v1/misc/beamnow.png";
}
JumpStart.showLoadingMsg("Loading complete.<br /><br /><font style='color: #00ff00; font-size: 30px; background-color: rgba(0, 0, 0, 0.5); padding: 10px; border-radius: 10px;'>Beam this app to an enclosure to begin!</font>");
return;
}
if( g_localUser.firstUser )
{
}
//var bug = JumpStart.spawnInstance("legacy/v1/models/Sammy/bugfull.obj");
// setTimeout(function() {
if( !g_sammy )
{
var bug = JumpStart.spawnInstance();
bug.JumpStart.onSpawn["bugSpawn"] = bugSpawn;
bug.JumpStart.onTick["bugTick"] = bugTick;
// bug.scale.set(1, 1, 1).multiplyScalar(g_worldScale);
bug.position.copy(g_worldOffset);
bug.rotation.set(0, 0, 0);
bug.JumpStart.wonderOrigin = new THREE.Vector3().copy(bug.position);
// bug.lookAt(g_camera.position);
bug.JumpStart.sync();
g_sammy = bug;
}
// }, 2000);
// Start the simulation
JumpStart.run();
}
// Window-level callback for onTick event
function onTick()
{
// do work
}
// Window-level callback for onCursorDown event
function onCursorDown()
{
// do work
}
// Window-level callback for onCursorUp event
function onCursorUp()
{
// do work
}
</script>
<!-- Custom Object-Level Event Callbacks -->
<script>
function doScaleLerp()
{
//console.log("scale lerp");
if( this.userData.hasOwnProperty("targetScaleLerp") && this.userData.targetScaleLerp < 1.0 )
{
this.userData.targetScaleLerp += (1.0/this.JumpStart.targetScaleLerpTime) * g_deltaTime;
var justFinished = false;
if( this.userData.targetScaleLerp >= 1.0 )
{
this.userData.targetScaleLerp = 1.0;
justFinished = true;
}
this.scale.lerpVectors(this.JumpStart.targetScaleOriginal, this.JumpStart.targetScale, this.userData.targetScaleLerp);
if( justFinished )
{
if( this.userData.hasOwnProperty("targetScaleAnim") && this.userData.targetScaleAnim && this.userData.targetScaleAnim.length > 0 )
{
var nextTarget = this.userData.targetScaleAnim.shift();
if( !nextTarget.targetScaleOriginal )
nextTarget.targetScaleOriginal = new THREE.Vector3().copy(this.scale);
// Set our new targets.
this.JumpStart.targetScale.copy(nextTarget.targetScale);
this.JumpStart.targetScaleOriginal.copy(nextTarget.targetScaleOriginal);
this.userData.targetScaleLerp = nextTarget.targetScaleLerp;
this.JumpStart.targetScaleLerpTime = nextTarget.targetScaleLerpTime;
}
}
}
}
function doPositionLerp()
{
if( this.userData.hasOwnProperty("targetPosLerp") && this.userData.targetPosLerp < 1.0 )
{
this.userData.targetPosLerp += (1.0/this.JumpStart.targetPosLerpTime) * g_deltaTime;
var justFinished = false;
if( this.userData.targetPosLerp >= 1.0 )
{
this.userData.targetPosLerp = 1.0;
justFinished = true;
}
this.position.lerpVectors(this.JumpStart.targetPosOriginal, this.JumpStart.targetPos, this.userData.targetPosLerp);
if( justFinished )
{
if( typeof this.userData.targetPosCallback === "function" )
this.userData.targetPosCallback.call(this);
this.userData.targetPosCallback = null;
if( this.userData.hasOwnProperty("targetPosAnim") && this.userData.targetPosAnim && this.userData.targetPosAnim.length > 0 )
{
var nextTarget = this.userData.targetPosAnim.shift();
if( !nextTarget.targetPosOriginal )
nextTarget.targetPosOriginal = new THREE.Vector3().copy(this.position);
// Set our new targets.
this.JumpStart.targetPos.copy(nextTarget.targetPos);
this.JumpStart.targetPosOriginal.copy(nextTarget.targetPosOriginal);
this.userData.targetPosLerp = nextTarget.targetPosLerp;
this.JumpStart.targetPosLerpTime = nextTarget.targetPosLerpTime;
if( typeof nextTarget.targetPosCallback === "function" )
this.userData.targetPosCallback = nextTarget.targetPosCallback;
this.JumpStart.sync();
}
}
}
}
function doRotationLerp()
{
//console.log("rot lerp");
if( this.userData.hasOwnProperty("targetRotLerp") && this.userData.targetRotLerp < 1.0 )
{
this.userData.targetRotLerp += (1.0/this.JumpStart.targetRotLerpTime) * g_deltaTime;
var justFinished = false;
if( this.userData.targetRotLerp >= 1.0 )
{
this.userData.targetRotLerp = 1.0;
justFinished = true;
}
var myQuaternionA = new THREE.Quaternion().setFromEuler(new THREE.Euler().setFromVector3(this.JumpStart.targetRotOriginal, 'XYZ'));
var myQuaternionB = new THREE.Quaternion().setFromEuler(new THREE.Euler().setFromVector3(this.JumpStart.targetRot, 'XYZ'));
myQuaternionA.slerp(myQuaternionB, this.userData.targetRotLerp);
this.quaternion.copy(myQuaternionA);
// this.rotation.lerpVectors(this.JumpStart.targetRotOriginal, this.JumpStart.targetRot, this.userData.targetRotLerp);
if( justFinished )
{
if( typeof this.userData.targetRotCallback === "function" )
this.userData.targetRotCallback.call(this);
this.userData.targetRotCallback = null;
if( this.userData.hasOwnProperty("targetRotAnim") && this.userData.targetRotAnim && this.userData.targetRotAnim.length > 0 )
{
var nextTarget = this.userData.targetRotAnim.shift();
if( !nextTarget.targetRotOriginal )
nextTarget.targetRotOriginal = new THREE.Vector3().copy(this.rotation);
// Set our new targets.
this.JumpStart.targetRot.copy(nextTarget.targetRot);
this.JumpStart.targetRotOriginal.copy(nextTarget.targetRotOriginal);
this.userData.targetRotLerp = nextTarget.targetRotLerp;
this.JumpStart.targetRotLerpTime = nextTarget.targetRotLerpTime;
if( typeof nextTarget.targetRotCallback === "function" )
this.userData.targetRotCallback = nextTarget.targetRotCallback;
}
}
}
}
function bugTick()
{
function randoNinjaStop()
{
var rando = Math.random();
if( rando > 0.9 )
return true;
else
return false;
}
function randoTurn()
{
var rando = Math.random();
if( rando < 0.2 )
return 1.0;
else if( rando > 0.8 )
return -1.0;
else
return 0;
}
function randoTurnSpeed()
{
var rando = Math.random() * 0.7;
// if( Math.random() > 0.5 )
// rando *= -1.0;
return rando;
}
if( !this.userData.hasOwnProperty("turnDirection") )
{
this.userData.turnDirection = randoTurn();
this.userData.turnSpeed = randoTurnSpeed();
this.userData.turnLife = 1.0 * Math.random();
}
var boost = 1.0;
if( this.userData.ninjaStop )
boost = 2.0;
this.userData.turnLife -= boost * g_deltaTime;
if( this.userData.turnLife < 0 )
{
this.userData.turnLife = 1.0;
this.userData.turnDirection = randoTurn();
this.userData.turnSpeed = randoTurnSpeed();
if( randoNinjaStop() )
this.userData.ninjaStop = true;
else
this.userData.ninjaStop = false;
}
var speed = 13.0;
if( !this.userData.ninjaStop )
{
this.translateZ(speed * g_deltaTime);
if( this.position.distanceTo(this.JumpStart.wonderOrigin) > 150.0 )
{
// var oldYAW = this.rotation.y;
this.lookAt(this.JumpStart.wonderOrigin);
// this.rotation.y = oldYAW;
}
else
this.rotateY(this.userData.turnSpeed * this.userData.turnDirection * g_deltaTime);
}
}
function flipFlopWalk()
{
this.userData.direction *= -1.0;
this.userData.targetRotAnim = [{
targetRot: new THREE.Vector3(0, this.userData.direction * (Math.PI/14.0), 0),
targetRotOriginal: null,
targetRotLerp: 0.0,
targetRotLerpTime: 0.8,
targetRotCallback: flipFlopWalk
}];
}
function legWalk()
{
if( this.userData.parentBug.userData.hasOwnProperty("ninjaStop") && this.userData.parentBug.userData.ninjaStop )
{
this.rotation.set(0, 0, 0);
return;
}
doScaleLerp.call(this);
doRotationLerp.call(this);
doPositionLerp.call(this);
if( this.userData.direction < 0 )
{
if( this.userData.targetRotLerp <= 0.5 )
this.rotateZ((Math.PI * this.userData.targetRotLerp) * 0.3);
else
this.rotateZ((Math.PI * (1.0 - this.userData.targetRotLerp)) * 0.3);
}
}
function legWalk2()
{
if( this.userData.parentBug.userData.hasOwnProperty("ninjaStop") && this.userData.parentBug.userData.ninjaStop )
{
this.rotation.set(0, 0, 0);
return;
}
doScaleLerp.call(this);
doRotationLerp.call(this);
doPositionLerp.call(this);
if( this.userData.direction > 0 )
{
if( this.userData.targetRotLerp <= 0.5 )
this.rotateZ(-(Math.PI * this.userData.targetRotLerp) * 0.3);
else
this.rotateZ(-(Math.PI * (1.0 - this.userData.targetRotLerp)) * 0.3);
}
}
function bugSpawn()
{
g_sammy = this;
// attach all our parts
var verts;
var x;
for( x in JumpStart.models )
{
if( JumpStart.models[x].fileName === "legacy/v1/models/Sammy/bugrig.obj" )
{
verts = JumpStart.models[x].object.children[JumpStart.models[x].object.children.length-1].geometry.vertices;
break;
}
}
var bugJoints = {"body": verts[4], "dish": verts[7], "eyes": verts[8], "rearleft": verts[1], "midleft": verts[0], "frontleft": verts[3], "rearright": verts[6], "midright": verts[5], "frontright": verts[2]};
var body = JumpStart.spawnInstance("legacy/v1/models/Sammy/bugbody.obj", {"parent": this});
body.position.copy(bugJoints.body);
body.JumpStart.blocksLOS = false;
var dish = JumpStart.spawnInstance("legacy/v1/models/Sammy/bugdish.obj", {"parent": this});
dish.position.copy(bugJoints.dish);
dish.JumpStart.blocksLOS = false;
dish.JumpStart.onTick = function()
{
this.rotateY(2.0 * g_deltaTime);
};
var eyes = JumpStart.spawnInstance("legacy/v1/models/Sammy/bugeyes.obj", {"parent": this});
eyes.position.copy(bugJoints.eyes);
eyes.JumpStart.blocksLOS = false;
var rearleft = JumpStart.spawnInstance("legacy/v1/models/Sammy/bugrearleft.obj", {"parent": this});
rearleft.JumpStart.blocksLOS = false;
rearleft.position.copy(bugJoints.rearleft);
rearleft.userData.direction = -1.0;
rearleft.JumpStart.targetRot = new THREE.Vector3(0, (Math.PI/14.0), 0);
rearleft.userData.targetRotLerp = 0.0;
rearleft.JumpStart.targetRotOriginal = new THREE.Vector3(0, 0, 0);
rearleft.JumpStart.targetRotLerpTime = 0.4;
rearleft.userData.targetRotCallback = flipFlopWalk;
rearleft.userData.parentBug = this;
rearleft.JumpStart.onTick = legWalk;
var midleft = JumpStart.spawnInstance("legacy/v1/models/Sammy/bugmidleft.obj", {"parent": this});
midleft.position.copy(bugJoints.midleft);
midleft.JumpStart.blocksLOS = false;
midleft.userData.direction = 1.0;
midleft.JumpStart.targetRot = new THREE.Vector3(0, (Math.PI/7.0), 0);
midleft.userData.targetRotLerp = 0.0;
midleft.JumpStart.targetRotOriginal = new THREE.Vector3(0, 0, 0);
midleft.JumpStart.targetRotLerpTime = 0.4;
midleft.userData.targetRotCallback = flipFlopWalk;
midleft.userData.parentBug = this;
midleft.JumpStart.onTick = legWalk;
var frontleft = JumpStart.spawnInstance("legacy/v1/models/Sammy/bugfrontleft.obj", {"parent": this});
frontleft.position.copy(bugJoints.frontleft);
frontleft.JumpStart.blocksLOS = false;
frontleft.userData.direction = -1.0;
frontleft.JumpStart.targetRot = new THREE.Vector3(0, (Math.PI/14.0), 0);
frontleft.userData.targetRotLerp = 0.0;
frontleft.JumpStart.targetRotOriginal = new THREE.Vector3(0, 0, 0);
frontleft.JumpStart.targetRotLerpTime = 0.4;
frontleft.userData.targetRotCallback = flipFlopWalk;
frontleft.userData.parentBug = this;
frontleft.JumpStart.onTick = legWalk;
var rearright = JumpStart.spawnInstance("legacy/v1/models/Sammy/bugrearright.obj", {"parent": this});
rearright.position.copy(bugJoints.rearright);
rearright.JumpStart.blocksLOS = false;
rearright.userData.direction = -1.0;
rearright.JumpStart.targetRot = new THREE.Vector3(0, (Math.PI/7.0), 0);
rearright.userData.targetRotLerp = 0.0;
rearright.JumpStart.targetRotOriginal = new THREE.Vector3(0, 0, 0);
rearright.JumpStart.targetRotLerpTime = 0.4;
rearright.userData.targetRotCallback = flipFlopWalk;
rearright.userData.parentBug = this;
rearright.JumpStart.onTick = legWalk2;
var midright = JumpStart.spawnInstance("legacy/v1/models/Sammy/bugmidright.obj", {"parent": this});
midright.position.copy(bugJoints.midright);
midright.JumpStart.blocksLOS = false;
midright.userData.direction = 1.0;
midright.JumpStart.targetRot = new THREE.Vector3(0, (Math.PI/7.0), 0);
midright.userData.targetRotLerp = 0.0;
midright.JumpStart.targetRotOriginal = new THREE.Vector3(0, 0, 0);
midright.JumpStart.targetRotLerpTime = 0.4;
midright.userData.targetRotCallback = flipFlopWalk;
midright.userData.parentBug = this;
midright.JumpStart.onTick = legWalk2;
var frontright = JumpStart.spawnInstance("legacy/v1/models/Sammy/bugfrontright.obj", {"parent": this});
frontright.position.copy(bugJoints.frontright);
frontright.JumpStart.blocksLOS = false;
frontright.userData.direction = -1.0;
frontright.JumpStart.targetRot = new THREE.Vector3(0, (Math.PI/7.0), 0);
frontright.userData.targetRotLerp = 0.0;
frontright.JumpStart.targetRotOriginal = new THREE.Vector3(0, 0, 0);
frontright.JumpStart.targetRotLerpTime = 0.4;
frontright.userData.targetRotCallback = flipFlopWalk;
frontright.userData.parentBug = this;
frontright.JumpStart.onTick = legWalk2;
/*
var eyes = JumpStart.spawnInstance("legacy/v1/models/Sammy/bugeyes.obj", {"parent": this});
eyes.position.copy(bugJoints.eyes);
eyes.JumpStart.blocksLOS = false;
*/
// this.lookAt(g_camera.position);
}
</script>
</body>
</html>