@react-three/drei 7.23.1 → 7.23.2
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/Bounds.cjs.js +1 -1
- package/core/Bounds.js +7 -4
- package/index.cjs.js +1 -1
- package/package.json +1 -1
package/core/Bounds.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("three"),r=require("@react-three/fiber");function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a=o(e),n=o(t);const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("three"),r=require("@react-three/fiber");function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a=o(e),n=o(t);const c=e=>e&&e.isOrthographicCamera,i=a.createContext(null);exports.Bounds=function({children:e,damping:t=6,fit:o,clip:s,margin:m=1.2,eps:u=.01,onFit:f}){const x=a.useRef(null),p=r.useThree((e=>e.camera)),l=r.useThree((e=>e.controls)),z=r.useThree((e=>e.invalidate)),h=a.useRef(f);function y(e,t){return Math.abs(e.x-t.x)<u&&Math.abs(e.y-t.y)<u&&Math.abs(e.z-t.z)<u}function d(e,t,r,o){e.x=n.MathUtils.damp(e.x,t.x,r,o),e.y=n.MathUtils.damp(e.y,t.y,r,o),e.z=n.MathUtils.damp(e.z,t.z,r,o)}h.current=f;const[M]=a.useState((()=>({animating:!1,focus:new n.Vector3,camera:new n.Vector3,zoom:1}))),[b]=a.useState((()=>({focus:new n.Vector3,camera:new n.Vector3,zoom:1}))),[g]=a.useState((()=>new n.Box3)),w=a.useMemo((()=>{function e(){const e=g.getSize(new n.Vector3),t=g.getCenter(new n.Vector3),r=Math.max(e.x,e.y,e.z),o=c(p)?4*r:r/(2*Math.atan(Math.PI*p.fov/360)),a=c(p)?4*r:o/p.aspect,i=m*Math.max(o,a);return{box:g,size:e,center:t,distance:i}}return{getSize:e,refresh(e){var t;if((t=e)&&t.isObject3D?g.setFromObject(e):(e=>e&&e.isBox3)(e)?g.copy(e):g.setFromObject(x.current),g.isEmpty()){const e=p.position.length()||10;g.setFromCenterAndSize(new n.Vector3,new n.Vector3(e,e,e))}return this},clip(){const{distance:t}=e();return l&&(l.maxDistance=10*t),p.near=t/100,p.far=100*t,p.updateProjectionMatrix(),l&&l.update(),this},fit(){M.camera.copy(p.position),l&&M.focus.copy(l.target);const{center:r,distance:o}=e(),a=r.clone().sub(p.position).normalize().multiplyScalar(o);if(b.camera.copy(r).sub(a),b.focus.copy(r),c(p)){M.zoom=p.zoom;let e=0,o=0;const a=[new n.Vector3(g.min.x,g.min.y,g.min.z),new n.Vector3(g.min.x,g.max.y,g.min.z),new n.Vector3(g.min.x,g.min.y,g.max.z),new n.Vector3(g.min.x,g.max.y,g.max.z),new n.Vector3(g.max.x,g.max.y,g.max.z),new n.Vector3(g.max.x,g.max.y,g.min.z),new n.Vector3(g.max.x,g.min.y,g.max.z),new n.Vector3(g.max.x,g.min.y,g.min.z)];r.applyMatrix4(p.matrixWorldInverse);for(const t of a)t.applyMatrix4(p.matrixWorldInverse),e=Math.max(e,Math.abs(t.y-r.y)),o=Math.max(o,Math.abs(t.x-r.x));e*=2,o*=2;const c=(p.top-p.bottom)/e,i=(p.right-p.left)/o;b.zoom=Math.min(c,i)/m,t||(p.zoom=b.zoom,p.updateProjectionMatrix())}return t?M.animating=!0:(p.position.copy(b.camera),p.lookAt(b.focus),l&&(l.target.copy(b.focus),l.update()),z()),h.current&&h.current(this.getSize()),this}}}),[g,p,l,m,t,z]);return a.useLayoutEffect((()=>{if(w.refresh(),o&&w.fit(),s&&w.clip(),l){const e=e=>M.animating=!1;return l.addEventListener("start",e),()=>l.removeEventListener("start",e)}}),[s,o,l]),r.useFrame(((e,r)=>{if(M.animating){if(d(M.focus,b.focus,t,r),d(M.camera,b.camera,t,r),M.zoom=n.MathUtils.damp(M.zoom,b.zoom,t,r),p.position.copy(M.camera),c(p)&&(p.zoom=M.zoom,p.updateProjectionMatrix()),l?(l.target.copy(M.focus),l.update()):p.lookAt(M.focus),z(),c(p)&&!(Math.abs(M.zoom-b.zoom)<u))return;if(!c(p)&&!y(M.camera,b.camera))return;if(l&&!y(M.focus,b.focus))return;M.animating=!1}})),a.createElement("group",{ref:x},a.createElement(i.Provider,{value:w},e))},exports.useBounds=function(){return a.useContext(i)};
|
package/core/Bounds.js
CHANGED
|
@@ -23,6 +23,8 @@ function Bounds({
|
|
|
23
23
|
|
|
24
24
|
const controls = useThree(state => state.controls);
|
|
25
25
|
const invalidate = useThree(state => state.invalidate);
|
|
26
|
+
const onFitRef = React.useRef(onFit);
|
|
27
|
+
onFitRef.current = onFit;
|
|
26
28
|
|
|
27
29
|
function equals(a, b) {
|
|
28
30
|
return Math.abs(a.x - b.x) < eps && Math.abs(a.y - b.y) < eps && Math.abs(a.z - b.z) < eps;
|
|
@@ -139,12 +141,12 @@ function Bounds({
|
|
|
139
141
|
invalidate();
|
|
140
142
|
}
|
|
141
143
|
|
|
142
|
-
if (
|
|
144
|
+
if (onFitRef.current) onFitRef.current(this.getSize());
|
|
143
145
|
return this;
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
};
|
|
147
|
-
}, [box, camera, controls, margin, damping, invalidate
|
|
149
|
+
}, [box, camera, controls, margin, damping, invalidate]);
|
|
148
150
|
React.useLayoutEffect(() => {
|
|
149
151
|
api.refresh();
|
|
150
152
|
if (fit) api.fit();
|
|
@@ -156,8 +158,9 @@ function Bounds({
|
|
|
156
158
|
|
|
157
159
|
controls.addEventListener('start', callback);
|
|
158
160
|
return () => controls.removeEventListener('start', callback);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
162
|
+
|
|
163
|
+
}, [clip, fit, controls]);
|
|
161
164
|
useFrame((state, delta) => {
|
|
162
165
|
if (current.animating) {
|
|
163
166
|
damp(current.focus, goal.focus, damping, delta);
|