uil 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -5
  3. package/examples/js/BufferGeometryUtils.js +0 -921
  4. package/examples/js/SimplexNoise.js +0 -324
  5. package/examples/js/controls/OrbitControls.js +0 -1215
  6. package/examples/js/controls/OrbitControls_.js +0 -1042
  7. package/examples/js/libs/sea3d.min.js +0 -373
  8. package/examples/js/libs/three.min.js +0 -6
  9. package/examples/js/math.js +0 -447
  10. package/examples/js/objects/Landscape.js +0 -778
  11. package/examples/js/objects/Lensflare.js +0 -372
  12. package/examples/js/objects/SuperSky.js +0 -297
  13. package/examples/js/objects/Water.js +0 -329
  14. package/src/Uil.js +0 -6
  15. package/src/Uil_dev.js +0 -15
  16. package/src/core/Gui.js +0 -807
  17. package/src/core/Proto.js +0 -679
  18. package/src/core/Roots.js +0 -864
  19. package/src/core/Tools.js +0 -830
  20. package/src/core/V2.js +0 -131
  21. package/src/core/add.js +0 -85
  22. package/src/polyfills.js +0 -85
  23. package/src/proto/Bool.js +0 -147
  24. package/src/proto/Button.js +0 -357
  25. package/src/proto/Circular.js +0 -230
  26. package/src/proto/Color.js +0 -411
  27. package/src/proto/Empty.js +0 -15
  28. package/src/proto/Fps.js +0 -327
  29. package/src/proto/Graph.js +0 -310
  30. package/src/proto/Grid.js +0 -297
  31. package/src/proto/Group.js +0 -430
  32. package/src/proto/Item.js +0 -120
  33. package/src/proto/Joystick.js +0 -241
  34. package/src/proto/Knob.js +0 -262
  35. package/src/proto/List.js +0 -789
  36. package/src/proto/Numeric.js +0 -417
  37. package/src/proto/Pad2D.js +0 -268
  38. package/src/proto/Rubric.js +0 -0
  39. package/src/proto/Select.js +0 -178
  40. package/src/proto/Selector.js +0 -13
  41. package/src/proto/Slide.js +0 -267
  42. package/src/proto/TextInput.js +0 -181
  43. package/src/proto/Title.js +0 -61
@@ -1,778 +0,0 @@
1
-
2
-
3
-
4
- var Landscape = function ( o ) {
5
-
6
- o = o === undefined ? {} : o;
7
-
8
- this.ready = false;
9
-
10
- this.type = 'terrain';
11
-
12
- this.callback = o.callback || null;
13
-
14
- this.perlin = null;
15
-
16
-
17
- this.p90 = Math.PI*0.5;
18
-
19
- this.textures = {};
20
- this.loaderMap = null;
21
-
22
- this.mapN = 0;
23
- this.mapMax = 6;
24
-
25
- // terrain, water, road
26
- this.ttype = o.terrainType || 'terrain';
27
-
28
- this.callback = o.callback || null;
29
- //this.physicsUpdate = function(){};
30
-
31
- this.uvx = [ o.uv || 18, o.uv || 18 ];
32
-
33
-
34
- this.sample = o.sample == undefined ? [128,128] : o.sample;
35
- this.size = o.size === undefined ? [100,30,100] : o.size;
36
-
37
- this.data = o.data || {
38
- move:[0,0],
39
- height: this.size[1],
40
- level: o.level || [1,0.2,0.05],
41
- frequency: o.frequency || [0.016,0.05,0.2],
42
- expo: o.expo || 1,
43
- }
44
-
45
- this.isWater = o.water || false;
46
-
47
- this.isBorder = false;
48
- this.wantBorder = o.border || false;
49
-
50
- this.isBottom = false;
51
- this.wantBottom = o.bottom || false;
52
- this.wantBorder = o.border || false;
53
-
54
- this.colorBase = this.isWater ? { r:0, g:0.7, b:1 } : { r:0.25, g:0.25, b:0.25 };
55
-
56
- this.maxspeed = o.maxSpeed || 0.1;
57
- this.acc = o.acc == undefined ? 0.01 : o.acc;
58
- this.dec = o.dec == undefined ? 0.01 : o.dec;
59
-
60
- this.deep = o.deep == undefined ? 0 : o.deep;
61
-
62
- this.ease = new THREE.Vector2();
63
-
64
- // for perlin
65
- this.complexity = o.complexity == undefined ? 30 : o.complexity;
66
- this.complexity2 = o.complexity2 == undefined ? null : o.complexity2;
67
-
68
- this.local = new THREE.Vector3();
69
- if( o.local ) this.local.fromArray( o.local );
70
-
71
- this.pp = new THREE.Vector3();
72
-
73
- this.lng = this.sample[0] * this.sample[1];
74
- var sx = this.sample[0] - 1;
75
- var sz = this.sample[1] - 1;
76
- this.rx = sx / this.size[0];
77
- this.rz = sz / this.size[2];
78
- this.ratio = 1 / this.sample[0];
79
- this.ruvx = 1.0 / ( this.size[0] / this.uvx[0] );
80
- this.ruvy = - ( 1.0 / ( this.size[2] / this.uvx[1] ) );
81
-
82
- this.is64 = o.is64 || false;
83
-
84
- this.isTurn = o.turn || false;
85
-
86
- this.heightData = [];//this.is64 ? new Float64Array( this.lng ) : new Float32Array( this.lng );
87
- this.height = [];
88
-
89
-
90
- this.underWater = o.underWater || 0;
91
-
92
- this.isAbsolute = o.isAbsolute || false;
93
- this.isReverse = o.isReverse || false;
94
- if( this.isReverse ) this.getReverseID();
95
-
96
- this.colors = new Float32Array( this.lng * 3 );
97
- this.geometry = new THREE.PlaneBufferGeometry( this.size[0], this.size[2], this.sample[0] - 1, this.sample[1] - 1 );
98
- this.geometry.rotateX( -this.p90 );
99
- if( this.isTurn ) this.geometry.rotateY( -this.p90 );
100
-
101
-
102
-
103
-
104
- // this.geometry.computeBoundingSphere();
105
-
106
- this.geometry.setAttribute( 'color', new THREE.BufferAttribute( this.colors, 3 ) );
107
- //this.geometry.setAttribute( 'uv2', this.geometry.attributes.uv );
108
- this.vertices = this.geometry.attributes.position.array;
109
-
110
-
111
-
112
-
113
- var isORM = false;
114
- var clevels = new THREE.Quaternion( 0.95, 0.8, 0.1, 0.05 );
115
- if( o.maplevels ) clevels.fromArray( o.maplevels );
116
- var T = TerrainShader;
117
- var maps = o.maps || [ 'sand', 'grass', 'rock' ], txt = {};
118
- var name;
119
-
120
- if(this.isWater) maps = ['water'];
121
-
122
- for( var i in maps ){
123
-
124
- name = maps[i];
125
- txt[name] = this.loadTextures('./assets/textures/terrain/'+name+'.jpg', { flip:false, repeat:this.uvx, encoding:o.encoding , callback: this.mapcallback.bind(this) });
126
- txt[name+'_n'] = this.loadTextures('./assets/textures/terrain/'+name+'_n.jpg', { flip:false, repeat:this.uvx, callback: this.mapcallback.bind(this) });
127
- if( isORM )txt[name+'_n'] = this.loadTextures('./assets/textures/terrain/'+name+'_n.jpg', { flip:false, repeat:this.uvx, callback: this.mapcallback.bind(this) });
128
-
129
- }
130
-
131
- this.material = new THREE.MeshStandardMaterial({ name:'terrain', vertexColors:THREE.VertexColors, color:0xFFFFFF, map:txt[maps[0]], normalMap:txt[maps[0]+'_n'], envMap:o.envMap || null });
132
-
133
- if( o.envmap !== undefined ) this.material.envMap = o.envmap
134
-
135
- if( this.isWater ){
136
- this.material.transparent = true;
137
- this.material.opacity = o.opacity || 0.4;
138
- this.material.side = THREE.DoubleSide;
139
- this.material.alphaMap = txt[maps[0]];
140
- this.material.map = null;
141
- this.material.metalnes = 0.9;
142
- this.material.roughness = 0.1;
143
- } else {
144
- this.material.metalnes = 0.4;
145
- this.material.roughness = 0.4;
146
- }
147
-
148
- if( isORM ){
149
- this.material.metalnes = 1;
150
- this.material.roughness = 1;
151
- }
152
-
153
- var ns = o.nScale || 1;
154
- this.material.normalScale.set(ns,ns);
155
-
156
- if( !this.isWater ){
157
-
158
- this.material.onBeforeCompile = function ( shader ) {
159
-
160
- var uniforms = shader.uniforms;
161
-
162
- //uniforms['fogTime'] = { value: 0 };
163
-
164
- uniforms['clevels'] = { value: clevels };
165
-
166
- uniforms['map1'] = { value: txt[maps[1]] };
167
- uniforms['map2'] = { value: txt[maps[2]] };
168
-
169
- uniforms['normalMap1'] = { value: txt[maps[1]+'_n'] };
170
- uniforms['normalMap2'] = { value: txt[maps[2]+'_n'] };
171
-
172
- //uniforms['underWater'] = { value: o.underWater || 0.1 };
173
- uniforms['waterColor'] = { value: new THREE.Color( o.waterColor || 0x3b4c5a ) };
174
-
175
- shader.uniforms = uniforms;
176
-
177
- var fragment = shader.fragmentShader;
178
-
179
- fragment = fragment.replace( 'uniform vec3 diffuse;', T.baseRemplace );
180
-
181
- fragment = fragment.replace( '#include <map_fragment>', T.map );
182
- fragment = fragment.replace( '#include <normal_fragment_maps>', T.normal );
183
- fragment = fragment.replace( '#include <color_fragment>', '' );
184
-
185
- if( isORM ){
186
-
187
- fragment = fragment.replace( '#include <normalmap_pars_fragment>', T.normal_pars );
188
-
189
- fragment = fragment.replace( '#include <roughnessmap_pars_fragment>', T.rough_pars );
190
- fragment = fragment.replace( '#include <metalnessmap_pars_fragment>', '' );
191
- fragment = fragment.replace( '#include <aomap_pars_fragment>', '' );
192
-
193
-
194
- fragment = fragment.replace( '#include <roughnessmap_fragment>', T.rough );
195
- fragment = fragment.replace( '#include <metalnessmap_fragment>', '' );
196
- fragment = fragment.replace( '#include <aomap_fragment>', T.ao );
197
-
198
- }
199
-
200
- shader.fragmentShader = fragment;
201
-
202
- if( o.shader ) o.shader.modify( shader );
203
-
204
- }
205
-
206
- } else {
207
-
208
- this.material.onBeforeCompile = function ( shader ) {
209
-
210
- var fragment = shader.fragmentShader;
211
-
212
- fragment = fragment.replace( '#include <alphamap_fragment>', T.alphamap );
213
-
214
-
215
-
216
- shader.fragmentShader = fragment;
217
-
218
- }
219
-
220
- }
221
-
222
-
223
- THREE.Mesh.call( this, this.geometry, this.material );
224
-
225
- if(o.debuger){
226
- var debuger = new THREE.Mesh( this.geometry, new THREE.MeshBasicMaterial({ wireframe:true } ));
227
- this.add( debuger );
228
- }
229
-
230
- //root.garbage.push( this.geometry );
231
-
232
-
233
- if( this.wantBorder ) this.addBorder( o );
234
- if( this.wantBottom ) this.addBottom( o );
235
-
236
- this.name = o.name === undefined ? 'terrain' : o.name;
237
- if( o.pos ) this.position.fromArray( o.pos );
238
- if( o.decal ) this.position.y += o.decal;
239
-
240
-
241
- this.castShadow = true;
242
- this.receiveShadow = true;
243
-
244
-
245
- this.update();
246
-
247
- //if(this.callback) this.callback()
248
-
249
- };
250
-
251
- Landscape.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
252
-
253
- constructor: Landscape,
254
-
255
- loadTextures: function ( url, o ) {
256
-
257
- o = o || {};
258
-
259
- if( this.loaderMap === null ) this.loaderMap = new THREE.TextureLoader();
260
-
261
- let name = url.substring( url.lastIndexOf('/')+1, url.lastIndexOf('.') );
262
-
263
- if( this.textures[ name ] ){
264
-
265
- if( o.callback ) o.callback();
266
- return this.textures[name];
267
-
268
- }
269
-
270
- this.textures[name] = this.loaderMap.load( url, function ( t ) {
271
-
272
- t.name = name;
273
-
274
- if( o.encoding ) t.encoding = THREE.sRGBEncoding;
275
-
276
- t.flipY = o.flip !== undefined ? o.flip : true;
277
-
278
- if( o.anisotropy !== undefined ) t.anisotropy = o.anisotropy;
279
- if( o.generateMipmaps !== undefined ) t.generateMipmaps = o.generateMipmaps;
280
-
281
- if( o.repeat ){
282
- t.repeat.fromArray( o.repeat );
283
- t.wrapS = THREE.RepeatWrapping;
284
- t.wrapT = THREE.RepeatWrapping;
285
- }
286
-
287
- if(o.filter){
288
- if(o.filter === 'near' ){
289
- t.minFilter = THREE.NearestFilter;
290
- t.magFilter = THREE.NearestFilter;
291
- }
292
- }
293
-
294
- if( o.callback ) o.callback();
295
-
296
- });
297
-
298
- return this.textures[name];
299
-
300
- },
301
-
302
- mapcallback: function (){
303
-
304
- //if( this.callback === null ) return;
305
-
306
- this.mapN++;
307
- if( this.mapN == this.mapMax ) this.callback();
308
-
309
- },
310
-
311
- addBottom: function ( o ){
312
-
313
- var geometry = new THREE.PlaneBufferGeometry( this.size[0], this.size[2], 1, 1 );
314
- geometry.rotateX( this.p90 );
315
-
316
-
317
- this.bottomMesh = new THREE.Mesh( geometry, this.borderMaterial );
318
-
319
- this.add( this.bottomMesh );
320
-
321
- this.isBottom = true;
322
- },
323
-
324
- addBorder: function ( o ){
325
-
326
- this.borderMaterial = new THREE.MeshStandardMaterial({
327
-
328
- vertexColors: THREE.VertexColors,
329
- metalness: this.isWater ? 0.8 : 0.4,
330
- roughness: this.isWater ? 0.2 : 0.6,
331
-
332
- //envMap: view.getEnvMap(),
333
- //normalMap:this.wn,
334
- normalScale:this.isWater ? [0.25,0.25]:[-1,-1],
335
- transparent:this.isWater ? true : false,
336
- opacity: this.isWater ? (o.opacity || 0.8) : 1,
337
- envMap: o.envMap || null,
338
- //shadowSide : false
339
-
340
- });
341
-
342
- //view.getMat()[this.name+'border'] = this.borderMaterial;
343
-
344
- var front = new THREE.PlaneGeometry( this.size[0], 2, this.sample[0] - 1, 1 );
345
- var back = new THREE.PlaneGeometry( this.size[0], 2, this.sample[0] - 1, 1 );
346
- var left = new THREE.PlaneGeometry( this.size[2], 2, this.sample[1] - 1, 1 );
347
- var right = new THREE.PlaneGeometry( this.size[2], 2, this.sample[1] - 1, 1 );
348
-
349
- front.translate( 0,1, this.size[2]*0.5);
350
- back.rotateY( -Math.PI );
351
- back.translate( 0,1, -this.size[2]*0.5);
352
- left.rotateY( -this.p90 );
353
- left.translate( -this.size[0]*0.5,1, 0);
354
- right.rotateY( this.p90 );
355
- right.translate( this.size[0]*0.5,1, 0);
356
-
357
- this.borderGeometry = THREE.BufferGeometryUtils.mergeVertices( THREE.BufferGeometryUtils.mergeBufferGeometries( [ front, back, left, right ] ) );
358
- this.borderVertices = this.borderGeometry.attributes.position.array;
359
- this.lng2 = this.borderVertices.length / 3;
360
- this.list = new Array( this.lng2 )
361
- this.borderColors = new Float32Array( this.lng * 3 );
362
- this.borderGeometry.setAttribute( 'color', new THREE.BufferAttribute( this.borderColors, 3 ) );
363
- this.borderMesh = new THREE.Mesh( this.borderGeometry, this.borderMaterial );
364
-
365
- var j = this.lng2, n, i;
366
- while(j--){
367
- n = j*3;
368
- i = this.borderVertices[n+1] > 0 ? this.findPoint( this.borderVertices[n], this.borderVertices[n+2] ) : -1;
369
- this.list[j] = i;
370
-
371
- }
372
-
373
- this.add( this.borderMesh );
374
-
375
- this.borderMesh.castShadow = true;
376
- this.borderMesh.receiveShadow = true;
377
-
378
- this.isBorder = true;
379
-
380
- },
381
-
382
- setData: function ( d ) {
383
-
384
- this.data = d;
385
- this.update();
386
-
387
- },
388
-
389
- dispose: function () {
390
-
391
- this.geometry.dispose();
392
- this.material.dispose();
393
-
394
- },
395
-
396
- easing: function ( key, azimuthal, wait ) {
397
-
398
- key = key || user.key;
399
-
400
- if( !key[0] || !key[1] ) return;
401
-
402
- var r = azimuthal || 0;//view.getAzimuthal();
403
-
404
- if( key[7] ) this.maxspeed = 1.5;
405
- else this.maxspeed = 0.25;
406
-
407
- //acceleration
408
- this.ease.y += key[1] * this.acc; // up down
409
- this.ease.x += key[0] * this.acc; // left right
410
- //speed limite
411
- this.ease.x = this.ease.x > this.maxspeed ? this.maxspeed : this.ease.x;
412
- this.ease.x = this.ease.x < -this.maxspeed ? -this.maxspeed : this.ease.x;
413
- this.ease.y = this.ease.y > this.maxspeed ? this.maxspeed : this.ease.y;
414
- this.ease.y = this.ease.y < -this.maxspeed ? -this.maxspeed : this.ease.y;
415
-
416
- //break
417
- if (!key[1]) {
418
- if (this.ease.y > this.dec) this.ease.y -= this.dec;
419
- else if (this.ease.y < -this.dec) this.ease.y += this.dec;
420
- else this.ease.y = 0;
421
- }
422
- if (!key[0]) {
423
- if (this.ease.x > this.dec) this.ease.x -= this.dec;
424
- else if (this.ease.x < -this.dec) this.ease.x += this.dec;
425
- else this.ease.x = 0;
426
- }
427
-
428
- if ( !this.ease.x && !this.ease.y ) return;
429
-
430
- this.local.z += Math.sin(r) * this.ease.x + Math.cos(r) * this.ease.y;
431
- this.local.x += Math.cos(r) * this.ease.x - Math.sin(r) * this.ease.y;
432
-
433
- this.update( wait );
434
-
435
- },
436
-
437
- getHeight: function ( x, z ) {
438
-
439
-
440
-
441
- x *= this.rx;
442
- z *= this.rz;
443
- x += this.sample[0]*0.5;
444
- z += this.sample[1]*0.5;
445
-
446
- //this.pv.set( x, 0, z ).applyAxisAngle( {x:0, y:1, z:0}, -this.p90 )
447
-
448
- /*if( this.isTurn ){
449
- x = Math.floor(-z);
450
- z = Math.floor(x);
451
- }else {*/
452
- x = Math.floor(x);
453
- z = Math.floor(z);
454
- //}
455
-
456
-
457
-
458
- var h = this.isTurn ? this.height[ this.findId2( x, z ) ] : this.height[ this.findId( x, z ) ];
459
- return ( h * this.size[ 1 ] ) + this.position.y;
460
-
461
- },
462
-
463
- findId: function( x, z ){
464
-
465
- return x+(z*this.sample[1]) || 1;
466
-
467
- },
468
-
469
- findId2: function( x, z ){
470
-
471
- return z+(-x*this.sample[0]) || 1;
472
-
473
- },
474
-
475
- findPoint: function( x, z ){
476
-
477
- var i = this.lng, n;
478
- while( i-- ){
479
- n = i * 3;
480
- if( this.vertices[ n ] === x && this.vertices[ n + 2 ] === z ) return i;
481
- }
482
-
483
- return -1;
484
-
485
- },
486
-
487
- getReverseID: function () {
488
-
489
- this.invId = [];
490
-
491
- var i = this.lng, n, x, z, zr, c, l=0;
492
- var sz = this.sample[1] - 1;
493
-
494
- while(i--){
495
- x = i % this.sample[0];
496
- z = Math.floor( i * this.ratio );
497
- zr = sz - z;
498
- this.invId[i] = this.findId( x, zr );
499
- }
500
-
501
- },
502
-
503
- clamp: function (v, min, max) {
504
-
505
- //return Math.max( min, Math.min( max, value ) );
506
- v = v < min ? min : v;
507
- v = v > max ? max : v;
508
- return v;
509
- },
510
-
511
- noise: function ( v, o ) {
512
-
513
- if( this.perlin === null ) this.perlin = new SimplexNoise();
514
-
515
- o = o || {};
516
-
517
- var level = o.level || [ 1, 0.2, 0.05 ];
518
- var frequency = o.frequency || [ 0.016, 0.05, 0.2 ];
519
-
520
- var i, f, c=0, d=0;
521
-
522
- for(i=0; i<level.length; i++){
523
-
524
- f = frequency[i];
525
- c += level[i] * ( 0.5 + this.perlin.noise3d( v.x*f, v.y*f, v.z*f ) * 0.5 );
526
- d += level[i];
527
-
528
- }
529
-
530
- c/=d;
531
-
532
- return c;
533
-
534
- },
535
-
536
- update: function ( wait ) {
537
-
538
- this.size[1] = this.data.height;
539
-
540
-
541
- if( this.isWater ){
542
- this.material.normalMap.offset.x+=0.002;
543
- this.material.normalMap.offset.y+=0.001;
544
- } else {
545
- this.material.map.offset.x = this.local.x * this.ruvx;
546
- this.material.map.offset.y = this.local.z * this.ruvy;
547
- }
548
-
549
- var v = this.pp;
550
- var cc = [1,1,1];
551
- var i = this.lng, n, x, z, c, l=0, id, result;
552
- var oldz, oldh, ccY;
553
-
554
- while( i-- ){
555
-
556
- n = i * 3;
557
- x = i % this.sample[0];
558
- z = Math.floor( i * this.ratio );
559
-
560
- v.set( x + ( this.local.x*this.rx ), this.local.y, z + ( this.local.z*this.rz ) );
561
-
562
-
563
-
564
- //c = math.noise( v, this.data );
565
- c = this.noise( v, this.data );
566
-
567
-
568
-
569
- //c = Math.quinticSCurve(c);
570
- //c = Math.cubicSCurve(c)
571
- //c = Math.linear(c,0.2, 1);
572
- //c = Math.clamp(c,0.2,1)
573
-
574
- c = Math.pow( c, this.data.expo );
575
-
576
- this.clamp( c, 0, 1);
577
-
578
-
579
-
580
-
581
- if( this.ttype === 'road' ) {
582
-
583
- if(oldz === z){
584
- if(x===1 || x===2 || x===29 || x===30) c = oldh + 0.1;
585
- else c = oldh;
586
- } else {
587
- oldz = z;
588
- oldh = c;
589
-
590
- }
591
-
592
- //console.log(x)
593
- }
594
-
595
- this.height[ i ] = c;
596
-
597
- id = this.isReverse ? this.invId[i] : i;
598
- //result = this.isAbsolute ? c : c * this.size[1];
599
-
600
- this.heightData[ id ] = this.isAbsolute ? c : (c * this.size[ 1 ]) + this.deep;
601
-
602
- ccY = (c * this.size[ 1 ]) + this.deep;
603
-
604
-
605
-
606
- this.vertices[ n + 1 ] = ccY;
607
-
608
- if( this.isWater ){
609
-
610
- cc = [ c * this.colorBase.r, c * this.colorBase.g, c * this.colorBase.b ];
611
-
612
- } else {
613
-
614
- cc = [ c, 0, 0];
615
-
616
- if( ccY < this.underWater ) cc[2] = 1.25-(ccY/this.underWater);////1;
617
-
618
- }
619
-
620
- //var ccc = this.clamp(cc[0]+0.25, 0.25, 1)
621
-
622
- this.colors[ n ] = cc[0];
623
- this.colors[ n + 1 ] = cc[1];
624
- this.colors[ n + 2 ] = cc[2];
625
- //oldx = x;
626
-
627
-
628
- }
629
-
630
-
631
- if( this.isBorder ){
632
-
633
- var j = this.lng2, h;
634
- while(j--){
635
- n = j*3;
636
- if(this.list[j]!==-1){
637
- h = this.height[ this.list[j] ];
638
- this.borderVertices[n+1] = (h * this.size[1]) + this.deep;
639
- var ccc = this.clamp(h+0.25, 0.25, 1)
640
- var ee = (0.5 + h+0.5);
641
- ee = ee > 1 ? 1 : ee;
642
- ee = ee < 0.5 ? 0.5 : ee;
643
- this.borderColors[n] = ccc //* this.colorBase.r;//h * this.colorBase.r//ee;
644
- this.borderColors[n+1] = ccc //* this.colorBase.g;// h * this.colorBase.g//ee*0.5;
645
- this.borderColors[n+2] = ccc //* this.colorBase.b;// h * this.colorBase.b//ee*0.3;
646
-
647
- } else{
648
- this.borderColors[n] = this.colorBase.r//0.5;
649
- this.borderColors[n+1] = this.colorBase.g//0.25;
650
- this.borderColors[n+2] = this.colorBase.b//0.15;
651
- }
652
- }
653
-
654
- }
655
-
656
- this.updateGeometry();
657
-
658
- this.ready = true;
659
-
660
- //if( phy ) root.view.update( { name:'terra', heightData:this.heightData, sample:this.sample } );
661
-
662
- },
663
-
664
- updateGeometry: function () {
665
-
666
- this.geometry.attributes.position.needsUpdate = true;
667
- this.geometry.attributes.color.needsUpdate = true;
668
- this.geometry.computeVertexNormals();
669
-
670
-
671
- if( this.isBorder ){
672
- this.borderGeometry.attributes.position.needsUpdate = true;
673
- this.borderGeometry.attributes.color.needsUpdate = true;
674
- }
675
-
676
- }
677
-
678
- });
679
-
680
- // SHADERS
681
-
682
- var TerrainShader = {
683
-
684
- baseRemplace : /* glsl */`
685
- uniform vec3 diffuse;
686
- uniform vec4 clevels;
687
-
688
- //uniform float underWater;
689
- uniform vec3 waterColor;
690
-
691
- uniform sampler2D normalMap1;
692
- uniform sampler2D normalMap2;
693
-
694
- uniform sampler2D roughnessMap1;
695
- uniform sampler2D roughnessMap2;
696
-
697
- uniform float aoMapIntensity;
698
- uniform sampler2D map1;
699
- uniform sampler2D map2;
700
-
701
- vec4 MappingMix( float slope, vec4 level, vec4 rocks, vec4 grasss, vec4 sands ){
702
- vec4 cc = rocks;
703
- if (slope < level.y) cc = grasss;
704
- if (slope < level.z) cc = sands;
705
- if (( slope < level.x ) && (slope >= level.y)) cc = mix( grasss , rocks, (slope - level.y) * (1. / (level.x - level.y)));
706
- if (( slope < level.y ) && (slope >= level.z)) cc = mix( sands , grasss, (slope - level.z) * (1. / (level.y - level.z)));
707
- return cc;
708
- }
709
- `,
710
-
711
- rough : /* glsl */`
712
- float roughnessFactor = roughness;
713
- float metalnessFactor = metalness;
714
- #ifdef USE_ROUGHNESSMAP
715
-
716
- vec4 sandR = texture2D( roughnessMap, vUv );
717
- vec4 grassR = texture2D( roughnessMap1, vUv );
718
- vec4 rockR = texture2D( roughnessMap2, vUv );
719
-
720
- vec4 baseColorR = MappingMix( vColor.r, clevels, rockR, grassR, sandR );
721
-
722
- // reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
723
- float ambientOcclusion =( baseColorR.r - 1.0 ) * aoMapIntensity + 1.0;
724
- roughnessFactor *= baseColorR.g;
725
- metalnessFactor *= baseColorR.b;
726
- #endif
727
- `,
728
-
729
- // ao
730
-
731
- ao : /* glsl */`
732
- reflectedLight.indirectDiffuse *= ambientOcclusion;
733
- #if defined( USE_ENVMAP ) && defined( STANDARD )
734
- float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
735
- reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );
736
- #endif
737
- `,
738
-
739
- // map
740
-
741
- map : /* glsl */`
742
- #ifdef USE_MAP
743
- vec4 sand = texture2D( map, vUv );
744
- vec4 grass = texture2D( map1, vUv );
745
- vec4 rock = texture2D( map2, vUv );
746
-
747
- vec4 baseColor = MappingMix( vColor.r, clevels, rock, grass, sand );
748
-
749
- baseColor = mix( baseColor, vec4( waterColor, 1.0 ), vColor.b );
750
-
751
- //if ( vColor.b < underWater ) baseColor *= vec4( waterColor, 0.25 );
752
-
753
- diffuseColor *= mapTexelToLinear( baseColor );
754
-
755
- #endif
756
- `,
757
-
758
- // normal
759
-
760
- normal : /* glsl */`
761
- #ifdef USE_NORMALMAP
762
- vec4 sandN = texture2D( normalMap, vUv );
763
- vec4 grassN = texture2D( normalMap1, vUv );
764
- vec4 rockN = texture2D( normalMap2, vUv );
765
-
766
- vec3 extraNormal = MappingMix(vColor.r, clevels, rockN, grassN, sandN).xyz * 2.0 - 1.0;
767
- extraNormal.xy *= normalScale;
768
- normal = perturbNormal2Arb( -vViewPosition, normal, extraNormal, faceDirection );
769
- #endif
770
- `,
771
-
772
- alphamap : /* glsl */`
773
- #ifdef USE_ALPHAMAP
774
- diffuseColor.a = opacity +( texture2D( alphaMap, vUv ).g * opacity) * (1.0-opacity);
775
- #endif
776
- `,
777
-
778
- }