1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610 |
- function Symbol3D()
- {
- this.canvas;
- this.engine;
- this.scene;
- this.camera;
- this.light;
- this.groundY=-10;
- this.tiledGround;
- this.ground;
- this.skybox;
- this.lock=false;
- this.roomWallMeshes=[];
- this.groundLength=6000;
- this.groundWidth=6000;
- this.doorBottom=60;
- this.windowBottom=100;
- this.doorHeigh=100;
- this.windowHeigh=50;
- this.doorThick=34;
- this.wallHeigh=150;
- this.wallThick=30;
- this.boardThick=15;
- this.baseSymbolThick;
- this.groundMaterial;
- this.skyboxMaterial;
- this.wallmaterial;
- this.floormaterial;
- this.frameMaterial;
- this.doorknobMaterial;
- this.windowframeMaterial;
- this.groundTexture="images/checkerboard.jpg";
- //this.floorStyle={floorTexture:"images/textures/floor/floor0.jpg",floorColor:null,type:0};
- this.floorStyle={floorTexture:"images/textures/floor/floor0.jpg",floorColor:null};
- this.wallTexture=null;
- this.skyTexture="images/textures/skyboxes/sky0";
- this.wallpicture_pre="images/textures/picture/";
- this.meshManager={collidables:[],firstMeshes:[],arrowMeshes:[],glassBoxMeshes:[],selectFurnitureMesh:null,selectMesh:false,editProduct:false,infoSize:15,furnitureScal:0.2,selectCircle:null,rotator:null,angle:0};
- this.paintPlane={id:null,value:null,beginPaint:false,currentId:null};
- this.paintWall={value:null,beginPaint:false};
- this.paintSet=[];
- this.wallSet={submeshes:[],subMaterials:[],verticesStart:0,indexStart:0};
- this.phoSet={start:false,photoFrameMesh:null,phochild:null,pts:null};
-
- };
- Symbol3D.prototype.setwallmaterial = function () {
-
-
- this.wallmaterial = new BABYLON.StandardMaterial("wallmaterial", this.scene);
- //this.wallmaterial.emissiveColor = new BABYLON.Color3(0.8,0.8,0.8);
- this.wallmaterial.backFaceCulling = false;
- this.wallmaterial.diffuseColor = new BABYLON.Color3(0.5,0.5,0.5);
- this.wallmaterial.specularColor = new BABYLON.Color3(.6,.6,.6);
- this.wallmaterial.useSpecularOverAlpha=false;
-
- /*
- this.wallmaterial = new BABYLON.PBRMaterial("p", this.scene);
- this.wallmaterial.reflectionColor = new BABYLON.Color3(0.5,0.5,0.5);
- this.wallmaterial.albedoColor = new BABYLON.Color3(0.5,0.5,0.5);
- this.wallmaterial.reflectivityColor = new BABYLON.Color3(0.15,0.15,0.15);
- this.wallmaterial.bumpTexture = new BABYLON.Texture("images/textures/bump2.jpg", this.scene);
- */
- };
- Symbol3D.prototype.getwallmaterial = function (id) {
- var wallmaterial = new BABYLON.StandardMaterial("wall"+id, this.scene);
- //wallmaterial.emissiveColor = new BABYLON.Color3(0.8,0.8,0.8);
- wallmaterial.diffuseColor = new BABYLON.Color3(0.5,0.5,0.5);
- wallmaterial.specularColor = new BABYLON.Color3(.6,.6,.6);
- wallmaterial.useSpecularOverAlpha=false;
- wallmaterial.backFaceCulling = false;
- return wallmaterial;
- };
- Symbol3D.prototype.setgroundmaterial= function ()
- {
- this.groundMaterial = new BABYLON.StandardMaterial("groundmaterial", this.scene);
- this.groundMaterial.diffuseTexture = new BABYLON.Texture(this.groundTexture, this.scene);
- this.groundMaterial.diffuseTexture.uScale = 5.0; //Repeat 5 times on the Vertical Axes
- this.groundMaterial.diffuseTexture.vScale = 5.0; //Repeat 5 times on the Horizont
- };
- Symbol3D.prototype.setskyboxMaterial= function ()
- {
- this.skyboxMaterial = new BABYLON.StandardMaterial("skyBox", this.scene);
- this.skyboxMaterial.backFaceCulling = false;
- this.skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture(this.skyTexture, this.scene);
- this.skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
- this.skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
- this.skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
- this.skyboxMaterial.disableLighting = true;
- };
- Symbol3D.prototype.setframeMaterial= function ()
- {
- this.frameMaterial = new BABYLON.StandardMaterial("frameMaterial", this.scene);
- this.frameMaterial.alpha = 1.0;
- this.frameMaterial.emissiveColor = new BABYLON.Color3(0.7,0.7,0.7);
- this.frameMaterial.backFaceCulling = true;
- };
- Symbol3D.prototype.setwindowframeMaterial= function ()
- {
- this.windowframeMaterial = new BABYLON.StandardMaterial("windowframeMaterial", this.scene);
- this.windowframeMaterial.alpha = 1.0;
- this.windowframeMaterial.emissiveColor = new BABYLON.Color3(0.5,0.5,0.5);
- this.windowframeMaterial.backFaceCulling = true;
- };
- Symbol3D.prototype.setdoorknobMaterial= function ()
- {
- this.doorknobMaterial = new BABYLON.StandardMaterial("doorknobMaterial", this.scene);
- this.doorknobMaterial.alpha = 1.0;
- this.doorknobMaterial.emissiveColor = new BABYLON.Color3(0.1,0.1,0.1);
- this.doorknobMaterial.backFaceCulling = true;
- };
- Symbol3D.prototype.setdoormaterial= function ()
- {
- this.doormaterial = new BABYLON.StandardMaterial("doormaterial", this.scene);
- this.doormaterial.diffuseTexture = new BABYLON.Texture("images/door.png", this.scene);
- this.doormaterial.backFaceCulling = false;
- };
- Symbol3D.prototype.setfloormaterial = function ()
- {
- this.floormaterial = new BABYLON.StandardMaterial("floormaterial", this.scene);
- /*
- if(this.floorStyle.type==0)
- {
- this.floormaterial.diffuseTexture = new BABYLON.Texture(this.floorStyle.floorTexture, this.scene);
- }
- else
- {
- this.floormaterial.diffuseTexture = new BABYLON.Texture(this.floorStyle.floorColor, this.scene);
- }
- */
- this.floormaterial.diffuseTexture = new BABYLON.Texture(this.floorStyle.floorTexture, this.scene);
- this.floormaterial.bumpTexture = new BABYLON.Texture("images/floor1.png", this.scene);
- this.floormaterial.specularColor=new BABYLON.Color3(0.2,0.2,0.2);
- };
- Symbol3D.prototype.setLights = function (){
-
- /*
- // Add a light
- this.light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(600, 600, 0), this.scene);
- this.light.diffuse = new BABYLON.Color3(1, 1, 1);
- this.light.specular = new BABYLON.Color3(0, 0, 0);
- this.light.position = new BABYLON.Vector3(250, 400, 0);
- this.light.intensity = 1.8;
- */
- var DLight1 = new BABYLON.DirectionalLight("dl", new BABYLON.Vector3(1,-1,1), this.scene);
- //DLight1.specular=new BABYLON.Color3(2, 2, 2);
- var DLight2 = new BABYLON.DirectionalLight("dl", new BABYLON.Vector3(-1,-1,1), this.scene);
- //DLight2.specular=new BABYLON.Color3(2, 2, 2);
- 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)
-
- /*
- var light0 = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(1.9,3.2,4.5), this.scene);
- //light0.diffuse = new BABYLON.Color3(1, 0, 0);
- //light0.specular = new BABYLON.Color3(1, 1, 1);
- light0.intensity = 3.3;
- */
-
- /*
- var light1 = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(600, 600, 0), this.scene);
- light1.diffuse = new BABYLON.Color3(1, 1, 1);
- light1.specular = new BABYLON.Color3(0.3, 0.3, 0.3);
- light1.position = new BABYLON.Vector3(250, 400, 0);
- light1.intensity = 2;
- */
- /*
- var light1 = new BABYLON.PointLight("Omni1", new BABYLON.Vector3(8.6,13.4,-0.9), this.scene);
- //light1.diffuse = new BABYLON.Color3(1, 0, 0);
- //light1.specular = new BABYLON.Color3(1, 1, 1);
- light1.intensity = 8.4;
- var light2 = new BABYLON.PointLight("Omni2", new BABYLON.Vector3(-3.5,-6.9,7.2), this.scene);
- //light2.diffuse = new BABYLON.Color3(1, 0, 0);
- //light2.specular = new BABYLON.Color3(1, 1, 1);
- light2.intensity = 7.3;
- */
- }
- Symbol3D.prototype.setCamera = function () {
- // Create a rotating camera
-
- this.camera = new BABYLON.ArcRotateCamera("Camera", -Math.PI/2, 0, 1000, BABYLON.Vector3.Zero(), this.scene);
- this.camera.attachControl(this.canvas, true);
- this.camera.lowerBetaLimit = 0.1;
- this.camera.upperBetaLimit = (Math.PI / 2) * 0.99;
- this.camera.lowerRadiusLimit = 125;
- this.camera.checkCollisions = true;
-
- //this.camera = new BABYLON.ArcRotateCamera("Camera", 0.4, 1.2, 20, new BABYLON.Vector3(-10, 0, 0), this.scene);
- };
- Symbol3D.prototype.setFreeCamera=function()
- {
- var followCam = new BABYLON.FollowCamera("fcam", this.camera.position, this.scene);
- //this.followCam.target = mesh;
- followCam.radius = 200;
- followCam.maxCameraSpeed = 10;
- //this.scene.activeCamera = followCam;
- return followCam;
- };
- Symbol3D.prototype.setProductCamera = function (position) {
- // Create a rotating camera
- this.camera.setTarget=position;
- };
- Symbol3D.prototype.createScene = function () {
- // Attach it to handle user inputs (keyboard, mouse, touch)
- this.canvas=document.getElementById('canvas3d');
- this.engine = new BABYLON.Engine(this.canvas, true);
- this.scene = new BABYLON.Scene(this.engine);
- this.setCamera();
- this.setLights();
- //this.light = new BABYLON.SpotLight("Spot0", new BABYLON.Vector3(0, 1000, -10), new BABYLON.Vector3(0, -10, 0), 0.8, 2, this.scene);
- //this.light.diffuse = new BABYLON.Color3(1, 0, 0);
- //this.light.specular = new BABYLON.Color3(1, 1, 1);
-
- //Create a light
- //this.light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(5,200,20), this.scene);
-
- };
- Symbol3D.prototype.addSkybox = function ()
- {
- this.skybox = BABYLON.Mesh.CreateBox("skyBox", 8000, this.scene);
- this.setskyboxMaterial();
- this.skybox.material = this.skyboxMaterial;
- };
- Symbol3D.prototype.refreshSkybox = function () {
- this.setskyboxMaterial();
- this.skybox.material = this.skyboxMaterial;
- };
- Symbol3D.prototype.addGround = function () {
- // make a ground
- this.ground = BABYLON.Mesh.CreateBox("Ground", 1, this.scene);
- this.ground.scaling = new BABYLON.Vector3(this.groundLength, 10, this.groundWidth);
- this.ground.position.y =this.groundY/2
- this.ground.checkCollisions = true;
- this.ground.material = this.groundMaterial;
- };
- Symbol3D.prototype.refreshGround = function () {
-
- this.setgroundmaterial();
- this.ground.material = this.groundMaterial;
- };
- Symbol3D.prototype.drawFloor= function(points,id)
- {
- var shape;
- for(var i=0;i<points.length;++i)
- {
- if(i==0)
- {
- shape = new BABYLON.Path2(points[i].x, points[i].y);
- }
- else
- {
- shape.addLineTo(points[i].x, points[i].y);
- }
- }
-
- var floorPlane = new BABYLON.PolygonMeshBuilder("floorPlane"+this.paintPlane.id, shape, this.scene).build();
- floorPlane.wallid="wall"+id;
- floorPlane.position.y =3;
-
- var flag=false;
- for(var i=0;i<this.paintSet.length;++i)
- {
- if(this.paintSet[i].type=="floor"&&this.paintSet[i].wallId=="wall"+id)
- {
- floorPlane.material=this.paintSet[i].material;
- floorPlane.floorId=this.paintPlane.id;
- flag=true;
- break;
- }
- }
- if(!flag)
- {
- floorPlane.material=this.floormaterial;
- floorPlane.material.hasAlpha=10;
- }
-
- ++this.paintPlane.id;
- this.roomWallMeshes.push(floorPlane);
- return floorPlane;
- };
- Symbol3D.prototype.refreshFloor = function (wallid)
- {
- if(this.paintPlane.currentId!=null)
- {
- var floormaterial = new BABYLON.StandardMaterial("floormaterial", this.scene);
- floormaterial.diffuseTexture = new BABYLON.Texture(this.floorStyle.value, this.scene);
- floormaterial.bumpTexture = new BABYLON.Texture("images/floor1.png", this.scene);
- this.scene.getMeshByID(this.paintPlane.currentId).material=floormaterial;
-
- var flag=false;
- for(var i=0;i<this.paintSet.length;++i)
- {
- if(this.paintSet[i].type=="floor"&&this.paintSet[i].floorId==this.paintPlane.currentId)
- {
- this.paintSet[i].material=floormaterial;
- flag=true;
- break;
- }
- }
- if(!flag)
- {
- this.paintSet.push({wallId:wallid,floorId:this.paintPlane.currentId,material:floormaterial,type:"floor"});
- }
-
- document.getElementById("container3d").style.cursor="default";
- }
- };
- Symbol3D.prototype.getLen = function (type) {
- if(type=="Symbol2D_OpeningWindow")
- {
- return layer.parameter.windowLength[0];
- }
- else if(type=="Symbol2D_OpeningDoor")
- {
- return layer.parameter.doorLength[0];
- }
- else if(type=="Symbol2D_SimpleDoor")
- {
- return layer.parameter.doorLength[1];
- }
- else if(type=="Symbol2D_SingleCasement")
- {
- return layer.parameter.windowLength[1];
- }
- else if(type=="Symbol2D_SlidingDoor")
- {
- return layer.parameter.doorLength[2];
- }
- else if(type=="Symbol2D_SlidingWindow")
- {
- return layer.parameter.windowLength[2];
- }
- else
- {
- return 60;
- }
- };
- Symbol3D.prototype.drawOpenWallSymbols=function(points,symbols,type,id)
- {
- var wallmeshes = [];
- var topWallmeshes=[];
- var pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8;
-
- this.wallSet.submeshes=[];
- this.wallSet.verticesStart=0;
- this.wallSet.indexStart=0;
- this.wallSet.subMaterials=[];
-
- var outpoints=points.side1;
- var inpoints=points.side2;
-
- var calculateLine=layer.calculateLine;
- //var calculateLine=new CalculateLine();
- var towards=[];
- var points=[];
- var collindex=[];
-
- for(var i=0;i<outpoints.length-1;++i)
- {
- pt1=new BABYLON.Vector3(outpoints[i].x, 0, outpoints[i].y);
- pt2=new BABYLON.Vector3(outpoints[i+1].x, 0, outpoints[i+1].y);
- var mesh=this.drawSideWall(pt1,pt2);
-
- pt3=inpoints[i];
- pt4=inpoints[i+1];
- var toward= calculateLine.getToward2(outpoints[i],outpoints[i+1],inpoints[i],inpoints[i+1]);
- towards.push(toward);
- this.meshManager.collidables[this.meshManager.collidables.length-1].toward=toward;
- points.push({point1:outpoints[i],point2:outpoints[i+1]});
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- pt5=new BABYLON.Vector3(inpoints[i].x, this.wallHeigh, inpoints[i].y);
- pt6=new BABYLON.Vector3(inpoints[i+1].x, this.wallHeigh, inpoints[i+1].y);
- pt7=new BABYLON.Vector3(outpoints[i].x, this.wallHeigh, outpoints[i].y);
- pt8=new BABYLON.Vector3(outpoints[i+1].x, this.wallHeigh, outpoints[i+1].y);
- mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
- mesh.material=this.wallmaterial;
- topWallmeshes.push(mesh);
- }
-
- pt1=new BABYLON.Vector3(outpoints[outpoints.length-1].x, 0, outpoints[outpoints.length-1].y);
- pt2=new BABYLON.Vector3(inpoints[outpoints.length-1].x, 0, inpoints[outpoints.length-1].y);
- var mesh=this.drawSideWall(pt1,pt2);
- var toward=calculateLine.getToward(outpoints[outpoints.length-1],inpoints[outpoints.length-1],outpoints[outpoints.length-2]);
- towards.push(-1*toward);
- this.meshManager.collidables[this.meshManager.collidables.length-1].toward=-1*toward;
- points.push({point1:outpoints[outpoints.length-1],point2:inpoints[outpoints.length-1]});
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- var num=wallmeshes.length-2;
- for(var i=inpoints.length-1;i>0;--i)
- {
- pt1=new BABYLON.Vector3(inpoints[i].x, 0, inpoints[i].y);
- pt2=new BABYLON.Vector3(inpoints[i-1].x, 0, inpoints[i-1].y);
- var toward=-1*towards[num];
- var mesh=this.drawSideWall(pt1,pt2);
- //mesh.toward=toward;
- towards.push(toward);
- this.meshManager.collidables[this.meshManager.collidables.length-1].toward=toward;
- points.push({point1:inpoints[i],point2:inpoints[i-1]});
- --num;
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
- }
-
- pt1=new BABYLON.Vector3(inpoints[0].x, 0, inpoints[0].y);
- pt2=new BABYLON.Vector3(outpoints[0].x, 0, outpoints[0].y);
- var mesh=this.drawSideWall(pt1,pt2);
- toward=calculateLine.getToward(inpoints[0],outpoints[0],outpoints[1]);
- towards.push(-1*toward);
- this.meshManager.collidables[this.meshManager.collidables.length-1].toward=-1*toward;
- points.push({point1:inpoints[0],point2:outpoints[0]});
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- var _topWallmesh=BABYLON.Mesh.MergeMeshes(topWallmeshes);
- var topCSG = BABYLON.CSG.FromMesh(_topWallmesh);
- var finalTopMesh = topCSG.toMesh("wallopen",this.wallmaterial, this.scene,true);
- _topWallmesh.dispose();
- _topWallmesh=null;
- this.roomWallMeshes.push(finalTopMesh);
-
- var wallmesh=BABYLON.Mesh.MergeMeshes(wallmeshes);
-
- wallmesh.subMeshes = [];
- this.wallSet.subMaterials=[];
- for(var i=0;i<this.wallSet.submeshes.length;++i)
- {
- wallmesh.subMeshes.push(new BABYLON.SubMesh(i, this.wallSet.submeshes[i].verticesStart, this.wallSet.submeshes[i].verticesCount, this.wallSet.submeshes[i].indexStart,this.wallSet.submeshes[i].indexCount, wallmesh));
- var wallmaterial = new BABYLON.StandardMaterial("wall"+i, this.scene);
- /*
- wallmaterial.alpha = 1.0;
- wallmaterial.emissiveColor = new BABYLON.Color3(0.8,0.8,0.8);
- wallmaterial.backFaceCulling = false;
- */
- wallmaterial=this.getwallmaterial(i);
- wallmaterial.toward=towards[i];
- wallmaterial.points=points[i];
- wallmaterial.indexplane=collindex[i];
- this.wallSet.subMaterials.push(wallmaterial);
-
- }
-
- var wallCSG =BABYLON.CSG.FromMesh(wallmesh);
-
- if(type==1)
- {
- this.baseSymbolThick=this.doorThick;
- }
- else
- {
- this.baseSymbolThick=this.doorThick/2;
- }
-
- for(var i=0;i<symbols.length;++i)
- {
- var symMesh;
- //var len=this.getLen(symbols[i].type);
- var len=symbols[i].len;
- /*
- if(symbols[i].type=="Symbol2D_OpeningDoor")
- {
- symMesh=this.drawOpeningDoor(symbols[i],len);
- }
- else if(symbols[i].type=="Symbol2D_OpeningWindow")
- {
- symMesh=this.drawOpeningWindow(symbols[i],len);
- }
- else if(symbols[i].type=="Symbol2D_SimpleDoor")
- {
- symMesh=this.drawSimpleDoor(symbols[i],len);
- }
- else if(symbols[i].type=="Symbol2D_SingleCasement")
- {
- symMesh=this.drawSingleCasement(symbols[i],len);
- }
- else if(symbols[i].type=="Symbol2D_SlidingDoor")
- {
- symMesh=this.drawSlidingDoor(symbols[i],len);
- }
- else if(symbols[i].type=="Symbol2D_SlidingWindow")
- {
- symMesh=this.drawSlidingWindow(symbols[i],len);
- }
- */
- if(symbols[i].type=="OpenDoor")
- {
- symMesh=this.drawOpeningDoor(symbols[i],len);
- }
- else if(symbols[i].type=="OpenWindow")
- {
- symMesh=this.drawOpeningWindow(symbols[i],len);
- }
- else if(symbols[i].type=="SimpleDoor")
- {
- symMesh=this.drawSimpleDoor(symbols[i],len);
- }
- else if(symbols[i].type=="BiFoldDoor")
- {
- symMesh=this.drawBiFoldDoor(symbols[i],len);
- }
- else if(symbols[i].type=="SlidingDoor")
- {
- symMesh=this.drawSlidingDoor(symbols[i],len);
- }
- else if(symbols[i].type=="SingleCasement")
- {
- symMesh=this.drawSingleCasement(symbols[i],len);
- }
- else if(symbols[i].type=="DoubleCasement")
- {
- symMesh=this.drawDoubleCasement(symbols[i],len);
- }
- else if(symbols[i].type=="SlidingWindow")
- {
- symMesh=this.drawSlidingWindow(symbols[i],len);
- }
- else
- {
- continue;
- }
- var symCSG = BABYLON.CSG.FromMesh(symMesh);
- wallCSG = wallCSG.subtract(symCSG);
- symMesh.dispose();
- }
- var wall = wallCSG.toMesh("wall"+id,null, this.scene,true);
- var multi=new BABYLON.MultiMaterial("material"+id,this.scene);
- multi.subMaterials=this.wallSet.subMaterials;
-
- wall.material=multi;
-
- for(var i=0;i<this.paintSet.length;++i)
- {
- if(this.paintSet[i].type=="wall"&&this.paintSet[i].wallId==wall.id&&this.wallSet.subMaterials.length>this.paintSet[i].materialId)
- {
- wall.material.subMaterials[this.paintSet[i].materialId]=this.paintSet[i].material;
- //break;
- }
- }
-
- wallmesh.dispose();
- wallmesh=null;
- this.roomWallMeshes.push(wall);
- //this.meshManager.collidables.push(wall);
-
- };
- Symbol3D.prototype.drawSingleWall=function(pt1,pt2,pt3,pt4)
- {
- var mesh = new BABYLON.Mesh("mesh", this.scene);
- mesh.material = this.wallmaterial;
-
- var path1 = [];
- var path2 = [];
-
- path1.push(pt1);
- path1.push(pt2);
-
- path2.push(pt3);
- path2.push(pt4);
-
- // positions
- var positions = [];
- for (var i = 0; i < path1.length; i++) {
- positions.push(path1[i].x, path1[i].y, path1[i].z);
- positions.push(path2[i].x, path2[i].y, path2[i].z);
- };
- // indices
- var indices = [];
- for (var i = 0; i < path1.length * 2 - 2 ; i+=2) {
- indices.push(i, i+1, i+2);
- indices.push(i+3, i+2, i+1);
- };
-
- // normals
- var normals = [];
- BABYLON.VertexData.ComputeNormals(positions, indices, normals);
- // mesh
- var colors = [
- 1, 0, 0, 1,
- 0, 1, 0, 1,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- ];
- mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors);
- var uvs=[[0,0],[1,0],[1,1],[0,1]];
- mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
- mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false);
- mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false);
- mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false);
- mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false);
- mesh.setIndices(indices);
- return mesh;
- };
- Symbol3D.prototype.drawTopWall=function(pt1,pt2,pt3,pt4)
- {
- var mesh = new BABYLON.Mesh("mesh", this.scene);
- //mesh.material = this.wallmaterial;
-
- var path1 = [];
- var path2 = [];
-
- path1.push(pt1);
- path1.push(pt2);
-
- path2.push(pt3);
- path2.push(pt4);
-
- // positions
- var positions = [];
- for (var i = 0; i < path1.length; i++) {
- positions.push(path1[i].x, path1[i].y, path1[i].z);
- positions.push(path2[i].x, path2[i].y, path2[i].z);
- };
- // indices
- var indices = [];
- for (var i = 0; i < path1.length * 2 - 2 ; i+=2) {
- indices.push(i, i+1, i+2);
- indices.push(i+3, i+2, i+1);
- };
-
- // normals
- var normals = [];
- BABYLON.VertexData.ComputeNormals(positions, indices, normals);
- // mesh
- var colors = [
- 1, 0, 0, 1,
- 0, 1, 0, 1,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- ];
- mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors);
- var uvs=[[0,0],[1,0],[1,1],[0,1]];
- mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
- mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false);
- mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false);
- mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false);
- mesh.setIndices(indices);
- mesh.material = this.wallmaterial;
- return mesh;
- };
- Symbol3D.prototype.drawSideWall=function(pt1,pt2)
- {
- var mesh = new BABYLON.Mesh("mesh", this.scene);
- //mesh.material = this.wallmaterial;
- this.createwallPlane(new BABYLON.Vector2(pt1.x,pt1.z),new BABYLON.Vector2(pt2.x,pt2.z));
-
- var path1 = [];
- var path2 = [];
-
- path1.push(pt1);
- path1.push(pt2);
-
- var pt3=new BABYLON.Vector3(pt1.x,this.wallHeigh, pt1.z);
- var pt4=new BABYLON.Vector3(pt2.x,this.wallHeigh, pt2.z);
-
- path2.push(pt3);
- path2.push(pt4);
-
- // positions
- var positions = [];
- for (var i = 0; i < path1.length; i++) {
- positions.push(path1[i].x, path1[i].y, path1[i].z);
- positions.push(path2[i].x, path2[i].y, path2[i].z);
- };
- // indices
- var indices = [];
- for (var i = 0; i < path1.length * 2 - 2 ; i+=2) {
- indices.push(i, i+1, i+2);
- indices.push(i+3, i+2, i+1);
- };
-
- // normals
- var normals = [];
- BABYLON.VertexData.ComputeNormals(positions, indices, normals);
-
- var uvs=[[0,0],[1,0],[1,1],[0,1]];
- mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
-
- var colors = [
- 1, 0, 0, 1,
- 0, 1, 0, 1,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- ];
-
- // mesh
- mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors);
- mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false);
- mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false);
- mesh.setIndices(indices);
- mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false);
- mesh.material = this.wallmaterial;
- this.wallSet.submeshes.push({verticesStart:this.wallSet.verticesStart, verticesCount:mesh.getTotalVertices(), indexStart:this.wallSet.indexStart, indexCount:mesh.getTotalIndices()});
- this.wallSet.verticesStart+=mesh.getTotalVertices();
- this.wallSet.indexStart+=mesh.getTotalIndices();
-
- mesh.planindex=this.meshManager.collidables.length-1;
- return mesh;
- };
- Symbol3D.prototype.drawCloseWallSymbols=function(outpoints,inpoints,symbols,type,id)
- {
- var wallmeshes = [];
- var topWallmeshes=[];
- var pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8;
-
- this.wallSet.submeshes=[];
- this.wallSet.verticesStart=0;
- this.wallSet.indexStart=0;
- this.wallSet.subMaterials=[];
-
- var calculateLine=layer.calculateLine;
- //var calculateLine=new CalculateLine();
- var towards=[];
- var points=[];
- var collindex=[];
-
- for(var i=0;i<outpoints.length;++i)
- {
- if(i==outpoints.length-1)
- {
- pt1=new BABYLON.Vector3(outpoints[0].x, 0, outpoints[0].y);
- pt2=new BABYLON.Vector3(outpoints[outpoints.length-1].x, 0, outpoints[outpoints.length-1].y);
- var mesh=this.drawSideWall(pt2,pt1);
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- pt3=new BABYLON.Vector3(inpoints[0].x, 0, inpoints[0].y);
- pt4=new BABYLON.Vector3(inpoints[inpoints.length-1].x, 0, inpoints[inpoints.length-1].y);
-
- var toward= calculateLine.getToward2(outpoints[0],outpoints[outpoints.length-1],inpoints[0],inpoints[inpoints.length-1]);
- towards.push(toward);
- this.meshManager.collidables[this.meshManager.collidables.length-1].toward=toward;
- points.push({point1:outpoints[0],point2:outpoints[outpoints.length-1]});
-
- mesh=this.drawSideWall(pt3,pt4);
- //mesh.toward=-1*toward;
- towards.push(-1*toward);
- this.meshManager.collidables[this.meshManager.collidables.length-1].toward=-1*toward;
- points.push({point1:inpoints[0],point2:inpoints[inpoints.length-1]});
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- pt5=new BABYLON.Vector3(inpoints[inpoints.length-1].x, this.wallHeigh, inpoints[inpoints.length-1].y);
- pt6=new BABYLON.Vector3(inpoints[0].x, this.wallHeigh, inpoints[0].y);
- pt7=new BABYLON.Vector3(outpoints[outpoints.length-1].x, this.wallHeigh, outpoints[outpoints.length-1].y);
- pt8=new BABYLON.Vector3(outpoints[0].x, this.wallHeigh, outpoints[0].y);
- mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
- mesh.material=this.wallmaterial;
- topWallmeshes.push(mesh);
- }
- else
- {
- pt1=new BABYLON.Vector3(outpoints[i].x, 0, outpoints[i].y);
- pt2=new BABYLON.Vector3(outpoints[i+1].x, 0, outpoints[i+1].y);
- var mesh=this.drawSideWall(pt1,pt2);
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- pt3=new BABYLON.Vector3(inpoints[i].x, 0, inpoints[i].y);
- pt4=new BABYLON.Vector3(inpoints[i+1].x, 0, inpoints[i+1].y);
-
- //var toward= calculateLine.getToward2(pt1,pt2,pt3,pt4);
- var toward= calculateLine.getToward2(outpoints[i],outpoints[i+1],inpoints[i],inpoints[i+1]);
- //mesh.toward=toward;
- points.push({point1:outpoints[i],point2:outpoints[i+1]});
- towards.push(toward);
- this.meshManager.collidables[this.meshManager.collidables.length-1].toward=toward;
-
- mesh=this.drawSideWall(pt3,pt4);
- //mesh.toward=-1*toward;
- points.push({point1:inpoints[i],point2:inpoints[i+1]});
- towards.push(-1*toward);
- this.meshManager.collidables[this.meshManager.collidables.length-1].toward=-1*toward;
- wallmeshes.push(mesh);
- collindex.push(mesh.planindex);
-
- pt5=new BABYLON.Vector3(inpoints[i].x, this.wallHeigh, inpoints[i].y);
- pt6=new BABYLON.Vector3(inpoints[i+1].x, this.wallHeigh, inpoints[i+1].y);
- pt7=new BABYLON.Vector3(outpoints[i].x, this.wallHeigh, outpoints[i].y);
- pt8=new BABYLON.Vector3(outpoints[i+1].x, this.wallHeigh, outpoints[i+1].y);
- mesh=this.drawTopWall(pt5,pt6,pt7,pt8);
- mesh.material=this.wallmaterial;
- topWallmeshes.push(mesh);
- }
- }
- var _topWallmesh=BABYLON.Mesh.MergeMeshes(topWallmeshes);
- var topCSG = BABYLON.CSG.FromMesh(_topWallmesh);
- var finalTopMesh = topCSG.toMesh("walltop",this.wallmaterial, this.scene,true);
- _topWallmesh.dispose();
- _topWallmesh=null;
- this.roomWallMeshes.push(finalTopMesh);
-
- var wallmesh=BABYLON.Mesh.MergeMeshes(wallmeshes);
- wallmesh.subMeshes = [];
- this.wallSet.subMaterials=[];
- for(var i=0;i<this.wallSet.submeshes.length;++i)
- {
- wallmesh.subMeshes.push(new BABYLON.SubMesh(i, this.wallSet.submeshes[i].verticesStart, this.wallSet.submeshes[i].verticesCount, this.wallSet.submeshes[i].indexStart,this.wallSet.submeshes[i].indexCount, wallmesh));
- /*
- var wallmaterial = new BABYLON.StandardMaterial("wall"+i, this.scene);
- wallmaterial.alpha = 1.0;
- wallmaterial.emissiveColor = new BABYLON.Color3(0.8,0.8,0.8);
- wallmaterial.backFaceCulling = false;
- */
- var wallmaterial =this.getwallmaterial(i);
- wallmaterial.toward=towards[i];
- wallmaterial.points=points[i];
- wallmaterial.indexplane=collindex[i];
- this.wallSet.subMaterials.push(wallmaterial);
- }
-
- var wallCSG =BABYLON.CSG.FromMesh(wallmesh);
-
- if(type==1)
- {
- this.baseSymbolThick=this.doorThick;
- }
- else
- {
- this.baseSymbolThick=this.doorThick/2;
- }
-
- for(var i=0;i<symbols.length;++i)
- {
- var symMesh;
- //var len=this.getLen(symbols[i].type);
- var len=symbols[i].len;
- /*
- if(symbols[i].type=="Symbol2D_OpeningDoor")
- {
- symMesh=this.drawOpeningDoor(symbols[i],len);
- }
- else if(symbols[i].type=="Symbol2D_OpeningWindow")
- {
- symMesh=this.drawOpeningWindow(symbols[i],len);
- }
- else if(symbols[i].type=="Symbol2D_SimpleDoor")
- {
- symMesh=this.drawSimpleDoor(symbols[i],len);
- }
- else if(symbols[i].type=="Symbol2D_SingleCasement")
- {
- symMesh=this.drawSingleCasement(symbols[i],len);
- }
- else if(symbols[i].type=="Symbol2D_SlidingDoor")
- {
- symMesh=this.drawSlidingDoor(symbols[i],len);
- }
- else if(symbols[i].type=="Symbol2D_SlidingWindow")
- {
- symMesh=this.drawSlidingWindow(symbols[i],len);
- }
- */
- if(symbols[i].type=="OpenDoor")
- {
- symMesh=this.drawOpeningDoor(symbols[i],len);
- }
- else if(symbols[i].type=="OpenWindow")
- {
- symMesh=this.drawOpeningWindow(symbols[i],len);
- }
- else if(symbols[i].type=="SimpleDoor")
- {
- symMesh=this.drawSimpleDoor(symbols[i],len);
- }
- else if(symbols[i].type=="BiFoldDoor")
- {
- symMesh=this.drawBiFoldDoor(symbols[i],len);
- }
- else if(symbols[i].type=="SlidingDoor")
- {
- symMesh=this.drawSlidingDoor(symbols[i],len);
- }
- else if(symbols[i].type=="SingleCasement")
- {
- symMesh=this.drawSingleCasement(symbols[i],len);
- }
- else if(symbols[i].type=="DoubleCasement")
- {
- symMesh=this.drawDoubleCasement(symbols[i],len);
- }
- else if(symbols[i].type=="SlidingWindow")
- {
- symMesh=this.drawSlidingWindow(symbols[i],len);
- }
- else
- {
- continue;
- }
- var symCSG = BABYLON.CSG.FromMesh(symMesh);
- wallCSG = wallCSG.subtract(symCSG);
- symMesh.dispose();
- }
- var wall = wallCSG.toMesh("wall"+id,null, this.scene,true);
- var multi=new BABYLON.MultiMaterial("material"+id,this.scene);
- multi.subMaterials=this.wallSet.subMaterials;
- wall.material=multi;
- wallmesh.dispose();
- wallmesh=null;
-
- for(var i=0;i<this.paintSet.length;++i)
- {
- if(this.paintSet[i].type=="wall"&&this.paintSet[i].wallId==wall.id&&this.wallSet.subMaterials.length>this.paintSet[i].materialId)
- {
- wall.material.subMaterials[this.paintSet[i].materialId]=this.paintSet[i].material;
- //break;
- }
- }
- this.roomWallMeshes.push(wall);
- };
- Symbol3D.prototype.extendedline=function(point,point1)
- {
- var dx=point.x-point1.x;
- var dy=point.y-point1.y;
- while(Math.abs(dx)>10||Math.abs(dx)>10)
- {
- dx/=10;
- dy/=10;
- }
- var dpoint={x:dx,y:dy};
- return dpoint;
- };
- Symbol3D.prototype.showPicture=function(src)
- {
- var plan = BABYLON.Mesh.CreatePlane("picture-"+src, 1, this.scene);
- plan.scaling.x=50;
- plan.scaling.y=40;
- plan.position=new BABYLON.Vector3(0, 0, 0);
- var material = new BABYLON.StandardMaterial("planmaterial", this.scene);
- material.diffuseTexture = new BABYLON.Texture(this.wallpicture_pre+src, this.scene);
- material.bumpTexture = new BABYLON.Texture("images/floor1.png", this.scene);
- plan.material=material;
- plan.rotation.x=Math.PI/2;
- this.meshManager.collidables.push(plan);
- };
- Symbol3D.prototype.showPhoFrame=function(src)
- {
- BABYLON.SceneLoader.ImportMesh("", "images/3d/", src, this.scene, function (newMeshes)
- {
- newMeshes[0].scaling=new BABYLON.Vector3(this.meshManager.furnitureScal,this.meshManager.furnitureScal,this.meshManager.furnitureScal);
-
- newMeshes[0].computeWorldMatrix(true);
- newMeshes[0].refreshBoundingInfo();
-
- newMeshes[0].position=new BABYLON.Vector3(0,-100,0);
- newMeshes[0].name="pho-"+src;
- newMeshes[0].thice=Math.abs(newMeshes[0]._boundingInfo.boundingBox.maximumWorld.z-newMeshes[0]._boundingInfo.boundingBox.minimumWorld.z);
- newMeshes[0].firstHeigh=Math.abs(newMeshes[0]._boundingInfo.boundingBox.maximumWorld.y-newMeshes[0]._boundingInfo.boundingBox.minimumWorld.y);
- if(this.phoSet.photoFrameMesh!=null)
- {
- this.phoSet.photoFrameMesh.dispose();
- this.phoSet.photoFrameMesh=null;
- }
- this.phoSet.photoFrameMesh=newMeshes[0];
- //this.phoSet.photoFrameMesh.showBoundingBox=true;
- this.phoSet.photoFrameMesh.height=newMeshes[0].firstHeigh;
- this.phoSet.photoFrameMesh.length=Math.abs(newMeshes[0]._boundingInfo.boundingBox.maximumWorld.x-newMeshes[0]._boundingInfo.boundingBox.minimumWorld.x);
- this.phoSet.photoFrameMesh.visibility=0;
- this.phoSet.start=true;
- document.getElementById("container3d").style.cursor="url('images/brush.ico'),auto";
- for(var i=0;i<this.phoSet.photoFrameMesh._boundingInfo.boundingBox.vectorsWorld.length;++i)
- {
- if(this.phoSet.photoFrameMesh._boundingInfo.boundingBox.vectorsWorld[i].z>this.phoSet.photoFrameMesh._boundingInfo.boundingBox.minimumWorld.z)
- {
- this.phoSet.photoFrameMesh.frontindex=i;
- break;
- }
- }
-
-
- /*
- var point1=new BABYLON.Vector3(this.phoSet.photoFrameMesh._boundingInfo.boundingBox.minimumWorld.x, -100, this.phoSet.photoFrameMesh._boundingInfo.boundingBox.maximumWorld.z);
- var point2=new BABYLON.Vector3(this.phoSet.photoFrameMesh._boundingInfo.boundingBox.maximumWorld.x, -100, this.phoSet.photoFrameMesh._boundingInfo.boundingBox.maximumWorld.z);
- var point3=new BABYLON.Vector3(this.phoSet.photoFrameMesh._boundingInfo.boundingBox.minimumWorld.x, -100, this.phoSet.photoFrameMesh._boundingInfo.boundingBox.maximumWorld.z);
- var point4=new BABYLON.Vector3(this.phoSet.photoFrameMesh._boundingInfo.boundingBox.maximumWorld.x, -100, this.phoSet.photoFrameMesh._boundingInfo.boundingBox.maximumWorld.z);
- this.phoSet.photoFrameMesh.pts={point1:{x:point1.x,y:point1.z},point2:{x:point2.x,y:point2.z},point3:point3,point4:point4};
- */
- this.engine.hideLoadingUI();
- }.bind(this));
- };
- Symbol3D.prototype.showProductfirst=function(src,position,rotation)
- {
- BABYLON.SceneLoader.ImportMesh("", "images/3d/", src, this.scene, function (newMeshes)
- {
- var mesh;
- if(newMeshes.length>1)
- {
- mesh=BABYLON.Mesh.MergeMeshes(newMeshes);
- }
- else
- {
- mesh=newMeshes[0];
- }
- //mesh.scaling=new BABYLON.Vector3(this.meshManager.furnitureScal,this.meshManager.furnitureScal,this.meshManager.furnitureScal);
- //mesh.position=position;
- //mesh.rotation=rotation;
- var name=src.replace(".babylon","");
- mesh.scaling=new BABYLON.Vector3(layer.parameter.testModelData[name],layer.parameter.testModelData[name],layer.parameter.testModelData[name]);
- mesh.position=position;
- //mesh.material.specularColor=new BABYLON.Color3(0.8,0.8,0.8);
- //if(mesh.name=="cabinet")
- if(layer.parameter.cabinet.indexOf(name+",")>-1)
- {
- var glassMesh = BABYLON.Mesh.CreateBox("box", 1, this.scene);
- glassMesh.scaling.x=Math.abs(mesh._boundingInfo.maximum.x-mesh._boundingInfo.minimum.x)*mesh.scaling.x-5;
- glassMesh.scaling.y=80;
- glassMesh.scaling.z=Math.abs(mesh._boundingInfo.maximum.z-mesh._boundingInfo.minimum.z)*mesh.scaling.z/1.2;
- glassMesh.position.x=position.x;
- glassMesh.position.y=Math.abs(mesh._boundingInfo.maximum.y-mesh._boundingInfo.minimum.y)*mesh.scaling.y-40;
- glassMesh.position.z=position.z-2;
- glassMesh.visibility = 0.3;
- glassMesh.name="mirror";
- this.meshManager.glassBoxMeshes.push(glassMesh);
- }
-
- for(var i=0;i<this.meshManager.collidables.length;++i)
- {
- if (typeof(this.meshManager.collidables[i]) == "undefined") {
- this.meshManager.collidables.splice(i,1);
- --i;
- continue;
- }
- if (mesh.intersectsMesh(this.meshManager.collidables[i], true))
- {
- this.meshManager.firstMeshes.push(src)
- break;
- }
- }
- ++initMesh;
- if(initMesh>21)
- {
- this.engine.hideLoadingUI();
- initMesh=0;
- }
- this.meshManager.collidables.push(mesh);
- }.bind(this));
- return this.meshManager.collidables[this.meshManager.collidables.length-1];
- };
- Symbol3D.prototype.showProduct=function(src)
- {
- this.engine.displayLoadingUI();
- this.engine.loadingUIText = "正在加载家具,请稍等!";
- //this.engine.loadingUIBackgroundColor = "red";
- BABYLON.SceneLoader.ImportMesh("", "images/3d/", src, this.scene, function (newMeshes)
- {
- var mesh;
- if(newMeshes.length>1)
- {
- mesh=BABYLON.Mesh.MergeMeshes(newMeshes);
- }
- else
- {
- mesh=newMeshes[0];
- }
- //mesh.scaling=new BABYLON.Vector3(this.meshManager.furnitureScal,this.meshManager.furnitureScal,this.meshManager.furnitureScal);
- //mesh.scaling=new BABYLON.Vector3(10,10,10);
- var name=src.replace(".babylon","");
- mesh.scaling=new BABYLON.Vector3(layer.parameter.testModelData[name],layer.parameter.testModelData[name],layer.parameter.testModelData[name]);
- //mesh.position=new BABYLON.Vector3(0, 60, 0);
- //newMeshes[0].showBoundingBox=true;
- mesh.name=src;
-
- for(var i=0;i<this.meshManager.collidables.length;++i)
- {
- if (typeof(this.meshManager.collidables[i]) == "undefined") {
- this.meshManager.collidables.splice(i,1);
- --i;
- continue;
- }
- if (mesh.intersectsMesh(this.meshManager.collidables[i], true))
- {
- this.meshManager.firstMeshes.push(src)
- break;
- }
- }
- this.meshManager.collidables.push(mesh);
- //div.style.display="none";
- this.engine.hideLoadingUI();
- }.bind(this));
- /*
- * <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>
- * */
- };
- Symbol3D.prototype.boxify=function (positions,blankmesh) {
- var box, boxmat;
- for (var i=0;i<positions.length;i+=3) {
- box = BABYLON.Mesh.CreateBox("box"+String(i), 10, this.scene);
- box.position = new BABYLON.Vector3(positions[i], positions[i+1], positions[i+2]);
- boxmat = new BABYLON.StandardMaterial("boxmat", this.scene);
- // new DynamicTexture(name, options, scene, generateMipMaps)
- boxmat.emissiveTexture = new BABYLON.DynamicTexture("dt", 512, this.scene, true);
- // drawText(text, x, y, font, color, clearColor, invertY)
- if (i<300) {
- boxmat.emissiveTexture.drawText((i/3<10?" "+String(i/3):String(i/3)), 10, 340, "bold 250pt verdana", "white", "blue", 1);
- }
- else {
- boxmat.emissiveTexture.drawText(String(i/3), 10, 340, "bold 160pt verdana", "white", "blue", 1);
- }
- box.material = boxmat;
- box.parent = blankmesh;
- }
- };
- /*
- Symbol3D.prototype.createwallPlane=function (point1,point2) {
- var p1=new BABYLON.Vector2(point1.x, point1.y);
- var p2=new BABYLON.Vector2(point2.x, point2.y);
- var distance= BABYLON.Vector2.Distance(p1,p2);
- var plan = BABYLON.Mesh.CreatePlane("plane", distance, this.scene);
- plan.material = this.wallmaterial;
- plan.scaling.y = this.wallHeigh;
- plan.position=new BABYLON.Vector3((p1.x+p2.x)/2,0, (p1.y+p2.y)/2);
- var angle=BABYLON.Angle.BetweenTwoPoints(p1,p2);
- plan.rotation.y=-angle._radians;
- //plan.visibility=0;
- this.meshManager.collidables.push(plan);
- };
- */
- Symbol3D.prototype.createwallPlane=function (point1,point2) {
- var p1=new BABYLON.Vector2(point1.x, point1.y);
- var p2=new BABYLON.Vector2(point2.x, point2.y);
- var distance= BABYLON.Vector2.Distance(p1,p2);
- //var plan = BABYLON.Mesh.CreatePlane("plane", distance, this.scene);
- var plan = BABYLON.Mesh.CreatePlane("plane", 1, this.scene);
- plan.scaling.x=distance;
- //plan.scaling.y =1;
- plan.scaling.y =this.wallHeigh;
- plan.material = this.wallmaterial;
-
- //plan.position=new BABYLON.Vector3((p1.x+p2.x)/2,0.5, (p1.y+p2.y)/2);
- plan.position=new BABYLON.Vector3((p1.x+p2.x)/2,this.wallHeigh/2, (p1.y+p2.y)/2);
- var angle=BABYLON.Angle.BetweenTwoPoints(p1,p2);
- plan.rotation.y=-angle._radians;
- plan.visibility=0;
- plan.pts={point1:point1,point2:point2};
- plan.planindex=this.meshManager.collidables.length;
- this.meshManager.collidables.push(plan);
- //plan.dispose();
- };
- /*
- Symbol3D.prototype.drawCloseWall = function (outpoints,inpoints,flag) {
- var shape=[];
- var shape2=[];
- for(var i=0;i<outpoints.length;++i)
- {
- var pt=new BABYLON.Vector3(outpoints[i].x, outpoints[i].y, 0);
- shape.push(pt);
- if(i!=outpoints.length-1)
- {
- this.createwallPlane(outpoints[i],outpoints[i+1]);
- }
- else
- {
- if(flag)
- {
- this.createwallPlane(outpoints[i],outpoints[0]);
- }
- }
- }
- shape.push(new BABYLON.Vector3(outpoints[0].x, outpoints[0].y, 0));
-
- for(var i=0;i<inpoints.length;++i)
- {
- var pt=new BABYLON.Vector3(inpoints[i].x, inpoints[i].y, 0);
- shape2.push(pt);
- if(i!=inpoints.length-1)
- {
- this.createwallPlane(inpoints[i],inpoints[i+1]);
- }
- else
- {
- if(flag)
- {
- this.createwallPlane(inpoints[i],inpoints[0]);
- }
- }
- }
- shape2.push(new BABYLON.Vector3(inpoints[0].x, inpoints[0].y, 0));
-
- var path = [
- new BABYLON.Vector3(0,0,0),
- new BABYLON.Vector3(0, 0, this.wallHeigh)
- ];
-
- var extruded2 = BABYLON.Mesh.ExtrudeShape("extruded2", shape2, path, 1, 0, 3, this.scene);
- var extruded = BABYLON.Mesh.ExtrudeShape("extruded", shape, path, 1, 0, 3, this.scene);
- var aCSG = BABYLON.CSG.FromMesh(extruded);
- var bCSG = BABYLON.CSG.FromMesh(extruded2);
- extruded.dispose();
- extruded2.dispose();
- //extruded.rotation.x = Math.PI / 2;
- //extruded2.rotation.x = Math.PI / 2;
- //extruded2.position=new BABYLON.Vector3(0, this.wallHeigh,0);
- //extruded.position=new BABYLON.Vector3(0, this.wallHeigh,0);
- var subCSG = bCSG.subtract(aCSG);
- return subCSG;
- };
- */
- Symbol3D.prototype.addSymbol = function () {
- // Meshes
- var blueBox = BABYLON.Mesh.CreateBox("blue", 16, this.scene);
- var blueMat = new BABYLON.StandardMaterial("ground", this.scene);
- blueMat.diffuseColor = new BABYLON.Color3(0.4, 0.4, 0.4);
- blueMat.specularColor = new BABYLON.Color3(0.4, 0.4, 0.4);
- blueMat.emissiveColor = BABYLON.Color3.Blue();
- blueBox.material = blueMat;
- blueBox.position.x += 20;
- blueBox.position.y = 8;
- blueBox.position.z -= 10;
- blueBox.ellipsoid = new BABYLON.Vector3(blueBox.getBoundingInfo().boundingBox.extendSize.x*blueBox.scaling.x,0.0001,blueBox.getBoundingInfo().boundingBox.extendSize.z*blueBox.scaling.z);
- blueBox.checkCollisions = true;
- //blueBox.showSubMeshesBoundingBox =true;
- var redBox = BABYLON.Mesh.CreateBox("red", 16, this.scene);
- var blueMat = new BABYLON.StandardMaterial("ground", this.scene);
- blueMat.diffuseColor = new BABYLON.Color3(0.4, 0.4, 0.4);
- blueMat.specularColor = new BABYLON.Color3(0.4, 0.4, 0.4);
- blueMat.emissiveColor = BABYLON.Color3.Red();
- redBox.material = blueMat;
- redBox.position.x -= 60;
- redBox.position.y = 8;
- redBox.ellipsoid = new BABYLON.Vector3(redBox.getBoundingInfo().boundingBox.extendSize.x*redBox.scaling.x,0.0001,redBox.getBoundingInfo().boundingBox.extendSize.z*redBox.scaling.z);
- redBox.checkCollisions = true;
- blueBox.checkCollisions = true;
- blueBox.applyGravity = true;
- redBox.checkCollisions = true;
- redBox.applyGravity = true;
- this.collidables.push(blueBox);
- this.collidables.push(redBox);
- };
- Symbol3D.prototype.clearAllSymbols=function()
- {
- for(var i=0;i<this.meshManager.collidables.length;++i)
- {
- this.meshManager.collidables[i].dispose();
- }
-
- for(var i=0;i<this.roomWallMeshes.length;++i)
- {
- this.roomWallMeshes[i].dispose();
- }
-
- for(var i=0;i<this.meshManager.arrowMeshes.length;++i)
- {
- this.meshManager.arrowMeshes[i].dispose();
- }
-
- for(var i=0;i<this.meshManager.glassBoxMeshes.length;++i)
- {
- this.meshManager.glassBoxMeshes[i].dispose();
- }
-
- }
- Symbol3D.prototype.clearSymbol=function()
- {
-
- for(var i=0;i<this.meshManager.collidables.length;++i)
- {
- if(this.meshManager.collidables[i].name=="plane")
- {
- this.meshManager.collidables[i].dispose();
- this.meshManager.collidables.splice(i, 1);
- --i;
- }
-
- }
-
- for(var i=0;i<this.roomWallMeshes.length;++i)
- {
- this.roomWallMeshes[i].dispose();
- }
- };
- Symbol3D.prototype.drawOpeningDoor= function(location,len)
- {
- var cubeMesh = BABYLON.Mesh.CreateBox( "OpeningDoor", 1, this.scene);
- //cubeMesh.scaling=new BABYLON.Vector3(this.baseSymbolThick,len/2,);
- //baseSymbolThick是30,doorHeigh是100,len是60
- cubeMesh.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.baseSymbolThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x, this.doorBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- return cubeMesh;
- };
- Symbol3D.prototype.drawOpeningWindow= function(location,len)
- {
- var cubeMesh = BABYLON.Mesh.CreateBox( "OpeningWindow", 1, this.scene);
- //baseSymbolThick是30,windowHeigh是50,len是40
- cubeMesh.scaling=new BABYLON.Vector3(len,this.windowHeigh,this.baseSymbolThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x, this.windowBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- return cubeMesh;
- };
- Symbol3D.prototype.drawSimpleDoor= function(location,len)
- {
- var cubeMesh = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.doorThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.baseSymbolThick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,this.baseSymbolThick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
- var newMesh = subCSG.toMesh("Door", this.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- //newMesh.rotation.x = Math.PI / 2;
- this.roomWallMeshes.push(newMesh);
- cubeMesh4.dispose();
- cubeMesh2.dispose();
-
- if(this.doormaterial==null)
- {
- this.setdoormaterial();
- }
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "SimpleDoor", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len-10,20,this.doorHeigh-10);
- cubeMesh3.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- cubeMesh3.rotation.y=-location.angle;
- cubeMesh3.rotation.x = Math.PI / 2;
- cubeMesh3.material=this.doormaterial;
- this.roomWallMeshes.push(cubeMesh3);
- if(this.doorknobMaterial==null)
- {
- this.setdoorknobMaterial();
- }
- var cubeMesh5=BABYLON.Mesh.CreateBox( "Doorknob", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(10,2,22);
- cubeMesh5.position=new BABYLON.Vector3(location.point.x+20*Math.cos(location.angle),this.doorBottom,location.point.y+20*Math.sin(location.angle));
- cubeMesh5.rotation.y=-location.angle;
- //cubeMesh5.rotation.x = Math.PI / 2;
- cubeMesh5.material=this.doorknobMaterial;
- this.roomWallMeshes.push(cubeMesh5);
-
- return cubeMesh;
- };
- Symbol3D.prototype.drawSingleCasement= function(location,len)
- {
- var cubeMesh = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.windowHeigh,this.doorThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.windowHeigh,this.baseSymbolThick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.windowHeigh-10,this.baseSymbolThick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
- var newMesh = subCSG.toMesh("Window", this.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- //newMesh.rotation.x = Math.PI / 2;
- this.roomWallMeshes.push(newMesh);
- cubeMesh4.dispose();
- cubeMesh2.dispose();
-
- if(this.windowframeMaterial==null)
- {
- this.setwindowframeMaterial();
- }
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.windowHeigh-10,20);
- var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
- var cubeMesh1 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
- cubeMesh1.scaling=new BABYLON.Vector3(len-20,this.windowHeigh-20,21);
- var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
- var subCSG2 = cCSG.subtract(dCSG);
- var newMesh2 = subCSG2.toMesh("Window", this.windowframeMaterial, this.scene);
- newMesh2.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
- newMesh2.rotation.y=-location.angle;
- //newMesh2.rotation.x = Math.PI / 2;
- this.roomWallMeshes.push(newMesh2);
- cubeMesh1.dispose();
- cubeMesh3.dispose();
-
- //镜子
- var cubeMesh6 = BABYLON.Mesh.CreateBox( "SingleWindow", 1, this.scene);
- cubeMesh6.scaling=new BABYLON.Vector3(len-20,21,this.windowHeigh-20);
- cubeMesh6.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
- cubeMesh6.rotation.z=-location.angle;
- cubeMesh6.rotation.x = Math.PI / 2;
- cubeMesh6.visibility = 0.08;
- this.roomWallMeshes.push(cubeMesh6);
-
- if(this.doorknobMaterial==null)
- {
- this.setdoorknobMaterial();
- }
- var cubeMesh5=BABYLON.Mesh.CreateBox( "Windowknob", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(2,5,22);
- cubeMesh5.position=new BABYLON.Vector3(location.point.x+14*Math.cos(location.angle),this.windowBottom,location.point.y+14*Math.sin(location.angle));
- cubeMesh5.rotation.y=-location.angle;
- //cubeMesh5.rotation.x = Math.PI / 2;
- cubeMesh5.material=this.doorknobMaterial;
- this.roomWallMeshes.push(cubeMesh5);
- return cubeMesh;
- };
- Symbol3D.prototype.drawSlidingDoor=function(location,len)
- {
- var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.doorThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.baseSymbolThick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,this.baseSymbolThick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
- var newMesh = subCSG.toMesh("Door", this.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- //newMesh.rotation.x = Math.PI / 2;
- this.roomWallMeshes.push(newMesh);
- cubeMesh4.dispose();
- cubeMesh2.dispose();
- if(this.doormaterial==null)
- {
- this.setdoormaterial();
- }
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,20);
- cubeMesh3.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- cubeMesh3.rotation.y=-location.angle;
- //cubeMesh3.rotation.x = Math.PI / 2;
- cubeMesh3.material=this.doormaterial;
- this.roomWallMeshes.push(cubeMesh3);
- if(this.doorknobMaterial==null)
- {
- this.setdoorknobMaterial();
- }
- var cubeMesh5=BABYLON.Mesh.CreateBox( "Doorknob", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(2,10,22);
- cubeMesh5.position=new BABYLON.Vector3(location.point.x+5*Math.cos(location.angle),this.doorBottom,location.point.y+5*Math.sin(location.angle));
- cubeMesh5.rotation.y=-location.angle;
- //cubeMesh5.rotation.x = Math.PI / 2;
- cubeMesh5.material=this.doorknobMaterial;
- this.roomWallMeshes.push(cubeMesh5);
-
- var cubeMesh6 = cubeMesh5.clone("cubeMesh5");
- cubeMesh6.position=new BABYLON.Vector3(location.point.x-5*Math.cos(location.angle),this.doorBottom,location.point.y-5*Math.sin(location.angle));
- this.roomWallMeshes.push(cubeMesh6);
-
- return cubeMesh;
- };
- Symbol3D.prototype.drawBiFoldDoor=function(location,len)
- {
- //墙挖洞
- var cubeMesh = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.doorThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- //门框
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.baseSymbolThick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- //门框挖洞
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "BiFoldDoor", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,this.baseSymbolThick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
- var newMesh = subCSG.toMesh("Door", this.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- //newMesh.rotation.x = Math.PI / 2;
- this.roomWallMeshes.push(newMesh);
- cubeMesh4.dispose();
- cubeMesh2.dispose();
- if(this.doormaterial==null)
- {
- this.setdoormaterial();
- }
- //大门
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingDoor", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,20);
- cubeMesh3.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- cubeMesh3.rotation.y=-location.angle;
- //cubeMesh3.rotation.x = Math.PI / 2;
- cubeMesh3.material=this.doormaterial;
- this.roomWallMeshes.push(cubeMesh3);
- if(this.doorknobMaterial==null)
- {
- this.setdoorknobMaterial();
- }
- //门把手
- var cubeMesh5=BABYLON.Mesh.CreateBox( "Doorknob", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(2,10,22);
- cubeMesh5.position=new BABYLON.Vector3(location.point.x+40*Math.cos(location.angle),this.doorBottom,location.point.y+40*Math.sin(location.angle));
- cubeMesh5.rotation.y=-location.angle;
- //cubeMesh5.rotation.x = Math.PI / 2;
- cubeMesh5.material=this.doorknobMaterial;
- this.roomWallMeshes.push(cubeMesh5);
-
- var cubeMesh6 = cubeMesh5.clone("cubeMesh5");
- cubeMesh6.position=new BABYLON.Vector3(location.point.x-40*Math.cos(location.angle),this.doorBottom,location.point.y-40*Math.sin(location.angle));
- this.roomWallMeshes.push(cubeMesh6);
-
- return cubeMesh;
- };
- Symbol3D.prototype.drawDoubleCasement=function(location,len)
- {
- var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.windowHeigh,this.doorThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.windowHeigh,this.baseSymbolThick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.windowHeigh-10,this.baseSymbolThick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
- var newMesh = subCSG.toMesh("Window", this.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- //newMesh.rotation.x = Math.PI / 2;
- this.roomWallMeshes.push(newMesh);
- cubeMesh4.dispose();
- cubeMesh2.dispose();
-
- if(this.windowframeMaterial==null)
- {
- this.setwindowframeMaterial();
- }
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len/2,this.windowHeigh-10,20);
- var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
- var cubeMesh1 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh1.scaling=new BABYLON.Vector3(len/2-11,this.windowHeigh-20,21);
- var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
- var subCSG2 = cCSG.subtract(dCSG);
- var newMesh2 = subCSG2.toMesh("Window", this.windowframeMaterial, this.scene);
- //newMesh2.position=new BABYLON.Vector3(location.point.x,this.windowBottom*2,location.point.y);
- newMesh2.position=new BABYLON.Vector3(location.point.x+25*Math.cos(location.angle),this.windowBottom,location.point.y+25*Math.sin(location.angle));
- newMesh2.rotation.y=-location.angle;
- //newMesh2.rotation.x = Math.PI / 2;
- this.roomWallMeshes.push(newMesh2);
-
- var newMesh3 = newMesh2.clone("cubeMesh5");
- newMesh3.position=new BABYLON.Vector3(location.point.x-25*Math.cos(location.angle),this.windowBottom,location.point.y-25*Math.sin(location.angle));
- //this.roomWallMeshes.push(newMesh3);
- cubeMesh1.dispose();
- cubeMesh3.dispose();
-
- //镜子
- var cubeMesh6 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh6.scaling=new BABYLON.Vector3(len-10,this.windowHeigh,21);
- cubeMesh6.position=new BABYLON.Vector3(location.point.x,this.windowBottom,location.point.y);
- cubeMesh6.rotation.y=-location.angle;
- //cubeMesh6.rotation.x = Math.PI / 2;
- cubeMesh6.visibility = 0.08;
- this.roomWallMeshes.push(cubeMesh6);
-
- if(this.doorknobMaterial==null)
- {
- this.setdoorknobMaterial();
- }
- var cubeMesh5=BABYLON.Mesh.CreateBox( "Windowknob", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(2,22,5);
- cubeMesh5.position=new BABYLON.Vector3(location.point.x+2*Math.cos(location.angle),this.windowBottom,location.point.y+2*Math.sin(location.angle));
- cubeMesh5.rotation.y=-location.angle;
- cubeMesh5.rotation.x = Math.PI / 2;
- cubeMesh5.material=this.doorknobMaterial;
- this.roomWallMeshes.push(cubeMesh5);
-
- var cubeMesh7 = cubeMesh5.clone("cubeMesh5");
- cubeMesh7.position=new BABYLON.Vector3(location.point.x-2*Math.cos(location.angle),this.windowBottom,location.point.y-2*Math.sin(location.angle));
- this.roomWallMeshes.push(cubeMesh7);
-
- return cubeMesh;
- };
- Symbol3D.prototype.drawSlidingWindow=function(location,len)
- {
- var cubeMesh = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.doorThick);
- cubeMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- cubeMesh.rotation.y=-location.angle;
- var cubeMesh2 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh2.scaling=new BABYLON.Vector3(len,this.doorHeigh,this.baseSymbolThick+1);
- var aCSG = BABYLON.CSG.FromMesh(cubeMesh2);
-
- var cubeMesh4 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh4.scaling=new BABYLON.Vector3(len-10,this.doorHeigh-10,this.baseSymbolThick+1);
- var bCSG = BABYLON.CSG.FromMesh(cubeMesh4);
- var subCSG = aCSG.subtract(bCSG);
- var newMesh = subCSG.toMesh("Window", this.frameMaterial, this.scene);
- newMesh.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- newMesh.rotation.y=-location.angle;
- //newMesh.rotation.x = Math.PI / 2;
- this.roomWallMeshes.push(newMesh);
- cubeMesh4.dispose();
- cubeMesh2.dispose();
-
- if(this.windowframeMaterial==null)
- {
- this.setwindowframeMaterial();
- }
- var cubeMesh3 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh3.scaling=new BABYLON.Vector3(len/2-5,this.doorHeigh-10,20);
- var cCSG = BABYLON.CSG.FromMesh(cubeMesh3);
- var cubeMesh1 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh1.scaling=new BABYLON.Vector3(len/2-16,this.doorHeigh-20,21);
- var dCSG = BABYLON.CSG.FromMesh(cubeMesh1);
- var subCSG2 = cCSG.subtract(dCSG);
- var newMesh2 = subCSG2.toMesh("Window", this.windowframeMaterial, this.scene);
- //newMesh2.position=new BABYLON.Vector3(location.point.x,this.windowBottom*2,location.point.y);
- newMesh2.position=new BABYLON.Vector3(location.point.x+25*Math.cos(location.angle),this.doorBottom,location.point.y+25*Math.sin(location.angle));
- newMesh2.rotation.y=-location.angle;
- //newMesh2.rotation.x = Math.PI / 2;
- this.roomWallMeshes.push(newMesh2);
-
- var newMesh3 = newMesh2.clone("cubeMesh5");
- newMesh3.position=new BABYLON.Vector3(location.point.x-25*Math.cos(location.angle),this.doorBottom,location.point.y-25*Math.sin(location.angle));
- //this.roomWallMeshes.push(newMesh3);
- cubeMesh1.dispose();
- cubeMesh3.dispose();
-
- //镜子
- var cubeMesh6 = BABYLON.Mesh.CreateBox( "SlidingWindow", 1, this.scene);
- cubeMesh6.scaling=new BABYLON.Vector3(len-10,this.doorHeigh,21);
- cubeMesh6.position=new BABYLON.Vector3(location.point.x,this.doorBottom,location.point.y);
- cubeMesh6.rotation.y=-location.angle;
- //cubeMesh6.rotation.x = Math.PI / 2;
- cubeMesh6.visibility = 0.08;
- this.roomWallMeshes.push(cubeMesh6);
-
- if(this.doorknobMaterial==null)
- {
- this.setdoorknobMaterial();
- }
- var cubeMesh5=BABYLON.Mesh.CreateBox( "Windowknob", 1, this.scene);
- cubeMesh5.scaling=new BABYLON.Vector3(2,22,5);
- cubeMesh5.position=new BABYLON.Vector3(location.point.x+2*Math.cos(location.angle),this.doorBottom,location.point.y+2*Math.sin(location.angle));
- cubeMesh5.rotation.y=-location.angle;
- cubeMesh5.rotation.x = Math.PI / 2;
- cubeMesh5.material=this.doorknobMaterial;
- this.roomWallMeshes.push(cubeMesh5);
-
- var cubeMesh7 = cubeMesh5.clone("cubeMesh5");
- cubeMesh7.position=new BABYLON.Vector3(location.point.x-2*Math.cos(location.angle),this.doorBottom,location.point.y-2*Math.sin(location.angle));
- this.roomWallMeshes.push(cubeMesh7);
-
- return cubeMesh;
- };
- Symbol3D.prototype.initialize = function ()
- {
- this.createScene();
- this.setgroundmaterial();
- this.setfloormaterial();
- this.addSkybox();
- this.addGround();
- this.addEvent();
- this.setwallmaterial();
-
- };
- Symbol3D.prototype.render= function () {
- this.scene.collisionsEnabled = true;
- //console.log("radius:"+this.camera.radius);
- var scene=this.scene;
-
- var flag=true;
-
- this.engine.runRenderLoop(
- function () {
- scene.render();
- }
- );
- };
- Symbol3D.prototype.refreshSelectMesh = function (currentMesh) {
- for(var i=0;i<this.meshManager.arrowMeshes.length;++i)
- {
- if(this.meshManager.arrowMeshes[i]!=null&&typeof(this.meshManager.arrowMeshes[i]) != "undefined")
- {
- this.meshManager.arrowMeshes[i].dispose();
- this.meshManager.arrowMeshes[i]=null;
- }
- }
- var height = 10;
- var shape = [
- new BABYLON.Vector3(10, 0, 0),
- new BABYLON.Vector3(5, height, 0)
- ];
- var top=1;
- 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;
- if(radius>6)
- {
- top=radius-5;
- }
- var selectmat=new BABYLON.StandardMaterial("selectMat", this.scene);
- selectmat.alpha = 1.0;
- selectmat.diffuseColor = new BABYLON.Color3.Green();
- selectmat.backFaceCulling = false;
-
- this.meshManager.selectCircle = BABYLON.Mesh.CreateLathe('selectCircle', shape , radius,top, this.scene);
- this.meshManager.selectCircle.material = selectmat;
- this.meshManager.selectCircle.position=new BABYLON.Vector3(currentMesh._boundingInfo.boundingBox.center.x,0,currentMesh._boundingInfo.boundingBox.center.z);
-
- if(currentMesh.name.indexOf("pho-")!=0&¤tMesh.name.indexOf("picture-")!=0)
- {
- this.meshManager.rotator = new BABYLON.Mesh.CreatePlane("rotator", 1, this.scene);
- this.meshManager.rotator.scaling.x=28;
- this.meshManager.rotator.scaling.y=14;
- this.meshManager.rotator.material = new BABYLON.StandardMaterial("buttons", this.scene);
- this.meshManager.rotator.material.diffuseTexture = new BABYLON.Texture("images/rotate.png", this.scene);
- this.meshManager.rotator.material.diffuseTexture.hasAlpha = !0;
- this.meshManager.rotator.material.backFaceCulling = !1;
- }
- this.meshManager.rotator.position.z = -radius;
- this.meshManager.rotator.position.y = 0;
- this.meshManager.rotator.parent = this.meshManager.selectCircle;
- this.meshManager.rotator.position.y = Math.PI;
- this.meshManager.rotator.rotation.x = Math.PI / 4;
-
- };
- Symbol3D.prototype.addEvent = function () {
- // Events
- var startingPoint;
- var lastPosition;
- var current;
- var tiledGround;
- //var angle=0;
- var scene =this.scene
- //var tiledGround=this.tiledGround;
- var ground =this.ground;
- var camera =this.camera;
- var canvas =this.canvas;
-
- var currentMesh=null;
- var collidables=this.meshManager.collidables;
- var firstMeshes=this.meshManager.firstMeshes;
- //var editProduct=this.meshManager.editProduct;
- var infosize =this.meshManager.infoSize;
- var selectMesh =this.meshManager.selectMesh;
- var mesh1=this.meshManager.arrowMeshes[0];
- var mesh2=this.meshManager.arrowMeshes[1];
- var mesh3=this.meshManager.arrowMeshes[2];
- var mesh4=this.meshManager.arrowMeshes[3];
- //var furnitureMesh=this.meshManager.selectFurnitureMesh;
- var wallHeigh=this.wallHeigh;
- var createArrow=false;
- var image="images/product/info.png";
- var imagearrow="images/product/arrow.png";
- var imageflip="images/product/infoGroup.png";
- var info=null;
- var infoextend=30;
- var selectCircleY=0;
- var infoheigh=3;
- var min,max;
- var top,down,left,right;
- var vertexPoints=[];
- //var length,heigh;
- //line1是上下arrow的连线,line2是左右两个arrow的连线
- var line1,line2;
- var templane=null;
- var interval=25;
- var arrowdown,arrowtop,arrowleft,arrowright;
- var measuremesh1=null,measuremesh2=null,measuremesh3=null,measuremesh4=null,measuremesh5=null,measuremesh6=null;
- var olddistance=null;
- var oldPlanept=null;
- var measurediff=null;
- var showpoint,showmesh;
- var actionmove=false;
- var actionRotator=false;
- //var picflip=1;
- var flipMesh=null;
- var calculateLine=layer.calculateLine;
- //var calculateLine=new CalculateLine();
-
- //var curPicPho={target:null,colliMesh:null,distance:0};
- var createSelectMat=function()
- {
- var mat=new BABYLON.StandardMaterial("selectMat", scene);
- mat.alpha = 1.0;
- mat.diffuseColor = new BABYLON.Color3.Green();
- mat.backFaceCulling = false;
- return mat;
- };
- var selectmat = createSelectMat();
- collidables.remove = function(elem, all) {
- for (var i=this.length-1; i>=0; i--) {
- if (this[i] === elem) {
- this.splice(i, 1);
- if(!all)
- break;
- }
- }
- return this;
- };
-
- var setProductInfo=function()
- {
- var position_x=document.getElementById("position-x");
- var position_y=document.getElementById("position-y");
- var position_z=document.getElementById("position-z");
-
- var position=my3DEngine.meshManager.selectFurnitureMesh.position;
- position_x.childNodes[1].childNodes[0].value=Math.floor(position.x);
- position_y.childNodes[1].childNodes[0].value=Math.floor(position.y);
- position_z.childNodes[1].childNodes[0].value=Math.floor(position.z);
-
- var params_width=document.getElementById("params-width");
- var params_length=document.getElementById("params-length");
- var width=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowdown.x,arrowdown.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z));
- var length=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowright.x,arrowright.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z));
- params_width.childNodes[1].childNodes[0].value=Math.floor(width);
- params_width.childNodes[1].childNodes[0].alt=Math.floor(width);
- params_length.childNodes[1].childNodes[0].value=Math.floor(length);
- params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
- };
- var editProductInfo=function(h,position)
- {
- var width=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowdown.x,arrowdown.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z));
- var length=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowright.x,arrowright.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z));
- var height=h;
-
- var positionX=position.x;
- var positionY=position.y;
- var positionZ=position.z;
- var angleY=Math.floor((my3DEngine.meshManager.angle/Math.PI)*180);
-
- var rotationy=document.getElementById("rotation-y");
- if(angleY<0)
- {
- angleY=360+angleY;
- }
- rotationy.childNodes[1].childNodes[0].value=angleY;
- rotationy.childNodes[1].childNodes[1].value=angleY;
- var position_x=document.getElementById("position-x");
- position_x.childNodes[1].childNodes[0].value=Math.floor(position.x);
-
- var position_y=document.getElementById("position-y");
- position_y.childNodes[1].childNodes[0].value=Math.floor(position.y);
-
- var position_z=document.getElementById("position-z");
- position_z.childNodes[1].childNodes[0].value=Math.floor(position.z);
-
- var params_width=document.getElementById("params-width");
- params_width.childNodes[1].childNodes[0].value=Math.floor(width);
- params_width.childNodes[1].childNodes[0].alt=Math.floor(width);
-
- var params_length=document.getElementById("params-length");
- params_length.childNodes[1].childNodes[0].value=Math.floor(length);
- params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
-
- var params_height=document.getElementById("params-height");
- params_height.childNodes[1].childNodes[0].value=Math.floor(height);
- params_height.childNodes[1].childNodes[0].alt=Math.floor(height);
- };
-
- var setVertex=function(points,min,max)
- {
- var y=points[0].y;
- var y1=points[1].y;
- var m_points=[];
- for(var i=0;i<points.length;++i)
- {
- if(y.toFixed(2)==points[i].y.toFixed(2)||Math.abs(points[i].y-y)<Math.abs(points[i].y-y1))
- {
- if(points[i].x==min.x&&points[i].z==min.z)
- {
- vertexPoints[0]=i;
- }
- else if(points[i].x==max.x&&points[i].z==max.z)
- {
- vertexPoints[2]=i;
- }
- else if(points[i].x==min.x&&points[i].z==max.z)
- {
- vertexPoints[1]=i;
- }
- else if(points[i].x==max.x&&points[i].z==min.z)
- {
- vertexPoints[3]=i;
- }
- 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))
- {
- vertexPoints[0]=i;
- }
- 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))
- {
- vertexPoints[2]=i;
- }
- 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))
- {
- vertexPoints[1]=i;
- }
- 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))
- {
- vertexPoints[3]=i;
- }
- }
- }
- };
- var createRotator=function()
- {
- var rotator = new BABYLON.Mesh.CreatePlane("rotator", 1, scene);
- rotator.scaling.x=28;
- rotator.scaling.y=14;
- rotator.material = new BABYLON.StandardMaterial("buttons", scene);
- rotator.material.diffuseTexture = new BABYLON.Texture("images/rotate.png", scene);
- rotator.material.diffuseTexture.hasAlpha = !0;
- rotator.material.backFaceCulling = !1;
- return rotator;
- };
-
- var isnotFurniture=function (currentMesh)
- {
- if (typeof(currentMesh.name) == "undefined") {
- return false;
- }
- //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"))
- if(currentMesh.name.indexOf("Door")>=0||currentMesh.name.indexOf("Window")>=0||currentMesh.name=="plane"||currentMesh.name=="skyBox")
- {
- return true;
- }
- else
- {
- return false;
- }
- };
-
- var getWallPlanePosition = function () {
- // Use a predicate to get position on the ground
- var pickinfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) { return mesh.name == "plane"; });
- if (pickinfo.hit) {
- //return {point:pickinfo.pickedPoint,index:pickinfo.pickedMesh.planindex};
- return {point:pickinfo.pickedPoint,index:pickinfo.pickedMesh.planindex};
- }
- return null;
- };
-
- var getGroundPosition = function () {
- // Use a predicate to get position on the ground
- var pickinfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) {
- return (mesh == tiledGround || mesh == ground ||isnotFurniture(mesh));
- });
- if (pickinfo.hit) {
- return pickinfo.pickedPoint;
- }
- return null;
- };
-
- var getGroundPositionFromArrow = function () {
- // Use a predicate to get position on the ground
- var pickinfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) {
- return (mesh == tiledGround || mesh == ground ||isnotFurniture(mesh)||(mesh.id.indexOf("arrow")>-1));
- });
- if (pickinfo.hit) {
- return pickinfo.pickedPoint;
- }
- return null;
- };
-
- var boundcontains=function(point,currentMesh)
- {
- currentMesh.computeWorldMatrix(true);
- currentMesh.refreshBoundingInfo();
- 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)
- {
- return false;
- }
- else
- {
- return true;
- }
- };
- var getDiff=function(diff,line)
- {
- var result;
- if(line.a==0)
- {
- if(line.x)
- {
- result=new BABYLON.Vector3(0,diff.y,diff.z);
- }
- else
- {
- result=new BABYLON.Vector3(diff.x,diff.y,0);
- }
- }
- else
- {
- line.b=0;
- var interpoint=calculateLine.getJoinLinePoint({x:diff.x,y:diff.z},line);
- result=new BABYLON.Vector3(interpoint.x,diff.y,interpoint.y);
- }
- return result;
- };
-
- var getDiff2=function(current,line)
- {
- var result;
- var interpoint=calculateLine.getJoinLinePoint({x:current.x,y:current.z},line);
- result=new BABYLON.Vector3(interpoint.x,current.y,interpoint.y);
- return result;
- };
-
- var setselectMesh=function()
- {
- var height = 10;
- var shape = [
- new BABYLON.Vector3(10, 0, 0),
- new BABYLON.Vector3(5, height, 0)
- ];
- var top=1;
- 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;
- if(radius>6)
- {
- top=radius-5;
- }
- if(my3DEngine.meshManager.selectCircle==null)
- {
- if(currentMesh.name.indexOf("pho-")!=0&¤tMesh.name.indexOf("picture-")!=0)
- {
- my3DEngine.meshManager.selectCircle = BABYLON.Mesh.CreateLathe('selectCircle', shape , radius,top, scene);
- my3DEngine.meshManager.selectCircle.material = selectmat;
- }
- }
- else
- {
- if(currentMesh.name.indexOf("picture-")==0||currentMesh.name.indexOf("pho-")==0)
- {
- my3DEngine.meshManager.selectCircle.dispose();
- my3DEngine.meshManager.selectCircle=null;
- }
- }
-
- if(currentMesh.name.indexOf("pho-")!=0&¤tMesh.name.indexOf("picture-")!=0)
- {
- my3DEngine.meshManager.selectCircle.position=new BABYLON.Vector3(currentMesh._boundingInfo.boundingBox.center.x,selectCircleY,currentMesh._boundingInfo.boundingBox.center.z);
- if(my3DEngine.meshManager.rotator==null)
- {
- my3DEngine.meshManager.rotator=createRotator();
- }
- my3DEngine.meshManager.rotator.position.z = -radius;
- my3DEngine.meshManager.rotator.position.y = selectCircleY;
- if(my3DEngine.meshManager.selectCircle!=null)
- {
- my3DEngine.meshManager.rotator.parent = my3DEngine.meshManager.selectCircle;
- }
- my3DEngine.meshManager.rotator.position.y = Math.PI;
- my3DEngine.meshManager.rotator.rotation.x = Math.PI / 4;
- }
- else
- {
- if(my3DEngine.meshManager.rotator!=null)
- {
- my3DEngine.meshManager.rotator.dispose();
- my3DEngine.meshManager.rotator=null;
- }
- }
- if(my3DEngine.meshManager.selectFurnitureMesh.rotationQuaternion==null||typeof(my3DEngine.meshManager.selectFurnitureMesh.rotationQuaternion) == "undefined")
- {
- my3DEngine.meshManager.angle=0;
- }
- else
- {
- //var angleY=my3DEngine.meshManager.selectFurnitureMesh.rotationQuaternion.y;
- var angleY=my3DEngine.meshManager.selectFurnitureMesh.rotation.y;
- if(angleY<0)
- {
- angleY=2*Math.PI+angleY;
- }
- my3DEngine.meshManager.angle=angleY;
- }
- };
- var createinfo=function()
- {
- var sprite = new BABYLON.SpriteManager("meshManager", image, 6, 128, scene);
- sprite.isPickable = true;
- // First animated player
- info = new BABYLON.Sprite("editFurniture", sprite);
- info.position= new BABYLON.Vector3(currentMesh.position.x, currentMesh._boundingInfo.boundingBox.maximumWorld.y+infoextend, currentMesh.position.z);
- //if(currentMesh.name.indexOf("picture-")==0||currentMesh.name.indexOf("pho-")==0)
- //{
- // info.position.y=(currentMesh._boundingInfo.boundingBox.maximumWorld.y+ currentMesh._boundingInfo.boundingBox.minimumWorld.y)/2;
- //}
- info.size = infosize;
-
- infoheigh=currentMesh._boundingInfo.boundingBox.maximumWorld.y/2;
-
- // click action for player
- info.actionManager = new BABYLON.ActionManager(scene);
- info.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickUpTrigger, function () {
- if(!actionmove)
- {
- if(!createArrow)
- {
- currentMesh.computeWorldMatrix(true);
- currentMesh.refreshBoundingInfo();
- var configuratorProduct=document.getElementById("configuratorWindow");
- configuratorProduct.style.display="block";
- /*
- if(currentMesh.name.indexOf("picture-")==0||currentMesh.name.indexOf("pho-")==0)
- {
- createArrows2(currentMesh,scene,imagearrow);
- document.getElementById("editptrot").innerText="位置";
- document.getElementById("item-1").style.display="none";
- document.getElementById("rotation-y").style.display="none";
- document.getElementById("params-height").style.display="none";
- }
- else
- {
- */
- createArrows(currentMesh,scene,imagearrow);
- document.getElementById("editptrot").innerText="位置和角度";
- document.getElementById("item-1").style.display="";
- document.getElementById("rotation-y").style.display="";
- document.getElementById("params-height").style.display="";
- //}
-
- createArrow=true;
- info.dispose();
- info=null;
- if(my3DEngine.meshManager.selectCircle!=null)
- {
- my3DEngine.meshManager.selectCircle.dispose();
- my3DEngine.meshManager.selectCircle=null;
- if(my3DEngine.meshManager.rotator!=null)
- {
- my3DEngine.meshManager.rotator.dispose();
- my3DEngine.meshManager.rotator=null;
- }
- }
-
- editProductInfo(Math.abs(currentMesh._boundingInfo.boundingBox.maximumWorld.y- currentMesh._boundingInfo.boundingBox.minimumWorld.y),currentMesh.position);
- }
- my3DEngine.meshManager.editProduct=true;
- }
- }));
- info.isPickable = true;
- };
- var selectArrow=function()
- {
- templane=BABYLON.Mesh.CreatePlane("temp", 1, scene);
-
- if(currentMesh.name=="downarrow")
- {
- templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.x*my3DEngine.meshManager.selectFurnitureMesh.scaling.x*2;
- templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
- templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle, BABYLON.Space.LOCAL);
- templane.position=arrowdown;
- olddistance=BABYLON.Vector3.Distance(arrowdown,arrowtop);
-
- var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z));
- var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowright.x,arrowright.z));
- if(distance1>distance2)
- {
- showpoint=arrowright;
- showmesh=mesh4;
- }
- else
- {
- showpoint=arrowleft;
- showmesh=mesh3;
- }
-
- }
- else if(currentMesh.name=="toparrow")
- {
- templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.x*my3DEngine.meshManager.selectFurnitureMesh.scaling.x*2;
- templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
- templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle, BABYLON.Space.LOCAL);
- templane.position=arrowtop;
- //templane.position=new BABYLON.Vector3(arrowtop.x,arrowtop.y,arrowtop.z);
- olddistance=BABYLON.Vector3.Distance(arrowdown,arrowtop);
-
- var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z));
- var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowright.x,arrowright.z));
- if(distance1>distance2)
- {
- showpoint=arrowright;
- showmesh=mesh4;
- }
- else
- {
- showpoint=arrowleft;
- showmesh=mesh3;
- }
- }
- else if(currentMesh.name=="leftarrow")
- {
- /*
- if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")==0||my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")==0)
- {
- templane.rotate(BABYLON.Axis.Y,Math.PI/2, BABYLON.Space.LOCAL);
- templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
- templane.scaling.y=10;
- }
- else
- {
- */
- templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle+Math.PI/2, BABYLON.Space.LOCAL);
- templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.z*my3DEngine.meshManager.selectFurnitureMesh.scaling.z*2;
- templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
- //}
-
- templane.position=arrowleft;
- //templane.position=new BABYLON.Vector3(arrowleft.x,arrowleft.y,arrowleft.z);
- olddistance=BABYLON.Vector3.Distance(arrowleft,arrowright);
-
- var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z));
- var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowdown.x,arrowdown.z));
- if(distance1>distance2)
- {
- showpoint=arrowdown;
- showmesh=mesh1;
- }
- else
- {
- showpoint=arrowtop;
- showmesh=mesh2;
- }
- }
- else if(currentMesh.name=="rightarrow")
- {
- /*
- if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")==0||my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")==0)
- {
- templane.rotate(BABYLON.Axis.Y,-Math.PI/2, BABYLON.Space.LOCAL);
- templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
- templane.scaling.y=10;
- }
- else
- {
- */
- templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle+Math.PI/2, BABYLON.Space.LOCAL);
- templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.z*my3DEngine.meshManager.selectFurnitureMesh.scaling.z*2;
- templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2;
- //}
-
- templane.position=arrowright;
- //templane.position=new BABYLON.Vector3(arrowright.x,arrowright.y,arrowright.z);
- olddistance=BABYLON.Vector3.Distance(arrowleft,arrowright);
-
- var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z));
- var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowdown.x,arrowdown.z));
- if(distance1>distance2)
- {
- showpoint=arrowdown;
- showmesh=mesh1;
- }
- else
- {
- showpoint=arrowtop;
- showmesh=mesh2;
- }
- }
- measurediff=showmesh.position.subtract(my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center);
- var r=new BABYLON.StandardMaterial("materialplane",scene);
- r.diffuseColor=new BABYLON.Color3.Green();
- r.backFaceCulling =false;
- templane.material=r;
- oldPlanept=new BABYLON.Vector3(templane.position.x,templane.position.y,templane.position.z);
- };
-
- var removeinfo=function()
- {
- if(info!=null&&!info._isDisposed)
- {
- info.dispose();
- info=null;
- }
-
- my3DEngine.meshManager.editProduct=false;
- clearArrow();
-
- if(my3DEngine.meshManager.selectCircle!=null)
- {
- my3DEngine.meshManager.selectCircle.dispose();
- my3DEngine.meshManager.selectCircle=null;
- if(my3DEngine.meshManager.rotator!=null)
- {
- my3DEngine.meshManager.rotator.dispose();
- my3DEngine.meshManager.rotator=null;
- }
- }
- };
-
- var removeSelectMesh=function()
- {
- if(my3DEngine.meshManager.selectFurnitureMesh!=null&&typeof(my3DEngine.meshManager.selectFurnitureMesh) != "undefined")
- {
- collidables.push(my3DEngine.meshManager.selectFurnitureMesh);
- my3DEngine.meshManager.selectFurnitureMesh=null;
- }
-
- if(currentMesh==null||typeof(currentMesh) == "undefined")
- {
- return;
- }
- removeinfo();
- };
- var finishEditMesh=function()
- {
- if(templane!=null)
- {
- if(olddistance!=null)
- {
- var dxz=templane.position.subtract(oldPlanept);
- var newscal,m_newdistance,m_olddistance;
- if(currentMesh.name=="downarrow")
- {
- m_newdistance=arrowdown.subtract(arrowtop);
- m_olddistance=oldPlanept.subtract(arrowtop);
- }
- else if(currentMesh.name=="toparrow")
- {
- m_newdistance=arrowtop.subtract(arrowdown);
- m_olddistance=oldPlanept.subtract(arrowdown);
- }
- else if(currentMesh.name=="leftarrow")
- {
- m_newdistance=arrowleft.subtract(arrowright);
- m_olddistance=oldPlanept.subtract(arrowright);
- }
- else if(currentMesh.name=="rightarrow")
- {
- m_newdistance=arrowright.subtract(arrowleft);
- m_olddistance=oldPlanept.subtract(arrowleft);
- }
- 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));
-
- if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow")
- {
- if(!isNaN(newscal.z)&&newscal.z!=-Number.POSITIVE_INFINITY&&newscal.z!=Number.POSITIVE_INFINITY)
- {
- /*
- if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")==0||my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")==0)
- {
- my3DEngine.meshManager.selectFurnitureMesh.scaling.y=m_newdistance.z.toFixed(2)/m_olddistance.z.toFixed(2)*my3DEngine.meshManager.selectFurnitureMesh.scaling.y.toFixed(2)
- }
- else
- {
- */
- my3DEngine.meshManager.selectFurnitureMesh.scaling.z=newscal.z;
- //}
-
- }
- }
- else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow")
- {
- if(!isNaN(newscal.x)&&newscal.x!=-Number.POSITIVE_INFINITY&&newscal.x!=Number.POSITIVE_INFINITY)
- {
- my3DEngine.meshManager.selectFurnitureMesh.scaling.x=newscal.x;
- }
- }
- my3DEngine.meshManager.selectFurnitureMesh.computeWorldMatrix(true);
- my3DEngine.meshManager.selectFurnitureMesh.refreshBoundingInfo();
- var dxz2;
- if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow")
- {
- dxz2=my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center.subtract(new BABYLON.Vector3((arrowdown.x+arrowtop.x)/2,0,(arrowdown.z+arrowtop.z)/2));
- my3DEngine.meshManager.selectFurnitureMesh.position.addInPlace(new BABYLON.Vector3(-dxz2.x,0,-dxz2.z));
- arrowleft.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
- arrowright.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
- }
- else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow")
- {
- dxz2=my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center.subtract(new BABYLON.Vector3((arrowleft.x+arrowright.x)/2,0,(arrowleft.z+arrowright.z)/2));
- my3DEngine.meshManager.selectFurnitureMesh.position.addInPlace(new BABYLON.Vector3(-dxz2.x,0,-dxz2.z));
- arrowtop.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
- arrowdown.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
- }
- line1=calculateLine.createLine(new BABYLON.Vector2(arrowdown.x,arrowdown.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z));
- line2=calculateLine.createLine(new BABYLON.Vector2(arrowleft.x,arrowleft.z),new BABYLON.Vector2(arrowright.x,arrowright.z));
- }
- templane.dispose();
- templane=null;
- olddistance=null;
- }
- };
- var editingMesh=function(type)
- {
- var newpoint;
- clearMeasureMesh();
- if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow")
- {
- if(type==1)
- {
- newpoint=getDiff2(current,line1);
- newpoint.y=currentMesh.position.y;
- }
- else //针对相框和墙贴
- {
- newpoint=new BABYLON.Vector3(line1.x,currentMesh.position.y,current.z);
- }
- diff2=showpoint.subtract(my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center);
- diff3=measurediff;
-
- ddif=diff3.subtract(diff2);
- ddif.x=ddif.x/4;
- ddif.y=ddif.y/4;
- ddif.z=ddif.z/4;
- startpoint=arrowtop.add(diff3);
- startpoint.addInPlace(ddif);
- endpoint=arrowdown.add(diff3);
- endpoint.addInPlace(ddif);
-
- var fontpt=new BABYLON.Vector3((startpoint.x+endpoint.x)/2,(startpoint.y+endpoint.y)/2,(startpoint.z+endpoint.z)/2);
- fontpt.addInPlace(ddif);
- measuremesh6 = makeTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", 50,fontpt);
- measuremesh6.rotation.x=Math.PI/2;
- if(showmesh.name=="rightarrow")
- {
- measuremesh6.rotation.y=-Math.PI/2+my3DEngine.meshManager.angle;
- }
- else
- {
- measuremesh6.rotation.y=Math.PI/2+my3DEngine.meshManager.angle;
- }
- }
- else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow")
- {
- if(type==1)
- {
- newpoint=getDiff2(current,line2);
- newpoint.y=currentMesh.position.y;
- }
- else
- {
- newpoint=new BABYLON.Vector3(line2.y,currentMesh.position.y,current.x);
- }
- diff2=showpoint.subtract(my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center);
- diff3=measurediff;
-
- ddif=diff3.subtract(diff2);
- ddif.x=ddif.x/4;
- ddif.y=ddif.y/4;
- ddif.z=ddif.z/4;
- startpoint=arrowleft.add(diff3);
- startpoint.addInPlace(ddif);
- endpoint=arrowright.add(diff3);
- endpoint.addInPlace(ddif);
-
- var fontpt=new BABYLON.Vector3((startpoint.x+endpoint.x)/2,(startpoint.y+endpoint.y)/2,(startpoint.z+endpoint.z)/2);
- fontpt.addInPlace(ddif);
- measuremesh6 = makeTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", 50,fontpt);
- measuremesh6.rotation.x=Math.PI/2;
- if(showmesh.name=="toparrow")
- {
- measuremesh6.rotation.y=Math.PI+my3DEngine.meshManager.angle;
- if(measuremesh6.rotation.y>2*Math.PI)
- {
- measuremesh6.rotation.y-=2*Math.PI;
- }
- }
- }
- var startpoint1=startpoint.add(ddif);
- var startpoint2=startpoint.subtract(ddif);
-
- var endpoint1=endpoint.add(ddif);
- var endpoint2=endpoint.subtract(ddif);
-
- measuremesh1=BABYLON.Mesh.CreateLines("start",[startpoint1,startpoint2],scene);
- measuremesh2=BABYLON.Mesh.CreateLines("end",[endpoint1,endpoint2],scene);
- measuremesh3=BABYLON.Mesh.CreateLines("end",[startpoint,endpoint],scene);
- var pts1=drawArrow({x:startpoint.x,y:startpoint.z},{x:endpoint.x,y:endpoint.z},endpoint.y);
- var pts2=drawArrow({x:endpoint.x,y:endpoint.z},{x:startpoint.x,y:startpoint.z},startpoint.y);
- measuremesh4=BABYLON.Mesh.CreateLines("arrowend",pts1,scene);
- measuremesh5=BABYLON.Mesh.CreateLines("arrowstart",pts2,scene);
- measuremesh1.color = new BABYLON.Color3.Black();
- measuremesh2.color = new BABYLON.Color3.Black();
- measuremesh3.color = new BABYLON.Color3.Black();
- measuremesh4.color = new BABYLON.Color3.Black();
- measuremesh5.color = new BABYLON.Color3.Black();
- return newpoint;
- };
-
- var closeConfigProduct=function()
- {
- var configuratorProduct=document.getElementById("configuratorWindow");
- configuratorProduct.style.display="none";
- };
- var paintWallFromSubMesh=function(subMeshId)
- {
- var addMat = new BABYLON.StandardMaterial("paint", scene);
- addMat.alpha = 1.0;
- var r=my3DEngine.paintWall.value.r;
- var g=my3DEngine.paintWall.value.g;
- var b=my3DEngine.paintWall.value.b;
-
-
- addMat.diffuseColor = new BABYLON.Color3(r, g, b);
- addMat.specularColor =new BABYLON.Color3(r, g, b);
- addMat.emissiveColor = new BABYLON.Color3(r, g, b);
-
- addMat.backFaceCulling = false;
- addMat.toward=currentMesh.material.subMaterials[subMeshId/2].toward;
- currentMesh.material.subMaterials[subMeshId/2]=addMat;
- //currentMesh.applyDisplacementMap("http://3.bp.blogspot.com/-0ceB5kqwo70/TgF9neqSuKI/AAAAAAAAKCc/cdK47cIp-ZY/s1600/PUMPKIN+CARVINGS+FACE.jpg", -0.5, 0);
- startingPoint=null;
- var flag=false;
-
- for(var i=0;i<my3DEngine.paintSet.length;++i)
- {
- if(my3DEngine.paintSet[i].type=="wall"&&my3DEngine.paintSet[i].wallId==currentMesh.id&&my3DEngine.paintSet[i].materialId==subMeshId/2)
- {
- my3DEngine.paintSet[i].material=addMat;
- flag=true;
- break;
- }
- }
- if(!flag)
- {
- my3DEngine.paintSet.push({wallId:currentMesh.id,materialId:subMeshId/2,material:addMat,type:"wall"});
- }
-
- document.getElementById("container3d").style.cursor="default";
- };
-
- var onPointerDown = function (evt) {
- if(this.lock)
- {
- return;
- }
- actionmove=false;
- if (evt.button !== 0&&evt.button !== 2) {
- return;
- }
- startingPoint = getGroundPosition(evt);
- if(evt.button == 2)
- {
- if (startingPoint) { // we need to disconnect camera from canvas
- setTimeout(function () {
- camera.detachControl(canvas);
- }, 0);
- }
- }
-
- // check if we are under a mesh
- var pickInfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) {
- return (mesh !== tiledGround && mesh !== ground&&!isnotFurniture(mesh) );
- });
-
- if (pickInfo.hit) {
- currentMesh= pickInfo.pickedMesh;
-
- if(currentMesh.name.indexOf("wall")>=0)
- {
-
- if(my3DEngine.paintWall.beginPaint)
- {
- paintWallFromSubMesh(pickInfo.subMeshId);
- my3DEngine.paintWall.beginPaint=false;
- }
- else if(my3DEngine.phoSet.start)
- {
- my3DEngine.phoSet.start=false;
- document.getElementById("container3d").style.cursor="default";
- var joinpoint=pickInfo.pickedPoint;
- var toward= currentMesh.material.subMaterials[pickInfo.subMeshId/2].toward;
- var indexplane=currentMesh.material.subMaterials[pickInfo.subMeshId/2].indexplane;
- var point1=currentMesh.material.subMaterials[pickInfo.subMeshId/2].points.point1;
- var point2=currentMesh.material.subMaterials[pickInfo.subMeshId/2].points.point2;
- var tempjoin=calculateLine.getPositionIntersect3D(point1,point2,toward,my3DEngine.phoSet.photoFrameMesh.thice,joinpoint);
-
- var tempjoin1=new BABYLON.Vector3(tempjoin.point1.x,tempjoin.point1.y,tempjoin.point1.z);
- var tempjoin2=new BABYLON.Vector3(tempjoin.point2.x,tempjoin.point2.y,tempjoin.point2.z);
-
- my3DEngine.phoSet.photoFrameMesh.rotation.y=collidables[indexplane].rotation.y;
-
- my3DEngine.phoSet.photoFrameMesh.position=tempjoin1;
-
- my3DEngine.phoSet.photoFrameMesh.computeWorldMatrix(true);
- my3DEngine.phoSet.photoFrameMesh.refreshBoundingInfo();
- if(my3DEngine.phoSet.photoFrameMesh._boundingInfo.boundingBox.maximumWorld.y>wallHeigh||my3DEngine.phoSet.photoFrameMesh._boundingInfo.boundingBox.minimumWorld.y<0)
- {
- my3DEngine.phoSet.photoFrameMesh.position.y=wallHeigh/2;
- tempjoin1.y=wallHeigh/2;
- tempjoin2.y=wallHeigh/2;
- }
-
- my3DEngine.phoSet.photoFrameMesh.planeindex=pickInfo.subMeshId/2;
-
- var diffplane=tempjoin2.subtract(tempjoin1);
- if(diffplane.x==0&&diffplane.y==0&&diffplane.z==0)
- {
- my3DEngine.phoSet.photoFrameMesh.visibility=1;
- alert("2275");
- return ;
- }
- else
- {
- var add=1;
- while(!collidables[indexplane].intersectsMesh(my3DEngine.phoSet.photoFrameMesh, true))
- {
- tempjoin1.addInPlace(new BABYLON.Vector3(diffplane.x*0.1,diffplane.y*0.1,diffplane.z*0.1));
- ++add;
- if(add>19)
- {
- //alert(2324);
- break;
- }
- my3DEngine.phoSet.photoFrameMesh.position=tempjoin1;
- my3DEngine.phoSet.photoFrameMesh.computeWorldMatrix(true);
- my3DEngine.phoSet.photoFrameMesh.refreshBoundingInfo();
- }
- my3DEngine.phoSet.photoFrameMesh.visibility=1;
-
- var fontpt=my3DEngine.phoSet.photoFrameMesh._boundingInfo.boundingBox.vectorsWorld[my3DEngine.phoSet.photoFrameMesh.frontindex];
- var toward2=calculateLine.getToward(point1,point2,{x:fontpt.x,y:fontpt.z});
- if(toward!=toward2)
- {
- my3DEngine.phoSet.photoFrameMesh.rotation.y+=Math.PI;
- }
- if(my3DEngine.phoSet.photoFrameMesh.rotation.y>=2*Math.PI)
- {
- my3DEngine.phoSet.photoFrameMesh.rotation.y-=2*Math.PI;
- }
-
- for(var i=0;i<collidables.length;++i)
- {
- if(i==indexplane)
- {
- continue;
- }
- if(collidables[i].intersectsMesh(my3DEngine.phoSet.photoFrameMesh, true))
- {
- my3DEngine.phoSet.photoFrameMesh.position.y=-100;
- my3DEngine.phoSet.photoFrameMesh.visibility=0;
- return;
- }
- }
-
- return;
- }
-
- }
- else
- {
- removeSelectMesh();
- closeConfigProduct();
- return;
- }
-
- return;
- }
- else if(currentMesh.name.indexOf("floor")>=0)
- {
- if(!my3DEngine.paintPlane.beginPaint)
- {
- removeSelectMesh();
- closeConfigProduct();
- return;
- }
- else
- {
- my3DEngine.paintPlane.beginPaint=false;
- }
-
- my3DEngine.paintPlane.currentId=currentMesh.id;
- my3DEngine.refreshFloor(currentMesh.wallid);
- return;
- }
- else if(currentMesh.name.indexOf("pho-")>=0||currentMesh.name.indexOf("picture-")>=0)
- {
- var configuratorProduct=document.getElementById("configuratorWindow");
- configuratorProduct.style.display="block";
- document.getElementById("editptrot").style.display="none";
- document.getElementById("item-1").style.display="none";
- document.getElementById("rotation-y").style.display="none";
- document.getElementById("params-width").style.display="none";
- var params_height=document.getElementById("params-height");
- var params_length=document.getElementById("params-length");
-
- //var height=Math.abs(currentMesh._boundingInfo.boundingBox.maximumWorld.y-currentMesh._boundingInfo.boundingBox.minimumWorld.y);
- //var length=Math.abs(currentMesh._boundingInfo.boundingBox.maximumWorld.x-currentMesh._boundingInfo.boundingBox.minimumWorld.x);
- var height=currentMesh.height;
- var length=currentMesh.length;
-
- params_height.childNodes[1].childNodes[0].value=Math.floor(height);
- params_height.childNodes[1].childNodes[0].alt=Math.floor(height);
- params_length.childNodes[1].childNodes[0].value=Math.floor(length);
- params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
-
- selectMesh=true;
- setTimeout(function () {
- camera.detachControl(canvas);
- }, 0);
- return;
- }
- selectMesh=true;
-
- if(currentMesh.name=="selectCircle"||currentMesh.name=="rotator")
- {
- actionRotator=true;
- setTimeout(function () {
- camera.detachControl(canvas);
- }, 0);
- return;
- }
- actionRotator=false;
-
- if(my3DEngine.meshManager.editProduct)
- {
- if(my3DEngine.meshManager.selectFurnitureMesh!=null&¤tMesh.name.indexOf("arrow")>-1)
- {
- selectArrow();
- }
- else if(currentMesh.name.indexOf("arrow")<0)
- {
- clearArrow();
- closeConfigProduct();
- my3DEngine.meshManager.editProduct=false;
-
- if(my3DEngine.meshManager.selectFurnitureMesh.name!=currentMesh.name)
- {
- removeSelectMesh();
- my3DEngine.meshManager.selectFurnitureMesh=currentMesh;
- }
- setselectMesh();
- createinfo();
- createArrow=false;
- setVertex(currentMesh._boundingInfo.boundingBox.vectorsWorld,currentMesh._boundingInfo.boundingBox.minimumWorld,currentMesh._boundingInfo.boundingBox.maximumWorld);
- collidables.remove(currentMesh);
-
- }
- else
- {
- alert("error1729");
- }
- }
- else
- {
-
- if(typeof(my3DEngine.meshManager.selectFurnitureMesh) != "undefined"&&my3DEngine.meshManager.selectFurnitureMesh!=null)
- {
- if(my3DEngine.meshManager.selectFurnitureMesh.name!=currentMesh.name)
- {
- removeSelectMesh();
- my3DEngine.meshManager.selectFurnitureMesh=currentMesh;
- collidables.remove(currentMesh);
- setselectMesh();
- }
- else
- {
- collidables.remove(currentMesh);
- }
- lastPosition=startingPoint;
- }
- else
- {
- collidables.remove(currentMesh);
- my3DEngine.meshManager.selectFurnitureMesh=currentMesh;
- }
-
- if(typeof(currentMesh.rotationQuaternion) != "undefined"&¤tMesh.rotationQuaternion!=null)
- {
- //my3DEngine.meshManager.angle=currentMesh.rotationQuaternion.y;
- my3DEngine.meshManager.angle=currentMesh.rotation.y;
- }
-
-
- if(info==null)
- {
- if(my3DEngine.meshManager.selectCircle==null)
- {
- setselectMesh();
- }
- else
- {
- my3DEngine.meshManager.selectCircle.position=new BABYLON.Vector3(currentMesh._boundingInfo.boundingBox.center.x,selectCircleY,currentMesh._boundingInfo.boundingBox.center.z);
- }
- createinfo();
- createArrow=false;
- setVertex(currentMesh._boundingInfo.boundingBox.vectorsWorld,currentMesh._boundingInfo.boundingBox.minimumWorld,currentMesh._boundingInfo.boundingBox.maximumWorld);
- }
- else
- {
- info.position= new BABYLON.Vector3(currentMesh.position.x, currentMesh._boundingInfo.boundingBox.maximumWorld.y+15, currentMesh.position.z);
- }
- }
-
- if (startingPoint) { // we need to disconnect camera from canvas
- setTimeout(function () {
- camera.detachControl(canvas);
- }, 0);
- }
- }
- else
- {
- removeSelectMesh();
- closeConfigProduct();
- }
- }.bind(this);
- var onPointerUp = function () {
- if(this.lock)
- {
- return;
- }
- if (startingPoint) {
- camera.attachControl(canvas, true);
- startingPoint = null;
- if(my3DEngine.meshManager.editProduct)
- {
- finishEditMesh();
- clearMeasureMesh();
- setProductInfo();
- }
-
- actionRotator=false;
- selectMesh=false;
- return;
- }
- };
-
- var drawArrow= function( p0, p1,height){
- var _ANGLE = 20;
- var _RADIUS = 10.0;
- var _ANGLE_CROSS = 90.0;
-
- var result=[];
-
- var nP = {};
- var angle = Math.atan2(p0.x-p1.x, p0.y-p1.y);
-
- result.push(new BABYLON.Vector3(p1.x,height,p1.y));
- //rotate by _ANGLE
- var tAngle = angle - _ANGLE * Math.PI/180.0;
- nP.x = parseFloat(p1.x) + _RADIUS * Math.sin(tAngle);
- nP.y = parseFloat(p1.y) + _RADIUS * Math.cos(tAngle);
-
- result.push(new BABYLON.Vector3(nP.x,height,nP.y));
- //lower part
- tAngle = angle + _ANGLE * Math.PI/180.0;
- nP.x = parseFloat(p1.x) + _RADIUS * Math.sin(tAngle);
- nP.y = parseFloat(p1.y) + _RADIUS * Math.cos(tAngle);
- result.push(new BABYLON.Vector3(p1.x,height,p1.y));
- result.push(new BABYLON.Vector3(nP.x,height,nP.y));
-
- return result;
- };
- var clearMeasureMesh=function()
- {
- if(measuremesh1!=null)
- {
- measuremesh1.dispose();
- measuremesh1=null;
- }
- if(measuremesh2!=null)
- {
- measuremesh2.dispose();
- measuremesh2=null;
- }
- if(measuremesh3!=null)
- {
- measuremesh3.dispose();
- measuremesh3=null;
- }
- if(measuremesh4!=null)
- {
- measuremesh4.dispose();
- measuremesh4=null;
- }
- if(measuremesh5!=null)
- {
- measuremesh5.dispose();
- measuremesh5=null;
- }
- if(measuremesh6!=null)
- {
- measuremesh6.dispose();
- measuremesh6=null;
- }
- };
-
- var makeTextPlane = function(text, color,size,position) {
- var dynamicTexture = new BABYLON.DynamicTexture("DynamicTexture", 50, scene, true);
- dynamicTexture.hasAlpha = true;
-
- var plane = BABYLON.Mesh.CreatePlane("TextPlane", size, scene, true);
- plane.material = new BABYLON.StandardMaterial("TextPlaneMaterial", scene);
- plane.material.backFaceCulling = false;
- plane.material.specularColor = new BABYLON.Color3(0, 0, 0);
- plane.material.diffuseTexture = dynamicTexture;
- plane.position=position;
- dynamicTexture._context.font = "bold 12px Arial";
- var textSize=dynamicTexture._context.measureText(text);
- if(size<textSize.width)
- {
- size=Math.floor(1+textSize.width);
- }
- var x = (size - textSize.width) / 2;
- dynamicTexture.drawText(text, x, 40, "bold 12px Arial", color , "transparent", true);
-
- return plane;
- };
-
-
- /*
- var setPhoPosition=function(angle,pt,position,thice)
- {
- var calculateLine=new CalculateLine();
- var line;
- var b=pt.z-pt.x*(Math.tan(angle));
- if(angle==0)
- {
- line={a:0,y:pt.z};
- }
- else if(angle==Math.PI/2||angle==-1.5*Math.PI)
- {
- line={a:0,x:pt.x};
- }
- else
- {
- line={a:Math.tan(angle),b:b};
- }
- var cross=calculateLine.getJoinLinePoint(position,line);
- cross=new BABYLON.Vector3(cross.x,position.y,cross.y);
- curPicPho.target=new BABYLON.Vector3(cross.x,cross.y,cross.z);
- var diff=position.subtract(cross);
- var distance=BABYLON.Vector2.Distance(new BABYLON.Vector2(cross.x,cross.z),new BABYLON.Vector2(position.x,position.z));
- diff.x=diff.x*thice/distance;
- diff.y=0;
- diff.z=diff.z*thice/distance;
- cross.addInPlace(diff);
- return cross;
- }
- */
-
- var onPointerMove = function (evt) {
-
- if(this.lock)
- {
- return;
- }
-
- if (!startingPoint) {
- return;
- }
-
- current = getGroundPosition(evt);
-
- var diff = current.subtract(startingPoint).normalize();
- if (evt.button == 2)
- {
- if(current==null)
- {
- evt.stopPropagation();
- return;
- }
- camera.target.addInPlace(new BABYLON.Vector3(diff.x*5,camera.target.y,diff.z*5));
- startingPoint=current;
- return;
- }
-
- if(!selectMesh)
- {
- evt.stopPropagation();
- return;
- }
-
- if(my3DEngine.meshManager.editProduct)
- {
- if(createArrow)
- {
- current=getGroundPositionFromArrow(evt);
- if(currentMesh.name.indexOf("arrow")>-1)
- {
- if(diff.x==0&&diff.z==0)
- {
- return;
- }
- else
- {
- var diff2,diff3;
- var startpoint,endpoint;
-
- var newpoint=editingMesh(1);
- diff = newpoint.subtract(currentMesh.position);
- templane.position.addInPlace(diff);
- if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow")
- {
- mesh3.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
- mesh4.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
- }
- else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow")
- {
- mesh1.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
- mesh2.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
- }
- currentMesh.position=newpoint;
-
- my3DEngine.meshManager.selectFurnitureMesh.computeWorldMatrix(true);
- my3DEngine.meshManager.selectFurnitureMesh.refreshBoundingInfo();
- }
- startingPoint = current;
- }
- evt.stopPropagation();
- return;
- }
- evt.stopPropagation();
- return;
- }
-
- if(actionRotator)
- {
- 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));
- 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));
- if(my3DEngine.meshManager.angle==null||typeof(my3DEngine.meshManager.angle)=="undefined")
- {
- my3DEngine.meshManager.angle=angle1._radians-angle2._radians;
- }
- else
- {
- my3DEngine.meshManager.angle+=angle1._radians-angle2._radians;
- }
- my3DEngine.meshManager.selectCircle.rotate(BABYLON.Axis.Y, angle1._radians-angle2._radians, BABYLON.Space.LOCAL);
-
- my3DEngine.meshManager.selectCircle.rotation.y+=angle1._radians-angle2._radians;
-
- //if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")!=0&&my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")!=0)
- //{
- my3DEngine.meshManager.selectFurnitureMesh.rotate(BABYLON.Axis.Y, angle1._radians-angle2._radians, BABYLON.Space.LOCAL);
- my3DEngine.meshManager.selectFurnitureMesh.rotation.y+=angle1._radians-angle2._radians;
-
- my3DEngine.meshManager.angle=my3DEngine.meshManager.selectFurnitureMesh.rotation.y;
- //}
- //console.log("selectFurnitureMesh:"+my3DEngine.meshManager.selectFurnitureMesh.rotation.y+",selectCircle:"+my3DEngine.meshManager.selectCircle.rotation.y);
- startingPoint = current;
- }
-
- if (!current||!currentMesh) {
- evt.stopPropagation();
- return;
- }
-
- if((currentMesh.name.indexOf("pho-")==0||currentMesh.name.indexOf("picture-")==0))
- {
- var m_pt=getWallPlanePosition();
- if(m_pt!=null)
- {
- var temp_last=null;
- var temp_pt =new BABYLON.Vector3(currentMesh.position.x,currentMesh.position.y,currentMesh.position.z);
-
- if(currentMesh.lastPos!=null&&typeof(currentMesh.lastPos) != "undefined")
- {
- temp_last=new BABYLON.Vector3(currentMesh.lastPos.x,currentMesh.lastPos.y,currentMesh.lastPos.z);
- var diff=m_pt.point.subtract(currentMesh.lastPos);
- currentMesh.lastPos=m_pt.point;
- currentMesh.position.addInPlace(diff);
- }
- else
- {
- currentMesh.lastPos=m_pt.point;
- }
- currentMesh.computeWorldMatrix(true);
- currentMesh.refreshBoundingInfo();
-
- if(currentMesh._boundingInfo.boundingBox.maximumWorld.y>wallHeigh||currentMesh._boundingInfo.boundingBox.minimumWorld.y<0)
- {
- currentMesh.lastPos=temp_last;
- currentMesh.position=temp_pt;
- }
- else
- {
- if(m_pt.index==my3DEngine.phoSet.photoFrameMesh.planeindex)
- {
- for(var i=0;i<collidables.length;++i)
- {
- if(i==my3DEngine.phoSet.photoFrameMesh.planeindex)
- {
- continue;
- }
- if(collidables[i].intersectsMesh(currentMesh, true))
- {
- currentMesh.lastPos=temp_last;
- currentMesh.position=temp_pt;
- break;
- }
- }
- }
- else
- {
- var temprotation=currentMesh.rotation.y;
- currentMesh.rotation.y=collidables[m_pt.index].rotation.y;
- if(collidables[my3DEngine.phoSet.photoFrameMesh.planeindex].intersectsMesh(currentMesh, true))
- {
- currentMesh.lastPos=temp_last;
- currentMesh.position=temp_pt;
- currentMesh.rotation.y=temprotation;
- }
- else
- {
- currentMesh.computeWorldMatrix(true);
- currentMesh.refreshBoundingInfo();
- var pos=currentMesh.position;
- var join=calculateLine.getJoinLinePoint({x:pos.x,y:pos.z},calculateLine.createLine(collidables[m_pt.index].pts.point1, collidables[m_pt.index].pts.point2));
- join=new BABYLON.Vector3(join.x,pos.y,join.y);
- var diffplane=join.subtract(pos);
- var add=0;
-
- while(!collidables[m_pt.index].intersectsMesh(currentMesh, true))
- {
- pos.addInPlace(new BABYLON.Vector3(diffplane.x*0.1,diffplane.y*0.1,diffplane.z*0.1));
- ++add;
- if(add>19)
- {
- //alert(2851);
- break;
- }
- currentMesh.position=pos;
- currentMesh.computeWorldMatrix(true);
- currentMesh.refreshBoundingInfo();
- }
-
-
- var fontpt=currentMesh._boundingInfo.boundingBox.vectorsWorld[currentMesh.frontindex];
- var toward2=calculateLine.getToward(collidables[m_pt.index].pts.point1,collidables[m_pt.index].pts.point2,{x:fontpt.x,y:fontpt.z});
- if(collidables[m_pt.index].toward!=toward2)
- {
- currentMesh.rotation.y+=Math.PI;
- }
- if(currentMesh.rotation.y>=2*Math.PI)
- {
- currentMesh.rotation.y-=2*Math.PI;
- }
- my3DEngine.phoSet.photoFrameMesh.planeindex=m_pt.index;
- }
- }
- }
-
-
-
- }
- }
- else
- {
- if(currentMesh.name!="selectCircle"&¤tMesh.name!="rotator")
- {
- currentMesh.position = new BABYLON.Vector3(current.x, currentMesh.position.y, current.z);
- }
- if(BABYLON.Vector2.Distance(new BABYLON.Vector2(startingPoint.x,startingPoint.z),new BABYLON.Vector2(current.x,current.z))>2)
- {
- actionmove=true;
- }
- //actionmove=true;
- if(info!=null)
- {
- info.position= new BABYLON.Vector3(my3DEngine.meshManager.selectFurnitureMesh.position.x, my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.maximumWorld.y+30, my3DEngine.meshManager.selectFurnitureMesh.position.z);
- }
-
- currentMesh.computeWorldMatrix(true);
- currentMesh.refreshBoundingInfo();
-
- if(my3DEngine.meshManager.selectCircle!=null)
- {
- //my3DEngine.meshManager.selectCircle.position=new BABYLON.Vector3(my3DEngine.meshManager.selectFurnitureMesh.position.x,selectCircleY,my3DEngine.meshManager.selectFurnitureMesh.position.z);
- my3DEngine.meshManager.selectCircle.position.x=my3DEngine.meshManager.selectFurnitureMesh.position.x;
- my3DEngine.meshManager.selectCircle.position.z=my3DEngine.meshManager.selectFurnitureMesh.position.z;
- }
-
- var flag=true;
- var meshindex=-1;
-
- if(firstMeshes.length>0)
- {
- for(var i=0;i<firstMeshes.length;++i)
- {
- if(firstMeshes[i]==currentMesh.name)
- {
- meshindex=i;
- break;
- }
- }
- }
-
- for(var i=0;i<collidables.length;++i)
- {
- if (typeof(collidables[i]) == "undefined") {
- collidables.remove(collidables[i]);
- --i;
- continue;
- }
- if (currentMesh.intersectsMesh(collidables[i], true))
- {
- if(currentMesh._boundingInfo.boundingBox.minimumWorld.y>collidables[i]._boundingInfo.boundingBox.maximumWorld.y&¤tMesh._boundingInfo.boundingBox.maximumWorld<collidables[i]._boundingInfo.boundingBox.minimumWorld)
- {
- break;
- }
- else if(currentMesh.name=="mirror")
- {
- break;
- }
- //console.log("2762");
- var m_flag=false;
- for(var j=0;j<firstMeshes.length;++j)
- {
- if(collidables[i].name==firstMeshes[j])
- {
- m_flag=true;
- break;
- }
- }
- if(m_flag)
- {
- continue;
- }
- flag=false;
- break;
- }
- }
- if(flag)
- {
- lastPosition=currentMesh.position;
- if(meshindex!=-1)
- {
- firstMeshes.splice(meshindex, 1);
- }
- }
- else
- {
- if(meshindex==-1)
- {
- currentMesh.position = new BABYLON.Vector3(lastPosition.x, lastPosition.y, lastPosition.z);
- if(info!=null)
- {
- info.position= new BABYLON.Vector3(my3DEngine.meshManager.selectFurnitureMesh.position.x, 0, my3DEngine.meshManager.selectFurnitureMesh.position.z);
- }
- if(my3DEngine.meshManager.selectCircle!=null)
- {
- my3DEngine.meshManager.selectCircle.position.x=my3DEngine.meshManager.selectFurnitureMesh.position.x;
- my3DEngine.meshManager.selectCircle.position.z=my3DEngine.meshManager.selectFurnitureMesh.position.z;
- }
-
- flag=true;
- }
- else
- {
- lastPosition=currentMesh.position;
- }
- }
- }
-
- evt.stopPropagation();
- };
-
- //针对相框、壁纸
- var createArrows2=function(currentMesh,scene,imagearrow)
- {
- min=currentMesh._boundingInfo.boundingBox.minimumWorld;
- max=currentMesh._boundingInfo.boundingBox.maximumWorld;
-
- var center=currentMesh._boundingInfo.boundingBox.center;
-
- var points=[];
- points[0]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[0]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[0]].z};
- points[1]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[1]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[1]].z};
- points[2]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[2]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[2]].z};
- points[3]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[3]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[3]].z};
-
- var down =new BABYLON.Vector3((points[0].x+points[3].x)/2,center.y,(points[0].y+points[3].y)/2);
- var top =new BABYLON.Vector3((points[1].x+points[2].x)/2,center.y,(points[1].y+points[2].y)/2);
- var left =new BABYLON.Vector3((points[1].x+points[0].x)/2,center.y,(points[1].y+points[0].y)/2);
- var right=new BABYLON.Vector3((points[2].x+points[3].x)/2,center.y,(points[2].y+points[3].y)/2);
-
- arrowdown =new BABYLON.Vector3(down.x ,down.y,down.z);
- arrowtop =new BABYLON.Vector3(top.x ,top.y,top.z);
- arrowleft =new BABYLON.Vector3(left.x ,left.y,left.z);
- arrowright=new BABYLON.Vector3(right.x,right.y,right.z);
-
- down=arrowdown.add(new BABYLON.Vector3(0,0,-interval));
- top=arrowtop.add(new BABYLON.Vector3(0,0,interval));
- left=arrowleft.add(new BABYLON.Vector3(-interval,0,0));
- right=arrowright.add(new BABYLON.Vector3(interval,0,0));
-
- down =new BABYLON.Vector2(down.x ,down.z);
- top =new BABYLON.Vector2(top.x ,top.z);
- left =new BABYLON.Vector2(left.x ,left.z);
- right=new BABYLON.Vector2(right.x,right.z);
-
- var arrowtexture = new BABYLON.Texture('data:my_image_name1', scene, true,
- true, BABYLON.Texture.BILINEAR_SAMPLINGMODE,
- null, null, imagearrow, true);
-
- mesh1=BABYLON.Mesh.CreateCylinder("arrow1", 0.00001, 24, 24, 64, 12, scene, false);
- mesh1.material =new BABYLON.StandardMaterial('newMaterial', scene);
- mesh1.material.diffuseTexture = arrowtexture;
- mesh1.position= new BABYLON.Vector3(down.x, infoheigh, down.y);
- mesh1.rotation.y=-Math.PI/2;
- mesh1.rotation.z=Math.PI;
- mesh1.name="downarrow";
-
- mesh2=mesh1.clone();
- mesh2.position= new BABYLON.Vector3(top.x, infoheigh, top.y);
- mesh2.rotation.y=-3*Math.PI/2;
- mesh2.rotation.z=Math.PI;
- mesh2.name="toparrow";
-
- mesh3=mesh1.clone();
- mesh3.position= new BABYLON.Vector3(left.x, infoheigh, left.y);
- mesh3.rotation.y=0;
- mesh3.rotation.z=Math.PI;
- mesh3.name="leftarrow";
-
- mesh4=mesh1.clone();
- mesh4.position= new BABYLON.Vector3(right.x, infoheigh, right.y);
- var angle4=BABYLON.Angle.BetweenTwoPoints(right,left);
- mesh4.rotation.y=-Math.PI;
- mesh4.rotation.z=Math.PI;
- mesh4.name="rightarrow";
-
- line1={x:down.x};
- line2={y:left.y};
-
- my3DEngine.meshManager.arrowMeshes[0]=mesh1;
- my3DEngine.meshManager.arrowMeshes[1]=mesh2;
- my3DEngine.meshManager.arrowMeshes[2]=mesh3;
- my3DEngine.meshManager.arrowMeshes[3]=mesh4;
- };
-
- var createArrows=function(currentMesh,scene,imagearrow)
- {
- min=currentMesh._boundingInfo.boundingBox.minimumWorld;
- max=currentMesh._boundingInfo.boundingBox.maximumWorld;
- //heigh=Math.abs(max.z-min.z);
- //length=Math.abs(max.x-min.x);
-
- var center=currentMesh._boundingInfo.boundingBox.center;
-
- var points=[];
- points[0]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[0]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[0]].z};
- points[1]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[1]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[1]].z};
- points[2]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[2]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[2]].z};
- points[3]={x:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[3]].x,y:currentMesh._boundingInfo.boundingBox.vectorsWorld[vertexPoints[3]].z};
-
-
- var down =new BABYLON.Vector3((points[0].x+points[3].x)/2,center.y,(points[0].y+points[3].y)/2);
- var top =new BABYLON.Vector3((points[1].x+points[2].x)/2,center.y,(points[1].y+points[2].y)/2);
- var left =new BABYLON.Vector3((points[1].x+points[0].x)/2,center.y,(points[1].y+points[0].y)/2);
- var right=new BABYLON.Vector3((points[2].x+points[3].x)/2,center.y,(points[2].y+points[3].y)/2);
- arrowdown =new BABYLON.Vector3(down.x ,down.y,down.z);
- arrowtop =new BABYLON.Vector3(top.x ,top.y,top.z);
- arrowleft =new BABYLON.Vector3(left.x ,left.y,left.z);
- arrowright=new BABYLON.Vector3(right.x,right.y,right.z);
-
-
- down =new BABYLON.Vector2(down.x ,down.z);
- top =new BABYLON.Vector2(top.x ,top.z);
- left =new BABYLON.Vector2(left.x ,left.z);
- right=new BABYLON.Vector2(right.x,right.z);
-
-
- var d1=BABYLON.Vector2.Distance(down,new BABYLON.Vector2(center.x,center.z));
- var diff1=arrowdown.subtract(center);
- //down=arrowdown.addInPlace(diff1);
- down=arrowdown.add(new BABYLON.Vector3(diff1.x/d1*interval,0,diff1.z/d1*interval));
-
- var d2=BABYLON.Vector2.Distance(top,new BABYLON.Vector2(center.x,center.z));
- var diff2=arrowtop.subtract(center);
- //top=arrowtop.addInPlace(diff2);
- //top.addInPlace(diff2);
- top=arrowtop.add(new BABYLON.Vector3(diff2.x/d2*interval,0,diff2.z/d2*interval));
-
- var d3=BABYLON.Vector2.Distance(left,new BABYLON.Vector2(center.x,center.z));
- var diff3=arrowleft.subtract(center);
- //left=arrowleft.addInPlace(diff3);
- //left.addInPlace(diff3);
- left=arrowleft.add(new BABYLON.Vector3(diff3.x/d3*interval,0,diff3.z/d3*interval));
-
- var d4=BABYLON.Vector2.Distance(right,new BABYLON.Vector2(center.x,center.z));
- var diff4=arrowright.subtract(center);
- //right=arrowright.addInPlace(diff4);
- //right.addInPlace(diff4);
- right=arrowright.add(new BABYLON.Vector3(diff4.x/d4*interval,0,diff4.z/d4*interval));
-
- down =new BABYLON.Vector2(down.x ,down.z);
- top =new BABYLON.Vector2(top.x ,top.z);
- left =new BABYLON.Vector2(left.x ,left.z);
- right=new BABYLON.Vector2(right.x,right.z);
-
- var arrowtexture = new BABYLON.Texture('data:my_image_name1', scene, true,
- true, BABYLON.Texture.BILINEAR_SAMPLINGMODE,
- null, null, imagearrow, true);
-
- mesh1=BABYLON.Mesh.CreateCylinder("arrow1", 0.00001, 24, 24, 64, 12, scene, false);
- mesh1.material =new BABYLON.StandardMaterial('newMaterial', scene);
- mesh1.material.diffuseTexture = arrowtexture;
- mesh1.position= new BABYLON.Vector3(down.x, infoheigh, down.y);
- var angle1=BABYLON.Angle.BetweenTwoPoints(down,top);
- mesh1.rotation.y=-angle1._radians;
- mesh1.rotation.z=Math.PI;
- mesh1.name="downarrow";
-
- mesh2=mesh1.clone();
- mesh2.position= new BABYLON.Vector3(top.x, infoheigh, top.y);
- var angle2=BABYLON.Angle.BetweenTwoPoints(top,down);
- mesh2.rotation.y=-angle2._radians;
- mesh2.rotation.z=Math.PI;
- mesh2.name="toparrow";
-
- mesh3=mesh1.clone();
- mesh3.position= new BABYLON.Vector3(left.x, infoheigh, left.y);
- var angle3=BABYLON.Angle.BetweenTwoPoints(left,right);
- mesh3.rotation.y=-angle3._radians;
- mesh3.rotation.z=Math.PI;
- mesh3.name="leftarrow";
-
- mesh4=mesh1.clone();
- mesh4.position= new BABYLON.Vector3(right.x, infoheigh, right.y);
- var angle4=BABYLON.Angle.BetweenTwoPoints(right,left);
- mesh4.rotation.y=-angle4._radians;
- mesh4.rotation.z=Math.PI;
- mesh4.name="rightarrow";
-
- line1=calculateLine.createLine(down,top);
- line2=calculateLine.createLine(left,right);
-
- my3DEngine.meshManager.arrowMeshes[0]=mesh1;
- my3DEngine.meshManager.arrowMeshes[1]=mesh2;
- my3DEngine.meshManager.arrowMeshes[2]=mesh3;
- my3DEngine.meshManager.arrowMeshes[3]=mesh4;
- };
-
- var clearArrow=function()
- {
- //if(typeof(mesh1) != "undefined"&&!mesh1._isDisposed)
- if(typeof(mesh1) != "undefined")
- {
- mesh1.dispose();
- }
- if(typeof(mesh2) != "undefined")
- {
- mesh2.dispose();
- }
- if(typeof(mesh3) != "undefined")
- {
- mesh3.dispose();
- }
- if(typeof(mesh4) != "undefined")
- {
- mesh4.dispose();
- }
- createArrow=false;
- };
-
- var onCameraWheel=function(e)
- {
- var type=e.type;
- var delta;
- if (type == 'DOMMouseScroll' || type == 'mousewheel') {
- delta = (e.wheelDelta) ? (e.wheelDelta / 120)*2 : -(e.detail || 0) / 3*2;
- }
-
- var mark=document.getElementById("mark");
- var markpy=parseInt(mark.style.marginTop);
- markpy-=delta;
- if(markpy<MixMark)
- {
- markpy=MixMark;
- }
- else if(markpy>MaxMark)
- {
- markpy=MaxMark;
- }
- mark.style.marginTop=markpy+"px";
- };
-
- canvas.addEventListener("mousedown", onPointerDown, false);
- canvas.addEventListener("mouseup", onPointerUp, false);
- canvas.addEventListener("mousemove", onPointerMove, false);
- canvas.addEventListener("mousewheel", onCameraWheel,false);
-
- scene.onDispose = function () {
- canvas.removeEventListener("mousedown", onPointerDown);
- canvas.removeEventListener("mouseup", onPointerUp);
- canvas.removeEventListener("mousemove", onPointerMove);
- canvas.removeEventListener("mousewheel", onCameraWheel);
- };
- };
|