data2d.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. function data2d() {
  2. //全部墙
  3. this.wallIds=[];
  4. //默认是当前屏幕显示的全部墙
  5. this.showWallIds=[];
  6. this.symbol2DIds=[];
  7. //楼梯
  8. this.stairIds=[];
  9. //还没有确定的wall,表示正在添加的墙
  10. this.temp_wallId=null;
  11. //还没有确定的元素
  12. this.temp_symbol2DIds=[];
  13. //当前显示的元素
  14. this.show_symbol2DIds=[];
  15. //节点
  16. //通过nodes计算wall上的joins,如果节点对应的是墙角,则endIndex为-1
  17. //value大部分情况是二个元素的数组,如果大于两个元素,表示指向同一个join
  18. //key是整型
  19. //{1:{info:[{startIndex:1,endIndex:2,wallId:26}],join:point},2:{info:[],join:point2}}
  20. this.nodes={};
  21. this.currentnodeskey = 1;
  22. };
  23. //根据wallid的值删除
  24. data2d.prototype.deleteWallid = function(value)
  25. {
  26. if(this.wallIds!=null&&this.wallIds.length>0)
  27. {
  28. for(var i=0;i<this.wallIds.length;++i)
  29. {
  30. if(this.wallIds[i]==value)
  31. {
  32. this.wallIds.splice(i,1);
  33. return ;
  34. }
  35. }
  36. }
  37. };
  38. //移动墙面
  39. data2d.prototype.moveNodeForWall = function(np1,np2)
  40. {
  41. for(var key in this.nodes){
  42. var node = this.nodes[key]["info"];
  43. for(var i=0;i<node.length;++i)
  44. {
  45. if(node[i].wallId == np1.wallId&&node[i].startIndex == np1.startIndex&&node[i].endIndex == np1.endIndex)
  46. {
  47. if(node.length==2)
  48. {
  49. delete this.nodes[key];
  50. }
  51. else
  52. {
  53. this.nodes[key]["info"].splice(i,1);
  54. }
  55. }
  56. else if(node[i].wallId == np2.wallId&&node[i].startIndex == np2.startIndex&&node[i].endIndex == np2.endIndex)
  57. {
  58. if(node.length==2)
  59. {
  60. delete this.nodes[key];
  61. }
  62. else
  63. {
  64. this.nodes[key]["info"].splice(i,1);
  65. }
  66. }
  67. else if(node[i].wallId == np1.wallId&&node[i].startIndex == np1.startIndex&&node[i].endIndex == np2.startIndex)
  68. {
  69. if(node.length==2)
  70. {
  71. delete this.nodes[key];
  72. }
  73. else
  74. {
  75. this.nodes[key]["info"].splice(i,1);
  76. }
  77. }
  78. }
  79. }
  80. };
  81. //移动墙角
  82. data2d.prototype.moveNodeForWallCorner = function(np)
  83. {
  84. for(var key in this.nodes){
  85. var node = this.nodes[key]["info"];
  86. for(var i=0;i<node.length;++i)
  87. {
  88. if(node[i].wallId == np.wallId&&node[i].startIndex == np.startIndex&&node[i].endIndex == np.endIndex)
  89. {
  90. if(node.length==2)
  91. {
  92. delete this.nodes[key];
  93. }
  94. else
  95. {
  96. this.nodes[key]["info"].splice(i,1);
  97. }
  98. }
  99. }
  100. }
  101. };
  102. //对应的墙角,墙面消失了
  103. data2d.prototype.deleteNode = function(np,nextIndex)
  104. {
  105. for(var key in this.nodes){
  106. var node = this.nodes[key]["info"];
  107. for(var i=0;i<node.length;++i)
  108. {
  109. if(node[i].wallId == np.wallId&&node[i].startIndex == np.startIndex&&node[i].endIndex == np.endIndex)
  110. {
  111. if(node.length==2)
  112. {
  113. delete this.nodes[key];
  114. }
  115. else
  116. {
  117. this.nodes[key]["info"].splice(i,1);
  118. }
  119. }
  120. else if(node[i].wallId == np.wallId&&node[i].startIndex == np.startIndex&&node[i].endIndex == nextIndex)
  121. {
  122. if(node.length==2)
  123. {
  124. delete this.nodes[key];
  125. }
  126. else
  127. {
  128. this.nodes[key]["info"].splice(i,1);
  129. }
  130. }
  131. else if(node[i].wallId == np.wallId)
  132. {
  133. var index = Math.max(np.startIndex,np.endIndex);
  134. if(node[i].startIndex>index)
  135. {
  136. --node[i].startIndex;
  137. if(node[i].endIndex>index)
  138. {
  139. --node[i].endIndex;
  140. }
  141. this.nodes[key]["info"][i] = node[i];
  142. }
  143. }
  144. }
  145. }
  146. };
  147. data2d.prototype.addNode = function(np1,np2,join)
  148. {
  149. var interval=layer.parameter.wallThickness;
  150. for(var key in this.nodes){
  151. var node = this.nodes[key];
  152. var point = node["join"];
  153. var distance=BABYLON.Vector2.Distance(point,join);
  154. //重合
  155. if(distance<interval)
  156. {
  157. var info = this.nodes[key]["info"];
  158. var flag1=false;
  159. var flag2=false;
  160. for(var j=0;j<info.length;++j)
  161. {
  162. if(!flag1)
  163. {
  164. if(info.wallId == np1.wallId&&info.startIndex == np1.wallId&&info.endIndex == np1.wallId)
  165. {
  166. flag1 = true;
  167. }
  168. }
  169. if(!flag2)
  170. {
  171. if(info.wallId == np2.wallId&&info.startIndex == np2.wallId&&info.endIndex == np2.wallId)
  172. {
  173. flag2 = true;
  174. }
  175. }
  176. }
  177. if(!flag1)
  178. {
  179. this.nodes[key]["info"].push(np1);
  180. }
  181. if(!flag2)
  182. {
  183. this.nodes[key]["info"].push(np2);
  184. }
  185. return;
  186. }
  187. }
  188. this.nodes[this.currentnodeskey]={};
  189. this.nodes[this.currentnodeskey]["info"]=[];
  190. this.nodes[this.currentnodeskey]["info"].push(np1);
  191. this.nodes[this.currentnodeskey]["info"].push(np2);
  192. this.nodes[this.currentnodeskey]["join"] = join;
  193. ++this.currentnodeskey;
  194. };