mx3d 0.0.26 → 0.0.29

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/mx3d.js CHANGED
@@ -7776,267 +7776,6 @@ var ObjectType;
7776
7776
  ObjectType["optimizedWall"] = "optimizedWall";
7777
7777
  })(ObjectType || (ObjectType = {}));
7778
7778
 
7779
- // CONCATENATED MODULE: ./src/lib/components/Project.ts
7780
-
7781
-
7782
- class Project_Project {
7783
- constructor(_app) {
7784
- //场景集合
7785
- this.objectDatas = new Dictionary();
7786
- this.app = _app;
7787
- }
7788
- delete() {
7789
- this.app.scene.blockfreeActiveMeshesAndRenderingGroups = true;
7790
- for (const _o in this.objectDatas.map) {
7791
- if (this.objectDatas.find(_o).instance)
7792
- this.objectDatas.find(_o).instance.dispose();
7793
- }
7794
- this.objectDatas.clear();
7795
- this.current = null;
7796
- this.app.scene.blockfreeActiveMeshesAndRenderingGroups = false;
7797
- }
7798
- optimization() {
7799
- //冻结活动网格,与自发光合用回导致内存泄露
7800
- this.app.scene.freezeActiveMeshes();
7801
- }
7802
- getChildNodes(_id) {
7803
- let _objects = new Array();
7804
- for (const id in this.objectDatas.map) {
7805
- let _object = this.app.project.objectDatas.find(id);
7806
- if (_object.parentId == _id && _object.objectType != ObjectType.Wall && _object.objectType != ObjectType.Corner)
7807
- _objects.push(_object);
7808
- }
7809
- return _objects;
7810
- }
7811
- getTrees() {
7812
- const infinite = (id, target) => {
7813
- for (const _id in this.objectDatas.map) {
7814
- let _object = this.app.project.objectDatas.find(_id);
7815
- if (!_object.isMonitor || _object.parentId != id)
7816
- continue;
7817
- target.push({ label: _object.name, id: _object.id, type: _object.objectType, children: [] });
7818
- infinite(_object.id, target[target.length - 1].children);
7819
- }
7820
- };
7821
- let node = { label: this.root.name, id: this.root.id, type: this.root.objectType, children: [] };
7822
- infinite(this.root.id, node.children);
7823
- return node;
7824
- }
7825
- find(_id) {
7826
- return this.objectDatas.find(_id);
7827
- }
7828
- findFormObjectType(_type, isCurent = true) {
7829
- let _objects = new Array();
7830
- for (const id in this.objectDatas.map) {
7831
- let _object = this.app.project.objectDatas.find(id);
7832
- if ((isCurent && _object.parentId != this.current.id) || _object.objectType != _type)
7833
- continue;
7834
- _objects.push(_object);
7835
- }
7836
- return _objects;
7837
- }
7838
- show() {
7839
- this.app.scene.blockfreeActiveMeshesAndRenderingGroups = true;
7840
- for (const id in this.app.project.objectDatas.map) {
7841
- let _object = this.app.project.objectDatas.find(id);
7842
- _object.setEnabled(true);
7843
- }
7844
- this.app.scene.blockfreeActiveMeshesAndRenderingGroups = false;
7845
- }
7846
- }
7847
-
7848
- // CONCATENATED MODULE: ./src/lib/Resources.ts
7849
-
7850
-
7851
-
7852
- class Resources_Resources {
7853
- constructor(_app) {
7854
- this.resourcePath = "http://models.wodashijie.com/";
7855
- this.walls = new Dictionary();
7856
- //模型资源集合
7857
- this.resources = new Dictionary();
7858
- this.ndoeMats = new Dictionary();
7859
- //资源集合
7860
- this.Materials = new Dictionary();
7861
- //贴图集合
7862
- this.Textures = new Dictionary();
7863
- this.MergeMaterials = new Dictionary();
7864
- this.app = _app;
7865
- let tranId = GUID.getGUID(12);
7866
- this.transparentBox = BABYLON.MeshBuilder.CreateBox(tranId, { size: 1 }, this.app.scene);
7867
- this.transparentBox.alwaysSelectAsActiveMesh = true;
7868
- let boxmat = new BABYLON.StandardMaterial(tranId, this.app.scene);
7869
- boxmat.diffuseTexture = new BABYLON.Texture(this.app.rootUrl + "resources/white.jpg", this.app.scene, true, false);
7870
- boxmat.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
7871
- boxmat.emissiveColor = BABYLON.Color3.Green();
7872
- this.transparentBox.material = boxmat;
7873
- this.transparentBox.setEnabled(false);
7874
- this.transparentBox.visibility = 0.3;
7875
- let boxId = GUID.getGUID(12);
7876
- this.BOX = BABYLON.MeshBuilder.CreateBox(boxId, { size: 1 }, this.app.scene);
7877
- this.BOX.edgesColor = BABYLON.Color4.FromHexString("#4ba3fff2");
7878
- // this.BOX.registerInstancedBuffer("color", 4);
7879
- // this.BOX.instancedBuffers.color = new BABYLON.Color4(1, 0, 0, 1);
7880
- this.BOX.setEnabled(false);
7881
- this.BOX.visibility = 0;
7882
- // 加上材质会影响加载时间
7883
- // let box_mat = new BABYLON.StandardMaterial(boxId, this.app.scene);
7884
- // box_mat.diffuseColor=BABYLON.Color3.White()
7885
- // box_mat.alpha = 0;
7886
- // this.BOX.setEnabled(false);
7887
- // this.BOX.material = box_mat;
7888
- // this.BOX.material.freeze();
7889
- // 粒子雾贴图
7890
- this.FogTex = new BABYLON.Texture(this.app.rootUrl + "resources/fogtex.png", this.app.scene, true, false);
7891
- }
7892
- async loadModelMesh(baseModel) {
7893
- let _mesh = this.resources.find(baseModel.modelId);
7894
- if (!_mesh) {
7895
- try {
7896
- _mesh = await BABYLON.SceneLoader.LoadAssetContainerAsync(this.resourcePath + "bundle/" + baseModel.modelId + "/", baseModel.modelId + baseModel.extension, this.app.scene);
7897
- if (_mesh.animationGroups.length > 0)
7898
- _mesh.animationGroups[0].stop();
7899
- _mesh.addAllToScene();
7900
- _mesh.meshes[0].setEnabled(false);
7901
- _mesh.meshes[0].getChildMeshes().forEach(m => {
7902
- if (m.metadata && m.metadata.gltf && m.metadata.gltf.extras) {
7903
- _mesh.isExtras = true;
7904
- if (m.metadata.gltf.extras.U)
7905
- BABYLON.Animation.CreateAndStartAnimation("u", m.material.albedoTexture, "uOffset", m.metadata.gltf.extras.Uspeed * 30, 30, 0, 1, 1);
7906
- if (m.metadata.gltf.extras.V)
7907
- BABYLON.Animation.CreateAndStartAnimation("v", m.material.albedoTexture, "vOffset", m.metadata.gltf.extras.Vspeed * 30, 30, 0, 1, 1);
7908
- }
7909
- });
7910
- if (baseModel.objectType != ObjectType.OutDoorScene && !_mesh.isExtras) {
7911
- _mesh.meshes[0].getChildMeshes().forEach(e => {
7912
- e.registerInstancedBuffer("color", 4);
7913
- e.instancedBuffers.color = new BABYLON.Color4(1, 1, 1, 1);
7914
- });
7915
- }
7916
- this.resources.add(baseModel.modelId, _mesh);
7917
- }
7918
- catch (ex) {
7919
- console.error("模型下载失败!模型编号:" + baseModel.modelId + ";错误信息:" + ex);
7920
- }
7921
- }
7922
- return _mesh;
7923
- }
7924
- loadModelMeshAsync(baseModel, callback) {
7925
- let _mesh = this.resources.find(baseModel.modelId);
7926
- if (!_mesh) {
7927
- BABYLON.SceneLoader.LoadAssetContainerAsync(this.resourcePath + "bundle/" + baseModel.modelId + "/", baseModel.modelId + baseModel.extension, this.app.scene).then((container) => {
7928
- if (container.animationGroups.length > 0)
7929
- container.animationGroups[0].stop();
7930
- // container.meshes[0].getChildMeshes().forEach(e => {
7931
- // (e as BABYLON.Mesh).registerInstancedBuffer("color", 4);
7932
- // e.instancedBuffers.color = new BABYLON.Color4(1, 1, 1, 1);
7933
- // });
7934
- this.resources.add(baseModel.modelId, container);
7935
- callback(container);
7936
- }).catch(() => {
7937
- console.error("模型下载失败!模型编号:" + baseModel.modelId);
7938
- });
7939
- }
7940
- else
7941
- callback(_mesh);
7942
- }
7943
- GetMaterial(textureData, scene) {
7944
- let _mat = this.Materials.find(textureData.modelId);
7945
- if (typeof _mat == "undefined") {
7946
- let _m = this.GetTexture(textureData, scene);
7947
- _mat = new BABYLON.StandardMaterial(textureData.modelId, scene);
7948
- _mat.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
7949
- _mat.diffuseTexture = _m;
7950
- this.Materials.add(textureData.modelId, _mat);
7951
- // if (_m.hasAlpha) {
7952
- // // _mat.needDepthPrePass = true;
7953
- // _mat.useAlphaFromDiffuseTexture = true;
7954
- // }
7955
- }
7956
- return _mat;
7957
- }
7958
- GetTexture(textureData, scene) {
7959
- let _Texture = this.Textures.find(textureData.modelId);
7960
- if (typeof _Texture == "undefined") {
7961
- _Texture = new BABYLON.Texture(this.resourcePath + "texture/" + textureData.modelId + textureData.extension, scene, false);
7962
- if (textureData.extension == ".png") {
7963
- _Texture.hasAlpha = true;
7964
- }
7965
- this.Textures.add(textureData.modelId, _Texture);
7966
- }
7967
- return _Texture;
7968
- }
7969
- GetMergeMaterial(textureData, scene) {
7970
- let _mat = this.MergeMaterials.find(textureData.modelId);
7971
- if (typeof _mat == "undefined") {
7972
- _mat = new BABYLON.CustomMaterial(textureData.modelId, scene);
7973
- _mat.alphaMode = 2;
7974
- this.MergeMaterials.add(textureData.modelId, _mat);
7975
- // _mat.specularPower=64;
7976
- // _mat.specularColor=BABYLON.Color3.Black();
7977
- _mat.AddUniform('textureData', 'sampler2D', null);
7978
- _mat.Vertex_Definitions(`
7979
- varying vec3 localPos ;
7980
- varying vec3 localNrm ;
7981
- `);
7982
- _mat.Fragment_Definitions(`
7983
- varying vec3 localPos ;
7984
- varying vec3 localNrm ;`);
7985
- _mat.Vertex_Before_PositionUpdated(`
7986
- localPos = position.xyz;
7987
- localNrm = normal;
7988
- `);
7989
- let tex = this.GetTexture(textureData, scene);
7990
- if (textureData.extension == ".png") {
7991
- tex.hasAlpha = true;
7992
- _mat.alpha = 0.9;
7993
- // _mat.needDepthPrePass = true;
7994
- // _mat.useAlphaFromDiffuseTexture = true;
7995
- }
7996
- textureData.length = 3.1;
7997
- console.log(textureData.width);
7998
- _mat.onBindObservable.add(() => _mat.getEffect().setTexture('textureData', tex));
7999
- _mat.Fragment_Custom_Diffuse(`
8000
- vec3 newUV = vec3(abs(localPos.x)/` + textureData.width + `,abs(localPos.y)/` + textureData.length + `,abs(localPos.z)/` + textureData.width + `);
8001
- if(abs(localNrm.z)>abs(localNrm.x)){
8002
- vec4 res = texture2D(textureData,newUV.xy);
8003
- diffuseColor = res.rgb;
8004
- alpha = res.a;
8005
- }
8006
- else {
8007
- vec4 res = texture2D(textureData,newUV.zy);
8008
- diffuseColor = res.rgb;
8009
- alpha = res.a;
8010
- }
8011
- `);
8012
- _mat.freeze();
8013
- }
8014
- return _mat;
8015
- }
8016
- delete(isAll = false) {
8017
- this.BOX && this.BOX.dispose();
8018
- this.transparentBox && this.transparentBox.dispose(true, true);
8019
- this.BOX = null;
8020
- this.transparentBox = null;
8021
- if (isAll) {
8022
- for (const _id in this.resources.map) {
8023
- this.resources.find(_id).removeAllFromScene();
8024
- this.resources.remove(_id);
8025
- }
8026
- this.resources.clear();
8027
- }
8028
- }
8029
- async GetWalls(url, projectId) {
8030
- let walls = await BABYLON.SceneLoader.LoadAssetContainerAsync(url, projectId + ".gltf", this.app.scene);
8031
- if (walls.meshes) {
8032
- let _walls = walls.meshes[0].getChildMeshes();
8033
- for (let i = 0; i < _walls.length; i++) {
8034
- this.walls.add(_walls[i].id, _walls[i]);
8035
- }
8036
- }
8037
- }
8038
- }
8039
-
8040
7779
  // CONCATENATED MODULE: ./src/lib/EventType.ts
8041
7780
  var EventType;
8042
7781
  (function (EventType) {
@@ -8066,55 +7805,6 @@ var EventType;
8066
7805
  EventType["out"] = "out";
8067
7806
  })(EventType || (EventType = {}));
8068
7807
 
8069
- // CONCATENATED MODULE: ./src/lib/VisualAngle.ts
8070
-
8071
-
8072
- class VisualAngle_VisualAngle {
8073
- constructor(_object) {
8074
- this.object = _object;
8075
- //重新计算包围盒
8076
- if (this.object instanceof Region_Region) {
8077
- let bound = this.object.getBounding();
8078
- let _vis = src.Tools.getVisualAngle(bound, this.object.app);
8079
- this.alpha = _vis.alpha;
8080
- this.beta = _vis.beta;
8081
- this.focus = _vis.focus;
8082
- this.radius = bound.boundingSphere.radiusWorld + 3;
8083
- this.focus.y = this.object.height;
8084
- }
8085
- else {
8086
- let bound = this.object.instance.getBoundingInfo();
8087
- let _vis = src.Tools.getVisualAngle(bound, this.object.app);
8088
- this.alpha = _vis.alpha;
8089
- this.beta = _vis.beta;
8090
- this.focus = this.object.instance.getAbsolutePosition();
8091
- this.radius = bound.boundingSphere.radiusWorld + 3;
8092
- }
8093
- this.minimumLimit = 0.3;
8094
- this.maximumLimit = this.radius * 2;
8095
- this.minBeta = 0.01;
8096
- this.maxBeta = (Math.PI / 2) * 0.98;
8097
- }
8098
- //设置视角参数
8099
- setVisual(_visual) {
8100
- let config = JSON.parse(_visual);
8101
- this.alpha = config.alpha;
8102
- this.beta = config.beta;
8103
- this.radius = config.radius;
8104
- this.focus = src.Tools.ToVector3(config.focus);
8105
- }
8106
- //设置缩放范围
8107
- setLimit(_miniLimit, _maxiLimit) {
8108
- this.minimumLimit = _miniLimit + 0.3;
8109
- this.maximumLimit = _maxiLimit;
8110
- }
8111
- //设置上下视角限制
8112
- setBeta(_minBeta, _maxBeta) {
8113
- this.minBeta = _minBeta;
8114
- this.maxBeta = _maxBeta;
8115
- }
8116
- }
8117
-
8118
7808
  // CONCATENATED MODULE: ./src/lib/EffectType.ts
8119
7809
  var EffectType;
8120
7810
  (function (EffectType) {
@@ -8373,6 +8063,44 @@ class DefaultObject_DefaultObject {
8373
8063
  }
8374
8064
  }
8375
8065
 
8066
+ // CONCATENATED MODULE: ./src/lib/components/ConduitObject.ts
8067
+ // import MX3D from "../../index";
8068
+
8069
+
8070
+
8071
+ //墙角
8072
+ class ConduitObject_ConduitObject extends DefaultObject_DefaultObject {
8073
+ bind(_m) {
8074
+ this.id = _m.id;
8075
+ this.name = _m.name;
8076
+ this.parentId = _m.parentId;
8077
+ this.isMonitor = _m.isMonitor;
8078
+ this.objectType = _m.objectType;
8079
+ this.isVisible = true;
8080
+ let pists = Tools.ToARRVector3(_m.pints);
8081
+ this.instance = Tools.createTube(_m.id, pists, _m.radius, this.app);
8082
+ let mat = new BABYLON.StandardMaterial(_m.id, this.app.scene);
8083
+ mat.diffuseColor = BABYLON.Color3.FromHexString(_m.color);
8084
+ mat.alpha = _m.alpha;
8085
+ this.instance.material = mat;
8086
+ if (this.id == "zWWMiZ0yp7Jx") {
8087
+ console.log(this.instance.getBoundingInfo());
8088
+ this.instance.showBoundingBox = true;
8089
+ }
8090
+ this.instance.enablePointerMoveEvents = this.isMonitor;
8091
+ this.instance.isPickable = this.isMonitor;
8092
+ this.instance.setEnabled(false);
8093
+ this.alwaysActive();
8094
+ this.optimization(true);
8095
+ this.visualAngle = new VisualAngle_VisualAngle(this);
8096
+ //重新计算包围盒
8097
+ // this.bound = this.instance.getBoundingInfo();
8098
+ // this.visualAngle = this.app.Tools.getVisualAngle(this.bound);
8099
+ // this.visualAngle.radius = this.bound.boundingSphere.radiusWorld + 3;
8100
+ // this.alwaysSelect();
8101
+ }
8102
+ }
8103
+
8376
8104
  // CONCATENATED MODULE: ./src/lib/components/WallObject.ts
8377
8105
 
8378
8106
 
@@ -8764,40 +8492,6 @@ class UI3DTextObject_UI3DTextObject extends DefaultObject_DefaultObject {
8764
8492
  }
8765
8493
  }
8766
8494
 
8767
- // CONCATENATED MODULE: ./src/lib/components/ConduitObject.ts
8768
- // import MX3D from "../../index";
8769
-
8770
-
8771
-
8772
- //墙角
8773
- class ConduitObject_ConduitObject extends DefaultObject_DefaultObject {
8774
- bind(_m) {
8775
- this.id = _m.id;
8776
- this.name = _m.name;
8777
- this.parentId = _m.parentId;
8778
- this.isMonitor = _m.isMonitor;
8779
- this.objectType = _m.objectType;
8780
- this.isVisible = true;
8781
- let pists = Tools.ToARRVector3(_m.pints);
8782
- this.instance = Tools.createTube(_m.id, pists, _m.radius, this.app);
8783
- let mat = new BABYLON.StandardMaterial(_m.id, this.app.scene);
8784
- mat.diffuseColor = BABYLON.Color3.FromHexString(_m.color);
8785
- mat.alpha = _m.alpha;
8786
- this.instance.material = mat;
8787
- this.instance.enablePointerMoveEvents = this.isMonitor;
8788
- this.instance.isPickable = this.isMonitor;
8789
- this.instance.setEnabled(false);
8790
- this.alwaysActive();
8791
- this.optimization(true);
8792
- this.visualAngle = new VisualAngle_VisualAngle(this);
8793
- //重新计算包围盒
8794
- // this.bound = this.instance.getBoundingInfo();
8795
- // this.visualAngle = this.app.Tools.getVisualAngle(this.bound);
8796
- // this.visualAngle.radius = this.bound.boundingSphere.radiusWorld + 3;
8797
- // this.alwaysSelect();
8798
- }
8799
- }
8800
-
8801
8495
  // CONCATENATED MODULE: ./src/lib/components/FloorObject.ts
8802
8496
 
8803
8497
 
@@ -9282,29 +8976,177 @@ class Region_Region extends DefaultObject_DefaultObject {
9282
8976
  }
9283
8977
  }
9284
8978
  }
9285
- //清除临时变量
9286
- walls = null;
8979
+ //清除临时变量
8980
+ walls = null;
8981
+ this.visualAngle = new VisualAngle_VisualAngle(this);
8982
+ }
8983
+ focus() {
8984
+ this.app.scene.blockfreeActiveMeshesAndRenderingGroups = true;
8985
+ for (const id in this.app.project.objectDatas.map) {
8986
+ let _object = this.app.project.objectDatas.find(id);
8987
+ if (_object.parentId == this.id)
8988
+ _object.setEnabled(_object.isVisible);
8989
+ else
8990
+ _object.setEnabled(false);
8991
+ }
8992
+ this.isEnabled = true;
8993
+ this.app.project.current = this;
8994
+ this.app.scene.blockfreeActiveMeshesAndRenderingGroups = false;
8995
+ }
8996
+ setEnabled(_value) { }
8997
+ getBounding() {
8998
+ var min, max;
8999
+ for (const _id in this.app.project.objectDatas.map) {
9000
+ let _model = this.app.project.objectDatas.find(_id);
9001
+ if (_model.objectType == ObjectType.ParkModel || _model.objectType == ObjectType.Storey || _model.parentId != this.id)
9002
+ continue;
9003
+ let boundingInfo = _model.instance.getBoundingInfo();
9004
+ if (!min || !max)
9005
+ min = max = boundingInfo.boundingBox.center.clone();
9006
+ min = BABYLON.Vector3.Minimize(min, boundingInfo.minimum.add(_model.instance.position));
9007
+ max = BABYLON.Vector3.Maximize(max, boundingInfo.maximum.add(_model.instance.position));
9008
+ }
9009
+ if (!min || !max) {
9010
+ min = BABYLON.Vector3.Zero();
9011
+ max = new BABYLON.Vector3(12, this.height, 8);
9012
+ }
9013
+ return new BABYLON.BoundingInfo(min, max);
9014
+ }
9015
+ dispose() { }
9016
+ }
9017
+
9018
+ // CONCATENATED MODULE: ./src/lib/VisualAngle.ts
9019
+
9020
+
9021
+
9022
+
9023
+ class VisualAngle_VisualAngle {
9024
+ constructor(_object) {
9025
+ this.object = _object;
9026
+ //重新计算包围盒
9027
+ if (this.object instanceof Region_Region || this.object instanceof Project_Project) {
9028
+ let bound = this.object.getBounding();
9029
+ let _vis = src.Tools.getVisualAngle(bound, this.object.app);
9030
+ this.alpha = _vis.alpha;
9031
+ this.beta = _vis.beta;
9032
+ this.focus = _vis.focus;
9033
+ this.radius = _vis.radius;
9034
+ if (this.object instanceof Region_Region) {
9035
+ // this.radius = bound.boundingSphere.radiusWorld + 3;
9036
+ this.focus.y = this.object.height;
9037
+ }
9038
+ }
9039
+ else {
9040
+ let bound = this.object.instance.getBoundingInfo();
9041
+ let _vis = src.Tools.getVisualAngle(bound, this.object.app);
9042
+ this.alpha = _vis.alpha;
9043
+ this.beta = _vis.beta;
9044
+ this.focus = _vis.focus;
9045
+ this.radius = _vis.radius;
9046
+ if (!(this.object instanceof ConduitObject_ConduitObject)) {
9047
+ this.focus = this.object.instance.getAbsolutePosition();
9048
+ this.radius = bound.boundingSphere.radiusWorld + 3;
9049
+ }
9050
+ }
9051
+ this.minimumLimit = 0.3;
9052
+ this.maximumLimit = this.radius * 2;
9053
+ this.minBeta = 0.01;
9054
+ this.maxBeta = (Math.PI / 2) * 0.98;
9055
+ }
9056
+ //设置视角参数
9057
+ setVisual(_visual) {
9058
+ let config = JSON.parse(_visual);
9059
+ this.alpha = config.alpha;
9060
+ this.beta = config.beta;
9061
+ this.radius = config.radius;
9062
+ this.focus = src.Tools.ToVector3(config.focus);
9063
+ }
9064
+ //设置缩放范围
9065
+ setLimit(_miniLimit, _maxiLimit) {
9066
+ this.minimumLimit = _miniLimit + 0.3;
9067
+ this.maximumLimit = _maxiLimit;
9068
+ }
9069
+ //设置上下视角限制
9070
+ setBeta(_minBeta, _maxBeta) {
9071
+ this.minBeta = _minBeta;
9072
+ this.maxBeta = _maxBeta;
9073
+ }
9074
+ }
9075
+
9076
+ // CONCATENATED MODULE: ./src/lib/components/Project.ts
9077
+
9078
+
9079
+
9080
+ class Project_Project {
9081
+ constructor(_app) {
9082
+ //场景集合
9083
+ this.objectDatas = new Dictionary();
9084
+ this.app = _app;
9085
+ }
9086
+ delete() {
9087
+ this.app.scene.blockfreeActiveMeshesAndRenderingGroups = true;
9088
+ for (const _o in this.objectDatas.map) {
9089
+ if (this.objectDatas.find(_o).instance)
9090
+ this.objectDatas.find(_o).instance.dispose();
9091
+ }
9092
+ this.objectDatas.clear();
9093
+ this.current = null;
9094
+ this.app.scene.blockfreeActiveMeshesAndRenderingGroups = false;
9095
+ }
9096
+ optimization() {
9287
9097
  this.visualAngle = new VisualAngle_VisualAngle(this);
9098
+ //冻结活动网格,与自发光合用回导致内存泄露
9099
+ this.app.scene.freezeActiveMeshes();
9288
9100
  }
9289
- focus() {
9101
+ getChildNodes(_id) {
9102
+ let _objects = new Array();
9103
+ for (const id in this.objectDatas.map) {
9104
+ let _object = this.app.project.objectDatas.find(id);
9105
+ if (_object.parentId == _id && _object.objectType != ObjectType.Wall && _object.objectType != ObjectType.Corner)
9106
+ _objects.push(_object);
9107
+ }
9108
+ return _objects;
9109
+ }
9110
+ getTrees() {
9111
+ const infinite = (id, target) => {
9112
+ for (const _id in this.objectDatas.map) {
9113
+ let _object = this.app.project.objectDatas.find(_id);
9114
+ if (!_object.isMonitor || _object.parentId != id)
9115
+ continue;
9116
+ target.push({ label: _object.name, id: _object.id, type: _object.objectType, children: [] });
9117
+ infinite(_object.id, target[target.length - 1].children);
9118
+ }
9119
+ };
9120
+ let node = { label: this.root.name, id: this.root.id, type: this.root.objectType, children: [] };
9121
+ infinite(this.root.id, node.children);
9122
+ return node;
9123
+ }
9124
+ find(_id) {
9125
+ return this.objectDatas.find(_id);
9126
+ }
9127
+ findFormObjectType(_type, isCurent = true) {
9128
+ let _objects = new Array();
9129
+ for (const id in this.objectDatas.map) {
9130
+ let _object = this.app.project.objectDatas.find(id);
9131
+ if ((isCurent && _object.parentId != this.current.id) || _object.objectType != _type)
9132
+ continue;
9133
+ _objects.push(_object);
9134
+ }
9135
+ return _objects;
9136
+ }
9137
+ show() {
9290
9138
  this.app.scene.blockfreeActiveMeshesAndRenderingGroups = true;
9291
9139
  for (const id in this.app.project.objectDatas.map) {
9292
9140
  let _object = this.app.project.objectDatas.find(id);
9293
- if (_object.parentId == this.id)
9294
- _object.setEnabled(_object.isVisible);
9295
- else
9296
- _object.setEnabled(false);
9141
+ _object.setEnabled(true);
9297
9142
  }
9298
- this.isEnabled = true;
9299
- this.app.project.current = this;
9300
9143
  this.app.scene.blockfreeActiveMeshesAndRenderingGroups = false;
9301
9144
  }
9302
- setEnabled(_value) { }
9303
9145
  getBounding() {
9304
9146
  var min, max;
9305
9147
  for (const _id in this.app.project.objectDatas.map) {
9306
9148
  let _model = this.app.project.objectDatas.find(_id);
9307
- if (_model.objectType == ObjectType.ParkModel || _model.objectType == ObjectType.Storey || _model.parentId != this.id)
9149
+ if (_model.objectType == ObjectType.ParkModel || _model.objectType == ObjectType.Storey)
9308
9150
  continue;
9309
9151
  let boundingInfo = _model.instance.getBoundingInfo();
9310
9152
  if (!min || !max)
@@ -9314,11 +9156,205 @@ class Region_Region extends DefaultObject_DefaultObject {
9314
9156
  }
9315
9157
  if (!min || !max) {
9316
9158
  min = BABYLON.Vector3.Zero();
9317
- max = new BABYLON.Vector3(12, this.height, 8);
9159
+ max = new BABYLON.Vector3(12, 0, 8);
9318
9160
  }
9319
9161
  return new BABYLON.BoundingInfo(min, max);
9320
9162
  }
9321
- dispose() { }
9163
+ flyTo() {
9164
+ this.app.camera.flyTo(this.visualAngle, 500);
9165
+ }
9166
+ }
9167
+
9168
+ // CONCATENATED MODULE: ./src/lib/Resources.ts
9169
+
9170
+
9171
+
9172
+ class Resources_Resources {
9173
+ constructor(_app) {
9174
+ this.resourcePath = "http://models.wodashijie.com/";
9175
+ this.walls = new Dictionary();
9176
+ //模型资源集合
9177
+ this.resources = new Dictionary();
9178
+ this.ndoeMats = new Dictionary();
9179
+ //资源集合
9180
+ this.Materials = new Dictionary();
9181
+ //贴图集合
9182
+ this.Textures = new Dictionary();
9183
+ this.MergeMaterials = new Dictionary();
9184
+ this.app = _app;
9185
+ let tranId = GUID.getGUID(12);
9186
+ this.transparentBox = BABYLON.MeshBuilder.CreateBox(tranId, { size: 1 }, this.app.scene);
9187
+ this.transparentBox.alwaysSelectAsActiveMesh = true;
9188
+ let boxmat = new BABYLON.StandardMaterial(tranId, this.app.scene);
9189
+ boxmat.diffuseTexture = new BABYLON.Texture(this.app.rootUrl + "resources/white.jpg", this.app.scene, true, false);
9190
+ boxmat.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
9191
+ boxmat.emissiveColor = BABYLON.Color3.Green();
9192
+ this.transparentBox.material = boxmat;
9193
+ this.transparentBox.setEnabled(false);
9194
+ this.transparentBox.visibility = 0.3;
9195
+ let boxId = GUID.getGUID(12);
9196
+ this.BOX = BABYLON.MeshBuilder.CreateBox(boxId, { size: 1 }, this.app.scene);
9197
+ this.BOX.edgesColor = BABYLON.Color4.FromHexString("#4ba3fff2");
9198
+ // this.BOX.registerInstancedBuffer("color", 4);
9199
+ // this.BOX.instancedBuffers.color = new BABYLON.Color4(1, 0, 0, 1);
9200
+ this.BOX.setEnabled(false);
9201
+ this.BOX.visibility = 0;
9202
+ // 加上材质会影响加载时间
9203
+ // let box_mat = new BABYLON.StandardMaterial(boxId, this.app.scene);
9204
+ // box_mat.diffuseColor=BABYLON.Color3.White()
9205
+ // box_mat.alpha = 0;
9206
+ // this.BOX.setEnabled(false);
9207
+ // this.BOX.material = box_mat;
9208
+ // this.BOX.material.freeze();
9209
+ // 粒子雾贴图
9210
+ this.FogTex = new BABYLON.Texture(this.app.rootUrl + "resources/fogtex.png", this.app.scene, true, false);
9211
+ }
9212
+ async loadModelMesh(baseModel) {
9213
+ let _mesh = this.resources.find(baseModel.modelId);
9214
+ if (!_mesh) {
9215
+ try {
9216
+ _mesh = await BABYLON.SceneLoader.LoadAssetContainerAsync(this.resourcePath + "bundle/" + baseModel.modelId + "/", baseModel.modelId + baseModel.extension, this.app.scene);
9217
+ if (_mesh.animationGroups.length > 0)
9218
+ _mesh.animationGroups[0].stop();
9219
+ _mesh.addAllToScene();
9220
+ _mesh.meshes[0].setEnabled(false);
9221
+ _mesh.meshes[0].getChildMeshes().forEach(m => {
9222
+ if (m.metadata && m.metadata.gltf && m.metadata.gltf.extras) {
9223
+ _mesh.isExtras = true;
9224
+ if (m.metadata.gltf.extras.U)
9225
+ BABYLON.Animation.CreateAndStartAnimation("u", m.material.albedoTexture, "uOffset", m.metadata.gltf.extras.Uspeed * 30, 30, 0, 1, 1);
9226
+ if (m.metadata.gltf.extras.V)
9227
+ BABYLON.Animation.CreateAndStartAnimation("v", m.material.albedoTexture, "vOffset", m.metadata.gltf.extras.Vspeed * 30, 30, 0, 1, 1);
9228
+ }
9229
+ });
9230
+ if (baseModel.objectType != ObjectType.OutDoorScene && !_mesh.isExtras) {
9231
+ _mesh.meshes[0].getChildMeshes().forEach(e => {
9232
+ e.registerInstancedBuffer("color", 4);
9233
+ e.instancedBuffers.color = new BABYLON.Color4(1, 1, 1, 1);
9234
+ });
9235
+ }
9236
+ this.resources.add(baseModel.modelId, _mesh);
9237
+ }
9238
+ catch (ex) {
9239
+ console.error("模型下载失败!模型编号:" + baseModel.modelId + ";错误信息:" + ex);
9240
+ }
9241
+ }
9242
+ return _mesh;
9243
+ }
9244
+ loadModelMeshAsync(baseModel, callback) {
9245
+ let _mesh = this.resources.find(baseModel.modelId);
9246
+ if (!_mesh) {
9247
+ BABYLON.SceneLoader.LoadAssetContainerAsync(this.resourcePath + "bundle/" + baseModel.modelId + "/", baseModel.modelId + baseModel.extension, this.app.scene).then((container) => {
9248
+ if (container.animationGroups.length > 0)
9249
+ container.animationGroups[0].stop();
9250
+ // container.meshes[0].getChildMeshes().forEach(e => {
9251
+ // (e as BABYLON.Mesh).registerInstancedBuffer("color", 4);
9252
+ // e.instancedBuffers.color = new BABYLON.Color4(1, 1, 1, 1);
9253
+ // });
9254
+ this.resources.add(baseModel.modelId, container);
9255
+ callback(container);
9256
+ }).catch(() => {
9257
+ console.error("模型下载失败!模型编号:" + baseModel.modelId);
9258
+ });
9259
+ }
9260
+ else
9261
+ callback(_mesh);
9262
+ }
9263
+ GetMaterial(textureData, scene) {
9264
+ let _mat = this.Materials.find(textureData.modelId);
9265
+ if (typeof _mat == "undefined") {
9266
+ let _m = this.GetTexture(textureData, scene);
9267
+ _mat = new BABYLON.StandardMaterial(textureData.modelId, scene);
9268
+ _mat.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
9269
+ _mat.diffuseTexture = _m;
9270
+ this.Materials.add(textureData.modelId, _mat);
9271
+ // if (_m.hasAlpha) {
9272
+ // // _mat.needDepthPrePass = true;
9273
+ // _mat.useAlphaFromDiffuseTexture = true;
9274
+ // }
9275
+ }
9276
+ return _mat;
9277
+ }
9278
+ GetTexture(textureData, scene) {
9279
+ let _Texture = this.Textures.find(textureData.modelId);
9280
+ if (typeof _Texture == "undefined") {
9281
+ _Texture = new BABYLON.Texture(this.resourcePath + "texture/" + textureData.modelId + textureData.extension, scene, false);
9282
+ if (textureData.extension == ".png") {
9283
+ _Texture.hasAlpha = true;
9284
+ }
9285
+ this.Textures.add(textureData.modelId, _Texture);
9286
+ }
9287
+ return _Texture;
9288
+ }
9289
+ GetMergeMaterial(textureData, scene) {
9290
+ let _mat = this.MergeMaterials.find(textureData.modelId);
9291
+ if (typeof _mat == "undefined") {
9292
+ _mat = new BABYLON.CustomMaterial(textureData.modelId, scene);
9293
+ _mat.alphaMode = 2;
9294
+ this.MergeMaterials.add(textureData.modelId, _mat);
9295
+ // _mat.specularPower=64;
9296
+ // _mat.specularColor=BABYLON.Color3.Black();
9297
+ _mat.AddUniform('textureData', 'sampler2D', null);
9298
+ _mat.Vertex_Definitions(`
9299
+ varying vec3 localPos ;
9300
+ varying vec3 localNrm ;
9301
+ `);
9302
+ _mat.Fragment_Definitions(`
9303
+ varying vec3 localPos ;
9304
+ varying vec3 localNrm ;`);
9305
+ _mat.Vertex_Before_PositionUpdated(`
9306
+ localPos = position.xyz;
9307
+ localNrm = normal;
9308
+ `);
9309
+ let tex = this.GetTexture(textureData, scene);
9310
+ if (textureData.extension == ".png") {
9311
+ tex.hasAlpha = true;
9312
+ _mat.alpha = 0.9;
9313
+ // _mat.needDepthPrePass = true;
9314
+ // _mat.useAlphaFromDiffuseTexture = true;
9315
+ }
9316
+ textureData.length = 3.1;
9317
+ console.log(textureData.width);
9318
+ _mat.onBindObservable.add(() => _mat.getEffect().setTexture('textureData', tex));
9319
+ _mat.Fragment_Custom_Diffuse(`
9320
+ vec3 newUV = vec3(abs(localPos.x)/` + textureData.width + `,abs(localPos.y)/` + textureData.length + `,abs(localPos.z)/` + textureData.width + `);
9321
+ if(abs(localNrm.z)>abs(localNrm.x)){
9322
+ vec4 res = texture2D(textureData,newUV.xy);
9323
+ diffuseColor = res.rgb;
9324
+ alpha = res.a;
9325
+ }
9326
+ else {
9327
+ vec4 res = texture2D(textureData,newUV.zy);
9328
+ diffuseColor = res.rgb;
9329
+ alpha = res.a;
9330
+ }
9331
+ `);
9332
+ _mat.freeze();
9333
+ }
9334
+ return _mat;
9335
+ }
9336
+ delete(isAll = false) {
9337
+ this.BOX && this.BOX.dispose();
9338
+ this.transparentBox && this.transparentBox.dispose(true, true);
9339
+ this.BOX = null;
9340
+ this.transparentBox = null;
9341
+ if (isAll) {
9342
+ for (const _id in this.resources.map) {
9343
+ this.resources.find(_id).removeAllFromScene();
9344
+ this.resources.remove(_id);
9345
+ }
9346
+ this.resources.clear();
9347
+ }
9348
+ }
9349
+ async GetWalls(url, projectId) {
9350
+ let walls = await BABYLON.SceneLoader.LoadAssetContainerAsync(url, projectId + ".gltf", this.app.scene);
9351
+ if (walls.meshes) {
9352
+ let _walls = walls.meshes[0].getChildMeshes();
9353
+ for (let i = 0; i < _walls.length; i++) {
9354
+ this.walls.add(_walls[i].id, _walls[i]);
9355
+ }
9356
+ }
9357
+ }
9322
9358
  }
9323
9359
 
9324
9360
  // CONCATENATED MODULE: ./src/lib/Optimized/OptimizedRegion.ts
@@ -9788,6 +9824,8 @@ class App_App {
9788
9824
  let _m = _data.scenes[i];
9789
9825
  if (_m.objectType == ObjectType.Storey || _m.objectType == ObjectType.ParkModel)
9790
9826
  continue;
9827
+ if (_m.id != "zWWMiZ0yp7Jx")
9828
+ continue;
9791
9829
  let _region = _regions.find(_m.parentId);
9792
9830
  if (_region.objectType == ObjectType.Floor)
9793
9831
  _objects.find(_region.parentId).push(_m);