decorate3D.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. //画墙、地板、门、窗、环境等
  2. function decorate3D(layer3D)
  3. {
  4. this.scene = layer3D.scene3D.scene;
  5. this.parameter = layer3D.layer.parameter;
  6. this.materials = layer3D.materials;
  7. this.collidableMeshes=layer3D.collectMeshes.collidableMeshes;
  8. this.roomWallMeshes=layer3D.collectMeshes.roomWallMeshes;
  9. this.arrowMeshes=layer3D.collectMeshes.arrowMeshes;
  10. this.layer3D = layer3D;
  11. this.floors = {
  12. index:0,
  13. selectId:null,
  14. floorImg:null
  15. };
  16. //里面的元素是json格式,主要分为wallId,floorId,material,type
  17. //this.paintSet=[];
  18. this.wallSet={submeshes:[],subMaterials:[],verticesStart:0,indexStart:0};
  19. };
  20. //使得墙透明
  21. decorate3D.prototype.transparentWall=function(value)
  22. {
  23. for(var i=0;i<this.roomWallMeshes.length;++i)
  24. {
  25. if((this.roomWallMeshes[i].name=="wall"||this.roomWallMeshes[i].name=="walltop")&&this.roomWallMeshes[i].floor<=parseInt(layer.selectFloor))
  26. {
  27. this.roomWallMeshes[i].visibility=value;
  28. }
  29. }
  30. };
  31. //显示某几层的内容
  32. decorate3D.prototype.showFloors=function(floor)
  33. {
  34. for(var i=0;i<this.collidableMeshes.length;++i)
  35. {
  36. if(this.collidableMeshes[i].floor<=floor&&this.collidableMeshes[i].name!="wallplane")
  37. {
  38. this.collidableMeshes[i].visibility=1;
  39. }
  40. }
  41. for(var i=0;i<this.roomWallMeshes.length;++i)
  42. {
  43. if(this.roomWallMeshes[i].floor<=floor)
  44. {
  45. this.roomWallMeshes[i].visibility=1;
  46. }
  47. }
  48. };
  49. //隐藏某几层的内容
  50. decorate3D.prototype.hideFloors=function(floor)
  51. {
  52. for(var i=0;i<this.collidableMeshes.length;++i)
  53. {
  54. if(this.collidableMeshes[i].floor>floor)
  55. {
  56. this.collidableMeshes[i].visibility=0;
  57. }
  58. }
  59. for(var i=0;i<this.roomWallMeshes.length;++i)
  60. {
  61. if(this.roomWallMeshes[i].floor>floor)
  62. {
  63. this.roomWallMeshes[i].visibility=0;
  64. }
  65. }
  66. };
  67. //删除某一层的内容
  68. decorate3D.prototype.deleteOneFloor=function(floor)
  69. {
  70. for(var i=0;i<this.collidableMeshes.length;++i)
  71. {
  72. if(this.collidableMeshes[i].floor== floor)
  73. {
  74. this.collidableMeshes[i].dispose();
  75. this.collidableMeshes.splice(i, 1);
  76. --i;
  77. }
  78. }
  79. for(var i=0;i<this.roomWallMeshes.length;++i)
  80. {
  81. if(this.roomWallMeshes[i].floor== floor)
  82. {
  83. this.roomWallMeshes[i].dispose();
  84. }
  85. }
  86. };
  87. //删除墙对应的内容
  88. decorate3D.prototype.deleteRoomMesh=function(wallId)
  89. {
  90. for(var i=0;i<this.collidableMeshes.length;++i)
  91. {
  92. //if(this.collidableMeshes[i].name=="wallplane"&&this.collidableMeshes[i].wallId== wallId)
  93. if(this.collidableMeshes[i].wallId== wallId)
  94. {
  95. this.collidableMeshes[i].dispose();
  96. this.collidableMeshes.splice(i, 1);
  97. --i;
  98. }
  99. }
  100. for(var i=0;i<this.roomWallMeshes.length;++i)
  101. {
  102. if(this.roomWallMeshes[i].wallId== wallId)
  103. {
  104. this.roomWallMeshes[i].dispose();
  105. }
  106. }
  107. }
  108. //删除墙,地板,门,窗户等等mesh
  109. decorate3D.prototype.deleteRoomMeshes=function()
  110. {
  111. for(var i=0;i<this.collidableMeshes.length;++i)
  112. {
  113. if(this.collidableMeshes[i].name=="wallplane")
  114. {
  115. this.collidableMeshes[i].dispose();
  116. this.collidableMeshes.splice(i, 1);
  117. --i;
  118. }
  119. }
  120. for(var i=0;i<this.roomWallMeshes.length;++i)
  121. {
  122. this.roomWallMeshes[i].dispose();
  123. }
  124. this.roomWallMeshes=[];
  125. };
  126. //添加天空
  127. decorate3D.prototype.addSkybox = function ()
  128. {
  129. this.skybox = BABYLON.Mesh.CreateBox("skyBox", this.parameter.skySize, this.scene);
  130. //this.skybox = BABYLON.Mesh.CreateBox("skyBox", 8000, this.scene);
  131. this.skybox.material = this.materials.skyboxMaterial;
  132. };
  133. decorate3D.prototype.refreshSkybox = function (img) {
  134. //this.skybox.material.diffuseTexture = new BABYLON.Texture(img, this.scene);
  135. this.skybox.material.reflectionTexture = new BABYLON.CubeTexture(img, this.scene);
  136. this.skybox.material.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  137. };
  138. //添加地面
  139. decorate3D.prototype.addGround = function () {
  140. // make a ground
  141. this.ground = BABYLON.Mesh.CreateBox("ground", 1, this.scene);
  142. this.ground.scaling = new BABYLON.Vector3(this.parameter.ground.length, this.parameter.ground.height, this.parameter.ground.width);
  143. this.ground.position.y = this.parameter.ground.positionY;
  144. this.ground.checkCollisions = true;
  145. this.ground.material = this.materials.groundMaterial;
  146. };
  147. decorate3D.prototype.refreshGround = function (img) {
  148. this.ground.material.diffuseTexture = new BABYLON.Texture(img, this.scene);
  149. };
  150. //添加地板
  151. decorate3D.prototype.drawFloor= function(id)
  152. {
  153. var shape;
  154. var points=layer.vectors[id].geometry.points;
  155. var floor=layer.vectors[id].geometry.floor;
  156. for(var i=0;i<points.length;++i)
  157. {
  158. if(i==0)
  159. {
  160. shape = new BABYLON.Path2(points[i].x, points[i].y);
  161. }
  162. else
  163. {
  164. shape.addLineTo(points[i].x, points[i].y);
  165. }
  166. }
  167. var floorPlane = new BABYLON.PolygonMeshBuilder("floorPlane", shape, this.scene).build();
  168. floorPlane.id="floorPlane"+this.floors.index;
  169. floorPlane.position.y =(floor-1)*this.parameter.wallHeight+this.parameter.floorPositionY;
  170. layer.vectors[id].geometry.floorId=floorPlane.id;
  171. floorPlane.material=this.materials.floormaterial;
  172. ++this.floors.index;
  173. floorPlane.floor=layer.vectors[id].geometry.floor;
  174. this.roomWallMeshes.push(floorPlane);
  175. return floorPlane;
  176. };
  177. decorate3D.prototype.refreshFloor = function (wallid)
  178. {
  179. if(this.layer3D.paint.currentId!=null)
  180. {
  181. var floormaterial = new BABYLON.StandardMaterial("floormaterial", this.scene);
  182. floormaterial.diffuseTexture = new BABYLON.Texture(this.floors.floorImg, this.scene);
  183. //floormaterial.bumpTexture = new BABYLON.Texture("images/floor1.png", this.scene);
  184. floormaterial.bumpTexture = new BABYLON.Texture(this.parameter.floorImgUrl, this.scene);
  185. this.scene.getMeshByID(this.layer3D.paint.currentId).material=floormaterial;
  186. document.getElementById("container3d").style.cursor="default";
  187. }
  188. };
  189. //添加不闭合的墙
  190. decorate3D.prototype.drawOpenWallSymbols=function(points,heights,symbols,type,id,floor)
  191. {
  192. var wallmeshes = [];
  193. var topWallmeshes=[];
  194. var pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8;
  195. this.wallSet.submeshes=[];
  196. this.wallSet.verticesStart=0;
  197. this.wallSet.indexStart=0;
  198. this.wallSet.subMaterials=[];
  199. var height = (floor-1)*this.parameter.wallHeight;
  200. var bottom = (floor-1)*this.parameter.wallHeight;
  201. var outpoints=points.build;
  202. var inpoints=points.use;
  203. var calculateLine=layer.calculateLine;
  204. var towards=[];
  205. var points=[];
  206. var collindex=[];
  207. heights[heights.length-1] = heights[heights.length-2];
  208. for(var i=0;i<outpoints.length-1;++i)
  209. {
  210. pt1=new BABYLON.Vector3(outpoints[i].x, bottom, outpoints[i].y);
  211. pt2=new BABYLON.Vector3(outpoints[i+1].x, bottom, outpoints[i+1].y);
  212. var mesh=this.drawSideWall(pt1,pt2,height+heights[i],id);
  213. pt3=new BABYLON.Vector3(inpoints[i].x, bottom, inpoints[i].y);
  214. pt4=new BABYLON.Vector3(inpoints[i+1].x, bottom, inpoints[i+1].y);
  215. var toward= calculateLine.getToward2(outpoints[i],outpoints[i+1],inpoints[i],inpoints[i+1]);
  216. towards.push(toward);
  217. this.collidableMeshes[this.collidableMeshes.length-1].toward=toward;
  218. points.push({point1:outpoints[i],point2:outpoints[i+1]});
  219. wallmeshes.push(mesh);
  220. collindex.push(mesh.planindex);
  221. if(i!=0)
  222. {
  223. mesh=this.drawSideWall(pt1,pt3,height+heights[i],id);
  224. wallmeshes.push(mesh);
  225. }
  226. if(i!=outpoints.length-2)
  227. {
  228. mesh=this.drawSideWall(pt2,pt4,height+heights[i],id);
  229. wallmeshes.push(mesh);
  230. }
  231. pt5=new BABYLON.Vector3(inpoints[i].x, height+heights[i], inpoints[i].y);
  232. pt6=new BABYLON.Vector3(inpoints[i+1].x, height+heights[i], inpoints[i+1].y);
  233. pt7=new BABYLON.Vector3(outpoints[i].x, height+heights[i], outpoints[i].y);
  234. pt8=new BABYLON.Vector3(outpoints[i+1].x, height+heights[i], outpoints[i+1].y);
  235. mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
  236. mesh.material=this.materials.wallmaterial;
  237. topWallmeshes.push(mesh);
  238. }
  239. pt1=new BABYLON.Vector3(outpoints[outpoints.length-1].x, bottom, outpoints[outpoints.length-1].y);
  240. pt2=new BABYLON.Vector3(inpoints[outpoints.length-1].x, bottom, inpoints[outpoints.length-1].y);
  241. var mesh=this.drawSideWall(pt1,pt2,height+heights[outpoints.length-2],id);
  242. var toward=calculateLine.getToward(outpoints[outpoints.length-1],inpoints[outpoints.length-1],outpoints[outpoints.length-2]);
  243. towards.push(-1*toward);
  244. this.collidableMeshes[this.collidableMeshes.length-1].toward=-1*toward;
  245. points.push({point1:outpoints[outpoints.length-1],point2:inpoints[outpoints.length-1]});
  246. wallmeshes.push(mesh);
  247. collindex.push(mesh.planindex);
  248. var num=wallmeshes.length-2;
  249. for(var i=inpoints.length-1;i>0;--i)
  250. {
  251. heights[i] = heights[i-1];
  252. pt1=new BABYLON.Vector3(inpoints[i].x, bottom, inpoints[i].y);
  253. pt2=new BABYLON.Vector3(inpoints[i-1].x, bottom, inpoints[i-1].y);
  254. var toward=-1*towards[num];
  255. var mesh=this.drawSideWall(pt1,pt2,height+heights[i],id);
  256. towards.push(toward);
  257. this.collidableMeshes[this.collidableMeshes.length-1].toward=toward;
  258. points.push({point1:inpoints[i],point2:inpoints[i-1]});
  259. --num;
  260. wallmeshes.push(mesh);
  261. collindex.push(mesh.planindex);
  262. }
  263. heights[0] = heights[1];
  264. pt1=new BABYLON.Vector3(inpoints[0].x, bottom, inpoints[0].y);
  265. pt2=new BABYLON.Vector3(outpoints[0].x, bottom, outpoints[0].y);
  266. var mesh=this.drawSideWall(pt1,pt2,height+heights[0],id);
  267. toward=calculateLine.getToward(inpoints[0],outpoints[0],outpoints[1]);
  268. towards.push(-1*toward);
  269. this.collidableMeshes[this.collidableMeshes.length-1].toward=-1*toward;
  270. points.push({point1:inpoints[0],point2:outpoints[0]});
  271. wallmeshes.push(mesh);
  272. collindex.push(mesh.planindex);
  273. var _topWallmesh=BABYLON.Mesh.MergeMeshes(topWallmeshes);
  274. var topCSG = BABYLON.CSG.FromMesh(_topWallmesh);
  275. var finalTopMesh = topCSG.toMesh("wallopen",this.materials.wallmaterial, this.scene,true);
  276. _topWallmesh.dispose();
  277. _topWallmesh=null;
  278. finalTopMesh.floor=floor;
  279. this.roomWallMeshes.push(finalTopMesh);
  280. var wallmesh=BABYLON.Mesh.MergeMeshes(wallmeshes);
  281. wallmesh.subMeshes = [];
  282. this.wallSet.subMaterials=[];
  283. for(var i=0;i<this.wallSet.submeshes.length;++i)
  284. {
  285. wallmesh.subMeshes.push(new BABYLON.SubMesh(i, this.wallSet.submeshes[i].verticesStart, this.wallSet.submeshes[i].verticesCount, this.wallSet.submeshes[i].indexStart,this.wallSet.submeshes[i].indexCount, wallmesh));
  286. var wallmaterial = this.materials.getwallmaterial(i);
  287. wallmaterial.toward=towards[i];
  288. wallmaterial.points=points[i];
  289. wallmaterial.indexplane=collindex[i];
  290. this.wallSet.subMaterials.push(wallmaterial);
  291. }
  292. var wallCSG =BABYLON.CSG.FromMesh(wallmesh);
  293. if(type==1)
  294. {
  295. this.baseSymbolThick=this.parameter.doorThick;
  296. }
  297. else
  298. {
  299. this.baseSymbolThick=this.parameter.doorThick/2;
  300. }
  301. for(var i=0;i<symbols.length;++i)
  302. {
  303. var symMesh;
  304. var len=symbols[i].len;
  305. var thick = layer.vectors[symbols[i].id].geometry.wallInfo[symbols[i].index].thick;
  306. if(symbols[i].type=="OpenDoor")
  307. {
  308. symMesh=this.drawOpeningDoor(symbols[i],len,thick);
  309. }
  310. else if(symbols[i].type=="OpenWindow")
  311. {
  312. symMesh=this.drawOpeningWindow(symbols[i],len,thick);
  313. }
  314. else if(symbols[i].type=="SimpleDoor")
  315. {
  316. symMesh=this.drawSimpleDoor(symbols[i],len,thick);
  317. }
  318. else if(symbols[i].type=="BiFoldDoor")
  319. {
  320. symMesh=this.drawBiFoldDoor(symbols[i],len,thick);
  321. }
  322. else if(symbols[i].type=="SlidingDoor")
  323. {
  324. symMesh=this.drawSlidingDoor(symbols[i],len,thick);
  325. }
  326. else if(symbols[i].type=="SingleCasement")
  327. {
  328. symMesh=this.drawSingleCasement(symbols[i],len,thick);
  329. }
  330. else if(symbols[i].type=="DoubleCasement")
  331. {
  332. symMesh=this.drawDoubleCasement(symbols[i],len,thick);
  333. }
  334. else if(symbols[i].type=="SlidingWindow")
  335. {
  336. symMesh=this.drawSlidingWindow(symbols[i],len,thick);
  337. }
  338. else
  339. {
  340. continue;
  341. }
  342. var symCSG = BABYLON.CSG.FromMesh(symMesh);
  343. wallCSG = wallCSG.subtract(symCSG);
  344. symMesh.dispose();
  345. }
  346. var wall = wallCSG.toMesh("wall"+id,null, this.scene,true);
  347. var multi=new BABYLON.MultiMaterial("material"+id,this.scene);
  348. multi.subMaterials=this.wallSet.subMaterials;
  349. wall.material=multi;
  350. wallmesh.dispose();
  351. wallmesh=null;
  352. wall.name="wall";
  353. wall.floor=floor;
  354. this.roomWallMeshes.push(wall);
  355. };
  356. //添加墙顶
  357. decorate3D.prototype.drawTopWall=function(pt1,pt2,pt3,pt4)
  358. {
  359. var mesh = new BABYLON.Mesh("mesh", this.scene);
  360. //mesh.material = this.materials.wallmaterial;
  361. var path1 = [];
  362. var path2 = [];
  363. path1.push(pt1);
  364. path1.push(pt2);
  365. path2.push(pt3);
  366. path2.push(pt4);
  367. // positions
  368. var positions = [];
  369. for (var i = 0; i < path1.length; i++) {
  370. positions.push(path1[i].x, path1[i].y, path1[i].z);
  371. positions.push(path2[i].x, path2[i].y, path2[i].z);
  372. };
  373. // indices
  374. var indices = [];
  375. for (var i = 0; i < path1.length * 2 - 2 ; i+=2) {
  376. indices.push(i, i+1, i+2);
  377. indices.push(i+3, i+2, i+1);
  378. };
  379. // normals
  380. var normals = [];
  381. BABYLON.VertexData.ComputeNormals(positions, indices, normals);
  382. // mesh
  383. var colors = [
  384. 1, 0, 0, 1,
  385. 0, 1, 0, 1,
  386. 0, 1, 0, 0,
  387. 0, 0, 1, 0,
  388. ];
  389. mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors);
  390. var uvs=[[0,0],[1,0],[1,1],[0,1]];
  391. mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
  392. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false);
  393. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false);
  394. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false);
  395. mesh.setIndices(indices);
  396. mesh.material = this.materials.wallmaterial;
  397. return mesh;
  398. };
  399. //添加墙的侧面
  400. decorate3D.prototype.drawSideWall=function(pt1,pt2,height,id)
  401. {
  402. var mesh = new BABYLON.Mesh("mesh", this.scene);
  403. var floor=layer.vectors[id].geometry.floor;
  404. //mesh.material = this.materials.wallmaterial;
  405. this.createwallPlane(new BABYLON.Vector2(pt1.x,pt1.z),new BABYLON.Vector2(pt2.x,pt2.z),id);
  406. height += (floor-1)*this.parameter.wallHeight;
  407. var path1 = [];
  408. var path2 = [];
  409. path1.push(pt1);
  410. path1.push(pt2);
  411. var pt3=new BABYLON.Vector3(pt1.x,height, pt1.z);
  412. var pt4=new BABYLON.Vector3(pt2.x,height, pt2.z);
  413. path2.push(pt3);
  414. path2.push(pt4);
  415. // positions
  416. var positions = [];
  417. for (var i = 0; i < path1.length; i++) {
  418. positions.push(path1[i].x, path1[i].y, path1[i].z);
  419. positions.push(path2[i].x, path2[i].y, path2[i].z);
  420. };
  421. // indices
  422. var indices = [];
  423. for (var i = 0; i < path1.length * 2 - 2 ; i+=2) {
  424. indices.push(i, i+1, i+2);
  425. indices.push(i+3, i+2, i+1);
  426. };
  427. // normals
  428. var normals = [];
  429. BABYLON.VertexData.ComputeNormals(positions, indices, normals);
  430. var uvs=[[0,0],[1,0],[1,1],[0,1]];
  431. mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
  432. var colors = [
  433. 1, 0, 0, 1,
  434. 0, 1, 0, 1,
  435. 0, 1, 0, 0,
  436. 0, 0, 1, 0,
  437. ];
  438. // mesh
  439. mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors);
  440. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false);
  441. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false);
  442. mesh.setIndices(indices);
  443. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false);
  444. mesh.material = this.materials.wallmaterial;
  445. this.wallSet.submeshes.push({verticesStart:this.wallSet.verticesStart, verticesCount:mesh.getTotalVertices(), indexStart:this.wallSet.indexStart, indexCount:mesh.getTotalIndices()});
  446. this.wallSet.verticesStart+=mesh.getTotalVertices();
  447. this.wallSet.indexStart+=mesh.getTotalIndices();
  448. mesh.planindex=this.collidableMeshes.length-1;
  449. return mesh;
  450. };
  451. //添加闭合的墙
  452. decorate3D.prototype.drawCloseWallSymbols=function(outpoints,inpoints,heights,symbols,type,id,floor)
  453. {
  454. var wallmeshes = [];
  455. var topWallmeshes=[];
  456. var pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8;
  457. var height = (floor-1)*this.parameter.wallHeight;
  458. var bottom = (floor-1)*this.parameter.wallHeight;
  459. this.wallSet.submeshes=[];
  460. this.wallSet.verticesStart=0;
  461. this.wallSet.indexStart=0;
  462. this.wallSet.subMaterials=[];
  463. var calculateLine=layer.calculateLine;
  464. var towards=[];
  465. var points=[];
  466. var collindex=[];
  467. for(var i=0;i<outpoints.length;++i)
  468. {
  469. if(i==outpoints.length-1)
  470. {
  471. pt1=new BABYLON.Vector3(outpoints[0].x, bottom, outpoints[0].y);
  472. pt2=new BABYLON.Vector3(outpoints[outpoints.length-1].x, bottom, outpoints[outpoints.length-1].y);
  473. var mesh=this.drawSideWall(pt2,pt1,height+heights[i],id);
  474. wallmeshes.push(mesh);
  475. collindex.push(mesh.planindex);
  476. pt3=new BABYLON.Vector3(inpoints[0].x, bottom, inpoints[0].y);
  477. pt4=new BABYLON.Vector3(inpoints[inpoints.length-1].x, bottom, inpoints[inpoints.length-1].y);
  478. var toward= calculateLine.getToward2(outpoints[0],outpoints[outpoints.length-1],inpoints[0],inpoints[inpoints.length-1]);
  479. towards.push(toward);
  480. this.collidableMeshes[this.collidableMeshes.length-1].toward=toward;
  481. points.push({point1:outpoints[0],point2:outpoints[outpoints.length-1]});
  482. mesh=this.drawSideWall(pt3,pt4,height+heights[i],id);
  483. //mesh.toward=-1*toward;
  484. towards.push(-1*toward);
  485. this.collidableMeshes[this.collidableMeshes.length-1].toward=-1*toward;
  486. points.push({point1:inpoints[0],point2:inpoints[inpoints.length-1]});
  487. wallmeshes.push(mesh);
  488. collindex.push(mesh.planindex);
  489. pt5=new BABYLON.Vector3(inpoints[inpoints.length-1].x, height+heights[i], inpoints[inpoints.length-1].y);
  490. pt6=new BABYLON.Vector3(inpoints[0].x, height+heights[i], inpoints[0].y);
  491. pt7=new BABYLON.Vector3(outpoints[outpoints.length-1].x, height+heights[i], outpoints[outpoints.length-1].y);
  492. pt8=new BABYLON.Vector3(outpoints[0].x, height+heights[i], outpoints[0].y);
  493. mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
  494. mesh.material=this.materials.wallmaterial;
  495. topWallmeshes.push(mesh);
  496. }
  497. else
  498. {
  499. pt1=new BABYLON.Vector3(outpoints[i].x, bottom, outpoints[i].y);
  500. pt2=new BABYLON.Vector3(outpoints[i+1].x, bottom, outpoints[i+1].y);
  501. var mesh=this.drawSideWall(pt1,pt2,height+heights[i],id);
  502. wallmeshes.push(mesh);
  503. collindex.push(mesh.planindex);
  504. pt3=new BABYLON.Vector3(inpoints[i].x, bottom, inpoints[i].y);
  505. pt4=new BABYLON.Vector3(inpoints[i+1].x, bottom, inpoints[i+1].y);
  506. //var toward= calculateLine.getToward2(pt1,pt2,pt3,pt4);
  507. var toward= calculateLine.getToward2(outpoints[i],outpoints[i+1],inpoints[i],inpoints[i+1]);
  508. //mesh.toward=toward;
  509. points.push({point1:outpoints[i],point2:outpoints[i+1]});
  510. towards.push(toward);
  511. this.collidableMeshes[this.collidableMeshes.length-1].toward=toward;
  512. mesh=this.drawSideWall(pt3,pt4,height+heights[i],id);
  513. //mesh.toward=-1*toward;
  514. points.push({point1:inpoints[i],point2:inpoints[i+1]});
  515. towards.push(-1*toward);
  516. this.collidableMeshes[this.collidableMeshes.length-1].toward=-1*toward;
  517. wallmeshes.push(mesh);
  518. collindex.push(mesh.planindex);
  519. pt5=new BABYLON.Vector3(inpoints[i].x, height+heights[i], inpoints[i].y);
  520. pt6=new BABYLON.Vector3(inpoints[i+1].x, height+heights[i], inpoints[i+1].y);
  521. pt7=new BABYLON.Vector3(outpoints[i].x, height+heights[i], outpoints[i].y);
  522. pt8=new BABYLON.Vector3(outpoints[i+1].x, height+heights[i], outpoints[i+1].y);
  523. mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
  524. mesh.material=this.materials.wallmaterial;
  525. topWallmeshes.push(mesh);
  526. }
  527. mesh=this.drawSideWall(pt1,pt3,height+heights[i],id);
  528. wallmeshes.push(mesh);
  529. mesh=this.drawSideWall(pt2,pt4,height+heights[i],id);
  530. wallmeshes.push(mesh);
  531. }
  532. var _topWallmesh=BABYLON.Mesh.MergeMeshes(topWallmeshes);
  533. var topCSG = BABYLON.CSG.FromMesh(_topWallmesh);
  534. var finalTopMesh = topCSG.toMesh("walltop",this.materials.wallmaterial, this.scene,true);
  535. _topWallmesh.dispose();
  536. _topWallmesh=null;
  537. finalTopMesh.floor=floor;
  538. this.roomWallMeshes.push(finalTopMesh);
  539. var wallmesh=BABYLON.Mesh.MergeMeshes(wallmeshes);
  540. wallmesh.subMeshes = [];
  541. this.wallSet.subMaterials=[];
  542. for(var i=0;i<this.wallSet.submeshes.length;++i)
  543. {
  544. wallmesh.subMeshes.push(new BABYLON.SubMesh(i, this.wallSet.submeshes[i].verticesStart, this.wallSet.submeshes[i].verticesCount, this.wallSet.submeshes[i].indexStart,this.wallSet.submeshes[i].indexCount, wallmesh));
  545. var wallmaterial =this.materials.getwallmaterial(i);
  546. wallmaterial.toward=towards[i];
  547. wallmaterial.points=points[i];
  548. wallmaterial.indexplane=collindex[i];
  549. this.wallSet.subMaterials.push(wallmaterial);
  550. }
  551. var wallCSG =BABYLON.CSG.FromMesh(wallmesh);
  552. if(type==1)
  553. {
  554. this.baseSymbolThick=this.parameter.doorThick;
  555. }
  556. else
  557. {
  558. this.baseSymbolThick=this.parameter.doorThick/2;
  559. }
  560. for(var i=0;i<symbols.length;++i)
  561. {
  562. var symMesh;
  563. //var len=this.getLen(symbols[i].type);
  564. var len=symbols[i].len;
  565. var thick = layer.vectors[symbols[i].id].geometry.wallInfo[symbols[i].index].thick;
  566. if(symbols[i].type=="OpenDoor")
  567. {
  568. symMesh=this.drawOpeningDoor(symbols[i],len,thick);
  569. }
  570. else if(symbols[i].type=="OpenWindow")
  571. {
  572. symMesh=this.drawOpeningWindow(symbols[i],len,thick);
  573. }
  574. else if(symbols[i].type=="SimpleDoor")
  575. {
  576. symMesh=this.drawSimpleDoor(symbols[i],len,thick);
  577. }
  578. else if(symbols[i].type=="BiFoldDoor")
  579. {
  580. symMesh=this.drawBiFoldDoor(symbols[i],len,thick);
  581. }
  582. else if(symbols[i].type=="SlidingDoor")
  583. {
  584. symMesh=this.drawSlidingDoor(symbols[i],len,thick);
  585. }
  586. else if(symbols[i].type=="SingleCasement")
  587. {
  588. symMesh=this.drawSingleCasement(symbols[i],len,thick);
  589. }
  590. else if(symbols[i].type=="DoubleCasement")
  591. {
  592. symMesh=this.drawDoubleCasement(symbols[i],len,thick);
  593. }
  594. else if(symbols[i].type=="SlidingWindow")
  595. {
  596. symMesh=this.drawSlidingWindow(symbols[i],len,thick);
  597. }
  598. else
  599. {
  600. continue;
  601. }
  602. var symCSG = BABYLON.CSG.FromMesh(symMesh);
  603. wallCSG = wallCSG.subtract(symCSG);
  604. symMesh.dispose();
  605. }
  606. var wall = wallCSG.toMesh("wall"+id,null, this.scene,true);
  607. var multi=new BABYLON.MultiMaterial("material"+id,this.scene);
  608. multi.subMaterials=this.wallSet.subMaterials;
  609. wall.material=multi;
  610. wallmesh.dispose();
  611. wallmesh=null;
  612. wall.name="wall";
  613. wall.floor=floor;
  614. this.roomWallMeshes.push(wall);
  615. };
  616. //每个墙添加plane,防止模型与墙重合
  617. decorate3D.prototype.createwallPlane=function (point1,point2,id) {
  618. var floor=layer.vectors[id].geometry.floor;
  619. var p1=new BABYLON.Vector2(point1.x, point1.y);
  620. var p2=new BABYLON.Vector2(point2.x, point2.y);
  621. var distance= BABYLON.Vector2.Distance(p1,p2);
  622. var plan = BABYLON.Mesh.CreatePlane("wallplane", 1, this.scene);
  623. plan.scaling.x=distance;
  624. //plan.scaling.y =1;
  625. plan.scaling.y =this.parameter.wallHeight;
  626. plan.material = this.materials.wallmaterial;
  627. //plan.position=new BABYLON.Vector3((p1.x+p2.x)/2,0.5, (p1.y+p2.y)/2);
  628. plan.position=new BABYLON.Vector3((p1.x+p2.x)/2,(floor-1)*this.parameter.wallHeight+this.parameter.wallHeight/2, (p1.y+p2.y)/2);
  629. var angle=BABYLON.Angle.BetweenTwoPoints(p1,p2);
  630. plan.rotation.y=-angle._radians;
  631. plan.visibility=0;
  632. plan.pts={point1:point1,point2:point2};
  633. plan.planindex=this.collidableMeshes.length;
  634. plan.wallId=id;
  635. plan.floor=floor;
  636. this.collidableMeshes.push(plan);
  637. //plan.dispose();
  638. };
  639. decorate3D.prototype.clearAllSymbols=function()
  640. {
  641. for(var i=0;i<this.collidableMeshes.length;++i)
  642. {
  643. this.collidableMeshes[i].dispose();
  644. }
  645. for(var i=0;i<this.roomWallMeshes.length;++i)
  646. {
  647. this.roomWallMeshes[i].dispose();
  648. }
  649. for(var i=0;i<this.arrowMeshes.length;++i)
  650. {
  651. this.arrowMeshes[i].dispose();
  652. }
  653. for(var i=0;i<this.glassBoxMeshes.length;++i)
  654. {
  655. this.glassBoxMeshes[i].dispose();
  656. }
  657. }
  658. decorate3D.prototype.clearSymbol=function()
  659. {
  660. for(var i=0;i<this.collidableMeshes.length;++i)
  661. {
  662. if(this.collidableMeshes[i].name=="wallplane")
  663. {
  664. this.collidableMeshes[i].dispose();
  665. this.collidableMeshes.splice(i, 1);
  666. --i;
  667. }
  668. }
  669. for(var i=0;i<this.roomWallMeshes.length;++i)
  670. {
  671. this.roomWallMeshes[i].dispose();
  672. }
  673. };
  674. //添加opendoor
  675. decorate3D.prototype.drawOpeningDoor= function(location,len,thick)
  676. {
  677. var floor=layer.vectors[location.id].geometry.floor;
  678. var cubeMesh = BABYLON.Mesh.CreateBox( "OpeningDoor", 1, this.scene);
  679. //cubeMesh.scaling=new BABYLON.Vector3(this.baseSymbolThick,len/2,);
  680. //baseSymbolThick是30,doorHeigh是100,len是60
  681. cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick);
  682. cubeMesh.position=new BABYLON.Vector3(location.point.x, (floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  683. cubeMesh.rotation.y=-location.angle;
  684. return cubeMesh;
  685. };
  686. //添加openwindow
  687. decorate3D.prototype.drawOpeningWindow= function(location,len,thick)
  688. {
  689. var floor=layer.vectors[location.id].geometry.floor;
  690. var cubeMesh = BABYLON.Mesh.CreateBox( "OpeningWindow", 1, this.scene);
  691. //baseSymbolThick是30,parameter.windowHeight是50,len是40
  692. cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.windowHeight,this.parameter.dthick+thick);
  693. cubeMesh.position=new BABYLON.Vector3(location.point.x, (floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
  694. cubeMesh.rotation.y=-location.angle;
  695. return cubeMesh;
  696. };
  697. //添加SimpleDoor
  698. decorate3D.prototype.drawSimpleDoor= function(location,len,thick)
  699. {
  700. var floor=layer.vectors[location.id].geometry.floor;
  701. var cubeMesh = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
  702. cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick);
  703. cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  704. cubeMesh.rotation.y=-location.angle;
  705. var cubeMesh2 = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
  706. cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick+1);
  707. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  708. var cubeMesh4 = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
  709. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,this.parameter.dthick+thick+1);
  710. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  711. var subCSG = aCSG.subtract(bCSG);
  712. var newMesh = subCSG.toMesh("door", this.materials.frameMaterial, this.scene);
  713. newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  714. newMesh.rotation.y=-location.angle;
  715. newMesh.wallId=location.id;
  716. newMesh.floor=layer.vectors[location.id].geometry.floor;
  717. this.roomWallMeshes.push(newMesh);
  718. cubeMesh4.dispose();
  719. cubeMesh2.dispose();
  720. var cubeMesh3 = BABYLON.Mesh.CreateBox( "door", 1, this.scene);
  721. cubeMesh3.scaling=new BABYLON.Vector3(len-10,20,this.parameter.doorHeigh-10);
  722. cubeMesh3.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  723. cubeMesh3.rotation.y=-location.angle;
  724. cubeMesh3.rotation.x = Math.PI / 2;
  725. cubeMesh3.material=this.materials.doorMaterial;
  726. cubeMesh3.wallId=location.id;
  727. cubeMesh3.floor=layer.vectors[location.id].geometry.floor;
  728. this.roomWallMeshes.push(cubeMesh3);
  729. var cubeMesh5=BABYLON.Mesh.CreateBox( "door", 1, this.scene);
  730. cubeMesh5.scaling=new BABYLON.Vector3(10,2,22);
  731. cubeMesh5.position=new BABYLON.Vector3(location.point.x+20*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y+20*Math.sin(location.angle));
  732. cubeMesh5.rotation.y=-location.angle;
  733. cubeMesh5.material=this.materials.doorknobMaterial;
  734. cubeMesh5.wallId=location.id;
  735. cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
  736. this.roomWallMeshes.push(cubeMesh5);
  737. return cubeMesh;
  738. };
  739. //添加SingleCasement
  740. decorate3D.prototype.drawSingleCasement= function(location,len,thick)
  741. {
  742. var floor=layer.vectors[location.id].geometry.floor;
  743. var cubeMesh = BABYLON.Mesh.CreateBox( "SingleCasementWindow", 1, this.scene);
  744. cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.windowHeight,this.parameter.doorThick);
  745. cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
  746. cubeMesh.rotation.y=-location.angle;
  747. var cubeMesh2 = BABYLON.Mesh.CreateBox( "SingleCasementWindow", 1, this.scene);
  748. cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.windowHeight,this.parameter.dthick+thick+1);
  749. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  750. var cubeMesh4 = BABYLON.Mesh.CreateBox( "SingleCasementWindow", 1, this.scene);
  751. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.windowHeight-10,this.parameter.dthick+thick+1);
  752. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  753. var subCSG = aCSG.subtract(bCSG);
  754. var newMesh = subCSG.toMesh("window", this.materials.frameMaterial, this.scene);
  755. newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
  756. newMesh.rotation.y=-location.angle;
  757. newMesh.wallId=location.id;
  758. newMesh.floor=layer.vectors[location.id].geometry.floor;
  759. this.roomWallMeshes.push(newMesh);
  760. cubeMesh4.dispose();
  761. cubeMesh2.dispose();
  762. var cubeMesh3 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
  763. cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.parameter.windowHeight-10,20);
  764. var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
  765. var cubeMesh1 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
  766. cubeMesh1.scaling=new BABYLON.Vector3(len-20,this.parameter.windowHeight-20,21);
  767. var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
  768. var subCSG2 = cCSG.subtract(dCSG);
  769. var newMesh2 = subCSG2.toMesh("window", this.materials.windowframeMaterial, this.scene);
  770. newMesh2.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
  771. newMesh2.rotation.y=-location.angle;
  772. newMesh2.wallId=location.id;
  773. newMesh2.floor=layer.vectors[location.id].geometry.floor;
  774. this.roomWallMeshes.push(newMesh2);
  775. cubeMesh1.dispose();
  776. cubeMesh3.dispose();
  777. //镜子
  778. var cubeMesh6 = BABYLON.Mesh.CreateBox( "window", 1, this.scene);
  779. cubeMesh6.scaling=new BABYLON.Vector3(len-20,21,this.parameter.windowHeight-20);
  780. cubeMesh6.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
  781. cubeMesh6.rotation.z=-location.angle;
  782. cubeMesh6.rotation.x = Math.PI / 2;
  783. var mirrorMaterial = new BABYLON.StandardMaterial("mirror", this.scene);
  784. cubeMesh6.visibility = 0.08;
  785. cubeMesh6.material=mirrorMaterial;
  786. cubeMesh6.wallId=location.id;
  787. cubeMesh6.floor=layer.vectors[location.id].geometry.floor;
  788. this.roomWallMeshes.push(cubeMesh6);
  789. var cubeMesh5=BABYLON.Mesh.CreateBox( "window", 1, this.scene);
  790. cubeMesh5.scaling=new BABYLON.Vector3(2,5,22);
  791. cubeMesh5.position=new BABYLON.Vector3(location.point.x+14*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y+14*Math.sin(location.angle));
  792. cubeMesh5.rotation.y=-location.angle;
  793. cubeMesh5.material=this.materials.doorknobMaterial;
  794. cubeMesh5.wallId=location.id;
  795. cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
  796. this.roomWallMeshes.push(cubeMesh5);
  797. return cubeMesh;
  798. };
  799. //添加SlidingDoor
  800. decorate3D.prototype.drawSlidingDoor=function(location,len,thick)
  801. {
  802. var floor=layer.vectors[location.id].geometry.floor;
  803. var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
  804. cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.doorThick);
  805. cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  806. cubeMesh.rotation.y=-location.angle;
  807. var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
  808. cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick+1);
  809. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  810. var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
  811. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,this.parameter.dthick+thick+1);
  812. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  813. var subCSG = aCSG.subtract(bCSG);
  814. var newMesh = subCSG.toMesh("door", this.materials.frameMaterial, this.scene);
  815. newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  816. newMesh.rotation.y=-location.angle;
  817. newMesh.wallId=location.id;
  818. newMesh.floor=layer.vectors[location.id].geometry.floor;
  819. this.roomWallMeshes.push(newMesh);
  820. cubeMesh4.dispose();
  821. cubeMesh2.dispose();
  822. var cubeMesh3 = BABYLON.Mesh.CreateBox( "door", 1, this.scene);
  823. cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,20);
  824. cubeMesh3.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  825. cubeMesh3.rotation.y=-location.angle;
  826. cubeMesh3.material=this.materials.doorMaterial;
  827. cubeMesh3.wallId=location.id;
  828. cubeMesh3.floor=layer.vectors[location.id].geometry.floor;
  829. this.roomWallMeshes.push(cubeMesh3);
  830. var cubeMesh5=BABYLON.Mesh.CreateBox( "door", 1, this.scene);
  831. cubeMesh5.scaling=new BABYLON.Vector3(2,10,22);
  832. cubeMesh5.position=new BABYLON.Vector3(location.point.x+5*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y+5*Math.sin(location.angle));
  833. cubeMesh5.rotation.y=-location.angle;
  834. cubeMesh5.material=this.materials.doorknobMaterial;
  835. cubeMesh5.wallId=location.id;
  836. cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
  837. this.roomWallMeshes.push(cubeMesh5);
  838. var cubeMesh6 = cubeMesh5.clone("door");
  839. cubeMesh6.position=new BABYLON.Vector3(location.point.x-5*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y-5*Math.sin(location.angle));
  840. cubeMesh6.wallId=location.id;
  841. cubeMesh6.floor=layer.vectors[location.id].geometry.floor;
  842. this.roomWallMeshes.push(cubeMesh6);
  843. return cubeMesh;
  844. };
  845. //添加BiFoldDoor
  846. decorate3D.prototype.drawBiFoldDoor=function(location,len,thick)
  847. {
  848. var floor=layer.vectors[location.id].geometry.floor;
  849. //墙挖洞
  850. var cubeMesh = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
  851. cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.doorThick);
  852. cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  853. cubeMesh.rotation.y=-location.angle;
  854. //门框
  855. var cubeMesh2 = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
  856. cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick+1);
  857. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  858. //门框挖洞
  859. var cubeMesh4 = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
  860. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,this.parameter.dthick+thick+1);
  861. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  862. var subCSG = aCSG.subtract(bCSG);
  863. var newMesh = subCSG.toMesh("door", this.materials.frameMaterial, this.scene);
  864. newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  865. newMesh.rotation.y=-location.angle;
  866. newMesh.wallId=location.id;
  867. newMesh.floor=layer.vectors[location.id].geometry.floor;
  868. this.roomWallMeshes.push(newMesh);
  869. cubeMesh4.dispose();
  870. cubeMesh2.dispose();
  871. //大门
  872. var cubeMesh3 = BABYLON.Mesh.CreateBox( "door", 1, this.scene);
  873. cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,20);
  874. cubeMesh3.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  875. cubeMesh3.rotation.y=-location.angle;
  876. cubeMesh3.material=this.materials.doorMaterial;
  877. cubeMesh3.wallId=location.id;
  878. cubeMesh3.floor=layer.vectors[location.id].geometry.floor;
  879. this.roomWallMeshes.push(cubeMesh3);
  880. //门把手
  881. var cubeMesh5=BABYLON.Mesh.CreateBox( "door", 1, this.scene);
  882. cubeMesh5.scaling=new BABYLON.Vector3(2,10,22);
  883. cubeMesh5.position=new BABYLON.Vector3(location.point.x+40*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y+40*Math.sin(location.angle));
  884. cubeMesh5.rotation.y=-location.angle;
  885. cubeMesh5.material=this.materials.doorknobMaterial;
  886. cubeMesh5.wallId=location.id;
  887. cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
  888. this.roomWallMeshes.push(cubeMesh5);
  889. var cubeMesh6 = cubeMesh5.clone("door");
  890. cubeMesh6.position=new BABYLON.Vector3(location.point.x-40*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y-40*Math.sin(location.angle));
  891. cubeMesh6.wallId=location.id;
  892. cubeMesh6.floor=layer.vectors[location.id].geometry.floor;
  893. this.roomWallMeshes.push(cubeMesh6);
  894. return cubeMesh;
  895. };
  896. //添加DoubleCasement
  897. decorate3D.prototype.drawDoubleCasement=function(location,len,thick)
  898. {
  899. var floor=layer.vectors[location.id].geometry.floor;
  900. var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  901. cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.windowHeight,this.parameter.doorThick);
  902. cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
  903. cubeMesh.rotation.y=-location.angle;
  904. var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  905. cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.windowHeight,this.parameter.dthick+thick+1);
  906. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  907. var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  908. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.windowHeight-10,this.parameter.dthick+thick+1);
  909. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  910. var subCSG = aCSG.subtract(bCSG);
  911. var newMesh = subCSG.toMesh("window", this.materials.frameMaterial, this.scene);
  912. newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
  913. newMesh.rotation.y=-location.angle;
  914. newMesh.wallId=location.id;
  915. newMesh.floor=layer.vectors[location.id].geometry.floor;
  916. this.roomWallMeshes.push(newMesh);
  917. cubeMesh4.dispose();
  918. cubeMesh2.dispose();
  919. var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  920. cubeMesh3.scaling=new BABYLON.Vector3(len/2,this.parameter.windowHeight-10,20);
  921. var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
  922. var cubeMesh1 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  923. cubeMesh1.scaling=new BABYLON.Vector3(len/2-11,this.parameter.windowHeight-20,21);
  924. var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
  925. var subCSG2 = cCSG.subtract(dCSG);
  926. var newMesh2 = subCSG2.toMesh("window", this.materials.windowframeMaterial, this.scene);
  927. newMesh2.position=new BABYLON.Vector3(location.point.x+25*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y+25*Math.sin(location.angle));
  928. newMesh2.rotation.y=-location.angle;
  929. newMesh2.wallId=location.id;
  930. newMesh2.floor=layer.vectors[location.id].geometry.floor;
  931. this.roomWallMeshes.push(newMesh2);
  932. var newMesh3 = newMesh2.clone("window");
  933. newMesh3.position=new BABYLON.Vector3(location.point.x-25*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y-25*Math.sin(location.angle));
  934. cubeMesh1.dispose();
  935. cubeMesh3.dispose();
  936. newMesh3.wallId=location.id;
  937. newMesh3.floor=layer.vectors[location.id].geometry.floor;
  938. this.roomWallMeshes.push(newMesh3);
  939. //镜子
  940. var cubeMesh6 = BABYLON.Mesh.CreateBox( "window", 1, this.scene);
  941. cubeMesh6.scaling=new BABYLON.Vector3(len-10,this.parameter.windowHeight,21);
  942. cubeMesh6.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
  943. cubeMesh6.rotation.y=-location.angle;
  944. cubeMesh6.visibility = 0.08;
  945. cubeMesh6.wallId=location.id;
  946. cubeMesh6.floor=layer.vectors[location.id].geometry.floor;
  947. this.roomWallMeshes.push(cubeMesh6);
  948. if(this.materials.doorknobMaterial==null)
  949. {
  950. this.setdoorknobMaterial();
  951. }
  952. var cubeMesh5=BABYLON.Mesh.CreateBox( "window", 1, this.scene);
  953. cubeMesh5.scaling=new BABYLON.Vector3(2,22,5);
  954. cubeMesh5.position=new BABYLON.Vector3(location.point.x+2*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y+2*Math.sin(location.angle));
  955. cubeMesh5.rotation.y=-location.angle;
  956. cubeMesh5.rotation.x = Math.PI / 2;
  957. cubeMesh5.material=this.materials.doorknobMaterial;
  958. cubeMesh5.wallId=location.id;
  959. cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
  960. this.roomWallMeshes.push(cubeMesh5);
  961. var cubeMesh7 = cubeMesh5.clone("window");
  962. cubeMesh7.position=new BABYLON.Vector3(location.point.x-2*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y-2*Math.sin(location.angle));
  963. cubeMesh7.wallId=location.id;
  964. cubeMesh7.floor=layer.vectors[location.id].geometry.floor;
  965. this.roomWallMeshes.push(cubeMesh7);
  966. return cubeMesh;
  967. };
  968. //添加SlidingWindow
  969. decorate3D.prototype.drawSlidingWindow=function(location,len,thick)
  970. {
  971. var floor=layer.vectors[location.id].geometry.floor;
  972. var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  973. cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.doorThick);
  974. cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  975. cubeMesh.rotation.y=-location.angle;
  976. var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  977. cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick+1);
  978. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  979. var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  980. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,this.parameter.dthick+thick+1);
  981. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  982. var subCSG = aCSG.subtract(bCSG);
  983. var newMesh = subCSG.toMesh("window", this.materials.frameMaterial, this.scene);
  984. newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  985. newMesh.rotation.y=-location.angle;
  986. newMesh.wallId=location.id;
  987. newMesh.floor=layer.vectors[location.id].geometry.floor;
  988. this.roomWallMeshes.push(newMesh);
  989. cubeMesh4.dispose();
  990. cubeMesh2.dispose();
  991. var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  992. cubeMesh3.scaling=new BABYLON.Vector3(len/2-5,this.parameter.doorHeigh-10,20);
  993. var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
  994. var cubeMesh1 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  995. cubeMesh1.scaling=new BABYLON.Vector3(len/2-16,this.parameter.doorHeigh-20,21);
  996. var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
  997. var subCSG2 = cCSG.subtract(dCSG);
  998. var newMesh2 = subCSG2.toMesh("window", this.materials.windowframeMaterial, this.scene);
  999. newMesh2.position=new BABYLON.Vector3(location.point.x+25*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y+25*Math.sin(location.angle));
  1000. newMesh2.rotation.y=-location.angle;
  1001. newMesh2.wallId=location.id;
  1002. newMesh2.floor=layer.vectors[location.id].geometry.floor;
  1003. this.roomWallMeshes.push(newMesh2);
  1004. var newMesh3 = newMesh2.clone("window");
  1005. newMesh3.position=new BABYLON.Vector3(location.point.x-25*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y-25*Math.sin(location.angle));
  1006. newMesh3.wallId=location.id;
  1007. newMesh3.floor=layer.vectors[location.id].geometry.floor;
  1008. this.roomWallMeshes.push(newMesh3);
  1009. cubeMesh1.dispose();
  1010. cubeMesh3.dispose();
  1011. //镜子
  1012. var cubeMesh6 = BABYLON.Mesh.CreateBox( "window", 1, this.scene);
  1013. cubeMesh6.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh,21);
  1014. cubeMesh6.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
  1015. cubeMesh6.rotation.y=-location.angle;
  1016. cubeMesh6.visibility = 0.08;
  1017. cubeMesh6.wallId=location.id;
  1018. cubeMesh6.floor=layer.vectors[location.id].geometry.floor;
  1019. this.roomWallMeshes.push(cubeMesh6);
  1020. var cubeMesh5=BABYLON.Mesh.CreateBox( "window", 1, this.scene);
  1021. cubeMesh5.scaling=new BABYLON.Vector3(2,22,5);
  1022. cubeMesh5.position=new BABYLON.Vector3(location.point.x+2*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y+2*Math.sin(location.angle));
  1023. cubeMesh5.rotation.y=-location.angle;
  1024. cubeMesh5.rotation.x = Math.PI / 2;
  1025. cubeMesh5.material=this.materials.doorknobMaterial;
  1026. cubeMesh5.wallId=location.id;
  1027. cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
  1028. this.roomWallMeshes.push(cubeMesh5);
  1029. var cubeMesh7 = cubeMesh5.clone("window");
  1030. cubeMesh7.position=new BABYLON.Vector3(location.point.x-2*Math.cos(location.angle),(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y-2*Math.sin(location.angle));
  1031. cubeMesh7.wallId=location.id;
  1032. cubeMesh7.floor=layer.vectors[location.id].geometry.floor;
  1033. this.roomWallMeshes.push(cubeMesh7);;
  1034. return cubeMesh;
  1035. };