import*as e from"three";import{Vector3 as t,Points as n}from"three";import{MTLLoader as i}from"three/examples/jsm/loaders/MTLLoader.js";import{OBJLoader as r}from"three/examples/jsm/loaders/OBJLoader.js";import{GLTFLoader as s}from"three/examples/jsm/loaders/GLTFLoader.js";import{DRACOLoader as o}from"three/examples/jsm/loaders/DRACOLoader.js";import{PLYLoader as a}from"three/examples/jsm/loaders/PLYLoader.js";import{TransformControls as c}from"three/examples/jsm/controls/TransformControls.js";import{OrbitControls as l}from"three/examples/jsm/controls/OrbitControls.js";import{Line2 as d}from"three/examples/jsm/lines/Line2.js";import{LineGeometry as h}from"three/examples/jsm/lines/LineGeometry.js";import{LineMaterial as f}from"three/examples/jsm/lines/LineMaterial.js";import{CSS2DObject as u,CSS2DRenderer as m}from"three/examples/jsm/renderers/CSS2DRenderer.js";function v(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{c(i.next(e))}catch(e){s(e)}}function a(e){try{c(i.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((i=i.apply(e,t||[])).next())}))}function p(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function g(e,t,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(e,n):r?r.value=n:t.set(e,n),n}var w,b,y,C,E,M,L,S,k;"function"==typeof SuppressedError&&SuppressedError;class j{constructor(e){w.add(this),b.set(this,void 0),g(this,b,e,"f"),this.scene=p(this,w,"m",y).call(this)}init(){console.log("Scene init")}}b=new WeakMap,w=new WeakSet,y=function(){const t=new e.Scene,n=p(this,b,"f").options.backgroundColor;return t.background=new e.Color(n),t};class x{constructor(t){C.set(this,void 0),g(this,C,t,"f");const{canvas:n}=t;this.camera=new e.PerspectiveCamera(75,n.clientWidth/n.clientHeight,.1,1e3)}init(){const e=this.camera;e.position.set(.07,7.5,9.13),e.rotation.set(-.7,.01,.01)}setCameraTopView(){p(this,C,"f").EditorControl.orbitControls.reset(),this.camera.position.set(0,36,0),this.camera.rotation.set(-1.5,0,0),p(this,C,"f").EditorControl.orbitControls.update()}}C=new WeakMap;class P{constructor(t,n){E.set(this,void 0),M.set(this,void 0),g(this,M,n,"f"),g(this,E,t,"f");const{canvas:i}=t,r=this.renderer=new e.WebGLRenderer({canvas:i,antialias:!0});r.shadowMap.enabled=!0,r.setPixelRatio(window.devicePixelRatio)}init(){const e=p(this,E,"f"),t=this.renderer,{canvas:n,camera:i}=e;e.on("resize",(()=>{p(this,M,"f").ResizeService.setResize(t,n,i)}))}render(){const e=p(this,E,"f"),{renderer:t,scene:n,camera:i}=e,r=()=>{t.render(n,i),e.trigger("render",{type:"render",target:e}),requestAnimationFrame(r)};requestAnimationFrame(r)}}E=new WeakMap,M=new WeakMap;class _{constructor(e){L.add(this),S.set(this,void 0),g(this,S,e,"f")}init(){p(this,L,"m",k).call(this)}eventTrigger(e,t){p(this,S,"f").trigger(e,t)}}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function D(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],i=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function O(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var i,r,s=n.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(i=s.next()).done;)o.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return o}function T(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(O(arguments[t]));return e}S=new WeakMap,L=new WeakSet,k=function(){const e=p(this,S,"f");window.addEventListener("resize",(()=>{e.trigger("resize",{type:"resize",target:e})}))};var W=function(e){return void 0===e},R=function(){function e(e,t){var n,i;if(this._canceled=!1,t)try{for(var r=D(Object.keys(t)),s=r.next();!s.done;s=r.next()){var o=s.value;this[o]=t[o]}}catch(e){n={error:e}}finally{try{s&&!s.done&&(i=r.return)&&i.call(r)}finally{if(n)throw n.error}}this.eventType=e}var t=e.prototype;return t.stop=function(){this._canceled=!0},t.isCanceled=function(){return this._canceled},e}(),F=function(){function e(){this._eventHandler={}}var t=e.prototype;return t.trigger=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var i=e instanceof R?e.eventType:e,r=T(this._eventHandler[i]||[]);return r.length<=0||(e instanceof R?(e.currentTarget=this,r.forEach((function(t){t(e)}))):r.forEach((function(e){e.apply(void 0,T(t))}))),this},t.once=function(e,t){var n=this;if("object"==typeof e&&W(t)){var i=e;for(var r in i)this.once(r,i[r]);return this}if("string"==typeof e&&"function"==typeof t){var s=function(){for(var i=[],r=0;r<arguments.length;r++)i[r]=arguments[r];t.apply(void 0,T(i)),n.off(e,s)};this.on(e,s)}return this},t.hasOn=function(e){return!!this._eventHandler[e]},t.on=function(e,t){if("object"==typeof e&&W(t)){var n=e;for(var i in n)this.on(i,n[i]);return this}if("string"==typeof e&&"function"==typeof t){var r=this._eventHandler[e];W(r)&&(this._eventHandler[e]=[],r=this._eventHandler[e]),r.push(t)}return this},t.off=function(e,t){var n,i;if(W(e))return this._eventHandler={},this;if(W(t)){if("string"==typeof e)return delete this._eventHandler[e],this;var r=e;for(var s in r)this.off(s,r[s]);return this}var o=this._eventHandler[e];if(o){var a=0;try{for(var c=D(o),l=c.next();!l.done;l=c.next()){if(l.value===t){o.splice(a,1),o.length<=0&&delete this._eventHandler[e];break}a++}}catch(e){n={error:e}}finally{try{l&&!l.done&&(i=c.return)&&i.call(c)}finally{if(n)throw n.error}}}return this},e.VERSION="3.0.4",e}();const z="GRID_HELPER_GROUP",G="MTL_MESH_OBJECT",B="TransformControls";var H,A,N,I,U,V,$,Y,K,q;const X=[z,B],J=["Line2"];class Z{constructor(e,t){H.add(this),A.set(this,void 0),N.set(this,void 0),I.set(this,!1),U.set(this,!0),V.set(this,(e=>{const t=p(this,H,"m",Y).call(this,e);t?(p(this,A,"f").trigger("object_click",{type:"object_click",target:t}),this.attachTransform(t)):!p(this,I,"f")&&this.detachTransform()})),g(this,A,e,"f"),g(this,N,t,"f")}get orbitControls(){return p(this,N,"f").OrbitControlService.orbitControls}set isObjectDragging(e){g(this,I,e,"f")}set orbitControlOnOff(e){g(this,U,e,"f"),p(this,N,"f").OrbitControlService.orbitControls.enabled=e}get transformController(){return p(this,N,"f").TransformControlService.controller}init(){this.turnOnObjectClickEvent(),p(this,N,"f").TransformControlService.controller.name=B,p(this,A,"f").options.keyboardCameraControl&&p(this,H,"m",$).call(this)}turnOffObjectClickEvent(){const e=p(this,N,"f").TransformControlService,{canvas:t}=p(this,A,"f");e.controller.detach(),p(this,N,"f").ObjectClickService.removeCanvasClickEvent(t,p(this,V,"f"))}turnOnObjectClickEvent(){p(this,H,"m",K).call(this),p(this,H,"m",q).call(this)}attachTransform(e){const t=p(this,N,"f").TransformControlService,n=p(this,I,"f");J.find((t=>e.type===t))||t.attachObjectToControl(n,e)}detachTransform(){p(this,N,"f").TransformControlService.controller.detach()}setTransformMode(e){const t=p(this,N,"f").TransformControlService;if(!t)throw"error";t.controller.setMode(e)}removeClickedObject(){const e=p(this,N,"f").TransformControlService.controller.object;e&&(e.removeFromParent(),e.remove(),e.clear(),p(this,N,"f").TransformControlService.controller.detach())}getTransformMode(){return this.transformController.mode}}var Q,ee,te,ne,ie,re,se,oe,ae,ce,le,de,he,fe,ue,me,ve,pe,ge,we,be,ye,Ce,Ee,Me,Le,Se,ke,je,xe,Pe,_e,De;A=new WeakMap,N=new WeakMap,I=new WeakMap,U=new WeakMap,V=new WeakMap,H=new WeakSet,$=function(){const e=this.orbitControls;e.listenToKeyEvents(window),e.keys={LEFT:"KeyA",RIGHT:"KeyD",UP:"KeyW",BOTTOM:"KeyS"},e.keyPanSpeed=30,e.enableDamping=!0,p(this,A,"f").on("render",(()=>{e.update()}))},Y=function(e){const t=p(this,N,"f").ObjectClickService,{camera:n,canvas:i,scene:r}=p(this,A,"f"),s=p(this,I,"f");return t.getClickObjectEvent(e,{scene:r,camera:n,canvas:i,isDragging:s,ignoreTargetName:X})},K=function(){const{canvas:e}=p(this,A,"f");p(this,N,"f").ObjectClickService.setCanvasClickEvent(e,p(this,V,"f"))},q=function(){const e=p(this,N,"f").TransformControlService;e.controller.addEventListener("dragging-changed",(e=>{this.isObjectDragging=e.value,this.orbitControlOnOff=!e.value,p(this,A,"f").trigger("transform_change",{type:"dragging-changed",target:this.transformController.object})})),e.controller.addEventListener("mouseUp",(e=>{var t;const n=e.target;n.object&&p(this,A,"f").EditorStorage.patch({transform:null===(t=n.object)||void 0===t?void 0:t.matrixWorld},n.object.uuid)}))};class Oe{constructor(e,t){Q.set(this,void 0),ee.set(this,void 0),g(this,Q,e,"f"),g(this,ee,t,"f")}init(){const{scene:e}=p(this,Q,"f");p(this,ee,"f").IndexedDBService.init(),p(this,ee,"f").IndexedDBService.loadAllObjects(e)}getDataAll(){return p(this,ee,"f").IndexedDBService.getDataAll()}patch(e,t){return p(this,ee,"f").IndexedDBService.patch(e,t)}save(e,t){const n={id:t,source:e,transform:null};p(this,ee,"f").IndexedDBService.save(n)}}Q=new WeakMap,ee=new WeakMap;class Te{constructor(e,t){te.add(this),ne.set(this,void 0),ie.set(this,void 0),g(this,ne,e,"f"),g(this,ie,t,"f"),this.scene=e.scene}init(){p(this,te,"m",re).call(this),p(this,te,"m",oe).call(this)}loadPLY(e){return v(this,void 0,void 0,(function*(){p(this,ne,"f").trigger("load_start",{type:"loadPLY",target:p(this,ne,"f")});const t=yield p(this,ie,"f").ObjectLoader.plyLoad(e);return t.name=G,this.scene.add(t),p(this,ne,"f").trigger("load",{type:"loadPLY",target:p(this,ne,"f"),loadData:t,id:t.id}),t}))}loadMTL(e,t){return v(this,void 0,void 0,(function*(){p(this,ne,"f").trigger("load_start",{target:p(this,ne,"f"),type:"loadMTL"});const n=yield p(this,ie,"f").ObjectLoader.mtlLoad(e,t);return n.rotation.x=-1.5,n.name=G,this.scene.add(n),p(this,ne,"f").trigger("load",{target:p(this,ne,"f"),type:"loadMTL",id:n.id,loadData:n}),n}))}}ne=new WeakMap,ie=new WeakMap,te=new WeakSet,re=function(){const{scene:e}=p(this,ne,"f"),t=p(this,ne,"f"),n=p(this,ie,"f").FileUploadService;document.addEventListener("drop",(i=>v(this,void 0,void 0,(function*(){if(i.preventDefault(),i.dataTransfer&&i.dataTransfer.items)try{n.checkValidFile(i),t.EditorEvent.eventTrigger("load_start",{type:"folder_drop",target:t,loadStartData:i.dataTransfer.items}),t.trigger("load_start",{type:"folder_drop",target:t,loadStartData:i.dataTransfer.items});const{files:r}=yield n.getFilesFromItemList(i.dataTransfer.items),s=yield p(this,te,"m",se).call(this,r);e.add(s),t.trigger("load",{type:"folder_drop",target:t,id:s.uuid,loadData:r}),t.EditorStorage.save(r,s.uuid)}catch(e){console.log(e)}}))))},se=function(e){return v(this,void 0,void 0,(function*(){const t=yield p(this,ie,"f").ObjectLoader.objectLoadAsFolder(e);if(!t)throw p(this,ne,"f").trigger("load_fail",{type:"folder_drop",target:p(this,ne,"f")}),"load_fail";return t.children.length?t.children[0]:t}))},oe=function(){document.addEventListener("dragover",(e=>{e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy")}))};class We{constructor(e){ae.add(this),ce.set(this,void 0),g(this,ce,e,"f")}init(){p(this,ae,"m",le).call(this)}}ce=new WeakMap,ae=new WeakSet,le=function(){const{scene:t}=p(this,ce,"f"),n=new e.AmbientLight(16777215);t.add(n)};class Re{constructor(e,t){de.set(this,void 0),he.set(this,void 0),g(this,de,e,"f"),g(this,he,t,"f")}init(){const{scene:e}=p(this,de,"f");p(this,he,"f").GridService.setGrid(e,{gridGroupName:z}),p(this,de,"f").options.defaultSquare&&p(this,he,"f").GeometryService.setCube(e)}}de=new WeakMap,he=new WeakMap;class Fe{constructor(){fe.add(this)}setCube(e){const t=p(this,fe,"m",ue).call(this);e.add(t)}}fe=new WeakSet,ue=function({width:t=1,height:n=1,depth:i=1,color:r=65280}={}){const s=new e.BoxGeometry(t,n,i),o=new e.MeshStandardMaterial({color:r});return new e.Mesh(s,o)};class ze extends e.Mesh{constructor(t={}){const{size1:n=10,size2:i=100,color:r=new e.Color("white"),distance:s=1e3,axes:o="xzy"}=t,a=o.substring(0,2);super(new e.PlaneGeometry(2,2,1,1),new e.ShaderMaterial({side:e.DoubleSide,uniforms:{uSize1:{value:n},uSize2:{value:i},uColor:{value:r},uDistance:{value:s}},transparent:!0,vertexShader:`\n        varying vec3 worldPosition;\n        uniform float uDistance;\n        \n        void main() {\n          vec3 pos = position.${o} * uDistance;\n          pos.${a} += cameraPosition.${a};\n          worldPosition = pos;\n          gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);\n        }\n      `,fragmentShader:`\n        varying vec3 worldPosition;\n        uniform float uSize1;\n        uniform float uSize2;\n        uniform vec3 uColor;\n        uniform float uDistance;\n\n        float getGrid(float size) {\n          vec2 r = worldPosition.${a} / size;\n          vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n          float line = min(grid.x, grid.y);\n          return 1.0 - min(line, 1.0);\n        }\n\n        void main() {\n          float d = 1.0 - min(distance(cameraPosition.${a}, worldPosition.${a}) / uDistance, 1.0);\n          float g1 = getGrid(uSize1);\n          float g2 = getGrid(uSize2);\n          gl_FragColor = vec4(uColor.rgb, mix(g2, g1, g1) * pow(d, 3.0));\n          gl_FragColor.a = mix(0.5 * gl_FragColor.a, gl_FragColor.a, g2);\n          if (gl_FragColor.a <= 0.0) discard;\n        }\n      `,extensions:{derivatives:!0}})),this.frustumCulled=!1}}class Ge{constructor(){me.add(this)}setGrid(t,{gridGroupName:n=""}={}){const i=new e.Group,r=p(this,me,"m",ve).call(this);i.name=n,i.add(r),t.add(i)}}me=new WeakSet,ve=function(){return new ze({color:new e.Color(8947848),size1:5,size2:25})};class Be{setResize(e,t,n){const i=t.clientWidth||1,r=t.clientHeight||1;n.aspect=i/r,n.updateProjectionMatrix(),e.setPixelRatio(window.devicePixelRatio),e.setSize(i,r,!1)}}class He{constructor(){pe.add(this)}plyLoad(t){const n=new a;return new Promise(((i,r)=>{n.load(t,(t=>{t.computeVertexNormals();const n=new e.MeshPhysicalMaterial({side:e.DoubleSide,clearcoat:1,clearcoatRoughness:.25,roughness:.5}),r=new e.Mesh(t,n);r.scale.set(.5,.5,.5),r.rotation.x=-1.5,r.castShadow=!0,r.receiveShadow=!0,t.computeVertexNormals(),i(r)}))}))}mtlLoad(e,t){const n=new i,s=new r;return new Promise((i=>{n.load(e,(e=>{e.preload(),s.setMaterials(e),s.load(t,(e=>{const t=e.children[0];i(t)}))}))}))}objectLoadAsFolder(e){return v(this,void 0,void 0,(function*(){const{type:t,textureImages:n,index3DFiles:i}=p(this,pe,"m",Ce).call(this,e);return"glb"===t?yield p(this,pe,"m",be).call(this,i):"mtl"===t||"obj"===t?yield p(this,pe,"m",we).call(this,i,n):"ply"===t?yield p(this,pe,"m",ge).call(this,i):void 0}))}}pe=new WeakSet,ge=function(t){return v(this,void 0,void 0,(function*(){const n=new a,i=t.ply;return new Promise(((t,r)=>{i.arrayBuffer().then((i=>{const r=n.parse(i);r.computeVertexNormals();const s=new e.PointsMaterial({alphaTest:.5,sizeAttenuation:!1,vertexColors:!0,transparent:!0}),o=new e.Points(r,s);o.scale.set(.1,.1,.1),o.rotation.x=-1.5,t(o)}))}))}))},we=function(e,t){return v(this,void 0,void 0,(function*(){const n=yield e.mtl.text(),s=yield e.obj.text(),o=new i,a=new r,c=o.parse(n,"");o.manager.setURLModifier((e=>{e=e.replace(/^(\.?\/)/,"");const n=t[e];return n?URL.createObjectURL(n):"/"})),c.preload();return a.setMaterials(c).parse(s)}))},be=function(e){return v(this,void 0,void 0,(function*(){const t=new s,n=e.glb,i=new o;return i.setDecoderPath("/public/draco/"),t.setDRACOLoader(i),new Promise(((e,i)=>{n.arrayBuffer().then((n=>{t.parse(n,"",(t=>{e(t.scene)}))}))}))}))},ye=function(e){const t={},n={};return e.forEach((e=>{const i=e.name.split("."),r=i[i.length-1];"jpg"!==r&&"png"!==r&&"jpeg"!==r||(t[e.name]=e),"mtl"===r&&(n.mtl=e),"obj"===r&&(n.obj=e),"glb"===r&&(n.glb=e),"ply"===r&&(n.ply=e)})),{textureImages:t,index3DFiles:n}},Ce=function(e){const{index3DFiles:t,textureImages:n}=p(this,pe,"m",ye).call(this,e);return{type:Object.keys(t)[0],textureImages:n,index3DFiles:t}};class Ae{init(){const e=window.indexedDB.open("EditorDB");e.onupgradeneeded=e=>{e.target.result.createObjectStore("states",{keyPath:"id",autoIncrement:!0})},e.onsuccess=t=>{e.result.transaction("states","readwrite").objectStore("states")}}getData(e){return v(this,void 0,void 0,(function*(){const t=indexedDB.open("EditorDB");return new Promise((n=>{t.onsuccess=t=>{const i=t.target.result.transaction("states","readonly").objectStore("states");n(i.get(e))}}))}))}getDataAll(){return v(this,void 0,void 0,(function*(){const e=indexedDB.open("EditorDB");return new Promise((t=>{e.onsuccess=e=>{const n=e.target.result.transaction("states","readonly").objectStore("states");t(n.getAll())}}))}))}patch(e,t){indexedDB.open("EditorDB").onsuccess=n=>{const i=n.target.result.transaction("states","readwrite").objectStore("states"),r=i.get(t);r.onsuccess=()=>{const t=r.result;t&&(t.transform=e.transform,i.put(t))}}}save(e){indexedDB.open("EditorDB").onsuccess=t=>{t.target.result.transaction("states","readwrite").objectStore("states").add(e)}}loadAllObjects(e){return v(this,void 0,void 0,(function*(){(yield this.getDataAll().then((e=>e))).onsuccess=t=>v(this,void 0,void 0,(function*(){t.target.result.forEach((t=>{const n=t.id,i=t.source,r=t.transform;(new He).objectLoadAsFolder(i).then((t=>{if(t){t.uuid=n;try{r&&t&&t.applyMatrix4(r)}catch(e){console.log(e)}e.add(t)}}))}))}))}))}}class Ne{constructor(){Ee.add(this)}getObjectMesh(e){throw new Error("Method not implemented.")}checkValidFile(e){if(!e.dataTransfer||"text/plain"===e.dataTransfer.types[0])throw"파일 형식이 올바르지 않습니다."}getFilesFromItemList(e){return v(this,void 0,void 0,(function*(){const t=[],n={};function i(e){return v(this,void 0,void 0,(function*(){return new Promise(((r,s)=>{if(e.isDirectory){e.createReader().readEntries((function(e){return v(this,void 0,void 0,(function*(){for(let t=0;t<e.length;t++)yield i(e[t]);r(!0)}))}))}if(e.isFile){e.file((function(i){t.push(i),n[e.fullPath.slice(1)]=i,r(!0)}),(()=>{s(!1)}))}}))}))}for(let t=0;t<e.length;t++){const n=e[t];if("file"===n.kind){const e=n.webkitGetAsEntry();e&&(yield i(e))}}return{files:t,filesMap:n}}))}}Ee=new WeakSet;class Ie{constructor({camera:e,canvas:t,scene:n}){Me.add(this),Le.set(this,void 0),Se.set(this,void 0),ke.set(this,void 0),je.set(this,void 0),g(this,ke,e,"f"),g(this,Se,t,"f"),g(this,Le,n,"f"),g(this,je,new c(e,t),"f"),p(this,je,"f").setMode("translate"),this.setTransformController()}get controller(){return p(this,je,"f")}setTransformController(){p(this,Me,"m",xe).call(this)}attachObjectToControl(e,t){const n=p(this,je,"f");t&&n.attach(t),t||e||n.detach()}}Le=new WeakMap,Se=new WeakMap,ke=new WeakMap,je=new WeakMap,Me=new WeakSet,xe=function(){const e=p(this,Le,"f"),t=p(this,je,"f");e.add(t)};class Ue{constructor({camera:e,canvas:t}){Pe.add(this),_e.set(this,void 0);const n=g(this,_e,new l(e,t),"f");n.minDistance=1,n.maxDistance=50,n.enablePan=!0,p(this,Pe,"m",De).call(this)}get orbitControls(){return p(this,_e,"f")}}_e=new WeakMap,Pe=new WeakSet,De=function(){};const Ve=e=>{let t=e.parent,n=e;for(;t;){if("Scene"===t.type)return n;if(!t)return null;n=t,t=t.parent}};var $e,Ye,Ke,qe,Xe,Je,Ze,Qe,et,tt,nt,it,rt;class st{constructor(){$e.add(this)}removeCanvasClickEvent(e,t){e.removeEventListener("mousedown",t)}setCanvasClickEvent(e,t){e.addEventListener("mousedown",t)}getClickObjectEvent(t,n){const{canvas:i,camera:r,scene:s,isDragging:o,ignoreTargetName:a=[]}=n,c=new e.Vector2,l=new e.Raycaster;t.preventDefault(),c.x=t.offsetX/i.clientWidth*2-1,c.y=-t.offsetY/i.clientHeight*2+1,l.setFromCamera(c,r);const d=l.intersectObjects(s.children);return p(this,$e,"m",Ye).call(this,d,a)}}$e=new WeakSet,Ye=function(e,t){for(let n=0;n<e.length;n++){const i=e[n].object,r=Ve(i);if(r&&(!t.includes(r.name)&&!t.includes(r.constructor.name)&&"Scene"!==(null==r?void 0:r.type)))return r}return null};class ot extends F{constructor(e){const{canvasContainer:t,canvas:n,backgroundColor:i="#373737",defaultSquare:r=!1,keyboardCameraControl:s=!1}=e;super(),this.plugins=[],this.canvasContainer=t,t.style.position="relative",this.canvas=n,this.options=e;const o=this.EditorCamera=new x(this),a=this.EditorScene=new j(this),c=this.EditorRenderer=new P(this,{ResizeService:new Be}),l=this.scene=a.scene,d=this.camera=o.camera;this.renderer=c.renderer,this.EditorEvent=new _(this),this.EditorControl=new Z(this,{TransformControlService:new Ie({camera:d,canvas:n,scene:l}),OrbitControlService:new Ue({camera:d,canvas:n}),ObjectClickService:new st}),this.EditorStorage=new Oe(this,{IndexedDBService:new Ae}),this.EditorUpload=new Te(this,{ObjectLoader:new He,FileUploadService:new Ne}),this.EditorLight=new We(this),this.EditorGeometry=new Re(this,{GeometryService:new Fe,GridService:new Ge})}init(){return v(this,void 0,void 0,(function*(){this.EditorCamera.init(),this.EditorScene.init(),this.EditorRenderer.init(),this.EditorEvent.init(),this.EditorControl.init(),this.EditorStorage.init(),this.EditorUpload.init(),this.EditorLight.init(),this.EditorGeometry.init(),this.trigger("ready",{type:"ready",target:this}),this.trigger("resize",{type:"resize",target:this}),this.EditorRenderer.render()}))}loadPLY(e){return v(this,void 0,void 0,(function*(){return this.EditorUpload.loadPLY(e)}))}loadMTL(e,t){return v(this,void 0,void 0,(function*(){return this.EditorUpload.loadMTL(e,t)}))}setTransformMode(e){if("off"!==e)return this.EditorControl.setTransformMode(e);this.EditorControl.turnOffObjectClickEvent()}getTransformMode(){return this.EditorControl.getTransformMode()}setCameraView(e){"topView"===e&&this.EditorCamera.setCameraTopView()}deleteObject(){return this.EditorControl.removeClickedObject()}remove(){this.trigger("remove",{type:"remove",target:this}),this.plugins.forEach((e=>{e.remove()}))}plugin(e){e.forEach((e=>{e.init(),this.plugins.push(e)}))}}class at{constructor(){Ke.add(this)}makeMeasurementLabel(e,n){const i=document.createElement("div");i.className="measurementLabel",i.style.color="black",i.innerText=e,i.style.backgroundColor="#DDF9FB",i.style.padding="10px",i.style.borderRadius="30px";const r=new u(i),s=n.geometry.attributes.instanceStart.array,o=[s[0],s[1],s[2]],a=[s[3],s[4],s[5]];return r.position.copy(new t((o[0]+a[0])/2,(o[1]+a[1])/2,(o[2]+a[2])/2)),r}makeLineMesh(e,t){const n=new h;n.setPositions([...e,...e]);const i=new f(Object.assign({color:1956327,linewidth:.002,depthTest:!1,dashed:!0,dashSize:.03,gapSize:.05,dashOffset:.03},null==t?void 0:t.lineMaterial));i.defines.USE_DASH="";const r=new d(n,i);return r.scale.set(1,1,1),(null==t?void 0:t.lineName)&&(r.name=t.lineName),r}setupMouseCords(e,t,n){t.x=e.offsetX/n.clientWidth*2-1,t.y=-e.offsetY/n.clientHeight*2+1}getIntersectsPoints(t,n,i,r){const s=[],o=new e.Raycaster;let a=null;o.setFromCamera(t,n);const c=o.intersectObjects(i.children,!1);for(let e=0;e<c.length;e++){const t=c[e];if(p(this,Ke,"m",qe).call(this,t,r)){s.push(...t.point),a=t.object;break}}return{points:s,targetObject:a}}addObjectAsChild(t,n,i){if(null==i?void 0:i.setChildMatrixFromParent){t.updateMatrixWorld(!0),n.updateMatrixWorld(!0);const i=new e.Vector3;n.getWorldPosition(i);const r=n.matrixWorld.clone(),s=t.matrixWorld.invert();n.applyMatrix4(s.multiply(r))}t.add(n)}updateLineGeometry(e,t){var n;const i=null===(n=e.geometry.attributes.instanceStart)||void 0===n?void 0:n.array;i&&(i[3]=t[0],i[4]=t[1],i[5]=t[2],e.geometry.setPositions([...i]),e.geometry.attributes.instanceStart.needsUpdate=!0)}setLabelRenderer(e,t){const n=new m;return n.setSize(t.clientWidth,t.clientHeight),n.domElement.style.position="absolute",n.domElement.style.top="0px",n.domElement.style.pointerEvents="none",e.appendChild(n.domElement),n}makePointMesh(t,n){const i=(null==n?void 0:n.width)||1,r=(null==n?void 0:n.height)||1,s=(null==n?void 0:n.depth)||1,o=(null==n?void 0:n.color)||65280,a=new e.BoxGeometry(i,r,s),c=new e.MeshBasicMaterial(Object.assign({color:o,depthTest:!1},null==n?void 0:n.MeshStandardMaterial)),l=new e.Mesh(a,c);return l.position.set(t[0],t[1],t[2]),l.rotation.y=45,(null==n?void 0:n.meshName)&&(l.name=n.meshName),l}}Ke=new WeakSet,qe=function(e,t){var n;return"LineSegments"!==e.object.type&&"GridHelper"!==e.object.type&&"Line2"!==e.object.type&&"Line"!==e.object.type&&"TransformControlsPlane"!==e.object.type&&"TransformControls"!==(null===(n=Ve(e.object))||void 0===n?void 0:n.constructor.name)};const ct="ENTER_DISTANCE_LINE";class lt{constructor(t){Xe.add(this),Je.set(this,void 0),Ze.set(this,new e.Raycaster),Qe.set(this,new e.Vector2),et.set(this,void 0),tt.set(this,void 0),this._turnOn=!1,this._isDrawingLineMode=!1,this._line=null,this._startPointMesh=null,this._endPointMesh=null,this._textLabel={},this._startPointCord=[0,0,0],this._endPointCord=[0,0,0],nt.set(this,(e=>{const{scene:t,camera:n,canvas:i}=p(this,Je,"f"),r=p(this,Qe,"f"),s=this._isDrawingLineMode,o=p(this,tt,"f");o.setupMouseCords(e,r,i);const{points:a,targetObject:c}=o.getIntersectsPoints(r,n,t,[]);if(this._turnOn&&!s&&c){const e=o.makeLineMesh(a,{lineName:ct}),n=o.makePointMesh(a,{width:.1,height:.1,depth:.1,color:1956327});return o.addObjectAsChild(c,e,{setChildMatrixFromParent:!0}),t.add(n),this._line=e,this._startPointMesh=n,this._isDrawingLineMode=!0,void(this._startPointCord=a)}if(s&&c){if(this._isDrawingLineMode=!1,this._line){const e=o.makePointMesh(a,{width:.1,height:.1,depth:.1,color:1956327});this._endPointMesh=e,t.add(e),this._endPointCord=a,p(this,Xe,"m",rt).call(this,this._line)}}else;})),it.set(this,(e=>{if(!this._isDrawingLineMode)return;e.preventDefault();const t=this.line,{canvas:n,camera:i,scene:r}=p(this,Je,"f"),s=p(this,Ze,"f"),o=p(this,Qe,"f"),a=p(this,tt,"f");a.setupMouseCords(e,o,n);const{points:c,targetObject:l}=a.getIntersectsPoints(o,i,r,[]);s.setFromCamera(o,i),l&&t&&(a.updateLineGeometry(t,c),t.computeLineDistances())})),g(this,Je,t,"f");const{canvas:n,canvasContainer:i}=t,r=g(this,tt,new at,"f");g(this,et,r.setLabelRenderer(i,n),"f")}get line(){return this._line}get textLabel(){return this._textLabel}get isDrawingLineMode(){return this._isDrawingLineMode}init(){console.log("Raycaster.line inited")}turnOnOff(e){const{canvas:t,scene:n,camera:i}=p(this,Je,"f");if("on"===e){if(this._line)return console.warn("이미 라인이 있습니다."),void p(this,Xe,"m",rt).call(this,this._line);this._turnOn=!0,t.style.cursor="crosshair",p(this,Je,"f").EditorControl.turnOffObjectClickEvent(),t.addEventListener("pointerdown",p(this,nt,"f"),{capture:!1}),t.addEventListener("mousemove",p(this,it,"f"),{capture:!1}),p(this,Je,"f").on("render",(()=>{p(this,et,"f").render(n,i)}))}else t.style.cursor="auto",p(this,Je,"f").EditorControl.turnOnObjectClickEvent(),t.removeEventListener("pointerdown",p(this,nt,"f")),t.removeEventListener("mousemove",p(this,it,"f"))}remove(){const{canvas:e,scene:t}=p(this,Je,"f");this._turnOn=!1,this._isDrawingLineMode=!1;const n=this.line,i=this._startPointMesh,r=this._endPointMesh;n&&(t.remove(n.userData.measurementLabel),n.remove(n.userData.measurementLabel),n.removeFromParent()),i&&i.removeFromParent(),r&&r.removeFromParent(),e.removeEventListener("pointerdown",p(this,nt,"f")),e.removeEventListener("mousemove",p(this,it,"f")),this._line=null,this._startPointMesh=null,this._endPointMesh=null}loadLine(e,t,n){const{scene:i}=p(this,Je,"f"),r=p(this,tt,"f"),s=i.getObjectByName(G);if(!s)return console.warn("Mesh object가 없습니다.");const o=r.makeLineMesh(e,{lineName:ct}),a=r.makePointMesh(e,{width:.1,height:.1,depth:.1,color:1956327}),c=r.makePointMesh(t,{width:.1,height:.1,depth:.1,color:1956327});if(this._startPointMesh=a,this._line=o,this._endPointMesh=c,r.addObjectAsChild(s,o,{setChildMatrixFromParent:!0}),i.add(a),i.add(c),r.updateLineGeometry(o,t),o.computeLineDistances(),n){const e=o;if(e.userData.measurementLabel)e.userData.measurementLabel.element.innerText=`${n}m`;else{const t=r.makeMeasurementLabel(`${n}m`,e);this._textLabel[t.uuid]=t,e.userData.measurementLabel=t,e.add(t)}}}setDistanceLabel(e){const t=this._line,n=p(this,tt,"f");if(!t)return console.warn("line mesh가 존재하지 않습니다.");if(t.userData.measurementLabel)t.userData.measurementLabel.element.innerText=`${e}m`;else{const i=n.makeMeasurementLabel(`${e}m`,t);this._textLabel[i.uuid]=i,t.userData.measurementLabel=i,t.add(i)}}}var dt,ht,ft,ut,mt,vt,pt,gt;Je=new WeakMap,Ze=new WeakMap,Qe=new WeakMap,et=new WeakMap,tt=new WeakMap,nt=new WeakMap,it=new WeakMap,Xe=new WeakSet,rt=function(e){const t=p(this,tt,"f"),n=this._startPointCord,i=this._endPointCord;p(this,Je,"f").trigger("line_distance",{type:"line_distance",target:e,startPointCord:n,endPointCord:i,setLineDistance:n=>{if(e.userData.distance=n,"delete"!==n)if(e.userData.measurementLabel)e.userData.measurementLabel.element.innerText=`${n}m`;else{const i=t.makeMeasurementLabel(`${n}m`,e);this._textLabel[i.uuid]=i,e.userData.measurementLabel=i,e.add(i)}else this.remove()}})};class wt{constructor(e){dt.set(this,void 0),g(this,dt,e,"f")}setLabelRenderer(e,t){const n=new m;return n.setSize(e,t),n.domElement.style.position="absolute",n.domElement.style.top="0px",n.domElement.style.pointerEvents="none",console.log(n),document.body.appendChild(n.domElement),n}makeSphere({visible:t=!1}={}){const n=new e.SphereGeometry(.1,32,32),i=new e.MeshBasicMaterial({color:16711680}),r=new e.Mesh(n,i);return r.name=p(this,dt,"f").SPHERE_NAME,r.visible=t,r}makeMeasurementLabel(e,t){const n=document.createElement("div");n.className="measurementLabel",n.style.color="white",n.innerText=e;return new u(n)}findPointObject(e){for(let t=0;t<e.children.length;t++){const i=e.children[t];if(i instanceof n)return i}return null}}dt=new WeakMap;class bt{get generatedPoints(){return p(this,mt,"f")}constructor(t){this.SPHERE_NAME="POINT_SPHERE",ht.set(this,void 0),ft.set(this,void 0),ut.set(this,void 0),mt.set(this,[]),vt.set(this,!1),pt.set(this,void 0),gt.set(this,(t=>{if(p(this,vt,"f"))return;const n=new e.Vector2,i=new e.Raycaster,{canvas:r,camera:s,scene:o}=p(this,ht,"f"),a=p(this,pt,"f").findPointObject(o);if(!a)return;n.x=t.offsetX/r.clientWidth*2-1,n.y=-t.offsetY/r.clientHeight*2+1,i.setFromCamera(n,s);const c=p(this,mt,"f"),l=i.intersectObjects([...c,a],!1);if(p(this,ht,"f").EditorControl.detachTransform(),l[0]){if(l[0].object.name===this.SPHERE_NAME)return p(this,ht,"f").trigger("object_click",{type:"object_click",target:l[0].object}),void p(this,ht,"f").EditorControl.attachTransform(l[0].object);const e=p(this,ft,"f");e.position.copy(l[0].point),e.scale.set(1,1,1),e.visible=!0,p(this,ht,"f").EditorControl.attachTransform(e)}})),g(this,ht,t,"f");const n=g(this,pt,new wt(this),"f");g(this,ut,n.setLabelRenderer(t.canvas.clientWidth,t.canvas.clientHeight),"f");const i=g(this,ft,n.makeSphere(),"f");p(this,ht,"f").scene.add(i)}init(){const{scene:e,camera:t}=p(this,ht,"f");p(this,ht,"f").on("render",(()=>{p(this,ut,"f").render(e,t)})),p(this,ht,"f").on("resize",(()=>{const{canvas:e}=p(this,ht,"f");p(this,ut,"f").setSize(e.clientWidth,e.clientHeight)})),console.log("PickPoint init")}remove(){p(this,ht,"f").canvas.removeEventListener("mousedown",p(this,gt,"f")),g(this,vt,!1,"f"),p(this,mt,"f").forEach((e=>{e.remove()})),g(this,mt,[],"f")}turnOnOff(e){const t=p(this,ht,"f").canvas,n=e=>{g(this,vt,!0,"f")},i=e=>{g(this,vt,!1,"f")};if("on"===e&&(p(this,ht,"f").EditorControl.transformController.addEventListener("mouseDown",n),p(this,ht,"f").EditorControl.transformController.addEventListener("mouseUp",i),t.addEventListener("mousedown",p(this,gt,"f")),p(this,ht,"f").EditorControl.turnOffObjectClickEvent()),"off"===e){const e=p(this,ht,"f").canvas;p(this,ht,"f").EditorControl.transformController.removeEventListener("mouseDown",n),p(this,ht,"f").EditorControl.transformController.removeEventListener("mouseUp",i),e.removeEventListener("mousedown",p(this,gt,"f")),p(this,ht,"f").EditorControl.turnOnObjectClickEvent()}}pointGenerate(e){const t=p(this,pt,"f"),n=p(this,ft,"f");if(!n.visible)throw"point를 먼저 찍어주세요.";p(this,mt,"f").push(n);const i=t.makeMeasurementLabel(e,n);n.add(i);const r=g(this,ft,p(this,pt,"f").makeSphere(),"f");p(this,ht,"f").scene.add(r),p(this,ht,"f").EditorControl.detachTransform(),p(this,ht,"f").trigger("point_enter",{type:"point_enter",target:n,id:n.id})}removeGeneratedPoint(e){p(this,mt,"f").forEach((t=>{e===t.id&&(p(this,ht,"f").EditorControl.transformController.detach(),t.clear(),t.removeFromParent(),t.remove())}))}loadGeneratedPoints(e){const t=p(this,pt,"f");e.forEach(((e,n,i)=>{const{uuid:r,label:s,position:o}=e,a=t.makeSphere({visible:!0}),c=t.makeMeasurementLabel(s,a);a.uuid=r,a.add(c),a.position.setX(o.x),a.position.setY(o.y),a.position.setZ(o.z),p(this,ht,"f").scene.add(a),p(this,mt,"f").push(a)}))}}ht=new WeakMap,ft=new WeakMap,ut=new WeakMap,mt=new WeakMap,vt=new WeakMap,pt=new WeakMap,gt=new WeakMap;export{lt as EnterDistance,bt as PickPoint,ot as default};
