forked from lo-th/Oimo.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
225 lines (194 loc) · 8.67 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Oimo.js DEV</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=11" />
<link rel="shortcut icon" href="images/favicon.ico">
<style>
body { background-color: #1a1a1a; margin:0; padding:0; overflow: hidden; height:100%;width: 100%; }
@font-face { font-family: 'SourceCode'; src: url('images/SourceCodePro.woff') format('woff');}
a { text-decoration:none; }
</style>
</head>
<body>
<script type="text/javascript" src="js/three.min.js"></script>
<script type="text/javascript" src="js/BufferGeometryUtils.js"></script>
<script type="text/javascript" src="js/tweenLite.min.js"></script>
<script type="text/javascript" src="js/loaders/sea3d/SEA3D.js"></script>
<script type="text/javascript" src="js/loaders/sea3d/SEA3DLoader.js"></script>
<script type="text/javascript" src="js/loaders/sea3d/SEA3DDeflate.js"></script>
<script type="text/javascript" src="js/loaders/sea3d/SEA3DLZMA.js"></script>
<script type="text/javascript" src="js/ThreeEngine.js"></script>
<script type="text/javascript" src="js/Detector.js"></script>
<script type="text/javascript" src="js/loth/Interface.js"></script>
<script type="text/javascript" src="js/loth/AutoTexture.js"></script>
<script type="text/javascript" src="js/loth/Ambience.js"></script>
<script type="text/javascript" src="js/loth/AmbienceMapList.js"></script>
<script type="text/javascript" src="js/loth/Editor.js"></script>
<script type="text/javascript" src="js/GSVPano.min.js"></script>
<script type="text/javascript" src='js/navigatorDetect.js'></script>
<script type="text/javascript">
var version='DEV';
var DemoNames = [
"Basic shape", "Dice fall", "Mad pool",
"Joint test", "Supermarket", "Car simulator",
"Ragdoll", "Van", "Bridge", "Droid"
];
var TE;
var Ambience;
var Interface;
var Editor;
var demoName, demo;
var OimoWorker = new Worker('js/oimo/worker_oimo_dev.js');
OimoWorker.postMessage = OimoWorker.webkitPostMessage || OimoWorker.postMessage;
window.onload = init;
function init() {
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
TE = new ThreeEngine();
Interface = new Interface('dev');
Ambience = new Ambience();
Editor = new Editor();
document.body.appendChild( TE.domElement );
document.body.appendChild( Editor.domElement );
document.body.appendChild( Interface.domElement );
Interface.menu.appendChild( Ambience.domElement );
demoName = Interface.demoName;
TE.init();
}
function mainAllObjectLoaded(){
// start physic worker
OimoWorker.postMessage({tell:"INITWORLD", dt:1/60, iterations:8, G:-10 });
}
//-----------------------------------------------------
// OIMO ON MESSAGE MAIN
//-----------------------------------------------------
OimoWorker.onmessage = function(e) {
var phase = e.data.tell;
// create mesh
if(phase === "INIT"){
TE.createObjects(e.data);
TE.createJoints(e.data.joints);
demo = e.data.demo;
if( demo !== -1) {
demoName(DemoNames[demo]);
}
OimoWorker.postMessage({tell:"UPDATE"});
}
// create static mesh debug
if(phase === "INITSTATIC"){
TE.createStaticObjects(e.data);
}
if( phase === "REMOVE"){TE.removeObject(e.data.n);}
// update three object
if( phase === "RUN"){
//var demo = e.data.infos[0];
var max = e.data.maxBody;
var i = max;
var m = e.data.matrix;
var mtx = new THREE.Matrix4();
var mesh;
// Update rendering meshes
while (i--) {
if( TE.content.children[i] ){
mesh = TE.content.children[i];
if( e.data.sleeps[i]===0){
mtx.fromArray( m[i] );
mesh.position.setFromMatrixPosition( mtx )
mesh.rotation.setFromRotationMatrix( mtx );
if(mesh.material){
if(mesh.material.name == "mat01sleep") mesh.material = TE.materials[0];
else if(mesh.material.name == "mat02sleep") mesh.material = TE.materials[1];
else if(mesh.material.name == "mat03sleep") mesh.material = TE.materials[2];
else if(mesh.material.name == "mat04sleep") mesh.material = TE.materials[3];
else if(mesh.material.name == "mat07sleep") mesh.material = TE.materials[6];
}
} else {
if(mesh.material){
if(mesh.material.name == "mat01") mesh.material = TE.materials[8];
else if(mesh.material.name == "mat02") mesh.material = TE.materials[9];
else if(mesh.material.name == "mat03") mesh.material = TE.materials[10];
else if(mesh.material.name == "mat04") mesh.material = TE.materials[11];
else if(mesh.material.name == "mat07") mesh.material = TE.materials[12];
}
}
}
}
// Update rendering joints
i = e.data.maxJ;
var jointPos = e.data.jointPos;
while (i--) {
if( TE.contentJoint.children[i] ){
n = 6*i
mesh = TE.contentJoint.children[i];
mesh.geometry.vertices[0].set( jointPos[n+0], jointPos[n+1], jointPos[n+2] );
mesh.geometry.vertices[1].set( jointPos[n+3], jointPos[n+4], jointPos[n+5] );
mesh.geometry.verticesNeedUpdate = true;
}
}
//skin update
if(demo === 3) TE.updateSnake();
if(demo === 6) TE.updateSila();
displayInfo(e.data.infos);
}
// clear three object
if(phase === "CLEAR"){
TE.clearAll();
// start new demo from editor
if(basicOption!==null){
OimoWorker.postMessage(basicOption);
basicOption=null;
if(Editor.getScript()) initDemo();
}
}
// get ragdoll info
if(phase === "GETBONES") TE.getSqueletonStructure(e.data.name);
if(phase === "GRAVITY") Interface.setCurrentGravity(e.data.G);
if(phase === "SET"){ SET = e.data.selects; endDemo(); }
}
//-----------------------------------------------------
// OIMO POST MESSAGE FUNCTION
//-----------------------------------------------------
function sendKey(key){ OimoWorker.postMessage({tell:"KEY", key:key}); }
function sendCameraOrientation(phi, theta){ OimoWorker.postMessage({tell:"CAMERA", cam:[phi, theta]}); }
function prevDemo(){ OimoWorker.postMessage({tell:"PREV"}); }
function nextDemo(){ OimoWorker.postMessage({tell:"NEXT"}); }
function changeGravity(G){ OimoWorker.postMessage({tell:"GRAVITY", G:G}); }
//-----------------------------------------------------
// TRANSE SCRIPT
//-----------------------------------------------------
var basicOption = null;
var SET = null;
var CAM = function(h, v, d){ TE.changeView(h, v, d); }
var ADD = function(obj){ TE.ADD(obj); }
var GET = function(names){ OimoWorker.postMessage({tell:"GET", names:names}); }
var CLEAR = function(obj){
basicOption = obj || {ground:false};
basicOption.tell = "BASIC";
OimoWorker.postMessage({tell:"CLEAR"});
}
//-----------------------------------------------------
// OIMO INFO
//-----------------------------------------------------
function displayInfo(a){
var info =[
"Rigidbody: "+a[1]+"<br>",
"Contact: "+a[2]+"<br>",
"Pair Check: "+a[3]+"<br>",
"Contact Point: "+a[4]+"<br>",
"Island: " + a[5] +"<br><br>",
"Broad-Phase Time: " + a[6] + " ms<br>",
"Narrow-Phase Time: " + a[7] + " ms<br>",
"Solving Time: " + a[8] + " ms<br>",
"Updating Time: " + a[9] + " ms<br>",
"Total Time: " + a[10] + " ms<br><br>",
"Physics: " + a[11] +" fps / "+a[12]+" ms<br>",
"Render: " + TE.getFps()+"<br><br>",
"Selected: "+ TE.getSelected()
].join("\n");
document.getElementById("output").innerHTML = info;
}
</script>
</body>
</html>