three-stdlib 2.12.1 → 2.13.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/index.cjs.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/objects/GroundProjectedEnv.cjs.js +1 -0
- package/objects/GroundProjectedEnv.d.ts +12 -0
- package/objects/GroundProjectedEnv.js +145 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -104,6 +104,7 @@ export * from './objects/ReflectorRTT';
|
|
|
104
104
|
export * from './objects/ReflectorForSSRPass';
|
|
105
105
|
export * from './objects/Sky';
|
|
106
106
|
export * from './objects/Water2';
|
|
107
|
+
export * from './objects/GroundProjectedEnv';
|
|
107
108
|
export * from './utils/SceneUtils';
|
|
108
109
|
export * from './utils/UVsDebug';
|
|
109
110
|
export * from './utils/GeometryUtils';
|
package/index.js
CHANGED
|
@@ -50,6 +50,7 @@ export { ReflectorRTT } from './objects/ReflectorRTT.js';
|
|
|
50
50
|
export { ReflectorForSSRPass } from './objects/ReflectorForSSRPass.js';
|
|
51
51
|
export { Sky } from './objects/Sky.js';
|
|
52
52
|
export { Water2 } from './objects/Water2.js';
|
|
53
|
+
export { GroundProjectedEnv } from './objects/GroundProjectedEnv.js';
|
|
53
54
|
export { SceneUtils } from './utils/SceneUtils.js';
|
|
54
55
|
export { UVsDebug } from './utils/UVsDebug.js';
|
|
55
56
|
export { GeometryUtils } from './utils/GeometryUtils.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class n extends e.Mesh{constructor(n,o){var t,r;const i=(a=n)&&a.isCubeTexture;var a;const c=(null!=(t=i?null===(r=n.image[0])||void 0===r?void 0:r.width:n.image.width)?t:1024)/4,s=Math.floor(Math.log2(c)),l=Math.pow(2,s),d=[i?"#define ENVMAP_TYPE_CUBE":"","#define CUBEUV_TEXEL_WIDTH "+1/(3*Math.max(l,112)),"#define CUBEUV_TEXEL_HEIGHT "+1/(4*l),`#define CUBEUV_MAX_MIP ${s}.0`].join("\n")+"\n #define ENVMAP_TYPE_CUBE_UV\n varying vec3 vWorldPosition;\n uniform float radius;\n uniform float height;\n uniform float angle;\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube map;\n #else\n uniform sampler2D map;\n #endif\n // From: https://www.shadertoy.com/view/4tsBD7\n float diskIntersectWithBackFaceCulling( vec3 ro, vec3 rd, vec3 c, vec3 n, float r ) \n {\n float d = dot ( rd, n );\n \n if( d > 0.0 ) { return 1e6; }\n \n vec3 o = ro - c;\n float t = - dot( n, o ) / d;\n vec3 q = o + rd * t;\n \n return ( dot( q, q ) < r * r ) ? t : 1e6;\n }\n // From: https://www.iquilezles.org/www/articles/intersectors/intersectors.htm\n float sphereIntersect( vec3 ro, vec3 rd, vec3 ce, float ra ) \n {\n vec3 oc = ro - ce;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - ra * ra;\n float h = b * b - c;\n \n if( h < 0.0 ) { return -1.0; }\n \n h = sqrt( h );\n \n return - b + h;\n }\n vec3 project() \n {\n vec3 p = normalize( vWorldPosition );\n vec3 camPos = cameraPosition;\n camPos.y -= height;\n float intersection = sphereIntersect( camPos, p, vec3( 0.0 ), radius );\n if( intersection > 0.0 ) {\n \n vec3 h = vec3( 0.0, - height, 0.0 );\n float intersection2 = diskIntersectWithBackFaceCulling( camPos, p, h, vec3( 0.0, 1.0, 0.0 ), radius );\n p = ( camPos + min( intersection, intersection2 ) * p ) / radius;\n } else {\n p = vec3( 0.0, 1.0, 0.0 );\n }\n return p;\n }\n #include <common>\n #include <cube_uv_reflection_fragment>\n void main() \n {\n vec3 projectedWorldPosition = project();\n \n #ifdef ENVMAP_TYPE_CUBE\n vec3 outcolor = textureCube( map, projectedWorldPosition ).rgb;\n #else\n vec3 direction = normalize( projectedWorldPosition );\n vec2 uv = equirectUv( direction );\n vec3 outcolor = texture2D( map, uv ).rgb;\n #endif\n gl_FragColor = vec4( outcolor, 1.0 );\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }\n ",u={map:{value:n},height:{value:(null==o?void 0:o.height)||15},radius:{value:(null==o?void 0:o.radius)||100}};super(new e.IcosahedronGeometry(1,16),new e.ShaderMaterial({uniforms:u,fragmentShader:d,vertexShader:"\n varying vec3 vWorldPosition;\n void main() \n {\n vec4 worldPosition = ( modelMatrix * vec4( position, 1.0 ) );\n vWorldPosition = worldPosition.xyz;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n ",side:e.DoubleSide}))}set radius(e){this.material.uniforms.radius.value=e}get radius(){return this.material.uniforms.radius.value}set height(e){this.material.uniforms.height.value=e}get height(){return this.material.uniforms.height.value}}exports.GroundProjectedEnv=n;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Mesh, ShaderMaterial, Texture, CubeTexture, BufferGeometry } from 'three';
|
|
2
|
+
export interface GroundProjectedEnvParameters {
|
|
3
|
+
height?: number;
|
|
4
|
+
radius?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class GroundProjectedEnv extends Mesh<BufferGeometry, ShaderMaterial> {
|
|
7
|
+
constructor(texture: CubeTexture | Texture, options?: GroundProjectedEnvParameters);
|
|
8
|
+
set radius(radius: number);
|
|
9
|
+
get radius(): number;
|
|
10
|
+
set height(height: number);
|
|
11
|
+
get height(): number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Mesh, IcosahedronGeometry, ShaderMaterial, DoubleSide } from 'three';
|
|
2
|
+
|
|
3
|
+
const isCubeTexture = def => def && def.isCubeTexture;
|
|
4
|
+
|
|
5
|
+
class GroundProjectedEnv extends Mesh {
|
|
6
|
+
constructor(texture, options) {
|
|
7
|
+
var _ref, _texture$image$;
|
|
8
|
+
|
|
9
|
+
const isCubeMap = isCubeTexture(texture);
|
|
10
|
+
const w = (_ref = isCubeMap ? (_texture$image$ = texture.image[0]) === null || _texture$image$ === void 0 ? void 0 : _texture$image$.width : texture.image.width) != null ? _ref : 1024;
|
|
11
|
+
const cubeSize = w / 4;
|
|
12
|
+
|
|
13
|
+
const _lodMax = Math.floor(Math.log2(cubeSize));
|
|
14
|
+
|
|
15
|
+
const _cubeSize = Math.pow(2, _lodMax);
|
|
16
|
+
|
|
17
|
+
const width = 3 * Math.max(_cubeSize, 16 * 7);
|
|
18
|
+
const height = 4 * _cubeSize;
|
|
19
|
+
const defines = [isCubeMap ? '#define ENVMAP_TYPE_CUBE' : '', `#define CUBEUV_TEXEL_WIDTH ${1.0 / width}`, `#define CUBEUV_TEXEL_HEIGHT ${1.0 / height}`, `#define CUBEUV_MAX_MIP ${_lodMax}.0`];
|
|
20
|
+
const vertexShader =
|
|
21
|
+
/* glsl */
|
|
22
|
+
`
|
|
23
|
+
varying vec3 vWorldPosition;
|
|
24
|
+
void main()
|
|
25
|
+
{
|
|
26
|
+
vec4 worldPosition = ( modelMatrix * vec4( position, 1.0 ) );
|
|
27
|
+
vWorldPosition = worldPosition.xyz;
|
|
28
|
+
|
|
29
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
const fragmentShader = defines.join('\n') +
|
|
33
|
+
/* glsl */
|
|
34
|
+
`
|
|
35
|
+
#define ENVMAP_TYPE_CUBE_UV
|
|
36
|
+
varying vec3 vWorldPosition;
|
|
37
|
+
uniform float radius;
|
|
38
|
+
uniform float height;
|
|
39
|
+
uniform float angle;
|
|
40
|
+
#ifdef ENVMAP_TYPE_CUBE
|
|
41
|
+
uniform samplerCube map;
|
|
42
|
+
#else
|
|
43
|
+
uniform sampler2D map;
|
|
44
|
+
#endif
|
|
45
|
+
// From: https://www.shadertoy.com/view/4tsBD7
|
|
46
|
+
float diskIntersectWithBackFaceCulling( vec3 ro, vec3 rd, vec3 c, vec3 n, float r )
|
|
47
|
+
{
|
|
48
|
+
float d = dot ( rd, n );
|
|
49
|
+
|
|
50
|
+
if( d > 0.0 ) { return 1e6; }
|
|
51
|
+
|
|
52
|
+
vec3 o = ro - c;
|
|
53
|
+
float t = - dot( n, o ) / d;
|
|
54
|
+
vec3 q = o + rd * t;
|
|
55
|
+
|
|
56
|
+
return ( dot( q, q ) < r * r ) ? t : 1e6;
|
|
57
|
+
}
|
|
58
|
+
// From: https://www.iquilezles.org/www/articles/intersectors/intersectors.htm
|
|
59
|
+
float sphereIntersect( vec3 ro, vec3 rd, vec3 ce, float ra )
|
|
60
|
+
{
|
|
61
|
+
vec3 oc = ro - ce;
|
|
62
|
+
float b = dot( oc, rd );
|
|
63
|
+
float c = dot( oc, oc ) - ra * ra;
|
|
64
|
+
float h = b * b - c;
|
|
65
|
+
|
|
66
|
+
if( h < 0.0 ) { return -1.0; }
|
|
67
|
+
|
|
68
|
+
h = sqrt( h );
|
|
69
|
+
|
|
70
|
+
return - b + h;
|
|
71
|
+
}
|
|
72
|
+
vec3 project()
|
|
73
|
+
{
|
|
74
|
+
vec3 p = normalize( vWorldPosition );
|
|
75
|
+
vec3 camPos = cameraPosition;
|
|
76
|
+
camPos.y -= height;
|
|
77
|
+
float intersection = sphereIntersect( camPos, p, vec3( 0.0 ), radius );
|
|
78
|
+
if( intersection > 0.0 ) {
|
|
79
|
+
|
|
80
|
+
vec3 h = vec3( 0.0, - height, 0.0 );
|
|
81
|
+
float intersection2 = diskIntersectWithBackFaceCulling( camPos, p, h, vec3( 0.0, 1.0, 0.0 ), radius );
|
|
82
|
+
p = ( camPos + min( intersection, intersection2 ) * p ) / radius;
|
|
83
|
+
} else {
|
|
84
|
+
p = vec3( 0.0, 1.0, 0.0 );
|
|
85
|
+
}
|
|
86
|
+
return p;
|
|
87
|
+
}
|
|
88
|
+
#include <common>
|
|
89
|
+
#include <cube_uv_reflection_fragment>
|
|
90
|
+
void main()
|
|
91
|
+
{
|
|
92
|
+
vec3 projectedWorldPosition = project();
|
|
93
|
+
|
|
94
|
+
#ifdef ENVMAP_TYPE_CUBE
|
|
95
|
+
vec3 outcolor = textureCube( map, projectedWorldPosition ).rgb;
|
|
96
|
+
#else
|
|
97
|
+
vec3 direction = normalize( projectedWorldPosition );
|
|
98
|
+
vec2 uv = equirectUv( direction );
|
|
99
|
+
vec3 outcolor = texture2D( map, uv ).rgb;
|
|
100
|
+
#endif
|
|
101
|
+
gl_FragColor = vec4( outcolor, 1.0 );
|
|
102
|
+
#include <tonemapping_fragment>
|
|
103
|
+
#include <encodings_fragment>
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
106
|
+
const uniforms = {
|
|
107
|
+
map: {
|
|
108
|
+
value: texture
|
|
109
|
+
},
|
|
110
|
+
height: {
|
|
111
|
+
value: (options === null || options === void 0 ? void 0 : options.height) || 15
|
|
112
|
+
},
|
|
113
|
+
radius: {
|
|
114
|
+
value: (options === null || options === void 0 ? void 0 : options.radius) || 100
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const geometry = new IcosahedronGeometry(1, 16);
|
|
118
|
+
const material = new ShaderMaterial({
|
|
119
|
+
uniforms,
|
|
120
|
+
fragmentShader,
|
|
121
|
+
vertexShader,
|
|
122
|
+
side: DoubleSide
|
|
123
|
+
});
|
|
124
|
+
super(geometry, material);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
set radius(radius) {
|
|
128
|
+
this.material.uniforms.radius.value = radius;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get radius() {
|
|
132
|
+
return this.material.uniforms.radius.value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
set height(height) {
|
|
136
|
+
this.material.uniforms.height.value = height;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
get height() {
|
|
140
|
+
return this.material.uniforms.height.value;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export { GroundProjectedEnv };
|