Symbol3D2.js 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151
  1. function Symbol3D()
  2. {
  3. this.canvas;
  4. this.engine;
  5. this.scene;
  6. this.camera;
  7. this.light;
  8. this.groundY=-10;
  9. this.tiledGround;
  10. this.ground;
  11. this.skybox;
  12. this.lock=false;
  13. this.roomWallMeshes=[];
  14. this.groundLength=6000;
  15. this.groundWidth=6000;
  16. this.doorBottom=60;
  17. this.windowBottom=100;
  18. this.doorHeigh=100;
  19. this.windowHeigh=50;
  20. this.doorThick=34;
  21. this.wallHeigh=150;
  22. this.wallThick=30;
  23. this.boardThick=15;
  24. this.baseSymbolThick;
  25. this.groundMaterial;
  26. this.skyboxMaterial;
  27. this.wallmaterial;
  28. this.floormaterial;
  29. this.frameMaterial;
  30. this.doorknobMaterial;
  31. this.windowframeMaterial;
  32. this.groundTexture="images/checkerboard.jpg";
  33. //this.floorStyle={floorTexture:"images/textures/floor/floor0.jpg",floorColor:null,type:0};
  34. this.floorStyle={floorTexture:"images/textures/floor/floor0.jpg",floorColor:null};
  35. this.wallTexture=null;
  36. this.skyTexture="images/textures/skyboxes/sky0";
  37. this.wallpicture_pre="images/textures/picture/";
  38. this.meshManager={collidables:[],firstMeshes:[],arrowMeshes:[],glassBoxMeshes:[],selectFurnitureMesh:null,selectMesh:false,editProduct:false,infoSize:15,furnitureScal:0.2,selectCircle:null,rotator:null,angle:0};
  39. this.paintPlane={id:null,value:null,beginPaint:false,currentId:null};
  40. this.paintWall={value:null,beginPaint:false};
  41. this.paintSet=[];
  42. this.wallSet={submeshes:[],subMaterials:[],verticesStart:0,indexStart:0};
  43. this.phoSet={start:false,photoFrameMesh:null,phochild:null,pts:null};
  44. };
  45. //添加天空
  46. Symbol3D.prototype.addSkybox = function ()
  47. {
  48. this.skybox = BABYLON.Mesh.CreateBox("skyBox", 8000, this.scene);
  49. this.setskyboxMaterial();
  50. this.skybox.material = this.skyboxMaterial;
  51. };
  52. Symbol3D.prototype.refreshSkybox = function () {
  53. this.setskyboxMaterial();
  54. this.skybox.material = this.skyboxMaterial;
  55. };
  56. //添加地面
  57. Symbol3D.prototype.addGround = function () {
  58. // make a ground
  59. this.ground = BABYLON.Mesh.CreateBox("Ground", 1, this.scene);
  60. this.ground.scaling = new BABYLON.Vector3(this.groundLength, 10, this.groundWidth);
  61. this.ground.position.y =this.groundY/2
  62. this.ground.checkCollisions = true;
  63. this.ground.material = this.groundMaterial;
  64. };
  65. Symbol3D.prototype.refreshGround = function () {
  66. this.setgroundmaterial();
  67. this.ground.material = this.groundMaterial;
  68. };
  69. //添加地板
  70. Symbol3D.prototype.drawFloor= function(points,id)
  71. {
  72. var shape;
  73. for(var i=0;i<points.length;++i)
  74. {
  75. if(i==0)
  76. {
  77. shape = new BABYLON.Path2(points[i].x, points[i].y);
  78. }
  79. else
  80. {
  81. shape.addLineTo(points[i].x, points[i].y);
  82. }
  83. }
  84. var floorPlane = new BABYLON.PolygonMeshBuilder("floorPlane"+this.paintPlane.id, shape, this.scene).build();
  85. floorPlane.wallid="wall"+id;
  86. floorPlane.position.y =3;
  87. var flag=false;
  88. for(var i=0;i<this.paintSet.length;++i)
  89. {
  90. if(this.paintSet[i].type=="floor"&&this.paintSet[i].wallId=="wall"+id)
  91. {
  92. floorPlane.material=this.paintSet[i].material;
  93. floorPlane.floorId=this.paintPlane.id;
  94. flag=true;
  95. break;
  96. }
  97. }
  98. if(!flag)
  99. {
  100. floorPlane.material=this.floormaterial;
  101. floorPlane.material.hasAlpha=10;
  102. }
  103. ++this.paintPlane.id;
  104. this.roomWallMeshes.push(floorPlane);
  105. return floorPlane;
  106. };
  107. Symbol3D.prototype.refreshFloor = function (wallid)
  108. {
  109. if(this.paintPlane.currentId!=null)
  110. {
  111. var floormaterial = new BABYLON.StandardMaterial("floormaterial", this.scene);
  112. floormaterial.diffuseTexture = new BABYLON.Texture(this.floorStyle.value, this.scene);
  113. floormaterial.bumpTexture = new BABYLON.Texture("images/floor1.png", this.scene);
  114. this.scene.getMeshByID(this.paintPlane.currentId).material=floormaterial;
  115. var flag=false;
  116. for(var i=0;i<this.paintSet.length;++i)
  117. {
  118. if(this.paintSet[i].type=="floor"&&this.paintSet[i].floorId==this.paintPlane.currentId)
  119. {
  120. this.paintSet[i].material=floormaterial;
  121. flag=true;
  122. break;
  123. }
  124. }
  125. if(!flag)
  126. {
  127. this.paintSet.push({wallId:wallid,floorId:this.paintPlane.currentId,material:floormaterial,type:"floor"});
  128. }
  129. document.getElementById("container3d").style.cursor="default";
  130. }
  131. };
  132. //添加不闭合的墙
  133. Symbol3D.prototype.drawOpenWallSymbols=function(points,symbols,type,id)
  134. {
  135. var wallmeshes = [];
  136. var topWallmeshes=[];
  137. var pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8;
  138. this.wallSet.submeshes=[];
  139. this.wallSet.verticesStart=0;
  140. this.wallSet.indexStart=0;
  141. this.wallSet.subMaterials=[];
  142. var outpoints=points.side1;
  143. var inpoints=points.side2;
  144. var calculateLine=layer.calculateLine;
  145. var towards=[];
  146. var points=[];
  147. var collindex=[];
  148. for(var i=0;i<outpoints.length-1;++i)
  149. {
  150. pt1=new BABYLON.Vector3(outpoints[i].x, 0, outpoints[i].y);
  151. pt2=new BABYLON.Vector3(outpoints[i+1].x, 0, outpoints[i+1].y);
  152. var mesh=this.drawSideWall(pt1,pt2);
  153. pt3=inpoints[i];
  154. pt4=inpoints[i+1];
  155. var toward= calculateLine.getToward2(outpoints[i],outpoints[i+1],inpoints[i],inpoints[i+1]);
  156. towards.push(toward);
  157. this.meshManager.collidables[this.meshManager.collidables.length-1].toward=toward;
  158. points.push({point1:outpoints[i],point2:outpoints[i+1]});
  159. wallmeshes.push(mesh);
  160. collindex.push(mesh.planindex);
  161. pt5=new BABYLON.Vector3(inpoints[i].x, this.wallHeigh, inpoints[i].y);
  162. pt6=new BABYLON.Vector3(inpoints[i+1].x, this.wallHeigh, inpoints[i+1].y);
  163. pt7=new BABYLON.Vector3(outpoints[i].x, this.wallHeigh, outpoints[i].y);
  164. pt8=new BABYLON.Vector3(outpoints[i+1].x, this.wallHeigh, outpoints[i+1].y);
  165. mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
  166. mesh.material=this.wallmaterial;
  167. topWallmeshes.push(mesh);
  168. }
  169. pt1=new BABYLON.Vector3(outpoints[outpoints.length-1].x, 0, outpoints[outpoints.length-1].y);
  170. pt2=new BABYLON.Vector3(inpoints[outpoints.length-1].x, 0, inpoints[outpoints.length-1].y);
  171. var mesh=this.drawSideWall(pt1,pt2);
  172. var toward=calculateLine.getToward(outpoints[outpoints.length-1],inpoints[outpoints.length-1],outpoints[outpoints.length-2]);
  173. towards.push(-1*toward);
  174. this.meshManager.collidables[this.meshManager.collidables.length-1].toward=-1*toward;
  175. points.push({point1:outpoints[outpoints.length-1],point2:inpoints[outpoints.length-1]});
  176. wallmeshes.push(mesh);
  177. collindex.push(mesh.planindex);
  178. var num=wallmeshes.length-2;
  179. for(var i=inpoints.length-1;i>0;--i)
  180. {
  181. pt1=new BABYLON.Vector3(inpoints[i].x, 0, inpoints[i].y);
  182. pt2=new BABYLON.Vector3(inpoints[i-1].x, 0, inpoints[i-1].y);
  183. var toward=-1*towards[num];
  184. var mesh=this.drawSideWall(pt1,pt2);
  185. towards.push(toward);
  186. this.meshManager.collidables[this.meshManager.collidables.length-1].toward=toward;
  187. points.push({point1:inpoints[i],point2:inpoints[i-1]});
  188. --num;
  189. wallmeshes.push(mesh);
  190. collindex.push(mesh.planindex);
  191. }
  192. pt1=new BABYLON.Vector3(inpoints[0].x, 0, inpoints[0].y);
  193. pt2=new BABYLON.Vector3(outpoints[0].x, 0, outpoints[0].y);
  194. var mesh=this.drawSideWall(pt1,pt2);
  195. toward=calculateLine.getToward(inpoints[0],outpoints[0],outpoints[1]);
  196. towards.push(-1*toward);
  197. this.meshManager.collidables[this.meshManager.collidables.length-1].toward=-1*toward;
  198. points.push({point1:inpoints[0],point2:outpoints[0]});
  199. wallmeshes.push(mesh);
  200. collindex.push(mesh.planindex);
  201. var _topWallmesh=BABYLON.Mesh.MergeMeshes(topWallmeshes);
  202. var topCSG = BABYLON.CSG.FromMesh(_topWallmesh);
  203. var finalTopMesh = topCSG.toMesh("wallopen",this.wallmaterial, this.scene,true);
  204. _topWallmesh.dispose();
  205. _topWallmesh=null;
  206. this.roomWallMeshes.push(finalTopMesh);
  207. var wallmesh=BABYLON.Mesh.MergeMeshes(wallmeshes);
  208. wallmesh.subMeshes = [];
  209. this.wallSet.subMaterials=[];
  210. for(var i=0;i<this.wallSet.submeshes.length;++i)
  211. {
  212. 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));
  213. var wallmaterial = new BABYLON.StandardMaterial("wall"+i, this.scene);
  214. wallmaterial=this.getwallmaterial(i);
  215. wallmaterial.toward=towards[i];
  216. wallmaterial.points=points[i];
  217. wallmaterial.indexplane=collindex[i];
  218. this.wallSet.subMaterials.push(wallmaterial);
  219. }
  220. var wallCSG =BABYLON.CSG.FromMesh(wallmesh);
  221. if(type==1)
  222. {
  223. this.baseSymbolThick=this.doorThick;
  224. }
  225. else
  226. {
  227. this.baseSymbolThick=this.doorThick/2;
  228. }
  229. for(var i=0;i<symbols.length;++i)
  230. {
  231. var symMesh;
  232. var len=symbols[i].len;
  233. if(symbols[i].type=="OpenDoor")
  234. {
  235. symMesh=this.drawOpeningDoor(symbols[i],len);
  236. }
  237. else if(symbols[i].type=="OpenWindow")
  238. {
  239. symMesh=this.drawOpeningWindow(symbols[i],len);
  240. }
  241. else if(symbols[i].type=="SimpleDoor")
  242. {
  243. symMesh=this.drawSimpleDoor(symbols[i],len);
  244. }
  245. else if(symbols[i].type=="BiFoldDoor")
  246. {
  247. symMesh=this.drawBiFoldDoor(symbols[i],len);
  248. }
  249. else if(symbols[i].type=="SlidingDoor")
  250. {
  251. symMesh=this.drawSlidingDoor(symbols[i],len);
  252. }
  253. else if(symbols[i].type=="SingleCasement")
  254. {
  255. symMesh=this.drawSingleCasement(symbols[i],len);
  256. }
  257. else if(symbols[i].type=="DoubleCasement")
  258. {
  259. symMesh=this.drawDoubleCasement(symbols[i],len);
  260. }
  261. else if(symbols[i].type=="SlidingWindow")
  262. {
  263. symMesh=this.drawSlidingWindow(symbols[i],len);
  264. }
  265. else
  266. {
  267. continue;
  268. }
  269. var symCSG = BABYLON.CSG.FromMesh(symMesh);
  270. wallCSG = wallCSG.subtract(symCSG);
  271. symMesh.dispose();
  272. }
  273. var wall = wallCSG.toMesh("wall"+id,null, this.scene,true);
  274. var multi=new BABYLON.MultiMaterial("material"+id,this.scene);
  275. multi.subMaterials=this.wallSet.subMaterials;
  276. wall.material=multi;
  277. for(var i=0;i<this.paintSet.length;++i)
  278. {
  279. if(this.paintSet[i].type=="wall"&&this.paintSet[i].wallId==wall.id&&this.wallSet.subMaterials.length>this.paintSet[i].materialId)
  280. {
  281. wall.material.subMaterials[this.paintSet[i].materialId]=this.paintSet[i].material;
  282. //break;
  283. }
  284. }
  285. wallmesh.dispose();
  286. wallmesh=null;
  287. this.roomWallMeshes.push(wall);
  288. };
  289. //添加墙顶
  290. Symbol3D.prototype.drawTopWall=function(pt1,pt2,pt3,pt4)
  291. {
  292. var mesh = new BABYLON.Mesh("mesh", this.scene);
  293. //mesh.material = this.wallmaterial;
  294. var path1 = [];
  295. var path2 = [];
  296. path1.push(pt1);
  297. path1.push(pt2);
  298. path2.push(pt3);
  299. path2.push(pt4);
  300. // positions
  301. var positions = [];
  302. for (var i = 0; i < path1.length; i++) {
  303. positions.push(path1[i].x, path1[i].y, path1[i].z);
  304. positions.push(path2[i].x, path2[i].y, path2[i].z);
  305. };
  306. // indices
  307. var indices = [];
  308. for (var i = 0; i < path1.length * 2 - 2 ; i+=2) {
  309. indices.push(i, i+1, i+2);
  310. indices.push(i+3, i+2, i+1);
  311. };
  312. // normals
  313. var normals = [];
  314. BABYLON.VertexData.ComputeNormals(positions, indices, normals);
  315. // mesh
  316. var colors = [
  317. 1, 0, 0, 1,
  318. 0, 1, 0, 1,
  319. 0, 1, 0, 0,
  320. 0, 0, 1, 0,
  321. ];
  322. mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors);
  323. var uvs=[[0,0],[1,0],[1,1],[0,1]];
  324. mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
  325. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false);
  326. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false);
  327. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false);
  328. mesh.setIndices(indices);
  329. mesh.material = this.wallmaterial;
  330. return mesh;
  331. };
  332. //添加墙的侧面
  333. Symbol3D.prototype.drawSideWall=function(pt1,pt2)
  334. {
  335. var mesh = new BABYLON.Mesh("mesh", this.scene);
  336. //mesh.material = this.wallmaterial;
  337. this.createwallPlane(new BABYLON.Vector2(pt1.x,pt1.z),new BABYLON.Vector2(pt2.x,pt2.z));
  338. var path1 = [];
  339. var path2 = [];
  340. path1.push(pt1);
  341. path1.push(pt2);
  342. var pt3=new BABYLON.Vector3(pt1.x,this.wallHeigh, pt1.z);
  343. var pt4=new BABYLON.Vector3(pt2.x,this.wallHeigh, pt2.z);
  344. path2.push(pt3);
  345. path2.push(pt4);
  346. // positions
  347. var positions = [];
  348. for (var i = 0; i < path1.length; i++) {
  349. positions.push(path1[i].x, path1[i].y, path1[i].z);
  350. positions.push(path2[i].x, path2[i].y, path2[i].z);
  351. };
  352. // indices
  353. var indices = [];
  354. for (var i = 0; i < path1.length * 2 - 2 ; i+=2) {
  355. indices.push(i, i+1, i+2);
  356. indices.push(i+3, i+2, i+1);
  357. };
  358. // normals
  359. var normals = [];
  360. BABYLON.VertexData.ComputeNormals(positions, indices, normals);
  361. var uvs=[[0,0],[1,0],[1,1],[0,1]];
  362. mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
  363. var colors = [
  364. 1, 0, 0, 1,
  365. 0, 1, 0, 1,
  366. 0, 1, 0, 0,
  367. 0, 0, 1, 0,
  368. ];
  369. // mesh
  370. mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors);
  371. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false);
  372. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false);
  373. mesh.setIndices(indices);
  374. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false);
  375. mesh.material = this.wallmaterial;
  376. this.wallSet.submeshes.push({verticesStart:this.wallSet.verticesStart, verticesCount:mesh.getTotalVertices(), indexStart:this.wallSet.indexStart, indexCount:mesh.getTotalIndices()});
  377. this.wallSet.verticesStart+=mesh.getTotalVertices();
  378. this.wallSet.indexStart+=mesh.getTotalIndices();
  379. mesh.planindex=this.meshManager.collidables.length-1;
  380. return mesh;
  381. };
  382. //添加闭合的墙
  383. Symbol3D.prototype.drawCloseWallSymbols=function(outpoints,inpoints,symbols,type,id)
  384. {
  385. var wallmeshes = [];
  386. var topWallmeshes=[];
  387. var pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8;
  388. this.wallSet.submeshes=[];
  389. this.wallSet.verticesStart=0;
  390. this.wallSet.indexStart=0;
  391. this.wallSet.subMaterials=[];
  392. var calculateLine=layer.calculateLine;
  393. //var calculateLine=new CalculateLine();
  394. var towards=[];
  395. var points=[];
  396. var collindex=[];
  397. for(var i=0;i<outpoints.length;++i)
  398. {
  399. if(i==outpoints.length-1)
  400. {
  401. pt1=new BABYLON.Vector3(outpoints[0].x, 0, outpoints[0].y);
  402. pt2=new BABYLON.Vector3(outpoints[outpoints.length-1].x, 0, outpoints[outpoints.length-1].y);
  403. var mesh=this.drawSideWall(pt2,pt1);
  404. wallmeshes.push(mesh);
  405. collindex.push(mesh.planindex);
  406. pt3=new BABYLON.Vector3(inpoints[0].x, 0, inpoints[0].y);
  407. pt4=new BABYLON.Vector3(inpoints[inpoints.length-1].x, 0, inpoints[inpoints.length-1].y);
  408. var toward= calculateLine.getToward2(outpoints[0],outpoints[outpoints.length-1],inpoints[0],inpoints[inpoints.length-1]);
  409. towards.push(toward);
  410. this.meshManager.collidables[this.meshManager.collidables.length-1].toward=toward;
  411. points.push({point1:outpoints[0],point2:outpoints[outpoints.length-1]});
  412. mesh=this.drawSideWall(pt3,pt4);
  413. //mesh.toward=-1*toward;
  414. towards.push(-1*toward);
  415. this.meshManager.collidables[this.meshManager.collidables.length-1].toward=-1*toward;
  416. points.push({point1:inpoints[0],point2:inpoints[inpoints.length-1]});
  417. wallmeshes.push(mesh);
  418. collindex.push(mesh.planindex);
  419. pt5=new BABYLON.Vector3(inpoints[inpoints.length-1].x, this.wallHeigh, inpoints[inpoints.length-1].y);
  420. pt6=new BABYLON.Vector3(inpoints[0].x, this.wallHeigh, inpoints[0].y);
  421. pt7=new BABYLON.Vector3(outpoints[outpoints.length-1].x, this.wallHeigh, outpoints[outpoints.length-1].y);
  422. pt8=new BABYLON.Vector3(outpoints[0].x, this.wallHeigh, outpoints[0].y);
  423. mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
  424. mesh.material=this.wallmaterial;
  425. topWallmeshes.push(mesh);
  426. }
  427. else
  428. {
  429. pt1=new BABYLON.Vector3(outpoints[i].x, 0, outpoints[i].y);
  430. pt2=new BABYLON.Vector3(outpoints[i+1].x, 0, outpoints[i+1].y);
  431. var mesh=this.drawSideWall(pt1,pt2);
  432. wallmeshes.push(mesh);
  433. collindex.push(mesh.planindex);
  434. pt3=new BABYLON.Vector3(inpoints[i].x, 0, inpoints[i].y);
  435. pt4=new BABYLON.Vector3(inpoints[i+1].x, 0, inpoints[i+1].y);
  436. //var toward= calculateLine.getToward2(pt1,pt2,pt3,pt4);
  437. var toward= calculateLine.getToward2(outpoints[i],outpoints[i+1],inpoints[i],inpoints[i+1]);
  438. //mesh.toward=toward;
  439. points.push({point1:outpoints[i],point2:outpoints[i+1]});
  440. towards.push(toward);
  441. this.meshManager.collidables[this.meshManager.collidables.length-1].toward=toward;
  442. mesh=this.drawSideWall(pt3,pt4);
  443. //mesh.toward=-1*toward;
  444. points.push({point1:inpoints[i],point2:inpoints[i+1]});
  445. towards.push(-1*toward);
  446. this.meshManager.collidables[this.meshManager.collidables.length-1].toward=-1*toward;
  447. wallmeshes.push(mesh);
  448. collindex.push(mesh.planindex);
  449. pt5=new BABYLON.Vector3(inpoints[i].x, this.wallHeigh, inpoints[i].y);
  450. pt6=new BABYLON.Vector3(inpoints[i+1].x, this.wallHeigh, inpoints[i+1].y);
  451. pt7=new BABYLON.Vector3(outpoints[i].x, this.wallHeigh, outpoints[i].y);
  452. pt8=new BABYLON.Vector3(outpoints[i+1].x, this.wallHeigh, outpoints[i+1].y);
  453. mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
  454. mesh.material=this.wallmaterial;
  455. topWallmeshes.push(mesh);
  456. }
  457. }
  458. var _topWallmesh=BABYLON.Mesh.MergeMeshes(topWallmeshes);
  459. var topCSG = BABYLON.CSG.FromMesh(_topWallmesh);
  460. var finalTopMesh = topCSG.toMesh("walltop",this.wallmaterial, this.scene,true);
  461. _topWallmesh.dispose();
  462. _topWallmesh=null;
  463. this.roomWallMeshes.push(finalTopMesh);
  464. var wallmesh=BABYLON.Mesh.MergeMeshes(wallmeshes);
  465. wallmesh.subMeshes = [];
  466. this.wallSet.subMaterials=[];
  467. for(var i=0;i<this.wallSet.submeshes.length;++i)
  468. {
  469. 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));
  470. /*
  471. var wallmaterial = new BABYLON.StandardMaterial("wall"+i, this.scene);
  472. wallmaterial.alpha = 1.0;
  473. wallmaterial.emissiveColor = new BABYLON.Color3(0.8,0.8,0.8);
  474. wallmaterial.backFaceCulling = false;
  475. */
  476. var wallmaterial =this.getwallmaterial(i);
  477. wallmaterial.toward=towards[i];
  478. wallmaterial.points=points[i];
  479. wallmaterial.indexplane=collindex[i];
  480. this.wallSet.subMaterials.push(wallmaterial);
  481. }
  482. var wallCSG =BABYLON.CSG.FromMesh(wallmesh);
  483. if(type==1)
  484. {
  485. this.baseSymbolThick=this.doorThick;
  486. }
  487. else
  488. {
  489. this.baseSymbolThick=this.doorThick/2;
  490. }
  491. for(var i=0;i<symbols.length;++i)
  492. {
  493. var symMesh;
  494. //var len=this.getLen(symbols[i].type);
  495. var len=symbols[i].len;
  496. if(symbols[i].type=="OpenDoor")
  497. {
  498. symMesh=this.drawOpeningDoor(symbols[i],len);
  499. }
  500. else if(symbols[i].type=="OpenWindow")
  501. {
  502. symMesh=this.drawOpeningWindow(symbols[i],len);
  503. }
  504. else if(symbols[i].type=="SimpleDoor")
  505. {
  506. symMesh=this.drawSimpleDoor(symbols[i],len);
  507. }
  508. else if(symbols[i].type=="BiFoldDoor")
  509. {
  510. symMesh=this.drawBiFoldDoor(symbols[i],len);
  511. }
  512. else if(symbols[i].type=="SlidingDoor")
  513. {
  514. symMesh=this.drawSlidingDoor(symbols[i],len);
  515. }
  516. else if(symbols[i].type=="SingleCasement")
  517. {
  518. symMesh=this.drawSingleCasement(symbols[i],len);
  519. }
  520. else if(symbols[i].type=="DoubleCasement")
  521. {
  522. symMesh=this.drawDoubleCasement(symbols[i],len);
  523. }
  524. else if(symbols[i].type=="SlidingWindow")
  525. {
  526. symMesh=this.drawSlidingWindow(symbols[i],len);
  527. }
  528. else
  529. {
  530. continue;
  531. }
  532. var symCSG = BABYLON.CSG.FromMesh(symMesh);
  533. wallCSG = wallCSG.subtract(symCSG);
  534. symMesh.dispose();
  535. }
  536. var wall = wallCSG.toMesh("wall"+id,null, this.scene,true);
  537. var multi=new BABYLON.MultiMaterial("material"+id,this.scene);
  538. multi.subMaterials=this.wallSet.subMaterials;
  539. wall.material=multi;
  540. wallmesh.dispose();
  541. wallmesh=null;
  542. for(var i=0;i<this.paintSet.length;++i)
  543. {
  544. if(this.paintSet[i].type=="wall"&&this.paintSet[i].wallId==wall.id&&this.wallSet.subMaterials.length>this.paintSet[i].materialId)
  545. {
  546. wall.material.subMaterials[this.paintSet[i].materialId]=this.paintSet[i].material;
  547. //break;
  548. }
  549. }
  550. this.roomWallMeshes.push(wall);
  551. };
  552. //添加画,图
  553. Symbol3D.prototype.showPicture=function(src)
  554. {
  555. var plan = BABYLON.Mesh.CreatePlane("picture-"+src, 1, this.scene);
  556. plan.scaling.x=50;
  557. plan.scaling.y=40;
  558. plan.position=new BABYLON.Vector3(0, 0, 0);
  559. var material = new BABYLON.StandardMaterial("planmaterial", this.scene);
  560. material.diffuseTexture = new BABYLON.Texture(this.wallpicture_pre+src, this.scene);
  561. material.bumpTexture = new BABYLON.Texture("images/floor1.png", this.scene);
  562. plan.material=material;
  563. plan.rotation.x=Math.PI/2;
  564. this.meshManager.collidables.push(plan);
  565. };
  566. //添加镜框
  567. Symbol3D.prototype.showPhoFrame=function(src)
  568. {
  569. BABYLON.SceneLoader.ImportMesh("", "images/3d/", src, this.scene, function (newMeshes)
  570. {
  571. newMeshes[0].scaling=new BABYLON.Vector3(this.meshManager.furnitureScal,this.meshManager.furnitureScal,this.meshManager.furnitureScal);
  572. newMeshes[0].computeWorldMatrix(true);
  573. newMeshes[0].refreshBoundingInfo();
  574. newMeshes[0].position=new BABYLON.Vector3(0,-100,0);
  575. newMeshes[0].name="pho-"+src;
  576. newMeshes[0].thice=Math.abs(newMeshes[0]._boundingInfo.boundingBox.maximumWorld.z-newMeshes[0]._boundingInfo.boundingBox.minimumWorld.z);
  577. newMeshes[0].firstHeigh=Math.abs(newMeshes[0]._boundingInfo.boundingBox.maximumWorld.y-newMeshes[0]._boundingInfo.boundingBox.minimumWorld.y);
  578. if(this.phoSet.photoFrameMesh!=null)
  579. {
  580. this.phoSet.photoFrameMesh.dispose();
  581. this.phoSet.photoFrameMesh=null;
  582. }
  583. this.phoSet.photoFrameMesh=newMeshes[0];
  584. //this.phoSet.photoFrameMesh.showBoundingBox=true;
  585. this.phoSet.photoFrameMesh.height=newMeshes[0].firstHeigh;
  586. this.phoSet.photoFrameMesh.length=Math.abs(newMeshes[0]._boundingInfo.boundingBox.maximumWorld.x-newMeshes[0]._boundingInfo.boundingBox.minimumWorld.x);
  587. this.phoSet.photoFrameMesh.visibility=0;
  588. this.phoSet.start=true;
  589. document.getElementById("container3d").style.cursor="url('images/brush.ico'),auto";
  590. for(var i=0;i<this.phoSet.photoFrameMesh._boundingInfo.boundingBox.vectorsWorld.length;++i)
  591. {
  592. if(this.phoSet.photoFrameMesh._boundingInfo.boundingBox.vectorsWorld[i].z>this.phoSet.photoFrameMesh._boundingInfo.boundingBox.minimumWorld.z)
  593. {
  594. this.phoSet.photoFrameMesh.frontindex=i;
  595. break;
  596. }
  597. }
  598. this.engine.hideLoadingUI();
  599. }.bind(this));
  600. };
  601. //初始化时,会有一些三维模型
  602. Symbol3D.prototype.showProductfirst=function(src,position,rotation)
  603. {
  604. BABYLON.SceneLoader.ImportMesh("", "images/3d/", src, this.scene, function (newMeshes)
  605. {
  606. var mesh;
  607. if(newMeshes.length>1)
  608. {
  609. mesh=BABYLON.Mesh.MergeMeshes(newMeshes);
  610. }
  611. else
  612. {
  613. mesh=newMeshes[0];
  614. }
  615. //mesh.scaling=new BABYLON.Vector3(this.meshManager.furnitureScal,this.meshManager.furnitureScal,this.meshManager.furnitureScal);
  616. //mesh.position=position;
  617. //mesh.rotation=rotation;
  618. var name=src.replace(".babylon","");
  619. mesh.scaling=new BABYLON.Vector3(layer.parameter.testModelData[name],layer.parameter.testModelData[name],layer.parameter.testModelData[name]);
  620. mesh.position=position;
  621. //mesh.material.specularColor=new BABYLON.Color3(0.8,0.8,0.8);
  622. //if(mesh.name=="cabinet")
  623. if(layer.parameter.cabinet.indexOf(name+",")>-1)
  624. {
  625. var glassMesh = BABYLON.Mesh.CreateBox("box", 1, this.scene);
  626. glassMesh.scaling.x=Math.abs(mesh._boundingInfo.maximum.x-mesh._boundingInfo.minimum.x)*mesh.scaling.x-5;
  627. glassMesh.scaling.y=80;
  628. glassMesh.scaling.z=Math.abs(mesh._boundingInfo.maximum.z-mesh._boundingInfo.minimum.z)*mesh.scaling.z/1.2;
  629. glassMesh.position.x=position.x;
  630. glassMesh.position.y=Math.abs(mesh._boundingInfo.maximum.y-mesh._boundingInfo.minimum.y)*mesh.scaling.y-40;
  631. glassMesh.position.z=position.z-2;
  632. glassMesh.visibility = 0.3;
  633. glassMesh.name="mirror";
  634. this.meshManager.glassBoxMeshes.push(glassMesh);
  635. }
  636. for(var i=0;i<this.meshManager.collidables.length;++i)
  637. {
  638. if (typeof(this.meshManager.collidables[i]) == "undefined") {
  639. this.meshManager.collidables.splice(i,1);
  640. --i;
  641. continue;
  642. }
  643. if (mesh.intersectsMesh(this.meshManager.collidables[i], true))
  644. {
  645. this.meshManager.firstMeshes.push(src)
  646. break;
  647. }
  648. }
  649. ++initMesh;
  650. if(initMesh>21)
  651. {
  652. this.engine.hideLoadingUI();
  653. initMesh=0;
  654. }
  655. this.meshManager.collidables.push(mesh);
  656. }.bind(this));
  657. return this.meshManager.collidables[this.meshManager.collidables.length-1];
  658. };
  659. //加载三维模型
  660. Symbol3D.prototype.showProduct=function(src)
  661. {
  662. this.engine.displayLoadingUI();
  663. this.engine.loadingUIText = "正在加载家具,请稍等!";
  664. //this.engine.loadingUIBackgroundColor = "red";
  665. BABYLON.SceneLoader.ImportMesh("", "images/3d/", src, this.scene, function (newMeshes)
  666. {
  667. var mesh;
  668. if(newMeshes.length>1)
  669. {
  670. mesh=BABYLON.Mesh.MergeMeshes(newMeshes);
  671. }
  672. else
  673. {
  674. mesh=newMeshes[0];
  675. }
  676. //mesh.scaling=new BABYLON.Vector3(this.meshManager.furnitureScal,this.meshManager.furnitureScal,this.meshManager.furnitureScal);
  677. //mesh.scaling=new BABYLON.Vector3(10,10,10);
  678. var name=src.replace(".babylon","");
  679. mesh.scaling=new BABYLON.Vector3(layer.parameter.testModelData[name],layer.parameter.testModelData[name],layer.parameter.testModelData[name]);
  680. //mesh.position=new BABYLON.Vector3(0, 60, 0);
  681. //newMeshes[0].showBoundingBox=true;
  682. mesh.name=src;
  683. for(var i=0;i<this.meshManager.collidables.length;++i)
  684. {
  685. if (typeof(this.meshManager.collidables[i]) == "undefined") {
  686. this.meshManager.collidables.splice(i,1);
  687. --i;
  688. continue;
  689. }
  690. if (mesh.intersectsMesh(this.meshManager.collidables[i], true))
  691. {
  692. this.meshManager.firstMeshes.push(src)
  693. break;
  694. }
  695. }
  696. this.meshManager.collidables.push(mesh);
  697. //div.style.display="none";
  698. this.engine.hideLoadingUI();
  699. }.bind(this));
  700. /*
  701. * <div style="position: absolute; left: 0px; top: 50%; margin-top: 80px; width: 100%; height: 20px; font-family: Arial; font-size: 14px; color: white; text-align: center;">Bitte haben Sie einen Moment Geduld, die benötigten Daten werden geladen...</div>
  702. * */
  703. };
  704. //每个墙添加plane,防止模型与墙重合
  705. Symbol3D.prototype.createwallPlane=function (point1,point2) {
  706. var p1=new BABYLON.Vector2(point1.x, point1.y);
  707. var p2=new BABYLON.Vector2(point2.x, point2.y);
  708. var distance= BABYLON.Vector2.Distance(p1,p2);
  709. //var plan = BABYLON.Mesh.CreatePlane("plane", distance, this.scene);
  710. var plan = BABYLON.Mesh.CreatePlane("plane", 1, this.scene);
  711. plan.scaling.x=distance;
  712. //plan.scaling.y =1;
  713. plan.scaling.y =this.wallHeigh;
  714. plan.material = this.wallmaterial;
  715. //plan.position=new BABYLON.Vector3((p1.x+p2.x)/2,0.5, (p1.y+p2.y)/2);
  716. plan.position=new BABYLON.Vector3((p1.x+p2.x)/2,this.wallHeigh/2, (p1.y+p2.y)/2);
  717. var angle=BABYLON.Angle.BetweenTwoPoints(p1,p2);
  718. plan.rotation.y=-angle._radians;
  719. plan.visibility=0;
  720. plan.pts={point1:point1,point2:point2};
  721. plan.planindex=this.meshManager.collidables.length;
  722. this.meshManager.collidables.push(plan);
  723. //plan.dispose();
  724. };
  725. Symbol3D.prototype.clearAllSymbols=function()
  726. {
  727. for(var i=0;i<this.meshManager.collidables.length;++i)
  728. {
  729. this.meshManager.collidables[i].dispose();
  730. }
  731. for(var i=0;i<this.roomWallMeshes.length;++i)
  732. {
  733. this.roomWallMeshes[i].dispose();
  734. }
  735. for(var i=0;i<this.meshManager.arrowMeshes.length;++i)
  736. {
  737. this.meshManager.arrowMeshes[i].dispose();
  738. }
  739. for(var i=0;i<this.meshManager.glassBoxMeshes.length;++i)
  740. {
  741. this.meshManager.glassBoxMeshes[i].dispose();
  742. }
  743. }
  744. Symbol3D.prototype.clearSymbol=function()
  745. {
  746. for(var i=0;i<this.meshManager.collidables.length;++i)
  747. {
  748. if(this.meshManager.collidables[i].name=="plane")
  749. {
  750. this.meshManager.collidables[i].dispose();
  751. this.meshManager.collidables.splice(i, 1);
  752. --i;
  753. }
  754. }
  755. for(var i=0;i<this.roomWallMeshes.length;++i)
  756. {
  757. this.roomWallMeshes[i].dispose();
  758. }
  759. };
  760. //添加opendoor
  761. Symbol3D.prototype.drawOpeningDoor= function(location,len)
  762. {
  763. var cubeMesh = BABYLON.Mesh.CreateBox( "OpeningDoor", 1, this.scene);
  764. //cubeMesh.scaling=new BABYLON.Vector3(this.baseSymbolThick,len/2,);
  765. //baseSymbolThick是30,doorHeigh是100,len是60
  766. cubeMesh.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.baseSymbolThick);
  767. cubeMesh.position=new BABYLON.Vector3(location.point.x, this.doorBottom,location.point.y);
  768. cubeMesh.rotation.y=-location.angle;
  769. return cubeMesh;
  770. };
  771. //添加openwindow
  772. Symbol3D.prototype.drawOpeningWindow= function(location,len)
  773. {
  774. var cubeMesh = BABYLON.Mesh.CreateBox( "OpeningWindow", 1, this.scene);
  775. //baseSymbolThick是30,windowHeigh是50,len是40
  776. cubeMesh.scaling=new BABYLON.Vector3(len,this.windowHeigh,this.baseSymbolThick);
  777. cubeMesh.position=new BABYLON.Vector3(location.point.x, this.windowBottom,location.point.y);
  778. cubeMesh.rotation.y=-location.angle;
  779. return cubeMesh;
  780. };
  781. //添加SimpleDoor
  782. Symbol3D.prototype.drawSimpleDoor= function(location,len)
  783. {
  784. var cubeMesh = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
  785. cubeMesh.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.doorThick);
  786. cubeMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  787. cubeMesh.rotation.y=-location.angle;
  788. var cubeMesh2 = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
  789. cubeMesh2.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.baseSymbolThick+1);
  790. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  791. var cubeMesh4 = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
  792. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,this.baseSymbolThick+1);
  793. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  794. var subCSG = aCSG.subtract(bCSG);
  795. var newMesh = subCSG.toMesh("Door", this.frameMaterial, this.scene);
  796. newMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  797. newMesh.rotation.y=-location.angle;
  798. //newMesh.rotation.x = Math.PI / 2;
  799. this.roomWallMeshes.push(newMesh);
  800. cubeMesh4.dispose();
  801. cubeMesh2.dispose();
  802. if(this.doormaterial==null)
  803. {
  804. this.setdoormaterial();
  805. }
  806. var cubeMesh3 = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
  807. cubeMesh3.scaling=new BABYLON.Vector3(len-10,20,this.doorHeigh-10);
  808. cubeMesh3.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  809. cubeMesh3.rotation.y=-location.angle;
  810. cubeMesh3.rotation.x = Math.PI / 2;
  811. cubeMesh3.material=this.doormaterial;
  812. this.roomWallMeshes.push(cubeMesh3);
  813. if(this.doorknobMaterial==null)
  814. {
  815. this.setdoorknobMaterial();
  816. }
  817. var cubeMesh5=BABYLON.Mesh.CreateBox( "Doorknob", 1, this.scene);
  818. cubeMesh5.scaling=new BABYLON.Vector3(10,2,22);
  819. cubeMesh5.position=new BABYLON.Vector3(location.point.x+20*Math.cos(location.angle),this.doorBottom,location.point.y+20*Math.sin(location.angle));
  820. cubeMesh5.rotation.y=-location.angle;
  821. //cubeMesh5.rotation.x = Math.PI / 2;
  822. cubeMesh5.material=this.doorknobMaterial;
  823. this.roomWallMeshes.push(cubeMesh5);
  824. return cubeMesh;
  825. };
  826. //添加SingleCasement
  827. Symbol3D.prototype.drawSingleCasement= function(location,len)
  828. {
  829. var cubeMesh = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
  830. cubeMesh.scaling=new BABYLON.Vector3(len,this.windowHeigh,this.doorThick);
  831. cubeMesh.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
  832. cubeMesh.rotation.y=-location.angle;
  833. var cubeMesh2 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
  834. cubeMesh2.scaling=new BABYLON.Vector3(len,this.windowHeigh,this.baseSymbolThick+1);
  835. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  836. var cubeMesh4 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
  837. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.windowHeigh-10,this.baseSymbolThick+1);
  838. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  839. var subCSG = aCSG.subtract(bCSG);
  840. var newMesh = subCSG.toMesh("Window", this.frameMaterial, this.scene);
  841. newMesh.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
  842. newMesh.rotation.y=-location.angle;
  843. //newMesh.rotation.x = Math.PI / 2;
  844. this.roomWallMeshes.push(newMesh);
  845. cubeMesh4.dispose();
  846. cubeMesh2.dispose();
  847. if(this.windowframeMaterial==null)
  848. {
  849. this.setwindowframeMaterial();
  850. }
  851. var cubeMesh3 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
  852. cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.windowHeigh-10,20);
  853. var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
  854. var cubeMesh1 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
  855. cubeMesh1.scaling=new BABYLON.Vector3(len-20,this.windowHeigh-20,21);
  856. var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
  857. var subCSG2 = cCSG.subtract(dCSG);
  858. var newMesh2 = subCSG2.toMesh("Window", this.windowframeMaterial, this.scene);
  859. newMesh2.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
  860. newMesh2.rotation.y=-location.angle;
  861. //newMesh2.rotation.x = Math.PI / 2;
  862. this.roomWallMeshes.push(newMesh2);
  863. cubeMesh1.dispose();
  864. cubeMesh3.dispose();
  865. //镜子
  866. var cubeMesh6 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
  867. cubeMesh6.scaling=new BABYLON.Vector3(len-20,21,this.windowHeigh-20);
  868. cubeMesh6.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
  869. cubeMesh6.rotation.z=-location.angle;
  870. cubeMesh6.rotation.x = Math.PI / 2;
  871. cubeMesh6.visibility = 0.08;
  872. this.roomWallMeshes.push(cubeMesh6);
  873. if(this.doorknobMaterial==null)
  874. {
  875. this.setdoorknobMaterial();
  876. }
  877. var cubeMesh5=BABYLON.Mesh.CreateBox( "Windowknob", 1, this.scene);
  878. cubeMesh5.scaling=new BABYLON.Vector3(2,5,22);
  879. cubeMesh5.position=new BABYLON.Vector3(location.point.x+14*Math.cos(location.angle),this.windowBottom,location.point.y+14*Math.sin(location.angle));
  880. cubeMesh5.rotation.y=-location.angle;
  881. //cubeMesh5.rotation.x = Math.PI / 2;
  882. cubeMesh5.material=this.doorknobMaterial;
  883. this.roomWallMeshes.push(cubeMesh5);
  884. return cubeMesh;
  885. };
  886. //添加SlidingDoor
  887. Symbol3D.prototype.drawSlidingDoor=function(location,len)
  888. {
  889. var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
  890. cubeMesh.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.doorThick);
  891. cubeMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  892. cubeMesh.rotation.y=-location.angle;
  893. var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
  894. cubeMesh2.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.baseSymbolThick+1);
  895. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  896. var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
  897. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,this.baseSymbolThick+1);
  898. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  899. var subCSG = aCSG.subtract(bCSG);
  900. var newMesh = subCSG.toMesh("Door", this.frameMaterial, this.scene);
  901. newMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  902. newMesh.rotation.y=-location.angle;
  903. //newMesh.rotation.x = Math.PI / 2;
  904. this.roomWallMeshes.push(newMesh);
  905. cubeMesh4.dispose();
  906. cubeMesh2.dispose();
  907. if(this.doormaterial==null)
  908. {
  909. this.setdoormaterial();
  910. }
  911. var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
  912. cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,20);
  913. cubeMesh3.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  914. cubeMesh3.rotation.y=-location.angle;
  915. //cubeMesh3.rotation.x = Math.PI / 2;
  916. cubeMesh3.material=this.doormaterial;
  917. this.roomWallMeshes.push(cubeMesh3);
  918. if(this.doorknobMaterial==null)
  919. {
  920. this.setdoorknobMaterial();
  921. }
  922. var cubeMesh5=BABYLON.Mesh.CreateBox( "Doorknob", 1, this.scene);
  923. cubeMesh5.scaling=new BABYLON.Vector3(2,10,22);
  924. cubeMesh5.position=new BABYLON.Vector3(location.point.x+5*Math.cos(location.angle),this.doorBottom,location.point.y+5*Math.sin(location.angle));
  925. cubeMesh5.rotation.y=-location.angle;
  926. //cubeMesh5.rotation.x = Math.PI / 2;
  927. cubeMesh5.material=this.doorknobMaterial;
  928. this.roomWallMeshes.push(cubeMesh5);
  929. var cubeMesh6 = cubeMesh5.clone("cubeMesh5");
  930. cubeMesh6.position=new BABYLON.Vector3(location.point.x-5*Math.cos(location.angle),this.doorBottom,location.point.y-5*Math.sin(location.angle));
  931. this.roomWallMeshes.push(cubeMesh6);
  932. return cubeMesh;
  933. };
  934. //添加BiFoldDoor
  935. Symbol3D.prototype.drawBiFoldDoor=function(location,len)
  936. {
  937. //墙挖洞
  938. var cubeMesh = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
  939. cubeMesh.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.doorThick);
  940. cubeMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  941. cubeMesh.rotation.y=-location.angle;
  942. //门框
  943. var cubeMesh2 = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
  944. cubeMesh2.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.baseSymbolThick+1);
  945. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  946. //门框挖洞
  947. var cubeMesh4 = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
  948. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,this.baseSymbolThick+1);
  949. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  950. var subCSG = aCSG.subtract(bCSG);
  951. var newMesh = subCSG.toMesh("Door", this.frameMaterial, this.scene);
  952. newMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  953. newMesh.rotation.y=-location.angle;
  954. //newMesh.rotation.x = Math.PI / 2;
  955. this.roomWallMeshes.push(newMesh);
  956. cubeMesh4.dispose();
  957. cubeMesh2.dispose();
  958. if(this.doormaterial==null)
  959. {
  960. this.setdoormaterial();
  961. }
  962. //大门
  963. var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
  964. cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,20);
  965. cubeMesh3.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  966. cubeMesh3.rotation.y=-location.angle;
  967. //cubeMesh3.rotation.x = Math.PI / 2;
  968. cubeMesh3.material=this.doormaterial;
  969. this.roomWallMeshes.push(cubeMesh3);
  970. if(this.doorknobMaterial==null)
  971. {
  972. this.setdoorknobMaterial();
  973. }
  974. //门把手
  975. var cubeMesh5=BABYLON.Mesh.CreateBox( "Doorknob", 1, this.scene);
  976. cubeMesh5.scaling=new BABYLON.Vector3(2,10,22);
  977. cubeMesh5.position=new BABYLON.Vector3(location.point.x+40*Math.cos(location.angle),this.doorBottom,location.point.y+40*Math.sin(location.angle));
  978. cubeMesh5.rotation.y=-location.angle;
  979. //cubeMesh5.rotation.x = Math.PI / 2;
  980. cubeMesh5.material=this.doorknobMaterial;
  981. this.roomWallMeshes.push(cubeMesh5);
  982. var cubeMesh6 = cubeMesh5.clone("cubeMesh5");
  983. cubeMesh6.position=new BABYLON.Vector3(location.point.x-40*Math.cos(location.angle),this.doorBottom,location.point.y-40*Math.sin(location.angle));
  984. this.roomWallMeshes.push(cubeMesh6);
  985. return cubeMesh;
  986. };
  987. //添加DoubleCasement
  988. Symbol3D.prototype.drawDoubleCasement=function(location,len)
  989. {
  990. var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  991. cubeMesh.scaling=new BABYLON.Vector3(len,this.windowHeigh,this.doorThick);
  992. cubeMesh.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
  993. cubeMesh.rotation.y=-location.angle;
  994. var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  995. cubeMesh2.scaling=new BABYLON.Vector3(len,this.windowHeigh,this.baseSymbolThick+1);
  996. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  997. var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  998. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.windowHeigh-10,this.baseSymbolThick+1);
  999. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  1000. var subCSG = aCSG.subtract(bCSG);
  1001. var newMesh = subCSG.toMesh("Window", this.frameMaterial, this.scene);
  1002. newMesh.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
  1003. newMesh.rotation.y=-location.angle;
  1004. //newMesh.rotation.x = Math.PI / 2;
  1005. this.roomWallMeshes.push(newMesh);
  1006. cubeMesh4.dispose();
  1007. cubeMesh2.dispose();
  1008. if(this.windowframeMaterial==null)
  1009. {
  1010. this.setwindowframeMaterial();
  1011. }
  1012. var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  1013. cubeMesh3.scaling=new BABYLON.Vector3(len/2,this.windowHeigh-10,20);
  1014. var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
  1015. var cubeMesh1 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  1016. cubeMesh1.scaling=new BABYLON.Vector3(len/2-11,this.windowHeigh-20,21);
  1017. var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
  1018. var subCSG2 = cCSG.subtract(dCSG);
  1019. var newMesh2 = subCSG2.toMesh("Window", this.windowframeMaterial, this.scene);
  1020. //newMesh2.position=new BABYLON.Vector3(location.point.x,this.windowBottom*2,location.point.y);
  1021. newMesh2.position=new BABYLON.Vector3(location.point.x+25*Math.cos(location.angle),this.windowBottom,location.point.y+25*Math.sin(location.angle));
  1022. newMesh2.rotation.y=-location.angle;
  1023. //newMesh2.rotation.x = Math.PI / 2;
  1024. this.roomWallMeshes.push(newMesh2);
  1025. var newMesh3 = newMesh2.clone("cubeMesh5");
  1026. newMesh3.position=new BABYLON.Vector3(location.point.x-25*Math.cos(location.angle),this.windowBottom,location.point.y-25*Math.sin(location.angle));
  1027. //this.roomWallMeshes.push(newMesh3);
  1028. cubeMesh1.dispose();
  1029. cubeMesh3.dispose();
  1030. //镜子
  1031. var cubeMesh6 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  1032. cubeMesh6.scaling=new BABYLON.Vector3(len-10,this.windowHeigh,21);
  1033. cubeMesh6.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
  1034. cubeMesh6.rotation.y=-location.angle;
  1035. //cubeMesh6.rotation.x = Math.PI / 2;
  1036. cubeMesh6.visibility = 0.08;
  1037. this.roomWallMeshes.push(cubeMesh6);
  1038. if(this.doorknobMaterial==null)
  1039. {
  1040. this.setdoorknobMaterial();
  1041. }
  1042. var cubeMesh5=BABYLON.Mesh.CreateBox( "Windowknob", 1, this.scene);
  1043. cubeMesh5.scaling=new BABYLON.Vector3(2,22,5);
  1044. cubeMesh5.position=new BABYLON.Vector3(location.point.x+2*Math.cos(location.angle),this.windowBottom,location.point.y+2*Math.sin(location.angle));
  1045. cubeMesh5.rotation.y=-location.angle;
  1046. cubeMesh5.rotation.x = Math.PI / 2;
  1047. cubeMesh5.material=this.doorknobMaterial;
  1048. this.roomWallMeshes.push(cubeMesh5);
  1049. var cubeMesh7 = cubeMesh5.clone("cubeMesh5");
  1050. cubeMesh7.position=new BABYLON.Vector3(location.point.x-2*Math.cos(location.angle),this.windowBottom,location.point.y-2*Math.sin(location.angle));
  1051. this.roomWallMeshes.push(cubeMesh7);
  1052. return cubeMesh;
  1053. };
  1054. //添加SlidingWindow
  1055. Symbol3D.prototype.drawSlidingWindow=function(location,len)
  1056. {
  1057. var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  1058. cubeMesh.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.doorThick);
  1059. cubeMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  1060. cubeMesh.rotation.y=-location.angle;
  1061. var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  1062. cubeMesh2.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.baseSymbolThick+1);
  1063. var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
  1064. var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  1065. cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,this.baseSymbolThick+1);
  1066. var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
  1067. var subCSG = aCSG.subtract(bCSG);
  1068. var newMesh = subCSG.toMesh("Window", this.frameMaterial, this.scene);
  1069. newMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  1070. newMesh.rotation.y=-location.angle;
  1071. //newMesh.rotation.x = Math.PI / 2;
  1072. this.roomWallMeshes.push(newMesh);
  1073. cubeMesh4.dispose();
  1074. cubeMesh2.dispose();
  1075. if(this.windowframeMaterial==null)
  1076. {
  1077. this.setwindowframeMaterial();
  1078. }
  1079. var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  1080. cubeMesh3.scaling=new BABYLON.Vector3(len/2-5,this.doorHeigh-10,20);
  1081. var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
  1082. var cubeMesh1 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  1083. cubeMesh1.scaling=new BABYLON.Vector3(len/2-16,this.doorHeigh-20,21);
  1084. var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
  1085. var subCSG2 = cCSG.subtract(dCSG);
  1086. var newMesh2 = subCSG2.toMesh("Window", this.windowframeMaterial, this.scene);
  1087. //newMesh2.position=new BABYLON.Vector3(location.point.x,this.windowBottom*2,location.point.y);
  1088. newMesh2.position=new BABYLON.Vector3(location.point.x+25*Math.cos(location.angle),this.doorBottom,location.point.y+25*Math.sin(location.angle));
  1089. newMesh2.rotation.y=-location.angle;
  1090. //newMesh2.rotation.x = Math.PI / 2;
  1091. this.roomWallMeshes.push(newMesh2);
  1092. var newMesh3 = newMesh2.clone("cubeMesh5");
  1093. newMesh3.position=new BABYLON.Vector3(location.point.x-25*Math.cos(location.angle),this.doorBottom,location.point.y-25*Math.sin(location.angle));
  1094. //this.roomWallMeshes.push(newMesh3);
  1095. cubeMesh1.dispose();
  1096. cubeMesh3.dispose();
  1097. //镜子
  1098. var cubeMesh6 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
  1099. cubeMesh6.scaling=new BABYLON.Vector3(len-10,this.doorHeigh,21);
  1100. cubeMesh6.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
  1101. cubeMesh6.rotation.y=-location.angle;
  1102. //cubeMesh6.rotation.x = Math.PI / 2;
  1103. cubeMesh6.visibility = 0.08;
  1104. this.roomWallMeshes.push(cubeMesh6);
  1105. if(this.doorknobMaterial==null)
  1106. {
  1107. this.setdoorknobMaterial();
  1108. }
  1109. var cubeMesh5=BABYLON.Mesh.CreateBox( "Windowknob", 1, this.scene);
  1110. cubeMesh5.scaling=new BABYLON.Vector3(2,22,5);
  1111. cubeMesh5.position=new BABYLON.Vector3(location.point.x+2*Math.cos(location.angle),this.doorBottom,location.point.y+2*Math.sin(location.angle));
  1112. cubeMesh5.rotation.y=-location.angle;
  1113. cubeMesh5.rotation.x = Math.PI / 2;
  1114. cubeMesh5.material=this.doorknobMaterial;
  1115. this.roomWallMeshes.push(cubeMesh5);
  1116. var cubeMesh7 = cubeMesh5.clone("cubeMesh5");
  1117. cubeMesh7.position=new BABYLON.Vector3(location.point.x-2*Math.cos(location.angle),this.doorBottom,location.point.y-2*Math.sin(location.angle));
  1118. this.roomWallMeshes.push(cubeMesh7);
  1119. return cubeMesh;
  1120. };
  1121. //初始化
  1122. Symbol3D.prototype.initialize = function ()
  1123. {
  1124. this.createScene();
  1125. this.setgroundmaterial();
  1126. this.setfloormaterial();
  1127. this.addSkybox();
  1128. this.addGround();
  1129. this.addEvent();
  1130. this.setwallmaterial();
  1131. };
  1132. //实时渲染
  1133. Symbol3D.prototype.render= function () {
  1134. this.scene.collisionsEnabled = true;
  1135. //console.log("radius:"+this.camera.radius);
  1136. var scene=this.scene;
  1137. var flag=true;
  1138. this.engine.runRenderLoop(
  1139. function () {
  1140. scene.render();
  1141. }
  1142. );
  1143. };
  1144. //编辑选中的模型
  1145. Symbol3D.prototype.refreshSelectMesh = function (currentMesh) {
  1146. for(var i=0;i<this.meshManager.arrowMeshes.length;++i)
  1147. {
  1148. if(this.meshManager.arrowMeshes[i]!=null&&typeof(this.meshManager.arrowMeshes[i]) != "undefined")
  1149. {
  1150. this.meshManager.arrowMeshes[i].dispose();
  1151. this.meshManager.arrowMeshes[i]=null;
  1152. }
  1153. }
  1154. var height = 10;
  1155. var shape = [
  1156. new BABYLON.Vector3(10, 0, 0),
  1157. new BABYLON.Vector3(5, height, 0)
  1158. ];
  1159. var top=1;
  1160. var radius= BABYLON.Vector2.Distance(new BABYLON.Vector2(currentMesh._boundingInfo.boundingBox.maximumWorld.x,currentMesh._boundingInfo.boundingBox.maximumWorld.z),new BABYLON.Vector2(currentMesh._boundingInfo.boundingBox.minimumWorld.x,currentMesh._boundingInfo.boundingBox.minimumWorld.z))/2;
  1161. if(radius>6)
  1162. {
  1163. top=radius-5;
  1164. }
  1165. var selectmat=new BABYLON.StandardMaterial("selectMat", this.scene);
  1166. selectmat.alpha = 1.0;
  1167. selectmat.diffuseColor = new BABYLON.Color3.Green();
  1168. selectmat.backFaceCulling = false;
  1169. this.meshManager.selectCircle = BABYLON.Mesh.CreateLathe('selectCircle', shape , radius,top, this.scene);
  1170. this.meshManager.selectCircle.material = selectmat;
  1171. this.meshManager.selectCircle.position=new BABYLON.Vector3(currentMesh._boundingInfo.boundingBox.center.x,0,currentMesh._boundingInfo.boundingBox.center.z);
  1172. if(currentMesh.name.indexOf("pho-")!=0&&currentMesh.name.indexOf("picture-")!=0)
  1173. {
  1174. this.meshManager.rotator = new BABYLON.Mesh.CreatePlane("rotator", 1, this.scene);
  1175. this.meshManager.rotator.scaling.x=28;
  1176. this.meshManager.rotator.scaling.y=14;
  1177. this.meshManager.rotator.material = new BABYLON.StandardMaterial("buttons", this.scene);
  1178. this.meshManager.rotator.material.diffuseTexture = new BABYLON.Texture("images/rotate.png", this.scene);
  1179. this.meshManager.rotator.material.diffuseTexture.hasAlpha = !0;
  1180. this.meshManager.rotator.material.backFaceCulling = !1;
  1181. }
  1182. this.meshManager.rotator.position.z = -radius;
  1183. this.meshManager.rotator.position.y = 0;
  1184. this.meshManager.rotator.parent = this.meshManager.selectCircle;
  1185. this.meshManager.rotator.position.y = Math.PI;
  1186. this.meshManager.rotator.rotation.x = Math.PI / 4;
  1187. };
  1188. Symbol3D.prototype.addEvent = function () {
  1189. // Events
  1190. var startingPoint;
  1191. var lastPosition;
  1192. var current;
  1193. //var angle=0;
  1194. var scene =this.scene
  1195. var tiledGround=this.tiledGround;
  1196. var ground =this.ground;
  1197. var camera =this.camera;
  1198. var canvas =this.canvas;
  1199. var currentMesh=null;
  1200. var collidables=this.meshManager.collidables;
  1201. var firstMeshes=this.meshManager.firstMeshes;
  1202. //var editProduct=this.meshManager.editProduct;
  1203. var infosize =this.meshManager.infoSize;
  1204. var selectMesh =this.meshManager.selectMesh;
  1205. var mesh1=this.meshManager.arrowMeshes[0];
  1206. var mesh2=this.meshManager.arrowMeshes[1];
  1207. var mesh3=this.meshManager.arrowMeshes[2];
  1208. var mesh4=this.meshManager.arrowMeshes[3];
  1209. //var furnitureMesh=this.meshManager.selectFurnitureMesh;
  1210. var wallHeigh=this.wallHeigh;
  1211. var createArrow=false;
  1212. var image="images/product/info.png";
  1213. var imagearrow="images/product/arrow.png";
  1214. var imageflip="images/product/infoGroup.png";
  1215. var info=null;
  1216. var infoextend=30;
  1217. var selectCircleY=0;
  1218. var infoheigh=3;
  1219. var min,max;
  1220. var top,down,left,right;
  1221. var vertexPoints=[];
  1222. //var length,heigh;
  1223. //line1是上下arrow的连线,line2是左右两个arrow的连线
  1224. var line1,line2;
  1225. var templane=null;
  1226. var interval=25;
  1227. var arrowdown,arrowtop,arrowleft,arrowright;
  1228. var measuremesh1=null,measuremesh2=null,measuremesh3=null,measuremesh4=null,measuremesh5=null,measuremesh6=null;
  1229. var olddistance=null;
  1230. var oldPlanept=null;
  1231. var measurediff=null;
  1232. var showpoint,showmesh;
  1233. var actionmove=false;
  1234. var actionRotator=false;
  1235. //var picflip=1;
  1236. var flipMesh=null;
  1237. var calculateLine=layer.calculateLine;
  1238. //var calculateLine=new CalculateLine();
  1239. //var curPicPho={target:null,colliMesh:null,distance:0};
  1240. var createSelectMat=function()
  1241. {
  1242. var mat=new BABYLON.StandardMaterial("selectMat", scene);
  1243. mat.alpha = 1.0;
  1244. mat.diffuseColor = new BABYLON.Color3.Green();
  1245. mat.backFaceCulling = false;
  1246. return mat;
  1247. };
  1248. var selectmat = createSelectMat();
  1249. collidables.remove = function(elem, all) {
  1250. for (var i=this.length-1; i>=0; i--) {
  1251. if (this[i] === elem) {
  1252. this.splice(i, 1);
  1253. if(!all)
  1254. break;
  1255. }
  1256. }
  1257. return this;
  1258. };
  1259. var setProductInfo=function()
  1260. {
  1261. var position_x=document.getElementById("position-x");
  1262. var position_y=document.getElementById("position-y");
  1263. var position_z=document.getElementById("position-z");
  1264. var position=my3DEngine.meshManager.selectFurnitureMesh.position;
  1265. position_x.childNodes[1].childNodes[0].value=Math.floor(position.x);
  1266. position_y.childNodes[1].childNodes[0].value=Math.floor(position.y);
  1267. position_z.childNodes[1].childNodes[0].value=Math.floor(position.z);
  1268. var params_width=document.getElementById("params-width");
  1269. var params_length=document.getElementById("params-length");
  1270. var width=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowdown.x,arrowdown.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z));
  1271. var length=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowright.x,arrowright.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z));
  1272. params_width.childNodes[1].childNodes[0].value=Math.floor(width);
  1273. params_width.childNodes[1].childNodes[0].alt=Math.floor(width);
  1274. params_length.childNodes[1].childNodes[0].value=Math.floor(length);
  1275. params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
  1276. };
  1277. var editProductInfo=function(h,position)
  1278. {
  1279. var width=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowdown.x,arrowdown.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z));
  1280. var length=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowright.x,arrowright.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z));
  1281. var height=h;
  1282. var positionX=position.x;
  1283. var positionY=position.y;
  1284. var positionZ=position.z;
  1285. var angleY=Math.floor((my3DEngine.meshManager.angle/Math.PI)*180);
  1286. var rotationy=document.getElementById("rotation-y");
  1287. if(angleY<0)
  1288. {
  1289. angleY=360+angleY;
  1290. }
  1291. rotationy.childNodes[1].childNodes[0].value=angleY;
  1292. rotationy.childNodes[1].childNodes[1].value=angleY;
  1293. var position_x=document.getElementById("position-x");
  1294. position_x.childNodes[1].childNodes[0].value=Math.floor(position.x);
  1295. var position_y=document.getElementById("position-y");
  1296. position_y.childNodes[1].childNodes[0].value=Math.floor(position.y);
  1297. var position_z=document.getElementById("position-z");
  1298. position_z.childNodes[1].childNodes[0].value=Math.floor(position.z);
  1299. var params_width=document.getElementById("params-width");
  1300. params_width.childNodes[1].childNodes[0].value=Math.floor(width);
  1301. params_width.childNodes[1].childNodes[0].alt=Math.floor(width);
  1302. var params_length=document.getElementById("params-length");
  1303. params_length.childNodes[1].childNodes[0].value=Math.floor(length);
  1304. params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
  1305. var params_height=document.getElementById("params-height");
  1306. params_height.childNodes[1].childNodes[0].value=Math.floor(height);
  1307. params_height.childNodes[1].childNodes[0].alt=Math.floor(height);
  1308. };
  1309. var setVertex=function(points,min,max)
  1310. {
  1311. var y=points[0].y;
  1312. var y1=points[1].y;
  1313. var m_points=[];
  1314. for(var i=0;i<points.length;++i)
  1315. {
  1316. if(y.toFixed(2)==points[i].y.toFixed(2)||Math.abs(points[i].y-y)<Math.abs(points[i].y-y1))
  1317. {
  1318. if(points[i].x==min.x&&points[i].z==min.z)
  1319. {
  1320. vertexPoints[0]=i;
  1321. }
  1322. else if(points[i].x==max.x&&points[i].z==max.z)
  1323. {
  1324. vertexPoints[2]=i;
  1325. }
  1326. else if(points[i].x==min.x&&points[i].z==max.z)
  1327. {
  1328. vertexPoints[1]=i;
  1329. }
  1330. else if(points[i].x==max.x&&points[i].z==min.z)
  1331. {
  1332. vertexPoints[3]=i;
  1333. }
  1334. else if(Math.abs(points[i].x-min.x)<Math.abs(points[i].x-max.x)&&Math.abs(points[i].z-min.z)<Math.abs(points[i].z-max.z))
  1335. {
  1336. vertexPoints[0]=i;
  1337. }
  1338. else if(Math.abs(points[i].x-max.x)<Math.abs(points[i].x-min.x)&&Math.abs(points[i].z-max.z)<Math.abs(points[i].z-min.z))
  1339. {
  1340. vertexPoints[2]=i;
  1341. }
  1342. else if(Math.abs(points[i].x-min.x)<Math.abs(points[i].x-max.x)&&Math.abs(points[i].z-max.z)<Math.abs(points[i].z-min.z))
  1343. {
  1344. vertexPoints[1]=i;
  1345. }
  1346. else if(Math.abs(points[i].x-max.x)<Math.abs(points[i].x-min.x)&&Math.abs(points[i].z-min.z)<Math.abs(points[i].z-max.z))
  1347. {
  1348. vertexPoints[3]=i;
  1349. }
  1350. }
  1351. }
  1352. };
  1353. var createRotator=function()
  1354. {
  1355. var rotator = new BABYLON.Mesh.CreatePlane("rotator", 1, scene);
  1356. rotator.scaling.x=28;
  1357. rotator.scaling.y=14;
  1358. rotator.material = new BABYLON.StandardMaterial("buttons", scene);
  1359. rotator.material.diffuseTexture = new BABYLON.Texture("images/rotate.png", scene);
  1360. rotator.material.diffuseTexture.hasAlpha = !0;
  1361. rotator.material.backFaceCulling = !1;
  1362. return rotator;
  1363. };
  1364. var isnotFurniture=function (currentMesh)
  1365. {
  1366. if (typeof(currentMesh.name) == "undefined") {
  1367. return false;
  1368. }
  1369. //if(currentMesh.name.indexOf("Door")>=0||currentMesh.name.indexOf("Window")>=0||currentMesh.name.indexOf("floor")>=0||currentMesh.name=="plane"||currentMesh.name=="skyBox"||(currentMesh.id.indexOf("wall")>=0)||(currentMesh.name=="mesh_merged"))
  1370. if(currentMesh.name.indexOf("Door")>=0||currentMesh.name.indexOf("Window")>=0||currentMesh.name=="plane"||currentMesh.name=="skyBox")
  1371. {
  1372. return true;
  1373. }
  1374. else
  1375. {
  1376. return false;
  1377. }
  1378. };
  1379. var getWallPlanePosition = function () {
  1380. // Use a predicate to get position on the ground
  1381. var pickinfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) { return mesh.name == "plane"; });
  1382. if (pickinfo.hit) {
  1383. //return {point:pickinfo.pickedPoint,index:pickinfo.pickedMesh.planindex};
  1384. return {point:pickinfo.pickedPoint,index:pickinfo.pickedMesh.planindex};
  1385. }
  1386. return null;
  1387. };
  1388. var getGroundPosition = function () {
  1389. // Use a predicate to get position on the ground
  1390. var pickinfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) {
  1391. return (mesh == tiledGround || mesh == ground ||isnotFurniture(mesh));
  1392. });
  1393. if (pickinfo.hit) {
  1394. return pickinfo.pickedPoint;
  1395. }
  1396. return null;
  1397. };
  1398. var getGroundPositionFromArrow = function () {
  1399. // Use a predicate to get position on the ground
  1400. var pickinfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) {
  1401. return (mesh == tiledGround || mesh == ground ||isnotFurniture(mesh)||(mesh.id.indexOf("arrow")>-1));
  1402. });
  1403. if (pickinfo.hit) {
  1404. return pickinfo.pickedPoint;
  1405. }
  1406. return null;
  1407. };
  1408. var boundcontains=function(point,currentMesh)
  1409. {
  1410. currentMesh.computeWorldMatrix(true);
  1411. currentMesh.refreshBoundingInfo();
  1412. if(point.x>currentMesh._boundingInfo.boundingBox.maximumWorld.x||point.y>currentMesh._boundingInfo.boundingBox.maximumWorld.z||point.x<currentMesh._boundingInfo.boundingBox.minimumWorld.x||point.y<currentMesh._boundingInfo.boundingBox.minimumWorld.z)
  1413. {
  1414. return false;
  1415. }
  1416. else
  1417. {
  1418. return true;
  1419. }
  1420. };
  1421. var getDiff=function(diff,line)
  1422. {
  1423. var result;
  1424. if(line.a==0)
  1425. {
  1426. if(line.x)
  1427. {
  1428. result=new BABYLON.Vector3(0,diff.y,diff.z);
  1429. }
  1430. else
  1431. {
  1432. result=new BABYLON.Vector3(diff.x,diff.y,0);
  1433. }
  1434. }
  1435. else
  1436. {
  1437. line.b=0;
  1438. var interpoint=calculateLine.getJoinLinePoint({x:diff.x,y:diff.z},line);
  1439. result=new BABYLON.Vector3(interpoint.x,diff.y,interpoint.y);
  1440. }
  1441. return result;
  1442. };
  1443. var getDiff2=function(current,line)
  1444. {
  1445. var result;
  1446. var interpoint=calculateLine.getJoinLinePoint({x:current.x,y:current.z},line);
  1447. result=new BABYLON.Vector3(interpoint.x,current.y,interpoint.y);
  1448. return result;
  1449. };
  1450. var setselectMesh=function()
  1451. {
  1452. var height = 10;
  1453. var shape = [
  1454. new BABYLON.Vector3(10, 0, 0),
  1455. new BABYLON.Vector3(5, height, 0)
  1456. ];
  1457. var top=1;
  1458. var radius= BABYLON.Vector2.Distance(new BABYLON.Vector2(currentMesh._boundingInfo.boundingBox.maximumWorld.x,currentMesh._boundingInfo.boundingBox.maximumWorld.z),new BABYLON.Vector2(currentMesh._boundingInfo.boundingBox.minimumWorld.x,currentMesh._boundingInfo.boundingBox.minimumWorld.z))/2;
  1459. if(radius>6)
  1460. {
  1461. top=radius-5;
  1462. }
  1463. if(my3DEngine.meshManager.selectCircle==null)
  1464. {
  1465. if(currentMesh.name.indexOf("pho-")!=0&&currentMesh.name.indexOf("picture-")!=0)
  1466. {
  1467. my3DEngine.meshManager.selectCircle = BABYLON.Mesh.CreateLathe('selectCircle', shape , radius,top, scene);
  1468. my3DEngine.meshManager.selectCircle.material = selectmat;
  1469. }
  1470. }
  1471. else
  1472. {
  1473. if(currentMesh.name.indexOf("picture-")==0||currentMesh.name.indexOf("pho-")==0)
  1474. {
  1475. my3DEngine.meshManager.selectCircle.dispose();
  1476. my3DEngine.meshManager.selectCircle=null;
  1477. }
  1478. }
  1479. if(currentMesh.name.indexOf("pho-")!=0&&currentMesh.name.indexOf("picture-")!=0)
  1480. {
  1481. my3DEngine.meshManager.selectCircle.position=new BABYLON.Vector3(currentMesh._boundingInfo.boundingBox.center.x,selectCircleY,currentMesh._boundingInfo.boundingBox.center.z);
  1482. if(my3DEngine.meshManager.rotator==null)
  1483. {
  1484. my3DEngine.meshManager.rotator=createRotator();
  1485. }
  1486. my3DEngine.meshManager.rotator.position.z = -radius;
  1487. my3DEngine.meshManager.rotator.position.y = selectCircleY;
  1488. if(my3DEngine.meshManager.selectCircle!=null)
  1489. {
  1490. my3DEngine.meshManager.rotator.parent = my3DEngine.meshManager.selectCircle;
  1491. }
  1492. my3DEngine.meshManager.rotator.position.y = Math.PI;
  1493. my3DEngine.meshManager.rotator.rotation.x = Math.PI / 4;
  1494. }
  1495. else
  1496. {
  1497. if(my3DEngine.meshManager.rotator!=null)
  1498. {
  1499. my3DEngine.meshManager.rotator.dispose();
  1500. my3DEngine.meshManager.rotator=null;
  1501. }
  1502. }
  1503. if(my3DEngine.meshManager.selectFurnitureMesh.rotationQuaternion==null||typeof(my3DEngine.meshManager.selectFurnitureMesh.rotationQuaternion) == "undefined")
  1504. {
  1505. my3DEngine.meshManager.angle=0;
  1506. }
  1507. else
  1508. {
  1509. //var angleY=my3DEngine.meshManager.selectFurnitureMesh.rotationQuaternion.y;
  1510. var angleY=my3DEngine.meshManager.selectFurnitureMesh.rotation.y;
  1511. if(angleY<0)
  1512. {
  1513. angleY=2*Math.PI+angleY;
  1514. }
  1515. my3DEngine.meshManager.angle=angleY;
  1516. }
  1517. };
  1518. var createinfo=function()
  1519. {
  1520. var sprite = new BABYLON.SpriteManager("meshManager", image, 6, 128, scene);
  1521. sprite.isPickable = true;
  1522. // First animated player
  1523. info = new BABYLON.Sprite("editFurniture", sprite);
  1524. info.position= new BABYLON.Vector3(currentMesh.position.x, currentMesh._boundingInfo.boundingBox.maximumWorld.y+infoextend, currentMesh.position.z);
  1525. //if(currentMesh.name.indexOf("picture-")==0||currentMesh.name.indexOf("pho-")==0)
  1526. //{
  1527. // info.position.y=(currentMesh._boundingInfo.boundingBox.maximumWorld.y+ currentMesh._boundingInfo.boundingBox.minimumWorld.y)/2;
  1528. //}
  1529. info.size = infosize;
  1530. infoheigh=currentMesh._boundingInfo.boundingBox.maximumWorld.y/2;
  1531. // click action for player
  1532. info.actionManager = new BABYLON.ActionManager(scene);
  1533. info.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickUpTrigger, function () {
  1534. if(!actionmove)
  1535. {
  1536. if(!createArrow)
  1537. {
  1538. currentMesh.computeWorldMatrix(true);
  1539. currentMesh.refreshBoundingInfo();
  1540. var configuratorProduct=document.getElementById("configuratorWindow");
  1541. configuratorProduct.style.display="block";
  1542. /*
  1543. if(currentMesh.name.indexOf("picture-")==0||currentMesh.name.indexOf("pho-")==0)
  1544. {
  1545. createArrows2(currentMesh,scene,imagearrow);
  1546. document.getElementById("editptrot").innerText="位置";
  1547. document.getElementById("item-1").style.display="none";
  1548. document.getElementById("rotation-y").style.display="none";
  1549. document.getElementById("params-height").style.display="none";
  1550. }
  1551. else
  1552. {
  1553. */
  1554. createArrows(currentMesh,scene,imagearrow);
  1555. document.getElementById("editptrot").innerText="位置和角度";
  1556. document.getElementById("item-1").style.display="";
  1557. document.getElementById("rotation-y").style.display="";
  1558. document.getElementById("params-height").style.display="";
  1559. //}
  1560. createArrow=true;
  1561. info.dispose();
  1562. info=null;
  1563. if(my3DEngine.meshManager.selectCircle!=null)
  1564. {
  1565. my3DEngine.meshManager.selectCircle.dispose();
  1566. my3DEngine.meshManager.selectCircle=null;
  1567. if(my3DEngine.meshManager.rotator!=null)
  1568. {
  1569. my3DEngine.meshManager.rotator.dispose();
  1570. my3DEngine.meshManager.rotator=null;
  1571. }
  1572. }
  1573. editProductInfo(Math.abs(currentMesh._boundingInfo.boundingBox.maximumWorld.y- currentMesh._boundingInfo.boundingBox.minimumWorld.y),currentMesh.position);
  1574. }
  1575. my3DEngine.meshManager.editProduct=true;
  1576. }
  1577. }));
  1578. info.isPickable = true;
  1579. };
  1580. var selectArrow=function()
  1581. {
  1582. templane=BABYLON.Mesh.CreatePlane("temp", 1, scene);
  1583. if(currentMesh.name=="downarrow")
  1584. {
  1585. templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.x*my3DEngine.meshManager.selectFurnitureMesh.scaling.x*2;
  1586. templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
  1587. templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle, BABYLON.Space.LOCAL);
  1588. templane.position=arrowdown;
  1589. olddistance=BABYLON.Vector3.Distance(arrowdown,arrowtop);
  1590. var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z));
  1591. var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowright.x,arrowright.z));
  1592. if(distance1>distance2)
  1593. {
  1594. showpoint=arrowright;
  1595. showmesh=mesh4;
  1596. }
  1597. else
  1598. {
  1599. showpoint=arrowleft;
  1600. showmesh=mesh3;
  1601. }
  1602. }
  1603. else if(currentMesh.name=="toparrow")
  1604. {
  1605. templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.x*my3DEngine.meshManager.selectFurnitureMesh.scaling.x*2;
  1606. templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
  1607. templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle, BABYLON.Space.LOCAL);
  1608. templane.position=arrowtop;
  1609. //templane.position=new BABYLON.Vector3(arrowtop.x,arrowtop.y,arrowtop.z);
  1610. olddistance=BABYLON.Vector3.Distance(arrowdown,arrowtop);
  1611. var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z));
  1612. var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowright.x,arrowright.z));
  1613. if(distance1>distance2)
  1614. {
  1615. showpoint=arrowright;
  1616. showmesh=mesh4;
  1617. }
  1618. else
  1619. {
  1620. showpoint=arrowleft;
  1621. showmesh=mesh3;
  1622. }
  1623. }
  1624. else if(currentMesh.name=="leftarrow")
  1625. {
  1626. /*
  1627. if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")==0||my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")==0)
  1628. {
  1629. templane.rotate(BABYLON.Axis.Y,Math.PI/2, BABYLON.Space.LOCAL);
  1630. templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
  1631. templane.scaling.y=10;
  1632. }
  1633. else
  1634. {
  1635. */
  1636. templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle+Math.PI/2, BABYLON.Space.LOCAL);
  1637. templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.z*my3DEngine.meshManager.selectFurnitureMesh.scaling.z*2;
  1638. templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
  1639. //}
  1640. templane.position=arrowleft;
  1641. //templane.position=new BABYLON.Vector3(arrowleft.x,arrowleft.y,arrowleft.z);
  1642. olddistance=BABYLON.Vector3.Distance(arrowleft,arrowright);
  1643. var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z));
  1644. var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowdown.x,arrowdown.z));
  1645. if(distance1>distance2)
  1646. {
  1647. showpoint=arrowdown;
  1648. showmesh=mesh1;
  1649. }
  1650. else
  1651. {
  1652. showpoint=arrowtop;
  1653. showmesh=mesh2;
  1654. }
  1655. }
  1656. else if(currentMesh.name=="rightarrow")
  1657. {
  1658. /*
  1659. if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")==0||my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")==0)
  1660. {
  1661. templane.rotate(BABYLON.Axis.Y,-Math.PI/2, BABYLON.Space.LOCAL);
  1662. templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
  1663. templane.scaling.y=10;
  1664. }
  1665. else
  1666. {
  1667. */
  1668. templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle+Math.PI/2, BABYLON.Space.LOCAL);
  1669. templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.z*my3DEngine.meshManager.selectFurnitureMesh.scaling.z*2;
  1670. templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
  1671. //}
  1672. templane.position=arrowright;
  1673. //templane.position=new BABYLON.Vector3(arrowright.x,arrowright.y,arrowright.z);
  1674. olddistance=BABYLON.Vector3.Distance(arrowleft,arrowright);
  1675. var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z));
  1676. var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowdown.x,arrowdown.z));
  1677. if(distance1>distance2)
  1678. {
  1679. showpoint=arrowdown;
  1680. showmesh=mesh1;
  1681. }
  1682. else
  1683. {
  1684. showpoint=arrowtop;
  1685. showmesh=mesh2;
  1686. }
  1687. }
  1688. measurediff=showmesh.position.subtract(my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center);
  1689. var r=new BABYLON.StandardMaterial("materialplane",scene);
  1690. r.diffuseColor=new BABYLON.Color3.Green();
  1691. r.backFaceCulling =false;
  1692. templane.material=r;
  1693. oldPlanept=new BABYLON.Vector3(templane.position.x,templane.position.y,templane.position.z);
  1694. };
  1695. var removeinfo=function()
  1696. {
  1697. if(info!=null&&!info._isDisposed)
  1698. {
  1699. info.dispose();
  1700. info=null;
  1701. }
  1702. my3DEngine.meshManager.editProduct=false;
  1703. clearArrow();
  1704. if(my3DEngine.meshManager.selectCircle!=null)
  1705. {
  1706. my3DEngine.meshManager.selectCircle.dispose();
  1707. my3DEngine.meshManager.selectCircle=null;
  1708. if(my3DEngine.meshManager.rotator!=null)
  1709. {
  1710. my3DEngine.meshManager.rotator.dispose();
  1711. my3DEngine.meshManager.rotator=null;
  1712. }
  1713. }
  1714. };
  1715. var removeSelectMesh=function()
  1716. {
  1717. if(my3DEngine.meshManager.selectFurnitureMesh!=null&&typeof(my3DEngine.meshManager.selectFurnitureMesh) != "undefined")
  1718. {
  1719. collidables.push(my3DEngine.meshManager.selectFurnitureMesh);
  1720. my3DEngine.meshManager.selectFurnitureMesh=null;
  1721. }
  1722. if(currentMesh==null||typeof(currentMesh) == "undefined")
  1723. {
  1724. return;
  1725. }
  1726. removeinfo();
  1727. };
  1728. var finishEditMesh=function()
  1729. {
  1730. if(templane!=null)
  1731. {
  1732. if(olddistance!=null)
  1733. {
  1734. var dxz=templane.position.subtract(oldPlanept);
  1735. var newscal,m_newdistance,m_olddistance;
  1736. if(currentMesh.name=="downarrow")
  1737. {
  1738. m_newdistance=arrowdown.subtract(arrowtop);
  1739. m_olddistance=oldPlanept.subtract(arrowtop);
  1740. }
  1741. else if(currentMesh.name=="toparrow")
  1742. {
  1743. m_newdistance=arrowtop.subtract(arrowdown);
  1744. m_olddistance=oldPlanept.subtract(arrowdown);
  1745. }
  1746. else if(currentMesh.name=="leftarrow")
  1747. {
  1748. m_newdistance=arrowleft.subtract(arrowright);
  1749. m_olddistance=oldPlanept.subtract(arrowright);
  1750. }
  1751. else if(currentMesh.name=="rightarrow")
  1752. {
  1753. m_newdistance=arrowright.subtract(arrowleft);
  1754. m_olddistance=oldPlanept.subtract(arrowleft);
  1755. }
  1756. newscal=new BABYLON.Vector3(m_newdistance.x.toFixed(2)/m_olddistance.x.toFixed(2)*my3DEngine.meshManager.selectFurnitureMesh.scaling.x.toFixed(2),0,m_newdistance.z.toFixed(2)/m_olddistance.z.toFixed(2)*my3DEngine.meshManager.selectFurnitureMesh.scaling.z.toFixed(2));
  1757. if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow")
  1758. {
  1759. if(!isNaN(newscal.z)&&newscal.z!=-Number.POSITIVE_INFINITY&&newscal.z!=Number.POSITIVE_INFINITY)
  1760. {
  1761. /*
  1762. if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")==0||my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")==0)
  1763. {
  1764. my3DEngine.meshManager.selectFurnitureMesh.scaling.y=m_newdistance.z.toFixed(2)/m_olddistance.z.toFixed(2)*my3DEngine.meshManager.selectFurnitureMesh.scaling.y.toFixed(2)
  1765. }
  1766. else
  1767. {
  1768. */
  1769. my3DEngine.meshManager.selectFurnitureMesh.scaling.z=newscal.z;
  1770. //}
  1771. }
  1772. }
  1773. else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow")
  1774. {
  1775. if(!isNaN(newscal.x)&&newscal.x!=-Number.POSITIVE_INFINITY&&newscal.x!=Number.POSITIVE_INFINITY)
  1776. {
  1777. my3DEngine.meshManager.selectFurnitureMesh.scaling.x=newscal.x;
  1778. }
  1779. }
  1780. my3DEngine.meshManager.selectFurnitureMesh.computeWorldMatrix(true);
  1781. my3DEngine.meshManager.selectFurnitureMesh.refreshBoundingInfo();
  1782. var dxz2;
  1783. if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow")
  1784. {
  1785. dxz2=my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center.subtract(new BABYLON.Vector3((arrowdown.x+arrowtop.x)/2,0,(arrowdown.z+arrowtop.z)/2));
  1786. my3DEngine.meshManager.selectFurnitureMesh.position.addInPlace(new BABYLON.Vector3(-dxz2.x,0,-dxz2.z));
  1787. arrowleft.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
  1788. arrowright.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
  1789. }
  1790. else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow")
  1791. {
  1792. dxz2=my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center.subtract(new BABYLON.Vector3((arrowleft.x+arrowright.x)/2,0,(arrowleft.z+arrowright.z)/2));
  1793. my3DEngine.meshManager.selectFurnitureMesh.position.addInPlace(new BABYLON.Vector3(-dxz2.x,0,-dxz2.z));
  1794. arrowtop.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
  1795. arrowdown.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
  1796. }
  1797. line1=calculateLine.createLine(new BABYLON.Vector2(arrowdown.x,arrowdown.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z));
  1798. line2=calculateLine.createLine(new BABYLON.Vector2(arrowleft.x,arrowleft.z),new BABYLON.Vector2(arrowright.x,arrowright.z));
  1799. }
  1800. templane.dispose();
  1801. templane=null;
  1802. olddistance=null;
  1803. }
  1804. };
  1805. var editingMesh=function(type)
  1806. {
  1807. var newpoint;
  1808. clearMeasureMesh();
  1809. if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow")
  1810. {
  1811. if(type==1)
  1812. {
  1813. newpoint=getDiff2(current,line1);
  1814. newpoint.y=currentMesh.position.y;
  1815. }
  1816. else //针对相框和墙贴
  1817. {
  1818. newpoint=new BABYLON.Vector3(line1.x,currentMesh.position.y,current.z);
  1819. }
  1820. diff2=showpoint.subtract(my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center);
  1821. diff3=measurediff;
  1822. ddif=diff3.subtract(diff2);
  1823. ddif.x=ddif.x/4;
  1824. ddif.y=ddif.y/4;
  1825. ddif.z=ddif.z/4;
  1826. startpoint=arrowtop.add(diff3);
  1827. startpoint.addInPlace(ddif);
  1828. endpoint=arrowdown.add(diff3);
  1829. endpoint.addInPlace(ddif);
  1830. var fontpt=new BABYLON.Vector3((startpoint.x+endpoint.x)/2,(startpoint.y+endpoint.y)/2,(startpoint.z+endpoint.z)/2);
  1831. fontpt.addInPlace(ddif);
  1832. measuremesh6 = makeTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", 50,fontpt);
  1833. measuremesh6.rotation.x=Math.PI/2;
  1834. if(showmesh.name=="rightarrow")
  1835. {
  1836. measuremesh6.rotation.y=-Math.PI/2+my3DEngine.meshManager.angle;
  1837. }
  1838. else
  1839. {
  1840. measuremesh6.rotation.y=Math.PI/2+my3DEngine.meshManager.angle;
  1841. }
  1842. }
  1843. else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow")
  1844. {
  1845. if(type==1)
  1846. {
  1847. newpoint=getDiff2(current,line2);
  1848. newpoint.y=currentMesh.position.y;
  1849. }
  1850. else
  1851. {
  1852. newpoint=new BABYLON.Vector3(line2.y,currentMesh.position.y,current.x);
  1853. }
  1854. diff2=showpoint.subtract(my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center);
  1855. diff3=measurediff;
  1856. ddif=diff3.subtract(diff2);
  1857. ddif.x=ddif.x/4;
  1858. ddif.y=ddif.y/4;
  1859. ddif.z=ddif.z/4;
  1860. startpoint=arrowleft.add(diff3);
  1861. startpoint.addInPlace(ddif);
  1862. endpoint=arrowright.add(diff3);
  1863. endpoint.addInPlace(ddif);
  1864. var fontpt=new BABYLON.Vector3((startpoint.x+endpoint.x)/2,(startpoint.y+endpoint.y)/2,(startpoint.z+endpoint.z)/2);
  1865. fontpt.addInPlace(ddif);
  1866. measuremesh6 = makeTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", 50,fontpt);
  1867. measuremesh6.rotation.x=Math.PI/2;
  1868. if(showmesh.name=="toparrow")
  1869. {
  1870. measuremesh6.rotation.y=Math.PI+my3DEngine.meshManager.angle;
  1871. if(measuremesh6.rotation.y>2*Math.PI)
  1872. {
  1873. measuremesh6.rotation.y-=2*Math.PI;
  1874. }
  1875. }
  1876. }
  1877. var startpoint1=startpoint.add(ddif);
  1878. var startpoint2=startpoint.subtract(ddif);
  1879. var endpoint1=endpoint.add(ddif);
  1880. var endpoint2=endpoint.subtract(ddif);
  1881. measuremesh1=BABYLON.Mesh.CreateLines("start",[startpoint1,startpoint2],scene);
  1882. measuremesh2=BABYLON.Mesh.CreateLines("end",[endpoint1,endpoint2],scene);
  1883. measuremesh3=BABYLON.Mesh.CreateLines("end",[startpoint,endpoint],scene);
  1884. var pts1=drawArrow({x:startpoint.x,y:startpoint.z},{x:endpoint.x,y:endpoint.z},endpoint.y);
  1885. var pts2=drawArrow({x:endpoint.x,y:endpoint.z},{x:startpoint.x,y:startpoint.z},startpoint.y);
  1886. measuremesh4=BABYLON.Mesh.CreateLines("arrowend",pts1,scene);
  1887. measuremesh5=BABYLON.Mesh.CreateLines("arrowstart",pts2,scene);
  1888. measuremesh1.color = new BABYLON.Color3.Black();
  1889. measuremesh2.color = new BABYLON.Color3.Black();
  1890. measuremesh3.color = new BABYLON.Color3.Black();
  1891. measuremesh4.color = new BABYLON.Color3.Black();
  1892. measuremesh5.color = new BABYLON.Color3.Black();
  1893. return newpoint;
  1894. };
  1895. var closeConfigProduct=function()
  1896. {
  1897. var configuratorProduct=document.getElementById("configuratorWindow");
  1898. configuratorProduct.style.display="none";
  1899. };
  1900. var paintWallFromSubMesh=function(subMeshId)
  1901. {
  1902. var addMat = new BABYLON.StandardMaterial("paint", scene);
  1903. addMat.alpha = 1.0;
  1904. var r=my3DEngine.paintWall.value.r;
  1905. var g=my3DEngine.paintWall.value.g;
  1906. var b=my3DEngine.paintWall.value.b;
  1907. addMat.diffuseColor = new BABYLON.Color3(r, g, b);
  1908. addMat.specularColor =new BABYLON.Color3(r, g, b);
  1909. addMat.emissiveColor = new BABYLON.Color3(r, g, b);
  1910. addMat.backFaceCulling = false;
  1911. addMat.toward=currentMesh.material.subMaterials[subMeshId/2].toward;
  1912. currentMesh.material.subMaterials[subMeshId/2]=addMat;
  1913. //currentMesh.applyDisplacementMap("http://3.bp.blogspot.com/-0ceB5kqwo70/TgF9neqSuKI/AAAAAAAAKCc/cdK47cIp-ZY/s1600/PUMPKIN+CARVINGS+FACE.jpg", -0.5, 0);
  1914. startingPoint=null;
  1915. var flag=false;
  1916. for(var i=0;i<my3DEngine.paintSet.length;++i)
  1917. {
  1918. if(my3DEngine.paintSet[i].type=="wall"&&my3DEngine.paintSet[i].wallId==currentMesh.id&&my3DEngine.paintSet[i].materialId==subMeshId/2)
  1919. {
  1920. my3DEngine.paintSet[i].material=addMat;
  1921. flag=true;
  1922. break;
  1923. }
  1924. }
  1925. if(!flag)
  1926. {
  1927. my3DEngine.paintSet.push({wallId:currentMesh.id,materialId:subMeshId/2,material:addMat,type:"wall"});
  1928. }
  1929. document.getElementById("container3d").style.cursor="default";
  1930. };
  1931. var onPointerDown = function (evt) {
  1932. if(this.lock)
  1933. {
  1934. return;
  1935. }
  1936. actionmove=false;
  1937. if (evt.button !== 0&&evt.button !== 2) {
  1938. return;
  1939. }
  1940. startingPoint = getGroundPosition(evt);
  1941. if(evt.button == 2)
  1942. {
  1943. if (startingPoint) { // we need to disconnect camera from canvas
  1944. setTimeout(function () {
  1945. camera.detachControl(canvas);
  1946. }, 0);
  1947. }
  1948. }
  1949. // check if we are under a mesh
  1950. var pickInfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) {
  1951. return (mesh !== tiledGround && mesh !== ground&&!isnotFurniture(mesh) );
  1952. });
  1953. if (pickInfo.hit) {
  1954. currentMesh= pickInfo.pickedMesh;
  1955. if(currentMesh.name.indexOf("wall")>=0)
  1956. {
  1957. if(my3DEngine.paintWall.beginPaint)
  1958. {
  1959. paintWallFromSubMesh(pickInfo.subMeshId);
  1960. my3DEngine.paintWall.beginPaint=false;
  1961. }
  1962. else if(my3DEngine.phoSet.start)
  1963. {
  1964. my3DEngine.phoSet.start=false;
  1965. document.getElementById("container3d").style.cursor="default";
  1966. var joinpoint=pickInfo.pickedPoint;
  1967. var toward= currentMesh.material.subMaterials[pickInfo.subMeshId/2].toward;
  1968. var indexplane=currentMesh.material.subMaterials[pickInfo.subMeshId/2].indexplane;
  1969. var point1=currentMesh.material.subMaterials[pickInfo.subMeshId/2].points.point1;
  1970. var point2=currentMesh.material.subMaterials[pickInfo.subMeshId/2].points.point2;
  1971. var tempjoin=calculateLine.getPtIntersect3D(point1,point2,toward,my3DEngine.phoSet.photoFrameMesh.thice,joinpoint);
  1972. var tempjoin1=new BABYLON.Vector3(tempjoin.point1.x,tempjoin.point1.y,tempjoin.point1.z);
  1973. var tempjoin2=new BABYLON.Vector3(tempjoin.point2.x,tempjoin.point2.y,tempjoin.point2.z);
  1974. my3DEngine.phoSet.photoFrameMesh.rotation.y=collidables[indexplane].rotation.y;
  1975. my3DEngine.phoSet.photoFrameMesh.position=tempjoin1;
  1976. my3DEngine.phoSet.photoFrameMesh.computeWorldMatrix(true);
  1977. my3DEngine.phoSet.photoFrameMesh.refreshBoundingInfo();
  1978. if(my3DEngine.phoSet.photoFrameMesh._boundingInfo.boundingBox.maximumWorld.y>wallHeigh||my3DEngine.phoSet.photoFrameMesh._boundingInfo.boundingBox.minimumWorld.y<0)
  1979. {
  1980. my3DEngine.phoSet.photoFrameMesh.position.y=wallHeigh/2;
  1981. tempjoin1.y=wallHeigh/2;
  1982. tempjoin2.y=wallHeigh/2;
  1983. }
  1984. my3DEngine.phoSet.photoFrameMesh.planeindex=pickInfo.subMeshId/2;
  1985. var diffplane=tempjoin2.subtract(tempjoin1);
  1986. if(diffplane.x==0&&diffplane.y==0&&diffplane.z==0)
  1987. {
  1988. my3DEngine.phoSet.photoFrameMesh.visibility=1;
  1989. alert("2275");
  1990. return ;
  1991. }
  1992. else
  1993. {
  1994. var add=1;
  1995. while(!collidables[indexplane].intersectsMesh(my3DEngine.phoSet.photoFrameMesh, true))
  1996. {
  1997. tempjoin1.addInPlace(new BABYLON.Vector3(diffplane.x*0.1,diffplane.y*0.1,diffplane.z*0.1));
  1998. ++add;
  1999. if(add>19)
  2000. {
  2001. //alert(2324);
  2002. break;
  2003. }
  2004. my3DEngine.phoSet.photoFrameMesh.position=tempjoin1;
  2005. my3DEngine.phoSet.photoFrameMesh.computeWorldMatrix(true);
  2006. my3DEngine.phoSet.photoFrameMesh.refreshBoundingInfo();
  2007. }
  2008. my3DEngine.phoSet.photoFrameMesh.visibility=1;
  2009. var fontpt=my3DEngine.phoSet.photoFrameMesh._boundingInfo.boundingBox.vectorsWorld[my3DEngine.phoSet.photoFrameMesh.frontindex];
  2010. var toward2=calculateLine.getToward(point1,point2,{x:fontpt.x,y:fontpt.z});
  2011. if(toward!=toward2)
  2012. {
  2013. my3DEngine.phoSet.photoFrameMesh.rotation.y+=Math.PI;
  2014. }
  2015. if(my3DEngine.phoSet.photoFrameMesh.rotation.y>=2*Math.PI)
  2016. {
  2017. my3DEngine.phoSet.photoFrameMesh.rotation.y-=2*Math.PI;
  2018. }
  2019. for(var i=0;i<collidables.length;++i)
  2020. {
  2021. if(i==indexplane)
  2022. {
  2023. continue;
  2024. }
  2025. if(collidables[i].intersectsMesh(my3DEngine.phoSet.photoFrameMesh, true))
  2026. {
  2027. my3DEngine.phoSet.photoFrameMesh.position.y=-100;
  2028. my3DEngine.phoSet.photoFrameMesh.visibility=0;
  2029. return;
  2030. }
  2031. }
  2032. return;
  2033. }
  2034. }
  2035. else
  2036. {
  2037. removeSelectMesh();
  2038. closeConfigProduct();
  2039. return;
  2040. }
  2041. return;
  2042. }
  2043. else if(currentMesh.name.indexOf("floor")>=0)
  2044. {
  2045. if(!my3DEngine.paintPlane.beginPaint)
  2046. {
  2047. removeSelectMesh();
  2048. closeConfigProduct();
  2049. return;
  2050. }
  2051. else
  2052. {
  2053. my3DEngine.paintPlane.beginPaint=false;
  2054. }
  2055. my3DEngine.paintPlane.currentId=currentMesh.id;
  2056. my3DEngine.refreshFloor(currentMesh.wallid);
  2057. return;
  2058. }
  2059. else if(currentMesh.name.indexOf("pho-")>=0||currentMesh.name.indexOf("picture-")>=0)
  2060. {
  2061. var configuratorProduct=document.getElementById("configuratorWindow");
  2062. configuratorProduct.style.display="block";
  2063. document.getElementById("editptrot").style.display="none";
  2064. document.getElementById("item-1").style.display="none";
  2065. document.getElementById("rotation-y").style.display="none";
  2066. document.getElementById("params-width").style.display="none";
  2067. var params_height=document.getElementById("params-height");
  2068. var params_length=document.getElementById("params-length");
  2069. //var height=Math.abs(currentMesh._boundingInfo.boundingBox.maximumWorld.y-currentMesh._boundingInfo.boundingBox.minimumWorld.y);
  2070. //var length=Math.abs(currentMesh._boundingInfo.boundingBox.maximumWorld.x-currentMesh._boundingInfo.boundingBox.minimumWorld.x);
  2071. var height=currentMesh.height;
  2072. var length=currentMesh.length;
  2073. params_height.childNodes[1].childNodes[0].value=Math.floor(height);
  2074. params_height.childNodes[1].childNodes[0].alt=Math.floor(height);
  2075. params_length.childNodes[1].childNodes[0].value=Math.floor(length);
  2076. params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
  2077. selectMesh=true;
  2078. setTimeout(function () {
  2079. camera.detachControl(canvas);
  2080. }, 0);
  2081. return;
  2082. }
  2083. selectMesh=true;
  2084. if(currentMesh.name=="selectCircle"||currentMesh.name=="rotator")
  2085. {
  2086. actionRotator=true;
  2087. setTimeout(function () {
  2088. camera.detachControl(canvas);
  2089. }, 0);
  2090. return;
  2091. }
  2092. actionRotator=false;
  2093. if(my3DEngine.meshManager.editProduct)
  2094. {
  2095. if(my3DEngine.meshManager.selectFurnitureMesh!=null&&currentMesh.name.indexOf("arrow")>-1)
  2096. {
  2097. selectArrow();
  2098. }
  2099. else if(currentMesh.name.indexOf("arrow")<0)
  2100. {
  2101. clearArrow();
  2102. closeConfigProduct();
  2103. my3DEngine.meshManager.editProduct=false;
  2104. if(my3DEngine.meshManager.selectFurnitureMesh.name!=currentMesh.name)
  2105. {
  2106. removeSelectMesh();
  2107. my3DEngine.meshManager.selectFurnitureMesh=currentMesh;
  2108. }
  2109. setselectMesh();
  2110. createinfo();
  2111. createArrow=false;
  2112. setVertex(currentMesh._boundingInfo.boundingBox.vectorsWorld,currentMesh._boundingInfo.boundingBox.minimumWorld,currentMesh._boundingInfo.boundingBox.maximumWorld);
  2113. collidables.remove(currentMesh);
  2114. }
  2115. else
  2116. {
  2117. alert("error1729");
  2118. }
  2119. }
  2120. else
  2121. {
  2122. if(typeof(my3DEngine.meshManager.selectFurnitureMesh) != "undefined"&&my3DEngine.meshManager.selectFurnitureMesh!=null)
  2123. {
  2124. if(my3DEngine.meshManager.selectFurnitureMesh.name!=currentMesh.name)
  2125. {
  2126. removeSelectMesh();
  2127. my3DEngine.meshManager.selectFurnitureMesh=currentMesh;
  2128. collidables.remove(currentMesh);
  2129. setselectMesh();
  2130. }
  2131. else
  2132. {
  2133. collidables.remove(currentMesh);
  2134. }
  2135. lastPosition=startingPoint;
  2136. }
  2137. else
  2138. {
  2139. collidables.remove(currentMesh);
  2140. my3DEngine.meshManager.selectFurnitureMesh=currentMesh;
  2141. }
  2142. if(typeof(currentMesh.rotationQuaternion) != "undefined"&&currentMesh.rotationQuaternion!=null)
  2143. {
  2144. //my3DEngine.meshManager.angle=currentMesh.rotationQuaternion.y;
  2145. my3DEngine.meshManager.angle=currentMesh.rotation.y;
  2146. }
  2147. if(info==null)
  2148. {
  2149. if(my3DEngine.meshManager.selectCircle==null)
  2150. {
  2151. setselectMesh();
  2152. }
  2153. else
  2154. {
  2155. my3DEngine.meshManager.selectCircle.position=new BABYLON.Vector3(currentMesh._boundingInfo.boundingBox.center.x,selectCircleY,currentMesh._boundingInfo.boundingBox.center.z);
  2156. }
  2157. createinfo();
  2158. createArrow=false;
  2159. setVertex(currentMesh._boundingInfo.boundingBox.vectorsWorld,currentMesh._boundingInfo.boundingBox.minimumWorld,currentMesh._boundingInfo.boundingBox.maximumWorld);
  2160. }
  2161. else
  2162. {
  2163. info.position= new BABYLON.Vector3(currentMesh.position.x, currentMesh._boundingInfo.boundingBox.maximumWorld.y+15, currentMesh.position.z);
  2164. }
  2165. }
  2166. if (startingPoint) { // we need to disconnect camera from canvas
  2167. setTimeout(function () {
  2168. camera.detachControl(canvas);
  2169. }, 0);
  2170. }
  2171. }
  2172. else
  2173. {
  2174. removeSelectMesh();
  2175. closeConfigProduct();
  2176. }
  2177. }.bind(this);
  2178. var onPointerUp = function () {
  2179. if(this.lock)
  2180. {
  2181. return;
  2182. }
  2183. if (startingPoint) {
  2184. camera.attachControl(canvas, true);
  2185. startingPoint = null;
  2186. if(my3DEngine.meshManager.editProduct)
  2187. {
  2188. finishEditMesh();
  2189. clearMeasureMesh();
  2190. setProductInfo();
  2191. }
  2192. actionRotator=false;
  2193. selectMesh=false;
  2194. return;
  2195. }
  2196. };
  2197. var drawArrow= function( p0, p1,height){
  2198. var _ANGLE = 20;
  2199. var _RADIUS = 10.0;
  2200. var _ANGLE_CROSS = 90.0;
  2201. var result=[];
  2202. var nP = {};
  2203. var angle = Math.atan2(p0.x-p1.x, p0.y-p1.y);
  2204. result.push(new BABYLON.Vector3(p1.x,height,p1.y));
  2205. //rotate by _ANGLE
  2206. var tAngle = angle - _ANGLE * Math.PI/180.0;
  2207. nP.x = parseFloat(p1.x) + _RADIUS * Math.sin(tAngle);
  2208. nP.y = parseFloat(p1.y) + _RADIUS * Math.cos(tAngle);
  2209. result.push(new BABYLON.Vector3(nP.x,height,nP.y));
  2210. //lower part
  2211. tAngle = angle + _ANGLE * Math.PI/180.0;
  2212. nP.x = parseFloat(p1.x) + _RADIUS * Math.sin(tAngle);
  2213. nP.y = parseFloat(p1.y) + _RADIUS * Math.cos(tAngle);
  2214. result.push(new BABYLON.Vector3(p1.x,height,p1.y));
  2215. result.push(new BABYLON.Vector3(nP.x,height,nP.y));
  2216. return result;
  2217. };
  2218. var clearMeasureMesh=function()
  2219. {
  2220. if(measuremesh1!=null)
  2221. {
  2222. measuremesh1.dispose();
  2223. measuremesh1=null;
  2224. }
  2225. if(measuremesh2!=null)
  2226. {
  2227. measuremesh2.dispose();
  2228. measuremesh2=null;
  2229. }
  2230. if(measuremesh3!=null)
  2231. {
  2232. measuremesh3.dispose();
  2233. measuremesh3=null;
  2234. }
  2235. if(measuremesh4!=null)
  2236. {
  2237. measuremesh4.dispose();
  2238. measuremesh4=null;
  2239. }
  2240. if(measuremesh5!=null)
  2241. {
  2242. measuremesh5.dispose();
  2243. measuremesh5=null;
  2244. }
  2245. if(measuremesh6!=null)
  2246. {
  2247. measuremesh6.dispose();
  2248. measuremesh6=null;
  2249. }
  2250. };
  2251. var makeTextPlane = function(text, color,size,position) {
  2252. var dynamicTexture = new BABYLON.DynamicTexture("DynamicTexture", 50, scene, true);
  2253. dynamicTexture.hasAlpha = true;
  2254. var plane = BABYLON.Mesh.CreatePlane("TextPlane", size, scene, true);
  2255. plane.material = new BABYLON.StandardMaterial("TextPlaneMaterial", scene);
  2256. plane.material.backFaceCulling = false;
  2257. plane.material.specularColor = new BABYLON.Color3(0, 0, 0);
  2258. plane.material.diffuseTexture = dynamicTexture;
  2259. plane.position=position;
  2260. dynamicTexture._context.font = "bold 12px Arial";
  2261. var textSize=dynamicTexture._context.measureText(text);
  2262. if(size<textSize.width)
  2263. {
  2264. size=Math.floor(1+textSize.width);
  2265. }
  2266. var x = (size - textSize.width) / 2;
  2267. dynamicTexture.drawText(text, x, 40, "bold 12px Arial", color , "transparent", true);
  2268. return plane;
  2269. };
  2270. /*
  2271. var setPhoPosition=function(angle,pt,position,thice)
  2272. {
  2273. var calculateLine=new CalculateLine();
  2274. var line;
  2275. var b=pt.z-pt.x*(Math.tan(angle));
  2276. if(angle==0)
  2277. {
  2278. line={a:0,y:pt.z};
  2279. }
  2280. else if(angle==Math.PI/2||angle==-1.5*Math.PI)
  2281. {
  2282. line={a:0,x:pt.x};
  2283. }
  2284. else
  2285. {
  2286. line={a:Math.tan(angle),b:b};
  2287. }
  2288. var cross=calculateLine.getJoinLinePoint(position,line);
  2289. cross=new BABYLON.Vector3(cross.x,position.y,cross.y);
  2290. curPicPho.target=new BABYLON.Vector3(cross.x,cross.y,cross.z);
  2291. var diff=position.subtract(cross);
  2292. var distance=BABYLON.Vector2.Distance(new BABYLON.Vector2(cross.x,cross.z),new BABYLON.Vector2(position.x,position.z));
  2293. diff.x=diff.x*thice/distance;
  2294. diff.y=0;
  2295. diff.z=diff.z*thice/distance;
  2296. cross.addInPlace(diff);
  2297. return cross;
  2298. }
  2299. */
  2300. var onPointerMove = function (evt) {
  2301. if(this.lock)
  2302. {
  2303. return;
  2304. }
  2305. if (!startingPoint) {
  2306. return;
  2307. }
  2308. current = getGroundPosition(evt);
  2309. var diff = current.subtract(startingPoint).normalize();
  2310. if (evt.button == 2)
  2311. {
  2312. if(current==null)
  2313. {
  2314. evt.stopPropagation();
  2315. return;
  2316. }
  2317. camera.target.addInPlace(new BABYLON.Vector3(diff.x*5,camera.target.y,diff.z*5));
  2318. startingPoint=current;
  2319. return;
  2320. }
  2321. if(!selectMesh)
  2322. {
  2323. evt.stopPropagation();
  2324. return;
  2325. }
  2326. if(my3DEngine.meshManager.editProduct)
  2327. {
  2328. if(createArrow)
  2329. {
  2330. current=getGroundPositionFromArrow(evt);
  2331. if(currentMesh.name.indexOf("arrow")>-1)
  2332. {
  2333. if(diff.x==0&&diff.z==0)
  2334. {
  2335. return;
  2336. }
  2337. else
  2338. {
  2339. var diff2,diff3;
  2340. var startpoint,endpoint;
  2341. var newpoint=editingMesh(1);
  2342. diff = newpoint.subtract(currentMesh.position);
  2343. templane.position.addInPlace(diff);
  2344. if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow")
  2345. {
  2346. mesh3.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
  2347. mesh4.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
  2348. }
  2349. else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow")
  2350. {
  2351. mesh1.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
  2352. mesh2.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
  2353. }
  2354. currentMesh.position=newpoint;
  2355. my3DEngine.meshManager.selectFurnitureMesh.computeWorldMatrix(true);
  2356. my3DEngine.meshManager.selectFurnitureMesh.refreshBoundingInfo();
  2357. }
  2358. startingPoint = current;
  2359. }
  2360. evt.stopPropagation();
  2361. return;
  2362. }
  2363. evt.stopPropagation();
  2364. return;
  2365. }
  2366. if(actionRotator)
  2367. {
  2368. var angle1=BABYLON.Angle.BetweenTwoPoints(new BABYLON.Vector2(startingPoint.x,startingPoint.z),new BABYLON.Vector2(my3DEngine.meshManager.selectCircle.position.x,my3DEngine.meshManager.selectCircle.position.z));
  2369. var angle2=BABYLON.Angle.BetweenTwoPoints(new BABYLON.Vector2(current.x,current.z),new BABYLON.Vector2(my3DEngine.meshManager.selectCircle.position.x,my3DEngine.meshManager.selectCircle.position.z));
  2370. if(my3DEngine.meshManager.angle==null||typeof(my3DEngine.meshManager.angle)=="undefined")
  2371. {
  2372. my3DEngine.meshManager.angle=angle1._radians-angle2._radians;
  2373. }
  2374. else
  2375. {
  2376. my3DEngine.meshManager.angle+=angle1._radians-angle2._radians;
  2377. }
  2378. my3DEngine.meshManager.selectCircle.rotate(BABYLON.Axis.Y, angle1._radians-angle2._radians, BABYLON.Space.LOCAL);
  2379. my3DEngine.meshManager.selectCircle.rotation.y+=angle1._radians-angle2._radians;
  2380. //if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")!=0&&my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")!=0)
  2381. //{
  2382. my3DEngine.meshManager.selectFurnitureMesh.rotate(BABYLON.Axis.Y, angle1._radians-angle2._radians, BABYLON.Space.LOCAL);
  2383. my3DEngine.meshManager.selectFurnitureMesh.rotation.y+=angle1._radians-angle2._radians;
  2384. my3DEngine.meshManager.angle=my3DEngine.meshManager.selectFurnitureMesh.rotation.y;
  2385. //}
  2386. //console.log("selectFurnitureMesh:"+my3DEngine.meshManager.selectFurnitureMesh.rotation.y+",selectCircle:"+my3DEngine.meshManager.selectCircle.rotation.y);
  2387. startingPoint = current;
  2388. }
  2389. if (!current||!currentMesh) {
  2390. evt.stopPropagation();
  2391. return;
  2392. }
  2393. if((currentMesh.name.indexOf("pho-")==0||currentMesh.name.indexOf("picture-")==0))
  2394. {
  2395. var m_pt=getWallPlanePosition();
  2396. if(m_pt!=null)
  2397. {
  2398. var temp_last=null;
  2399. var temp_pt =new BABYLON.Vector3(currentMesh.position.x,currentMesh.position.y,currentMesh.position.z);
  2400. if(currentMesh.lastPos!=null&&typeof(currentMesh.lastPos) != "undefined")
  2401. {
  2402. temp_last=new BABYLON.Vector3(currentMesh.lastPos.x,currentMesh.lastPos.y,currentMesh.lastPos.z);
  2403. var diff=m_pt.point.subtract(currentMesh.lastPos);
  2404. currentMesh.lastPos=m_pt.point;
  2405. currentMesh.position.addInPlace(diff);
  2406. }
  2407. else
  2408. {
  2409. currentMesh.lastPos=m_pt.point;
  2410. }
  2411. currentMesh.computeWorldMatrix(true);
  2412. currentMesh.refreshBoundingInfo();
  2413. if(currentMesh._boundingInfo.boundingBox.maximumWorld.y>wallHeigh||currentMesh._boundingInfo.boundingBox.minimumWorld.y<0)
  2414. {
  2415. currentMesh.lastPos=temp_last;
  2416. currentMesh.position=temp_pt;
  2417. }
  2418. else
  2419. {
  2420. if(m_pt.index==my3DEngine.phoSet.photoFrameMesh.planeindex)
  2421. {
  2422. for(var i=0;i<collidables.length;++i)
  2423. {
  2424. if(i==my3DEngine.phoSet.photoFrameMesh.planeindex)
  2425. {
  2426. continue;
  2427. }
  2428. if(collidables[i].intersectsMesh(currentMesh, true))
  2429. {
  2430. currentMesh.lastPos=temp_last;
  2431. currentMesh.position=temp_pt;
  2432. break;
  2433. }
  2434. }
  2435. }
  2436. else
  2437. {
  2438. var temprotation=currentMesh.rotation.y;
  2439. currentMesh.rotation.y=collidables[m_pt.index].rotation.y;
  2440. if(collidables[my3DEngine.phoSet.photoFrameMesh.planeindex].intersectsMesh(currentMesh, true))
  2441. {
  2442. currentMesh.lastPos=temp_last;
  2443. currentMesh.position=temp_pt;
  2444. currentMesh.rotation.y=temprotation;
  2445. }
  2446. else
  2447. {
  2448. currentMesh.computeWorldMatrix(true);
  2449. currentMesh.refreshBoundingInfo();
  2450. var pos=currentMesh.position;
  2451. var join=calculateLine.getJoinLinePoint({x:pos.x,y:pos.z},calculateLine.createLine(collidables[m_pt.index].pts.point1, collidables[m_pt.index].pts.point2));
  2452. join=new BABYLON.Vector3(join.x,pos.y,join.y);
  2453. var diffplane=join.subtract(pos);
  2454. var add=0;
  2455. while(!collidables[m_pt.index].intersectsMesh(currentMesh, true))
  2456. {
  2457. pos.addInPlace(new BABYLON.Vector3(diffplane.x*0.1,diffplane.y*0.1,diffplane.z*0.1));
  2458. ++add;
  2459. if(add>19)
  2460. {
  2461. //alert(2851);
  2462. break;
  2463. }
  2464. currentMesh.position=pos;
  2465. currentMesh.computeWorldMatrix(true);
  2466. currentMesh.refreshBoundingInfo();
  2467. }
  2468. var fontpt=currentMesh._boundingInfo.boundingBox.vectorsWorld[currentMesh.frontindex];
  2469. var toward2=calculateLine.getToward(collidables[m_pt.index].pts.point1,collidables[m_pt.index].pts.point2,{x:fontpt.x,y:fontpt.z});
  2470. if(collidables[m_pt.index].toward!=toward2)
  2471. {
  2472. currentMesh.rotation.y+=Math.PI;
  2473. }
  2474. if(currentMesh.rotation.y>=2*Math.PI)
  2475. {
  2476. currentMesh.rotation.y-=2*Math.PI;
  2477. }
  2478. my3DEngine.phoSet.photoFrameMesh.planeindex=m_pt.index;
  2479. }
  2480. }
  2481. }
  2482. }
  2483. }
  2484. else
  2485. {
  2486. if(currentMesh.name!="selectCircle"&&currentMesh.name!="rotator")
  2487. {
  2488. currentMesh.position = new BABYLON.Vector3(current.x, currentMesh.position.y, current.z);
  2489. }
  2490. if(BABYLON.Vector2.Distance(new BABYLON.Vector2(startingPoint.x,startingPoint.z),new BABYLON.Vector2(current.x,current.z))>2)
  2491. {
  2492. actionmove=true;
  2493. }
  2494. //actionmove=true;
  2495. if(info!=null)
  2496. {
  2497. info.position= new BABYLON.Vector3(my3DEngine.meshManager.selectFurnitureMesh.position.x, my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.maximumWorld.y+30, my3DEngine.meshManager.selectFurnitureMesh.position.z);
  2498. }
  2499. currentMesh.computeWorldMatrix(true);
  2500. currentMesh.refreshBoundingInfo();
  2501. if(my3DEngine.meshManager.selectCircle!=null)
  2502. {
  2503. //my3DEngine.meshManager.selectCircle.position=new BABYLON.Vector3(my3DEngine.meshManager.selectFurnitureMesh.position.x,selectCircleY,my3DEngine.meshManager.selectFurnitureMesh.position.z);
  2504. my3DEngine.meshManager.selectCircle.position.x=my3DEngine.meshManager.selectFurnitureMesh.position.x;
  2505. my3DEngine.meshManager.selectCircle.position.z=my3DEngine.meshManager.selectFurnitureMesh.position.z;
  2506. }
  2507. var flag=true;
  2508. var meshindex=-1;
  2509. if(firstMeshes.length>0)
  2510. {
  2511. for(var i=0;i<firstMeshes.length;++i)
  2512. {
  2513. if(firstMeshes[i]==currentMesh.name)
  2514. {
  2515. meshindex=i;
  2516. break;
  2517. }
  2518. }
  2519. }
  2520. for(var i=0;i<collidables.length;++i)
  2521. {
  2522. if (typeof(collidables[i]) == "undefined") {
  2523. collidables.remove(collidables[i]);
  2524. --i;
  2525. continue;
  2526. }
  2527. if (currentMesh.intersectsMesh(collidables[i], true))
  2528. {
  2529. if(currentMesh._boundingInfo.boundingBox.minimumWorld.y>collidables[i]._boundingInfo.boundingBox.maximumWorld.y&&currentMesh._boundingInfo.boundingBox.maximumWorld<collidables[i]._boundingInfo.boundingBox.minimumWorld)
  2530. {
  2531. break;
  2532. }
  2533. else if(currentMesh.name=="mirror")
  2534. {
  2535. break;
  2536. }
  2537. //console.log("2762");
  2538. var m_flag=false;
  2539. for(var j=0;j<firstMeshes.length;++j)
  2540. {
  2541. if(collidables[i].name==firstMeshes[j])
  2542. {
  2543. m_flag=true;
  2544. break;
  2545. }
  2546. }
  2547. if(m_flag)
  2548. {
  2549. continue;
  2550. }
  2551. flag=false;
  2552. break;
  2553. }
  2554. }
  2555. if(flag)
  2556. {
  2557. lastPosition=currentMesh.position;
  2558. if(meshindex!=-1)
  2559. {
  2560. firstMeshes.splice(meshindex, 1);
  2561. }
  2562. }
  2563. else
  2564. {
  2565. if(meshindex==-1)
  2566. {
  2567. currentMesh.position = new BABYLON.Vector3(lastPosition.x, lastPosition.y, lastPosition.z);
  2568. if(info!=null)
  2569. {
  2570. info.position= new BABYLON.Vector3(my3DEngine.meshManager.selectFurnitureMesh.position.x, 0, my3DEngine.meshManager.selectFurnitureMesh.position.z);
  2571. }
  2572. if(my3DEngine.meshManager.selectCircle!=null)
  2573. {
  2574. my3DEngine.meshManager.selectCircle.position.x=my3DEngine.meshManager.selectFurnitureMesh.position.x;
  2575. my3DEngine.meshManager.selectCircle.position.z=my3DEngine.meshManager.selectFurnitureMesh.position.z;
  2576. }
  2577. flag=true;
  2578. }
  2579. else
  2580. {
  2581. lastPosition=currentMesh.position;
  2582. }
  2583. }
  2584. }
  2585. evt.stopPropagation();
  2586. };
  2587. //针对相框、壁纸
  2588. var createArrows2=function(currentMesh,scene,imagearrow)
  2589. {
  2590. min=currentMesh._boundingInfo.boundingBox.minimumWorld;
  2591. max=currentMesh._boundingInfo.boundingBox.maximumWorld;
  2592. var center=currentMesh._boundingInfo.boundingBox.center;
  2593. var points=[];
  2594. points[0]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[0]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[0]].z};
  2595. points[1]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[1]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[1]].z};
  2596. points[2]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[2]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[2]].z};
  2597. points[3]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[3]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[3]].z};
  2598. var down =new BABYLON.Vector3((points[0].x+points[3].x)/2,center.y,(points[0].y+points[3].y)/2);
  2599. var top =new BABYLON.Vector3((points[1].x+points[2].x)/2,center.y,(points[1].y+points[2].y)/2);
  2600. var left =new BABYLON.Vector3((points[1].x+points[0].x)/2,center.y,(points[1].y+points[0].y)/2);
  2601. var right=new BABYLON.Vector3((points[2].x+points[3].x)/2,center.y,(points[2].y+points[3].y)/2);
  2602. arrowdown =new BABYLON.Vector3(down.x ,down.y,down.z);
  2603. arrowtop =new BABYLON.Vector3(top.x ,top.y,top.z);
  2604. arrowleft =new BABYLON.Vector3(left.x ,left.y,left.z);
  2605. arrowright=new BABYLON.Vector3(right.x,right.y,right.z);
  2606. down=arrowdown.add(new BABYLON.Vector3(0,0,-interval));
  2607. top=arrowtop.add(new BABYLON.Vector3(0,0,interval));
  2608. left=arrowleft.add(new BABYLON.Vector3(-interval,0,0));
  2609. right=arrowright.add(new BABYLON.Vector3(interval,0,0));
  2610. down =new BABYLON.Vector2(down.x ,down.z);
  2611. top =new BABYLON.Vector2(top.x ,top.z);
  2612. left =new BABYLON.Vector2(left.x ,left.z);
  2613. right=new BABYLON.Vector2(right.x,right.z);
  2614. var arrowtexture = new BABYLON.Texture('data:my_image_name1', scene, true,
  2615. true, BABYLON.Texture.BILINEAR_SAMPLINGMODE,
  2616. null, null, imagearrow, true);
  2617. mesh1=BABYLON.Mesh.CreateCylinder("arrow1", 0.00001, 24, 24, 64, 12, scene, false);
  2618. mesh1.material =new BABYLON.StandardMaterial('newMaterial', scene);
  2619. mesh1.material.diffuseTexture = arrowtexture;
  2620. mesh1.position= new BABYLON.Vector3(down.x, infoheigh, down.y);
  2621. mesh1.rotation.y=-Math.PI/2;
  2622. mesh1.rotation.z=Math.PI;
  2623. mesh1.name="downarrow";
  2624. mesh2=mesh1.clone();
  2625. mesh2.position= new BABYLON.Vector3(top.x, infoheigh, top.y);
  2626. mesh2.rotation.y=-3*Math.PI/2;
  2627. mesh2.rotation.z=Math.PI;
  2628. mesh2.name="toparrow";
  2629. mesh3=mesh1.clone();
  2630. mesh3.position= new BABYLON.Vector3(left.x, infoheigh, left.y);
  2631. mesh3.rotation.y=0;
  2632. mesh3.rotation.z=Math.PI;
  2633. mesh3.name="leftarrow";
  2634. mesh4=mesh1.clone();
  2635. mesh4.position= new BABYLON.Vector3(right.x, infoheigh, right.y);
  2636. var angle4=BABYLON.Angle.BetweenTwoPoints(right,left);
  2637. mesh4.rotation.y=-Math.PI;
  2638. mesh4.rotation.z=Math.PI;
  2639. mesh4.name="rightarrow";
  2640. line1={x:down.x};
  2641. line2={y:left.y};
  2642. my3DEngine.meshManager.arrowMeshes[0]=mesh1;
  2643. my3DEngine.meshManager.arrowMeshes[1]=mesh2;
  2644. my3DEngine.meshManager.arrowMeshes[2]=mesh3;
  2645. my3DEngine.meshManager.arrowMeshes[3]=mesh4;
  2646. };
  2647. var createArrows=function(currentMesh,scene,imagearrow)
  2648. {
  2649. min=currentMesh._boundingInfo.boundingBox.minimumWorld;
  2650. max=currentMesh._boundingInfo.boundingBox.maximumWorld;
  2651. //heigh=Math.abs(max.z-min.z);
  2652. //length=Math.abs(max.x-min.x);
  2653. var center=currentMesh._boundingInfo.boundingBox.center;
  2654. var points=[];
  2655. points[0]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[0]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[0]].z};
  2656. points[1]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[1]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[1]].z};
  2657. points[2]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[2]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[2]].z};
  2658. points[3]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[3]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[3]].z};
  2659. var down =new BABYLON.Vector3((points[0].x+points[3].x)/2,center.y,(points[0].y+points[3].y)/2);
  2660. var top =new BABYLON.Vector3((points[1].x+points[2].x)/2,center.y,(points[1].y+points[2].y)/2);
  2661. var left =new BABYLON.Vector3((points[1].x+points[0].x)/2,center.y,(points[1].y+points[0].y)/2);
  2662. var right=new BABYLON.Vector3((points[2].x+points[3].x)/2,center.y,(points[2].y+points[3].y)/2);
  2663. arrowdown =new BABYLON.Vector3(down.x ,down.y,down.z);
  2664. arrowtop =new BABYLON.Vector3(top.x ,top.y,top.z);
  2665. arrowleft =new BABYLON.Vector3(left.x ,left.y,left.z);
  2666. arrowright=new BABYLON.Vector3(right.x,right.y,right.z);
  2667. down =new BABYLON.Vector2(down.x ,down.z);
  2668. top =new BABYLON.Vector2(top.x ,top.z);
  2669. left =new BABYLON.Vector2(left.x ,left.z);
  2670. right=new BABYLON.Vector2(right.x,right.z);
  2671. var d1=BABYLON.Vector2.Distance(down,new BABYLON.Vector2(center.x,center.z));
  2672. var diff1=arrowdown.subtract(center);
  2673. //down=arrowdown.addInPlace(diff1);
  2674. down=arrowdown.add(new BABYLON.Vector3(diff1.x/d1*interval,0,diff1.z/d1*interval));
  2675. var d2=BABYLON.Vector2.Distance(top,new BABYLON.Vector2(center.x,center.z));
  2676. var diff2=arrowtop.subtract(center);
  2677. //top=arrowtop.addInPlace(diff2);
  2678. //top.addInPlace(diff2);
  2679. top=arrowtop.add(new BABYLON.Vector3(diff2.x/d2*interval,0,diff2.z/d2*interval));
  2680. var d3=BABYLON.Vector2.Distance(left,new BABYLON.Vector2(center.x,center.z));
  2681. var diff3=arrowleft.subtract(center);
  2682. //left=arrowleft.addInPlace(diff3);
  2683. //left.addInPlace(diff3);
  2684. left=arrowleft.add(new BABYLON.Vector3(diff3.x/d3*interval,0,diff3.z/d3*interval));
  2685. var d4=BABYLON.Vector2.Distance(right,new BABYLON.Vector2(center.x,center.z));
  2686. var diff4=arrowright.subtract(center);
  2687. //right=arrowright.addInPlace(diff4);
  2688. //right.addInPlace(diff4);
  2689. right=arrowright.add(new BABYLON.Vector3(diff4.x/d4*interval,0,diff4.z/d4*interval));
  2690. down =new BABYLON.Vector2(down.x ,down.z);
  2691. top =new BABYLON.Vector2(top.x ,top.z);
  2692. left =new BABYLON.Vector2(left.x ,left.z);
  2693. right=new BABYLON.Vector2(right.x,right.z);
  2694. var arrowtexture = new BABYLON.Texture('data:my_image_name1', scene, true,
  2695. true, BABYLON.Texture.BILINEAR_SAMPLINGMODE,
  2696. null, null, imagearrow, true);
  2697. mesh1=BABYLON.Mesh.CreateCylinder("arrow1", 0.00001, 24, 24, 64, 12, scene, false);
  2698. mesh1.material =new BABYLON.StandardMaterial('newMaterial', scene);
  2699. mesh1.material.diffuseTexture = arrowtexture;
  2700. mesh1.position= new BABYLON.Vector3(down.x, infoheigh, down.y);
  2701. var angle1=BABYLON.Angle.BetweenTwoPoints(down,top);
  2702. mesh1.rotation.y=-angle1._radians;
  2703. mesh1.rotation.z=Math.PI;
  2704. mesh1.name="downarrow";
  2705. mesh2=mesh1.clone();
  2706. mesh2.position= new BABYLON.Vector3(top.x, infoheigh, top.y);
  2707. var angle2=BABYLON.Angle.BetweenTwoPoints(top,down);
  2708. mesh2.rotation.y=-angle2._radians;
  2709. mesh2.rotation.z=Math.PI;
  2710. mesh2.name="toparrow";
  2711. mesh3=mesh1.clone();
  2712. mesh3.position= new BABYLON.Vector3(left.x, infoheigh, left.y);
  2713. var angle3=BABYLON.Angle.BetweenTwoPoints(left,right);
  2714. mesh3.rotation.y=-angle3._radians;
  2715. mesh3.rotation.z=Math.PI;
  2716. mesh3.name="leftarrow";
  2717. mesh4=mesh1.clone();
  2718. mesh4.position= new BABYLON.Vector3(right.x, infoheigh, right.y);
  2719. var angle4=BABYLON.Angle.BetweenTwoPoints(right,left);
  2720. mesh4.rotation.y=-angle4._radians;
  2721. mesh4.rotation.z=Math.PI;
  2722. mesh4.name="rightarrow";
  2723. line1=calculateLine.createLine(down,top);
  2724. line2=calculateLine.createLine(left,right);
  2725. my3DEngine.meshManager.arrowMeshes[0]=mesh1;
  2726. my3DEngine.meshManager.arrowMeshes[1]=mesh2;
  2727. my3DEngine.meshManager.arrowMeshes[2]=mesh3;
  2728. my3DEngine.meshManager.arrowMeshes[3]=mesh4;
  2729. };
  2730. var clearArrow=function()
  2731. {
  2732. //if(typeof(mesh1) != "undefined"&&!mesh1._isDisposed)
  2733. if(typeof(mesh1) != "undefined")
  2734. {
  2735. mesh1.dispose();
  2736. }
  2737. if(typeof(mesh2) != "undefined")
  2738. {
  2739. mesh2.dispose();
  2740. }
  2741. if(typeof(mesh3) != "undefined")
  2742. {
  2743. mesh3.dispose();
  2744. }
  2745. if(typeof(mesh4) != "undefined")
  2746. {
  2747. mesh4.dispose();
  2748. }
  2749. createArrow=false;
  2750. };
  2751. var onCameraWheel=function(e)
  2752. {
  2753. var type=e.type;
  2754. var delta;
  2755. if (type == 'DOMMouseScroll' || type == 'mousewheel') {
  2756. delta = (e.wheelDelta) ? (e.wheelDelta / 120)*2 : -(e.detail || 0) / 3*2;
  2757. }
  2758. var mark=document.getElementById("mark");
  2759. var markpy=parseInt(mark.style.marginTop);
  2760. markpy-=delta;
  2761. if(markpy<MixMark)
  2762. {
  2763. markpy=MixMark;
  2764. }
  2765. else if(markpy>MaxMark)
  2766. {
  2767. markpy=MaxMark;
  2768. }
  2769. mark.style.marginTop=markpy+"px";
  2770. };
  2771. canvas.addEventListener("mousedown", onPointerDown, false);
  2772. canvas.addEventListener("mouseup", onPointerUp, false);
  2773. canvas.addEventListener("mousemove", onPointerMove, false);
  2774. canvas.addEventListener("mousewheel", onCameraWheel,false);
  2775. scene.onDispose = function () {
  2776. canvas.removeEventListener("mousedown", onPointerDown);
  2777. canvas.removeEventListener("mouseup", onPointerUp);
  2778. canvas.removeEventListener("mousemove", onPointerMove);
  2779. canvas.removeEventListener("mousewheel", onCameraWheel);
  2780. };
  2781. };