a3js 0.0.0 → 0.0.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/dist/a3js.cjs.js +1 -1
- package/dist/a3js.es.js +516 -4
- package/package.json +3 -3
- package/dist/vite.svg +0 -1
package/dist/a3js.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class t{txt;constructor(){this.txt="abcdefg"}}exports.A3=t;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("three");function D(i){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const e in i)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>i[e]})}}return t.default=i,Object.freeze(t)}const p=D(o),y={type:"change"},f={type:"start"},E={type:"end"},m=new o.Ray,g=new o.Plane,M=Math.cos(70*o.MathUtils.DEG2RAD),h=new o.Vector3,l=2*Math.PI,n={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},_=1e-6;class S extends o.Controls{constructor(t,e=null){super(t,e),this.state=n.NONE,this.target=new o.Vector3,this.cursor=new o.Vector3,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:o.MOUSE.ROTATE,MIDDLE:o.MOUSE.DOLLY,RIGHT:o.MOUSE.PAN},this.touches={ONE:o.TOUCH.ROTATE,TWO:o.TOUCH.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new o.Vector3,this._lastQuaternion=new o.Quaternion,this._lastTargetPosition=new o.Vector3,this._quat=new o.Quaternion().setFromUnitVectors(t.up,new o.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new o.Spherical,this._sphericalDelta=new o.Spherical,this._scale=1,this._panOffset=new o.Vector3,this._rotateStart=new o.Vector2,this._rotateEnd=new o.Vector2,this._rotateDelta=new o.Vector2,this._panStart=new o.Vector2,this._panEnd=new o.Vector2,this._panDelta=new o.Vector2,this._dollyStart=new o.Vector2,this._dollyEnd=new o.Vector2,this._dollyDelta=new o.Vector2,this._dollyDirection=new o.Vector3,this._mouse=new o.Vector2,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=O.bind(this),this._onPointerDown=w.bind(this),this._onPointerUp=A.bind(this),this._onContextMenu=N.bind(this),this._onMouseWheel=j.bind(this),this._onKeyDown=C.bind(this),this._onTouchStart=k.bind(this),this._onTouchMove=x.bind(this),this._onMouseDown=R.bind(this),this._onMouseMove=L.bind(this),this._interceptControlDown=U.bind(this),this._interceptControlUp=I.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}connect(t){super.connect(t),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(t){t.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=t}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(y),this.update(),this.state=n.NONE}update(t=null){const e=this.object.position;h.copy(e).sub(this.target),h.applyQuaternion(this._quat),this._spherical.setFromVector3(h),this.autoRotate&&this.state===n.NONE&&this._rotateLeft(this._getAutoRotationAngle(t)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let s=this.minAzimuthAngle,a=this.maxAzimuthAngle;isFinite(s)&&isFinite(a)&&(s<-Math.PI?s+=l:s>Math.PI&&(s-=l),a<-Math.PI?a+=l:a>Math.PI&&(a-=l),s<=a?this._spherical.theta=Math.max(s,Math.min(a,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(s+a)/2?Math.max(s,this._spherical.theta):Math.min(a,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let r=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const c=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),r=c!=this._spherical.radius}if(h.setFromSpherical(this._spherical),h.applyQuaternion(this._quatInverse),e.copy(this.target).add(h),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let c=null;if(this.object.isPerspectiveCamera){const d=h.length();c=this._clampDistance(d*this._scale);const u=d-c;this.object.position.addScaledVector(this._dollyDirection,u),this.object.updateMatrixWorld(),r=!!u}else if(this.object.isOrthographicCamera){const d=new o.Vector3(this._mouse.x,this._mouse.y,0);d.unproject(this.object);const u=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),r=u!==this.object.zoom;const b=new o.Vector3(this._mouse.x,this._mouse.y,0);b.unproject(this.object),this.object.position.sub(b).add(d),this.object.updateMatrixWorld(),c=h.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;c!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(c).add(this.object.position):(m.origin.copy(this.object.position),m.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(m.direction))<M?this.object.lookAt(this.target):(g.setFromNormalAndCoplanarPoint(this.object.up,this.target),m.intersectPlane(g,this.target))))}else if(this.object.isOrthographicCamera){const c=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),c!==this.object.zoom&&(this.object.updateProjectionMatrix(),r=!0)}return this._scale=1,this._performCursorZoom=!1,r||this._lastPosition.distanceToSquared(this.object.position)>_||8*(1-this._lastQuaternion.dot(this.object.quaternion))>_||this._lastTargetPosition.distanceToSquared(this.target)>_?(this.dispatchEvent(y),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(t){return t!==null?l/60*this.autoRotateSpeed*t:l/60/60*this.autoRotateSpeed}_getZoomScale(t){const e=Math.abs(t*.01);return Math.pow(.95,this.zoomSpeed*e)}_rotateLeft(t){this._sphericalDelta.theta-=t}_rotateUp(t){this._sphericalDelta.phi-=t}_panLeft(t,e){h.setFromMatrixColumn(e,0),h.multiplyScalar(-t),this._panOffset.add(h)}_panUp(t,e){this.screenSpacePanning===!0?h.setFromMatrixColumn(e,1):(h.setFromMatrixColumn(e,0),h.crossVectors(this.object.up,h)),h.multiplyScalar(t),this._panOffset.add(h)}_pan(t,e){const s=this.domElement;if(this.object.isPerspectiveCamera){const a=this.object.position;h.copy(a).sub(this.target);let r=h.length();r*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*t*r/s.clientHeight,this.object.matrix),this._panUp(2*e*r/s.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(t*(this.object.right-this.object.left)/this.object.zoom/s.clientWidth,this.object.matrix),this._panUp(e*(this.object.top-this.object.bottom)/this.object.zoom/s.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(t,e){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const s=this.domElement.getBoundingClientRect(),a=t-s.left,r=e-s.top,c=s.width,d=s.height;this._mouse.x=a/c*2-1,this._mouse.y=-(r/d)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(t){return Math.max(this.minDistance,Math.min(this.maxDistance,t))}_handleMouseDownRotate(t){this._rotateStart.set(t.clientX,t.clientY)}_handleMouseDownDolly(t){this._updateZoomParameters(t.clientX,t.clientX),this._dollyStart.set(t.clientX,t.clientY)}_handleMouseDownPan(t){this._panStart.set(t.clientX,t.clientY)}_handleMouseMoveRotate(t){this._rotateEnd.set(t.clientX,t.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(l*this._rotateDelta.x/e.clientHeight),this._rotateUp(l*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(t){this._dollyEnd.set(t.clientX,t.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(t){this._panEnd.set(t.clientX,t.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(t){this._updateZoomParameters(t.clientX,t.clientY),t.deltaY<0?this._dollyIn(this._getZoomScale(t.deltaY)):t.deltaY>0&&this._dollyOut(this._getZoomScale(t.deltaY)),this.update()}_handleKeyDown(t){let e=!1;switch(t.code){case this.keys.UP:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(l*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),e=!0;break;case this.keys.BOTTOM:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(-l*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),e=!0;break;case this.keys.LEFT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(l*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),e=!0;break;case this.keys.RIGHT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(-l*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),e=!0;break}e&&(t.preventDefault(),this.update())}_handleTouchStartRotate(t){if(this._pointers.length===1)this._rotateStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),a=.5*(t.pageY+e.y);this._rotateStart.set(s,a)}}_handleTouchStartPan(t){if(this._pointers.length===1)this._panStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),a=.5*(t.pageY+e.y);this._panStart.set(s,a)}}_handleTouchStartDolly(t){const e=this._getSecondPointerPosition(t),s=t.pageX-e.x,a=t.pageY-e.y,r=Math.sqrt(s*s+a*a);this._dollyStart.set(0,r)}_handleTouchStartDollyPan(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enablePan&&this._handleTouchStartPan(t)}_handleTouchStartDollyRotate(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enableRotate&&this._handleTouchStartRotate(t)}_handleTouchMoveRotate(t){if(this._pointers.length==1)this._rotateEnd.set(t.pageX,t.pageY);else{const s=this._getSecondPointerPosition(t),a=.5*(t.pageX+s.x),r=.5*(t.pageY+s.y);this._rotateEnd.set(a,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(l*this._rotateDelta.x/e.clientHeight),this._rotateUp(l*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(t){if(this._pointers.length===1)this._panEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),a=.5*(t.pageY+e.y);this._panEnd.set(s,a)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(t){const e=this._getSecondPointerPosition(t),s=t.pageX-e.x,a=t.pageY-e.y,r=Math.sqrt(s*s+a*a);this._dollyEnd.set(0,r),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const c=(t.pageX+e.x)*.5,d=(t.pageY+e.y)*.5;this._updateZoomParameters(c,d)}_handleTouchMoveDollyPan(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enablePan&&this._handleTouchMovePan(t)}_handleTouchMoveDollyRotate(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enableRotate&&this._handleTouchMoveRotate(t)}_addPointer(t){this._pointers.push(t.pointerId)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId){this._pointers.splice(e,1);return}}_isTrackingPointer(t){for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId)return!0;return!1}_trackPointer(t){let e=this._pointerPositions[t.pointerId];e===void 0&&(e=new o.Vector2,this._pointerPositions[t.pointerId]=e),e.set(t.pageX,t.pageY)}_getSecondPointerPosition(t){const e=t.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[e]}_customWheelEvent(t){const e=t.deltaMode,s={clientX:t.clientX,clientY:t.clientY,deltaY:t.deltaY};switch(e){case 1:s.deltaY*=16;break;case 2:s.deltaY*=100;break}return t.ctrlKey&&!this._controlActive&&(s.deltaY*=10),s}}function w(i){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(i.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(i)&&(this._addPointer(i),i.pointerType==="touch"?this._onTouchStart(i):this._onMouseDown(i)))}function O(i){this.enabled!==!1&&(i.pointerType==="touch"?this._onTouchMove(i):this._onMouseMove(i))}function A(i){switch(this._removePointer(i),this._pointers.length){case 0:this.domElement.releasePointerCapture(i.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(E),this.state=n.NONE;break;case 1:const t=this._pointers[0],e=this._pointerPositions[t];this._onTouchStart({pointerId:t,pageX:e.x,pageY:e.y});break}}function R(i){let t;switch(i.button){case 0:t=this.mouseButtons.LEFT;break;case 1:t=this.mouseButtons.MIDDLE;break;case 2:t=this.mouseButtons.RIGHT;break;default:t=-1}switch(t){case o.MOUSE.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(i),this.state=n.DOLLY;break;case o.MOUSE.ROTATE:if(i.ctrlKey||i.metaKey||i.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(i),this.state=n.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(i),this.state=n.ROTATE}break;case o.MOUSE.PAN:if(i.ctrlKey||i.metaKey||i.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(i),this.state=n.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(i),this.state=n.PAN}break;default:this.state=n.NONE}this.state!==n.NONE&&this.dispatchEvent(f)}function L(i){switch(this.state){case n.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(i);break;case n.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(i);break;case n.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(i);break}}function j(i){this.enabled===!1||this.enableZoom===!1||this.state!==n.NONE||(i.preventDefault(),this.dispatchEvent(f),this._handleMouseWheel(this._customWheelEvent(i)),this.dispatchEvent(E))}function C(i){this.enabled!==!1&&this._handleKeyDown(i)}function k(i){switch(this._trackPointer(i),this._pointers.length){case 1:switch(this.touches.ONE){case o.TOUCH.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(i),this.state=n.TOUCH_ROTATE;break;case o.TOUCH.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(i),this.state=n.TOUCH_PAN;break;default:this.state=n.NONE}break;case 2:switch(this.touches.TWO){case o.TOUCH.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(i),this.state=n.TOUCH_DOLLY_PAN;break;case o.TOUCH.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(i),this.state=n.TOUCH_DOLLY_ROTATE;break;default:this.state=n.NONE}break;default:this.state=n.NONE}this.state!==n.NONE&&this.dispatchEvent(f)}function x(i){switch(this._trackPointer(i),this.state){case n.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(i),this.update();break;case n.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(i),this.update();break;case n.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(i),this.update();break;case n.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(i),this.update();break;default:this.state=n.NONE}}function N(i){this.enabled!==!1&&i.preventDefault()}function U(i){i.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function I(i){i.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}class P{obj;constructor(t){this.obj=t}}class Y{scene;constructor(){this.scene=new p.Scene}add(t){this.scene.add(t.obj)}}class T extends HTMLElement{ro;renderer;scene=null;camera;controls;constructor(){super(),this.renderer=new p.WebGLRenderer,this.camera=new p.PerspectiveCamera(75,300/150,.1,1e3),this.camera.position.set(0,0,3),this.controls=new S(this.camera,this.renderer.domElement),this.controls.target.set(0,0,0),this.style="display: block;",this.renderer.domElement.style="display: block; width: 100%; height: 100%; margin: 0; padding: 0;",this.appendChild(this.renderer.domElement)}connectedCallback(){this.ro=new ResizeObserver(()=>{const{width:t,height:e}=this.renderer.domElement.getBoundingClientRect();this.camera.aspect=t/e,this.camera.updateProjectionMatrix(),this.renderer.setSize(t,e),console.log("GAHA: resize")}),this.ro.observe(this)}disconnectedCallback(){this.ro?.disconnect()}hemiLight=new p.AmbientLight(16777215,.6);dirLight=new p.DirectionalLight(16777215,1);setScene(t){this.scene=t,this.scene.scene.add(this.camera),this.scene.scene.add(this.hemiLight),this.dirLight.position.set(5,10,4),this.scene.scene.add(this.dirLight),this.animationFrameId=requestAnimationFrame(this.renderingLoop)}removeScene(){this.scene&&(this.scene.scene.remove(this.camera),this.scene.scene.remove(this.hemiLight),this.scene.scene.remove(this.dirLight),this.scene=null,cancelAnimationFrame(this.animationFrameId))}animationFrameId=-1;previousTime=-1;renderingLoop=t=>{const e=this.previousTime===-1?0:t-this.previousTime;this.controls.update(e),this.scene&&this.renderer.render(this.scene.scene,this.camera),this.animationFrameId=requestAnimationFrame(this.renderingLoop)}}customElements.define("a3-canvas",T);class z extends P{constructor(){const t=new p.BoxGeometry,e=new p.MeshStandardMaterial({color:65280}),s=new p.Mesh(t,e);super(s)}}function v(i){return 2*i}exports.A3Canvas=T;exports.A3Object=P;exports.A3Scene=Y;exports.A3Test=z;exports.times2=v;
|
package/dist/a3js.es.js
CHANGED
|
@@ -1,9 +1,521 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as m from "three";
|
|
2
|
+
import { Controls as S, Vector3 as d, MOUSE as u, TOUCH as _, Quaternion as P, Spherical as D, Vector2 as c, Ray as O, Plane as L, MathUtils as R } from "three";
|
|
3
|
+
const T = { type: "change" }, g = { type: "start" }, M = { type: "end" }, y = new O(), w = new L(), A = Math.cos(70 * R.DEG2RAD), a = new d(), r = 2 * Math.PI, o = {
|
|
4
|
+
NONE: -1,
|
|
5
|
+
ROTATE: 0,
|
|
6
|
+
DOLLY: 1,
|
|
7
|
+
PAN: 2,
|
|
8
|
+
TOUCH_ROTATE: 3,
|
|
9
|
+
TOUCH_PAN: 4,
|
|
10
|
+
TOUCH_DOLLY_PAN: 5,
|
|
11
|
+
TOUCH_DOLLY_ROTATE: 6
|
|
12
|
+
}, b = 1e-6;
|
|
13
|
+
class j extends S {
|
|
14
|
+
/**
|
|
15
|
+
* Constructs a new controls instance.
|
|
16
|
+
*
|
|
17
|
+
* @param {Object3D} object - The object that is managed by the controls.
|
|
18
|
+
* @param {?HTMLElement} domElement - The HTML element used for event listeners.
|
|
19
|
+
*/
|
|
20
|
+
constructor(t, e = null) {
|
|
21
|
+
super(t, e), this.state = o.NONE, this.target = new d(), this.cursor = new d(), this.minDistance = 0, this.maxDistance = 1 / 0, this.minZoom = 0, this.maxZoom = 1 / 0, this.minTargetRadius = 0, this.maxTargetRadius = 1 / 0, this.minPolarAngle = 0, this.maxPolarAngle = Math.PI, this.minAzimuthAngle = -1 / 0, this.maxAzimuthAngle = 1 / 0, this.enableDamping = !1, this.dampingFactor = 0.05, this.enableZoom = !0, this.zoomSpeed = 1, this.enableRotate = !0, this.rotateSpeed = 1, this.keyRotateSpeed = 1, this.enablePan = !0, this.panSpeed = 1, this.screenSpacePanning = !0, this.keyPanSpeed = 7, this.zoomToCursor = !1, this.autoRotate = !1, this.autoRotateSpeed = 2, this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" }, this.mouseButtons = { LEFT: u.ROTATE, MIDDLE: u.DOLLY, RIGHT: u.PAN }, this.touches = { ONE: _.ROTATE, TWO: _.DOLLY_PAN }, this.target0 = this.target.clone(), this.position0 = this.object.position.clone(), this.zoom0 = this.object.zoom, this._domElementKeyEvents = null, this._lastPosition = new d(), this._lastQuaternion = new P(), this._lastTargetPosition = new d(), this._quat = new P().setFromUnitVectors(t.up, new d(0, 1, 0)), this._quatInverse = this._quat.clone().invert(), this._spherical = new D(), this._sphericalDelta = new D(), this._scale = 1, this._panOffset = new d(), this._rotateStart = new c(), this._rotateEnd = new c(), this._rotateDelta = new c(), this._panStart = new c(), this._panEnd = new c(), this._panDelta = new c(), this._dollyStart = new c(), this._dollyEnd = new c(), this._dollyDelta = new c(), this._dollyDirection = new d(), this._mouse = new c(), this._performCursorZoom = !1, this._pointers = [], this._pointerPositions = {}, this._controlActive = !1, this._onPointerMove = k.bind(this), this._onPointerDown = C.bind(this), this._onPointerUp = x.bind(this), this._onContextMenu = v.bind(this), this._onMouseWheel = Y.bind(this), this._onKeyDown = U.bind(this), this._onTouchStart = z.bind(this), this._onTouchMove = Z.bind(this), this._onMouseDown = N.bind(this), this._onMouseMove = I.bind(this), this._interceptControlDown = K.bind(this), this._interceptControlUp = H.bind(this), this.domElement !== null && this.connect(this.domElement), this.update();
|
|
22
|
+
}
|
|
23
|
+
connect(t) {
|
|
24
|
+
super.connect(t), this.domElement.addEventListener("pointerdown", this._onPointerDown), this.domElement.addEventListener("pointercancel", this._onPointerUp), this.domElement.addEventListener("contextmenu", this._onContextMenu), this.domElement.addEventListener("wheel", this._onMouseWheel, { passive: !1 }), this.domElement.getRootNode().addEventListener("keydown", this._interceptControlDown, { passive: !0, capture: !0 }), this.domElement.style.touchAction = "none";
|
|
25
|
+
}
|
|
26
|
+
disconnect() {
|
|
27
|
+
this.domElement.removeEventListener("pointerdown", this._onPointerDown), this.domElement.ownerDocument.removeEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.removeEventListener("pointerup", this._onPointerUp), this.domElement.removeEventListener("pointercancel", this._onPointerUp), this.domElement.removeEventListener("wheel", this._onMouseWheel), this.domElement.removeEventListener("contextmenu", this._onContextMenu), this.stopListenToKeyEvents(), this.domElement.getRootNode().removeEventListener("keydown", this._interceptControlDown, { capture: !0 }), this.domElement.style.touchAction = "auto";
|
|
28
|
+
}
|
|
29
|
+
dispose() {
|
|
30
|
+
this.disconnect();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get the current vertical rotation, in radians.
|
|
34
|
+
*
|
|
35
|
+
* @return {number} The current vertical rotation, in radians.
|
|
36
|
+
*/
|
|
37
|
+
getPolarAngle() {
|
|
38
|
+
return this._spherical.phi;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get the current horizontal rotation, in radians.
|
|
42
|
+
*
|
|
43
|
+
* @return {number} The current horizontal rotation, in radians.
|
|
44
|
+
*/
|
|
45
|
+
getAzimuthalAngle() {
|
|
46
|
+
return this._spherical.theta;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns the distance from the camera to the target.
|
|
50
|
+
*
|
|
51
|
+
* @return {number} The distance from the camera to the target.
|
|
52
|
+
*/
|
|
53
|
+
getDistance() {
|
|
54
|
+
return this.object.position.distanceTo(this.target);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Adds key event listeners to the given DOM element.
|
|
58
|
+
* `window` is a recommended argument for using this method.
|
|
59
|
+
*
|
|
60
|
+
* @param {HTMLElement} domElement - The DOM element
|
|
61
|
+
*/
|
|
62
|
+
listenToKeyEvents(t) {
|
|
63
|
+
t.addEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = t;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Removes the key event listener previously defined with `listenToKeyEvents()`.
|
|
67
|
+
*/
|
|
68
|
+
stopListenToKeyEvents() {
|
|
69
|
+
this._domElementKeyEvents !== null && (this._domElementKeyEvents.removeEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = null);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Save the current state of the controls. This can later be recovered with `reset()`.
|
|
73
|
+
*/
|
|
74
|
+
saveState() {
|
|
75
|
+
this.target0.copy(this.target), this.position0.copy(this.object.position), this.zoom0 = this.object.zoom;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Reset the controls to their state from either the last time the `saveState()`
|
|
79
|
+
* was called, or the initial state.
|
|
80
|
+
*/
|
|
81
|
+
reset() {
|
|
82
|
+
this.target.copy(this.target0), this.object.position.copy(this.position0), this.object.zoom = this.zoom0, this.object.updateProjectionMatrix(), this.dispatchEvent(T), this.update(), this.state = o.NONE;
|
|
83
|
+
}
|
|
84
|
+
update(t = null) {
|
|
85
|
+
const e = this.object.position;
|
|
86
|
+
a.copy(e).sub(this.target), a.applyQuaternion(this._quat), this._spherical.setFromVector3(a), this.autoRotate && this.state === o.NONE && this._rotateLeft(this._getAutoRotationAngle(t)), this.enableDamping ? (this._spherical.theta += this._sphericalDelta.theta * this.dampingFactor, this._spherical.phi += this._sphericalDelta.phi * this.dampingFactor) : (this._spherical.theta += this._sphericalDelta.theta, this._spherical.phi += this._sphericalDelta.phi);
|
|
87
|
+
let s = this.minAzimuthAngle, n = this.maxAzimuthAngle;
|
|
88
|
+
isFinite(s) && isFinite(n) && (s < -Math.PI ? s += r : s > Math.PI && (s -= r), n < -Math.PI ? n += r : n > Math.PI && (n -= r), s <= n ? this._spherical.theta = Math.max(s, Math.min(n, this._spherical.theta)) : this._spherical.theta = this._spherical.theta > (s + n) / 2 ? Math.max(s, this._spherical.theta) : Math.min(n, this._spherical.theta)), this._spherical.phi = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, this._spherical.phi)), this._spherical.makeSafe(), this.enableDamping === !0 ? this.target.addScaledVector(this._panOffset, this.dampingFactor) : this.target.add(this._panOffset), this.target.sub(this.cursor), this.target.clampLength(this.minTargetRadius, this.maxTargetRadius), this.target.add(this.cursor);
|
|
89
|
+
let h = !1;
|
|
90
|
+
if (this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera)
|
|
91
|
+
this._spherical.radius = this._clampDistance(this._spherical.radius);
|
|
92
|
+
else {
|
|
93
|
+
const l = this._spherical.radius;
|
|
94
|
+
this._spherical.radius = this._clampDistance(this._spherical.radius * this._scale), h = l != this._spherical.radius;
|
|
95
|
+
}
|
|
96
|
+
if (a.setFromSpherical(this._spherical), a.applyQuaternion(this._quatInverse), e.copy(this.target).add(a), this.object.lookAt(this.target), this.enableDamping === !0 ? (this._sphericalDelta.theta *= 1 - this.dampingFactor, this._sphericalDelta.phi *= 1 - this.dampingFactor, this._panOffset.multiplyScalar(1 - this.dampingFactor)) : (this._sphericalDelta.set(0, 0, 0), this._panOffset.set(0, 0, 0)), this.zoomToCursor && this._performCursorZoom) {
|
|
97
|
+
let l = null;
|
|
98
|
+
if (this.object.isPerspectiveCamera) {
|
|
99
|
+
const p = a.length();
|
|
100
|
+
l = this._clampDistance(p * this._scale);
|
|
101
|
+
const f = p - l;
|
|
102
|
+
this.object.position.addScaledVector(this._dollyDirection, f), this.object.updateMatrixWorld(), h = !!f;
|
|
103
|
+
} else if (this.object.isOrthographicCamera) {
|
|
104
|
+
const p = new d(this._mouse.x, this._mouse.y, 0);
|
|
105
|
+
p.unproject(this.object);
|
|
106
|
+
const f = this.object.zoom;
|
|
107
|
+
this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), this.object.updateProjectionMatrix(), h = f !== this.object.zoom;
|
|
108
|
+
const E = new d(this._mouse.x, this._mouse.y, 0);
|
|
109
|
+
E.unproject(this.object), this.object.position.sub(E).add(p), this.object.updateMatrixWorld(), l = a.length();
|
|
110
|
+
} else
|
|
111
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."), this.zoomToCursor = !1;
|
|
112
|
+
l !== null && (this.screenSpacePanning ? this.target.set(0, 0, -1).transformDirection(this.object.matrix).multiplyScalar(l).add(this.object.position) : (y.origin.copy(this.object.position), y.direction.set(0, 0, -1).transformDirection(this.object.matrix), Math.abs(this.object.up.dot(y.direction)) < A ? this.object.lookAt(this.target) : (w.setFromNormalAndCoplanarPoint(this.object.up, this.target), y.intersectPlane(w, this.target))));
|
|
113
|
+
} else if (this.object.isOrthographicCamera) {
|
|
114
|
+
const l = this.object.zoom;
|
|
115
|
+
this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), l !== this.object.zoom && (this.object.updateProjectionMatrix(), h = !0);
|
|
116
|
+
}
|
|
117
|
+
return this._scale = 1, this._performCursorZoom = !1, h || this._lastPosition.distanceToSquared(this.object.position) > b || 8 * (1 - this._lastQuaternion.dot(this.object.quaternion)) > b || this._lastTargetPosition.distanceToSquared(this.target) > b ? (this.dispatchEvent(T), this._lastPosition.copy(this.object.position), this._lastQuaternion.copy(this.object.quaternion), this._lastTargetPosition.copy(this.target), !0) : !1;
|
|
118
|
+
}
|
|
119
|
+
_getAutoRotationAngle(t) {
|
|
120
|
+
return t !== null ? r / 60 * this.autoRotateSpeed * t : r / 60 / 60 * this.autoRotateSpeed;
|
|
121
|
+
}
|
|
122
|
+
_getZoomScale(t) {
|
|
123
|
+
const e = Math.abs(t * 0.01);
|
|
124
|
+
return Math.pow(0.95, this.zoomSpeed * e);
|
|
125
|
+
}
|
|
126
|
+
_rotateLeft(t) {
|
|
127
|
+
this._sphericalDelta.theta -= t;
|
|
128
|
+
}
|
|
129
|
+
_rotateUp(t) {
|
|
130
|
+
this._sphericalDelta.phi -= t;
|
|
131
|
+
}
|
|
132
|
+
_panLeft(t, e) {
|
|
133
|
+
a.setFromMatrixColumn(e, 0), a.multiplyScalar(-t), this._panOffset.add(a);
|
|
134
|
+
}
|
|
135
|
+
_panUp(t, e) {
|
|
136
|
+
this.screenSpacePanning === !0 ? a.setFromMatrixColumn(e, 1) : (a.setFromMatrixColumn(e, 0), a.crossVectors(this.object.up, a)), a.multiplyScalar(t), this._panOffset.add(a);
|
|
137
|
+
}
|
|
138
|
+
// deltaX and deltaY are in pixels; right and down are positive
|
|
139
|
+
_pan(t, e) {
|
|
140
|
+
const s = this.domElement;
|
|
141
|
+
if (this.object.isPerspectiveCamera) {
|
|
142
|
+
const n = this.object.position;
|
|
143
|
+
a.copy(n).sub(this.target);
|
|
144
|
+
let h = a.length();
|
|
145
|
+
h *= Math.tan(this.object.fov / 2 * Math.PI / 180), this._panLeft(2 * t * h / s.clientHeight, this.object.matrix), this._panUp(2 * e * h / s.clientHeight, this.object.matrix);
|
|
146
|
+
} else this.object.isOrthographicCamera ? (this._panLeft(t * (this.object.right - this.object.left) / this.object.zoom / s.clientWidth, this.object.matrix), this._panUp(e * (this.object.top - this.object.bottom) / this.object.zoom / s.clientHeight, this.object.matrix)) : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."), this.enablePan = !1);
|
|
147
|
+
}
|
|
148
|
+
_dollyOut(t) {
|
|
149
|
+
this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale /= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
|
|
150
|
+
}
|
|
151
|
+
_dollyIn(t) {
|
|
152
|
+
this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale *= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
|
|
153
|
+
}
|
|
154
|
+
_updateZoomParameters(t, e) {
|
|
155
|
+
if (!this.zoomToCursor)
|
|
156
|
+
return;
|
|
157
|
+
this._performCursorZoom = !0;
|
|
158
|
+
const s = this.domElement.getBoundingClientRect(), n = t - s.left, h = e - s.top, l = s.width, p = s.height;
|
|
159
|
+
this._mouse.x = n / l * 2 - 1, this._mouse.y = -(h / p) * 2 + 1, this._dollyDirection.set(this._mouse.x, this._mouse.y, 1).unproject(this.object).sub(this.object.position).normalize();
|
|
160
|
+
}
|
|
161
|
+
_clampDistance(t) {
|
|
162
|
+
return Math.max(this.minDistance, Math.min(this.maxDistance, t));
|
|
163
|
+
}
|
|
164
|
+
//
|
|
165
|
+
// event callbacks - update the object state
|
|
166
|
+
//
|
|
167
|
+
_handleMouseDownRotate(t) {
|
|
168
|
+
this._rotateStart.set(t.clientX, t.clientY);
|
|
169
|
+
}
|
|
170
|
+
_handleMouseDownDolly(t) {
|
|
171
|
+
this._updateZoomParameters(t.clientX, t.clientX), this._dollyStart.set(t.clientX, t.clientY);
|
|
172
|
+
}
|
|
173
|
+
_handleMouseDownPan(t) {
|
|
174
|
+
this._panStart.set(t.clientX, t.clientY);
|
|
175
|
+
}
|
|
176
|
+
_handleMouseMoveRotate(t) {
|
|
177
|
+
this._rotateEnd.set(t.clientX, t.clientY), this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
|
|
178
|
+
const e = this.domElement;
|
|
179
|
+
this._rotateLeft(r * this._rotateDelta.x / e.clientHeight), this._rotateUp(r * this._rotateDelta.y / e.clientHeight), this._rotateStart.copy(this._rotateEnd), this.update();
|
|
180
|
+
}
|
|
181
|
+
_handleMouseMoveDolly(t) {
|
|
182
|
+
this._dollyEnd.set(t.clientX, t.clientY), this._dollyDelta.subVectors(this._dollyEnd, this._dollyStart), this._dollyDelta.y > 0 ? this._dollyOut(this._getZoomScale(this._dollyDelta.y)) : this._dollyDelta.y < 0 && this._dollyIn(this._getZoomScale(this._dollyDelta.y)), this._dollyStart.copy(this._dollyEnd), this.update();
|
|
183
|
+
}
|
|
184
|
+
_handleMouseMovePan(t) {
|
|
185
|
+
this._panEnd.set(t.clientX, t.clientY), this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd), this.update();
|
|
186
|
+
}
|
|
187
|
+
_handleMouseWheel(t) {
|
|
188
|
+
this._updateZoomParameters(t.clientX, t.clientY), t.deltaY < 0 ? this._dollyIn(this._getZoomScale(t.deltaY)) : t.deltaY > 0 && this._dollyOut(this._getZoomScale(t.deltaY)), this.update();
|
|
189
|
+
}
|
|
190
|
+
_handleKeyDown(t) {
|
|
191
|
+
let e = !1;
|
|
192
|
+
switch (t.code) {
|
|
193
|
+
case this.keys.UP:
|
|
194
|
+
t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(r * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, this.keyPanSpeed), e = !0;
|
|
195
|
+
break;
|
|
196
|
+
case this.keys.BOTTOM:
|
|
197
|
+
t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(-r * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, -this.keyPanSpeed), e = !0;
|
|
198
|
+
break;
|
|
199
|
+
case this.keys.LEFT:
|
|
200
|
+
t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(r * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(this.keyPanSpeed, 0), e = !0;
|
|
201
|
+
break;
|
|
202
|
+
case this.keys.RIGHT:
|
|
203
|
+
t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(-r * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(-this.keyPanSpeed, 0), e = !0;
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
e && (t.preventDefault(), this.update());
|
|
207
|
+
}
|
|
208
|
+
_handleTouchStartRotate(t) {
|
|
209
|
+
if (this._pointers.length === 1)
|
|
210
|
+
this._rotateStart.set(t.pageX, t.pageY);
|
|
211
|
+
else {
|
|
212
|
+
const e = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + e.x), n = 0.5 * (t.pageY + e.y);
|
|
213
|
+
this._rotateStart.set(s, n);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
_handleTouchStartPan(t) {
|
|
217
|
+
if (this._pointers.length === 1)
|
|
218
|
+
this._panStart.set(t.pageX, t.pageY);
|
|
219
|
+
else {
|
|
220
|
+
const e = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + e.x), n = 0.5 * (t.pageY + e.y);
|
|
221
|
+
this._panStart.set(s, n);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
_handleTouchStartDolly(t) {
|
|
225
|
+
const e = this._getSecondPointerPosition(t), s = t.pageX - e.x, n = t.pageY - e.y, h = Math.sqrt(s * s + n * n);
|
|
226
|
+
this._dollyStart.set(0, h);
|
|
227
|
+
}
|
|
228
|
+
_handleTouchStartDollyPan(t) {
|
|
229
|
+
this.enableZoom && this._handleTouchStartDolly(t), this.enablePan && this._handleTouchStartPan(t);
|
|
230
|
+
}
|
|
231
|
+
_handleTouchStartDollyRotate(t) {
|
|
232
|
+
this.enableZoom && this._handleTouchStartDolly(t), this.enableRotate && this._handleTouchStartRotate(t);
|
|
233
|
+
}
|
|
234
|
+
_handleTouchMoveRotate(t) {
|
|
235
|
+
if (this._pointers.length == 1)
|
|
236
|
+
this._rotateEnd.set(t.pageX, t.pageY);
|
|
237
|
+
else {
|
|
238
|
+
const s = this._getSecondPointerPosition(t), n = 0.5 * (t.pageX + s.x), h = 0.5 * (t.pageY + s.y);
|
|
239
|
+
this._rotateEnd.set(n, h);
|
|
240
|
+
}
|
|
241
|
+
this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
|
|
242
|
+
const e = this.domElement;
|
|
243
|
+
this._rotateLeft(r * this._rotateDelta.x / e.clientHeight), this._rotateUp(r * this._rotateDelta.y / e.clientHeight), this._rotateStart.copy(this._rotateEnd);
|
|
244
|
+
}
|
|
245
|
+
_handleTouchMovePan(t) {
|
|
246
|
+
if (this._pointers.length === 1)
|
|
247
|
+
this._panEnd.set(t.pageX, t.pageY);
|
|
248
|
+
else {
|
|
249
|
+
const e = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + e.x), n = 0.5 * (t.pageY + e.y);
|
|
250
|
+
this._panEnd.set(s, n);
|
|
251
|
+
}
|
|
252
|
+
this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd);
|
|
253
|
+
}
|
|
254
|
+
_handleTouchMoveDolly(t) {
|
|
255
|
+
const e = this._getSecondPointerPosition(t), s = t.pageX - e.x, n = t.pageY - e.y, h = Math.sqrt(s * s + n * n);
|
|
256
|
+
this._dollyEnd.set(0, h), this._dollyDelta.set(0, Math.pow(this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed)), this._dollyOut(this._dollyDelta.y), this._dollyStart.copy(this._dollyEnd);
|
|
257
|
+
const l = (t.pageX + e.x) * 0.5, p = (t.pageY + e.y) * 0.5;
|
|
258
|
+
this._updateZoomParameters(l, p);
|
|
259
|
+
}
|
|
260
|
+
_handleTouchMoveDollyPan(t) {
|
|
261
|
+
this.enableZoom && this._handleTouchMoveDolly(t), this.enablePan && this._handleTouchMovePan(t);
|
|
262
|
+
}
|
|
263
|
+
_handleTouchMoveDollyRotate(t) {
|
|
264
|
+
this.enableZoom && this._handleTouchMoveDolly(t), this.enableRotate && this._handleTouchMoveRotate(t);
|
|
265
|
+
}
|
|
266
|
+
// pointers
|
|
267
|
+
_addPointer(t) {
|
|
268
|
+
this._pointers.push(t.pointerId);
|
|
269
|
+
}
|
|
270
|
+
_removePointer(t) {
|
|
271
|
+
delete this._pointerPositions[t.pointerId];
|
|
272
|
+
for (let e = 0; e < this._pointers.length; e++)
|
|
273
|
+
if (this._pointers[e] == t.pointerId) {
|
|
274
|
+
this._pointers.splice(e, 1);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
_isTrackingPointer(t) {
|
|
279
|
+
for (let e = 0; e < this._pointers.length; e++)
|
|
280
|
+
if (this._pointers[e] == t.pointerId) return !0;
|
|
281
|
+
return !1;
|
|
282
|
+
}
|
|
283
|
+
_trackPointer(t) {
|
|
284
|
+
let e = this._pointerPositions[t.pointerId];
|
|
285
|
+
e === void 0 && (e = new c(), this._pointerPositions[t.pointerId] = e), e.set(t.pageX, t.pageY);
|
|
286
|
+
}
|
|
287
|
+
_getSecondPointerPosition(t) {
|
|
288
|
+
const e = t.pointerId === this._pointers[0] ? this._pointers[1] : this._pointers[0];
|
|
289
|
+
return this._pointerPositions[e];
|
|
290
|
+
}
|
|
291
|
+
//
|
|
292
|
+
_customWheelEvent(t) {
|
|
293
|
+
const e = t.deltaMode, s = {
|
|
294
|
+
clientX: t.clientX,
|
|
295
|
+
clientY: t.clientY,
|
|
296
|
+
deltaY: t.deltaY
|
|
297
|
+
};
|
|
298
|
+
switch (e) {
|
|
299
|
+
case 1:
|
|
300
|
+
s.deltaY *= 16;
|
|
301
|
+
break;
|
|
302
|
+
case 2:
|
|
303
|
+
s.deltaY *= 100;
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
return t.ctrlKey && !this._controlActive && (s.deltaY *= 10), s;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function C(i) {
|
|
310
|
+
this.enabled !== !1 && (this._pointers.length === 0 && (this.domElement.setPointerCapture(i.pointerId), this.domElement.ownerDocument.addEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.addEventListener("pointerup", this._onPointerUp)), !this._isTrackingPointer(i) && (this._addPointer(i), i.pointerType === "touch" ? this._onTouchStart(i) : this._onMouseDown(i)));
|
|
311
|
+
}
|
|
312
|
+
function k(i) {
|
|
313
|
+
this.enabled !== !1 && (i.pointerType === "touch" ? this._onTouchMove(i) : this._onMouseMove(i));
|
|
314
|
+
}
|
|
315
|
+
function x(i) {
|
|
316
|
+
switch (this._removePointer(i), this._pointers.length) {
|
|
317
|
+
case 0:
|
|
318
|
+
this.domElement.releasePointerCapture(i.pointerId), this.domElement.ownerDocument.removeEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.removeEventListener("pointerup", this._onPointerUp), this.dispatchEvent(M), this.state = o.NONE;
|
|
319
|
+
break;
|
|
320
|
+
case 1:
|
|
321
|
+
const t = this._pointers[0], e = this._pointerPositions[t];
|
|
322
|
+
this._onTouchStart({ pointerId: t, pageX: e.x, pageY: e.y });
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function N(i) {
|
|
327
|
+
let t;
|
|
328
|
+
switch (i.button) {
|
|
329
|
+
case 0:
|
|
330
|
+
t = this.mouseButtons.LEFT;
|
|
331
|
+
break;
|
|
332
|
+
case 1:
|
|
333
|
+
t = this.mouseButtons.MIDDLE;
|
|
334
|
+
break;
|
|
335
|
+
case 2:
|
|
336
|
+
t = this.mouseButtons.RIGHT;
|
|
337
|
+
break;
|
|
338
|
+
default:
|
|
339
|
+
t = -1;
|
|
340
|
+
}
|
|
341
|
+
switch (t) {
|
|
342
|
+
case u.DOLLY:
|
|
343
|
+
if (this.enableZoom === !1) return;
|
|
344
|
+
this._handleMouseDownDolly(i), this.state = o.DOLLY;
|
|
345
|
+
break;
|
|
346
|
+
case u.ROTATE:
|
|
347
|
+
if (i.ctrlKey || i.metaKey || i.shiftKey) {
|
|
348
|
+
if (this.enablePan === !1) return;
|
|
349
|
+
this._handleMouseDownPan(i), this.state = o.PAN;
|
|
350
|
+
} else {
|
|
351
|
+
if (this.enableRotate === !1) return;
|
|
352
|
+
this._handleMouseDownRotate(i), this.state = o.ROTATE;
|
|
353
|
+
}
|
|
354
|
+
break;
|
|
355
|
+
case u.PAN:
|
|
356
|
+
if (i.ctrlKey || i.metaKey || i.shiftKey) {
|
|
357
|
+
if (this.enableRotate === !1) return;
|
|
358
|
+
this._handleMouseDownRotate(i), this.state = o.ROTATE;
|
|
359
|
+
} else {
|
|
360
|
+
if (this.enablePan === !1) return;
|
|
361
|
+
this._handleMouseDownPan(i), this.state = o.PAN;
|
|
362
|
+
}
|
|
363
|
+
break;
|
|
364
|
+
default:
|
|
365
|
+
this.state = o.NONE;
|
|
366
|
+
}
|
|
367
|
+
this.state !== o.NONE && this.dispatchEvent(g);
|
|
368
|
+
}
|
|
369
|
+
function I(i) {
|
|
370
|
+
switch (this.state) {
|
|
371
|
+
case o.ROTATE:
|
|
372
|
+
if (this.enableRotate === !1) return;
|
|
373
|
+
this._handleMouseMoveRotate(i);
|
|
374
|
+
break;
|
|
375
|
+
case o.DOLLY:
|
|
376
|
+
if (this.enableZoom === !1) return;
|
|
377
|
+
this._handleMouseMoveDolly(i);
|
|
378
|
+
break;
|
|
379
|
+
case o.PAN:
|
|
380
|
+
if (this.enablePan === !1) return;
|
|
381
|
+
this._handleMouseMovePan(i);
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function Y(i) {
|
|
386
|
+
this.enabled === !1 || this.enableZoom === !1 || this.state !== o.NONE || (i.preventDefault(), this.dispatchEvent(g), this._handleMouseWheel(this._customWheelEvent(i)), this.dispatchEvent(M));
|
|
387
|
+
}
|
|
388
|
+
function U(i) {
|
|
389
|
+
this.enabled !== !1 && this._handleKeyDown(i);
|
|
390
|
+
}
|
|
391
|
+
function z(i) {
|
|
392
|
+
switch (this._trackPointer(i), this._pointers.length) {
|
|
393
|
+
case 1:
|
|
394
|
+
switch (this.touches.ONE) {
|
|
395
|
+
case _.ROTATE:
|
|
396
|
+
if (this.enableRotate === !1) return;
|
|
397
|
+
this._handleTouchStartRotate(i), this.state = o.TOUCH_ROTATE;
|
|
398
|
+
break;
|
|
399
|
+
case _.PAN:
|
|
400
|
+
if (this.enablePan === !1) return;
|
|
401
|
+
this._handleTouchStartPan(i), this.state = o.TOUCH_PAN;
|
|
402
|
+
break;
|
|
403
|
+
default:
|
|
404
|
+
this.state = o.NONE;
|
|
405
|
+
}
|
|
406
|
+
break;
|
|
407
|
+
case 2:
|
|
408
|
+
switch (this.touches.TWO) {
|
|
409
|
+
case _.DOLLY_PAN:
|
|
410
|
+
if (this.enableZoom === !1 && this.enablePan === !1) return;
|
|
411
|
+
this._handleTouchStartDollyPan(i), this.state = o.TOUCH_DOLLY_PAN;
|
|
412
|
+
break;
|
|
413
|
+
case _.DOLLY_ROTATE:
|
|
414
|
+
if (this.enableZoom === !1 && this.enableRotate === !1) return;
|
|
415
|
+
this._handleTouchStartDollyRotate(i), this.state = o.TOUCH_DOLLY_ROTATE;
|
|
416
|
+
break;
|
|
417
|
+
default:
|
|
418
|
+
this.state = o.NONE;
|
|
419
|
+
}
|
|
420
|
+
break;
|
|
421
|
+
default:
|
|
422
|
+
this.state = o.NONE;
|
|
423
|
+
}
|
|
424
|
+
this.state !== o.NONE && this.dispatchEvent(g);
|
|
425
|
+
}
|
|
426
|
+
function Z(i) {
|
|
427
|
+
switch (this._trackPointer(i), this.state) {
|
|
428
|
+
case o.TOUCH_ROTATE:
|
|
429
|
+
if (this.enableRotate === !1) return;
|
|
430
|
+
this._handleTouchMoveRotate(i), this.update();
|
|
431
|
+
break;
|
|
432
|
+
case o.TOUCH_PAN:
|
|
433
|
+
if (this.enablePan === !1) return;
|
|
434
|
+
this._handleTouchMovePan(i), this.update();
|
|
435
|
+
break;
|
|
436
|
+
case o.TOUCH_DOLLY_PAN:
|
|
437
|
+
if (this.enableZoom === !1 && this.enablePan === !1) return;
|
|
438
|
+
this._handleTouchMoveDollyPan(i), this.update();
|
|
439
|
+
break;
|
|
440
|
+
case o.TOUCH_DOLLY_ROTATE:
|
|
441
|
+
if (this.enableZoom === !1 && this.enableRotate === !1) return;
|
|
442
|
+
this._handleTouchMoveDollyRotate(i), this.update();
|
|
443
|
+
break;
|
|
444
|
+
default:
|
|
445
|
+
this.state = o.NONE;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function v(i) {
|
|
449
|
+
this.enabled !== !1 && i.preventDefault();
|
|
450
|
+
}
|
|
451
|
+
function K(i) {
|
|
452
|
+
i.key === "Control" && (this._controlActive = !0, this.domElement.getRootNode().addEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
|
|
453
|
+
}
|
|
454
|
+
function H(i) {
|
|
455
|
+
i.key === "Control" && (this._controlActive = !1, this.domElement.getRootNode().removeEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
|
|
456
|
+
}
|
|
457
|
+
class F {
|
|
458
|
+
obj;
|
|
459
|
+
constructor(t) {
|
|
460
|
+
this.obj = t;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
class q {
|
|
464
|
+
scene;
|
|
465
|
+
constructor() {
|
|
466
|
+
this.scene = new m.Scene();
|
|
467
|
+
}
|
|
468
|
+
add(t) {
|
|
469
|
+
this.scene.add(t.obj);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
class X extends HTMLElement {
|
|
473
|
+
ro;
|
|
474
|
+
renderer;
|
|
475
|
+
scene = null;
|
|
476
|
+
camera;
|
|
477
|
+
controls;
|
|
478
|
+
constructor() {
|
|
479
|
+
super(), this.renderer = new m.WebGLRenderer(), this.camera = new m.PerspectiveCamera(75, 300 / 150, 0.1, 1e3), this.camera.position.set(0, 0, 3), this.controls = new j(this.camera, this.renderer.domElement), this.controls.target.set(0, 0, 0), this.style = "display: block;", this.renderer.domElement.style = "display: block; width: 100%; height: 100%; margin: 0; padding: 0;", this.appendChild(this.renderer.domElement);
|
|
480
|
+
}
|
|
481
|
+
connectedCallback() {
|
|
482
|
+
this.ro = new ResizeObserver(() => {
|
|
483
|
+
const { width: t, height: e } = this.renderer.domElement.getBoundingClientRect();
|
|
484
|
+
this.camera.aspect = t / e, this.camera.updateProjectionMatrix(), this.renderer.setSize(t, e), console.log("GAHA: resize");
|
|
485
|
+
}), this.ro.observe(this);
|
|
486
|
+
}
|
|
487
|
+
disconnectedCallback() {
|
|
488
|
+
this.ro?.disconnect();
|
|
489
|
+
}
|
|
490
|
+
hemiLight = new m.AmbientLight(16777215, 0.6);
|
|
491
|
+
dirLight = new m.DirectionalLight(16777215, 1);
|
|
492
|
+
setScene(t) {
|
|
493
|
+
this.scene = t, this.scene.scene.add(this.camera), this.scene.scene.add(this.hemiLight), this.dirLight.position.set(5, 10, 4), this.scene.scene.add(this.dirLight), this.animationFrameId = requestAnimationFrame(this.renderingLoop);
|
|
494
|
+
}
|
|
495
|
+
removeScene() {
|
|
496
|
+
this.scene && (this.scene.scene.remove(this.camera), this.scene.scene.remove(this.hemiLight), this.scene.scene.remove(this.dirLight), this.scene = null, cancelAnimationFrame(this.animationFrameId));
|
|
497
|
+
}
|
|
498
|
+
animationFrameId = -1;
|
|
499
|
+
previousTime = -1;
|
|
500
|
+
renderingLoop = (t) => {
|
|
501
|
+
const e = this.previousTime === -1 ? 0 : t - this.previousTime;
|
|
502
|
+
this.controls.update(e), this.scene && this.renderer.render(this.scene.scene, this.camera), this.animationFrameId = requestAnimationFrame(this.renderingLoop);
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
customElements.define("a3-canvas", X);
|
|
506
|
+
class G extends F {
|
|
3
507
|
constructor() {
|
|
4
|
-
|
|
508
|
+
const t = new m.BoxGeometry(), e = new m.MeshStandardMaterial({ color: 65280 }), s = new m.Mesh(t, e);
|
|
509
|
+
super(s);
|
|
5
510
|
}
|
|
6
511
|
}
|
|
512
|
+
function V(i) {
|
|
513
|
+
return 2 * i;
|
|
514
|
+
}
|
|
7
515
|
export {
|
|
8
|
-
|
|
516
|
+
X as A3Canvas,
|
|
517
|
+
F as A3Object,
|
|
518
|
+
q as A3Scene,
|
|
519
|
+
G as A3Test,
|
|
520
|
+
V as times2
|
|
9
521
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "a3js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/a3js.cjs.js",
|
|
6
6
|
"module": "dist/a3js.es.js",
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/a3js.es.js",
|
|
11
|
-
"require": "./dist/a3js.cjs.js"
|
|
12
|
-
"types": "./dist/types/index.d.ts"
|
|
11
|
+
"require": "./dist/a3js.cjs.js"
|
|
13
12
|
}
|
|
14
13
|
},
|
|
15
14
|
"files": [
|
|
@@ -21,6 +20,7 @@
|
|
|
21
20
|
"preview": "vite preview"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
23
|
+
"@types/three": "^0.182.0",
|
|
24
24
|
"typescript": "~5.9.3",
|
|
25
25
|
"vite": "^7.2.4"
|
|
26
26
|
},
|
package/dist/vite.svg
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|