uil 1.0.1 → 4.0.0
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.
- package/README.md +57 -0
- package/build/uil.js +7040 -4199
- package/build/uil.min.js +6 -4
- package/build/uil.module.js +7200 -2761
- package/examples/js/BufferGeometryUtils.js +921 -0
- package/examples/js/SimplexNoise.js +324 -0
- package/examples/js/controls/OrbitControls.js +1215 -0
- package/examples/js/controls/OrbitControls_.js +1042 -0
- package/examples/js/libs/sea3d.min.js +373 -0
- package/examples/js/libs/three.min.js +6 -0
- package/examples/js/math.js +447 -0
- package/examples/js/objects/Landscape.js +778 -0
- package/examples/js/objects/Lensflare.js +372 -0
- package/examples/js/objects/SuperSky.js +297 -0
- package/examples/js/objects/Water.js +329 -0
- package/package.json +56 -54
- package/src/Uil.js +2 -17
- package/src/Uil_dev.js +15 -0
- package/src/core/Gui.js +601 -299
- package/src/core/Proto.js +490 -220
- package/src/core/Roots.js +864 -0
- package/src/core/Tools.js +591 -140
- package/src/core/V2.js +131 -0
- package/src/core/add.js +52 -57
- package/src/proto/Bool.js +117 -52
- package/src/proto/Button.js +286 -146
- package/src/proto/Circular.js +162 -130
- package/src/proto/Color.js +331 -289
- package/src/proto/Empty.js +15 -0
- package/src/proto/Fps.js +232 -159
- package/src/proto/Graph.js +310 -0
- package/src/proto/Grid.js +297 -0
- package/src/proto/Group.js +334 -160
- package/src/proto/Item.js +120 -0
- package/src/proto/Joystick.js +159 -185
- package/src/proto/Knob.js +210 -91
- package/src/proto/List.js +661 -249
- package/src/proto/Numeric.js +329 -162
- package/src/proto/Pad2D.js +268 -0
- package/src/proto/Rubric.js +0 -0
- package/src/proto/Select.js +178 -0
- package/src/proto/Selector.js +13 -0
- package/src/proto/Slide.js +191 -185
- package/src/proto/TextInput.js +149 -59
- package/src/proto/Title.js +40 -31
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
THREE.Lensflare = function () {
|
|
2
|
+
|
|
3
|
+
THREE.Mesh.call( this, THREE.Lensflare.Geometry, new THREE.MeshBasicMaterial( { opacity: 0, transparent: true } ) );
|
|
4
|
+
|
|
5
|
+
this.type = 'Lensflare';
|
|
6
|
+
this.frustumCulled = false;
|
|
7
|
+
this.renderOrder = Infinity;
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
var positionScreen = new THREE.Vector3();
|
|
12
|
+
var positionView = new THREE.Vector3();
|
|
13
|
+
|
|
14
|
+
// textures
|
|
15
|
+
|
|
16
|
+
var tempMap = new THREE.DataTexture( new Uint8Array( 16 * 16 * 3 ), 16, 16, THREE.RGBFormat );
|
|
17
|
+
tempMap.minFilter = THREE.NearestFilter;
|
|
18
|
+
tempMap.magFilter = THREE.NearestFilter;
|
|
19
|
+
tempMap.wrapS = THREE.ClampToEdgeWrapping;
|
|
20
|
+
tempMap.wrapT = THREE.ClampToEdgeWrapping;
|
|
21
|
+
|
|
22
|
+
var occlusionMap = new THREE.DataTexture( new Uint8Array( 16 * 16 * 3 ), 16, 16, THREE.RGBFormat );
|
|
23
|
+
occlusionMap.minFilter = THREE.NearestFilter;
|
|
24
|
+
occlusionMap.magFilter = THREE.NearestFilter;
|
|
25
|
+
occlusionMap.wrapS = THREE.ClampToEdgeWrapping;
|
|
26
|
+
occlusionMap.wrapT = THREE.ClampToEdgeWrapping;
|
|
27
|
+
|
|
28
|
+
// material
|
|
29
|
+
|
|
30
|
+
var geometry = THREE.Lensflare.Geometry;
|
|
31
|
+
|
|
32
|
+
var material1a = new THREE.RawShaderMaterial( {
|
|
33
|
+
uniforms: {
|
|
34
|
+
'scale': { value: null },
|
|
35
|
+
'screenPosition': { value: null }
|
|
36
|
+
},
|
|
37
|
+
vertexShader: [
|
|
38
|
+
|
|
39
|
+
'precision highp float;',
|
|
40
|
+
|
|
41
|
+
'uniform vec3 screenPosition;',
|
|
42
|
+
'uniform vec2 scale;',
|
|
43
|
+
|
|
44
|
+
'attribute vec3 position;',
|
|
45
|
+
|
|
46
|
+
'void main() {',
|
|
47
|
+
|
|
48
|
+
' gl_Position = vec4( position.xy * scale + screenPosition.xy, screenPosition.z, 1.0 );',
|
|
49
|
+
|
|
50
|
+
'}'
|
|
51
|
+
|
|
52
|
+
].join( '\n' ),
|
|
53
|
+
fragmentShader: [
|
|
54
|
+
|
|
55
|
+
'precision highp float;',
|
|
56
|
+
|
|
57
|
+
'void main() {',
|
|
58
|
+
|
|
59
|
+
' gl_FragColor = vec4( 1.0, 0.0, 1.0, 1.0 );',
|
|
60
|
+
|
|
61
|
+
'}'
|
|
62
|
+
|
|
63
|
+
].join( '\n' ),
|
|
64
|
+
depthTest: true,
|
|
65
|
+
depthWrite: false,
|
|
66
|
+
transparent: false
|
|
67
|
+
} );
|
|
68
|
+
|
|
69
|
+
var material1b = new THREE.RawShaderMaterial( {
|
|
70
|
+
uniforms: {
|
|
71
|
+
'map': { value: tempMap },
|
|
72
|
+
'scale': { value: null },
|
|
73
|
+
'screenPosition': { value: null }
|
|
74
|
+
},
|
|
75
|
+
vertexShader: [
|
|
76
|
+
|
|
77
|
+
'precision highp float;',
|
|
78
|
+
|
|
79
|
+
'uniform vec3 screenPosition;',
|
|
80
|
+
'uniform vec2 scale;',
|
|
81
|
+
|
|
82
|
+
'attribute vec3 position;',
|
|
83
|
+
'attribute vec2 uv;',
|
|
84
|
+
|
|
85
|
+
'varying vec2 vUV;',
|
|
86
|
+
|
|
87
|
+
'void main() {',
|
|
88
|
+
|
|
89
|
+
' vUV = uv;',
|
|
90
|
+
|
|
91
|
+
' gl_Position = vec4( position.xy * scale + screenPosition.xy, screenPosition.z, 1.0 );',
|
|
92
|
+
|
|
93
|
+
'}'
|
|
94
|
+
|
|
95
|
+
].join( '\n' ),
|
|
96
|
+
fragmentShader: [
|
|
97
|
+
|
|
98
|
+
'precision highp float;',
|
|
99
|
+
|
|
100
|
+
'uniform sampler2D map;',
|
|
101
|
+
|
|
102
|
+
'varying vec2 vUV;',
|
|
103
|
+
|
|
104
|
+
'void main() {',
|
|
105
|
+
|
|
106
|
+
' gl_FragColor = texture2D( map, vUV );',
|
|
107
|
+
|
|
108
|
+
'}'
|
|
109
|
+
|
|
110
|
+
].join( '\n' ),
|
|
111
|
+
depthTest: false,
|
|
112
|
+
depthWrite: false,
|
|
113
|
+
transparent: false
|
|
114
|
+
} );
|
|
115
|
+
|
|
116
|
+
// the following object is used for occlusionMap generation
|
|
117
|
+
|
|
118
|
+
var mesh1 = new THREE.Mesh( geometry, material1a );
|
|
119
|
+
|
|
120
|
+
//
|
|
121
|
+
|
|
122
|
+
var elements = [];
|
|
123
|
+
|
|
124
|
+
var shader = THREE.LensflareElement.Shader;
|
|
125
|
+
|
|
126
|
+
var material2 = new THREE.RawShaderMaterial( {
|
|
127
|
+
uniforms: {
|
|
128
|
+
'map': { value: null },
|
|
129
|
+
'occlusionMap': { value: occlusionMap },
|
|
130
|
+
'color': { value: new THREE.Color( 0xffffff ) },
|
|
131
|
+
'scale': { value: new THREE.Vector2() },
|
|
132
|
+
'screenPosition': { value: new THREE.Vector3() }
|
|
133
|
+
},
|
|
134
|
+
vertexShader: shader.vertexShader,
|
|
135
|
+
fragmentShader: shader.fragmentShader,
|
|
136
|
+
blending: THREE.AdditiveBlending,
|
|
137
|
+
transparent: true,
|
|
138
|
+
depthWrite: false
|
|
139
|
+
} );
|
|
140
|
+
|
|
141
|
+
var mesh2 = new THREE.Mesh( geometry, material2 );
|
|
142
|
+
|
|
143
|
+
this.addElement = function ( element ) {
|
|
144
|
+
|
|
145
|
+
elements.push( element );
|
|
146
|
+
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
//
|
|
150
|
+
|
|
151
|
+
var scale = new THREE.Vector2();
|
|
152
|
+
var screenPositionPixels = new THREE.Vector2();
|
|
153
|
+
var validArea = new THREE.Box2();
|
|
154
|
+
var viewport = new THREE.Vector4();
|
|
155
|
+
|
|
156
|
+
this.onBeforeRender = function ( renderer, scene, camera ) {
|
|
157
|
+
|
|
158
|
+
renderer.getCurrentViewport( viewport );
|
|
159
|
+
|
|
160
|
+
var invAspect = viewport.w / viewport.z;
|
|
161
|
+
var halfViewportWidth = viewport.z / 2.0;
|
|
162
|
+
var halfViewportHeight = viewport.w / 2.0;
|
|
163
|
+
|
|
164
|
+
var size = 16 / viewport.w;
|
|
165
|
+
scale.set( size * invAspect, size );
|
|
166
|
+
|
|
167
|
+
validArea.min.set( viewport.x, viewport.y );
|
|
168
|
+
validArea.max.set( viewport.x + ( viewport.z - 16 ), viewport.y + ( viewport.w - 16 ) );
|
|
169
|
+
|
|
170
|
+
// calculate position in screen space
|
|
171
|
+
|
|
172
|
+
positionView.setFromMatrixPosition( this.matrixWorld );
|
|
173
|
+
positionView.applyMatrix4( camera.matrixWorldInverse );
|
|
174
|
+
|
|
175
|
+
if ( positionView.z > 0 ) return; // lensflare is behind the camera
|
|
176
|
+
|
|
177
|
+
positionScreen.copy( positionView ).applyMatrix4( camera.projectionMatrix );
|
|
178
|
+
|
|
179
|
+
// horizontal and vertical coordinate of the lower left corner of the pixels to copy
|
|
180
|
+
|
|
181
|
+
screenPositionPixels.x = viewport.x + ( positionScreen.x * halfViewportWidth ) + halfViewportWidth - 8;
|
|
182
|
+
screenPositionPixels.y = viewport.y + ( positionScreen.y * halfViewportHeight ) + halfViewportHeight - 8;
|
|
183
|
+
|
|
184
|
+
// screen cull
|
|
185
|
+
|
|
186
|
+
if ( validArea.containsPoint( screenPositionPixels ) ) {
|
|
187
|
+
|
|
188
|
+
// save current RGB to temp texture
|
|
189
|
+
|
|
190
|
+
renderer.copyFramebufferToTexture( screenPositionPixels, tempMap );
|
|
191
|
+
|
|
192
|
+
// render pink quad
|
|
193
|
+
|
|
194
|
+
var uniforms = material1a.uniforms;
|
|
195
|
+
uniforms[ 'scale' ].value = scale;
|
|
196
|
+
uniforms[ 'screenPosition' ].value = positionScreen;
|
|
197
|
+
|
|
198
|
+
renderer.renderBufferDirect( camera, null, geometry, material1a, mesh1, null );
|
|
199
|
+
|
|
200
|
+
// copy result to occlusionMap
|
|
201
|
+
|
|
202
|
+
renderer.copyFramebufferToTexture( screenPositionPixels, occlusionMap );
|
|
203
|
+
|
|
204
|
+
// restore graphics
|
|
205
|
+
|
|
206
|
+
var uniforms = material1b.uniforms;
|
|
207
|
+
uniforms[ 'scale' ].value = scale;
|
|
208
|
+
uniforms[ 'screenPosition' ].value = positionScreen;
|
|
209
|
+
|
|
210
|
+
renderer.renderBufferDirect( camera, null, geometry, material1b, mesh1, null );
|
|
211
|
+
|
|
212
|
+
// render elements
|
|
213
|
+
|
|
214
|
+
var vecX = - positionScreen.x * 2;
|
|
215
|
+
var vecY = - positionScreen.y * 2;
|
|
216
|
+
|
|
217
|
+
for ( var i = 0, l = elements.length; i < l; i ++ ) {
|
|
218
|
+
|
|
219
|
+
var element = elements[ i ];
|
|
220
|
+
|
|
221
|
+
var uniforms = material2.uniforms;
|
|
222
|
+
|
|
223
|
+
uniforms[ 'color' ].value.copy( element.color );
|
|
224
|
+
uniforms[ 'map' ].value = element.texture;
|
|
225
|
+
uniforms[ 'screenPosition' ].value.x = positionScreen.x + vecX * element.distance;
|
|
226
|
+
uniforms[ 'screenPosition' ].value.y = positionScreen.y + vecY * element.distance;
|
|
227
|
+
|
|
228
|
+
var size = element.size / viewport.w;
|
|
229
|
+
var invAspect = viewport.w / viewport.z;
|
|
230
|
+
|
|
231
|
+
uniforms[ 'scale' ].value.set( size * invAspect, size );
|
|
232
|
+
|
|
233
|
+
material2.uniformsNeedUpdate = true;
|
|
234
|
+
|
|
235
|
+
renderer.renderBufferDirect( camera, null, geometry, material2, mesh2, null );
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
this.dispose = function () {
|
|
244
|
+
|
|
245
|
+
material1a.dispose();
|
|
246
|
+
material1b.dispose();
|
|
247
|
+
material2.dispose();
|
|
248
|
+
|
|
249
|
+
tempMap.dispose();
|
|
250
|
+
occlusionMap.dispose();
|
|
251
|
+
|
|
252
|
+
for ( var i = 0, l = elements.length; i < l; i ++ ) {
|
|
253
|
+
|
|
254
|
+
elements[ i ].texture.dispose();
|
|
255
|
+
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
THREE.Lensflare.prototype = Object.create( THREE.Mesh.prototype );
|
|
263
|
+
THREE.Lensflare.prototype.constructor = THREE.Lensflare;
|
|
264
|
+
THREE.Lensflare.prototype.isLensflare = true;
|
|
265
|
+
|
|
266
|
+
//
|
|
267
|
+
|
|
268
|
+
THREE.LensflareElement = function ( texture, size, distance, color ) {
|
|
269
|
+
|
|
270
|
+
this.texture = texture;
|
|
271
|
+
this.size = size || 1;
|
|
272
|
+
this.distance = distance || 0;
|
|
273
|
+
this.color = color || new THREE.Color( 0xffffff );
|
|
274
|
+
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
THREE.LensflareElement.Shader = {
|
|
278
|
+
|
|
279
|
+
uniforms: {
|
|
280
|
+
|
|
281
|
+
'map': { value: null },
|
|
282
|
+
'occlusionMap': { value: null },
|
|
283
|
+
'color': { value: null },
|
|
284
|
+
'scale': { value: null },
|
|
285
|
+
'screenPosition': { value: null }
|
|
286
|
+
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
vertexShader: [
|
|
290
|
+
|
|
291
|
+
'precision highp float;',
|
|
292
|
+
|
|
293
|
+
'uniform vec3 screenPosition;',
|
|
294
|
+
'uniform vec2 scale;',
|
|
295
|
+
|
|
296
|
+
'uniform sampler2D occlusionMap;',
|
|
297
|
+
|
|
298
|
+
'attribute vec3 position;',
|
|
299
|
+
'attribute vec2 uv;',
|
|
300
|
+
|
|
301
|
+
'varying vec2 vUV;',
|
|
302
|
+
'varying float vVisibility;',
|
|
303
|
+
|
|
304
|
+
'void main() {',
|
|
305
|
+
|
|
306
|
+
' vUV = uv;',
|
|
307
|
+
|
|
308
|
+
' vec2 pos = position.xy;',
|
|
309
|
+
|
|
310
|
+
' vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );',
|
|
311
|
+
' visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );',
|
|
312
|
+
' visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );',
|
|
313
|
+
' visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );',
|
|
314
|
+
' visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );',
|
|
315
|
+
' visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );',
|
|
316
|
+
' visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );',
|
|
317
|
+
' visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );',
|
|
318
|
+
' visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );',
|
|
319
|
+
|
|
320
|
+
' vVisibility = visibility.r / 9.0;',
|
|
321
|
+
' vVisibility *= 1.0 - visibility.g / 9.0;',
|
|
322
|
+
' vVisibility *= visibility.b / 9.0;',
|
|
323
|
+
|
|
324
|
+
' gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );',
|
|
325
|
+
|
|
326
|
+
'}'
|
|
327
|
+
|
|
328
|
+
].join( '\n' ),
|
|
329
|
+
|
|
330
|
+
fragmentShader: [
|
|
331
|
+
|
|
332
|
+
'precision highp float;',
|
|
333
|
+
|
|
334
|
+
'uniform sampler2D map;',
|
|
335
|
+
'uniform vec3 color;',
|
|
336
|
+
|
|
337
|
+
'varying vec2 vUV;',
|
|
338
|
+
'varying float vVisibility;',
|
|
339
|
+
|
|
340
|
+
'void main() {',
|
|
341
|
+
|
|
342
|
+
' vec4 texture = texture2D( map, vUV );',
|
|
343
|
+
' texture.a *= vVisibility;',
|
|
344
|
+
' gl_FragColor = texture;',
|
|
345
|
+
' gl_FragColor.rgb *= color;',
|
|
346
|
+
|
|
347
|
+
'}'
|
|
348
|
+
|
|
349
|
+
].join( '\n' )
|
|
350
|
+
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
THREE.Lensflare.Geometry = ( function () {
|
|
354
|
+
|
|
355
|
+
var geometry = new THREE.BufferGeometry();
|
|
356
|
+
|
|
357
|
+
var float32Array = new Float32Array( [
|
|
358
|
+
- 1, - 1, 0, 0, 0,
|
|
359
|
+
1, - 1, 0, 1, 0,
|
|
360
|
+
1, 1, 0, 1, 1,
|
|
361
|
+
- 1, 1, 0, 0, 1
|
|
362
|
+
] );
|
|
363
|
+
|
|
364
|
+
var interleavedBuffer = new THREE.InterleavedBuffer( float32Array, 5 );
|
|
365
|
+
|
|
366
|
+
geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
|
|
367
|
+
geometry.setAttribute( 'position', new THREE.InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
|
|
368
|
+
geometry.setAttribute( 'uv', new THREE.InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
|
|
369
|
+
|
|
370
|
+
return geometry;
|
|
371
|
+
|
|
372
|
+
} )();
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
|
|
2
|
+
function SuperSky ( o ) {
|
|
3
|
+
|
|
4
|
+
this.skyResolution = 512;
|
|
5
|
+
|
|
6
|
+
this.size = o.size || 10000;
|
|
7
|
+
this.callback = o.callback || function(){};
|
|
8
|
+
|
|
9
|
+
this.setting = {
|
|
10
|
+
|
|
11
|
+
t:0,
|
|
12
|
+
fog:0,
|
|
13
|
+
cloud_size: .45,
|
|
14
|
+
cloud_covr: .3,
|
|
15
|
+
cloud_dens: 40,
|
|
16
|
+
|
|
17
|
+
inclination: 45,
|
|
18
|
+
azimuth: 90,
|
|
19
|
+
hour:12,
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this.scene = o.scene;
|
|
24
|
+
this.renderer = o.renderer;
|
|
25
|
+
|
|
26
|
+
this.sceneSky = new THREE.Scene();
|
|
27
|
+
|
|
28
|
+
this.urls = ['./glsl/base_vs.glsl', './glsl/dome_fs.glsl', './glsl/sky_fs.glsl'];
|
|
29
|
+
this.shaders = {};
|
|
30
|
+
this.textureLoader = new THREE.TextureLoader();
|
|
31
|
+
|
|
32
|
+
this.geometry = new THREE.SphereBufferGeometry( this.size, 30, 15 );
|
|
33
|
+
this.material = new THREE.ShaderMaterial();
|
|
34
|
+
|
|
35
|
+
THREE.Mesh.call( this, this.geometry, this.material );
|
|
36
|
+
|
|
37
|
+
this.visible = false;
|
|
38
|
+
this.castShadow = false;
|
|
39
|
+
this.receiveShadow = false;
|
|
40
|
+
this.needsUpdate = false;
|
|
41
|
+
this.torad = 0.0174532925199432957;
|
|
42
|
+
|
|
43
|
+
this.addLight();
|
|
44
|
+
this.load();
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
SuperSky.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
|
|
49
|
+
|
|
50
|
+
constructor: SuperSky,
|
|
51
|
+
|
|
52
|
+
load: function () {
|
|
53
|
+
if( this.urls.length === 0 ){
|
|
54
|
+
|
|
55
|
+
// load noise map
|
|
56
|
+
this.noiseMap = this.textureLoader.load( "./assets/textures/sky/noise.png", function ( texture ) { texture.wrapS = texture.wrapT = THREE.RepeatWrapping; texture.flipY = false; this.init(); }.bind(this) )
|
|
57
|
+
|
|
58
|
+
} else{
|
|
59
|
+
this.loadShader( this.urls.shift() );
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
loadShader : function ( link ) {
|
|
64
|
+
|
|
65
|
+
var name = link.substring( link.lastIndexOf('/')+1, link.lastIndexOf('.') );
|
|
66
|
+
var xhr = new XMLHttpRequest();
|
|
67
|
+
xhr.open('GET', link, true );
|
|
68
|
+
|
|
69
|
+
xhr.onreadystatechange = function () {
|
|
70
|
+
|
|
71
|
+
if ( xhr.readyState === 2 ) {
|
|
72
|
+
} else if ( xhr.readyState === 3 ) { // progress
|
|
73
|
+
} else if ( xhr.readyState === 4 ) {
|
|
74
|
+
if ( xhr.status === 200 || xhr.status === 0 ){
|
|
75
|
+
this.shaders[name] = xhr.response;
|
|
76
|
+
this.load();
|
|
77
|
+
}
|
|
78
|
+
else console.error( "Couldn't load ["+ name + "] [" + xhr.status + "]" );
|
|
79
|
+
}
|
|
80
|
+
}.bind(this);
|
|
81
|
+
|
|
82
|
+
xhr.send( null );
|
|
83
|
+
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
addLight: function () {
|
|
87
|
+
|
|
88
|
+
this.sunMaterial = new THREE.SpriteMaterial( { map: this.textureLoader.load("assets/textures/sky/lensflare1.png"), blending:THREE.AdditiveBlending, opacity:0.5 } );
|
|
89
|
+
var sunSprite = new THREE.Sprite( this.sunMaterial );
|
|
90
|
+
sunSprite.scale.set( 40, 40, 1 );
|
|
91
|
+
|
|
92
|
+
this.sun = new THREE.DirectionalLight( 0xffffff, 4 );
|
|
93
|
+
this.sun.add( sunSprite );
|
|
94
|
+
|
|
95
|
+
var dd = 20;
|
|
96
|
+
this.sun.shadow.camera.top = dd;
|
|
97
|
+
this.sun.shadow.camera.bottom = - dd;
|
|
98
|
+
this.sun.shadow.camera.left = - dd;
|
|
99
|
+
this.sun.shadow.camera.right = dd;
|
|
100
|
+
this.sun.shadow.camera.near = 880;
|
|
101
|
+
this.sun.shadow.camera.far = 920;
|
|
102
|
+
this.sun.shadow.mapSize.width = 1024;
|
|
103
|
+
this.sun.shadow.mapSize.height = 1024;
|
|
104
|
+
//this.sun.shadow.bias = 0.001;
|
|
105
|
+
this.sun.shadow.radius = 2;
|
|
106
|
+
this.sun.castShadow = true;
|
|
107
|
+
|
|
108
|
+
this.moonMaterial = new THREE.SpriteMaterial( { map: this.textureLoader.load("assets/textures/sky/lensflare2.png"), opacity:0.3 } );
|
|
109
|
+
var moonSprite = new THREE.Sprite( this.moonMaterial );
|
|
110
|
+
moonSprite.scale.set( 70, 70, 1 );
|
|
111
|
+
|
|
112
|
+
this.moon = new THREE.DirectionalLight( 0xffffff, 0.8 );//new THREE.PointLight( 0x909090, 0.5, 10000, 2 );
|
|
113
|
+
this.moon.add( moonSprite );
|
|
114
|
+
|
|
115
|
+
this.ambient = new THREE.AmbientLight( 0x3b4c5a, 0.5 );
|
|
116
|
+
//this.ambient = new THREE.HemisphereLight(0, 0x3b4c5a, 0.1);
|
|
117
|
+
|
|
118
|
+
this.scene.add( this.sun );
|
|
119
|
+
this.scene.add( this.moon );
|
|
120
|
+
|
|
121
|
+
//this.scene.add( new THREE.CameraHelper( this.sun.shadow.camera ) );
|
|
122
|
+
this.scene.add( this.ambient );
|
|
123
|
+
|
|
124
|
+
this.sunSph = new THREE.Spherical(this.size-this.size*0.1);
|
|
125
|
+
this.moonSph = new THREE.Spherical(this.size-this.size*0.1);
|
|
126
|
+
|
|
127
|
+
this.sunPosition = new THREE.Vector3();
|
|
128
|
+
this.moonPosition = new THREE.Vector3();
|
|
129
|
+
|
|
130
|
+
var textureFlare3 = this.textureLoader.load("assets/textures/sky/lensflare3.png")
|
|
131
|
+
this.lensflare = new THREE.Lensflare();
|
|
132
|
+
this.lensflare.addElement( new THREE.LensflareElement( this.textureLoader.load("assets/textures/sky/lensflare0.png"), this.size*0.1, 0, this.sun.color ) );
|
|
133
|
+
this.lensflare.addElement( new THREE.LensflareElement( textureFlare3, 60, 0.6, this.sun.color ) );
|
|
134
|
+
this.lensflare.addElement( new THREE.LensflareElement( textureFlare3, 70, 0.7, this.sun.color ) );
|
|
135
|
+
this.lensflare.addElement( new THREE.LensflareElement( textureFlare3, 120, 0.9, this.sun.color ) );
|
|
136
|
+
this.lensflare.addElement( new THREE.LensflareElement( textureFlare3, 70, 1, this.sun.color ) );
|
|
137
|
+
this.sun.add(this.lensflare);
|
|
138
|
+
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
init: function (){
|
|
142
|
+
|
|
143
|
+
this.materialSky = new THREE.ShaderMaterial( {
|
|
144
|
+
|
|
145
|
+
uniforms: {
|
|
146
|
+
lightdir: { value: this.sunPosition },
|
|
147
|
+
noiseMap: { value: this.noiseMap },
|
|
148
|
+
cloud_size: { value: this.setting.cloud_size },
|
|
149
|
+
cloud_covr: { value: this.setting.cloud_covr },
|
|
150
|
+
cloud_dens: { value: this.setting.cloud_dens },
|
|
151
|
+
cloudColor: { value: new THREE.Color(0xFFFFFF) },
|
|
152
|
+
groundColor: { value: new THREE.Color(0x3b4c5a) },
|
|
153
|
+
fogColor: { value: new THREE.Color(0xff0000) },
|
|
154
|
+
fog: { value: this.setting.fog },
|
|
155
|
+
t: { value: this.setting.t }
|
|
156
|
+
},
|
|
157
|
+
vertexShader: this.shaders['base_vs'],
|
|
158
|
+
fragmentShader: this.shaders['sky_fs'],
|
|
159
|
+
depthWrite: false,
|
|
160
|
+
depthTest: false,
|
|
161
|
+
side:THREE.BackSide,
|
|
162
|
+
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
var t = new THREE.IcosahedronGeometry( 1, 1 );
|
|
166
|
+
var cmesh = new THREE.Mesh( t, this.materialSky );
|
|
167
|
+
this.sceneSky.add( cmesh );
|
|
168
|
+
|
|
169
|
+
this.cubeCameraRender = new THREE.WebGLCubeRenderTarget( this.skyResolution, {
|
|
170
|
+
format: THREE.RGBFormat,
|
|
171
|
+
generateMipmaps: true,
|
|
172
|
+
minFilter: THREE.LinearMipmapLinearFilter,
|
|
173
|
+
encoding: THREE.sRGBEncoding
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
this.cubeCamera = new THREE.CubeCamera( 0.5, 2, this.cubeCameraRender );
|
|
177
|
+
this.sceneSky.add( this.cubeCamera );
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
//this.render();
|
|
181
|
+
this.envMap = this.cubeCameraRender.texture;
|
|
182
|
+
//this.envMap.minFilter = THREE.LinearMipMapLinearFilter;
|
|
183
|
+
//this.envMap.format = THREE.RGBAFormat;
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
this.material = new THREE.ShaderMaterial( {
|
|
188
|
+
|
|
189
|
+
uniforms: {
|
|
190
|
+
lightdir: { value: this.sunPosition },
|
|
191
|
+
lunardir: { value: new THREE.Vector3(0, -.2, 1) },
|
|
192
|
+
tCube: { value: this.envMap },
|
|
193
|
+
tDome: { value: this.textureLoader.load( "./assets/textures/sky/milkyway.png", function ( t ) { t.encoding = THREE.sRGBEncoding; } ) },
|
|
194
|
+
},
|
|
195
|
+
vertexShader: this.shaders['base_vs'],
|
|
196
|
+
fragmentShader: this.shaders['dome_fs'],
|
|
197
|
+
side:THREE.BackSide,
|
|
198
|
+
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
this.material.needsUpdate = true;
|
|
202
|
+
|
|
203
|
+
this.update();
|
|
204
|
+
|
|
205
|
+
this.callback();
|
|
206
|
+
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
k: function (e, t) {
|
|
210
|
+
var n = t.dot(t),
|
|
211
|
+
a = 2 * t.dot(e),
|
|
212
|
+
o = e.dot(e) - 1,
|
|
213
|
+
r = a * a - 4 * n * o,
|
|
214
|
+
i = Math.sqrt(r),
|
|
215
|
+
l = (-a - i) / 2,
|
|
216
|
+
s = o / l;
|
|
217
|
+
return s
|
|
218
|
+
},
|
|
219
|
+
|
|
220
|
+
z: function (e, t, n, a) {
|
|
221
|
+
var o = new THREE.Vector3(.188, .458, .682),
|
|
222
|
+
r = a.y >= 0 ? 1 : 0;
|
|
223
|
+
return this.r = (t.x - t.x * Math.pow(o.x, n / e)) * r, this.g = (t.y - t.y * Math.pow(o.y, n / e)) * r, this.b = (t.z - t.z * Math.pow(o.z, n / e)) * r, this
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
setData: function ( d ) {
|
|
227
|
+
|
|
228
|
+
this.setting = d;
|
|
229
|
+
this.update();
|
|
230
|
+
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
update: function () {
|
|
234
|
+
|
|
235
|
+
var setting = this.setting;
|
|
236
|
+
|
|
237
|
+
setting.inclination = (setting.hour*15)-90;
|
|
238
|
+
|
|
239
|
+
this.sunSph.phi = (setting.inclination-90) * this.torad;
|
|
240
|
+
this.sunSph.theta = (setting.azimuth-90) * this.torad;
|
|
241
|
+
this.sun.position.setFromSpherical( this.sunSph );
|
|
242
|
+
|
|
243
|
+
this.moonSph.phi = (setting.inclination+90) * this.torad;
|
|
244
|
+
this.moonSph.theta = (setting.azimuth-90) * this.torad;
|
|
245
|
+
this.moon.position.setFromSpherical( this.moonSph )
|
|
246
|
+
|
|
247
|
+
this.sunPosition = this.sun.position.clone().normalize();
|
|
248
|
+
this.moonPosition = this.sun.position.clone().normalize();
|
|
249
|
+
|
|
250
|
+
// sun color formule
|
|
251
|
+
var n = this.k(new THREE.Vector3(0, .99, 0), this.sunPosition), a = this.z(n, new THREE.Vector3(1.8, 1.8, 1.8), .028, this.sunPosition);
|
|
252
|
+
a.r = a.r > 1.0 ? 1.0:a.r;
|
|
253
|
+
a.g = a.g > 1.0 ? 1.0:a.g;
|
|
254
|
+
a.b = a.b > 1.0 ? 1.0:a.b;
|
|
255
|
+
|
|
256
|
+
this.day = a.r;
|
|
257
|
+
|
|
258
|
+
this.sun.color.setRGB(a.r, a.g, a.b);
|
|
259
|
+
this.sunMaterial.color.copy( this.sun.color )
|
|
260
|
+
|
|
261
|
+
this.sun.intensity = a.r;
|
|
262
|
+
|
|
263
|
+
var ma = 1 - a.r;
|
|
264
|
+
var mg = 1 - a.g;
|
|
265
|
+
var mb = 1 - a.b;
|
|
266
|
+
this.moon.intensity = ma*0.35;
|
|
267
|
+
this.moon.color.setRGB(ma, mg, mb);
|
|
268
|
+
this.moonMaterial.color.copy( this.moon.color );
|
|
269
|
+
|
|
270
|
+
this.materialSky.uniforms.t.value = setting.t;
|
|
271
|
+
this.materialSky.uniforms.fog.value = setting.fog;
|
|
272
|
+
this.materialSky.uniforms.cloud_size.value = setting.cloud_size;
|
|
273
|
+
this.materialSky.uniforms.cloud_covr.value = setting.cloud_covr;
|
|
274
|
+
this.materialSky.uniforms.cloud_dens.value = setting.cloud_dens;
|
|
275
|
+
this.materialSky.uniforms.lightdir.value = this.sunPosition;
|
|
276
|
+
this.material.uniforms.lightdir.value = this.sunPosition;
|
|
277
|
+
|
|
278
|
+
this.needsUpdate = true;
|
|
279
|
+
|
|
280
|
+
if( !this.visible ) this.visible = true;
|
|
281
|
+
|
|
282
|
+
//this.render()
|
|
283
|
+
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
render: function () {
|
|
287
|
+
|
|
288
|
+
this.cubeCamera.update( this.renderer, this.sceneSky );
|
|
289
|
+
this.needsUpdate = false;
|
|
290
|
+
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
});
|