123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- function data2d() {
-
- //全部墙
- this.wallIds=[];
- //默认是当前屏幕显示的全部墙
- this.showWallIds=[];
- this.symbol2DIds=[];
- //楼梯
- this.stairIds=[];
- //还没有确定的wall,表示正在添加的墙
- this.temp_wallId=null;
- //还没有确定的元素
- this.temp_symbol2DIds=[];
- //当前显示的元素
- this.show_symbol2DIds=[];
- //节点
- //通过nodes计算wall上的joins,如果节点对应的是墙角,则endIndex为-1
- //value大部分情况是二个元素的数组,如果大于两个元素,表示指向同一个join
- //key是整型
- //{1:{info:[{startIndex:1,endIndex:2,wallId:26}],join:point},2:{info:[],join:point2}}
- this.nodes={};
- this.currentnodeskey = 1;
- };
- //根据wallid的值删除
- data2d.prototype.deleteWallid = function(value)
- {
- if(this.wallIds!=null&&this.wallIds.length>0)
- {
- for(var i=0;i<this.wallIds.length;++i)
- {
- if(this.wallIds[i]==value)
- {
- this.wallIds.splice(i,1);
- return ;
- }
- }
- }
- };
- //移动墙面
- data2d.prototype.moveNodeForWall = function(np1,np2)
- {
- for(var key in this.nodes){
- var node = this.nodes[key]["info"];
- for(var i=0;i<node.length;++i)
- {
- if(node[i].wallId == np1.wallId&&node[i].startIndex == np1.startIndex&&node[i].endIndex == np1.endIndex)
- {
- if(node.length==2)
- {
- delete this.nodes[key];
- }
- else
- {
- this.nodes[key]["info"].splice(i,1);
- }
- }
- else if(node[i].wallId == np2.wallId&&node[i].startIndex == np2.startIndex&&node[i].endIndex == np2.endIndex)
- {
- if(node.length==2)
- {
- delete this.nodes[key];
- }
- else
- {
- this.nodes[key]["info"].splice(i,1);
- }
- }
- else if(node[i].wallId == np1.wallId&&node[i].startIndex == np1.startIndex&&node[i].endIndex == np2.startIndex)
- {
- if(node.length==2)
- {
- delete this.nodes[key];
- }
- else
- {
- this.nodes[key]["info"].splice(i,1);
- }
- }
- }
- }
- };
- //移动墙角
- data2d.prototype.moveNodeForWallCorner = function(np)
- {
- for(var key in this.nodes){
- var node = this.nodes[key]["info"];
- for(var i=0;i<node.length;++i)
- {
- if(node[i].wallId == np.wallId&&node[i].startIndex == np.startIndex&&node[i].endIndex == np.endIndex)
- {
- if(node.length==2)
- {
- delete this.nodes[key];
- }
- else
- {
- this.nodes[key]["info"].splice(i,1);
- }
- }
- }
- }
- };
- //对应的墙角,墙面消失了
- data2d.prototype.deleteNode = function(np,nextIndex)
- {
- for(var key in this.nodes){
- var node = this.nodes[key]["info"];
- for(var i=0;i<node.length;++i)
- {
- if(node[i].wallId == np.wallId&&node[i].startIndex == np.startIndex&&node[i].endIndex == np.endIndex)
- {
- if(node.length==2)
- {
- delete this.nodes[key];
- }
- else
- {
- this.nodes[key]["info"].splice(i,1);
- }
- }
- else if(node[i].wallId == np.wallId&&node[i].startIndex == np.startIndex&&node[i].endIndex == nextIndex)
- {
- if(node.length==2)
- {
- delete this.nodes[key];
- }
- else
- {
- this.nodes[key]["info"].splice(i,1);
- }
- }
- else if(node[i].wallId == np.wallId)
- {
- var index = Math.max(np.startIndex,np.endIndex);
- if(node[i].startIndex>index)
- {
- --node[i].startIndex;
- if(node[i].endIndex>index)
- {
- --node[i].endIndex;
- }
- this.nodes[key]["info"][i] = node[i];
- }
- }
- }
- }
- };
- data2d.prototype.addNode = function(np1,np2,join)
- {
- var interval=layer.parameter.wallThickness;
- for(var key in this.nodes){
- var node = this.nodes[key];
- var point = node["join"];
-
- var distance=BABYLON.Vector2.Distance(point,join);
- //重合
- if(distance<interval)
- {
- var info = this.nodes[key]["info"];
- var flag1=false;
- var flag2=false;
- for(var j=0;j<info.length;++j)
- {
- if(!flag1)
- {
- if(info.wallId == np1.wallId&&info.startIndex == np1.wallId&&info.endIndex == np1.wallId)
- {
- flag1 = true;
- }
- }
- if(!flag2)
- {
- if(info.wallId == np2.wallId&&info.startIndex == np2.wallId&&info.endIndex == np2.wallId)
- {
- flag2 = true;
- }
- }
- }
- if(!flag1)
- {
- this.nodes[key]["info"].push(np1);
- }
- if(!flag2)
- {
- this.nodes[key]["info"].push(np2);
- }
- return;
- }
- }
- this.nodes[this.currentnodeskey]={};
- this.nodes[this.currentnodeskey]["info"]=[];
- this.nodes[this.currentnodeskey]["info"].push(np1);
- this.nodes[this.currentnodeskey]["info"].push(np2);
- this.nodes[this.currentnodeskey]["join"] = join;
- ++this.currentnodeskey;
- };
|