forked from smsithlord/JumpStart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
136 lines (112 loc) · 3.46 KB
/
example.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example Project</title>
<script src="engine/misc/JumpStart.js"></script>
<script>
loadJumpStart({
"multiuserOnly": true,
"debug": {"showCursorPlanes": true}
});
function spin()
{
this.rotateY(1.0 * jumpStart.deltaTime);
}
function extraRemove()
{
console.log("Object removed listener.");
}
jumpStart.addEventListener("precache", function()
{
// Async
jumpStart.loadModels(["models/block"]).then( function()
{
jumpStart.doneCaching();
});
// true : SYNCHRONOUS
// false: ASYNCHRONOUS (must call JumpStart.doneCaching)
return false;
});
jumpStart.addEventListener("initialize", function()
{
console.log("initing");
// This listener only gets called when initializing the room of a multiuser app.
var extraBlock = jumpStart.spawnInstance("models/block");
extraBlock.name = "globalBlock";
extraBlock.scale.set(2, 2, 2);
//extraBlock.position.y += 250.0;
//extraBlock.applyBehavior("physics");
//extraBlock.addEventListener("spawn", testerSpawn);
// extraBlock.translateY(200);
// extraBlock.addEventListener("tick", spin);
// extraBlock.addEventListener("remove", extraRemove);
// extraBlock.syncData.myVar = "5150";
extraBlock.sync();
// true : SYNCHRONOUS
// false: ASYNCHRONOUS (must call JumpStart.doneInitializing)
return true;
});
jumpStart.addEventListener("ready", function()
{
var floorBoundary = jumpStart.enclosureBoundary("floor");
floorBoundary.addEventListener("cursordown", function()
{
var extraBlock = jumpStart.scene.getObjectByName("globalBlock");
extraBlock.applyBehavior("physics");
extraBlock.sync();
});
var cursor = jumpStart.spawnInstance("models/block");
cursor.addEventListener("tick", function()
{
if( !jumpStart.localUser.cursorHit )
return;
var pos = jumpStart.localUser.cursorHit.scaledPoint.clone();
pos.y += 100.0;
this.position.copy(pos);
});
cursor.translateY(100);
var myObject = jumpStart.spawnInstance("models/block");
myObject.blocksLOS = true;
myObject.addEventListener("tick", function()
{
this.rotateY(2.0 * jumpStart.deltaTime);
});
myObject.addEventListener("cursorenter", function()
{
console.log("Object is being highlighted (and then scaled)! " + this);
this.scale.set(2, 2, 2);
});
myObject.addEventListener("cursorexit", function()
{
console.log("Object is being un-highlighted (then scaled)! " + this);
this.scale.set(1, 1, 1);
});
myObject.addEventListener("cursordown", function()
{
console.log("Object is being clicked down (then shifted on x-axis)! " + this);
myObject.translateX(20.0);
jumpStart.world.translateX(100.0);
});
myObject.addEventListener("cursorup", function()
{
console.log("Object is being clicked up (then removing globalBlock)! " + this);
// var extraBlock = jumpStart.scene.getObjectByName("globalBlock");
// jumpStart.removeInstance(extraBlock);
});
myObject.addEventListener("spawn", function()
{
console.log("Object is being spawned! " + this);
});
myObject.addEventListener("remove", function()
{
console.log("Object is being removed! " + this);
});
// true : SYNCHRONOUS
// false: ASYNCHRONOUS (must call JumpStart.run)
return true;
});
</script>
</head>
<body>
</body>
</html>