@react-three/drei 9.107.2 → 9.108.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/drei",
3
- "version": "9.107.2",
3
+ "version": "9.108.0",
4
4
  "private": false,
5
5
  "description": "useful add-ons for react-three-fiber",
6
6
  "keywords": [
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("@react-three/fiber"),t=require("react"),i=require("three"),a=require("./AxisArrow.cjs.js"),n=require("./AxisRotator.cjs.js"),o=require("./PlaneSlider.cjs.js"),c=require("./ScalingSphere.cjs.js"),s=require("./context.cjs.js"),l=require("../../core/calculateScaleFactor.cjs.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function d(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("../../core/Line.cjs.js"),require("three-stdlib"),require("../Html.cjs.js"),require("react-dom/client");var x=u(e),m=d(t),p=d(i);const f=new p.Matrix4,y=new p.Matrix4,w=new p.Matrix4,g=new p.Matrix4,b=new p.Matrix4,j=new p.Matrix4,E=new p.Matrix4,S=new p.Matrix4,h=new p.Matrix4,v=new p.Box3,M=new p.Box3,A=new p.Vector3,q=new p.Vector3,R=new p.Vector3,V=new p.Vector3,P=new p.Vector3,W=new p.Vector3(1,0,0),D=new p.Vector3(0,1,0),C=new p.Vector3(0,0,1),L=m.forwardRef((({matrix:e,onDragStart:t,onDrag:i,onDragEnd:u,autoTransform:d=!0,anchor:L,disableAxes:O=!1,disableSliders:B=!1,disableRotations:F=!1,disableScaling:z=!1,activeAxes:T=[!0,!0,!0],offset:_=[0,0,0],rotation:k=[0,0,0],scale:H=1,lineWidth:I=4,fixed:U=!1,translationLimits:G,rotationLimits:J,scaleLimits:K,depthTest:N=!0,axisColors:Q=["#ff2060","#20df80","#2080ff"],hoveredColor:X="#ffff40",annotations:Y=!1,annotationsClass:Z,opacity:$=1,visible:ee=!0,userData:re,children:te,...ie},ae)=>{const ne=r.useThree((e=>e.invalidate)),oe=m.useRef(null),ce=m.useRef(null),se=m.useRef(null),le=m.useRef(null),ue=m.useRef([0,0,0]),de=m.useRef(new p.Vector3(1,1,1)),xe=m.useRef(new p.Vector3(1,1,1));m.useLayoutEffect((()=>{L&&(le.current.updateWorldMatrix(!0,!0),g.copy(le.current.matrixWorld).invert(),v.makeEmpty(),le.current.traverse((e=>{e.geometry&&(e.geometry.boundingBox||e.geometry.computeBoundingBox(),j.copy(e.matrixWorld).premultiply(g),M.copy(e.geometry.boundingBox),M.applyMatrix4(j),v.union(M))})),A.copy(v.max).add(v.min).multiplyScalar(.5),q.copy(v.max).sub(v.min).multiplyScalar(.5),R.copy(q).multiply(new p.Vector3(...L)).add(A),V.set(..._).add(R),se.current.position.copy(V),ne())}));const me=m.useMemo((()=>({onDragStart:e=>{f.copy(ce.current.matrix),y.copy(ce.current.matrixWorld),t&&t(e),ne()},onDrag:e=>{w.copy(oe.current.matrixWorld),g.copy(w).invert(),b.copy(y).premultiply(e),j.copy(b).premultiply(g),E.copy(f).invert(),S.copy(j).multiply(E),d&&ce.current.matrix.copy(j),i&&i(j,S,b,e),ne()},onDragEnd:()=>{u&&u(),ne()},translation:ue,translationLimits:G,rotationLimits:J,axisColors:Q,hoveredColor:X,opacity:$,scale:H,lineWidth:I,fixed:U,depthTest:N,userData:re,annotations:Y,annotationsClass:Z})),[t,i,u,ue,G,J,K,N,H,I,U,...Q,X,$,re,d,Y,Z]),pe=new p.Vector3;return r.useFrame((r=>{if(U){const e=l.calculateScaleFactor(se.current.getWorldPosition(pe),H,r.camera,r.size);de.current.setScalar(e)}e&&e instanceof p.Matrix4&&(ce.current.matrix=e),ce.current.updateWorldMatrix(!0,!0),h.makeRotationFromEuler(se.current.rotation).setPosition(se.current.position).premultiply(ce.current.matrixWorld),xe.current.setFromMatrixScale(h),P.copy(de.current).divide(xe.current),(Math.abs(se.current.scale.x-P.x)>1e-4||Math.abs(se.current.scale.y-P.y)>1e-4||Math.abs(se.current.scale.z-P.z)>1e-4)&&(se.current.scale.copy(P),r.invalidate())})),m.useImperativeHandle(ae,(()=>ce.current),[]),m.createElement(s.context.Provider,{value:me},m.createElement("group",{ref:oe},m.createElement("group",x.default({ref:ce,matrix:e,matrixAutoUpdate:!1},ie),m.createElement("group",{visible:ee,ref:se,position:_,rotation:k},!O&&T[0]&&m.createElement(a.AxisArrow,{axis:0,direction:W}),!O&&T[1]&&m.createElement(a.AxisArrow,{axis:1,direction:D}),!O&&T[2]&&m.createElement(a.AxisArrow,{axis:2,direction:C}),!B&&T[0]&&T[1]&&m.createElement(o.PlaneSlider,{axis:2,dir1:W,dir2:D}),!B&&T[0]&&T[2]&&m.createElement(o.PlaneSlider,{axis:1,dir1:C,dir2:W}),!B&&T[2]&&T[1]&&m.createElement(o.PlaneSlider,{axis:0,dir1:D,dir2:C}),!F&&T[0]&&T[1]&&m.createElement(n.AxisRotator,{axis:2,dir1:W,dir2:D}),!F&&T[0]&&T[2]&&m.createElement(n.AxisRotator,{axis:1,dir1:C,dir2:W}),!F&&T[2]&&T[1]&&m.createElement(n.AxisRotator,{axis:0,dir1:D,dir2:C}),!z&&T[0]&&m.createElement(c.ScalingSphere,{axis:0,direction:W}),!z&&T[1]&&m.createElement(c.ScalingSphere,{axis:1,direction:D}),!z&&T[2]&&m.createElement(c.ScalingSphere,{axis:2,direction:C})),m.createElement("group",{ref:le},te))))}));exports.PivotControls=L;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("@react-three/fiber"),t=require("react"),i=require("three"),a=require("./AxisArrow.cjs.js"),n=require("./AxisRotator.cjs.js"),o=require("./PlaneSlider.cjs.js"),c=require("./ScalingSphere.cjs.js"),s=require("./context.cjs.js"),l=require("../../core/calculateScaleFactor.cjs.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function d(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("../../core/Line.cjs.js"),require("three-stdlib"),require("../Html.cjs.js"),require("react-dom/client");var x=u(e),m=d(t),p=d(i);const f=new p.Matrix4,y=new p.Matrix4,w=new p.Matrix4,g=new p.Matrix4,b=new p.Matrix4,j=new p.Matrix4,E=new p.Matrix4,S=new p.Matrix4,h=new p.Matrix4,v=new p.Box3,M=new p.Box3,A=new p.Vector3,q=new p.Vector3,R=new p.Vector3,V=new p.Vector3,P=new p.Vector3,W=new p.Vector3(1,0,0),D=new p.Vector3(0,1,0),C=new p.Vector3(0,0,1),L=m.forwardRef((({enabled:e=!0,matrix:t,onDragStart:i,onDrag:u,onDragEnd:d,autoTransform:L=!0,anchor:O,disableAxes:B=!1,disableSliders:F=!1,disableRotations:z=!1,disableScaling:T=!1,activeAxes:_=[!0,!0,!0],offset:k=[0,0,0],rotation:H=[0,0,0],scale:I=1,lineWidth:U=4,fixed:G=!1,translationLimits:J,rotationLimits:K,scaleLimits:N,depthTest:Q=!0,axisColors:X=["#ff2060","#20df80","#2080ff"],hoveredColor:Y="#ffff40",annotations:Z=!1,annotationsClass:$,opacity:ee=1,visible:re=!0,userData:te,children:ie,...ae},ne)=>{const oe=r.useThree((e=>e.invalidate)),ce=m.useRef(null),se=m.useRef(null),le=m.useRef(null),ue=m.useRef(null),de=m.useRef([0,0,0]),xe=m.useRef(new p.Vector3(1,1,1)),me=m.useRef(new p.Vector3(1,1,1));m.useLayoutEffect((()=>{O&&(ue.current.updateWorldMatrix(!0,!0),g.copy(ue.current.matrixWorld).invert(),v.makeEmpty(),ue.current.traverse((e=>{e.geometry&&(e.geometry.boundingBox||e.geometry.computeBoundingBox(),j.copy(e.matrixWorld).premultiply(g),M.copy(e.geometry.boundingBox),M.applyMatrix4(j),v.union(M))})),A.copy(v.max).add(v.min).multiplyScalar(.5),q.copy(v.max).sub(v.min).multiplyScalar(.5),R.copy(q).multiply(new p.Vector3(...O)).add(A),V.set(...k).add(R),le.current.position.copy(V),oe())}));const pe=m.useMemo((()=>({onDragStart:e=>{f.copy(se.current.matrix),y.copy(se.current.matrixWorld),i&&i(e),oe()},onDrag:e=>{w.copy(ce.current.matrixWorld),g.copy(w).invert(),b.copy(y).premultiply(e),j.copy(b).premultiply(g),E.copy(f).invert(),S.copy(j).multiply(E),L&&se.current.matrix.copy(j),u&&u(j,S,b,e),oe()},onDragEnd:()=>{d&&d(),oe()},translation:de,translationLimits:J,rotationLimits:K,axisColors:X,hoveredColor:Y,opacity:ee,scale:I,lineWidth:U,fixed:G,depthTest:Q,userData:te,annotations:Z,annotationsClass:$})),[i,u,d,de,J,K,N,Q,I,U,G,...X,Y,ee,te,L,Z,$]),fe=new p.Vector3;return r.useFrame((e=>{if(G){const r=l.calculateScaleFactor(le.current.getWorldPosition(fe),I,e.camera,e.size);xe.current.setScalar(r)}t&&t instanceof p.Matrix4&&(se.current.matrix=t),se.current.updateWorldMatrix(!0,!0),h.makeRotationFromEuler(le.current.rotation).setPosition(le.current.position).premultiply(se.current.matrixWorld),me.current.setFromMatrixScale(h),P.copy(xe.current).divide(me.current),(Math.abs(le.current.scale.x-P.x)>1e-4||Math.abs(le.current.scale.y-P.y)>1e-4||Math.abs(le.current.scale.z-P.z)>1e-4)&&(le.current.scale.copy(P),e.invalidate())})),m.useImperativeHandle(ne,(()=>se.current),[]),m.createElement(s.context.Provider,{value:pe},m.createElement("group",{ref:ce},m.createElement("group",x.default({ref:se,matrix:t,matrixAutoUpdate:!1},ae),e&&m.createElement("group",{visible:re,ref:le,position:k,rotation:H},!B&&_[0]&&m.createElement(a.AxisArrow,{axis:0,direction:W}),!B&&_[1]&&m.createElement(a.AxisArrow,{axis:1,direction:D}),!B&&_[2]&&m.createElement(a.AxisArrow,{axis:2,direction:C}),!F&&_[0]&&_[1]&&m.createElement(o.PlaneSlider,{axis:2,dir1:W,dir2:D}),!F&&_[0]&&_[2]&&m.createElement(o.PlaneSlider,{axis:1,dir1:C,dir2:W}),!F&&_[2]&&_[1]&&m.createElement(o.PlaneSlider,{axis:0,dir1:D,dir2:C}),!z&&_[0]&&_[1]&&m.createElement(n.AxisRotator,{axis:2,dir1:W,dir2:D}),!z&&_[0]&&_[2]&&m.createElement(n.AxisRotator,{axis:1,dir1:C,dir2:W}),!z&&_[2]&&_[1]&&m.createElement(n.AxisRotator,{axis:0,dir1:D,dir2:C}),!T&&_[0]&&m.createElement(c.ScalingSphere,{axis:0,direction:W}),!T&&_[1]&&m.createElement(c.ScalingSphere,{axis:1,direction:D}),!T&&_[2]&&m.createElement(c.ScalingSphere,{axis:2,direction:C})),m.createElement("group",{ref:ue},ie))))}));exports.PivotControls=L;
@@ -3,6 +3,7 @@ import * as THREE from 'three';
3
3
  import { ForwardRefComponent } from '../../helpers/ts-utils';
4
4
  import { OnDragStartProps } from './context';
5
5
  type PivotControlsProps = {
6
+ enabled?: boolean;
6
7
  scale?: number;
7
8
  lineWidth?: number;
8
9
  fixed?: boolean;
@@ -29,6 +29,7 @@ const xDir = /* @__PURE__ */new THREE.Vector3(1, 0, 0);
29
29
  const yDir = /* @__PURE__ */new THREE.Vector3(0, 1, 0);
30
30
  const zDir = /* @__PURE__ */new THREE.Vector3(0, 0, 1);
31
31
  const PivotControls = /* @__PURE__ */React.forwardRef(({
32
+ enabled = true,
32
33
  matrix,
33
34
  onDragStart,
34
35
  onDrag,
@@ -155,7 +156,7 @@ const PivotControls = /* @__PURE__ */React.forwardRef(({
155
156
  ref: ref,
156
157
  matrix: matrix,
157
158
  matrixAutoUpdate: false
158
- }, props), /*#__PURE__*/React.createElement("group", {
159
+ }, props), enabled && /*#__PURE__*/React.createElement("group", {
159
160
  visible: visible,
160
161
  ref: gizmoRef,
161
162
  position: offset,