@allincart-ag/dive
Version:
Allincart Spatial Framework
2 lines (1 loc) • 17.8 kB
JavaScript
"use strict";var w=Object.defineProperty;var x=(i,n,e)=>n in i?w(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var s=(i,n,e)=>x(i,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./chunks/FileTypes-B2JRjVgw.cjs"),d=require("./chunks/PerspectiveCamera-CONx93im.cjs"),r=require("three"),M=require("./chunks/network-error-D_pq8VU6.cjs"),I=require("./chunks/findInterface-C6mrvf_t.cjs"),V=require("./chunks/parse-error-Bd09D_1L.cjs"),b=require("./chunks/PovSchema-Co9FznEz.cjs");class f extends r.Object3D{constructor(e,t,o,h,l){super();s(this,"isHoverable",!0);s(this,"isDraggable",!0);s(this,"parent",null);s(this,"axis");s(this,"_color",new r.Color(16711935));s(this,"_colorHover");s(this,"_hovered");s(this,"_highlight");s(this,"_lineMaterial");s(this,"_colliderMesh");this.name="DIVERadialHandle",this.axis=e,this._color.set(l),this._colorHover=this._color.clone().multiplyScalar(2),this._hovered=!1,this._highlight=!1;const _=new r.TorusGeometry(t,.01,13,48,o);this._lineMaterial=new r.MeshBasicMaterial({color:l,depthTest:!1,depthWrite:!1});const c=new r.Mesh(_,this._lineMaterial);c.layers.mask=d.UI_LAYER_MASK,c.renderOrder=1/0,this.add(c);const p=new r.TorusGeometry(t,.1,3,48,o),g=new r.MeshBasicMaterial({color:16711935,transparent:!0,opacity:.15,depthTest:!1,depthWrite:!1});this._colliderMesh=new r.Mesh(p,g),this._colliderMesh.visible=!1,this._colliderMesh.layers.mask=d.UI_LAYER_MASK,this._colliderMesh.renderOrder=1/0,this.add(this._colliderMesh),this.lookAt(h)}set debug(e){this._colliderMesh.visible=e}get highlight(){return this._highlight}set highlight(e){this._highlight=e,this._lineMaterial.color=this._highlight||this._hovered?this._colorHover:this._color}get forwardVector(){return new r.Vector3(0,0,1).applyQuaternion(this.quaternion).normalize()}get rightVector(){return new r.Vector3(1,0,0).applyQuaternion(this.quaternion).normalize()}get upVector(){return new r.Vector3(0,1,0).applyQuaternion(this.quaternion).normalize()}reset(){this._lineMaterial.color=this._color}onPointerEnter(){this._hovered=!0,this.parent&&this.parent.onHandleHover(this,!0)}onPointerLeave(){this._hovered=!1,this.parent&&this.parent.onHandleHover(this,!1)}onDragStart(){this.parent&&this.parent.onHandleDragStart(this)}onDrag(e){this.parent&&this.parent.onHandleDrag(this,e)}onDragEnd(){this.parent&&this.parent.onHandleDragEnd(this)}}function u(i,n){const e=(i+"e").split("e");return+(e[0]+"e"+(+e[1]+(n||0)))}function P(i,n=0){const e=u(i,+n);return u(Math.ceil(e),-n)}function S(i,n=0){const e=u(i,+n);return u(Math.floor(e),-n)}function y(i,n=0){if(i<0)return-y(-i,n);const e=u(i,+n);return u(Math.round(e),-n)}function R(i,n,e){return Math.atan2(i.clone().cross(n).dot(e),n.clone().dot(i))}function v(i,n=0){const e=u(i,+n);return u(Math.round(e),-n).toFixed(n)}function H(i,n=0){const e=u(i,+n);return u(Math.trunc(e),-n)}function z(i){return(r.MathUtils.radToDeg(i)+360)%360}function G(i){return r.MathUtils.degToRad(i)}const A={ceilExp:P,floorExp:S,roundExp:y,toFixedExp:v,truncateExp:H,signedAngleTo:R,radToDeg:z,degToRad:G};class L extends r.Object3D{constructor(e){super();s(this,"children");s(this,"_controller");s(this,"_startRot");this.name="DIVERotateGizmo",this.children=[],this._startRot=null,this._controller=e,this.add(new f("x",1,Math.PI/2,new r.Vector3(1,0,0),a.AxesColorRed)),this.add(new f("y",1,-Math.PI/2,new r.Vector3(0,1,0),a.AxesColorGreen)),this.add(new f("z",1,Math.PI/2,new r.Vector3(0,0,1),a.AxesColorBlue))}set debug(e){this.children.forEach(t=>{t.debug=e})}reset(){this.children.forEach(e=>{e.reset()})}handleHighlight(e,t,o){this.children.forEach(h=>{o?h.highlight=h.axis===e&&o:h.highlight=h.axis===e&&t})}onHandleHover(e,t){this._startRot||this.parent&&this.parent.parent&&(this.parent.parent.onHover("rotate",e.axis,t),this.handleHighlight(e.axis,t,!1))}onHandleDragStart(e){if(!this.parent||!this.parent.parent)return;const t=this.parent.parent.object;t&&(this._startRot=t.rotation.clone(),this.handleHighlight(e.axis,!0,!0))}onHandleDrag(e,t){if(!this._startRot||!this.parent||!this.parent.parent||!("onChange"in this.parent.parent))return;const o=t.dragCurrent.clone().sub(this.parent.parent.position).normalize(),h=t.dragStart.clone().sub(this.parent.parent.position).normalize(),l=A.signedAngleTo(h,o,e.forwardVector),_=new r.Euler(this._startRot.x+e.forwardVector.x*l,this._startRot.y+e.forwardVector.y*l,this._startRot.z+e.forwardVector.z*l);this.parent.parent.onChange(void 0,_)}onHandleDragEnd(e){this._startRot=null,this.handleHighlight(e.axis,!1,!1)}}class E extends r.Object3D{constructor(e,t,o,h){super();s(this,"isHoverable",!0);s(this,"isDraggable",!0);s(this,"parent",null);s(this,"axis");s(this,"_color",new r.Color(16711935));s(this,"_colorHover");s(this,"_hovered");s(this,"_highlight");s(this,"_lineMaterial");s(this,"_colliderMesh");this.name="DIVEAxisHandle",this.axis=e,this._color.set(h),this._colorHover=this._color.clone().multiplyScalar(2),this._highlight=!1,this._hovered=!1;const l=new r.CylinderGeometry(.01,.01,t,13);this._lineMaterial=new r.MeshBasicMaterial({color:h,depthTest:!1,depthWrite:!1});const _=new r.Mesh(l,this._lineMaterial);_.layers.mask=d.UI_LAYER_MASK,_.renderOrder=1/0,_.rotateX(Math.PI/2),_.translateY(t/2),this.add(_);const c=new r.CylinderGeometry(.1,.1,t,3),p=new r.MeshBasicMaterial({color:16711935,transparent:!0,opacity:.15,depthTest:!1,depthWrite:!1});this._colliderMesh=new r.Mesh(c,p),this._colliderMesh.visible=!1,this._colliderMesh.layers.mask=d.UI_LAYER_MASK,this._colliderMesh.renderOrder=1/0,this._colliderMesh.rotateX(Math.PI/2),this._colliderMesh.translateY(t/2),this.add(this._colliderMesh),this.rotateX(o.y*-Math.PI/2),this.rotateY(o.x*Math.PI/2)}set debug(e){this._colliderMesh.visible=e}get highlight(){return this._highlight}set highlight(e){this._highlight=e,this._lineMaterial.color=this._highlight||this._hovered?this._colorHover:this._color}get forwardVector(){return new r.Vector3(0,0,1).applyQuaternion(this.quaternion).normalize()}get rightVector(){return new r.Vector3(1,0,0).applyQuaternion(this.quaternion).normalize()}get upVector(){return new r.Vector3(0,1,0).applyQuaternion(this.quaternion).normalize()}reset(){this._lineMaterial.color=this._color}onPointerEnter(){this._hovered=!0,this.parent&&this.parent.onHandleHover(this,!0)}onPointerLeave(){this._hovered=!1,this.parent&&this.parent.onHandleHover(this,!1)}onDragStart(){this.parent&&this.parent.onHandleDragStart(this)}onDrag(e){this.parent&&this.parent.onHandleDrag(this,e)}onDragEnd(){this.parent&&this.parent.onHandleDragEnd(this)}}class O extends r.Object3D{constructor(e){super();s(this,"_controller");s(this,"children");s(this,"_startPos");this.name="DIVETranslateGizmo",this.children=[],this._startPos=null,this._controller=e,this.add(new E("x",1,new r.Vector3(1,0,0),a.AxesColorRed)),this.add(new E("y",1,new r.Vector3(0,1,0),a.AxesColorGreen)),this.add(new E("z",1,new r.Vector3(0,0,1),a.AxesColorBlue))}set debug(e){this.children.forEach(t=>{t.debug=e})}reset(){this.children.forEach(e=>{e.reset()})}handleHighlight(e,t,o){this.children.forEach(h=>{o?h.highlight=h.axis===e&&o:h.highlight=h.axis===e&&t})}onHandleHover(e,t){this._startPos||this.parent&&this.parent.parent&&(this.parent.parent.onHover("translate",e.axis,t),this.handleHighlight(e.axis,t,!1))}onHandleDragStart(e){if(!this.parent||!this.parent.parent)return;const t=this.parent.parent.object;t&&(this._startPos=t.position.clone(),this.handleHighlight(e.axis,!0,!0))}onHandleDrag(e,t){if(!this._startPos||!this.parent||!this.parent.parent||!("onChange"in this.parent.parent))return;const o=t.dragDelta.clone().projectOnVector(e.forwardVector);this.parent.parent.onChange(this._startPos.clone().add(o))}onHandleDragEnd(e){this._startPos=null,this.handleHighlight(e.axis,!1,!1)}}class m extends r.Object3D{constructor(e,t,o,h,l=.05){super();s(this,"isHoverable",!0);s(this,"isDraggable",!0);s(this,"parent",null);s(this,"axis");s(this,"_color",new r.Color(16711935));s(this,"_colorHover");s(this,"_hovered");s(this,"_highlight");s(this,"_lineMaterial");s(this,"_colliderMesh");s(this,"_box");s(this,"_boxSize");this.name="DIVEScaleHandle",this.axis=e,this._color.set(h),this._colorHover=this._color.clone().multiplyScalar(2),this._hovered=!1,this._highlight=!1,this._boxSize=l;const _=new r.CylinderGeometry(.01,.01,t-l/2,13);this._lineMaterial=new r.MeshBasicMaterial({color:h,depthTest:!1,depthWrite:!1});const c=new r.Mesh(_,this._lineMaterial);c.layers.mask=d.UI_LAYER_MASK,c.renderOrder=1/0,c.rotateX(Math.PI/2),c.translateY(t/2-l/4),this.add(c),this._box=new r.Mesh(new r.BoxGeometry(l,l,l),this._lineMaterial),this._box.layers.mask=d.UI_LAYER_MASK,this._box.renderOrder=1/0,this._box.rotateX(Math.PI/2),this._box.translateY(t-l/2),this._box.rotateZ(o.x*Math.PI/2),this._box.rotateX(o.z*Math.PI/2),this.add(this._box);const p=new r.CylinderGeometry(.1,.1,t+l/2,3),g=new r.MeshBasicMaterial({color:16711935,transparent:!0,opacity:.15,depthTest:!1,depthWrite:!1});this._colliderMesh=new r.Mesh(p,g),this._colliderMesh.visible=!1,this._colliderMesh.layers.mask=d.UI_LAYER_MASK,this._colliderMesh.renderOrder=1/0,this._colliderMesh.rotateX(Math.PI/2),this._colliderMesh.translateY(t/2),this.add(this._colliderMesh),this.rotateX(o.y*-Math.PI/2),this.rotateY(o.x*Math.PI/2)}set debug(e){this._colliderMesh.visible=e}get highlight(){return this._highlight}set highlight(e){this._highlight=e,this._lineMaterial.color=this._highlight||this._hovered?this._colorHover:this._color}get forwardVector(){return new r.Vector3(0,0,1).applyQuaternion(this.quaternion).normalize()}get rightVector(){return new r.Vector3(1,0,0).applyQuaternion(this.quaternion).normalize()}get upVector(){return new r.Vector3(0,1,0).applyQuaternion(this.quaternion).normalize()}reset(){this._lineMaterial.color=this._color}update(e){this._box.scale.copy(new r.Vector3(1,1,1).sub(this.forwardVector).add(e.clone().multiply(this.forwardVector)))}onPointerEnter(){this._hovered=!0,this.parent&&this.parent.onHoverAxis(this,!0)}onPointerLeave(){this._hovered=!1,this.parent&&this.parent.onHoverAxis(this,!1)}onDragStart(){this.parent&&this.parent.onAxisDragStart(this)}onDrag(e){this.parent&&this.parent.onAxisDrag(this,e)}onDragEnd(){this.parent&&this.parent.onAxisDragEnd(this)}}class j extends r.Object3D{constructor(e){super();s(this,"isHoverable",!0);s(this,"children");s(this,"_controller");s(this,"_startScale");this.name="DIVEScaleGizmo",this.children=[],this._startScale=null,this._controller=e,this.add(new m("x",1,new r.Vector3(1,0,0),a.AxesColorRed)),this.add(new m("y",1,new r.Vector3(0,1,0),a.AxesColorGreen)),this.add(new m("z",1,new r.Vector3(0,0,1),a.AxesColorBlue))}set debug(e){this.children.forEach(t=>{t.debug=e})}reset(){this.children.forEach(e=>{e.reset()})}update(e){this.children.forEach(t=>{t.update(e)})}handleHighlight(e,t,o){this.children.forEach(h=>{o?h.highlight=h.axis===e&&o:h.highlight=h.axis===e&&t})}onHoverAxis(e,t){this._startScale||this.parent&&this.parent.parent&&(this.parent.parent.onHover("translate",e.axis,t),this.handleHighlight(e.axis,t,!1))}onAxisDragStart(e){if(!this.parent||!this.parent.parent)return;const t=this.parent.parent.object;t&&(this._startScale=t.scale.clone(),this.handleHighlight(e.axis,!0,!0))}onAxisDrag(e,t){if(!this._startScale||!this.parent||!this.parent.parent||!("onChange"in this.parent.parent))return;const o=t.dragDelta.clone().projectOnVector(e.forwardVector);this.parent.parent.onChange(void 0,void 0,this._startScale.clone().add(o))}onAxisDragEnd(e){this._startScale=null,this.handleHighlight(e.axis,!1,!1)}}class C extends r.Object3D{constructor(){super();s(this,"_meshX");s(this,"_meshY");s(this,"_meshZ");this.name="DIVEGizmoPlane";const e=new r.MeshBasicMaterial({transparent:!0,opacity:.15,depthTest:!1,depthWrite:!1,side:2}),t=new r.PlaneGeometry(100,100,2,2),o=e.clone();o.color.set(16711680),this._meshX=new r.Mesh(t,o),this._meshX.layers.mask=d.UI_LAYER_MASK,this._meshX.rotateY(Math.PI/2);const h=new r.PlaneGeometry(100,100,2,2),l=e.clone();l.color.set(65280),this._meshY=new r.Mesh(h,l),this._meshY.layers.mask=d.UI_LAYER_MASK,this._meshY.rotateX(-Math.PI/2);const _=new r.PlaneGeometry(100,100,2,2),c=e.clone();c.color.set(255),this._meshZ=new r.Mesh(_,c),this._meshZ.layers.mask=d.UI_LAYER_MASK}get XPlane(){return this._meshX}get YPlane(){return this._meshY}get ZPlane(){return this._meshZ}assemble(e,t){if(this.clear(),e==="translate"||e==="scale")switch(t){case"x":this.add(this._meshY),this.add(this._meshZ);break;case"y":this.add(this._meshX),this.add(this._meshZ);break;case"z":this.add(this._meshX),this.add(this._meshY);break}else if(e==="rotate")switch(t){case"x":this.add(this._meshX);break;case"y":this.add(this._meshY);break;case"z":this.add(this._meshZ);break}}}class Y extends r.Object3D{constructor(e){super();s(this,"_mode");s(this,"_gizmoNode");s(this,"_translateGizmo");s(this,"_rotateGizmo");s(this,"_scaleGizmo");s(this,"_gizmoPlane");s(this,"_object");this.name="DIVEGizmo",e.addEventListener("change",()=>{const t=e.getDistance()/2.5;this.scale.set(t,t,t)}),this._mode="translate",this._gizmoNode=new r.Object3D,this.add(this._gizmoNode),this._translateGizmo=new O(e),this._rotateGizmo=new L(e),this._scaleGizmo=new j(e),this._gizmoPlane=new C,this._gizmoPlane.visible=!1,this._object=null}get mode(){return this._mode}set mode(e){this._mode=e,this.assemble()}set debug(e){this._translateGizmo.debug=e,this._rotateGizmo.debug=e,this._scaleGizmo.debug=e}get gizmoNode(){return this._gizmoNode}get gizmoPlane(){return this._gizmoPlane}get object(){return this._object}attach(e){return this._object=e,this.assemble(),this}detach(){return this._object=null,this.assemble(),this}onHover(e,t,o){o&&this._gizmoPlane.assemble(e,t)}onChange(e,t,o){this.object!==null&&(e&&(this.position.copy(e),this.object.position.copy(e)),t&&this.object.rotation.copy(t),o&&(this.object.scale.copy(o),this._scaleGizmo.update(o)))}assemble(){this._gizmoNode.clear(),this._gizmoPlane.clear(),this._translateGizmo.reset(),this._rotateGizmo.reset(),this._scaleGizmo.reset(),this.object!==null&&(this._mode==="translate"&&this._gizmoNode.add(this._translateGizmo),this._mode==="rotate"&&this._gizmoNode.add(this._rotateGizmo),this._mode==="scale"&&this._gizmoNode.add(this._scaleGizmo),this.add(this._gizmoPlane))}}class T{constructor(){s(this,"isMovable",!0)}}class N{constructor(){s(this,"isSelectable",!0)}}const D=(i,n)=>{if(Object.keys(i).length===0&&Object.keys(n).length===0)return{};if(typeof i!="object"||typeof n!="object")return n;let e={};return Object.keys(n).forEach(t=>{if(!Object.keys(i).includes(t)){e={...e,[t]:n[t]};return}if(Array.isArray(n[t])){if(!Array.isArray(i[t])){e={...e,[t]:n[t]};return}const o=i[t],h=n[t];if(o.length===0&&h.length===0){e={...e};return}if(o.length!==h.length){e={...e,[t]:n[t]};return}const l=[];if(h.forEach((_,c)=>{const p=D(o[c],h[c]);Object.keys(p).length&&l.push(h[c])}),Object.keys(l).length){e={...e,[t]:l};return}return}if(typeof n[t]=="object"){if(typeof i[t]!="object"){e={...e,[t]:n[t]};return}const o=D(i[t],n[t]);if(Object.keys(o).length){e={...e,[t]:o};return}}i[t]!==n[t]&&(e={...e,[t]:n[t]})}),e};function U(i,n){return n.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(o=>{if(o==="constructor")return;const h=Object.getOwnPropertyDescriptor(e.prototype,o);Object.defineProperty(i.prototype,o,h)});const t=new e;Object.getOwnPropertyNames(t).forEach(o=>{const h=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(i.prototype,o,h)})}),i}function K(i){return i.entityType==="group"}function X(i){return i.entityType==="light"}function F(i){return i.entityType==="primitive"}exports.AxesColorBlue=a.AxesColorBlue;exports.AxesColorBlueLetter=a.AxesColorBlueLetter;exports.AxesColorGreen=a.AxesColorGreen;exports.AxesColorGreenLetter=a.AxesColorGreenLetter;exports.AxesColorRed=a.AxesColorRed;exports.AxesColorRedLetter=a.AxesColorRedLetter;exports.DIVE=a.DIVE;exports.DIVEAmbientLight=a.DIVEAmbientLight;exports.DIVEClock=a.DIVEClock;exports.DIVEDefaultSettings=a.DIVEDefaultSettings;exports.DIVEEngine=a.DIVEEngine;exports.DIVEFloor=a.DIVEFloor;exports.DIVEGrid=a.DIVEGrid;exports.DIVEGroup=a.DIVEGroup;exports.DIVEModel=a.DIVEModel;exports.DIVENode=a.DIVENode;exports.DIVEPointLight=a.DIVEPointLight;exports.DIVEPrimitive=a.DIVEPrimitive;exports.DIVERenderPipeline=a.DIVERenderPipeline;exports.DIVERenderPipelineDefaultSettings=a.DIVERenderPipelineDefaultSettings;exports.DIVEResizeManager=a.DIVEResizeManager;exports.DIVERoot=a.DIVERoot;exports.DIVEScene=a.DIVEScene;exports.DIVESceneLight=a.DIVESceneLight;exports.EngineDefaultSettings=a.EngineDefaultSettings;exports.FILE_TYPES=a.FILE_TYPES;exports.GRID_CENTER_LINE_COLOR=a.GRID_CENTER_LINE_COLOR;exports.GRID_SIDE_LINE_COLOR=a.GRID_SIDE_LINE_COLOR;exports.SUPPORTED_FILE_TYPES=a.SUPPORTED_FILE_TYPES;exports.findSceneRecursive=a.findSceneRecursive;exports.COORDINATE_LAYER_MASK=d.COORDINATE_LAYER_MASK;exports.DEFAULT_LAYER_MASK=d.DEFAULT_LAYER_MASK;exports.DIVEPerspectiveCamera=d.DIVEPerspectiveCamera;exports.DIVEPerspectiveCameraDefaultSettings=d.DIVEPerspectiveCameraDefaultSettings;exports.HELPER_LAYER_MASK=d.HELPER_LAYER_MASK;exports.PRODUCT_LAYER_MASK=d.PRODUCT_LAYER_MASK;exports.UI_LAYER_MASK=d.UI_LAYER_MASK;exports.NetworkError=M.NetworkError;exports.getFileTypeFromUri=M.getFileTypeFromUri;exports.isFileTypeSupported=M.isFileTypeSupported;exports.findInterface=I.findInterface;exports.implementsInterface=I.implementsInterface;exports.FileTypeError=V.FileTypeError;exports.ParseError=V.ParseError;exports.isModelSchema=b.isModelSchema;exports.isPovSchema=b.isPovSchema;exports.DIVEGizmo=Y;exports.DIVEMath=A;exports.DIVEMovable=T;exports.DIVESelectable=N;exports.applyMixins=U;exports.getObjectDelta=D;exports.isGroupSchema=K;exports.isLightSchema=X;exports.isPrimitiveSchema=F;