-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
208 lines (191 loc) · 6.76 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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Mechanical Morphogenesis</title>
<script src="lib/jquery-1.8.2.min.js"></script>
<script src="lib/three.min.js"></script>
<script src="lib/TrackballControls.js"></script>
<style>
.v {
color:black;
}
.t {
color:gray;
}
.collide {
color:red;
}
</style>
</head>
<body>
<div style="font-family:sans-serif;font-size:12px;border:thin solid #bbb;padding:5px;position:absolute;top:10px;left:10px;z-index:10;background-color:rgba(255,255,255,0.8)">
<table id="params"></table>
<div id="log" style="border:thin solid lightGrey;padding:10px"></div>
<button id="restart">Restart</button>
<button id="startStop">Stop</button>
<a id="saveParams" href=# >Save Params</a>
</div>
<script src="algebra.js"></script>
<script src="geometry.js"></script>
<script src="growth.js"></script>
<script src="mechanics.js"></script>
<script src="display.js"></script>
<script src="simulation.js"></script>
<script src="collision.js"></script>
<script src="presets.js"></script>
<script>
var menus={
preset: ["Block Border","U Block Collision","Ring Tangential","Ring Border","Sphere Surface","Sphere Surface Fine","Ellipsoid Surface"],
growth: ["homogeneous","block border instantaneous","ring tangential instantaneous","ring border instantaneous","surface homogeneous instantaneous"],
geometry: ["block","ublock","ring","surface"],
colormap: ["normal","deformation"]
};
// get model preset from URL (use BlockBorder by default)
var args=getArguments();
simulationParams=getPresetParams(args.model);
setParams(simulationParams,menus);
// init display
display=initDisplay(simulationParams);
// start simulation
initSimulation(simulationParams)
.then(function(sim) {
simulation=sim;
initMesh(display,simulation,simulationParams);
// trigger animation
animate();
});
$("body").on('change', "#preset", function() {
simulationParams=getPresetParams($("#preset").val());
setParams(simulationParams,menus);
initSimulation(simulationParams)
.then(function(sim) {
simulation=sim;
initMesh(display,simulation,simulationParams);
});
});
$("#restart").click(function(){
simulationParams=getParams();
initSimulation(simulationParams)
.then(function(sim) {
simulation=sim;
initMesh(display,simulation,simulationParams);
});
});
$("#startStop").click(function(){
pauseResume();
});
$("#saveParams").click(function(){
var data = getParams();
data.t = simulation.time.toFixed(4);
data.Ue = simulation.me.Ue.toFixed(2);
var name = prompt("Preset name",data.preset);
if(name==undefined)
return;
data.preset=name;
var paramExport = JSON.stringify( data );
var paramExportData = 'data:application/csv;charset=utf-8,' + encodeURIComponent( paramExport );
this.href = paramExportData;
this.target = '_blank';
this.download = name+'.json';
});
function getArguments() {
var search = location.search.substring(1);
return search?JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
function(key, value) { return key===""?value:decodeURIComponent(value) }):{}
}
function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}
function setParams(param,menus) {
console.log("set parametres",param);
var i,j,key,type,val,sel;
$(".param").remove();
for(key in param) {
val=param[key];
// handle menus
if(menus[key]!=undefined) {
var str;
str="<tr class='param'><td>"+key+"</td><td><select id='"+key+"' class='string'>";
for(j in menus[key])
str+="<option value='"+menus[key][j]+"'>"+menus[key][j]+"</option>";
str+="</select></td></tr>";
$("#params").append(str);
$("#"+key).val(val);
continue;
}
// handle single value fields
type=typeof val;
switch(type) {
case "number":
case "string":
$("#params").append("<tr class='param'><td>"+key+"</td><td><input type='text' class='"+type+"' id='"+key+"' size='10'/></td></tr>");
$("#"+key).val(param[key].toString());
break;
case "boolean":
$("#params").append("<tr class='param'><td>"+key+"</td><td><input type='checkbox' class='"+type+"' id='"+key+"' size='10'/></td></tr>");
$("#"+key).prop('checked',param[key]);
break;
}
}
}
function getParams() {
var param={};
$(".param").each(function(i){
var key,val,type;
key=$(this).find("td")[0].innerHTML;
type=$("#"+key).attr('class');
switch(type) {
case "boolean":
val=$("#"+key).prop('checked');
break;
case "number":
val=JSON.parse($("#"+key).val());
break;
case "string":
val=$("#"+key).val();
break;
}
param[key]=val;
});
return param;
}
function getPresetParams(presetName) {
var param;
switch(presetName) {
case "BlockBorder":
case "Block Border":
param=clone(BlockBorder);
break;
case "UBlockCollision":
case "U Block Collision":
param=clone(UBlockCollision);
break;
case "RingTangential":
case "Ring Tangential":
param=clone(RingTangential);
break;
case "RingBorder":
case "Ring Border":
param=clone(RingBorder);
break;
case "Sphere":
case "Sphere Surface":
param=clone(SphereSurface);
break;
case "SphereFine":
case "Sphere Surface Fine":
param=clone(SphereSurfaceFine);
break;
case "Ellipsoid":
case "Ellipsoid Surface":
param=clone(EllipsoidSurface);
break;
default:
param=clone(BlockBorder);
}
return param;
}
</script>
</body>
</html>