"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var l=require("three"),y=require("three/examples/jsm/loaders/GLTFLoader.js");class p{constructor(){this._listeners={}}on(e,t,s){this._listeners[e]?this._listeners[e].push({callback:t,isOnce:s}):this._listeners[e]=[{callback:t,isOnce:s}]}off(e,t){if(!t)throw new Error("\u53D6\u6D88\u4E8B\u4EF6\u65F6\u9700\u8981\u4F20\u5165\u539F\u56DE\u8C03\u51FD\u6570");const s=this._listeners[e];if(s&&s.length>0){for(let i=0;i0)for(let i=0;i{f(e)})}function f(c){const e=s=>{s.geometry&&s.geometry.dispose(),s.material&&s.material.dispose&&s.material.dispose(),s.material.texture&&s.material.texture.dispose&&s.material.texture.dispose()},t=s=>{let i=s.children.filter(r=>r);i.forEach(r=>{r.children.length?t(r):r.isMesh&&e(r)}),i=null};t(c)}class v extends p{constructor(e,t){super(),this.frameTimer=-1,this.needsUpdate=!1,t=t||{},this.customCoords=e.customCoords,this.center=t.customCoordsCenter||e.getCenter().toArray(),this.customCoords.lngLatsToCoords([this.center]);const s={zooms:[2,20],opacity:1,alpha:!1,antialias:!1,visible:!0,zIndex:120};this.options=Object.assign({},s,t),this.map=e,this.init()}init(){const e=this.map,t=this.options,s={zooms:t.zooms,opacity:t.opacity,visible:t.visible,zIndex:t.zIndex,init:i=>{const r=e.getContainer(),n=r.offsetWidth,o=r.offsetHeight;let a;e.getView().type==="3D"?a=new l.PerspectiveCamera(60,n/o,100,1<<30):a=new l.OrthographicCamera(n/-2,n/2,o/2,o/-2,1,1e3);const h=new l.WebGLRenderer({context:i,alpha:t.alpha,antialias:t.antialias});h.setSize(n,o),h.autoClear=!1;const m=new l.Scene;this.camera=a,this.renderer=h,this.scene=m,t.onInit&&t.onInit(h,m,a),this.animate(),this.emit("complete")},render:()=>{var i,r,n;(i=this.renderer)===null||i===void 0||i.resetState(),this.customCoords.setCenter(this.center);const o=this.camera;if(e.getView().type==="3D"){const{near:a,far:h,fov:m,up:d,lookAt:u,position:g}=this.customCoords.getCameraParams();o.near=a,o.far=h,o.fov=m,o.position.set(...g),o.up.set(...d),o.lookAt(...u),o.updateProjectionMatrix()}else{const{top:a,bottom:h,left:m,right:d,position:u}=this.customCoords.getCameraParams();o.top=a,o.bottom=h,o.left=m,o.right=d,o.position.set(...u),o.updateProjectionMatrix()}this.camera=o,t.onRender?t.onRender(this.renderer,this.scene,this.camera):(r=this.renderer)===null||r===void 0||r.render(this.scene,o),(n=this.renderer)===null||n===void 0||n.resetState()}};this.layer=new AMap.GLCustomLayer(s),this.layer.setMap(e)}update(){this.needsUpdate=!0}animate(){this.needsUpdate&&(this.refreshMap(),this.needsUpdate=!1),this.frameTimer=requestAnimationFrame(()=>{this.animate()})}refreshMap(){this.map&&this.map.render()}convertLngLat(e){return this.customCoords.lngLatsToCoords([e])[0]}add(e){var t;(t=this.scene)===null||t===void 0||t.add(e),this.refreshMap()}remove(e){var t;(t=this.scene)===null||t===void 0||t.remove(e),this.refreshMap()}getScene(){return this.scene}getCamera(){return this.camera}getRender(){return this.renderer}destroy(){var e;cancelAnimationFrame(this.frameTimer),this.layer.setMap(null),this.customCoords=null,b(this.scene),this.scene=void 0,this.camera=void 0,(e=this.renderer)===null||e===void 0||e.dispose(),this.renderer=void 0,this.layer=null,this.map=null,l.Cache.clear(),this.options=null}getMap(){return this.map?this.map:null}getOpacity(){return this.layer.getOpacity()}setOpacity(e){this.layer.setOpacity(e)}getZooms(){return this.layer.getZooms()}setZooms(e){this.layer.setZooms(e)}getzIndex(){return this.layer.getzIndex()}setzIndex(e){this.layer.setzIndex(e)}show(){this.layer.show()}hide(){this.layer.hide()}}class j extends p{constructor(e,t){super(),this.linerAnimationFrame=-1,this.layer=e,t=Object.assign({},{url:"",position:[0,0],height:0,rotation:{x:0,y:0,z:0},scale:1,angle:0},t),this.init(t)}init(e){new y.GLTFLoader().load(e.url,t=>{const s=t.scene,i=t.animations;this.layer.add(s),this.object=s,this.animations=i,this.setScale(e.scale),this.setRotation(e.rotation),this.setAngle(e.angle),this.setPosition(e.position),this.setHeight(e.height),e.onLoaded&&e.onLoaded(s,i),this.emit("complete",{target:s,animations:i})})}setScale(e){let t;typeof e=="number"?t={x:e,y:e,z:e}:t=e,this.object.scale.set(t.x,t.y,t.z),this.refresh()}setPosition(e){const t=this.layer.convertLngLat(e);this.object.position.setX(t[0]),this.object.position.setY(t[1]),this.refresh()}setRotation(e){if(e){const t=Math.PI/180*(e.x||0),s=Math.PI/180*(e.y||0),i=Math.PI/180*(e.z||0);this.object.rotation.set(t,s,i),this.refresh()}}setAngle(e){const t=this.object.rotation.x,s=this.object.rotation.z,i=Math.PI/180*e;this.object.rotation.set(t,i,s),this.refresh()}setHeight(e){e!==void 0&&(this.object.position.setZ(e),this.refresh())}getAnimations(){return this.animations}getObject(){return this.object}refresh(){this.layer.update()}show(){this.object.visible=!0,this.refresh()}hide(){this.object.visible=!1,this.refresh()}animate(e){this.linerAnimationFrame=requestAnimationFrame(()=>{this.animate(e)}),e()}startAnimations(){if(this.animations){const e=this.animations,t=new l.AnimationMixer(this.object),s={};for(let r=0;r{const r=i.getDelta();t&&t.update(r),this.refresh()})}}stopAnimations(){cancelAnimationFrame(this.linerAnimationFrame)}remove(){this.object&&this.layer.remove(this.object)}destroy(){this.stopAnimations(),this.object&&(f(this.object),this.object=null,this.layer=null)}}exports.ThreeGltf=j,exports.ThreeLayer=v; //# sourceMappingURL=index-cjs.js.map