@react-three/drei 9.78.0 → 9.78.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.
- package/core/Grid.cjs.js +1 -1
- package/core/Grid.js +4 -1
- package/index.cjs.js +1 -1
- package/package.json +1 -1
- package/react-three-drei-0.0.0-semantic-release.tgz +0 -0
package/core/Grid.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@babel/runtime/helpers/extends"),n=require("react"),o=require("three"),i=require("react-merge-refs"),r=require("@react-three/fiber"),t=require("./shaderMaterial.cjs.js");function l(e){var n=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var i=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(n,o,i.get?i:{enumerable:!0,get:function(){return e[o]}})}})),n.default=e,Object.freeze(n)}var a=l(n),s=l(o);const c=t.shaderMaterial({cellSize:.5,sectionSize:1,fadeDistance:100,fadeStrength:1,cellThickness:.5,sectionThickness:1,cellColor:new s.Color,sectionColor:new s.Color,infiniteGrid:!1,followCamera:!1,worldCamProjPosition:new s.Vector3,worldPlanePosition:new s.Vector3},"\n varying vec3 localPosition;\n varying vec4 worldPosition;\n\n uniform vec3 worldCamProjPosition;\n uniform vec3 worldPlanePosition;\n uniform float fadeDistance;\n uniform bool infiniteGrid;\n uniform bool followCamera;\n\n void main() {\n localPosition = position.xzy;\n if (infiniteGrid) localPosition *= 1.0 + fadeDistance;\n \n worldPosition = modelMatrix * vec4(localPosition, 1.0);\n if (followCamera) {\n worldPosition.xyz += (worldCamProjPosition - worldPlanePosition);\n localPosition = (inverse(modelMatrix) * worldPosition).xyz;\n }\n\n gl_Position = projectionMatrix * viewMatrix * worldPosition;\n }\n ","\n varying vec3 localPosition;\n varying vec4 worldPosition;\n\n uniform vec3 worldCamProjPosition;\n uniform float cellSize;\n uniform float sectionSize;\n uniform vec3 cellColor;\n uniform vec3 sectionColor;\n uniform float fadeDistance;\n uniform float fadeStrength;\n uniform float cellThickness;\n uniform float sectionThickness;\n\n float getGrid(float size, float thickness) {\n vec2 r = localPosition.xz / size;\n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y) + 1.0 - thickness;\n return 1.0 - min(line, 1.0);\n }\n\n void main() {\n float g1 = getGrid(cellSize, cellThickness);\n float g2 = getGrid(sectionSize, sectionThickness);\n\n float dist = distance(worldCamProjPosition, worldPosition.xyz);\n float d = 1.0 - min(dist / fadeDistance, 1.0);\n vec3 color = mix(cellColor, sectionColor, min(1.0, sectionThickness * g2));\n\n gl_FragColor = vec4(color, (g1 + g2) * pow(d, fadeStrength));\n gl_FragColor.a = mix(0.75 * gl_FragColor.a, gl_FragColor.a, g2);\n if (gl_FragColor.a <= 0.0) discard;\n\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }\n "),f=a.forwardRef((({args:n,cellColor:o="#000000",sectionColor:t="#2080ff",cellSize:l=.5,sectionSize:f=1,followCamera:d=!1,infiniteGrid:m=!1,fadeDistance:u=100,fadeStrength:g=1,cellThickness:P=.5,sectionThickness:w=1,side:v=s.BackSide,...C},h)=>{r.extend({GridMaterial:c});const x=a.useRef(null)
|
|
1
|
+
"use strict";var e=require("@babel/runtime/helpers/extends"),n=require("react"),o=require("three"),i=require("react-merge-refs"),r=require("@react-three/fiber"),t=require("./shaderMaterial.cjs.js");function l(e){var n=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var i=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(n,o,i.get?i:{enumerable:!0,get:function(){return e[o]}})}})),n.default=e,Object.freeze(n)}var a=l(n),s=l(o);const c=t.shaderMaterial({cellSize:.5,sectionSize:1,fadeDistance:100,fadeStrength:1,cellThickness:.5,sectionThickness:1,cellColor:new s.Color,sectionColor:new s.Color,infiniteGrid:!1,followCamera:!1,worldCamProjPosition:new s.Vector3,worldPlanePosition:new s.Vector3},"\n varying vec3 localPosition;\n varying vec4 worldPosition;\n\n uniform vec3 worldCamProjPosition;\n uniform vec3 worldPlanePosition;\n uniform float fadeDistance;\n uniform bool infiniteGrid;\n uniform bool followCamera;\n\n void main() {\n localPosition = position.xzy;\n if (infiniteGrid) localPosition *= 1.0 + fadeDistance;\n \n worldPosition = modelMatrix * vec4(localPosition, 1.0);\n if (followCamera) {\n worldPosition.xyz += (worldCamProjPosition - worldPlanePosition);\n localPosition = (inverse(modelMatrix) * worldPosition).xyz;\n }\n\n gl_Position = projectionMatrix * viewMatrix * worldPosition;\n }\n ","\n varying vec3 localPosition;\n varying vec4 worldPosition;\n\n uniform vec3 worldCamProjPosition;\n uniform float cellSize;\n uniform float sectionSize;\n uniform vec3 cellColor;\n uniform vec3 sectionColor;\n uniform float fadeDistance;\n uniform float fadeStrength;\n uniform float cellThickness;\n uniform float sectionThickness;\n\n float getGrid(float size, float thickness) {\n vec2 r = localPosition.xz / size;\n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y) + 1.0 - thickness;\n return 1.0 - min(line, 1.0);\n }\n\n void main() {\n float g1 = getGrid(cellSize, cellThickness);\n float g2 = getGrid(sectionSize, sectionThickness);\n\n float dist = distance(worldCamProjPosition, worldPosition.xyz);\n float d = 1.0 - min(dist / fadeDistance, 1.0);\n vec3 color = mix(cellColor, sectionColor, min(1.0, sectionThickness * g2));\n\n gl_FragColor = vec4(color, (g1 + g2) * pow(d, fadeStrength));\n gl_FragColor.a = mix(0.75 * gl_FragColor.a, gl_FragColor.a, g2);\n if (gl_FragColor.a <= 0.0) discard;\n\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }\n "),f=a.forwardRef((({args:n,cellColor:o="#000000",sectionColor:t="#2080ff",cellSize:l=.5,sectionSize:f=1,followCamera:d=!1,infiniteGrid:m=!1,fadeDistance:u=100,fadeStrength:g=1,cellThickness:P=.5,sectionThickness:w=1,side:v=s.BackSide,...C},h)=>{r.extend({GridMaterial:c});const x=a.useRef(null),p=new s.Plane,z=new s.Vector3(0,1,0),S=new s.Vector3(0,0,0);r.useFrame((e=>{p.setFromNormalAndCoplanarPoint(z,S).applyMatrix4(x.current.matrixWorld);const n=x.current.material,o=n.uniforms.worldCamProjPosition,i=n.uniforms.worldPlanePosition;p.projectPoint(e.camera.position,o.value),i.value.set(0,0,0).applyMatrix4(x.current.matrixWorld)}));const j={cellSize:l,sectionSize:f,cellColor:o,sectionColor:t,cellThickness:P,sectionThickness:w},k={fadeDistance:u,fadeStrength:g,infiniteGrid:m,followCamera:d};return a.createElement("mesh",e({ref:i([x,h]),frustumCulled:!1},C),a.createElement("gridMaterial",e({transparent:!0,"extensions-derivatives":!0,side:v},j,k)),a.createElement("planeGeometry",{args:n}))}));exports.Grid=f;
|
package/core/Grid.js
CHANGED
|
@@ -100,8 +100,11 @@ const Grid = /*#__PURE__*/React.forwardRef(({
|
|
|
100
100
|
GridMaterial
|
|
101
101
|
});
|
|
102
102
|
const ref = React.useRef(null);
|
|
103
|
+
const plane = new THREE.Plane();
|
|
104
|
+
const upVector = new THREE.Vector3(0, 1, 0);
|
|
105
|
+
const zeroVector = new THREE.Vector3(0, 0, 0);
|
|
103
106
|
useFrame(state => {
|
|
104
|
-
|
|
107
|
+
plane.setFromNormalAndCoplanarPoint(upVector, zeroVector).applyMatrix4(ref.current.matrixWorld);
|
|
105
108
|
const gridMaterial = ref.current.material;
|
|
106
109
|
const worldCamProjPosition = gridMaterial.uniforms.worldCamProjPosition;
|
|
107
110
|
const worldPlanePosition = gridMaterial.uniforms.worldPlanePosition;
|