UNPKG

lingo3d-react

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

741 lines (740 loc) 30.9 kB
import { aZ as Yt, a as r, O as ot, Q as P, E as At, h as bt, a2 as St, o as Zt, a_ as M, a$ as f, r as rt, s as lt, n as a, b0 as N, p as I, b1 as V, aD as Ht, a1 as Tt } from "./index-895cfa2f.mjs"; import "react"; import "react-dom"; const e = 0.5, u = 0.2, ht = 13386820, ct = 4508740, pt = 4474060, $ = 13417284, zt = 7895160, A = new Yt(), m = new r(), Q = new r(), c = new P(), dt = { X: new r(1, 0, 0), Y: new r(0, 1, 0), Z: new r(0, 0, 1) }, it = { type: "change" }, mt = { type: "mouseDown" }, ut = { type: "mouseUp", mode: null }, wt = { type: "objectChange" }; class Ft extends ot { constructor(n, o) { super(), o === void 0 && (console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'), o = document), this.isTransformControls = !0, this.visible = !1, this.domElement = o, this.domElement.style.touchAction = "none"; const s = new Ot(); this._gizmo = s, this.add(s); const i = new Rt(); this._plane = i, this.add(i); const h = this; function t(w, x) { let D = x; Object.defineProperty(h, w, { get: function() { return D !== void 0 ? D : x; }, set: function(Y) { D !== Y && (D = Y, i[w] = Y, s[w] = Y, h.dispatchEvent({ type: w + "-changed", value: Y }), h.dispatchEvent(it)); } }), h[w] = x, i[w] = x, s[w] = x; } t("camera", n), t("object", void 0), t("enabled", !0), t("axis", null), t("mode", "translate"), t("translationSnap", null), t("rotationSnap", null), t("scaleSnap", null), t("space", "world"), t("size", 1), t("dragging", !1), t("showX", !0), t("showY", !0), t("showZ", !0); const d = new r(), v = new r(), X = new P(), H = new P(), q = new r(), C = new P(), st = new r(), G = new r(), T = new r(), z = 0, S = new r(); t("worldPosition", d), t("worldPositionStart", v), t("worldQuaternion", X), t("worldQuaternionStart", H), t("cameraPosition", q), t("cameraQuaternion", C), t("pointStart", st), t("pointEnd", G), t("rotationAxis", T), t("rotationAngle", z), t("eye", S), this._offset = new r(), this._startNorm = new r(), this._endNorm = new r(), this._cameraScale = new r(), this._parentPosition = new r(), this._parentQuaternion = new P(), this._parentQuaternionInv = new P(), this._parentScale = new r(), this._worldScaleStart = new r(), this._worldQuaternionInv = new P(), this._worldScale = new r(), this._positionStart = new r(), this._quaternionStart = new P(), this._scaleStart = new r(), this._getPointer = Dt.bind(this), this._onPointerDown = qt.bind(this), this._onPointerHover = jt.bind(this), this._onPointerMove = Lt.bind(this), this._onPointerUp = kt.bind(this), this.domElement.addEventListener("pointerdown", this._onPointerDown), this.domElement.addEventListener("pointermove", this._onPointerHover), this.domElement.addEventListener("pointerup", this._onPointerUp); } // updateMatrixWorld updates key transformation variables updateMatrixWorld() { this.object !== void 0 && (this.object.updateMatrixWorld(), this.object.parent === null ? console.error("TransformControls: The attached 3D object must be a part of the scene graph.") : this.object.parent.matrixWorld.decompose(this._parentPosition, this._parentQuaternion, this._parentScale), this.object.matrixWorld.decompose(this.worldPosition, this.worldQuaternion, this._worldScale), this._parentQuaternionInv.copy(this._parentQuaternion).invert(), this._worldQuaternionInv.copy(this.worldQuaternion).invert()), this.camera.updateMatrixWorld(), this.camera.matrixWorld.decompose(this.cameraPosition, this.cameraQuaternion, this._cameraScale), this.camera.isOrthographicCamera ? this.camera.getWorldDirection(this.eye).negate() : this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(), super.updateMatrixWorld(this); } pointerHover(n) { if (this.object === void 0 || this.dragging === !0) return; A.setFromCamera(n, this.camera); const o = nt(this._gizmo.picker[this.mode], A); o ? this.axis = o.object.name : this.axis = null; } pointerDown(n) { if (!(this.object === void 0 || this.dragging === !0 || n.button !== 0) && this.axis !== null) { A.setFromCamera(n, this.camera); const o = nt(this._plane, A, !0); o && (this.object.updateMatrixWorld(), this.object.parent.updateMatrixWorld(), this._positionStart.copy(this.object.position), this._quaternionStart.copy(this.object.quaternion), this._scaleStart.copy(this.object.scale), this.object.matrixWorld.decompose(this.worldPositionStart, this.worldQuaternionStart, this._worldScaleStart), this.pointStart.copy(o.point).sub(this.worldPositionStart)), this.dragging = !0, mt.mode = this.mode, this.dispatchEvent(mt); } } pointerMove(n) { const o = this.axis, s = this.mode, i = this.object; let h = this.space; if (s === "scale" ? h = "local" : (o === "E" || o === "XYZE" || o === "XYZ") && (h = "world"), i === void 0 || o === null || this.dragging === !1 || n.button !== -1) return; A.setFromCamera(n, this.camera); const t = nt(this._plane, A, !0); if (t) { if (this.pointEnd.copy(t.point).sub(this.worldPositionStart), s === "translate") this._offset.copy(this.pointEnd).sub(this.pointStart), h === "local" && o !== "XYZ" && this._offset.applyQuaternion(this._worldQuaternionInv), o.indexOf("X") === -1 && (this._offset.x = 0), o.indexOf("Y") === -1 && (this._offset.y = 0), o.indexOf("Z") === -1 && (this._offset.z = 0), h === "local" && o !== "XYZ" ? this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale) : this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale), i.position.copy(this._offset).add(this._positionStart), this.translationSnap && (h === "local" && (i.position.applyQuaternion(c.copy(this._quaternionStart).invert()), o.search("X") !== -1 && (i.position.x = Math.round(i.position.x / this.translationSnap) * this.translationSnap), o.search("Y") !== -1 && (i.position.y = Math.round(i.position.y / this.translationSnap) * this.translationSnap), o.search("Z") !== -1 && (i.position.z = Math.round(i.position.z / this.translationSnap) * this.translationSnap), i.position.applyQuaternion(this._quaternionStart)), h === "world" && (i.parent && i.position.add(m.setFromMatrixPosition(i.parent.matrixWorld)), o.search("X") !== -1 && (i.position.x = Math.round(i.position.x / this.translationSnap) * this.translationSnap), o.search("Y") !== -1 && (i.position.y = Math.round(i.position.y / this.translationSnap) * this.translationSnap), o.search("Z") !== -1 && (i.position.z = Math.round(i.position.z / this.translationSnap) * this.translationSnap), i.parent && i.position.sub(m.setFromMatrixPosition(i.parent.matrixWorld)))); else if (s === "scale") { if (o.search("XYZ") !== -1) { let d = this.pointEnd.length() / this.pointStart.length(); this.pointEnd.dot(this.pointStart) < 0 && (d *= -1), Q.set(d, d, d); } else m.copy(this.pointStart), Q.copy(this.pointEnd), m.applyQuaternion(this._worldQuaternionInv), Q.applyQuaternion(this._worldQuaternionInv), Q.divide(m), o.search("X") === -1 && (Q.x = 1), o.search("Y") === -1 && (Q.y = 1), o.search("Z") === -1 && (Q.z = 1); i.scale.copy(this._scaleStart).multiply(Q), this.scaleSnap && (o.search("X") !== -1 && (i.scale.x = Math.round(i.scale.x / this.scaleSnap) * this.scaleSnap || this.scaleSnap), o.search("Y") !== -1 && (i.scale.y = Math.round(i.scale.y / this.scaleSnap) * this.scaleSnap || this.scaleSnap), o.search("Z") !== -1 && (i.scale.z = Math.round(i.scale.z / this.scaleSnap) * this.scaleSnap || this.scaleSnap)); } else if (s === "rotate") { this._offset.copy(this.pointEnd).sub(this.pointStart); const d = 20 / this.worldPosition.distanceTo(m.setFromMatrixPosition(this.camera.matrixWorld)); o === "E" ? (this.rotationAxis.copy(this.eye), this.rotationAngle = this.pointEnd.angleTo(this.pointStart), this._startNorm.copy(this.pointStart).normalize(), this._endNorm.copy(this.pointEnd).normalize(), this.rotationAngle *= this._endNorm.cross(this._startNorm).dot(this.eye) < 0 ? 1 : -1) : o === "XYZE" ? (this.rotationAxis.copy(this._offset).cross(this.eye).normalize(), this.rotationAngle = this._offset.dot(m.copy(this.rotationAxis).cross(this.eye)) * d) : (o === "X" || o === "Y" || o === "Z") && (this.rotationAxis.copy(dt[o]), m.copy(dt[o]), h === "local" && m.applyQuaternion(this.worldQuaternion), m.cross(this.eye).normalize(), m.x === 0 && m.y === 0 && m.z === 0 && m.set(0, 1, 0), this.rotationAngle = this._offset.dot(m) * d), this.rotationSnap && (this.rotationAngle = Math.round(this.rotationAngle / this.rotationSnap) * this.rotationSnap), h === "local" && o !== "E" && o !== "XYZE" ? (i.quaternion.copy(this._quaternionStart), i.quaternion.multiply(c.setFromAxisAngle(this.rotationAxis, this.rotationAngle)).normalize()) : (this.rotationAxis.applyQuaternion(this._parentQuaternionInv), i.quaternion.copy(c.setFromAxisAngle(this.rotationAxis, this.rotationAngle)), i.quaternion.multiply(this._quaternionStart).normalize()); } this.dispatchEvent(it), this.dispatchEvent(wt); } } pointerUp(n) { n.button === 0 && (this.dragging && this.axis !== null && (ut.mode = this.mode, this.dispatchEvent(ut)), this.dragging = !1, this.axis = null); } dispose() { this.domElement.removeEventListener("pointerdown", this._onPointerDown), this.domElement.removeEventListener("pointermove", this._onPointerHover), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.domElement.removeEventListener("pointerup", this._onPointerUp), this.traverse(function(n) { n.geometry && n.geometry.dispose(), n.material && n.material.dispose(); }); } // Set current object attach(n) { return this.object = n, this.visible = !0, this; } // Detach from object detach() { return this.object = void 0, this.visible = !1, this.axis = null, this; } reset() { this.enabled && this.dragging && (this.object.position.copy(this._positionStart), this.object.quaternion.copy(this._quaternionStart), this.object.scale.copy(this._scaleStart), this.dispatchEvent(it), this.dispatchEvent(wt), this.pointStart.copy(this.pointEnd)); } getRaycaster() { return A; } // TODO: deprecate getMode() { return this.mode; } setMode(n) { this.mode = n; } setTranslationSnap(n) { this.translationSnap = n; } setRotationSnap(n) { this.rotationSnap = n; } setScaleSnap(n) { this.scaleSnap = n; } setSize(n) { this.size = n; } setSpace(n) { this.space = n; } } function Dt(p) { if (this.domElement.ownerDocument.pointerLockElement) return { x: 0, y: 0, button: p.button }; { const n = this.domElement.getBoundingClientRect(); return { x: (p.clientX - n.left) / n.width * 2 - 1, y: -(p.clientY - n.top) / n.height * 2 + 1, button: p.button }; } } function jt(p) { if (this.enabled) switch (p.pointerType) { case "mouse": case "pen": this.pointerHover(this._getPointer(p)); break; } } function qt(p) { this.enabled && (document.pointerLockElement || this.domElement.setPointerCapture(p.pointerId), this.domElement.addEventListener("pointermove", this._onPointerMove), this.pointerHover(this._getPointer(p)), this.pointerDown(this._getPointer(p))); } function Lt(p) { this.enabled && this.pointerMove(this._getPointer(p)); } function kt(p) { this.enabled && (this.domElement.releasePointerCapture(p.pointerId), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.pointerUp(this._getPointer(p))); } function nt(p, n, o) { const s = n.intersectObject(p, !0); for (let i = 0; i < s.length; i++) if (s[i].object.visible || o) return s[i]; return !1; } const J = new At(), l = new r(0, 1, 0), ft = new r(0, 0, 0), yt = new bt(), K = new P(), et = new P(), g = new r(), _t = new bt(), O = new r(1, 0, 0), Z = new r(0, 1, 0), R = new r(0, 0, 1), tt = new r(), L = new r(), k = new r(); class Ot extends ot { constructor() { super(), this.isTransformControlsGizmo = !0, this.type = "TransformControlsGizmo"; const n = new St({ depthTest: !1, depthWrite: !1, fog: !1, toneMapped: !1, transparent: !0 }), o = new Zt({ depthTest: !1, depthWrite: !1, fog: !1, toneMapped: !1, transparent: !0 }), s = n.clone(); s.opacity = 0.15; const i = o.clone(); i.opacity = 0.5; const h = n.clone(); h.color.setHex(ht); const t = n.clone(); t.color.setHex(ct); const d = n.clone(); d.color.setHex(pt); const v = n.clone(); v.color.setHex(ht), v.opacity = 1; const X = n.clone(); X.color.setHex(ct), X.opacity = 1; const H = n.clone(); H.color.setHex(pt), H.opacity = 1; const q = n.clone(); q.opacity = 0.25; const C = n.clone(); C.color.setHex($), C.opacity = 0.25, n.clone().color.setHex($); const G = n.clone(); G.color.setHex(zt); const T = new M(0, 0.04 * e, 0.1 * e, 12); T.translate(0, 0.05 * e, 0); const z = new f(0.08 * e, 0.08 * e, 0.08 * e); z.translate(0, 0.04 * e, 0); const S = new rt(); S.setAttribute("position", new lt([0, 0, 0, 1, 0, 0], 3)); const w = new M(75e-4, 75e-4, 0.5 * e, 3); w.translate(0, 0.25 * e, 0); function x(_, W) { const b = new V(_ * e, 75e-4, 3, 64, W * Math.PI * 2); return b.rotateY(Math.PI / 2), b.rotateX(Math.PI / 2), b; } function D() { const _ = new rt(); return _.setAttribute("position", new lt([0, 0, 0, 1, 1, 1], 3)), _; } const Y = { X: [ [ new a(T, h), [0.5 * e, 0, 0], [0, 0, -Math.PI / 2] ], // [ // new Mesh(arrowGeometry, matRed), // [-0.5 * ratio, 0, 0], // [0, 0, Math.PI / 2] // ], [ new a(w, h), [0, 0, 0], [0, 0, -Math.PI / 2] ] ], Y: [ [new a(T, t), [0, 0.5 * e, 0]], // [ // new Mesh(arrowGeometry, matGreen), // [0, -0.5 * ratio, 0], // [Math.PI, 0, 0] // ], [new a(w, t)] ], Z: [ [ new a(T, d), [0, 0, 0.5 * e], [Math.PI / 2, 0, 0] ], // [ // new Mesh(arrowGeometry, matBlue), // [0, 0, -0.5 * ratio], // [-Math.PI / 2, 0, 0] // ], [new a(w, d), null, [Math.PI / 2, 0, 0]] ], XYZ: [ [ new a(new N(0.1 * e, 0), q.clone()), [0, 0, 0] ] ], XY: [ [ new a(new f(u * e, u * e, 0.01 * e), H.clone()), [u * e, u * e, 0] ] ], YZ: [ [ new a(new f(u * e, u * e, 0.01 * e), v.clone()), [0, u * e, u * e], [0, Math.PI / 2, 0] ] ], XZ: [ [ new a(new f(u * e, u * e, 0.01 * e), X.clone()), [u * e, 0, u * e], [-Math.PI / 2, 0, 0] ] ] }, xt = { X: [ [ new a(new M(0.2 * e, 0, 0.6 * e, 4), s), [0.3 * e, 0, 0], [0, 0, -Math.PI / 2] ] // [ // new Mesh( // new CylinderGeometry(0.2 * ratio, 0, 0.6 * ratio, 4), // matInvisible // ), // [-0.3 * ratio, 0, 0], // [0, 0, Math.PI / 2] // ] ], Y: [ [ new a(new M(0.2 * e, 0, 0.6 * e, 4), s), [0, 0.3 * e, 0] ] // [ // new Mesh( // new CylinderGeometry(0.2 * ratio, 0, 0.6 * ratio, 4), // matInvisible // ), // [0, -0.3 * ratio, 0], // [0, 0, Math.PI] // ] ], Z: [ [ new a(new M(0.2 * e, 0, 0.6 * e, 4), s), [0, 0, 0.3 * e], [Math.PI / 2, 0, 0] ] // [ // new Mesh( // new CylinderGeometry(0.2 * ratio, 0, 0.6 * ratio, 4), // matInvisible // ), // [0, 0, -0.3 * ratio], // [-Math.PI / 2, 0, 0] // ] ], XYZ: [ [new a(new N(0.2 * e, 0), s)] ], XY: [ [ new a(new f(0.2 * e, 0.2 * e, 0.01 * e), s), [u * e, u * e, 0] ] ], YZ: [ [ new a(new f(0.2 * e, 0.2 * e, 0.01 * e), s), [0, u * e, u * e], [0, Math.PI / 2, 0] ] ], XZ: [ [ new a(new f(0.2 * e, 0.2 * e, 0.01 * e), s), [u * e, 0, u * e], [-Math.PI / 2, 0, 0] ] ] }, gt = { START: [ [ new a(new N(0.01, 2), i), null, null, null, "helper" ] ], END: [ [ new a(new N(0.01, 2), i), null, null, null, "helper" ] ], DELTA: [ [ new I(D(), i), null, null, null, "helper" ] ], X: [ [ new I(S, i.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], "helper" ] ], Y: [ [ new I(S, i.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], "helper" ] ], Z: [ [ new I(S, i.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], "helper" ] ] }, Pt = { XYZE: [ [ new a(x(0.5, 1), G), null, [0, Math.PI / 2, 0] ] ], X: [[new a(x(0.5, 0.5), h)]], Y: [ [ new a(x(0.5, 0.5), t), null, [0, 0, -Math.PI / 2] ] ], Z: [ [ new a(x(0.5, 0.5), d), null, [0, Math.PI / 2, 0] ] ] // E: [ // [ // new Mesh(CircleGeometry(0.75, 1), matYellowTransparent), // null, // [0, Math.PI / 2, 0] // ] // ] }, vt = { AXIS: [ [ new I(S, i.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], "helper" ] ] }, Et = { // XYZE: [ // [ // new Mesh( // new SphereGeometry(0.25 * ratio, 10, 8), // matInvisible // ) // ] // ], X: [ [ new a(new V(0.5 * e, 0.1 * e, 4, 24), s), [0, 0, 0], [0, -Math.PI / 2, -Math.PI / 2] ] ], Y: [ [ new a(new V(0.5 * e, 0.1 * e, 4, 24), s), [0, 0, 0], [Math.PI / 2, 0, 0] ] ], Z: [ [ new a(new V(0.5 * e, 0.1 * e, 4, 24), s), [0, 0, 0], [0, 0, -Math.PI / 2] ] ] // E: [ // [ // new Mesh( // new TorusGeometry(0.75 * ratio, 0.1 * ratio, 2, 24), // matInvisible // ) // ] // ] }, Mt = { X: [ [ new a(z, h), [0.5 * e, 0, 0], [0, 0, -Math.PI / 2] ], [ new a(w, h), [0, 0, 0], [0, 0, -Math.PI / 2] ] // [ // new Mesh(scaleHandleGeometry, matRed), // [-0.5 * ratio, 0, 0], // [0, 0, Math.PI / 2] // ] ], Y: [ [new a(z, t), [0, 0.5 * e, 0]], [new a(w, t)] // [ // new Mesh(scaleHandleGeometry, matGreen), // [0, -0.5 * ratio, 0], // [0, 0, Math.PI] // ] ], Z: [ [ new a(z, d), [0, 0, 0.5 * e], [Math.PI / 2, 0, 0] ], [ new a(w, d), [0, 0, 0], [Math.PI / 2, 0, 0] ] // [ // new Mesh(scaleHandleGeometry, matBlue), // [0, 0, -0.5 * ratio], // [-Math.PI / 2, 0, 0] // ] ], XY: [ [ new a(new f(0.15 * e, 0.15 * e, 0.01 * e), H), [0.15 * e, 0.15 * e, 0] ] ], YZ: [ [ new a(new f(0.15 * e, 0.15 * e, 0.01 * e), v), [0, 0.15 * e, 0.15 * e], [0, Math.PI / 2, 0] ] ], XZ: [ [ new a(new f(0.15 * e, 0.15 * e, 0.01 * e), X), [0.15 * e, 0, 0.15 * e], [-Math.PI / 2, 0, 0] ] ], XYZ: [ [ new a(new f(0.1 * e, 0.1 * e, 0.1 * e), q.clone()) ] ] }, It = { X: [ [ new a(new M(0.2 * e, 0, 0.6 * e, 4), s), [0.3 * e, 0, 0], [0, 0, -Math.PI / 2] ] // [ // new Mesh( // new CylinderGeometry(0.2 * ratio, 0, 0.6 * ratio, 4), // matInvisible // ), // [-0.3 * ratio, 0, 0], // [0, 0, Math.PI / 2] // ] ], Y: [ [ new a(new M(0.2 * e, 0, 0.6 * e, 4), s), [0, 0.3 * e, 0] ] // [ // new Mesh( // new CylinderGeometry(0.2 * ratio, 0, 0.6 * ratio, 4), // matInvisible // ), // [0, -0.3 * ratio, 0], // [0, 0, Math.PI] // ] ], Z: [ [ new a(new M(0.2 * e, 0, 0.6 * e, 4), s), [0, 0, 0.3 * e], [Math.PI / 2, 0, 0] ] // [ // new Mesh( // new CylinderGeometry(0.2 * ratio, 0, 0.6 * ratio, 4), // matInvisible // ), // [0, 0, -0.3 * ratio], // [-Math.PI / 2, 0, 0] // ] ], XY: [ [ new a(new f(0.2 * e, 0.2 * e, 0.01 * e), s), [0.15 * e, 0.15 * e, 0] ] ], YZ: [ [ new a(new f(0.2 * e, 0.2 * e, 0.01 * e), s), [0, 0.15 * e, 0.15 * e], [0, Math.PI / 2, 0] ] ], XZ: [ [ new a(new f(0.2 * e, 0.2 * e, 0.01 * e), s), [0.15 * e, 0, 0.15 * e], [-Math.PI / 2, 0, 0] ] ], XYZ: [ [ new a(new f(0.2 * e, 0.2 * e, 0.2 * e), s), [0, 0, 0] ] ] }, Qt = { X: [ [ new I(S, i.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], "helper" ] ], Y: [ [ new I(S, i.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], "helper" ] ], Z: [ [ new I(S, i.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], "helper" ] ] }; function E(_) { const W = new ot(); for (const b in _) for (let j = _[b].length; j--; ) { const y = _[b][j][0].clone(), F = _[b][j][1], B = _[b][j][2], U = _[b][j][3], Xt = _[b][j][4]; y.name = b, y.tag = Xt, F && y.position.set(F[0], F[1], F[2]), B && y.rotation.set(B[0], B[1], B[2]), U && y.scale.set(U[0], U[1], U[2]), y.updateMatrix(); const at = y.geometry.clone(); at.applyMatrix4(y.matrix), y.geometry = at, y.renderOrder = 1 / 0, y.position.set(0, 0, 0), y.rotation.set(0, 0, 0), y.scale.set(1, 1, 1), W.add(y); } return W; } this.gizmo = {}, this.picker = {}, this.helper = {}, this.add(this.gizmo.translate = E(Y)), this.add(this.gizmo.rotate = E(Pt)), this.add(this.gizmo.scale = E(Mt)), this.add(this.picker.translate = E(xt)), this.add(this.picker.rotate = E(Et)), this.add(this.picker.scale = E(It)), this.add(this.helper.translate = E(gt)), this.add(this.helper.rotate = E(vt)), this.add(this.helper.scale = E(Qt)), this.picker.translate.visible = !1, this.picker.rotate.visible = !1, this.picker.scale.visible = !1; } // updateMatrixWorld will update transformations and appearance of individual handles updateMatrixWorld(n) { const s = (this.mode === "scale" ? "local" : this.space) === "local" ? this.worldQuaternion : et; this.gizmo.translate.visible = this.mode === "translate", this.gizmo.rotate.visible = this.mode === "rotate", this.gizmo.scale.visible = this.mode === "scale", this.helper.translate.visible = this.mode === "translate", this.helper.rotate.visible = this.mode === "rotate", this.helper.scale.visible = this.mode === "scale"; let i = []; i = i.concat(this.picker[this.mode].children), i = i.concat(this.gizmo[this.mode].children), i = i.concat(this.helper[this.mode].children); for (let h = 0; h < i.length; h++) { const t = i[h]; t.visible = !0, t.rotation.set(0, 0, 0), t.position.copy(this.worldPosition); let d; if (this.camera.isOrthographicCamera ? d = (this.camera.top - this.camera.bottom) / this.camera.zoom : d = this.worldPosition.distanceTo(this.cameraPosition) * Math.min(1.9 * Math.tan(Math.PI * this.camera.fov / 360) / this.camera.zoom, 7), t.scale.set(1, 1, 1).multiplyScalar(d * this.size / 4), t.tag === "helper") { t.visible = !1, t.name === "AXIS" ? (t.visible = !!this.axis, this.axis === "X" && (c.setFromEuler(J.set(0, 0, 0)), t.quaternion.copy(s).multiply(c), Math.abs(l.copy(O).applyQuaternion(s).dot(this.eye)) > 0.9 && (t.visible = !1)), this.axis === "Y" && (c.setFromEuler(J.set(0, 0, Math.PI / 2)), t.quaternion.copy(s).multiply(c), Math.abs(l.copy(Z).applyQuaternion(s).dot(this.eye)) > 0.9 && (t.visible = !1)), this.axis === "Z" && (c.setFromEuler(J.set(0, Math.PI / 2, 0)), t.quaternion.copy(s).multiply(c), Math.abs(l.copy(R).applyQuaternion(s).dot(this.eye)) > 0.9 && (t.visible = !1)), this.axis === "XYZE" && (c.setFromEuler(J.set(0, Math.PI / 2, 0)), l.copy(this.rotationAxis), t.quaternion.setFromRotationMatrix(yt.lookAt(ft, l, Z)), t.quaternion.multiply(c), t.visible = this.dragging), this.axis === "E" && (t.visible = !1)) : t.name === "START" ? (t.position.copy(this.worldPositionStart), t.visible = this.dragging) : t.name === "END" ? (t.position.copy(this.worldPosition), t.visible = this.dragging) : t.name === "DELTA" ? (t.position.copy(this.worldPositionStart), t.quaternion.copy(this.worldQuaternionStart), m.set(1e-10, 1e-10, 1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1), m.applyQuaternion(this.worldQuaternionStart.clone().invert()), t.scale.copy(m), t.visible = this.dragging) : (t.quaternion.copy(s), this.dragging ? t.position.copy(this.worldPositionStart) : t.position.copy(this.worldPosition), this.axis && (t.visible = this.axis.search(t.name) !== -1)); continue; } t.quaternion.copy(s), this.mode === "translate" || this.mode === "scale" ? (t.name === "X" && Math.abs(l.copy(O).applyQuaternion(s).dot(this.eye)) > 0.99 && (t.scale.set(1e-10, 1e-10, 1e-10), t.visible = !1), t.name === "Y" && Math.abs(l.copy(Z).applyQuaternion(s).dot(this.eye)) > 0.99 && (t.scale.set(1e-10, 1e-10, 1e-10), t.visible = !1), t.name === "Z" && Math.abs(l.copy(R).applyQuaternion(s).dot(this.eye)) > 0.99 && (t.scale.set(1e-10, 1e-10, 1e-10), t.visible = !1), t.name === "XY" && Math.abs(l.copy(R).applyQuaternion(s).dot(this.eye)) < 0.2 && (t.scale.set(1e-10, 1e-10, 1e-10), t.visible = !1), t.name === "YZ" && Math.abs(l.copy(O).applyQuaternion(s).dot(this.eye)) < 0.2 && (t.scale.set(1e-10, 1e-10, 1e-10), t.visible = !1), t.name === "XZ" && Math.abs(l.copy(Z).applyQuaternion(s).dot(this.eye)) < 0.2 && (t.scale.set(1e-10, 1e-10, 1e-10), t.visible = !1)) : this.mode === "rotate" && (K.copy(s), l.copy(this.eye).applyQuaternion(c.copy(s).invert()), t.name.search("E") !== -1 && t.quaternion.setFromRotationMatrix(yt.lookAt(this.eye, ft, Z)), t.name === "X" && (c.setFromAxisAngle(O, Math.atan2(-l.y, l.z)), c.multiplyQuaternions(K, c), t.quaternion.copy(c)), t.name === "Y" && (c.setFromAxisAngle(Z, Math.atan2(l.x, l.z)), c.multiplyQuaternions(K, c), t.quaternion.copy(c)), t.name === "Z" && (c.setFromAxisAngle(R, Math.atan2(l.y, l.x)), c.multiplyQuaternions(K, c), t.quaternion.copy(c))), t.visible = t.visible && (t.name.indexOf("X") === -1 || this.showX), t.visible = t.visible && (t.name.indexOf("Y") === -1 || this.showY), t.visible = t.visible && (t.name.indexOf("Z") === -1 || this.showZ), t.visible = t.visible && (t.name.indexOf("E") === -1 || this.showX && this.showY && this.showZ), t.material._color = t.material._color || t.material.color.clone(), t.material._opacity = t.material._opacity || t.material.opacity, t.material.color.copy(t.material._color), t.material.opacity = t.material._opacity, this.enabled && this.axis && (t.name === this.axis || this.axis.split("").some(function(v) { return t.name === v; })) && (t.material.color.setHex($), t.material.opacity = 1); } super.updateMatrixWorld(n); } } class Rt extends a { constructor() { super(new Ht(1e5, 1e5, 2, 2), new St({ visible: !1, wireframe: !0, side: Tt, transparent: !0, opacity: 0.1, toneMapped: !1 })), this.isTransformControlsPlane = !0, this.type = "TransformControlsPlane"; } updateMatrixWorld(n) { let o = this.space; switch (this.position.copy(this.worldPosition), this.mode === "scale" && (o = "local"), tt.copy(O).applyQuaternion(o === "local" ? this.worldQuaternion : et), L.copy(Z).applyQuaternion(o === "local" ? this.worldQuaternion : et), k.copy(R).applyQuaternion(o === "local" ? this.worldQuaternion : et), l.copy(L), this.mode) { case "translate": case "scale": switch (this.axis) { case "X": l.copy(this.eye).cross(tt), g.copy(tt).cross(l); break; case "Y": l.copy(this.eye).cross(L), g.copy(L).cross(l); break; case "Z": l.copy(this.eye).cross(k), g.copy(k).cross(l); break; case "XY": g.copy(k); break; case "YZ": g.copy(tt); break; case "XZ": l.copy(k), g.copy(L); break; case "XYZ": case "E": g.set(0, 0, 0); break; } break; case "rotate": default: g.set(0, 0, 0); } g.length() === 0 ? this.quaternion.copy(this.cameraQuaternion) : (_t.lookAt(m.set(0, 0, 0), g, l), this.quaternion.setFromRotationMatrix(_t)), super.updateMatrixWorld(n); } } export { Ft as TransformControls, Ot as TransformControlsGizmo, Rt as TransformControlsPlane };