uil 4.0.0 → 4.0.4
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 +5 -1
- package/build/uil.js +33 -45
- package/build/uil.min.js +1 -1
- package/build/uil.module.js +45 -58
- package/package.json +6 -10
- package/examples/js/BufferGeometryUtils.js +0 -921
- package/examples/js/SimplexNoise.js +0 -324
- package/examples/js/controls/OrbitControls.js +0 -1215
- package/examples/js/controls/OrbitControls_.js +0 -1042
- package/examples/js/libs/sea3d.min.js +0 -373
- package/examples/js/libs/three.min.js +0 -6
- package/examples/js/math.js +0 -447
- package/examples/js/objects/Landscape.js +0 -778
- package/examples/js/objects/Lensflare.js +0 -372
- package/examples/js/objects/SuperSky.js +0 -297
- package/examples/js/objects/Water.js +0 -329
- package/src/Uil.js +0 -6
- package/src/Uil_dev.js +0 -15
- package/src/core/Gui.js +0 -807
- package/src/core/Proto.js +0 -679
- package/src/core/Roots.js +0 -864
- package/src/core/Tools.js +0 -830
- package/src/core/V2.js +0 -131
- package/src/core/add.js +0 -85
- package/src/polyfills.js +0 -85
- package/src/proto/Bool.js +0 -147
- package/src/proto/Button.js +0 -357
- package/src/proto/Circular.js +0 -230
- package/src/proto/Color.js +0 -411
- package/src/proto/Empty.js +0 -15
- package/src/proto/Fps.js +0 -327
- package/src/proto/Graph.js +0 -310
- package/src/proto/Grid.js +0 -297
- package/src/proto/Group.js +0 -430
- package/src/proto/Item.js +0 -120
- package/src/proto/Joystick.js +0 -241
- package/src/proto/Knob.js +0 -262
- package/src/proto/List.js +0 -789
- package/src/proto/Numeric.js +0 -417
- package/src/proto/Pad2D.js +0 -268
- package/src/proto/Rubric.js +0 -0
- package/src/proto/Select.js +0 -178
- package/src/proto/Selector.js +0 -13
- package/src/proto/Slide.js +0 -267
- package/src/proto/TextInput.js +0 -181
- package/src/proto/Title.js +0 -61
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Work based on :
|
|
3
|
-
* http://slayvin.net : Flat mirror for three.js
|
|
4
|
-
* http://www.adelphi.edu/~stemkoski : An implementation of water shader based on the flat mirror
|
|
5
|
-
* http://29a.ch/ && http://29a.ch/slides/2012/webglwater/ : Water shader explanations in WebGL
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
THREE.Water = function ( geometry, options ) {
|
|
9
|
-
|
|
10
|
-
THREE.Mesh.call( this, geometry );
|
|
11
|
-
|
|
12
|
-
var scope = this;
|
|
13
|
-
|
|
14
|
-
options = options || {};
|
|
15
|
-
|
|
16
|
-
var textureWidth = options.textureWidth !== undefined ? options.textureWidth : 512;
|
|
17
|
-
var textureHeight = options.textureHeight !== undefined ? options.textureHeight : 512;
|
|
18
|
-
|
|
19
|
-
var clipBias = options.clipBias !== undefined ? options.clipBias : 0.0;
|
|
20
|
-
var alpha = options.alpha !== undefined ? options.alpha : 1.0;
|
|
21
|
-
var time = options.time !== undefined ? options.time : 0.0;
|
|
22
|
-
var normalSampler = options.waterNormals !== undefined ? options.waterNormals : null;
|
|
23
|
-
var sunDirection = options.sunDirection !== undefined ? options.sunDirection : new THREE.Vector3( 0.70707, 0.70707, 0.0 );
|
|
24
|
-
var sunColor = new THREE.Color( options.sunColor !== undefined ? options.sunColor : 0xffffff );
|
|
25
|
-
var waterColor = new THREE.Color( options.waterColor !== undefined ? options.waterColor : 0x7F7F7F );
|
|
26
|
-
var eye = options.eye !== undefined ? options.eye : new THREE.Vector3( 0, 0, 0 );
|
|
27
|
-
var distortionScale = options.distortionScale !== undefined ? options.distortionScale : 20.0;
|
|
28
|
-
var side = options.side !== undefined ? options.side : THREE.FrontSide;
|
|
29
|
-
var fog = options.fog !== undefined ? options.fog : false;
|
|
30
|
-
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
var mirrorPlane = new THREE.Plane();
|
|
34
|
-
var normal = new THREE.Vector3();
|
|
35
|
-
var mirrorWorldPosition = new THREE.Vector3();
|
|
36
|
-
var cameraWorldPosition = new THREE.Vector3();
|
|
37
|
-
var rotationMatrix = new THREE.Matrix4();
|
|
38
|
-
var lookAtPosition = new THREE.Vector3( 0, 0, - 1 );
|
|
39
|
-
var clipPlane = new THREE.Vector4();
|
|
40
|
-
|
|
41
|
-
var view = new THREE.Vector3();
|
|
42
|
-
var target = new THREE.Vector3();
|
|
43
|
-
var q = new THREE.Vector4();
|
|
44
|
-
|
|
45
|
-
var textureMatrix = new THREE.Matrix4();
|
|
46
|
-
|
|
47
|
-
var mirrorCamera = new THREE.PerspectiveCamera();
|
|
48
|
-
|
|
49
|
-
var parameters = {
|
|
50
|
-
minFilter: THREE.LinearFilter,
|
|
51
|
-
magFilter: THREE.LinearFilter,
|
|
52
|
-
format: THREE.RGBFormat
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
var renderTarget = new THREE.WebGLRenderTarget( textureWidth, textureHeight, parameters );
|
|
56
|
-
|
|
57
|
-
if ( ! THREE.MathUtils.isPowerOfTwo( textureWidth ) || ! THREE.MathUtils.isPowerOfTwo( textureHeight ) ) {
|
|
58
|
-
|
|
59
|
-
renderTarget.texture.generateMipmaps = false;
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
var mirrorShader = {
|
|
64
|
-
|
|
65
|
-
uniforms: THREE.UniformsUtils.merge( [
|
|
66
|
-
THREE.UniformsLib[ 'fog' ],
|
|
67
|
-
THREE.UniformsLib[ 'lights' ],
|
|
68
|
-
{
|
|
69
|
-
'normalSampler': { value: null },
|
|
70
|
-
'mirrorSampler': { value: null },
|
|
71
|
-
'alpha': { value: 1.0 },
|
|
72
|
-
'time': { value: 0.0 },
|
|
73
|
-
'size': { value: options.size !== undefined ? options.size : 1.0 },
|
|
74
|
-
'distortionScale': { value: 20.0 },
|
|
75
|
-
'textureMatrix': { value: new THREE.Matrix4() },
|
|
76
|
-
'sunColor': { value: new THREE.Color( 0x7F7F7F ) },
|
|
77
|
-
'sunDirection': { value: new THREE.Vector3( 0.70707, 0.70707, 0 ) },
|
|
78
|
-
'eye': { value: new THREE.Vector3() },
|
|
79
|
-
'waterColor': { value: waterColor },
|
|
80
|
-
'depth': { value: options.depth !== undefined ? options.depth : 1.5 }
|
|
81
|
-
}
|
|
82
|
-
] ),
|
|
83
|
-
|
|
84
|
-
vertexShader: [
|
|
85
|
-
'uniform mat4 textureMatrix;',
|
|
86
|
-
'uniform float time;',
|
|
87
|
-
|
|
88
|
-
'varying vec4 mirrorCoord;',
|
|
89
|
-
'varying vec4 worldPosition;',
|
|
90
|
-
|
|
91
|
-
'#include <common>',
|
|
92
|
-
'#include <fog_pars_vertex>',
|
|
93
|
-
'#include <shadowmap_pars_vertex>',
|
|
94
|
-
'#include <logdepthbuf_pars_vertex>',
|
|
95
|
-
|
|
96
|
-
'void main() {',
|
|
97
|
-
' mirrorCoord = modelMatrix * vec4( position, 1.0 );',
|
|
98
|
-
' worldPosition = mirrorCoord.xyzw;',
|
|
99
|
-
' mirrorCoord = textureMatrix * mirrorCoord;',
|
|
100
|
-
' vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );',
|
|
101
|
-
' gl_Position = projectionMatrix * mvPosition;',
|
|
102
|
-
|
|
103
|
-
'#include <beginnormal_vertex>',
|
|
104
|
-
'#include <defaultnormal_vertex>',
|
|
105
|
-
'#include <logdepthbuf_vertex>',
|
|
106
|
-
'#include <fog_vertex>',
|
|
107
|
-
'#include <shadowmap_vertex>',
|
|
108
|
-
'}'
|
|
109
|
-
].join( '\n' ),
|
|
110
|
-
|
|
111
|
-
fragmentShader: [
|
|
112
|
-
'uniform sampler2D mirrorSampler;',
|
|
113
|
-
'uniform float alpha;',
|
|
114
|
-
'uniform float time;',
|
|
115
|
-
'uniform float size;',
|
|
116
|
-
'uniform float distortionScale;',
|
|
117
|
-
'uniform sampler2D normalSampler;',
|
|
118
|
-
'uniform vec3 sunColor;',
|
|
119
|
-
'uniform vec3 sunDirection;',
|
|
120
|
-
'uniform vec3 eye;',
|
|
121
|
-
'uniform vec3 waterColor;',
|
|
122
|
-
'uniform float depth;',
|
|
123
|
-
|
|
124
|
-
'varying vec4 mirrorCoord;',
|
|
125
|
-
'varying vec4 worldPosition;',
|
|
126
|
-
|
|
127
|
-
'vec4 getNoise( vec2 uv ) {',
|
|
128
|
-
' vec2 uv0 = ( uv / 103.0 ) + vec2(time / 17.0, time / 29.0);',
|
|
129
|
-
' vec2 uv1 = uv / 107.0-vec2( time / -19.0, time / 31.0 );',
|
|
130
|
-
' vec2 uv2 = uv / vec2( 8907.0, 9803.0 ) + vec2( time / 101.0, time / 97.0 );',
|
|
131
|
-
' vec2 uv3 = uv / vec2( 1091.0, 1027.0 ) - vec2( time / 109.0, time / -113.0 );',
|
|
132
|
-
' vec4 noise = texture2D( normalSampler, uv0 ) +',
|
|
133
|
-
' texture2D( normalSampler, uv1 ) +',
|
|
134
|
-
' texture2D( normalSampler, uv2 ) +',
|
|
135
|
-
' texture2D( normalSampler, uv3 );',
|
|
136
|
-
' return noise * 0.5 - 1.0;',
|
|
137
|
-
'}',
|
|
138
|
-
|
|
139
|
-
'void sunLight( const vec3 surfaceNormal, const vec3 eyeDirection, float shiny, float spec, float diffuse, inout vec3 diffuseColor, inout vec3 specularColor ) {',
|
|
140
|
-
' vec3 reflection = normalize( reflect( -sunDirection, surfaceNormal ) );',
|
|
141
|
-
' float direction = max( 0.0, dot( eyeDirection, reflection ) );',
|
|
142
|
-
' specularColor += pow( direction, shiny ) * sunColor * spec;',
|
|
143
|
-
' diffuseColor += max( dot( sunDirection, surfaceNormal ), 0.0 ) * sunColor * diffuse;',
|
|
144
|
-
'}',
|
|
145
|
-
|
|
146
|
-
'#include <common>',
|
|
147
|
-
'#include <packing>',
|
|
148
|
-
'#include <bsdfs>',
|
|
149
|
-
'#include <fog_pars_fragment>',
|
|
150
|
-
'#include <logdepthbuf_pars_fragment>',
|
|
151
|
-
'#include <lights_pars_begin>',
|
|
152
|
-
'#include <shadowmap_pars_fragment>',
|
|
153
|
-
'#include <shadowmask_pars_fragment>',
|
|
154
|
-
|
|
155
|
-
'void main() {',
|
|
156
|
-
|
|
157
|
-
'#include <logdepthbuf_fragment>',
|
|
158
|
-
' vec4 noise = getNoise( worldPosition.xz * size );',
|
|
159
|
-
' vec3 surfaceNormal = normalize( noise.xzy * vec3( depth, 1.0, depth ) );',
|
|
160
|
-
|
|
161
|
-
' vec3 diffuseLight = vec3(0.0);',
|
|
162
|
-
' vec3 specularLight = vec3(0.0);',
|
|
163
|
-
|
|
164
|
-
' vec3 worldToEye = eye-worldPosition.xyz;',
|
|
165
|
-
' vec3 eyeDirection = normalize( worldToEye );',
|
|
166
|
-
' sunLight( surfaceNormal, eyeDirection, 100.0, 2.0, 0.5, diffuseLight, specularLight );',
|
|
167
|
-
|
|
168
|
-
' float distance = length(worldToEye);',
|
|
169
|
-
|
|
170
|
-
' vec2 distortion = surfaceNormal.xz * ( 0.001 + 1.0 / distance ) * distortionScale;',
|
|
171
|
-
' vec3 reflectionSample = vec3( texture2D( mirrorSampler, mirrorCoord.xy / mirrorCoord.w + distortion ) );',
|
|
172
|
-
|
|
173
|
-
' float theta = max( dot( eyeDirection, surfaceNormal ), 0.0 );',
|
|
174
|
-
' float rf0 = 0.3;',
|
|
175
|
-
' float reflectance = rf0 + ( 1.0 - rf0 ) * pow( ( 1.0 - theta ), 5.0 );',
|
|
176
|
-
' vec3 scatter = max( 0.0, dot( surfaceNormal, eyeDirection ) ) * waterColor;',
|
|
177
|
-
' vec3 albedo = mix( ( sunColor * diffuseLight * 0.3 + scatter ) * getShadowMask(), ( vec3( 0.1 ) + reflectionSample * 0.9 + reflectionSample * specularLight ), reflectance);',
|
|
178
|
-
' vec3 outgoingLight = albedo;',
|
|
179
|
-
' gl_FragColor = vec4( outgoingLight, alpha );',
|
|
180
|
-
|
|
181
|
-
'#include <tonemapping_fragment>',
|
|
182
|
-
'#include <fog_fragment>',
|
|
183
|
-
'}'
|
|
184
|
-
].join( '\n' )
|
|
185
|
-
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
var material = new THREE.ShaderMaterial( {
|
|
189
|
-
fragmentShader: mirrorShader.fragmentShader,
|
|
190
|
-
vertexShader: mirrorShader.vertexShader,
|
|
191
|
-
uniforms: THREE.UniformsUtils.clone( mirrorShader.uniforms ),
|
|
192
|
-
transparent: true,
|
|
193
|
-
lights: true,
|
|
194
|
-
side: side,
|
|
195
|
-
fog: fog,
|
|
196
|
-
//shadowSide : false,
|
|
197
|
-
} );
|
|
198
|
-
|
|
199
|
-
material.uniforms[ 'mirrorSampler' ].value = renderTarget.texture;
|
|
200
|
-
material.uniforms[ 'textureMatrix' ].value = textureMatrix;
|
|
201
|
-
material.uniforms[ 'alpha' ].value = alpha;
|
|
202
|
-
material.uniforms[ 'time' ].value = time;
|
|
203
|
-
material.uniforms[ 'normalSampler' ].value = normalSampler;
|
|
204
|
-
material.uniforms[ 'sunColor' ].value = sunColor;
|
|
205
|
-
material.uniforms[ 'waterColor' ].value = waterColor;
|
|
206
|
-
material.uniforms[ 'sunDirection' ].value = sunDirection;
|
|
207
|
-
material.uniforms[ 'distortionScale' ].value = distortionScale;
|
|
208
|
-
|
|
209
|
-
material.uniforms[ 'eye' ].value = eye;
|
|
210
|
-
|
|
211
|
-
scope.material = material;
|
|
212
|
-
|
|
213
|
-
scope.onBeforeRender = function ( renderer, scene, camera ) {
|
|
214
|
-
|
|
215
|
-
mirrorWorldPosition.setFromMatrixPosition( scope.matrixWorld );
|
|
216
|
-
cameraWorldPosition.setFromMatrixPosition( camera.matrixWorld );
|
|
217
|
-
|
|
218
|
-
rotationMatrix.extractRotation( scope.matrixWorld );
|
|
219
|
-
|
|
220
|
-
normal.set( 0, 0, 1 );
|
|
221
|
-
normal.applyMatrix4( rotationMatrix );
|
|
222
|
-
|
|
223
|
-
view.subVectors( mirrorWorldPosition, cameraWorldPosition );
|
|
224
|
-
|
|
225
|
-
// Avoid rendering when mirror is facing away
|
|
226
|
-
|
|
227
|
-
if ( view.dot( normal ) > 0 ) return;
|
|
228
|
-
|
|
229
|
-
view.reflect( normal ).negate();
|
|
230
|
-
view.add( mirrorWorldPosition );
|
|
231
|
-
|
|
232
|
-
rotationMatrix.extractRotation( camera.matrixWorld );
|
|
233
|
-
|
|
234
|
-
lookAtPosition.set( 0, 0, - 1 );
|
|
235
|
-
lookAtPosition.applyMatrix4( rotationMatrix );
|
|
236
|
-
lookAtPosition.add( cameraWorldPosition );
|
|
237
|
-
|
|
238
|
-
target.subVectors( mirrorWorldPosition, lookAtPosition );
|
|
239
|
-
target.reflect( normal ).negate();
|
|
240
|
-
target.add( mirrorWorldPosition );
|
|
241
|
-
|
|
242
|
-
mirrorCamera.position.copy( view );
|
|
243
|
-
mirrorCamera.up.set( 0, 1, 0 );
|
|
244
|
-
mirrorCamera.up.applyMatrix4( rotationMatrix );
|
|
245
|
-
mirrorCamera.up.reflect( normal );
|
|
246
|
-
mirrorCamera.lookAt( target );
|
|
247
|
-
|
|
248
|
-
mirrorCamera.far = camera.far; // Used in WebGLBackground
|
|
249
|
-
|
|
250
|
-
mirrorCamera.updateMatrixWorld();
|
|
251
|
-
mirrorCamera.projectionMatrix.copy( camera.projectionMatrix );
|
|
252
|
-
|
|
253
|
-
// Update the texture matrix
|
|
254
|
-
textureMatrix.set(
|
|
255
|
-
0.5, 0.0, 0.0, 0.5,
|
|
256
|
-
0.0, 0.5, 0.0, 0.5,
|
|
257
|
-
0.0, 0.0, 0.5, 0.5,
|
|
258
|
-
0.0, 0.0, 0.0, 1.0
|
|
259
|
-
);
|
|
260
|
-
textureMatrix.multiply( mirrorCamera.projectionMatrix );
|
|
261
|
-
textureMatrix.multiply( mirrorCamera.matrixWorldInverse );
|
|
262
|
-
|
|
263
|
-
// Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
|
|
264
|
-
// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
|
|
265
|
-
mirrorPlane.setFromNormalAndCoplanarPoint( normal, mirrorWorldPosition );
|
|
266
|
-
mirrorPlane.applyMatrix4( mirrorCamera.matrixWorldInverse );
|
|
267
|
-
|
|
268
|
-
clipPlane.set( mirrorPlane.normal.x, mirrorPlane.normal.y, mirrorPlane.normal.z, mirrorPlane.constant );
|
|
269
|
-
|
|
270
|
-
var projectionMatrix = mirrorCamera.projectionMatrix;
|
|
271
|
-
|
|
272
|
-
q.x = ( Math.sign( clipPlane.x ) + projectionMatrix.elements[ 8 ] ) / projectionMatrix.elements[ 0 ];
|
|
273
|
-
q.y = ( Math.sign( clipPlane.y ) + projectionMatrix.elements[ 9 ] ) / projectionMatrix.elements[ 5 ];
|
|
274
|
-
q.z = - 1.0;
|
|
275
|
-
q.w = ( 1.0 + projectionMatrix.elements[ 10 ] ) / projectionMatrix.elements[ 14 ];
|
|
276
|
-
|
|
277
|
-
// Calculate the scaled plane vector
|
|
278
|
-
clipPlane.multiplyScalar( 2.0 / clipPlane.dot( q ) );
|
|
279
|
-
|
|
280
|
-
// Replacing the third row of the projection matrix
|
|
281
|
-
projectionMatrix.elements[ 2 ] = clipPlane.x;
|
|
282
|
-
projectionMatrix.elements[ 6 ] = clipPlane.y;
|
|
283
|
-
projectionMatrix.elements[ 10 ] = clipPlane.z + 1.0 - clipBias;
|
|
284
|
-
projectionMatrix.elements[ 14 ] = clipPlane.w;
|
|
285
|
-
|
|
286
|
-
eye.setFromMatrixPosition( camera.matrixWorld );
|
|
287
|
-
|
|
288
|
-
// Render
|
|
289
|
-
|
|
290
|
-
var currentRenderTarget = renderer.getRenderTarget();
|
|
291
|
-
|
|
292
|
-
var currentXrEnabled = renderer.xr.enabled;
|
|
293
|
-
var currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
|
|
294
|
-
|
|
295
|
-
scope.visible = false;
|
|
296
|
-
|
|
297
|
-
renderer.xr.enabled = false; // Avoid camera modification and recursion
|
|
298
|
-
renderer.shadowMap.autoUpdate = false; // Avoid re-computing shadows
|
|
299
|
-
|
|
300
|
-
renderer.setRenderTarget( renderTarget );
|
|
301
|
-
|
|
302
|
-
renderer.state.buffers.depth.setMask( true ); // make sure the depth buffer is writable so it can be properly cleared, see #18897
|
|
303
|
-
|
|
304
|
-
if ( renderer.autoClear === false ) renderer.clear();
|
|
305
|
-
renderer.render( scene, mirrorCamera );
|
|
306
|
-
|
|
307
|
-
scope.visible = true;
|
|
308
|
-
|
|
309
|
-
renderer.xr.enabled = currentXrEnabled;
|
|
310
|
-
renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
|
|
311
|
-
|
|
312
|
-
renderer.setRenderTarget( currentRenderTarget );
|
|
313
|
-
|
|
314
|
-
// Restore viewport
|
|
315
|
-
|
|
316
|
-
var viewport = camera.viewport;
|
|
317
|
-
|
|
318
|
-
if ( viewport !== undefined ) {
|
|
319
|
-
|
|
320
|
-
renderer.state.viewport( viewport );
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
THREE.Water.prototype = Object.create( THREE.Mesh.prototype );
|
|
329
|
-
THREE.Water.prototype.constructor = THREE.Water;
|
package/src/Uil.js
DELETED