-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemotest1.html
255 lines (219 loc) · 9.41 KB
/
demotest1.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ObjectCloner</title>
<!-- Babylon.js -->
<script src="lib/b3alpha.max.js"></script>
<script src="lib/babylon.marbleProceduralTexture.js"></script>
<script src="lib/dat.gui.min.js"></script>
<script src="src/cloner.js"></script>
<style>
html,
body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0px;
background-color: #333344;
}
#target {
position: absolute;
top: 0em;
left: 0em;
}
#btest {
position: absolute;
top: 6em;
left: 15em;
}
#btest2 {
position: absolute;
top: 8em;
left: 15em;
}
#sliderCount {
position: absolute;
top: 8em;
left: 3em;
}
#sliderGrowth {
position: absolute;
top: 10em;
left: 3em;
}
#renderCanvas {
width: 100%;
height: 100%;
padding: 0px;
}
.dg {
color: #00AA00;
text-shadow: none !important;
}
</style>
</head>
<body bgcolor="#333344" oncontextmenu="return false; ">
<canvas id="renderCanvas"></canvas>
<script>
/*
*/
var gui = new dat.GUI({
height: 5 * 32 - 1
});
var matrix_params = {
countX: 4,
countY: 4,
countZ: 4,
sizeX: 2,
sizeY: 2,
sizeZ: 2,
peffectorstrength: 1,
interpolmode: "step"
}
var rand_params = {
strength: 0,
PX: 0,
PY: 0,
PZ: 0,
SX: 1,
SY: 1,
SZ: 1,
RX: 0,
RY: 0,
RZ: 0,
uniformScale:false,
seed: 123
}
var ani_params= {
animate:false
}
var g_animate=false;
function init_gui() {
var pcontroller = {};
var scontroller = {};
var rcontroller = {};
var rpcontroller = {};
var rscontroller = {};
var rrcontroller = {};
var mcount = {};
var msize = {};
var mf = gui.addFolder("ObjectCloner");
var handleCount=function() {
mm.mcount={x:mcount.x.getValue(),y:mcount.y.getValue(),z:mcount.z.getValue()};
};
mcount.x=mf.add(matrix_params, 'countX').min(1).max(9).step(1).onChange(function (value) {handleCount()});
mcount.y=mf.add(matrix_params, 'countY').min(1).max(9).step(1).onChange(function (value) {handleCount()});
mcount.z=mf.add(matrix_params, 'countZ').min(1).max(9).step(1).onChange(function (value) {handleCount()});
var handleSize=function() {
mm.size={x:msize.x.getValue(),y:msize.y.getValue(),z:msize.z.getValue()};
}
msize.x=mf.add(matrix_params, 'sizeX').min(0).max(50).step(.01).onChange(function (value) {handleSize() });
msize.y=mf.add(matrix_params, 'sizeY').min(0).max(50).step(.01).onChange(function (value) {handleSize() });
msize.z=mf.add(matrix_params, 'sizeZ').min(0).max(50).step(.01).onChange(function (value) {handleSize() });
mf.add(matrix_params, 'interpolmode', ['step', 'end']).onChange(function (value) {
});
mf.add(matrix_params, 'peffectorstrength').name("Sens.Effector1").min(0).max(1).step(.02).onChange(function (value) {
oc.effectors[0].sensitivity = value; oc.update();
});
var re = gui.addFolder("RandomEffector");
re.add(rand_params, 'strength').min(0).max(1).step(.02).onChange(function (value) { reff.strength = value; reff.updateClients() });
re.add(rand_params,'seed').min(1).max(1000).step(1).onChange(function (value) {reff.seed=value;reff.updateClients() });
f1 = re.addFolder('Random-Position');
rpcontroller.x = f1.add(rand_params, 'PX').min(-20).max(20).step(1).onChange(function (value) { reff.position = { x: rpcontroller.x.getValue(), y: rpcontroller.y.getValue(), z: rpcontroller.z.getValue() }; reff.updateClients() });
rpcontroller.y = f1.add(rand_params, 'PY').min(-20).max(20).step(1).onChange(function (value) { reff.position = { x: rpcontroller.x.getValue(), y: rpcontroller.y.getValue(), z: rpcontroller.z.getValue() }; reff.updateClients() });
rpcontroller.z = f1.add(rand_params, 'PZ').min(-20).max(20).step(1).onChange(function (value) { reff.position = { x: rpcontroller.x.getValue(), y: rpcontroller.y.getValue(), z: rpcontroller.z.getValue() }; reff.updateClients() });
f1 = re.addFolder('Random-Scale');
var handleScale=function(value) {
let x=rscontroller.x.getValue();
let y=rscontroller.y.getValue();
let z=rscontroller.z.getValue();
let u=rscontroller.u.getValue();
if(u) {
y=z=x;
}
reff.scale = { x: x, y: y, z: z,u:u };
reff.updateClients();
}
rscontroller.x = f1.add(rand_params, 'SX').min(-1).max(5).step(.1).onChange(function(value){handleScale(value)});
rscontroller.y = f1.add(rand_params, 'SY').min(-1).max(5).step(.1).onChange(function(value){handleScale(value)});
rscontroller.z = f1.add(rand_params, 'SZ').min(-1).max(5).step(.1).onChange(function(value){handleScale(value)});
rscontroller.u= f1.add(rand_params, 'uniformScale').onChange(function (value) {
rscontroller.y.domElement.hidden=value;
rscontroller.z.domElement.hidden=value;
handleScale(value);
});
var handleRotation=function(value) {
let x=rrcontroller.x.getValue();
let y=rrcontroller.y.getValue();
let z=rrcontroller.z.getValue();
reff.rotation = { x: x, y: y, z: z };
reff.updateClients()
}
f1 = re.addFolder('Random-Rotation')
rrcontroller.x = f1.add(rand_params, 'RX').min(-360).max(360).step(1).onChange(function (value) {handleRotation(value) });
rrcontroller.y = f1.add(rand_params, 'RY').min(-360).max(360).step(1).onChange(function (value) {handleRotation(value) });
rrcontroller.z = f1.add(rand_params, 'RZ').min(-360).max(360).step(1).onChange(function (value) {handleRotation(value) });
gui.add(ani_params,"animate").onChange(function (value) {
g_animate=value;
if(value==true) {
//reff.position = {x:15,y:15,z:15};
//reff.rotation = {x:238*5,y:200*5,z:200*5};
reff.scale= {x:1.0,y:1.0,z:1.0,u:true};
reff.strength=1;
//mm.mcount={x:9,y:9,z:1}
//mm.size={x:2,y:2,z:2}
} else {
reff.position = {x:0,y:0,z:0};
reff.rotation = {x:0,y:0,z:0};
reff.scale= {x:0,y:0,z:0,u:true};
reff.strength=0;
reff.updateClients();
}
});
//
}
init_gui();
var demo = new BABYLONX.Demoscene();
demo.init();
var demomeshes= new BABYLONX.Demomeshes(demo.scene);
var scene=demo.scene;
//demo._scene.debugLayer.show();
var matrix_opts = {
iModeStep: matrix_params.interpolmode == "step",
size: {x:matrix_params.sizeX,y:matrix_params.sizeY,z:matrix_params.sizeZ},
mcount: {x:matrix_params.countX,y:matrix_params.countY,z:matrix_params.countZ},
useInstances: true
}
var matrix_opts2 = {
iModeStep: matrix_params.interpolmode == "step",
size: {x:matrix_params.sizeX*6,y:matrix_params.sizeY*6,z:matrix_params.sizeZ*6},
mcount: {x:matrix_params.countX,y:matrix_params.countY,z:matrix_params.countZ},
useInstances: true
}
var rad_opts = {
count: 5,
radius: 10,
}
var box1 = demomeshes.createCube({w:0.425,h:0.425,d:0.425},"#DAA520");
var box2 = demomeshes.createCube({w:1,h:0.5,d:0.5}, "#DCDCDC");
var box3 = demomeshes.createCube({w:0.5,h:0.5,d:1}, "#DA6620");
var sph2= demomeshes.createSphere(.5, "#55FFDC",16);
//var sph1 = demomeshes.createIcoSphere(8);
var oc=new BABYLONX.MatrixCloner([box1,box2,box3,sph2], scene);
var reff = new BABYLONX.RandomEffector();
oc.addEffector(reff,matrix_params.peffectorstrength);
var frame = 0;
demo.scene.registerBeforeRender(function () {
frame++;
oc.root.rotation.y += 0.0015;
//mm2.root.rotation.y -= 0.01;
if(g_animate) {
oc.effectors[0].sensitivity=Math.sin(frame*.14)*Math.sin(frame*.14);
reff.updateClients();
}
});
</script>
</body>
</html>