备份.js 108 KB

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