Symbol3D.js 121 KB

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