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