@react-three/drei 9.56.24 → 9.56.26
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 +8 -8
- package/core/Billboard.cjs.js +1 -1
- package/core/Billboard.js +1 -1
- package/core/MeshRefractionMaterial.cjs.js +1 -1
- package/core/MeshRefractionMaterial.js +13 -5
- package/index.cjs.js +1 -1
- package/materials/MeshRefractionMaterial.cjs.js +1 -1
- package/materials/MeshRefractionMaterial.js +40 -34
- package/package.json +1 -1
- package/web/Html.cjs.js +1 -1
- package/web/Html.js +11 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("../core/shaderMaterial.cjs.js"),n=require("three-mesh-bvh");function i(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}})),r.default=e,Object.freeze(r)}var o=i(e);const t=r.shaderMaterial({envMap:null,bounces:3,ior:2.4,correctMips:!0,aberrationStrength:.01,fresnel:0,bvh:new n.MeshBVHUniformStruct,color:new o.Color("white"),resolution:new o.Vector2,viewMatrixInverse:new o.Matrix4,projectionMatrixInverse:new o.Matrix4},"\n uniform mat4 viewMatrixInverse;\n\n varying vec3 vWorldPosition; \n varying vec3 vNormal;\n varying mat4 vModelMatrixInverse;\n\n #ifdef USE_INSTANCING_COLOR\n varying vec3 vInstanceColor;\n #endif\n\n void main() { \n vec4 transformedNormal = vec4(normal, 0.0);\n vec4 transformedPosition = vec4(position, 1.0);\n #ifdef USE_INSTANCING\n transformedNormal = instanceMatrix * transformedNormal;\n transformedPosition = instanceMatrix * transformedPosition;\n #endif\n\n #ifdef USE_INSTANCING\n vModelMatrixInverse = inverse(modelMatrix * instanceMatrix);\n #else\n vModelMatrixInverse = inverse(modelMatrix);\n #endif\n\n #ifdef USE_INSTANCING_COLOR\n vInstanceColor = instanceColor.rgb;\n #endif\n\n vWorldPosition = (modelMatrix * transformedPosition).xyz;\n vNormal = normalize((viewMatrixInverse * vec4(normalMatrix * transformedNormal.xyz, 0.0)).xyz);\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * transformedPosition;\n }",`\n #define ENVMAP_TYPE_CUBE_UV\n precision highp isampler2D;\n precision highp usampler2D;\n varying vec3 vWorldPosition;\n varying vec3 vNormal;\n varying mat4 vModelMatrixInverse;\n\n #ifdef USE_INSTANCING_COLOR\n varying vec3 vInstanceColor;\n #endif\n \n #ifdef ENVMAP_TYPE_CUBEM\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n \n uniform float bounces;\n ${n.shaderStructs}\n ${n.shaderIntersectFunction}\n uniform BVH bvh;\n uniform float ior;\n uniform bool correctMips;\n uniform vec2 resolution;\n uniform float fresnel;\n uniform mat4 modelMatrix;\n uniform mat4 projectionMatrixInverse;\n uniform mat4 viewMatrixInverse;\n uniform float aberrationStrength;\n uniform vec3 color;\n \n float fresnelFunc(vec3 viewDirection, vec3 worldNormal) {\n return pow( 1.0 + dot( viewDirection, worldNormal), 10.0 );\n }\n \n vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 normal, float ior, mat4 modelMatrixInverse) {\n vec3 rayOrigin = ro;\n vec3 rayDirection = rd;\n rayDirection = refract(rayDirection, normal, 1.0 / ior);\n rayOrigin = vWorldPosition + rayDirection * 0.001;\n rayOrigin = (modelMatrixInverse * vec4(rayOrigin, 1.0)).xyz;\n rayDirection = normalize((modelMatrixInverse * vec4(rayDirection, 0.0)).xyz);\n for(float i = 0.0; i < bounces; i++) {\n uvec4 faceIndices = uvec4( 0u );\n vec3 faceNormal = vec3( 0.0, 0.0, 1.0 );\n vec3 barycoord = vec3( 0.0 );\n float side = 1.0;\n float dist = 0.0;\n bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist );\n vec3 hitPos = rayOrigin + rayDirection * max(dist - 0.001, 0.0); \n vec3 tempDir = refract(rayDirection, faceNormal, ior);\n if (length(tempDir) != 0.0) {\n rayDirection = tempDir;\n break;\n }\n rayDirection = reflect(rayDirection, faceNormal);\n rayOrigin = hitPos + rayDirection * 0.01;\n }\n rayDirection = normalize((modelMatrix * vec4(rayDirection, 0.0)).xyz);\n return rayDirection;\n }\n \n #include <common>\n #include <cube_uv_reflection_fragment>\n \n #ifdef ENVMAP_TYPE_CUBEM\n vec4 textureGradient(samplerCube envMap, vec3 rayDirection, vec3 directionCamPerfect) {\n return textureGrad(envMap, rayDirection, dFdx(correctMips ? directionCamPerfect: rayDirection), dFdy(correctMips ? directionCamPerfect: rayDirection));\n }\n #else\n vec4 textureGradient(sampler2D envMap, vec3 rayDirection, vec3 directionCamPerfect) {\n vec2 uvv = equirectUv( rayDirection );\n vec2 smoothUv = equirectUv( directionCamPerfect );\n return textureGrad(envMap, uvv, dFdx(correctMips ? smoothUv : uvv), dFdy(correctMips ? smoothUv : uvv));\n }\n #endif\n \n void main() {\n vec2 uv = gl_FragCoord.xy / resolution;\n vec3 directionCamPerfect = (projectionMatrixInverse * vec4(uv * 2.0 - 1.0, 0.0, 1.0)).xyz;\n directionCamPerfect = (viewMatrixInverse * vec4(directionCamPerfect, 0.0)).xyz;\n directionCamPerfect = normalize(directionCamPerfect);\n vec3 normal = vNormal;\n vec3 rayOrigin = cameraPosition;\n vec3 rayDirection = normalize(vWorldPosition - cameraPosition);\n vec3 finalColor;\n #ifdef CHROMATIC_ABERRATIONS\n vec3 rayDirectionG = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);\n #ifdef FAST_CHROMA \n vec3 rayDirectionR = normalize(rayDirectionG + 1.0 * vec3(aberrationStrength / 2.0));\n vec3 rayDirectionB = normalize(rayDirectionG - 1.0 * vec3(aberrationStrength / 2.0));\n #else\n vec3 rayDirectionR = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 - aberrationStrength), 1.0), vModelMatrixInverse);\n vec3 rayDirectionB = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 + aberrationStrength), 1.0), vModelMatrixInverse);\n #endif\n float finalColorR = textureGradient(envMap, rayDirectionR, directionCamPerfect).r;\n float finalColorG = textureGradient(envMap, rayDirectionG, directionCamPerfect).g;\n float finalColorB = textureGradient(envMap, rayDirectionB, directionCamPerfect).b;\n finalColor = vec3(finalColorR, finalColorG, finalColorB);\n #else\n rayDirection = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);\n finalColor = textureGradient(envMap, rayDirection, directionCamPerfect).rgb; \n #endif\n\n finalColor *= color;\n #ifdef USE_INSTANCING_COLOR\n finalColor *= vInstanceColor;\n #endif\n\n vec3 viewDirection = normalize(vWorldPosition - cameraPosition);\n float nFresnel = fresnelFunc(viewDirection, normal) * fresnel;\n gl_FragColor = vec4(mix(finalColor, vec3(1.0), nFresnel), 1.0); \n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }`);exports.MeshRefractionMaterial=t;
|
|
@@ -12,43 +12,42 @@ const MeshRefractionMaterial = shaderMaterial({
|
|
|
12
12
|
fresnel: 0,
|
|
13
13
|
bvh: new MeshBVHUniformStruct(),
|
|
14
14
|
color: new THREE.Color('white'),
|
|
15
|
-
resolution: new THREE.Vector2()
|
|
15
|
+
resolution: new THREE.Vector2(),
|
|
16
|
+
viewMatrixInverse: new THREE.Matrix4(),
|
|
17
|
+
projectionMatrixInverse: new THREE.Matrix4()
|
|
16
18
|
},
|
|
17
19
|
/*glsl*/
|
|
18
20
|
`
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
#endif
|
|
21
|
+
uniform mat4 viewMatrixInverse;
|
|
22
|
+
|
|
22
23
|
varying vec3 vWorldPosition;
|
|
23
24
|
varying vec3 vNormal;
|
|
24
|
-
varying mat4
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
varying mat4 vModelMatrixInverse;
|
|
26
|
+
|
|
27
|
+
#ifdef USE_INSTANCING_COLOR
|
|
28
|
+
varying vec3 vInstanceColor;
|
|
29
|
+
#endif
|
|
30
|
+
|
|
30
31
|
void main() {
|
|
31
32
|
vec4 transformedNormal = vec4(normal, 0.0);
|
|
32
33
|
vec4 transformedPosition = vec4(position, 1.0);
|
|
33
34
|
#ifdef USE_INSTANCING
|
|
34
|
-
vInstanceMatrix = instanceMatrix;
|
|
35
35
|
transformedNormal = instanceMatrix * transformedNormal;
|
|
36
36
|
transformedPosition = instanceMatrix * transformedPosition;
|
|
37
|
+
#endif
|
|
38
|
+
|
|
39
|
+
#ifdef USE_INSTANCING
|
|
40
|
+
vModelMatrixInverse = inverse(modelMatrix * instanceMatrix);
|
|
37
41
|
#else
|
|
38
|
-
|
|
42
|
+
vModelMatrixInverse = inverse(modelMatrix);
|
|
39
43
|
#endif
|
|
40
44
|
|
|
41
|
-
vColor = color;
|
|
42
45
|
#ifdef USE_INSTANCING_COLOR
|
|
43
|
-
|
|
46
|
+
vInstanceColor = instanceColor.rgb;
|
|
44
47
|
#endif
|
|
45
|
-
|
|
46
|
-
projectionMatrixInv = inverse(projectionMatrix);
|
|
47
|
-
viewMatrixInv = inverse(viewMatrix);
|
|
48
48
|
|
|
49
49
|
vWorldPosition = (modelMatrix * transformedPosition).xyz;
|
|
50
|
-
vNormal = normalize((
|
|
51
|
-
viewDirection = normalize(vWorldPosition - cameraPosition);
|
|
50
|
+
vNormal = normalize((viewMatrixInverse * vec4(normalMatrix * transformedNormal.xyz, 0.0)).xyz);
|
|
52
51
|
gl_Position = projectionMatrix * viewMatrix * modelMatrix * transformedPosition;
|
|
53
52
|
}`,
|
|
54
53
|
/*glsl*/
|
|
@@ -58,6 +57,11 @@ const MeshRefractionMaterial = shaderMaterial({
|
|
|
58
57
|
precision highp usampler2D;
|
|
59
58
|
varying vec3 vWorldPosition;
|
|
60
59
|
varying vec3 vNormal;
|
|
60
|
+
varying mat4 vModelMatrixInverse;
|
|
61
|
+
|
|
62
|
+
#ifdef USE_INSTANCING_COLOR
|
|
63
|
+
varying vec3 vInstanceColor;
|
|
64
|
+
#endif
|
|
61
65
|
|
|
62
66
|
#ifdef ENVMAP_TYPE_CUBEM
|
|
63
67
|
uniform samplerCube envMap;
|
|
@@ -74,13 +78,10 @@ const MeshRefractionMaterial = shaderMaterial({
|
|
|
74
78
|
uniform vec2 resolution;
|
|
75
79
|
uniform float fresnel;
|
|
76
80
|
uniform mat4 modelMatrix;
|
|
77
|
-
|
|
81
|
+
uniform mat4 projectionMatrixInverse;
|
|
82
|
+
uniform mat4 viewMatrixInverse;
|
|
78
83
|
uniform float aberrationStrength;
|
|
79
|
-
|
|
80
|
-
varying mat4 viewMatrixInv;
|
|
81
|
-
varying vec3 viewDirection;
|
|
82
|
-
varying mat4 vInstanceMatrix;
|
|
83
|
-
varying vec3 vColor;
|
|
84
|
+
uniform vec3 color;
|
|
84
85
|
|
|
85
86
|
float fresnelFunc(vec3 viewDirection, vec3 worldNormal) {
|
|
86
87
|
return pow( 1.0 + dot( viewDirection, worldNormal), 10.0 );
|
|
@@ -129,33 +130,38 @@ const MeshRefractionMaterial = shaderMaterial({
|
|
|
129
130
|
#endif
|
|
130
131
|
|
|
131
132
|
void main() {
|
|
132
|
-
mat4 modelMatrixInverse = inverse(modelMatrix * vInstanceMatrix);
|
|
133
133
|
vec2 uv = gl_FragCoord.xy / resolution;
|
|
134
|
-
vec3 directionCamPerfect = (
|
|
135
|
-
directionCamPerfect = (
|
|
134
|
+
vec3 directionCamPerfect = (projectionMatrixInverse * vec4(uv * 2.0 - 1.0, 0.0, 1.0)).xyz;
|
|
135
|
+
directionCamPerfect = (viewMatrixInverse * vec4(directionCamPerfect, 0.0)).xyz;
|
|
136
136
|
directionCamPerfect = normalize(directionCamPerfect);
|
|
137
137
|
vec3 normal = vNormal;
|
|
138
138
|
vec3 rayOrigin = cameraPosition;
|
|
139
139
|
vec3 rayDirection = normalize(vWorldPosition - cameraPosition);
|
|
140
140
|
vec3 finalColor;
|
|
141
141
|
#ifdef CHROMATIC_ABERRATIONS
|
|
142
|
-
vec3 rayDirectionG = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0),
|
|
142
|
+
vec3 rayDirectionG = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);
|
|
143
143
|
#ifdef FAST_CHROMA
|
|
144
144
|
vec3 rayDirectionR = normalize(rayDirectionG + 1.0 * vec3(aberrationStrength / 2.0));
|
|
145
145
|
vec3 rayDirectionB = normalize(rayDirectionG - 1.0 * vec3(aberrationStrength / 2.0));
|
|
146
146
|
#else
|
|
147
|
-
vec3 rayDirectionR = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 - aberrationStrength), 1.0),
|
|
148
|
-
vec3 rayDirectionB = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 + aberrationStrength), 1.0),
|
|
147
|
+
vec3 rayDirectionR = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 - aberrationStrength), 1.0), vModelMatrixInverse);
|
|
148
|
+
vec3 rayDirectionB = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 + aberrationStrength), 1.0), vModelMatrixInverse);
|
|
149
149
|
#endif
|
|
150
150
|
float finalColorR = textureGradient(envMap, rayDirectionR, directionCamPerfect).r;
|
|
151
151
|
float finalColorG = textureGradient(envMap, rayDirectionG, directionCamPerfect).g;
|
|
152
152
|
float finalColorB = textureGradient(envMap, rayDirectionB, directionCamPerfect).b;
|
|
153
|
-
finalColor = vec3(finalColorR, finalColorG, finalColorB)
|
|
153
|
+
finalColor = vec3(finalColorR, finalColorG, finalColorB);
|
|
154
154
|
#else
|
|
155
|
-
rayDirection = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0),
|
|
155
|
+
rayDirection = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);
|
|
156
156
|
finalColor = textureGradient(envMap, rayDirection, directionCamPerfect).rgb;
|
|
157
|
-
finalColor *= vColor;
|
|
158
157
|
#endif
|
|
158
|
+
|
|
159
|
+
finalColor *= color;
|
|
160
|
+
#ifdef USE_INSTANCING_COLOR
|
|
161
|
+
finalColor *= vInstanceColor;
|
|
162
|
+
#endif
|
|
163
|
+
|
|
164
|
+
vec3 viewDirection = normalize(vWorldPosition - cameraPosition);
|
|
159
165
|
float nFresnel = fresnelFunc(viewDirection, normal) * fresnel;
|
|
160
166
|
gl_FragColor = vec4(mix(finalColor, vec3(1.0), nFresnel), 1.0);
|
|
161
167
|
#include <tonemapping_fragment>
|
package/package.json
CHANGED
package/web/Html.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("react-dom/client"),n=require("three"),o=require("@react-three/fiber");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("react-dom/client"),n=require("three"),o=require("@react-three/fiber");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a=i(e),c=s(t),l=s(r);const u=new n.Vector3,d=new n.Vector3,m=new n.Vector3;function f(e,t,r){const n=u.setFromMatrixPosition(e.matrixWorld);n.project(t);const o=r.width/2,i=r.height/2;return[n.x*o+o,-n.y*i+i]}const h=e=>Math.abs(e)<1e-10?0:e;function p(e,t,r=""){let n="matrix3d(";for(let r=0;16!==r;r++)n+=h(t[r]*e.elements[r])+(15!==r?",":")");return r+n}const x=(v=[1,-1,1,1,1,-1,1,1,1,-1,1,1,1,-1,1,1],e=>p(e,v));var v;const y=(e,t)=>{return p(e,[1/(r=t),1/r,1/r,1,-1/r,-1/r,-1/r,-1,1/r,1/r,1/r,1,1,1,1,1],"translate(-50%,-50%)");var r};const g=c.forwardRef((({children:e,eps:t=.001,style:r,className:i,prepend:s,center:p,fullscreen:v,portal:g,distanceFactor:M,sprite:b=!1,transform:P=!1,occlude:w,onOcclude:E,castShadow:W,receiveShadow:S,material:$,geometry:j,zIndexRange:z=[16777271,0],calculatePosition:O=f,as:R="div",wrapperClass:F,pointerEvents:C="auto",...T},I)=>{const{gl:A,camera:k,scene:H,size:N,raycaster:_,events:q,viewport:V}=o.useThree(),[L]=c.useState((()=>document.createElement(R))),D=c.useRef(),G=c.useRef(null),Z=c.useRef(0),B=c.useRef([0,0]),J=c.useRef(null),K=c.useRef(null),Q=(null==g?void 0:g.current)||q.connected||A.domElement.parentNode,U=c.useRef(null),X=c.useRef(!1),Y=c.useMemo((()=>w&&"blending"!==w||Array.isArray(w)&&w.length&&function(e){return e&&"object"==typeof e&&"current"in e}(w[0])),[w]);c.useLayoutEffect((()=>{const e=A.domElement;w&&"blending"===w?(e.style.zIndex=`${Math.floor(z[0]/2)}`,e.style.position="absolute",e.style.pointerEvents="none"):(e.style.zIndex=null,e.style.position=null,e.style.pointerEvents=null)}),[w]),c.useLayoutEffect((()=>{if(G.current){const e=D.current=l.createRoot(L);if(H.updateMatrixWorld(),P)L.style.cssText="position:absolute;top:0;left:0;pointer-events:none;overflow:hidden;";else{const e=O(G.current,k,N);L.style.cssText=`position:absolute;top:0;left:0;transform:translate3d(${e[0]}px,${e[1]}px,0);transform-origin:0 0;`}return Q&&(s?Q.prepend(L):Q.appendChild(L)),()=>{Q&&Q.removeChild(L),e.unmount()}}}),[Q,P]),c.useLayoutEffect((()=>{F&&(L.className=F)}),[F]);const ee=c.useMemo((()=>P?{position:"absolute",top:0,left:0,width:N.width,height:N.height,transformStyle:"preserve-3d",pointerEvents:"none"}:{position:"absolute",transform:p?"translate3d(-50%,-50%,0)":"none",...v&&{top:-N.height/2,left:-N.width/2,width:N.width,height:N.height},...r}),[r,p,v,N,P]),te=c.useMemo((()=>({position:"absolute",pointerEvents:C})),[C]);c.useLayoutEffect((()=>{var t,n;(X.current=!1,P)?null==(t=D.current)||t.render(c.createElement("div",{ref:J,style:ee},c.createElement("div",{ref:K,style:te},c.createElement("div",{ref:I,className:i,style:r,children:e})))):null==(n=D.current)||n.render(c.createElement("div",{ref:I,style:ee,className:i,children:e}))}));const re=c.useRef(!0);o.useFrame((e=>{if(G.current){k.updateMatrixWorld(),G.current.updateWorldMatrix(!0,!1);const e=P?B.current:O(G.current,k,N);if(P||Math.abs(Z.current-k.zoom)>t||Math.abs(B.current[0]-e[0])>t||Math.abs(B.current[1]-e[1])>t){const t=function(e,t){const r=u.setFromMatrixPosition(e.matrixWorld),n=d.setFromMatrixPosition(t.matrixWorld),o=r.sub(n),i=t.getWorldDirection(m);return o.angleTo(i)>Math.PI/2}(G.current,k);let r=!1;Y&&("blending"!==w?r=[H]:Array.isArray(w)&&(r=w.map((e=>e.current))));const o=re.current;if(r){const e=function(e,t,r,n){const o=u.setFromMatrixPosition(e.matrixWorld),i=o.clone();i.project(t),r.setFromCamera(i,t);const s=r.intersectObjects(n,!0);if(s.length){const e=s[0].distance;return o.distanceTo(r.ray.origin)<e}return!0}(G.current,k,_,r);re.current=e&&!t}else re.current=!t;o!==re.current&&(E?E(!re.current):L.style.display=re.current?"block":"none");const i=Math.floor(z[0]/2),s=w?Y?[z[0],i]:[i-1,0]:z;if(L.style.zIndex=`${function(e,t,r){if(t instanceof n.PerspectiveCamera||t instanceof n.OrthographicCamera){const n=u.setFromMatrixPosition(e.matrixWorld),o=d.setFromMatrixPosition(t.matrixWorld),i=n.distanceTo(o),s=(r[1]-r[0])/(t.far-t.near),a=r[1]-s*t.far;return Math.round(s*i+a)}}(G.current,k,s)}`,P){const[e,t]=[N.width/2,N.height/2],r=k.projectionMatrix.elements[5]*t,{isOrthographicCamera:n,top:o,left:i,bottom:s,right:a}=k,c=x(k.matrixWorldInverse),l=n?`scale(${r})translate(${h(-(a+i)/2)}px,${h((o+s)/2)}px)`:`translateZ(${r}px)`;let u=G.current.matrixWorld;b&&(u=k.matrixWorldInverse.clone().transpose().copyPosition(u).scale(G.current.scale),u.elements[3]=u.elements[7]=u.elements[11]=0,u.elements[15]=1),L.style.width=N.width+"px",L.style.height=N.height+"px",L.style.perspective=n?"":`${r}px`,J.current&&K.current&&(J.current.style.transform=`${l}${c}translate(${e}px,${t}px)`,K.current.style.transform=y(u,1/((M||10)/400)))}else{const t=void 0===M?1:function(e,t){if(t instanceof n.OrthographicCamera)return t.zoom;if(t instanceof n.PerspectiveCamera){const r=u.setFromMatrixPosition(e.matrixWorld),n=d.setFromMatrixPosition(t.matrixWorld),o=t.fov*Math.PI/180,i=r.distanceTo(n);return 1/(2*Math.tan(o/2)*i)}return 1}(G.current,k)*M;L.style.transform=`translate3d(${e[0]}px,${e[1]}px,0) scale(${t})`}B.current=e,Z.current=k.zoom}}if(!Y&&U.current&&!X.current)if(P){if(J.current){const e=J.current.children[0];if(null!=e&&e.clientWidth&&null!=e&&e.clientHeight){const{isOrthographicCamera:t}=k;if(t||j)T.scale&&(Array.isArray(T.scale)?T.scale instanceof n.Vector3?U.current.scale.copy(T.scale.clone().divideScalar(1)):U.current.scale.set(1/T.scale[0],1/T.scale[1],1/T.scale[2]):U.current.scale.setScalar(1/T.scale));else{const t=(M||10)/400,r=e.clientWidth*t,n=e.clientHeight*t;U.current.scale.set(r,n,1)}X.current=!0}}}else{const t=L.children[0];if(null!=t&&t.clientWidth&&null!=t&&t.clientHeight){const e=1/V.factor,r=t.clientWidth*e,n=t.clientHeight*e;U.current.scale.set(r,n,1),X.current=!0}U.current.lookAt(e.camera.position)}}));const ne=c.useMemo((()=>({vertexShader:P?void 0:'\n /*\n This shader is from the THREE\'s SpriteMaterial.\n We need to turn the backing plane into a Sprite\n (make it always face the camera) if "transfrom" \n is false. \n */\n #include <common>\n\n void main() {\n vec2 center = vec2(0., 1.);\n float rotation = 0.0;\n \n // This is somewhat arbitrary, but it seems to work well\n // Need to figure out how to derive this dynamically if it even matters\n float size = 0.03;\n\n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n bool isPerspective = isPerspectiveMatrix( projectionMatrix );\n if ( isPerspective ) scale *= - mvPosition.z;\n\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale * size;\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n mvPosition.xy += rotatedPosition;\n\n gl_Position = projectionMatrix * mvPosition;\n }\n ',fragmentShader:"\n void main() {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n }\n "})),[P]);return c.createElement("group",a.default({},T,{ref:G}),w&&!Y&&c.createElement("mesh",{castShadow:W,receiveShadow:S,ref:U},j||c.createElement("planeGeometry",null),$||c.createElement("shaderMaterial",{side:n.DoubleSide,vertexShader:ne.vertexShader,fragmentShader:ne.fragmentShader})))}));exports.Html=g;
|
package/web/Html.js
CHANGED
|
@@ -142,10 +142,17 @@ const Html = /*#__PURE__*/React.forwardRef(({
|
|
|
142
142
|
}, [occlude]);
|
|
143
143
|
React.useLayoutEffect(() => {
|
|
144
144
|
const el = gl.domElement;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
|
|
146
|
+
if (occlude && occlude === 'blending') {
|
|
147
|
+
el.style.zIndex = `${Math.floor(zIndexRange[0] / 2)}`;
|
|
148
|
+
el.style.position = 'absolute';
|
|
149
|
+
el.style.pointerEvents = 'none';
|
|
150
|
+
} else {
|
|
151
|
+
el.style.zIndex = null;
|
|
152
|
+
el.style.position = null;
|
|
153
|
+
el.style.pointerEvents = null;
|
|
154
|
+
}
|
|
155
|
+
}, [occlude]);
|
|
149
156
|
React.useLayoutEffect(() => {
|
|
150
157
|
if (group.current) {
|
|
151
158
|
const currentRoot = root.current = ReactDOM.createRoot(el);
|