/
CloudsProcedural4.x3d
439 lines (295 loc) · 14.3 KB
/
CloudsProcedural4.x3d
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.2//EN" "https://www.web3d.org/specifications/x3d-3.2.dtd">
<X3D profile='Immersive' version='3.2' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.2.xsd'>
<head>
<meta content='CloudsProcedural4.x3d' name='title'/>
<meta content='X3D utilizing ecmascript to develop quasi volumetric 3D clouds from png image textured billboard nodes.' name='description'/>
<meta content='Capt Darren W. Murphy' name='creator'/>
<meta content='1 November 2007' name='created'/>
<meta content='14 January 2014' name='modified'/>
<meta content='https://savage.nps.edu/Savage/Environment/Atmosphere/CloudsProcedural4.x3d' name='identifier'/>
<meta content='X3D-Edit, https://www.web3d.org/x3d/content/README.X3D-Edit.html' name='generator'/>
<meta content='../../license.html' name='license'/>
<meta content='fix links' name='TODO'/>
</head>
<Scene>
<!-- A png image file for the cloud texture must be designated in the ecmascript node. -->
<Viewpoint description='Main' jump='false' orientation='0 1 0 1.57' position='50000 1000 42000'/>
<Viewpoint description='Light House Tower' jump='false' orientation='0 1 0 1.3' position='45000 1290 44000'/>
<Viewpoint description='centerWest' jump='false' orientation='0 1 0 2.5' position='48000 1000 20000'/>
<Background groundColor='0 0 1' skyColor='0 0 1'/>
<DirectionalLight ambientIntensity='1' direction='-1 0 0' global='true'/>
<Group DEF='Terrain'>
<Transform scale='50 50 50' translation='25000 0 25000'>
<Inline url='"MontereyBayLargeMesh.x3d" "https://savage.nps.edu/Savage/Environment/Atmosphere/MontereyBayLargeMesh.x3d" "MontereyBayLargeMesh.wrl" "https://savage.nps.edu/Savage/Environment/Atmosphere/MontereyBayLargeMesh.wrl"'/>
</Transform>
<Transform rotation='1 0 0 1.57' translation='25000 0 25000'>
<Shape>
<Rectangle2D size='77000 55000'/>
<Appearance>
<ImageTexture url='"ocean.png" "https://savage.nps.edu/Savage/Environment/Atmosphere/ocean.png"'/>
</Appearance>
</Shape>
</Transform>
</Group>
<Group DEF='Placemarks'>
<Transform scale='50 50 50' translation='45000 30 44000'>
<Inline url='"Lighthouse.x3d" "https://savage.nps.edu/Savage/Environment/Atmosphere/Lighthouse.x3d" "Lighthouse.wrl" "https://savage.nps.edu/Savage/Environment/Atmosphere/Lighthouse.wrl"'/>
</Transform>
</Group>
<Group DEF='Clouds'>
<Transform DEF='Cumulus'/>
<Transform DEF='Cirrus'/>
<Transform DEF='Fog'/>
<Script DEF='PixelScript' directOutput='true'>
<field accessType='initializeOnly' name='Cumulus' type='SFNode'>
<Transform USE='Cumulus'/>
</field>
<field accessType='initializeOnly' name='Cirrus' type='SFNode'>
<Transform USE='Cirrus'/>
</field>
<field accessType='initializeOnly' name='Fog' type='SFNode'/>
<![CDATA[
ecmascript:
function cumulustranslation() // These values designate the boundary location of the cloud
{
X = 50000*Math.random(); // X horizontal range
Y = 1000 + 300*Math.random(); // Y vertical base + range
Z = 50000*Math.random(); // z horizontal range
randomt = new String(X+' '+Y+' '+Z);
return randomt;
}
function cumulusscale() // these values scale a cloud within a designated size
{
var maxscale = 1;
scale = Math.round(9+maxscale*Math.random());
X = 1.5*scale;
Y = scale;
Z = scale;
randomscale = new String(X+' '+Y+' '+Z);
return randomscale;
}
function cirrustranslation() // These values designate the boundary location of the cloud
{
X = 50000*Math.random(); // X horizontal range
Y = 8000 + 1000*Math.random(); // Y vertical base + range
Z = 50000*Math.random(); // z horizontal range
randomt = new String(X+' '+Y+' '+Z);
return randomt;
}
function cirrusscale() // these values scale a cloud within a designated size
{
var maxscale = 1;
scale = Math.round(9+maxscale*Math.random());
X = 1.5*scale;
Y = 2*Math.random();
Z = 1.5*scale;
randomscale = new String(X+' '+Y+' '+Z);
return randomscale;
}
function cumulussectiontranslation() // These random values place another portion of cumulus type cloud
{
randomtheta = 6.28319*Math.random();
randomphi = .7854*Math.random();
randomradius = 90 + 5*Math.random();//the first whole number should be close to the sectionradius
X = randomradius*Math.cos(randomtheta)*Math.sin(randomphi);
Z = randomradius*Math.sin(randomtheta)*Math.sin(randomphi);
Y = randomradius*Math.cos(randomphi);
randomt = new String(X+' '+Y+' '+Z);
return randomt;
}
function cirrussectiontranslation() // These random values place another portion of cirrus type cloud
{
randomtheta = 6.28319*Math.random();
randomphi = .7854*Math.random();
randomradius = 90 + 5*Math.random();//the first whole number should be close to the sectionradius
X = randomradius*Math.cos(randomtheta)*Math.sin(randomphi);
Z = randomradius*Math.sin(randomtheta)*Math.sin(randomphi);
Y = randomradius*Math.cos(randomphi);
randomt = new String(X+' '+Y+' '+Z);
return randomt;
}
function rotation() // This random value is for the billboard rotation not used in this script
{
radians = 6.28*Math.random();
randomr = new String('0 0 1 ' + radians );
return randomr;
}
function cumulus()
{
var maxi = 20; // number of clouds
var maxj = 5; // denotes how many portions affecting the size of the cloud
var maxk = 8; // number of billboards indicating cloud density
var sectionradius = 100; //radius of individual cloud sections
for (var i=0; i < maxi; i++)
{
CloudStringA = ' Transform { \n' +
' scale '+ cumulusscale() + ' \n' +
' translation '+ cumulustranslation() + ' \n' + // cloud placement
' children [ \n';
CloudStringB = new Array();
CloudStringF = new Array();
for (var j=0; j < maxj; j++)
{
radius = 0;
CloudStringB[j]= ' Transform { \n' +
' translation '+ cumulussectiontranslation() + ' \n' + // section placement
' children [ \n';
CloudStringC = new Array();
image = new String();
for (var k=1; k < maxk; k++) // maxk value denotes how many textured billboards make up the cloud
{
randomtheta = 6.28319*Math.random();
randomphi = 1.57079*Math.random();
radius = radius+(sectionradius/maxk); // radius incremental steps based on billow radius and max billboards
X = radius*Math.cos(randomtheta)*Math.sin(randomphi);
Z = radius*Math.sin(randomtheta)*Math.sin(randomphi);
Y = radius*Math.cos(randomphi);
if (Y <= 30) //cloud shading and lighting control
{
image = ' \"CloudTexture1_5.png\" \"https://savage.nps.edu/Savage/Environment/Spheretexture.png\" \n';
}
else
{
image = ' \"CloudTexture1_4.png\" \"https://savage.nps.edu/Savage/Environment/Spheretexture.png\" \n';
}
Billboardtranslation = new String(X+' '+Y+' '+Z);
CloudStringC[k] = ' Transform { \n' +
' translation '+ Billboardtranslation + ' \n' + // random billboard placement within radius designated above
' children [ \n' +
' Billboard { \n' +
' axisOfRotation 0 0 0 \n' + // 0 0 0 designates rotation on all axis
' children [ \n' +
' Transform { \n' +
' rotation 0 0 0 0 \n' + // a rotation of the individual billboards can be defined
' children [ \n' +
' Shape { \n' +
' appearance Appearance { \n' +
' material Material { \n' +
' } \n' +
' texture ImageTexture { \n' +
' url [ ' + image + ' ] \n' +
' } \n' +
' } \n' +
' geometry IndexedFaceSet { \n' + // define type of geometry to texture
' coordIndex [ 0, 1, 2, 3 ] \n' +
' solid FALSE \n' +
' coord Coordinate { \n' +
' point [ 50 50 0, \n' + // define size of the geometry. Here 100 meter 2D square.
' 50 -50 0, \n' +
' -50 -50 0, \n' +
' -50 50 0 ] \n' +
' } \n' +
' } \n' +
' } \n' +
' ] \n' +
' } \n' +
' ] \n' +
' } \n' +
' ] \n' +
' } \n';
}
CloudStringD = CloudStringC.join(' ');
CloudStringE = ' ] \n' +
' } \n';
CloudStringF[j] = CloudStringB[j] + CloudStringD +CloudStringE;
}
CloudStringG = CloudStringF.join(' ');
CloudStringH = ' ] \n' +
' } \n' +
'######################################################### \n';
CloudString = CloudStringA + CloudStringG + CloudStringH;
newNode = Browser.createVrmlFromString(CloudString);
Cumulus.children[i] = newNode[0];
}
}
function cirrus()
{
var maxi = 2; // number of clouds
var maxj = 5; // denotes how many portions affecting the size of the cloud
var maxk = 8; // number of billboards indicating cloud density
var sectionradius = 1000; //radius of individual cloud sections
for (var i=0; i < maxi; i++)
{
CloudStringA = ' Transform { \n' +
' scale '+ cirrusscale() + ' \n' +
' translation '+ cirrustranslation() + ' \n' + // cloud placement
' children [ \n';
CloudStringB = new Array();
CloudStringF = new Array();
for (var j=0; j < maxj; j++)
{
radius = 0;
CloudStringB[j]= ' Transform { \n' +
' translation '+ cirrussectiontranslation() + ' \n' + // section placement
' children [ \n';
CloudStringC = new Array();
for (var k=1; k < maxk; k++) // maxk value denotes how many textured billboards make up the cloud
{
randomtheta = 6.28319*Math.random();
randomphi = 1.57079*Math.random();
radius = radius+(sectionradius/maxk); // radius incremental steps based on section radius and max billboards
X = radius*Math.cos(randomtheta)*Math.sin(randomphi);
Z = radius*Math.sin(randomtheta)*Math.sin(randomphi);
Y = radius*Math.cos(randomphi);
Billboardtranslation = new String(X+' '+Y+' '+Z);
CloudStringC[k] = ' Transform { \n' +
' translation '+ Billboardtranslation + ' \n' + // random billboard placement within radius designated above
' children [ \n' +
' Billboard { \n' +
' axisOfRotation 0 0 0 \n' + // 0 0 0 designates rotation on all axis
' children [ \n' +
' Transform { \n' +
' rotation ' + rotation() + ' \n' +
' children [ \n' +
' Shape { \n' +
' appearance Appearance { \n' +
' material Material { \n' +
' } \n' +
' texture ImageTexture { \n' +
' url [\"cloudtexture3.png\" \"https://savage.nps.edu/Savage/Environment/cloudtexture1_4.png\" ] \n' +
' } \n' +
' } \n' +
' geometry IndexedFaceSet { \n' + // define type of geometry to texture
' coordIndex [ 0, 1, 2, 3 ] \n' +
' solid FALSE \n' +
' coord Coordinate { \n' +
' point [ 500 500 0, \n' + // define size of the geometry. Here 100 meter 2D square.
' 500 -500 0, \n' +
' -500 -500 0, \n' +
' -500 500 0 ] \n' +
' } \n' +
' } \n' +
' } \n' +
' ] \n' +
' } \n' +
' ] \n' +
' } \n' +
' ] \n' +
' } \n';
}
CloudStringD = CloudStringC.join(' ');
CloudStringE = ' ] \n' +
' } \n';
CloudStringF[j] = CloudStringB[j] + CloudStringD +CloudStringE;
}
CloudStringG = CloudStringF.join(' ');
CloudStringH = ' ] \n' +
' } \n' +
'######################################################### \n';
CloudString = CloudStringA + CloudStringG + CloudStringH;
newNode = Browser.createVrmlFromString(CloudString);
Cirrus.children[i] = newNode[0];
}
}
function initialize()
{
cumulus();
cirrus();
}
]]>
</Script>
<DirectionalLight ambientIntensity='1' color='1 0 0' direction='-1 -1 0' global='true'/>
</Group>
</Scene>
</X3D>