mx3d 0.4.1 → 0.4.3
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/models/FloorObject.d.ts +1 -0
- package/mx3d.min.js +1 -1
- package/package.json +1 -1
package/models/FloorObject.d.ts
CHANGED
package/mx3d.min.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#ifdef FOG
|
|
3
3
|
vFogDistance=(worldPos).xyz;
|
|
4
4
|
#endif
|
|
5
|
-
`}setTransparent(e=1){this.app.scene.clearColor=new BABYLON.Color4(this._color.r,this._color.g,this._color.b,this._color.a*e)}default(){this.color=new BABYLON.Color4(0,.0588,.1176,1)}set fogDistance(e){this.app.scene.fogDensity=1/e}set color(e){this._color=new BABYLON.Color4(e.r,e.g,e.b,e.a),this.app.scene.clearColor=this._color,this.app.scene.fogColor=new BABYLON.Color3(this._color.r,this._color.g,this._color.b)}reflex(e,t){e=new BABYLON.CubeTexture(e,this.app.scene);this.app.scene.environmentTexture=e,this.app.scene.environmentIntensity=t}setBackground(e){this.background&&this.background.dispose(),this.background=new BABYLON.Layer("background",e,this.app.scene),this.background.isBackground=!0}setReflexEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.reflexEnabled=e,this.app.scene.environmentIntensity=this.reflexEnabled?this.reflexIntensity:0,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}setFlexIntensity(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.reflexIntensity=e,this.app.scene.environmentIntensity=this.reflexIntensity,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}defaultLights(){let e=new h(this.app);e.id=a.getGUID(12),e.lightType="Hemispheric",e.name="半球光_"+this.lights.count(),e.direction=new BABYLON.Vector3(1,1,0),e.color="#FFFFFF",e.intensity=1,this.lights.add(e.id,e);let t=new h(this.app);t.id=a.getGUID(12),t.lightType="Hemispheric",t.name="半球光_"+this.lights.count(),t.direction=new BABYLON.Vector3(-1,1,0),t.color="#FFFFFF",t.intensity=.7,this.lights.add(t.id,t)}offAllLight(){for(const e in this.lights.map)this.lights.find(e).light&&(this.lights.find(e).light.intensity=0,this.app.scene.removeLight(this.lights.find(e).light),this.lights.find(e).light.dispose()),this.lights.find(e).light=null}openAllLight(){for(const e in this.lights.map)this.lights.find(e).load()}loadLight(i){for(let t=0;t<i.length;t++){var r=i[t];let e;r.lightType==n.Hemispheric?(e=new h(this.app),e.id=r.id,e.lightType=r.lightType,e.name=r.name,e.direction=p.ToVector3(r.direction),e.color=r.color,e.intensity=r.intensity):r.lightType==n.Directional?(e=new c(this.app),e.id=r.id,e.lightType=r.lightType,e.name=r.name,e.direction=p.ToVector3(r.direction),e.position=p.ToVector3(r.position),e.color=r.color,e.intensity=r.intensity):r.lightType==n.Spot?(e=new _(this.app),e.id=r.id,e.lightType=r.lightType,e.name=r.name,e.direction=p.ToVector3(r.direction),e.position=p.ToVector3(r.position),e.angle=r.angle,e.exponent=r.exponent,e.range=r.range,e.color=r.color,e.intensity=r.intensity):r.lightType==n.Point&&(e=new m(this.app),e.id=r.id,e.lightType=r.lightType,e.name=r.name,e.position=p.ToVector3(r.position),e.range=r.range,e.color=r.color,e.intensity=r.intensity),e&&this.lights.add(e.id,e)}this.lights.count()<1&&this.defaultLights(),this.openAllLight()}setLightIntensity(e=1){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,console.log(this.lights);for(const t in this.lights.map)this.lights.find(t).light.intensity=this.lights.find(t).intensity*e;this.app.scene.environmentIntensity=this.reflexIntensity*e,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}showTips(){this.app.toolTips=new g(this.app)}closeTips(){this.app.toolTips&&this.app.toolTips.dispose(),this.app.toolTips=null}showFps(e="position: absolute;left: 5px;bottom: 5px;z-index:999999999; font-size: 10px;color: rgb(0, 255, 0);text-shadow:rgba(0, 0, 0, 0.2) 1px 1px 0;"){this.app.fps||(this.app.fps=document.createElement("div"),this.app.canvas.parentElement.appendChild(this.app.fps)),this.app.fps.style.cssText=e}hideFps(){this.app.fps&&this.app.canvas.parentElement.removeChild(this.app.fps),this.app.fps=null}showDebug(){this.app.scene.debugLayer.show()}}(t=f=f||{}).Cabinet="Cabinet",t.Corner="Corner",t.Other="Other",t.Door="Door",t.Floor="Floor",t.LeakWater="LeakWater",t.UI3D="UI3D",t.VirtualBox="VirtualBox",t.Wall="Wall",t.Window="Window",t.Conduit="Conduit",t.Building="Building",t.Storey="Storey",t.Campus="Campus",(t=u=u||{}).leftClick="leftClick",t.rightClick="rightClick",t.doubleClick="doubleClick",t.eover="eover",t.longPress="longPress",t.out="out",t.click="click";class x{toJosn(e){e=JSON.parse(e);this.alpha=e.alpha,this.beta=e.beta,this.radius=e.radius,this.minimumLimit=e.minimumLimit,this.maximumLimit=e.maximumLimit,this.minBeta=e.minBeta,this.maxBeta=e.maxBeta,this.focus=p.ToVector3(e.focus)}toString(){return JSON.stringify({alpha:this.alpha,focus:p.vector3ToJson(this.focus),radius:this.radius,beta:this.beta,minimumLimit:this.minimumLimit,maximumLimit:this.maximumLimit,minBeta:this.minBeta,maxBeta:this.maxBeta})}setLimit(e,t){this.minimumLimit=e+.3,this.maximumLimit=t}setBeta(e,t){this.minBeta=e,this.maxBeta=t}}class v{constructor(e){this.app=e}getInto(){}goBack(){}loadProperties(e){this.id="墙角_"+a.getGUID(12),this.name="墙角",this.parentId=e.parentId,this.customNumber=this.id,this.objectType=f.Corner,this.customType=this.objectType,this.height=e.height,this.pints=e.corners}alwaysActive(){this.instance.getChildMeshes().forEach(e=>{e.alwaysSelectAsActiveMesh=!0,e.doNotSyncBoundingInfo=!1,e.ignoreNonUniformScaling=!0}),this.instance.alwaysSelectAsActiveMesh=!0,this.instance.doNotSyncBoundingInfo=!1}optimization(t){this.instance.getChildMeshes().forEach(e=>{t?e.freezeWorldMatrix():e.unfreezeWorldMatrix()}),t?this.instance.freezeWorldMatrix():this.instance.unfreezeWorldMatrix(),this.instance.material&&(t?this.instance.material.freeze():this.instance.material.unfreeze())}setFlash(e){}setTransparent(){}setOpaque(){}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}addEventListener(e,t){}removeEventListener(e){}computeView(){}bind(){let i=new Array;for(let t=0;t<this.pints.length;t++)if(2<this.pints[t].pints.length){let e=BABYLON.MeshBuilder.CreatePolygon(this.id,{shape:this.pints[t].pints,sideOrientation:BABYLON.Mesh.FRONTSIDE},this.app.scene);e.setEnabled(!1),e.position.y=this.pints[t].height,e.isPickable=!0,e.enablePointerMoveEvents=!1,i.push(e)}return!(i.length<1)&&(1<i.length?this.instance=p.MergeMeshes(i,this.app):this.instance=i[0],this.instance.id=this.id,this.instance.name=this.id,this.instance.position.y=this.height,this.instance.setEnabled(!1),this.instance.isPickable=!1,!(this.instance.enablePointerMoveEvents=!1))}toJson(){return{id:this.id,parentId:this.parentId,name:this.name,customNumber:this.customNumber,customType:this.customType,objectType:this.objectType}}completed(){this.alwaysActive(),this.optimization(!0)}}var b,t=i(3),w=i.n(t);class T{static init(){let e=new w.a.Tween(this.colors[1]).to({r:1,g:0,b:0},500),t=new w.a.Tween(this.colors[1]).to({r:1,g:.5,b:.5},500);t.chain(e),e.chain(t),e.start();let i=new w.a.Tween(this.colors[2]).to({r:1,g:.55,b:0},500),r=new w.a.Tween(this.colors[2]).to({r:0,g:0,b:0},500);i.chain(r),r.chain(i),i.start();let n=new w.a.Tween(this.colors[3]).to({r:1,g:.84,b:0},500),o=new w.a.Tween(this.colors[3]).to({r:0,g:0,b:0},500);n.chain(o),o.chain(n),n.start();let s=new w.a.Tween(this.colors[4]).to({r:0,g:.75,b:1},500),a=new w.a.Tween(this.colors[4]).to({r:0,g:0,b:0},500);s.chain(a),a.chain(s),s.start();let l=new w.a.Tween(this.colors[5]).to({r:.53,g:.8,b:0},500),c=new w.a.Tween(this.colors[5]).to({r:0,g:0,b:0},500);l.chain(c),c.chain(l),l.start();let h=new w.a.Tween(this.colors[6]).to({r:.8,g:.8,b:.8},500),u=new w.a.Tween(this.colors[6]).to({r:0,g:0,b:0},500);h.chain(u),u.chain(h),h.start()}}T.colors={1:BABYLON.Color3.Red(),2:new BABYLON.Color3(1,.5,0),3:BABYLON.Color3.Yellow(),4:new BABYLON.Color3(0,1,1),5:BABYLON.Color3.Green(),6:BABYLON.Color3.Gray()},(t=b=b||{})[t.Opaque=0]="Opaque",t[t.Flash=1]="Flash",t[t.Transparent=2]="Transparent";class A{constructor(e){this.executes=new d,this.clickEvents=new d,this.touchtime=(new Date).getTime(),this.statusType=b.Opaque,this.app=e}loadProperties(e){this.id=e.id,this.customNumber=e.customNumber,this.parentId=e.parentId,this.name=e.name,this.baseModel=e.baseModel,this.isLoop=e.isLoop,this.objectType=e.objectType,this.customType=e.customType,this.position=p.ToVector3(e.position),this.rotation=p.ToVector3(e.rotation),this.scaling=p.ToVector3(e.scaling)}setEnabled(e){if(this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(e=>e.dispose()),e){let t=new BABYLON.Mesh(this.id,this.app.scene),e=this.app.resources.resources.find(this.baseModel.modelId);e.meshes[0].getChildMeshes().forEach(e=>{e=e.createInstance(this.id);e.isPickable=!1,e.enablePointerMoveEvents=!1,e.parent=t}),t.rotation=p.ToVector3(this.rotation.clone()),t.position=p.ToVector3(this.position.clone()),t.scaling=p.ToVector3(this.scaling.clone()),this.instance.addChild(t),this.alwaysActive(),this.optimization(!0)}this.instance.setEnabled(e),e?(this.instance.isPickable=0<this.executes.count(),this.executes.find(u.eover)||this.executes.find(u.out)?this.instance.enablePointerMoveEvents=!0:this.instance.enablePointerMoveEvents=!1):(this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}set showBoundingBox(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.showBoundingBox=e,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}get showBoundingBox(){return this.instance.showBoundingBox}bind(){var e=this.app.resources.resources.find(this.baseModel.modelId),e=p.computeBounds(e.meshes[0]);this.instance=this.app.resources.BOX.clone(this.id),this.instance.setBoundingInfo(e),this.instance.id=this.id,this.instance.enablePointerMoveEvents=!1,this.instance.isPickable=!1,this.instance.scaling=new BABYLON.Vector3((e.maximum.x-e.minimum.x)*this.scaling.x,(e.maximum.y-e.minimum.y)*this.scaling.y,(e.maximum.z-e.minimum.z)*this.scaling.z),0==this.instance.scaling.y&&(this.instance.scaling.y=.01),this.instance.position=p.ToVector3(this.position.clone()),this.instance.position=p.ToVector3(this.position.clone()),this.instance.position.y=(e.maximum.y-e.minimum.y)/2+this.position.y,this.instance.rotation=p.ToVector3(this.rotation.clone()),this.instance.setEnabled(!1),this.completed()}completed(){this.alwaysActive(),this.optimization(!0),this.computeView()}computeView(){this.Sight=new x;var e=this.instance.getBoundingInfo(),t=p.getVisualAngle(e,this.app);this.Sight.alpha=t.alpha,this.Sight.beta=t.beta,this.Sight.focus=this.instance.getAbsolutePosition(),this.Sight.radius=5*e.boundingSphere.radius,this.Sight.minimumLimit=.3,this.Sight.maximumLimit=2*this.Sight.radius,this.Sight.minBeta=.01,this.Sight.maxBeta=Math.PI/2*.98}optimization(t){this.instance.getChildMeshes().forEach(e=>{t?e.freezeWorldMatrix():e.unfreezeWorldMatrix()}),t?this.instance.freezeWorldMatrix():this.instance.unfreezeWorldMatrix(),this.instance.material&&(t?this.instance.material.freeze():this.instance.material.unfreeze())}alwaysActive(){this.instance.getChildMeshes().forEach(e=>{e.alwaysSelectAsActiveMesh=!0,e.doNotSyncBoundingInfo=!1,e.ignoreNonUniformScaling=!0}),this.instance.alwaysSelectAsActiveMesh=!0,this.instance.doNotSyncBoundingInfo=!1}addEventListener(e,t){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;let i=null;var r;e==u.leftClick||e==u.rightClick?(this.clickEvents.remove(e),this.clickEvents.add(e,t),this.instance.isPickable=!0,i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger,e=>{let t=this.clickEvents.find(u.leftClick);t&&0==e.sourceEvent.button&&t(this,e);let i=this.clickEvents.find(u.rightClick);i&&2==e.sourceEvent.button&&i(this,e),this.touchtime=(new Date).getTime()}),e=u.click):e==u.doubleClick?i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnDoublePickTrigger,e=>t(this,e)):e==u.eover?(i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOverTrigger,e=>t(this,e)),this.instance.enablePointerMoveEvents=!0):e==u.longPress?i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnLongPressTrigger,e=>t(this,e)):e==u.out&&(i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOutTrigger,e=>t(this,e)),this.instance.enablePointerMoveEvents=!0),i&&(this.action||(this.action=new BABYLON.ActionManager(this.app.scene),this.instance.actionManager=this.action),(r=this.executes.find(e))&&this.action.unregisterAction(r),this.executes.remove(e),this.executes.add(e,i),this.action.registerAction(i)),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}removeEventListener(e){if(e==u.leftClick||e==u.rightClick||e==u.doubleClick){if(this.clickEvents.remove(e),0<this.clickEvents.count())return;e=u.click}this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;var t=this.executes.find(e);t&&this.action.unregisterAction(t),this.executes.remove(e),0==this.executes.count()&&(this.action=null,this.instance.actionManager=this.action),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}setFlash(t){this.statusType==b.Opaque&&(this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(e=>{e.instancedBuffers&&(e.instancedBuffers.color=T.colors[t])}),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1,this.statusType=b.Flash)}setOpaque(){this.statusType!=b.Opaque&&(this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(e=>{e.setEnabled(!0),e.instancedBuffers&&(e.instancedBuffers.color=new BABYLON.Color4(1,1,1,1))}),this.instance.disableEdgesRendering(),this.instance.visibility=0,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1,this.statusType=b.Opaque)}setTransparent(e=.3){this.statusType==b.Opaque&&(this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(e=>e.setEnabled(!1)),this.instance.visibility=e,this.instance.enableEdgesRendering(),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1,this.statusType=b.Transparent)}play(){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(t=>{let i;t.animations.forEach(e=>{-1!=e.name.indexOf("open")&&(i=e)}),i?this.app.scene.beginDirectAnimation(t,[i],0,10*i.getKeys().length,this.isLoop):t.animations.forEach(e=>this.app.scene.beginDirectAnimation(t,[e],0,10*e.getKeys().length,this.isLoop))}),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}stop(){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(t=>{let i;t.animations.forEach(e=>{-1!=e.name.indexOf("close")&&(i=e)}),i?this.app.scene.beginDirectAnimation(t,[i],0,10*i.getKeys().length,!1):t.animations.forEach(e=>this.app.scene.beginDirectAnimation(t,[e],10*e.getKeys().length,0,!1))}),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}toJson(){return{id:this.id,parentId:this.parentId,name:this.name,customNumber:this.customNumber,customType:this.customType,objectType:this.objectType}}getInto(){this.app.cameraController.flyTo(this.Sight)}goBack(){}}class E extends A{loadProperties(e){this.id=e.id,this.name=e.name,this.customNumber=e.customNumber,this.customType=e.customType,this.parentId=e.parentId,this.baseModel=e.baseModel,this.objectType=f.Floor,this.vectors=e.vectors,this.buckles=e.buckles,this.height=e.height}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),e?(this.instance.isPickable=0<this.executes.count(),this.executes.find(u.eover)||this.executes.find(u.out)?this.instance.enablePointerMoveEvents=!0:this.instance.enablePointerMoveEvents=!1):(this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}bind(){this.instance=BABYLON.MeshBuilder.CreatePolygon("地板",{shape:p.Expand(this.vectors,-.01),holes:this.buckles,sideOrientation:BABYLON.Mesh.DOUBLESIDE},this.app.scene),this.instance.setEnabled(!1),this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1,this.instance.position.y=this.height-.01,this.instance.id=this.id,this.instance.name="地板";var e=this.app.resources.GetMaterial(this.baseModel,this.app.scene).clone(this.id),t=this.instance.getBoundingInfo();this.Sight=p.getVisualAngle(t,this.app),this.baseModel.isTiling&&(e.diffuseTexture.uScale=(t.maximum.x-t.minimum.x)/this.baseModel.width,e.diffuseTexture.vScale=(t.maximum.z-t.minimum.z)/this.baseModel.length),this.instance.material=e,this.completed()}}class M extends A{loadProperties(e){this.id="墙_"+a.getGUID(12),this.objectType=f.Wall,this.parentId=e.parentId,this.name="墙体",this.customNumber=this.id,this.customType=this.objectType,this.walls=e.walls,this.height=e.height,this.baseModel=e.baseModel,this.baseModel&&!this.baseModel.length&&(this.baseModel.length=3.1)}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}bind(){this.instance=se.Tools.MergeMeshes(this.walls,this.app),this.instance.setEnabled(!1),this.instance.receiveShadows=!0,this.baseModel?this.nativeMaterial=this.app.resources.GetMergeMaterial(this.baseModel,this.app.scene):this.nativeMaterial=null,this.instance.material=this.nativeMaterial,this.instance.id=this.id,this.instance.name=this.id,this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1,this.instance.position.y+=this.height,this.completed()}completed(){this.alwaysActive(),this.optimization(!0)}}class S{constructor(e){this.executes=new d,this.clickEvents=new d,this.touchtime=(new Date).getTime(),this.app=e}loadProperties(e){}bind(){}completed(){this.computeView()}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}addEventListener(e,t){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;let i=null;var r;e==u.leftClick||e==u.rightClick?(this.clickEvents.remove(e),this.clickEvents.add(e,t),this.instance.isPickable=!0,i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger,e=>{let t=this.clickEvents.find(u.leftClick);t&&0==e.sourceEvent.button&&t(this,e);let i=this.clickEvents.find(u.rightClick);i&&2==e.sourceEvent.button&&i(this,e),this.touchtime=(new Date).getTime()}),e=u.click):e==u.doubleClick?i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnDoublePickTrigger,e=>t(this,e)):e==u.eover?(i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOverTrigger,e=>t(this,e)),this.instance.enablePointerMoveEvents=!0):e==u.longPress?i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnLongPressTrigger,e=>t(this,e)):e==u.out&&(i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOutTrigger,e=>t(this,e)),this.instance.enablePointerMoveEvents=!0),i&&(this.action||(this.action=new BABYLON.ActionManager(this.app.scene),this.instance.actionManager=this.action),(r=this.executes.find(e))&&this.action.unregisterAction(r),this.executes.remove(e),this.executes.add(e,i),this.action.registerAction(i)),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}removeEventListener(e){if(e==u.leftClick||e==u.rightClick||e==u.doubleClick){if(this.clickEvents.remove(e),0<this.clickEvents.count())return;e=u.click}this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;var t=this.executes.find(e);t&&this.action.unregisterAction(t),this.executes.remove(e),0==this.executes.count()&&(this.action=null,this.instance.actionManager=this.action),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}load(e,n){let s=new Array;for(let t=0;t<n.length;t++){let e=n[t];e.objectType==f.Wall&&(e.height||(e.height=3.1),e.ply||(e.ply=.09),s.push(e))}let o=new d;for(let e=0;e<n.length;e++){let i=n[e];i.objectType==f.Corner&&(o.add(i.id,i.corner),2<i.pints.length&&(i.height=3.1,i.walls.forEach(t=>{s.forEach(e=>{t==e.id&&parseFloat(e.height)<i.height&&(i.height=parseFloat(e.height))})})))}if(!e){let t=new Array;for(let e=0;e<n.length;e++){var i=n[e];i.objectType==f.Corner&&t.push(i)}let e=new v(this.app);e.loadProperties({parentId:this.id,height:this.position.y,corners:t}),e.bind()?this.app.project.objectDatas.add(e.id,e):e=null}for(let i=0;i<n.length;i++){let r=n[i];if(r.objectType==f.Floor){r.vectors=new Array;let e=n[i];e.pints.forEach(e=>{o.find(e)||console.log(e),r.vectors.push(o.find(e))}),r.buckles=new Array,e.holes&&e.holes.forEach(e=>{let t=new Array;e.forEach(e=>t.push(o.find(e))),r.buckles.push(t)}),e.middles&&e.middles.forEach(t=>{let i=Array();for(let e=0;e<n.length;e++)n[e].id==t&&n[e].pints.forEach(e=>{e=o.find(e);i.push(new BABYLON.Vector3(e.x,0,e.z))});r.buckles.push(i)}),r.height=this.position.y;let t=new E(this.app);t.loadProperties(r),t.bind(),this.app.project.objectDatas.add(t.id,t)}}if(o=null,!e){let o=new d;o.add("body",{t:"",walls:new Array});for(let n=0;n<s.length;n++){let r=BABYLON.MeshBuilder.ExtrudePolygon(s[n].id,{shape:[p.ToVector3(s[n].wtop),p.ToVector3(s[n].wleft),p.ToVector3(s[n].wbottom),p.ToVector3(s[n].wright)],depth:parseFloat(s[n].height),sideOrientation:BABYLON.Mesh.FRONTSIDE},this.app.scene);r.setEnabled(!1),r.position.y=parseFloat(s[n].height),r.subMeshes=[];var a=r.getTotalVertices();r.subMeshes.push(new BABYLON.SubMesh(0,0,a,0,6,r)),r.subMeshes.push(new BABYLON.SubMesh(0,1,a,18,6,r)),r.subMeshes.push(new BABYLON.SubMesh(0,2,a,30,6,r));for(let i=0;i<s[n].wallwindows.length;i++){const u=BABYLON.CSG.FromMesh(r);let e=this.app.project.objectDatas.find(s[n].wallwindows[i]);var l=e.instance.getBoundingInfo(),c=BABYLON.MeshBuilder.CreateBox((new Date).getTime().toString(),{height:l.maximum.y-l.minimum.y,width:l.maximum.x-l.minimum.x,depth:2*parseFloat(s[n].ply)+.1},this.app.scene);c.position=e.instance.position.clone(),c.position.y=(l.maximum.y-l.minimum.y)/2+e.height,c.rotation=e.instance.rotation.clone();l=BABYLON.CSG.FromMesh(c);let t=u.subtract(l);c.dispose(),r.dispose(),r=t.toMesh(s[n].id,null,this.app.scene,!0),r.setEnabled(!1)}let t=o.find(s[n].leftMap.modelId);t||(t={t:s[n].leftMap,walls:new Array},o.add(s[n].leftMap.modelId,t));let i=o.find(s[n].rightMap.modelId);i||(i={t:s[n].rightMap,walls:new Array},o.add(s[n].rightMap.modelId,i));var h=p.DeconsTructMesh(r,parseFloat(s[n].height),this.app);for(let e=0;e<h.length;e++)(2==e||3==e?t:4==e||5==e?i:o.find("body")).walls.push(h[e])}for(const r in o.map){var t=o.find(r);if(0<t.walls.length){let e=new M(this.app);e.loadProperties({baseModel:t.t,walls:t.walls,parentId:this.id,height:this.position.y}),e.bind(),this.app.project.objectDatas.add(e.id,e)}}}this.completed(),s=null}toJson(){return{id:this.id,parentId:this.parentId,name:this.name,customNumber:this.customNumber,customType:this.customType,objectType:this.objectType,index:this.index,layerHeight:this.layerHeight,layerName:this.layerName}}computeView(){var i,r;let n=this.app.project.getChildsById(this.id);0<n.length&&(i=r=n[0].instance.position.clone());for(let e=0;e<n.length;e++){let t=n[e];if(t.objectType!=f.Storey&&t.objectType!=f.Campus){let e=t.instance.getBoundingInfo();i=BABYLON.Vector3.Minimize(i,e.minimum.add(t.instance.position)),r=BABYLON.Vector3.Maximize(r,e.maximum.add(t.instance.position))}}i&&r||(i=BABYLON.Vector3.Zero(),r=new BABYLON.Vector3(12,0,8)),this.Sight=new x;var e=p.getVisualAngle(new BABYLON.BoundingInfo(i,r),this.app);this.Sight.alpha=e.alpha,this.Sight.beta=e.beta,this.Sight.focus=e.focus,this.Sight.radius=e.radius,this.Sight.minimumLimit=.3,this.Sight.maximumLimit=2*this.Sight.radius,this.Sight.minBeta=.01,this.Sight.maxBeta=Math.PI/2*.98}getInto(){for(var t in this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.app.project.objectDatas.map){let e=this.app.project.objectDatas.find(t);e.setEnabled(e.parentId==this.id)}this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}goBack(){}}class C extends A{loadProperties(e){this.id=e.id,this.name=e.name,this.customNumber=e.customNumber,this.customType=e.customType,this.parentId=e.parentId,this.baseModel=e.baseModel,this.height=e.baseModel.height,this.objectType=f.Door,this.rotation=p.ToVector3(e.rotation),this.position=p.ToVector3(e.position)}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),e?(this.instance.isPickable=0<this.executes.count(),this.executes.find(u.eover)||this.executes.find(u.out)?this.instance.enablePointerMoveEvents=!0:this.instance.enablePointerMoveEvents=!1):(this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}bind(){this.instance=new BABYLON.Mesh(this.id,this.app.scene);let e=this.app.resources.resources.find(this.baseModel.modelId);e.meshes[0].getChildMeshes().forEach(e=>{e.createInstance(this.id).parent=this.instance});var t=p.computeBounds(this.instance);this.instance.rotation=this.rotation.clone(),this.instance.position=this.position.clone();let i=this.app.resources.BOX.createInstance(this.id);i.setBoundingInfo(t),i.enablePointerMoveEvents=!1,i.isPickable=!1,i.scaling=new BABYLON.Vector3((t.maximum.x-t.minimum.x)*this.instance.scaling.x,(t.maximum.y-t.minimum.y)*this.instance.scaling.y,(t.maximum.z-t.minimum.z)*this.instance.scaling.z),i.position=this.instance.position.clone(),i.position.y=(t.maximum.y-t.minimum.y)/2+this.instance.position.y,i.rotation=this.instance.rotation.clone(),this.instance.getChildMeshes().forEach(e=>e.setParent(i)),this.instance.dispose(),this.instance=i,this.instance.setEnabled(!1),this.completed()}}class I extends A{loadProperties(e){this.id=e.id,this.name=e.name,this.customNumber=e.customNumber,this.customType=e.customType,this.parentId=e.parentId,this.baseModel=e.baseModel,this.height=e.baseModel.height,this.objectType=f.Window,this.rotation=p.ToVector3(e.rotation),this.position=p.ToVector3(e.position)}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),e?(this.instance.isPickable=0<this.executes.count(),this.executes.find(u.eover)||this.executes.find(u.out)?this.instance.enablePointerMoveEvents=!0:this.instance.enablePointerMoveEvents=!1):(this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}bind(){this.instance=new BABYLON.Mesh(this.id,this.app.scene);let e=this.app.resources.resources.find(this.baseModel.modelId);e.meshes[0].getChildMeshes().forEach(e=>{e.createInstance(this.id).parent=this.instance});var t=p.computeBounds(this.instance);this.instance.rotation=this.rotation.clone(),this.instance.position=this.position.clone(),this.Sight=p.getVisualAngle(t,this.app);let i=this.app.resources.BOX.createInstance(this.id);i.setBoundingInfo(t),i.enablePointerMoveEvents=!1,i.isPickable=!1,i.scaling=new BABYLON.Vector3((t.maximum.x-t.minimum.x)*this.instance.scaling.x,(t.maximum.y-t.minimum.y)*this.instance.scaling.y,(t.maximum.z-t.minimum.z)*this.instance.scaling.z),i.position=this.instance.position.clone(),i.position.y=(t.maximum.y-t.minimum.y)/2+this.instance.position.y,i.rotation=this.instance.rotation.clone(),this.instance.getChildMeshes().forEach(e=>e.setParent(i)),this.instance.dispose(),this.instance=i,this.instance.setEnabled(!1),this.completed()}}class B extends S{loadProperties(e){this.id=e.id,this.name=e.name,this.parentId=e.parentId,this.index=e.index,this.layerName=this.index<0?"B"+this.index:"F"+(this.index+1),this.layerHeight=e.layerHeight,this.objectType=e.objectType,this.customNumber=e.customNumber||e.id,this.customType=e.customType||this.objectType,this.position=p.ToVector3(e.position),this.rotation=p.ToVector3(e.rotation),this.scaling=p.ToVector3(e.scaling)}bind(){this.instance=BABYLON.MeshBuilder.CreateGround(this.id,{width:this.scaling.x,height:this.scaling.z},this.app.scene),this.instance.enablePointerMoveEvents=!1,this.instance.isPickable=!1;let e=new BABYLON.StandardMaterial("mat_"+this.id);e.diffuseColor=BABYLON.Color3.White(),e.alpha=0,e.backFaceCulling=!1,this.instance.material=e,this.instance.position=this.position,this.instance.position.y-=.01,this.instance.rotation=this.rotation.clone(),this.setEnabled(!1)}alwaysActive(){this.instance.getChildMeshes().forEach(e=>{e.alwaysSelectAsActiveMesh=!0,e.doNotSyncBoundingInfo=!1,e.ignoreNonUniformScaling=!0}),this.instance.alwaysSelectAsActiveMesh=!0,this.instance.doNotSyncBoundingInfo=!1}completed(){this.alwaysActive(),this.computeView()}computeView(){var i,r;let n=this.app.project.getChildsById(this.id);0<n.length&&(i=r=n[0].instance.position.clone());for(let e=0;e<n.length;e++){let t=n[e];if(t.objectType!=f.Storey&&t.objectType!=f.Campus&&t.objectType!=f.Wall&&t.objectType!=f.Corner){let e=t.instance.getBoundingInfo();i=BABYLON.Vector3.Minimize(i,e.minimum.add(t.instance.position)),r=BABYLON.Vector3.Maximize(r,e.maximum.add(t.instance.position))}}i&&r||(i=BABYLON.Vector3.Zero(),r=new BABYLON.Vector3(12,0,8)),this.Sight=p.getVisualAngle(new BABYLON.BoundingInfo(i,r),this.app)}}class z extends A{completed(){this.alwaysActive(),this.optimization(!0),this.computeView()}computeView(){this.Sight=new x;var e=this.instance.getBoundingInfo(),t=p.getVisualAngle(e,this.app);this.Sight.alpha=t.alpha,this.Sight.beta=t.beta,this.Sight.focus=this.position.clone(),this.Sight.radius=2*e.boundingSphere.radius,this.Sight.minimumLimit=.3,this.Sight.maximumLimit=3*this.Sight.radius,this.Sight.minBeta=.01,this.Sight.maxBeta=Math.PI/2*.98}getInto(){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;let n=new d,e=this.app.project.getChildsById(this.id);e.forEach(i=>{var r=this.app.project.getChildsById(i.id);for(let t=0;t<r.length;t++){let e=r[t];(e instanceof M||e instanceof C||e instanceof v||e instanceof I||e instanceof E)&&n.add(e.id,e.id),e instanceof M&&i instanceof B&&(e.addEventListener(u.leftClick,()=>{this.app.project.switchLevel(i.id)}),e.addEventListener(u.eover,()=>{this.app.toolTips.text=i.layerName}),e.addEventListener(u.out,()=>{this.app.toolTips.text=""}))}n.add(i.id,i.id)});for(const t in this.app.project.objectDatas.map){let e=this.app.project.objectDatas.find(t);n.find(e.id)||e.parentId==this.parentId?e.setEnabled(!0):e.setEnabled(!1)}this.setEnabled(!1),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}goBack(){this.app.toolTips.text="";let e=this.app.project.getChildsById(this.id);e.forEach(e=>{var i=this.app.project.getChildsById(e.id);for(let t=0;t<i.length;t++){let e=i[t];e instanceof M&&(e.removeEventListener(u.leftClick),e.removeEventListener(u.eover),e.removeEventListener(u.out))}})}}class k{constructor(e){this.objectDatas=new d,this.app=e}clear(){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;for(const e in this.objectDatas.map)this.objectDatas.find(e).instance&&this.objectDatas.find(e).instance.dispose();this.objectDatas.clear(),this.current=null,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}optimization(){this.app.scene.freezeActiveMeshes()}getChildsById(e=this.root.id,r=!1){e=e||this.root.id;let n=new Array;const o=e=>{for(const i in this.objectDatas.map){var t=this.objectDatas.find(i);t.parentId==e&&(n.push(t),r&&o(t.id))}};return o(e),n}getSceneTree(e=this.root.id,n=[]){e=e||this.root.id;const o=(e,r)=>{for(const t in this.objectDatas.map){let i=this.objectDatas.find(t);if(i.parentId==e){let t=!1;for(let e=0;e<n.length;e++)i.customType!=n[e]||(t=!0);t||(r.push({...i.toJson(),children:[]}),o(i.id,r[r.length-1].children))}}};let t=this.objectDatas.find(e);if(t){e={...t.toJson(),children:[]};return o(this.root.id,e.children),e}console.error("指定的层级不存在")}findObjectById(e){return this.objectDatas.find(e)}findObjectByCustomNumber(e){let t=[];for(const r in this.objectDatas.map){var i=this.objectDatas.find(r);i.customNumber==e&&t.push(i)}return 0==t.length?null:(1<t.length&&console.log("存在编号重复对象,重复个数:"+t.length),t[0])}findObjectsByCustomType(t,i={isCurrent:!1,isEnabled:!1}){let r=[];for(const n in this.objectDatas.map){let e=this.objectDatas.find(n);e.customType==t&&(i.isCurrent&&e.parentId!=this.current.id||i.isEnabled&&1!=e.instance.isEnabled()||r.push(e))}return r}findObjectsByType(e){let t=new Array;for(const r in this.objectDatas.map){var i=this.objectDatas.find(r);i.objectType==e&&t.push(i)}return t}computeSight(i){var r=BABYLON.Vector3.Zero(),n=BABYLON.Vector3.Zero();for(let e=0;e<i.length;e++){let t=i[e];if(t.objectType!=f.Storey&&t.objectType!=f.Campus){let e=t.instance.getBoundingInfo();r&&n||(r=n=e.boundingBox.center.clone()),r=BABYLON.Vector3.Minimize(r,e.minimum.add(t.instance.position)),n=BABYLON.Vector3.Maximize(n,e.maximum.add(t.instance.position))}}return r&&n||(r=BABYLON.Vector3.Zero(),n=new BABYLON.Vector3(12,0,8)),p.getVisualAngle(new BABYLON.BoundingInfo(r,n),this.app)}switchLevel(e=this.root.id,t=!0){e=e||this.root.id;let i=this.objectDatas.find(e);i?(this.current&&this.current.goBack(),i instanceof S||i instanceof z||i.parentId==this.current.id||this.objectDatas.find(i.parentId).getInto(),i.getInto(),this.current=i,this.levelEvent&&this.levelEvent(this.current),t&&(i instanceof S||i instanceof z)&&this.app.cameraController.perspective(i.Sight)):console.error("层级不存在")}goBack(){this.app.isDefaultMutual&&(this.current?this.current.parentId?(this.current.goBack&&this.current.goBack(),this.switchLevel(this.current.parentId)):console.error("已经是最顶层级!"):console.error("层级有误、未知错误!"))}getTypes(e=null){let t=[],i=new d;for(var r in this.objectDatas.map){r=this.objectDatas.find(r);e&&r.parentId!=e||i.find(r.objectType)||i.add(r.objectType,r.objectType)}for(var n in i.map)t.push(n);return t}getCustomTypes(e=null){let t=[],i=new d;for(var r in this.objectDatas.map){r=this.objectDatas.find(r);e&&r.parentId!=e||i.find(r.customType)||i.add(r.customType,r.customType)}for(var n in i.map)t.push(n);return t}}class P{constructor(e){this.walls=new d,this.resources=new d,this.ndoeMats=new d,this.Materials=new d,this.Textures=new d,this.MergeMaterials=new d,this.app=e;e=a.getGUID(12);this.transparentBox=BABYLON.MeshBuilder.CreateBox(e,{size:1},this.app.scene),this.transparentBox.alwaysSelectAsActiveMesh=!0;let t=new BABYLON.StandardMaterial(e,this.app.scene);t.diffuseTexture=new BABYLON.Texture(se.rl+"resources/white.jpg",this.app.scene,!0,!1),t.alphaMode=BABYLON.Engine.ALPHA_COMBINE,t.emissiveColor=BABYLON.Color3.Green(),this.transparentBox.material=t,this.transparentBox.setEnabled(!1),this.transparentBox.visibility=.3;e=a.getGUID(12);this.BOX=BABYLON.MeshBuilder.CreateBox(e,{size:1},this.app.scene),this.BOX.edgesColor=BABYLON.Color4.FromHexString("#4ba3fff2"),this.BOX.setEnabled(!1),this.BOX.visibility=0,this.FogTex=new BABYLON.Texture(se.rl+"resources/fogtex.png",this.app.scene,!0,!1)}async loadModelMesh(t){let i=this.resources.find(t.modelId);if(!i)try{i=await BABYLON.SceneLoader.LoadAssetContainerAsync(se.rl+"bundle/"+t.modelId+"/",t.modelId+t.extension,this.app.scene),0<i.animationGroups.length&&i.animationGroups[0].stop(),i.addAllToScene(),i.meshes[0].setEnabled(!1),i.meshes[0].getChildMeshes().forEach(e=>{e.metadata&&e.metadata.gltf&&e.metadata.gltf.extras&&(i.isExtras=!0,e.metadata.gltf.extras.U&&BABYLON.Animation.CreateAndStartAnimation("u",e.material.albedoTexture,"uOffset",30*e.metadata.gltf.extras.Uspeed,30,0,1,1),e.metadata.gltf.extras.V&&BABYLON.Animation.CreateAndStartAnimation("v",e.material.albedoTexture,"vOffset",30*e.metadata.gltf.extras.Vspeed,30,0,1,1))}),i.isExtras||i.meshes[0].getChildMeshes().forEach(e=>{e.registerInstancedBuffer("color",4),e.instancedBuffers.color=new BABYLON.Color4(1,1,1,1)}),this.resources.add(t.modelId,i)}catch(e){console.error("模型下载失败!模型编号:"+t.modelId+";错误信息:"+e)}return i}loadModelMeshAsync(t,i){var e=this.resources.find(t.modelId);e?i(e):BABYLON.SceneLoader.LoadAssetContainerAsync(se.rl+"bundle/"+t.modelId+"/",t.modelId+t.extension,this.app.scene).then(e=>{0<e.animationGroups.length&&e.animationGroups[0].stop(),this.resources.add(t.modelId,e),i(e)}).catch(()=>{console.error("模型下载失败!模型编号:"+t.modelId)})}GetMaterial(e,t){let i=this.Materials.find(e.modelId);var r;return void 0===i&&(r=this.GetTexture(e,t),i=new BABYLON.StandardMaterial(e.modelId,t),i.alphaMode=BABYLON.Engine.ALPHA_COMBINE,i.diffuseTexture=r,this.Materials.add(e.modelId,i)),i}GetTexture(e,t){let i=this.Textures.find(e.modelId);return void 0===i&&(i=new BABYLON.Texture(se.rl+"texture/"+e.modelId+e.extension,t,!1),".png"==e.extension&&(i.hasAlpha=!0),this.Textures.add(e.modelId,i)),i}GetMergeMaterial(t,i){let r=this.MergeMaterials.find(t.modelId);if(void 0===r){r=new BABYLON.CustomMaterial(t.modelId,i),r.alphaMode=2,this.MergeMaterials.add(t.modelId,r),r.AddUniform("textureData","sampler2D",null),r.Vertex_Definitions(`
|
|
5
|
+
`}setTransparent(e=1){this.app.scene.clearColor=new BABYLON.Color4(this._color.r,this._color.g,this._color.b,this._color.a*e)}default(){this.color=new BABYLON.Color4(0,.0588,.1176,1)}set fogDistance(e){this.app.scene.fogDensity=1/e}set color(e){this._color=new BABYLON.Color4(e.r,e.g,e.b,e.a),this.app.scene.clearColor=this._color,this.app.scene.fogColor=new BABYLON.Color3(this._color.r,this._color.g,this._color.b)}reflex(e,t){e=new BABYLON.CubeTexture(e,this.app.scene);this.app.scene.environmentTexture=e,this.app.scene.environmentIntensity=t}setBackground(e){this.background&&this.background.dispose(),this.background=new BABYLON.Layer("background",e,this.app.scene),this.background.isBackground=!0}setReflexEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.reflexEnabled=e,this.app.scene.environmentIntensity=this.reflexEnabled?this.reflexIntensity:0,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}setFlexIntensity(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.reflexIntensity=e,this.app.scene.environmentIntensity=this.reflexIntensity,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}defaultLights(){let e=new h(this.app);e.id=a.getGUID(12),e.lightType="Hemispheric",e.name="半球光_"+this.lights.count(),e.direction=new BABYLON.Vector3(1,1,0),e.color="#FFFFFF",e.intensity=1,this.lights.add(e.id,e);let t=new h(this.app);t.id=a.getGUID(12),t.lightType="Hemispheric",t.name="半球光_"+this.lights.count(),t.direction=new BABYLON.Vector3(-1,1,0),t.color="#FFFFFF",t.intensity=.7,this.lights.add(t.id,t)}offAllLight(){for(const e in this.lights.map)this.lights.find(e).light&&(this.lights.find(e).light.intensity=0,this.app.scene.removeLight(this.lights.find(e).light),this.lights.find(e).light.dispose()),this.lights.find(e).light=null}openAllLight(){for(const e in this.lights.map)this.lights.find(e).load()}loadLight(i){for(let t=0;t<i.length;t++){var r=i[t];let e;r.lightType==n.Hemispheric?(e=new h(this.app),e.id=r.id,e.lightType=r.lightType,e.name=r.name,e.direction=p.ToVector3(r.direction),e.color=r.color,e.intensity=r.intensity):r.lightType==n.Directional?(e=new c(this.app),e.id=r.id,e.lightType=r.lightType,e.name=r.name,e.direction=p.ToVector3(r.direction),e.position=p.ToVector3(r.position),e.color=r.color,e.intensity=r.intensity):r.lightType==n.Spot?(e=new _(this.app),e.id=r.id,e.lightType=r.lightType,e.name=r.name,e.direction=p.ToVector3(r.direction),e.position=p.ToVector3(r.position),e.angle=r.angle,e.exponent=r.exponent,e.range=r.range,e.color=r.color,e.intensity=r.intensity):r.lightType==n.Point&&(e=new m(this.app),e.id=r.id,e.lightType=r.lightType,e.name=r.name,e.position=p.ToVector3(r.position),e.range=r.range,e.color=r.color,e.intensity=r.intensity),e&&this.lights.add(e.id,e)}this.lights.count()<1&&this.defaultLights(),this.openAllLight()}setLightIntensity(e=1){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,console.log(this.lights);for(const t in this.lights.map)this.lights.find(t).light.intensity=this.lights.find(t).intensity*e;this.app.scene.environmentIntensity=this.reflexIntensity*e,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}showTips(){this.app.toolTips=new g(this.app)}closeTips(){this.app.toolTips&&this.app.toolTips.dispose(),this.app.toolTips=null}showFps(e="position: absolute;left: 5px;bottom: 5px;z-index:999999999; font-size: 10px;color: rgb(0, 255, 0);text-shadow:rgba(0, 0, 0, 0.2) 1px 1px 0;"){this.app.fps||(this.app.fps=document.createElement("div"),this.app.canvas.parentElement.appendChild(this.app.fps)),this.app.fps.style.cssText=e}hideFps(){this.app.fps&&this.app.canvas.parentElement.removeChild(this.app.fps),this.app.fps=null}showDebug(){this.app.scene.debugLayer.show()}}(t=f=f||{}).Cabinet="Cabinet",t.Corner="Corner",t.Other="Other",t.Door="Door",t.Floor="Floor",t.LeakWater="LeakWater",t.UI3D="UI3D",t.VirtualBox="VirtualBox",t.Wall="Wall",t.Window="Window",t.Conduit="Conduit",t.Building="Building",t.Storey="Storey",t.Campus="Campus",(t=u=u||{}).leftClick="leftClick",t.rightClick="rightClick",t.doubleClick="doubleClick",t.eover="eover",t.longPress="longPress",t.out="out",t.click="click";class x{toJosn(e){e=JSON.parse(e);this.alpha=e.alpha,this.beta=e.beta,this.radius=e.radius,this.minimumLimit=e.minimumLimit,this.maximumLimit=e.maximumLimit,this.minBeta=e.minBeta,this.maxBeta=e.maxBeta,this.focus=p.ToVector3(e.focus)}toString(){return JSON.stringify({alpha:this.alpha,focus:p.vector3ToJson(this.focus),radius:this.radius,beta:this.beta,minimumLimit:this.minimumLimit,maximumLimit:this.maximumLimit,minBeta:this.minBeta,maxBeta:this.maxBeta})}setLimit(e,t){this.minimumLimit=e+.3,this.maximumLimit=t}setBeta(e,t){this.minBeta=e,this.maxBeta=t}}class v{constructor(e){this.app=e}getInto(){}goBack(){}loadProperties(e){this.id="墙角_"+a.getGUID(12),this.name="墙角",this.parentId=e.parentId,this.customNumber=this.id,this.objectType=f.Corner,this.customType=this.objectType,this.height=e.height,this.pints=e.corners}alwaysActive(){this.instance.getChildMeshes().forEach(e=>{e.alwaysSelectAsActiveMesh=!0,e.doNotSyncBoundingInfo=!1,e.ignoreNonUniformScaling=!0}),this.instance.alwaysSelectAsActiveMesh=!0,this.instance.doNotSyncBoundingInfo=!1}optimization(t){this.instance.getChildMeshes().forEach(e=>{t?e.freezeWorldMatrix():e.unfreezeWorldMatrix()}),t?this.instance.freezeWorldMatrix():this.instance.unfreezeWorldMatrix(),this.instance.material&&(t?this.instance.material.freeze():this.instance.material.unfreeze())}setFlash(e){}setTransparent(){}setOpaque(){}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}addEventListener(e,t){}removeEventListener(e){}computeView(){}bind(){let i=new Array;for(let t=0;t<this.pints.length;t++)if(2<this.pints[t].pints.length){let e=BABYLON.MeshBuilder.CreatePolygon(this.id,{shape:this.pints[t].pints,sideOrientation:BABYLON.Mesh.FRONTSIDE},this.app.scene);e.setEnabled(!1),e.position.y=this.pints[t].height,e.isPickable=!0,e.enablePointerMoveEvents=!1,i.push(e)}return!(i.length<1)&&(1<i.length?this.instance=p.MergeMeshes(i,this.app):this.instance=i[0],this.instance.id=this.id,this.instance.name=this.id,this.instance.position.y=this.height,this.instance.setEnabled(!1),this.instance.isPickable=!1,!(this.instance.enablePointerMoveEvents=!1))}toJson(){return{id:this.id,parentId:this.parentId,name:this.name,customNumber:this.customNumber,customType:this.customType,objectType:this.objectType}}completed(){this.alwaysActive(),this.optimization(!0)}}var b,t=i(3),w=i.n(t);class T{static init(){let e=new w.a.Tween(this.colors[1]).to({r:1,g:0,b:0},500),t=new w.a.Tween(this.colors[1]).to({r:1,g:.5,b:.5},500);t.chain(e),e.chain(t),e.start();let i=new w.a.Tween(this.colors[2]).to({r:1,g:.55,b:0},500),r=new w.a.Tween(this.colors[2]).to({r:0,g:0,b:0},500);i.chain(r),r.chain(i),i.start();let n=new w.a.Tween(this.colors[3]).to({r:1,g:.84,b:0},500),o=new w.a.Tween(this.colors[3]).to({r:0,g:0,b:0},500);n.chain(o),o.chain(n),n.start();let s=new w.a.Tween(this.colors[4]).to({r:0,g:.75,b:1},500),a=new w.a.Tween(this.colors[4]).to({r:0,g:0,b:0},500);s.chain(a),a.chain(s),s.start();let l=new w.a.Tween(this.colors[5]).to({r:.53,g:.8,b:0},500),c=new w.a.Tween(this.colors[5]).to({r:0,g:0,b:0},500);l.chain(c),c.chain(l),l.start();let h=new w.a.Tween(this.colors[6]).to({r:.8,g:.8,b:.8},500),u=new w.a.Tween(this.colors[6]).to({r:0,g:0,b:0},500);h.chain(u),u.chain(h),h.start()}}T.colors={1:BABYLON.Color3.Red(),2:new BABYLON.Color3(1,.5,0),3:BABYLON.Color3.Yellow(),4:new BABYLON.Color3(0,1,1),5:BABYLON.Color3.Green(),6:BABYLON.Color3.Gray()},(t=b=b||{})[t.Opaque=0]="Opaque",t[t.Flash=1]="Flash",t[t.Transparent=2]="Transparent";class A{constructor(e){this.executes=new d,this.clickEvents=new d,this.touchtime=(new Date).getTime(),this.statusType=b.Opaque,this.app=e}loadProperties(e){this.id=e.id,this.customNumber=e.customNumber,this.parentId=e.parentId,this.name=e.name,this.baseModel=e.baseModel,this.isLoop=e.isLoop,this.objectType=e.objectType,this.customType=e.customType,this.position=p.ToVector3(e.position),this.rotation=p.ToVector3(e.rotation),this.scaling=p.ToVector3(e.scaling)}setEnabled(e){if(this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(e=>e.dispose()),e){let t=new BABYLON.Mesh(this.id,this.app.scene),e=this.app.resources.resources.find(this.baseModel.modelId);e.meshes[0].getChildMeshes().forEach(e=>{e=e.createInstance(this.id);e.isPickable=!1,e.enablePointerMoveEvents=!1,e.parent=t}),t.rotation=p.ToVector3(this.rotation.clone()),t.position=p.ToVector3(this.position.clone()),t.scaling=p.ToVector3(this.scaling.clone()),this.instance.addChild(t),this.alwaysActive(),this.optimization(!0)}this.instance.setEnabled(e),e?(this.instance.isPickable=0<this.executes.count(),this.executes.find(u.eover)||this.executes.find(u.out)?this.instance.enablePointerMoveEvents=!0:this.instance.enablePointerMoveEvents=!1):(this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1),this.statusType=b.Opaque,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}set showBoundingBox(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.showBoundingBox=e,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}get showBoundingBox(){return this.instance.showBoundingBox}bind(){var e=this.app.resources.resources.find(this.baseModel.modelId),e=p.computeBounds(e.meshes[0]);this.instance=this.app.resources.BOX.clone(this.id),this.instance.id=this.id,this.instance.enablePointerMoveEvents=!1,this.instance.isPickable=!1,this.instance.scaling=new BABYLON.Vector3((e.maximum.x-e.minimum.x)*this.scaling.x,(e.maximum.y-e.minimum.y)*this.scaling.y,(e.maximum.z-e.minimum.z)*this.scaling.z),0==this.instance.scaling.y&&(this.instance.scaling.y=.01),this.instance.position=p.ToVector3(this.position.clone()),this.instance.position=p.ToVector3(this.position.clone()),this.instance.position.y=(e.maximum.y-e.minimum.y)/2+this.position.y,this.instance.rotation=p.ToVector3(this.rotation.clone()),this.instance.setEnabled(!1),this.completed()}completed(){this.alwaysActive(),this.optimization(!0),this.computeView()}computeView(){this.Sight=new x;var e=this.instance.getBoundingInfo(),t=p.getVisualAngle(e,this.app);this.Sight.alpha=t.alpha,this.Sight.beta=t.beta,this.Sight.focus=this.instance.getAbsolutePosition(),this.Sight.radius=5*e.boundingSphere.radius,this.Sight.minimumLimit=.3,this.Sight.maximumLimit=2*this.Sight.radius,this.Sight.minBeta=.01,this.Sight.maxBeta=Math.PI/2*.98}optimization(t){this.instance.getChildMeshes().forEach(e=>{t?e.freezeWorldMatrix():e.unfreezeWorldMatrix()}),t?this.instance.freezeWorldMatrix():this.instance.unfreezeWorldMatrix(),this.instance.material&&(t?this.instance.material.freeze():this.instance.material.unfreeze())}alwaysActive(){this.instance.getChildMeshes().forEach(e=>{e.alwaysSelectAsActiveMesh=!0,e.doNotSyncBoundingInfo=!1,e.ignoreNonUniformScaling=!0}),this.instance.alwaysSelectAsActiveMesh=!0,this.instance.doNotSyncBoundingInfo=!1}addEventListener(e,t){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;let i=null;var r;e==u.leftClick||e==u.rightClick?(this.clickEvents.remove(e),this.clickEvents.add(e,t),this.instance.isPickable=!0,i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger,e=>{let t=this.clickEvents.find(u.leftClick);t&&0==e.sourceEvent.button&&t(this,e);let i=this.clickEvents.find(u.rightClick);i&&2==e.sourceEvent.button&&i(this,e),this.touchtime=(new Date).getTime()}),e=u.click):e==u.doubleClick?i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnDoublePickTrigger,e=>t(this,e)):e==u.eover?(i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOverTrigger,e=>t(this,e)),this.instance.enablePointerMoveEvents=!0):e==u.longPress?i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnLongPressTrigger,e=>t(this,e)):e==u.out&&(i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOutTrigger,e=>t(this,e)),this.instance.enablePointerMoveEvents=!0),i&&(this.action||(this.action=new BABYLON.ActionManager(this.app.scene),this.instance.actionManager=this.action),(r=this.executes.find(e))&&this.action.unregisterAction(r),this.executes.remove(e),this.executes.add(e,i),this.action.registerAction(i)),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}removeEventListener(e){if(e==u.leftClick||e==u.rightClick||e==u.doubleClick){if(this.clickEvents.remove(e),0<this.clickEvents.count())return;e=u.click}this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;var t=this.executes.find(e);t&&this.action.unregisterAction(t),this.executes.remove(e),0==this.executes.count()&&(this.action=null,this.instance.actionManager=this.action),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}setFlash(t){this.statusType==b.Opaque&&(this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(e=>{e.instancedBuffers&&(e.instancedBuffers.color=T.colors[t])}),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1,this.statusType=b.Flash)}setOpaque(){this.statusType!=b.Opaque&&(this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(e=>{e.setEnabled(!0),e.instancedBuffers&&(e.instancedBuffers.color=new BABYLON.Color4(1,1,1,1))}),this.instance.disableEdgesRendering(),this.instance.visibility=0,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1,this.statusType=b.Opaque)}setTransparent(e=.3){this.statusType==b.Opaque&&(this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(e=>e.setEnabled(!1)),this.instance.visibility=e,this.instance.enableEdgesRendering(),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1,this.statusType=b.Transparent)}play(){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(t=>{let i;t.animations.forEach(e=>{-1!=e.name.indexOf("open")&&(i=e)}),i?this.app.scene.beginDirectAnimation(t,[i],0,10*i.getKeys().length,this.isLoop):t.animations.forEach(e=>this.app.scene.beginDirectAnimation(t,[e],0,10*e.getKeys().length,this.isLoop))}),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}stop(){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.getChildMeshes().forEach(t=>{let i;t.animations.forEach(e=>{-1!=e.name.indexOf("close")&&(i=e)}),i?this.app.scene.beginDirectAnimation(t,[i],0,10*i.getKeys().length,!1):t.animations.forEach(e=>this.app.scene.beginDirectAnimation(t,[e],10*e.getKeys().length,0,!1))}),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}toJson(){return{id:this.id,parentId:this.parentId,name:this.name,customNumber:this.customNumber,customType:this.customType,objectType:this.objectType}}getInto(){this.app.cameraController.flyTo(this.Sight)}goBack(){}}class E extends A{loadProperties(e){this.id=e.id,this.name=e.name,this.customNumber=e.customNumber,this.customType=e.customType,this.parentId=e.parentId,this.baseModel=e.baseModel,this.objectType=f.Floor,this.vectors=e.vectors,this.buckles=e.buckles,this.height=e.height}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),e?(this.instance.isPickable=0<this.executes.count(),this.executes.find(u.eover)||this.executes.find(u.out)?this.instance.enablePointerMoveEvents=!0:this.instance.enablePointerMoveEvents=!1):(this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}bind(){this.instance=BABYLON.MeshBuilder.CreatePolygon("地板",{shape:p.Expand(this.vectors,-.01),holes:this.buckles,sideOrientation:BABYLON.Mesh.DOUBLESIDE},this.app.scene),this.instance.setEnabled(!1),this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1,this.instance.position.y=this.height-.01,this.instance.id=this.id,this.instance.name="地板";var e=this.app.resources.GetMaterial(this.baseModel,this.app.scene).clone(this.id),t=this.instance.getBoundingInfo();this.Sight=p.getVisualAngle(t,this.app),this.baseModel.isTiling&&(e.diffuseTexture.uScale=(t.maximum.x-t.minimum.x)/this.baseModel.width,e.diffuseTexture.vScale=(t.maximum.z-t.minimum.z)/this.baseModel.length),this.instance.material=e,this.completed()}computeView(){this.Sight=new x;let e=this.instance.getBoundingInfo();var t=p.getVisualAngle(e,this.app);this.Sight.alpha=t.alpha,this.Sight.beta=t.beta,this.Sight.focus=e.boundingBox.center.clone(),this.Sight.focus.y=this.instance.position.y,this.Sight.radius=5*e.boundingSphere.radius,this.Sight.minimumLimit=.3,this.Sight.maximumLimit=2*this.Sight.radius,this.Sight.minBeta=.01,this.Sight.maxBeta=Math.PI/2*.98}}class M extends A{loadProperties(e){this.id="墙_"+a.getGUID(12),this.objectType=f.Wall,this.parentId=e.parentId,this.name="墙体",this.customNumber=this.id,this.customType=this.objectType,this.walls=e.walls,this.height=e.height,this.baseModel=e.baseModel,this.baseModel&&!this.baseModel.length&&(this.baseModel.length=3.1)}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}bind(){this.instance=se.Tools.MergeMeshes(this.walls,this.app),this.instance.setEnabled(!1),this.instance.receiveShadows=!0,this.baseModel?this.nativeMaterial=this.app.resources.GetMergeMaterial(this.baseModel,this.app.scene):this.nativeMaterial=null,this.instance.material=this.nativeMaterial,this.instance.id=this.id,this.instance.name=this.id,this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1,this.instance.position.y+=this.height,this.completed()}completed(){this.alwaysActive(),this.optimization(!0)}}class S{constructor(e){this.executes=new d,this.clickEvents=new d,this.touchtime=(new Date).getTime(),this.app=e}loadProperties(e){}bind(){}completed(){this.computeView()}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}addEventListener(e,t){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;let i=null;var r;e==u.leftClick||e==u.rightClick?(this.clickEvents.remove(e),this.clickEvents.add(e,t),this.instance.isPickable=!0,i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger,e=>{let t=this.clickEvents.find(u.leftClick);t&&0==e.sourceEvent.button&&t(this,e);let i=this.clickEvents.find(u.rightClick);i&&2==e.sourceEvent.button&&i(this,e),this.touchtime=(new Date).getTime()}),e=u.click):e==u.doubleClick?i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnDoublePickTrigger,e=>t(this,e)):e==u.eover?(i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOverTrigger,e=>t(this,e)),this.instance.enablePointerMoveEvents=!0):e==u.longPress?i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnLongPressTrigger,e=>t(this,e)):e==u.out&&(i=new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOutTrigger,e=>t(this,e)),this.instance.enablePointerMoveEvents=!0),i&&(this.action||(this.action=new BABYLON.ActionManager(this.app.scene),this.instance.actionManager=this.action),(r=this.executes.find(e))&&this.action.unregisterAction(r),this.executes.remove(e),this.executes.add(e,i),this.action.registerAction(i)),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}removeEventListener(e){if(e==u.leftClick||e==u.rightClick||e==u.doubleClick){if(this.clickEvents.remove(e),0<this.clickEvents.count())return;e=u.click}this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;var t=this.executes.find(e);t&&this.action.unregisterAction(t),this.executes.remove(e),0==this.executes.count()&&(this.action=null,this.instance.actionManager=this.action),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}load(e,n){let s=new Array;for(let t=0;t<n.length;t++){let e=n[t];e.objectType==f.Wall&&(e.height||(e.height=3.1),e.ply||(e.ply=.09),s.push(e))}let o=new d;for(let e=0;e<n.length;e++){let i=n[e];i.objectType==f.Corner&&(o.add(i.id,i.corner),2<i.pints.length&&(i.height=3.1,i.walls.forEach(t=>{s.forEach(e=>{t==e.id&&parseFloat(e.height)<i.height&&(i.height=parseFloat(e.height))})})))}if(!e){let t=new Array;for(let e=0;e<n.length;e++){var i=n[e];i.objectType==f.Corner&&t.push(i)}let e=new v(this.app);e.loadProperties({parentId:this.id,height:this.position.y,corners:t}),e.bind()?this.app.project.objectDatas.add(e.id,e):e=null}for(let i=0;i<n.length;i++){let r=n[i];if(r.objectType==f.Floor){r.vectors=new Array;let e=n[i];e.pints.forEach(e=>{o.find(e)||console.log(e),r.vectors.push(o.find(e))}),r.buckles=new Array,e.holes&&e.holes.forEach(e=>{let t=new Array;e.forEach(e=>t.push(o.find(e))),r.buckles.push(t)}),e.middles&&e.middles.forEach(t=>{let i=Array();for(let e=0;e<n.length;e++)n[e].id==t&&n[e].pints.forEach(e=>{e=o.find(e);i.push(new BABYLON.Vector3(e.x,0,e.z))});r.buckles.push(i)}),r.height=this.position.y;let t=new E(this.app);t.loadProperties(r),t.bind(),this.app.project.objectDatas.add(t.id,t)}}if(o=null,!e){let o=new d;o.add("body",{t:"",walls:new Array});for(let n=0;n<s.length;n++){let r=BABYLON.MeshBuilder.ExtrudePolygon(s[n].id,{shape:[p.ToVector3(s[n].wtop),p.ToVector3(s[n].wleft),p.ToVector3(s[n].wbottom),p.ToVector3(s[n].wright)],depth:parseFloat(s[n].height),sideOrientation:BABYLON.Mesh.FRONTSIDE},this.app.scene);r.setEnabled(!1),r.position.y=parseFloat(s[n].height),r.subMeshes=[];var a=r.getTotalVertices();r.subMeshes.push(new BABYLON.SubMesh(0,0,a,0,6,r)),r.subMeshes.push(new BABYLON.SubMesh(0,1,a,18,6,r)),r.subMeshes.push(new BABYLON.SubMesh(0,2,a,30,6,r));for(let i=0;i<s[n].wallwindows.length;i++){const u=BABYLON.CSG.FromMesh(r);let e=this.app.project.objectDatas.find(s[n].wallwindows[i]);var l=e.instance.getBoundingInfo(),c=BABYLON.MeshBuilder.CreateBox((new Date).getTime().toString(),{height:l.maximum.y-l.minimum.y,width:l.maximum.x-l.minimum.x,depth:2*parseFloat(s[n].ply)+.1},this.app.scene);c.position=e.instance.position.clone(),c.position.y=(l.maximum.y-l.minimum.y)/2+e.height,c.rotation=e.instance.rotation.clone();l=BABYLON.CSG.FromMesh(c);let t=u.subtract(l);c.dispose(),r.dispose(),r=t.toMesh(s[n].id,null,this.app.scene,!0),r.setEnabled(!1)}let t=o.find(s[n].leftMap.modelId);t||(t={t:s[n].leftMap,walls:new Array},o.add(s[n].leftMap.modelId,t));let i=o.find(s[n].rightMap.modelId);i||(i={t:s[n].rightMap,walls:new Array},o.add(s[n].rightMap.modelId,i));var h=p.DeconsTructMesh(r,parseFloat(s[n].height),this.app);for(let e=0;e<h.length;e++)(2==e||3==e?t:4==e||5==e?i:o.find("body")).walls.push(h[e])}for(const r in o.map){var t=o.find(r);if(0<t.walls.length){let e=new M(this.app);e.loadProperties({baseModel:t.t,walls:t.walls,parentId:this.id,height:this.position.y}),e.bind(),this.app.project.objectDatas.add(e.id,e)}}}this.completed(),s=null}toJson(){return{id:this.id,parentId:this.parentId,name:this.name,customNumber:this.customNumber,customType:this.customType,objectType:this.objectType,index:this.index,layerHeight:this.layerHeight,layerName:this.layerName}}computeView(){var i,r;let n=this.app.project.getChildsById(this.id,!0);0<n.length&&(i=r=n[0].instance.position.clone());for(let e=0;e<n.length;e++){let t=n[e];if(t.objectType!=f.Storey&&t.objectType!=f.Campus){let e=t.instance.getBoundingInfo();i=BABYLON.Vector3.Minimize(i,e.minimum.add(t.instance.position)),r=BABYLON.Vector3.Maximize(r,e.maximum.add(t.instance.position))}}i&&r||(i=BABYLON.Vector3.Zero(),r=new BABYLON.Vector3(12,0,8)),this.Sight=new x;var e=p.getVisualAngle(new BABYLON.BoundingInfo(i,r),this.app);this.Sight.alpha=e.alpha,this.Sight.beta=e.beta,this.Sight.focus=e.focus,this.Sight.radius=e.radius,this.Sight.minimumLimit=.3,this.Sight.maximumLimit=2*this.Sight.radius,this.Sight.minBeta=.01,this.Sight.maxBeta=Math.PI/2*.98}getInto(){for(var t in this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.app.project.objectDatas.map){let e=this.app.project.objectDatas.find(t);e.setEnabled(e.parentId==this.id)}this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}goBack(){}}class C extends A{loadProperties(e){this.id=e.id,this.name=e.name,this.customNumber=e.customNumber,this.customType=e.customType,this.parentId=e.parentId,this.baseModel=e.baseModel,this.height=e.baseModel.height,this.objectType=f.Door,this.rotation=p.ToVector3(e.rotation),this.position=p.ToVector3(e.position)}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),e?(this.instance.isPickable=0<this.executes.count(),this.executes.find(u.eover)||this.executes.find(u.out)?this.instance.enablePointerMoveEvents=!0:this.instance.enablePointerMoveEvents=!1):(this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}bind(){this.instance=new BABYLON.Mesh(this.id,this.app.scene);let e=this.app.resources.resources.find(this.baseModel.modelId);e.meshes[0].getChildMeshes().forEach(e=>{e.createInstance(this.id).parent=this.instance});var t=p.computeBounds(this.instance);this.instance.rotation=this.rotation.clone(),this.instance.position=this.position.clone();let i=this.app.resources.BOX.createInstance(this.id);i.setBoundingInfo(t),i.enablePointerMoveEvents=!1,i.isPickable=!1,i.scaling=new BABYLON.Vector3((t.maximum.x-t.minimum.x)*this.instance.scaling.x,(t.maximum.y-t.minimum.y)*this.instance.scaling.y,(t.maximum.z-t.minimum.z)*this.instance.scaling.z),i.position=this.instance.position.clone(),i.position.y=(t.maximum.y-t.minimum.y)/2+this.instance.position.y,i.rotation=this.instance.rotation.clone(),this.instance.getChildMeshes().forEach(e=>e.setParent(i)),this.instance.dispose(),this.instance=i,this.instance.setEnabled(!1),this.completed()}}class I extends A{loadProperties(e){this.id=e.id,this.name=e.name,this.customNumber=e.customNumber,this.customType=e.customType,this.parentId=e.parentId,this.baseModel=e.baseModel,this.height=e.baseModel.height,this.objectType=f.Window,this.rotation=p.ToVector3(e.rotation),this.position=p.ToVector3(e.position)}setEnabled(e){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0,this.instance.setEnabled(e),e?(this.instance.isPickable=0<this.executes.count(),this.executes.find(u.eover)||this.executes.find(u.out)?this.instance.enablePointerMoveEvents=!0:this.instance.enablePointerMoveEvents=!1):(this.instance.isPickable=!1,this.instance.enablePointerMoveEvents=!1),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}bind(){this.instance=new BABYLON.Mesh(this.id,this.app.scene);let e=this.app.resources.resources.find(this.baseModel.modelId);e.meshes[0].getChildMeshes().forEach(e=>{e.createInstance(this.id).parent=this.instance});var t=p.computeBounds(this.instance);this.instance.rotation=this.rotation.clone(),this.instance.position=this.position.clone(),this.Sight=p.getVisualAngle(t,this.app);let i=this.app.resources.BOX.createInstance(this.id);i.setBoundingInfo(t),i.enablePointerMoveEvents=!1,i.isPickable=!1,i.scaling=new BABYLON.Vector3((t.maximum.x-t.minimum.x)*this.instance.scaling.x,(t.maximum.y-t.minimum.y)*this.instance.scaling.y,(t.maximum.z-t.minimum.z)*this.instance.scaling.z),i.position=this.instance.position.clone(),i.position.y=(t.maximum.y-t.minimum.y)/2+this.instance.position.y,i.rotation=this.instance.rotation.clone(),this.instance.getChildMeshes().forEach(e=>e.setParent(i)),this.instance.dispose(),this.instance=i,this.instance.setEnabled(!1),this.completed()}}class B extends S{loadProperties(e){this.id=e.id,this.name=e.name,this.parentId=e.parentId,this.index=e.index,this.layerName=this.index<0?"B"+this.index:"F"+(this.index+1),this.layerHeight=e.layerHeight,this.objectType=e.objectType,this.customNumber=e.customNumber||e.id,this.customType=e.customType||this.objectType,this.position=p.ToVector3(e.position),this.rotation=p.ToVector3(e.rotation),this.scaling=p.ToVector3(e.scaling)}bind(){this.instance=BABYLON.MeshBuilder.CreateGround(this.id,{width:this.scaling.x,height:this.scaling.z},this.app.scene),this.instance.enablePointerMoveEvents=!1,this.instance.isPickable=!1;let e=new BABYLON.StandardMaterial("mat_"+this.id);e.diffuseColor=BABYLON.Color3.White(),e.alpha=0,e.backFaceCulling=!1,this.instance.material=e,this.instance.position=this.position,this.instance.position.y-=.01,this.instance.rotation=this.rotation.clone(),this.setEnabled(!1)}alwaysActive(){this.instance.getChildMeshes().forEach(e=>{e.alwaysSelectAsActiveMesh=!0,e.doNotSyncBoundingInfo=!1,e.ignoreNonUniformScaling=!0}),this.instance.alwaysSelectAsActiveMesh=!0,this.instance.doNotSyncBoundingInfo=!1}completed(){this.alwaysActive(),this.computeView()}computeView(){var i,r;let n=this.app.project.getChildsById(this.id);0<n.length&&(i=r=n[0].instance.position.clone());for(let e=0;e<n.length;e++){let t=n[e];if(t.objectType!=f.Storey&&t.objectType!=f.Campus&&t.objectType!=f.Wall&&t.objectType!=f.Corner){let e=t.instance.getBoundingInfo();i=BABYLON.Vector3.Minimize(i,e.minimum.add(t.instance.position)),r=BABYLON.Vector3.Maximize(r,e.maximum.add(t.instance.position))}}i&&r||(i=BABYLON.Vector3.Zero(),r=new BABYLON.Vector3(12,0,8)),this.Sight=p.getVisualAngle(new BABYLON.BoundingInfo(i,r),this.app)}}class z extends A{completed(){this.alwaysActive(),this.optimization(!0),this.computeView()}computeView(){var e=this.app.resources.resources.find(this.baseModel.modelId);this.instance.setBoundingInfo(p.computeBounds(e.meshes[0])),this.Sight=new x;var t=this.instance.getBoundingInfo(),e=p.getVisualAngle(t,this.app);this.Sight.alpha=e.alpha,this.Sight.beta=e.beta,this.Sight.focus=this.position.clone(),this.Sight.radius=2*t.boundingSphere.radius,this.Sight.minimumLimit=.3,this.Sight.maximumLimit=3*this.Sight.radius,this.Sight.minBeta=.01,this.Sight.maxBeta=Math.PI/2*.98}getInto(){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;let n=new d,e=this.app.project.getChildsById(this.id);e.forEach(i=>{var r=this.app.project.getChildsById(i.id);for(let t=0;t<r.length;t++){let e=r[t];(e instanceof M||e instanceof C||e instanceof v||e instanceof I||e instanceof E)&&n.add(e.id,e.id),e instanceof M&&i instanceof B&&(e.addEventListener(u.leftClick,()=>{this.app.project.switchLevel(i.id)}),e.addEventListener(u.eover,()=>{this.app.toolTips.text=i.layerName}),e.addEventListener(u.out,()=>{this.app.toolTips.text=""}))}n.add(i.id,i.id)});for(const t in this.app.project.objectDatas.map){let e=this.app.project.objectDatas.find(t);n.find(e.id)||e.parentId==this.parentId?e.setEnabled(!0):e.setEnabled(!1)}this.setEnabled(!1),this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}goBack(){this.app.toolTips.text="";let e=this.app.project.getChildsById(this.id);e.forEach(e=>{var i=this.app.project.getChildsById(e.id);for(let t=0;t<i.length;t++){let e=i[t];e instanceof M&&(e.removeEventListener(u.leftClick),e.removeEventListener(u.eover),e.removeEventListener(u.out))}})}}class k{constructor(e){this.objectDatas=new d,this.app=e}clear(){this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!0;for(const e in this.objectDatas.map)this.objectDatas.find(e).instance&&this.objectDatas.find(e).instance.dispose();this.objectDatas.clear(),this.current=null,this.app.scene.blockfreeActiveMeshesAndRenderingGroups=!1}optimization(){this.app.scene.freezeActiveMeshes()}getChildsById(e=this.root.id,r=!1){e=e||this.root.id;let n=new Array;const o=e=>{for(const i in this.objectDatas.map){var t=this.objectDatas.find(i);t.parentId==e&&(n.push(t),r&&o(t.id))}};return o(e),n}getSceneTree(e=this.root.id,n=[]){e=e||this.root.id;const o=(e,r)=>{for(const t in this.objectDatas.map){let i=this.objectDatas.find(t);if(i.parentId==e){let t=!1;for(let e=0;e<n.length;e++)i.customType!=n[e]||(t=!0);t||(r.push({...i.toJson(),children:[]}),o(i.id,r[r.length-1].children))}}};let t=this.objectDatas.find(e);if(t){e={...t.toJson(),children:[]};return o(this.root.id,e.children),e}console.error("指定的层级不存在")}findObjectById(e){return this.objectDatas.find(e)}findObjectByCustomNumber(e){let t=[];for(const r in this.objectDatas.map){var i=this.objectDatas.find(r);i.customNumber==e&&t.push(i)}return 0==t.length?null:(1<t.length&&console.log("存在编号重复对象,重复个数:"+t.length),t[0])}findObjectsByCustomType(t,i={isCurrent:!1,isEnabled:!1}){let r=[];for(const n in this.objectDatas.map){let e=this.objectDatas.find(n);e.customType==t&&(i.isCurrent&&e.parentId!=this.current.id||i.isEnabled&&1!=e.instance.isEnabled()||r.push(e))}return r}findObjectsByType(e){let t=new Array;for(const r in this.objectDatas.map){var i=this.objectDatas.find(r);i.objectType==e&&t.push(i)}return t}computeSight(i){var r=BABYLON.Vector3.Zero(),n=BABYLON.Vector3.Zero();for(let e=0;e<i.length;e++){let t=i[e];if(t.objectType!=f.Storey&&t.objectType!=f.Campus){let e=t.instance.getBoundingInfo();r&&n||(r=n=e.boundingBox.center.clone()),r=BABYLON.Vector3.Minimize(r,e.minimum.add(t.instance.position)),n=BABYLON.Vector3.Maximize(n,e.maximum.add(t.instance.position))}}return r&&n||(r=BABYLON.Vector3.Zero(),n=new BABYLON.Vector3(12,0,8)),p.getVisualAngle(new BABYLON.BoundingInfo(r,n),this.app)}switchLevel(e=this.root.id,t=!0){e=e||this.root.id;let i=this.objectDatas.find(e);if(i){if(this.current&&this.current.goBack(),!(i instanceof S||i instanceof z)){let e=this.objectDatas.find(i.parentId);this.current instanceof S||this.current instanceof z?i.parentId!=this.current.id&&e.getInto():i.parentId!=this.current.parentId&&e.getInto()}i.getInto(),this.current=i,this.levelEvent&&this.levelEvent(this.current),t&&(i instanceof S||i instanceof z)&&this.app.cameraController.perspective(i.Sight)}else console.error("层级不存在")}goBack(){this.app.isDefaultMutual&&(this.current?this.current.parentId?(this.current.goBack&&this.current.goBack(),this.switchLevel(this.current.parentId)):console.error("已经是最顶层级!"):console.error("层级有误、未知错误!"))}getTypes(e=null){let t=[],i=new d;for(var r in this.objectDatas.map){r=this.objectDatas.find(r);e&&r.parentId!=e||i.find(r.objectType)||i.add(r.objectType,r.objectType)}for(var n in i.map)t.push(n);return t}getCustomTypes(e=null){let t=[],i=new d;for(var r in this.objectDatas.map){r=this.objectDatas.find(r);e&&r.parentId!=e||i.find(r.customType)||i.add(r.customType,r.customType)}for(var n in i.map)t.push(n);return t}}class P{constructor(e){this.walls=new d,this.resources=new d,this.ndoeMats=new d,this.Materials=new d,this.Textures=new d,this.MergeMaterials=new d,this.app=e;e=a.getGUID(12);this.transparentBox=BABYLON.MeshBuilder.CreateBox(e,{size:1},this.app.scene),this.transparentBox.alwaysSelectAsActiveMesh=!0;let t=new BABYLON.StandardMaterial(e,this.app.scene);t.diffuseTexture=new BABYLON.Texture(se.rl+"resources/white.jpg",this.app.scene,!0,!1),t.alphaMode=BABYLON.Engine.ALPHA_COMBINE,t.emissiveColor=BABYLON.Color3.Green(),this.transparentBox.material=t,this.transparentBox.setEnabled(!1),this.transparentBox.visibility=.3;e=a.getGUID(12);this.BOX=BABYLON.MeshBuilder.CreateBox(e,{size:1},this.app.scene),this.BOX.edgesColor=BABYLON.Color4.FromHexString("#4ba3fff2"),this.BOX.setEnabled(!1),this.BOX.visibility=0,this.FogTex=new BABYLON.Texture(se.rl+"resources/fogtex.png",this.app.scene,!0,!1)}async loadModelMesh(t){let i=this.resources.find(t.modelId);if(!i)try{i=await BABYLON.SceneLoader.LoadAssetContainerAsync(se.rl+"bundle/"+t.modelId+"/",t.modelId+t.extension,this.app.scene),0<i.animationGroups.length&&i.animationGroups[0].stop(),i.addAllToScene(),i.meshes[0].setEnabled(!1),i.meshes[0].getChildMeshes().forEach(e=>{e.metadata&&e.metadata.gltf&&e.metadata.gltf.extras&&(i.isExtras=!0,e.metadata.gltf.extras.U&&BABYLON.Animation.CreateAndStartAnimation("u",e.material.albedoTexture,"uOffset",30*e.metadata.gltf.extras.Uspeed,30,0,1,1),e.metadata.gltf.extras.V&&BABYLON.Animation.CreateAndStartAnimation("v",e.material.albedoTexture,"vOffset",30*e.metadata.gltf.extras.Vspeed,30,0,1,1))}),i.isExtras||i.meshes[0].getChildMeshes().forEach(e=>{e.registerInstancedBuffer("color",4),e.instancedBuffers.color=new BABYLON.Color4(1,1,1,1)}),this.resources.add(t.modelId,i)}catch(e){console.error("模型下载失败!模型编号:"+t.modelId+";错误信息:"+e)}return i}loadModelMeshAsync(t,i){var e=this.resources.find(t.modelId);e?i(e):BABYLON.SceneLoader.LoadAssetContainerAsync(se.rl+"bundle/"+t.modelId+"/",t.modelId+t.extension,this.app.scene).then(e=>{0<e.animationGroups.length&&e.animationGroups[0].stop(),this.resources.add(t.modelId,e),i(e)}).catch(()=>{console.error("模型下载失败!模型编号:"+t.modelId)})}GetMaterial(e,t){let i=this.Materials.find(e.modelId);var r;return void 0===i&&(r=this.GetTexture(e,t),i=new BABYLON.StandardMaterial(e.modelId,t),i.alphaMode=BABYLON.Engine.ALPHA_COMBINE,i.diffuseTexture=r,this.Materials.add(e.modelId,i)),i}GetTexture(e,t){let i=this.Textures.find(e.modelId);return void 0===i&&(i=new BABYLON.Texture(se.rl+"texture/"+e.modelId+e.extension,t,!1),".png"==e.extension&&(i.hasAlpha=!0),this.Textures.add(e.modelId,i)),i}GetMergeMaterial(t,i){let r=this.MergeMaterials.find(t.modelId);if(void 0===r){r=new BABYLON.CustomMaterial(t.modelId,i),r.alphaMode=2,this.MergeMaterials.add(t.modelId,r),r.AddUniform("textureData","sampler2D",null),r.Vertex_Definitions(`
|
|
6
6
|
varying vec3 localPos ;
|
|
7
7
|
varying vec3 localNrm ;
|
|
8
8
|
`),r.Fragment_Definitions(`
|