@react-three/drei 9.52.6 → 9.53.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/README.md +2 -1
- package/core/Line.cjs.js +1 -1
- package/core/Line.d.ts +3 -2
- package/core/Line.js +5 -4
- package/index.cjs.js +1 -1
- package/package.json +1 -1
- package/web/pivotControls/index.cjs.js +1 -1
- package/web/pivotControls/index.js +10 -3
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("three"),t=require("react"),i=require("@react-three/fiber"),o=require("./AxisArrow.cjs.js"),n=require("./PlaneSlider.cjs.js"),a=require("./AxisRotator.cjs.js"),c=require("./context.cjs.js");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function l(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"),require("lodash.clamp");var u=s(e),d=l(r),x=l(t);const p=new d.Vector3,m=new d.Vector3,f=new d.Vector3,y=(e,r,t,i=1)=>{const o=p.set(e.x/t.width*2-1,-e.y/t.height*2+1,i);return o.unproject(r),o},w=(e,r,t,i)=>{const o=((e,r,t)=>{const i=t.width/2,o=t.height/2;r.updateMatrixWorld(!1);const n=e.project(r);return n.x=n.x*i+i,n.y=-n.y*o+o,n})(f.copy(e),t,i);let n=0;for(let a=0;a<2;++a){const c=m.copy(o).setComponent(a,o.getComponent(a)+r),s=y(c,t,i,c.z);n=Math.max(n,e.distanceTo(s))}return n},g=new d.Matrix4,v=new d.Matrix4,h=new d.Matrix4,j=new d.Matrix4,b=new d.Matrix4,E=new d.Matrix4,M=new d.Matrix4,A=new d.Matrix4,q=new d.Box3,V=new d.Box3,R=new d.Vector3,S=new d.Vector3,P=new d.Vector3,C=new d.Vector3,D=new d.Vector3(1,0,0),W=new d.Vector3(0,1,0),L=new d.Vector3(0,0,1),O=x.forwardRef((({matrix:e,onDragStart:r,onDrag:t,onDragEnd:s,autoTransform:l=!0,anchor:p,disableAxes:m=!1,disableSliders:f=!1,disableRotations:y=!1,activeAxes:O=[!0,!0,!0],offset:B=[0,0,0],rotation:T=[0,0,0],scale:z=1,lineWidth:_=4,fixed:k=!1,translationLimits:F,rotationLimits:H,depthTest:I=!0,axisColors:U=["#ff2060","#20df80","#2080ff"],hoveredColor:G="#ffff40",annotations:J=!1,annotationsClass:K,opacity:N=1,visible:Q=!0,userData:X,children:Y,...Z},$)=>{const ee=i.useThree((e=>e.invalidate)),re=x.useRef(null),te=x.useRef(null),ie=x.useRef(null),oe=x.useRef(null),ne=x.useRef([0,0,0]);x.useLayoutEffect((()=>{p&&(oe.current.updateWorldMatrix(!0,!0),j.copy(oe.current.matrixWorld).invert(),q.makeEmpty(),oe.current.traverse((e=>{e.geometry&&(e.geometry.boundingBox||e.geometry.computeBoundingBox(),E.copy(e.matrixWorld).premultiply(j),V.copy(e.geometry.boundingBox),V.applyMatrix4(E),q.union(V))})),R.copy(q.max).add(q.min).multiplyScalar(.5),S.copy(q.max).sub(q.min).multiplyScalar(.5),P.copy(S).multiply(new d.Vector3(...p)).add(R),C.set(...B).add(P),ie.current.position.copy(C),ee())}));const ae=x.useMemo((()=>({onDragStart:e=>{g.copy(te.current.matrix),v.copy(te.current.matrixWorld),r&&r(e),ee()},onDrag:e=>{h.copy(re.current.matrixWorld),j.copy(h).invert(),b.copy(v).premultiply(e),E.copy(b).premultiply(j),M.copy(g).invert(),A.copy(E).multiply(M),l&&te.current.matrix.copy(E),t&&t(E,A,b,e),ee()},onDragEnd:()=>{s&&s(),ee()},translation:ne,translationLimits:F,rotationLimits:H,axisColors:U,hoveredColor:G,opacity:N,scale:z,lineWidth:_,fixed:k,depthTest:I,userData:X,annotations:J,annotationsClass:K})),[r,t,s,ne,F,H,I,z,_,k,...U,G,N,X,l,J,K]),ce=new d.Vector3;return i.useFrame((e=>{if(k){const o=w(ie.current.getWorldPosition(ce),z,e.camera,e.size);var r,t,i;if(ie.current)(null==(r=ie.current)?void 0:r.scale.x)===o&&(null==(t=ie.current)?void 0:t.scale.y)===o&&(null==(i=ie.current)?void 0:i.scale.z)===o||(ie.current.scale.setScalar(o),e.invalidate())}})),x.useImperativeHandle($,(()=>te.current),[]),x.useLayoutEffect((()=>{e&&e instanceof d.Matrix4&&(te.current.matrix=e)}),[e]),x.createElement(c.context.Provider,{value:ae},x.createElement("group",{ref:re},x.createElement("group",u.default({ref:te,matrix:e,matrixAutoUpdate:!1},Z),x.createElement("group",{visible:Q,ref:ie,position:B,rotation:T},!m&&O[0]&&x.createElement(o.AxisArrow,{axis:0,direction:D}),!m&&O[1]&&x.createElement(o.AxisArrow,{axis:1,direction:W}),!m&&O[2]&&x.createElement(o.AxisArrow,{axis:2,direction:L}),!f&&O[0]&&O[1]&&x.createElement(n.PlaneSlider,{axis:2,dir1:D,dir2:W}),!f&&O[0]&&O[2]&&x.createElement(n.PlaneSlider,{axis:1,dir1:L,dir2:D}),!f&&O[2]&&O[1]&&x.createElement(n.PlaneSlider,{axis:0,dir1:W,dir2:L}),!y&&O[0]&&O[1]&&x.createElement(a.AxisRotator,{axis:2,dir1:D,dir2:W}),!y&&O[0]&&O[2]&&x.createElement(a.AxisRotator,{axis:1,dir1:L,dir2:D}),!y&&O[2]&&O[1]&&x.createElement(a.AxisRotator,{axis:0,dir1:W,dir2:L})),x.createElement("group",{ref:oe},Y))))}));exports.PivotControls=O,exports.calculateScaleFactor=w;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
1
2
|
import * as THREE from 'three';
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
import { useThree, useFrame } from '@react-three/fiber';
|
|
@@ -81,7 +82,8 @@ const PivotControls = /*#__PURE__*/React.forwardRef(({
|
|
|
81
82
|
opacity = 1,
|
|
82
83
|
visible = true,
|
|
83
84
|
userData,
|
|
84
|
-
children
|
|
85
|
+
children,
|
|
86
|
+
...props
|
|
85
87
|
}, fRef) => {
|
|
86
88
|
const invalidate = useThree(state => state.invalidate);
|
|
87
89
|
const parentRef = React.useRef(null);
|
|
@@ -162,15 +164,20 @@ const PivotControls = /*#__PURE__*/React.forwardRef(({
|
|
|
162
164
|
}
|
|
163
165
|
});
|
|
164
166
|
React.useImperativeHandle(fRef, () => ref.current, []);
|
|
167
|
+
React.useLayoutEffect(() => {
|
|
168
|
+
// If the matrix is a real matrix4 it means that the user wants to control the gizmo
|
|
169
|
+
// In that case it should just be set, as a bare prop update would merely copy it
|
|
170
|
+
if (matrix && matrix instanceof THREE.Matrix4) ref.current.matrix = matrix;
|
|
171
|
+
}, [matrix]);
|
|
165
172
|
return /*#__PURE__*/React.createElement(context.Provider, {
|
|
166
173
|
value: config
|
|
167
174
|
}, /*#__PURE__*/React.createElement("group", {
|
|
168
175
|
ref: parentRef
|
|
169
|
-
}, /*#__PURE__*/React.createElement("group", {
|
|
176
|
+
}, /*#__PURE__*/React.createElement("group", _extends({
|
|
170
177
|
ref: ref,
|
|
171
178
|
matrix: matrix,
|
|
172
179
|
matrixAutoUpdate: false
|
|
173
|
-
}, /*#__PURE__*/React.createElement("group", {
|
|
180
|
+
}, props), /*#__PURE__*/React.createElement("group", {
|
|
174
181
|
visible: visible,
|
|
175
182
|
ref: gizmoRef,
|
|
176
183
|
position: offset,
|