123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191 |
- //画墙、地板、门、窗、环境等
- function decorate3D(layer3D)
- {
- this.scene = layer3D.scene3D.scene;
- this.parameter = layer3D.layer.parameter;
- this.materials = layer3D.materials;
-
- this.collidableMeshes=layer3D.collectMeshes.collidableMeshes;
- this.roomWallMeshes=layer3D.collectMeshes.roomWallMeshes;
- this.arrowMeshes=layer3D.collectMeshes.arrowMeshes;
-
- this.layer3D = layer3D;
-
- this.floors = {
- index:0,
- selectId:null,
- floorImg:null
- };
-
- //里面的元素是json格式,主要分为wallId,floorId,material,type
- //this.paintSet=[];
- this.wallSet={submeshes:[],subMaterials:[],verticesStart:0,indexStart:0};
- };
- //使得墙透明
- decorate3D.prototype.transparentWall=function(value)
- {
- for(var i=0;i<this.roomWallMeshes.length;++i)
- {
- if((this.roomWallMeshes[i].name=="wall"||this.roomWallMeshes[i].name=="walltop")&&this.roomWallMeshes[i].floor<=parseInt(layer.selectFloor))
- {
- this.roomWallMeshes[i].visibility=value;
- }
- }
- };
- //显示某几层的内容
- decorate3D.prototype.showFloors=function(floor)
- {
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- if(this.collidableMeshes[i].floor<=floor&&this.collidableMeshes[i].name!="wallplane")
- {
- this.collidableMeshes[i].visibility=1;
- }
- }
-
- for(var i=0;i<this.roomWallMeshes.length;++i)
- {
- if(this.roomWallMeshes[i].floor<=floor)
- {
- this.roomWallMeshes[i].visibility=1;
- }
- }
- };
- //隐藏某几层的内容
- decorate3D.prototype.hideFloors=function(floor)
- {
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- if(this.collidableMeshes[i].floor>floor)
- {
- this.collidableMeshes[i].visibility=0;
- }
- }
-
- for(var i=0;i<this.roomWallMeshes.length;++i)
- {
- if(this.roomWallMeshes[i].floor>floor)
- {
- this.roomWallMeshes[i].visibility=0;
- }
- }
- };
- //删除某一层的内容
- decorate3D.prototype.deleteOneFloor=function(floor)
- {
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- if(this.collidableMeshes[i].floor== floor)
- {
- this.collidableMeshes[i].dispose();
- this.collidableMeshes.splice(i, 1);
- --i;
- }
- }
-
- for(var i=0;i<this.roomWallMeshes.length;++i)
- {
- if(this.roomWallMeshes[i].floor== floor)
- {
- this.roomWallMeshes[i].dispose();
- }
-
- }
- };
- //删除墙对应的内容
- decorate3D.prototype.deleteRoomMesh=function(wallId)
- {
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- //if(this.collidableMeshes[i].name=="wallplane"&&this.collidableMeshes[i].wallId== wallId)
- if(this.collidableMeshes[i].wallId== wallId)
- {
- this.collidableMeshes[i].dispose();
- this.collidableMeshes.splice(i, 1);
- --i;
- }
- }
-
- for(var i=0;i<this.roomWallMeshes.length;++i)
- {
- if(this.roomWallMeshes[i].wallId== wallId)
- {
- this.roomWallMeshes[i].dispose();
- }
-
- }
- }
- //删除墙,地板,门,窗户等等mesh
- decorate3D.prototype.deleteRoomMeshes=function()
- {
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- if(this.collidableMeshes[i].name=="wallplane")
- {
- this.collidableMeshes[i].dispose();
- this.collidableMeshes.splice(i, 1);
- --i;
- }
- }
-
- for(var i=0;i<this.roomWallMeshes.length;++i)
- {
- this.roomWallMeshes[i].dispose();
- }
- this.roomWallMeshes=[];
- };
- //添加天空
- decorate3D.prototype.addSkybox = function ()
- {
- this.skybox = BABYLON.Mesh.CreateBox("skyBox", this.parameter.skySize, this.scene);
- //this.skybox = BABYLON.Mesh.CreateBox("skyBox", 8000, this.scene);
- this.skybox.material = this.materials.skyboxMaterial;
- };
- decorate3D.prototype.refreshSkybox = function (img) {
- //this.skybox.material.diffuseTexture = new BABYLON.Texture(img, this.scene);
- this.skybox.material.reflectionTexture = new BABYLON.CubeTexture(img, this.scene);
- this.skybox.material.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
- };
- //添加地面
- decorate3D.prototype.addGround = function () {
- // make a ground
- this.ground = BABYLON.Mesh.CreateBox("ground", 1, this.scene);
- this.ground.scaling = new BABYLON.Vector3(this.parameter.ground.length, this.parameter.ground.height, this.parameter.ground.width);
- this.ground.position.y = this.parameter.ground.positionY;
- this.ground.checkCollisions = true;
- this.ground.material = this.materials.groundMaterial;
- };
- decorate3D.prototype.refreshGround = function (img) {
- this.ground.material.diffuseTexture = new BABYLON.Texture(img, this.scene);
- };
- //添加地板
- decorate3D.prototype.drawFloor= function(id)
- {
- var shape;
- var points=layer.vectors[id].geometry.points;
- var floor=layer.vectors[id].geometry.floor;
- for(var i=0;i<points.length;++i)
- {
- if(i==0)
- {
- shape = new BABYLON.Path2(points[i].x, points[i].y);
- }
- else
- {
- shape.addLineTo(points[i].x, points[i].y);
- }
- }
-
- var floorPlane = new BABYLON.PolygonMeshBuilder("floorPlane", shape, this.scene).build();
- floorPlane.id="floorPlane"+this.floors.index;
- floorPlane.position.y =(floor-1)*this.parameter.wallHeight+this.parameter.floorPositionY;
- layer.vectors[id].geometry.floorId=floorPlane.id;
-
- floorPlane.material=this.materials.floormaterial;
-
- ++this.floors.index;
- floorPlane.floor=layer.vectors[id].geometry.floor;
- this.roomWallMeshes.push(floorPlane);
- return floorPlane;
- };
- decorate3D.prototype.refreshFloor = function (wallid)
- {
- if(this.layer3D.paint.currentId!=null)
- {
- var floormaterial = new BABYLON.StandardMaterial("floormaterial", this.scene);
- floormaterial.diffuseTexture = new BABYLON.Texture(this.floors.floorImg, this.scene);
- //floormaterial.bumpTexture = new BABYLON.Texture("images/floor1.png", this.scene);
- floormaterial.bumpTexture = new BABYLON.Texture(this.parameter.floorImgUrl, this.scene);
-
- this.scene.getMeshByID(this.layer3D.paint.currentId).material=floormaterial;
- document.getElementById("container3d").style.cursor="default";
- }
- };
- //添加不闭合的墙
- decorate3D.prototype.drawOpenWallSymbols=function(points,heights,symbols,type,id,floor)
- {
- var wallmeshes = [];
- var topWallmeshes=[];
- var pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8;
-
- this.wallSet.submeshes=[];
- this.wallSet.verticesStart=0;
- this.wallSet.indexStart=0;
- this.wallSet.subMaterials=[];
-
- var height = (floor-1)*this.parameter.wallHeight;
- var bottom = (floor-1)*this.parameter.wallHeight;
-
- var outpoints=points.build;
- var inpoints=points.use;
-
- var calculateLine=layer.calculateLine;
- var towards=[];
- var points=[];
- var collindex=[];
-
- heights[heights.length-1] = heights[heights.length-2];
-
- for(var i=0;i<outpoints.length-1;++i)
- {
- pt1=new BABYLON.Vector3(outpoints[i].x, bottom, outpoints[i].y);
- pt2=new BABYLON.Vector3(outpoints[i+1].x, bottom, outpoints[i+1].y);
- var mesh=this.drawSideWall(pt1,pt2,height+heights[i],id);
-
- pt3=new BABYLON.Vector3(inpoints[i].x, bottom, inpoints[i].y);
- pt4=new BABYLON.Vector3(inpoints[i+1].x, bottom, inpoints[i+1].y);
-
- var toward= calculateLine.getToward2(outpoints[i],outpoints[i+1],inpoints[i],inpoints[i+1]);
- towards.push(toward);
- this.collidableMeshes[this.collidableMeshes.length-1].toward=toward;
- points.push({point1:outpoints[i],point2:outpoints[i+1]});
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- if(i!=0)
- {
- mesh=this.drawSideWall(pt1,pt3,height+heights[i],id);
- wallmeshes.push(mesh);
- }
-
- if(i!=outpoints.length-2)
- {
- mesh=this.drawSideWall(pt2,pt4,height+heights[i],id);
- wallmeshes.push(mesh);
- }
-
- pt5=new BABYLON.Vector3(inpoints[i].x, height+heights[i], inpoints[i].y);
- pt6=new BABYLON.Vector3(inpoints[i+1].x, height+heights[i], inpoints[i+1].y);
- pt7=new BABYLON.Vector3(outpoints[i].x, height+heights[i], outpoints[i].y);
- pt8=new BABYLON.Vector3(outpoints[i+1].x, height+heights[i], outpoints[i+1].y);
- mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
- mesh.material=this.materials.wallmaterial;
- topWallmeshes.push(mesh);
- }
-
- pt1=new BABYLON.Vector3(outpoints[outpoints.length-1].x, bottom, outpoints[outpoints.length-1].y);
- pt2=new BABYLON.Vector3(inpoints[outpoints.length-1].x, bottom, inpoints[outpoints.length-1].y);
- var mesh=this.drawSideWall(pt1,pt2,height+heights[outpoints.length-2],id);
- var toward=calculateLine.getToward(outpoints[outpoints.length-1],inpoints[outpoints.length-1],outpoints[outpoints.length-2]);
- towards.push(-1*toward);
- this.collidableMeshes[this.collidableMeshes.length-1].toward=-1*toward;
- points.push({point1:outpoints[outpoints.length-1],point2:inpoints[outpoints.length-1]});
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- var num=wallmeshes.length-2;
- for(var i=inpoints.length-1;i>0;--i)
- {
- heights[i] = heights[i-1];
- pt1=new BABYLON.Vector3(inpoints[i].x, bottom, inpoints[i].y);
- pt2=new BABYLON.Vector3(inpoints[i-1].x, bottom, inpoints[i-1].y);
- var toward=-1*towards[num];
- var mesh=this.drawSideWall(pt1,pt2,height+heights[i],id);
- towards.push(toward);
- this.collidableMeshes[this.collidableMeshes.length-1].toward=toward;
- points.push({point1:inpoints[i],point2:inpoints[i-1]});
- --num;
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
- }
- heights[0] = heights[1];
-
- pt1=new BABYLON.Vector3(inpoints[0].x, bottom, inpoints[0].y);
- pt2=new BABYLON.Vector3(outpoints[0].x, bottom, outpoints[0].y);
- var mesh=this.drawSideWall(pt1,pt2,height+heights[0],id);
- toward=calculateLine.getToward(inpoints[0],outpoints[0],outpoints[1]);
- towards.push(-1*toward);
- this.collidableMeshes[this.collidableMeshes.length-1].toward=-1*toward;
- points.push({point1:inpoints[0],point2:outpoints[0]});
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- var _topWallmesh=BABYLON.Mesh.MergeMeshes(topWallmeshes);
- var topCSG = BABYLON.CSG.FromMesh(_topWallmesh);
- var finalTopMesh = topCSG.toMesh("wallopen",this.materials.wallmaterial, this.scene,true);
- _topWallmesh.dispose();
- _topWallmesh=null;
- finalTopMesh.floor=floor;
- this.roomWallMeshes.push(finalTopMesh);
-
- var wallmesh=BABYLON.Mesh.MergeMeshes(wallmeshes);
-
- wallmesh.subMeshes = [];
- this.wallSet.subMaterials=[];
- for(var i=0;i<this.wallSet.submeshes.length;++i)
- {
- 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));
- var wallmaterial = this.materials.getwallmaterial(i);
- wallmaterial.toward=towards[i];
- wallmaterial.points=points[i];
- wallmaterial.indexplane=collindex[i];
- this.wallSet.subMaterials.push(wallmaterial);
-
- }
-
- var wallCSG =BABYLON.CSG.FromMesh(wallmesh);
-
- if(type==1)
- {
- this.baseSymbolThick=this.parameter.doorThick;
- }
- else
- {
- this.baseSymbolThick=this.parameter.doorThick/2;
- }
-
- for(var i=0;i<symbols.length;++i)
- {
- var symMesh;
- var len=symbols[i].len;
- var thick = layer.vectors[symbols[i].id].geometry.wallInfo[symbols[i].index].thick;
- if(symbols[i].type=="OpenDoor")
- {
- symMesh=this.drawOpeningDoor(symbols[i],len,thick);
- }
- else if(symbols[i].type=="OpenWindow")
- {
- symMesh=this.drawOpeningWindow(symbols[i],len,thick);
- }
- else if(symbols[i].type=="SimpleDoor")
- {
- symMesh=this.drawSimpleDoor(symbols[i],len,thick);
- }
- else if(symbols[i].type=="BiFoldDoor")
- {
- symMesh=this.drawBiFoldDoor(symbols[i],len,thick);
- }
- else if(symbols[i].type=="SlidingDoor")
- {
- symMesh=this.drawSlidingDoor(symbols[i],len,thick);
- }
- else if(symbols[i].type=="SingleCasement")
- {
- symMesh=this.drawSingleCasement(symbols[i],len,thick);
- }
- else if(symbols[i].type=="DoubleCasement")
- {
- symMesh=this.drawDoubleCasement(symbols[i],len,thick);
- }
- else if(symbols[i].type=="SlidingWindow")
- {
- symMesh=this.drawSlidingWindow(symbols[i],len,thick);
- }
- else
- {
- continue;
- }
- var symCSG = BABYLON.CSG.FromMesh(symMesh);
- wallCSG = wallCSG.subtract(symCSG);
- symMesh.dispose();
- }
- var wall = wallCSG.toMesh("wall"+id,null, this.scene,true);
- var multi=new BABYLON.MultiMaterial("material"+id,this.scene);
- multi.subMaterials=this.wallSet.subMaterials;
-
- wall.material=multi;
- wallmesh.dispose();
- wallmesh=null;
- wall.name="wall";
- wall.floor=floor;
- this.roomWallMeshes.push(wall);
-
- };
- //添加墙顶
- decorate3D.prototype.drawTopWall=function(pt1,pt2,pt3,pt4)
- {
- var mesh = new BABYLON.Mesh("mesh", this.scene);
- //mesh.material = this.materials.wallmaterial;
-
- var path1 = [];
- var path2 = [];
-
- path1.push(pt1);
- path1.push(pt2);
-
- path2.push(pt3);
- path2.push(pt4);
-
- // positions
- var positions = [];
- for (var i = 0; i < path1.length; i++) {
- positions.push(path1[i].x, path1[i].y, path1[i].z);
- positions.push(path2[i].x, path2[i].y, path2[i].z);
- };
- // indices
- var indices = [];
- for (var i = 0; i < path1.length * 2 - 2 ; i+=2) {
- indices.push(i, i+1, i+2);
- indices.push(i+3, i+2, i+1);
- };
-
- // normals
- var normals = [];
- BABYLON.VertexData.ComputeNormals(positions, indices, normals);
- // mesh
- var colors = [
- 1, 0, 0, 1,
- 0, 1, 0, 1,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- ];
- mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors);
- var uvs=[[0,0],[1,0],[1,1],[0,1]];
- mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
- mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false);
- mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false);
- mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false);
- mesh.setIndices(indices);
- mesh.material = this.materials.wallmaterial;
- return mesh;
- };
- //添加墙的侧面
- decorate3D.prototype.drawSideWall=function(pt1,pt2,height,id)
- {
- var mesh = new BABYLON.Mesh("mesh", this.scene);
- var floor=layer.vectors[id].geometry.floor;
- //mesh.material = this.materials.wallmaterial;
- this.createwallPlane(new BABYLON.Vector2(pt1.x,pt1.z),new BABYLON.Vector2(pt2.x,pt2.z),id);
-
- height += (floor-1)*this.parameter.wallHeight;
-
- var path1 = [];
- var path2 = [];
-
- path1.push(pt1);
- path1.push(pt2);
-
- var pt3=new BABYLON.Vector3(pt1.x,height, pt1.z);
- var pt4=new BABYLON.Vector3(pt2.x,height, pt2.z);
-
- path2.push(pt3);
- path2.push(pt4);
-
- // positions
- var positions = [];
- for (var i = 0; i < path1.length; i++) {
- positions.push(path1[i].x, path1[i].y, path1[i].z);
- positions.push(path2[i].x, path2[i].y, path2[i].z);
- };
- // indices
- var indices = [];
- for (var i = 0; i < path1.length * 2 - 2 ; i+=2) {
- indices.push(i, i+1, i+2);
- indices.push(i+3, i+2, i+1);
- };
-
- // normals
- var normals = [];
- BABYLON.VertexData.ComputeNormals(positions, indices, normals);
-
- var uvs=[[0,0],[1,0],[1,1],[0,1]];
- mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
-
- var colors = [
- 1, 0, 0, 1,
- 0, 1, 0, 1,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- ];
-
- // mesh
- mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors);
- mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false);
- mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false);
- mesh.setIndices(indices);
- mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false);
- mesh.material = this.materials.wallmaterial;
- this.wallSet.submeshes.push({verticesStart:this.wallSet.verticesStart, verticesCount:mesh.getTotalVertices(), indexStart:this.wallSet.indexStart, indexCount:mesh.getTotalIndices()});
- this.wallSet.verticesStart+=mesh.getTotalVertices();
- this.wallSet.indexStart+=mesh.getTotalIndices();
-
- mesh.planindex=this.collidableMeshes.length-1;
- return mesh;
- };
- //添加闭合的墙
- decorate3D.prototype.drawCloseWallSymbols=function(outpoints,inpoints,heights,symbols,type,id,floor)
- {
- var wallmeshes = [];
- var topWallmeshes=[];
- var pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8;
- var height = (floor-1)*this.parameter.wallHeight;
- var bottom = (floor-1)*this.parameter.wallHeight;
- this.wallSet.submeshes=[];
- this.wallSet.verticesStart=0;
- this.wallSet.indexStart=0;
- this.wallSet.subMaterials=[];
-
- var calculateLine=layer.calculateLine;
-
- var towards=[];
- var points=[];
- var collindex=[];
-
- for(var i=0;i<outpoints.length;++i)
- {
- if(i==outpoints.length-1)
- {
- pt1=new BABYLON.Vector3(outpoints[0].x, bottom, outpoints[0].y);
- pt2=new BABYLON.Vector3(outpoints[outpoints.length-1].x, bottom, outpoints[outpoints.length-1].y);
- var mesh=this.drawSideWall(pt2,pt1,height+heights[i],id);
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- pt3=new BABYLON.Vector3(inpoints[0].x, bottom, inpoints[0].y);
- pt4=new BABYLON.Vector3(inpoints[inpoints.length-1].x, bottom, inpoints[inpoints.length-1].y);
-
- var toward= calculateLine.getToward2(outpoints[0],outpoints[outpoints.length-1],inpoints[0],inpoints[inpoints.length-1]);
- towards.push(toward);
- this.collidableMeshes[this.collidableMeshes.length-1].toward=toward;
- points.push({point1:outpoints[0],point2:outpoints[outpoints.length-1]});
-
- mesh=this.drawSideWall(pt3,pt4,height+heights[i],id);
- //mesh.toward=-1*toward;
- towards.push(-1*toward);
- this.collidableMeshes[this.collidableMeshes.length-1].toward=-1*toward;
- points.push({point1:inpoints[0],point2:inpoints[inpoints.length-1]});
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- pt5=new BABYLON.Vector3(inpoints[inpoints.length-1].x, height+heights[i], inpoints[inpoints.length-1].y);
- pt6=new BABYLON.Vector3(inpoints[0].x, height+heights[i], inpoints[0].y);
- pt7=new BABYLON.Vector3(outpoints[outpoints.length-1].x, height+heights[i], outpoints[outpoints.length-1].y);
- pt8=new BABYLON.Vector3(outpoints[0].x, height+heights[i], outpoints[0].y);
- mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
- mesh.material=this.materials.wallmaterial;
- topWallmeshes.push(mesh);
- }
- else
- {
- pt1=new BABYLON.Vector3(outpoints[i].x, bottom, outpoints[i].y);
- pt2=new BABYLON.Vector3(outpoints[i+1].x, bottom, outpoints[i+1].y);
- var mesh=this.drawSideWall(pt1,pt2,height+heights[i],id);
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- pt3=new BABYLON.Vector3(inpoints[i].x, bottom, inpoints[i].y);
- pt4=new BABYLON.Vector3(inpoints[i+1].x, bottom, inpoints[i+1].y);
-
- //var toward= calculateLine.getToward2(pt1,pt2,pt3,pt4);
- var toward= calculateLine.getToward2(outpoints[i],outpoints[i+1],inpoints[i],inpoints[i+1]);
- //mesh.toward=toward;
- points.push({point1:outpoints[i],point2:outpoints[i+1]});
- towards.push(toward);
- this.collidableMeshes[this.collidableMeshes.length-1].toward=toward;
-
- mesh=this.drawSideWall(pt3,pt4,height+heights[i],id);
- //mesh.toward=-1*toward;
- points.push({point1:inpoints[i],point2:inpoints[i+1]});
- towards.push(-1*toward);
- this.collidableMeshes[this.collidableMeshes.length-1].toward=-1*toward;
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- pt5=new BABYLON.Vector3(inpoints[i].x, height+heights[i], inpoints[i].y);
- pt6=new BABYLON.Vector3(inpoints[i+1].x, height+heights[i], inpoints[i+1].y);
- pt7=new BABYLON.Vector3(outpoints[i].x, height+heights[i], outpoints[i].y);
- pt8=new BABYLON.Vector3(outpoints[i+1].x, height+heights[i], outpoints[i+1].y);
- mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
- mesh.material=this.materials.wallmaterial;
- topWallmeshes.push(mesh);
- }
-
- mesh=this.drawSideWall(pt1,pt3,height+heights[i],id);
- wallmeshes.push(mesh);
-
- mesh=this.drawSideWall(pt2,pt4,height+heights[i],id);
- wallmeshes.push(mesh);
- }
- var _topWallmesh=BABYLON.Mesh.MergeMeshes(topWallmeshes);
- var topCSG = BABYLON.CSG.FromMesh(_topWallmesh);
- var finalTopMesh = topCSG.toMesh("walltop",this.materials.wallmaterial, this.scene,true);
- _topWallmesh.dispose();
- _topWallmesh=null;
- finalTopMesh.floor=floor;
- this.roomWallMeshes.push(finalTopMesh);
-
- var wallmesh=BABYLON.Mesh.MergeMeshes(wallmeshes);
-
- wallmesh.subMeshes = [];
- this.wallSet.subMaterials=[];
- for(var i=0;i<this.wallSet.submeshes.length;++i)
- {
- 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));
- var wallmaterial =this.materials.getwallmaterial(i);
- wallmaterial.toward=towards[i];
- wallmaterial.points=points[i];
- wallmaterial.indexplane=collindex[i];
- this.wallSet.subMaterials.push(wallmaterial);
- }
-
- var wallCSG =BABYLON.CSG.FromMesh(wallmesh);
-
- if(type==1)
- {
- this.baseSymbolThick=this.parameter.doorThick;
- }
- else
- {
- this.baseSymbolThick=this.parameter.doorThick/2;
- }
-
- for(var i=0;i<symbols.length;++i)
- {
- var symMesh;
- //var len=this.getLen(symbols[i].type);
- var len=symbols[i].len;
- var thick = layer.vectors[symbols[i].id].geometry.wallInfo[symbols[i].index].thick;
- if(symbols[i].type=="OpenDoor")
- {
- symMesh=this.drawOpeningDoor(symbols[i],len,thick);
- }
- else if(symbols[i].type=="OpenWindow")
- {
- symMesh=this.drawOpeningWindow(symbols[i],len,thick);
- }
- else if(symbols[i].type=="SimpleDoor")
- {
- symMesh=this.drawSimpleDoor(symbols[i],len,thick);
- }
- else if(symbols[i].type=="BiFoldDoor")
- {
- symMesh=this.drawBiFoldDoor(symbols[i],len,thick);
- }
- else if(symbols[i].type=="SlidingDoor")
- {
- symMesh=this.drawSlidingDoor(symbols[i],len,thick);
- }
- else if(symbols[i].type=="SingleCasement")
- {
- symMesh=this.drawSingleCasement(symbols[i],len,thick);
- }
- else if(symbols[i].type=="DoubleCasement")
- {
- symMesh=this.drawDoubleCasement(symbols[i],len,thick);
- }
- else if(symbols[i].type=="SlidingWindow")
- {
- symMesh=this.drawSlidingWindow(symbols[i],len,thick);
- }
- else
- {
- continue;
- }
- var symCSG = BABYLON.CSG.FromMesh(symMesh);
- wallCSG = wallCSG.subtract(symCSG);
- symMesh.dispose();
- }
- var wall = wallCSG.toMesh("wall"+id,null, this.scene,true);
- var multi=new BABYLON.MultiMaterial("material"+id,this.scene);
- multi.subMaterials=this.wallSet.subMaterials;
- wall.material=multi;
- wallmesh.dispose();
- wallmesh=null;
-
- wall.name="wall";
- wall.floor=floor;
- this.roomWallMeshes.push(wall);
-
- };
- //每个墙添加plane,防止模型与墙重合
- decorate3D.prototype.createwallPlane=function (point1,point2,id) {
- var floor=layer.vectors[id].geometry.floor;
- var p1=new BABYLON.Vector2(point1.x, point1.y);
- var p2=new BABYLON.Vector2(point2.x, point2.y);
- var distance= BABYLON.Vector2.Distance(p1,p2);
- var plan = BABYLON.Mesh.CreatePlane("wallplane", 1, this.scene);
- plan.scaling.x=distance;
- //plan.scaling.y =1;
- plan.scaling.y =this.parameter.wallHeight;
- plan.material = this.materials.wallmaterial;
-
- //plan.position=new BABYLON.Vector3((p1.x+p2.x)/2,0.5, (p1.y+p2.y)/2);
- plan.position=new BABYLON.Vector3((p1.x+p2.x)/2,(floor-1)*this.parameter.wallHeight+this.parameter.wallHeight/2, (p1.y+p2.y)/2);
- var angle=BABYLON.Angle.BetweenTwoPoints(p1,p2);
- plan.rotation.y=-angle._radians;
- plan.visibility=0;
- plan.pts={point1:point1,point2:point2};
- plan.planindex=this.collidableMeshes.length;
- plan.wallId=id;
- plan.floor=floor;
- this.collidableMeshes.push(plan);
- //plan.dispose();
- };
- decorate3D.prototype.clearAllSymbols=function()
- {
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- this.collidableMeshes[i].dispose();
- }
-
- for(var i=0;i<this.roomWallMeshes.length;++i)
- {
- this.roomWallMeshes[i].dispose();
- }
-
- for(var i=0;i<this.arrowMeshes.length;++i)
- {
- this.arrowMeshes[i].dispose();
- }
-
- for(var i=0;i<this.glassBoxMeshes.length;++i)
- {
- this.glassBoxMeshes[i].dispose();
- }
- }
- decorate3D.prototype.clearSymbol=function()
- {
-
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- if(this.collidableMeshes[i].name=="wallplane")
- {
- this.collidableMeshes[i].dispose();
- this.collidableMeshes.splice(i, 1);
- --i;
- }
-
- }
-
- for(var i=0;i<this.roomWallMeshes.length;++i)
- {
- this.roomWallMeshes[i].dispose();
- }
- };
- //添加opendoor
- decorate3D.prototype.drawOpeningDoor= function(location,len,thick)
- {
- var floor=layer.vectors[location.id].geometry.floor;
- var cubeMesh = BABYLON.Mesh.CreateBox( "OpeningDoor", 1, this.scene);
- //cubeMesh.scaling=new BABYLON.Vector3(this.baseSymbolThick,len/2,);
- //baseSymbolThick是30,doorHeigh是100,len是60
- cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x, (floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- return cubeMesh;
- };
- //添加openwindow
- decorate3D.prototype.drawOpeningWindow= function(location,len,thick)
- {
- var floor=layer.vectors[location.id].geometry.floor;
- var cubeMesh = BABYLON.Mesh.CreateBox( "OpeningWindow", 1, this.scene);
- //baseSymbolThick是30,parameter.windowHeight是50,len是40
- cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.windowHeight,this.parameter.dthick+thick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x, (floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- return cubeMesh;
- };
- //添加SimpleDoor
- decorate3D.prototype.drawSimpleDoor= function(location,len,thick)
- {
- var floor=layer.vectors[location.id].geometry.floor;
- var cubeMesh = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,this.parameter.dthick+thick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
-
- var newMesh = subCSG.toMesh("door", this.materials.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- newMesh.wallId=location.id;
- newMesh.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(newMesh);
- cubeMesh4.dispose();
- cubeMesh2.dispose();
-
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "door", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len-10,20,this.parameter.doorHeigh-10);
- cubeMesh3.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- cubeMesh3.rotation.y=-location.angle;
- cubeMesh3.rotation.x = Math.PI / 2;
- cubeMesh3.material=this.materials.doorMaterial;
- cubeMesh3.wallId=location.id;
- cubeMesh3.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh3);
-
- var cubeMesh5=BABYLON.Mesh.CreateBox( "door", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(10,2,22);
- 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));
- cubeMesh5.rotation.y=-location.angle;
- cubeMesh5.material=this.materials.doorknobMaterial;
- cubeMesh5.wallId=location.id;
- cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh5);
- return cubeMesh;
- };
- //添加SingleCasement
- decorate3D.prototype.drawSingleCasement= function(location,len,thick)
- {
- var floor=layer.vectors[location.id].geometry.floor;
- var cubeMesh = BABYLON.Mesh.CreateBox( "SingleCasementWindow", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.windowHeight,this.parameter.doorThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "SingleCasementWindow", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.windowHeight,this.parameter.dthick+thick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "SingleCasementWindow", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.windowHeight-10,this.parameter.dthick+thick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
- var newMesh = subCSG.toMesh("window", this.materials.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- newMesh.wallId=location.id;
- newMesh.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(newMesh);
- cubeMesh4.dispose();
- cubeMesh2.dispose();
-
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.parameter.windowHeight-10,20);
- var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
- var cubeMesh1 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
- cubeMesh1.scaling=new BABYLON.Vector3(len-20,this.parameter.windowHeight-20,21);
- var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
- var subCSG2 = cCSG.subtract(dCSG);
- var newMesh2 = subCSG2.toMesh("window", this.materials.windowframeMaterial, this.scene);
- newMesh2.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
- newMesh2.rotation.y=-location.angle;
- newMesh2.wallId=location.id;
- newMesh2.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(newMesh2);
- cubeMesh1.dispose();
- cubeMesh3.dispose();
-
- //镜子
- var cubeMesh6 = BABYLON.Mesh.CreateBox( "window", 1, this.scene);
- cubeMesh6.scaling=new BABYLON.Vector3(len-20,21,this.parameter.windowHeight-20);
- cubeMesh6.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
- cubeMesh6.rotation.z=-location.angle;
- cubeMesh6.rotation.x = Math.PI / 2;
- var mirrorMaterial = new BABYLON.StandardMaterial("mirror", this.scene);
- cubeMesh6.visibility = 0.08;
- cubeMesh6.material=mirrorMaterial;
- cubeMesh6.wallId=location.id;
- cubeMesh6.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh6);
-
- var cubeMesh5=BABYLON.Mesh.CreateBox( "window", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(2,5,22);
- 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));
- cubeMesh5.rotation.y=-location.angle;
- cubeMesh5.material=this.materials.doorknobMaterial;
- cubeMesh5.wallId=location.id;
- cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh5);
-
- return cubeMesh;
- };
- //添加SlidingDoor
- decorate3D.prototype.drawSlidingDoor=function(location,len,thick)
- {
- var floor=layer.vectors[location.id].geometry.floor;
- var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.doorThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,this.parameter.dthick+thick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
- var newMesh = subCSG.toMesh("door", this.materials.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- newMesh.wallId=location.id;
- newMesh.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(newMesh);
-
- cubeMesh4.dispose();
- cubeMesh2.dispose();
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "door", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,20);
- cubeMesh3.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- cubeMesh3.rotation.y=-location.angle;
- cubeMesh3.material=this.materials.doorMaterial;
- cubeMesh3.wallId=location.id;
- cubeMesh3.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh3);
- var cubeMesh5=BABYLON.Mesh.CreateBox( "door", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(2,10,22);
- 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));
- cubeMesh5.rotation.y=-location.angle;
- cubeMesh5.material=this.materials.doorknobMaterial;
- cubeMesh5.wallId=location.id;
- cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh5);
-
- var cubeMesh6 = cubeMesh5.clone("door");
- 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));
- cubeMesh6.wallId=location.id;
- cubeMesh6.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh6);
- return cubeMesh;
- };
- //添加BiFoldDoor
- decorate3D.prototype.drawBiFoldDoor=function(location,len,thick)
- {
- var floor=layer.vectors[location.id].geometry.floor;
- //墙挖洞
- var cubeMesh = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.doorThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- //门框
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- //门框挖洞
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,this.parameter.dthick+thick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
- var newMesh = subCSG.toMesh("door", this.materials.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- newMesh.wallId=location.id;
- newMesh.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(newMesh);
-
- cubeMesh4.dispose();
- cubeMesh2.dispose();
- //大门
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "door", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,20);
- cubeMesh3.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- cubeMesh3.rotation.y=-location.angle;
- cubeMesh3.material=this.materials.doorMaterial;
- cubeMesh3.wallId=location.id;
- cubeMesh3.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh3);
-
- //门把手
- var cubeMesh5=BABYLON.Mesh.CreateBox( "door", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(2,10,22);
- 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));
- cubeMesh5.rotation.y=-location.angle;
- cubeMesh5.material=this.materials.doorknobMaterial;
- cubeMesh5.wallId=location.id;
- cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh5);
-
- var cubeMesh6 = cubeMesh5.clone("door");
- 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));
- cubeMesh6.wallId=location.id;
- cubeMesh6.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh6);
- return cubeMesh;
- };
- //添加DoubleCasement
- decorate3D.prototype.drawDoubleCasement=function(location,len,thick)
- {
- var floor=layer.vectors[location.id].geometry.floor;
- var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.windowHeight,this.parameter.doorThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.windowHeight,this.parameter.dthick+thick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.windowHeight-10,this.parameter.dthick+thick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
- var newMesh = subCSG.toMesh("window", this.materials.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- newMesh.wallId=location.id;
- newMesh.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(newMesh);
-
- cubeMesh4.dispose();
- cubeMesh2.dispose();
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len/2,this.parameter.windowHeight-10,20);
- var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
- var cubeMesh1 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh1.scaling=new BABYLON.Vector3(len/2-11,this.parameter.windowHeight-20,21);
- var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
- var subCSG2 = cCSG.subtract(dCSG);
- var newMesh2 = subCSG2.toMesh("window", this.materials.windowframeMaterial, this.scene);
- 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));
- newMesh2.rotation.y=-location.angle;
- newMesh2.wallId=location.id;
- newMesh2.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(newMesh2);
-
- var newMesh3 = newMesh2.clone("window");
- 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));
- cubeMesh1.dispose();
- cubeMesh3.dispose();
- newMesh3.wallId=location.id;
- newMesh3.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(newMesh3);
-
- //镜子
- var cubeMesh6 = BABYLON.Mesh.CreateBox( "window", 1, this.scene);
- cubeMesh6.scaling=new BABYLON.Vector3(len-10,this.parameter.windowHeight,21);
- cubeMesh6.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.windowBottom,location.point.y);
- cubeMesh6.rotation.y=-location.angle;
- cubeMesh6.visibility = 0.08;
- cubeMesh6.wallId=location.id;
- cubeMesh6.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh6);
-
- if(this.materials.doorknobMaterial==null)
- {
- this.setdoorknobMaterial();
- }
- var cubeMesh5=BABYLON.Mesh.CreateBox( "window", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(2,22,5);
- 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));
- cubeMesh5.rotation.y=-location.angle;
- cubeMesh5.rotation.x = Math.PI / 2;
- cubeMesh5.material=this.materials.doorknobMaterial;
- cubeMesh5.wallId=location.id;
- cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh5);
-
- var cubeMesh7 = cubeMesh5.clone("window");
- 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));
- cubeMesh7.wallId=location.id;
- cubeMesh7.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh7);
-
- return cubeMesh;
- };
- //添加SlidingWindow
- decorate3D.prototype.drawSlidingWindow=function(location,len,thick)
- {
- var floor=layer.vectors[location.id].geometry.floor;
- var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.doorThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
-
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.parameter.doorHeigh,this.parameter.dthick+thick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh-10,this.parameter.dthick+thick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
- var newMesh = subCSG.toMesh("window", this.materials.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- newMesh.wallId=location.id;
- newMesh.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(newMesh);
- cubeMesh4.dispose();
- cubeMesh2.dispose();
-
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len/2-5,this.parameter.doorHeigh-10,20);
- var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
- var cubeMesh1 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh1.scaling=new BABYLON.Vector3(len/2-16,this.parameter.doorHeigh-20,21);
- var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
- var subCSG2 = cCSG.subtract(dCSG);
- var newMesh2 = subCSG2.toMesh("window", this.materials.windowframeMaterial, this.scene);
- 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));
- newMesh2.rotation.y=-location.angle;
- newMesh2.wallId=location.id;
- newMesh2.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(newMesh2);
-
- var newMesh3 = newMesh2.clone("window");
- 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));
- newMesh3.wallId=location.id;
- newMesh3.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(newMesh3);
- cubeMesh1.dispose();
- cubeMesh3.dispose();
-
- //镜子
- var cubeMesh6 = BABYLON.Mesh.CreateBox( "window", 1, this.scene);
- cubeMesh6.scaling=new BABYLON.Vector3(len-10,this.parameter.doorHeigh,21);
- cubeMesh6.position=new BABYLON.Vector3(location.point.x,(floor-1)*this.parameter.wallHeight+this.parameter.doorBottom,location.point.y);
- cubeMesh6.rotation.y=-location.angle;
- cubeMesh6.visibility = 0.08;
- cubeMesh6.wallId=location.id;
- cubeMesh6.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh6);
-
- var cubeMesh5=BABYLON.Mesh.CreateBox( "window", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(2,22,5);
- 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));
- cubeMesh5.rotation.y=-location.angle;
- cubeMesh5.rotation.x = Math.PI / 2;
- cubeMesh5.material=this.materials.doorknobMaterial;
- cubeMesh5.wallId=location.id;
- cubeMesh5.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh5);
-
- var cubeMesh7 = cubeMesh5.clone("window");
- 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));
- cubeMesh7.wallId=location.id;
- cubeMesh7.floor=layer.vectors[location.id].geometry.floor;
- this.roomWallMeshes.push(cubeMesh7);;
-
- return cubeMesh;
- };
|