123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277 |
- /* var ceshi = '';
- // var ceshi = 'http://192.168.0.135:8105';
- // var ceshi = 'http://47.107.252.54:8105';
- // var token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsInJvbGUiOm51bGwsIm1hbmFnZXIiOm51bGwsImlkIjoxLCJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNTk2NzAxNjAyLCJpYXQiOjE1OTY2MTUyMDIsImp0aSI6Ijk0YjA5YTg1LWViY2ItNDE1Yy04OGVmLWU0MDM1M2UzYmIxYyJ9.Uzi95n0kYXp7bdpY77MdLtTpPL_Fq-jn0tE7gjg6AzA"
- var token = window.localStorage.dcj_token
-
- */
- var _musicMaxWeight = 8
- //M
- var cmp = getQueryVariable('cmp') || ''
- var _hotNum = 0
- function reData(data, type) {
- return JSON.stringify(data) == type ? null : data
- }
- //新编辑界面
- var EditTools = function(n) {
- //main2018 里面的主要对象
- this.n = n;
- //当前状态
- this.atPanel = null;
- //场景信息
- this.sceneInformation = new SceneInformation();
- //热点
- this.hotpoint = new Hotpoint();
- //导览
- this.editGuide = new EditGuide();
- //音乐
- this.editMiuse = new EditMiuse();
- //初始化界面
- //this.init();
- this.data = {}
- }
- EditTools.prototype.loadDone = function(name, data){
- this.data[name] = data
- if('data' in this.data && 'data2' in this.data){
- this.init();
- }
- }
- EditTools.prototype.init = function() {
- this.hotpoint.init(/* this.n */);
- var that = this;
- this.initSaveAll();
- this.active();
-
- if(player.mode != 'panorama'){
- $(".toolLeft li[data-name=panoVisible]").addClass('unable')
- player.once("pano.chosen",()=>{
- $(".toolLeft li[data-name=panoVisible]").removeClass('unable')
- })
- }
- that.hotpoint.initTexSelect( this.data.data2.hots);
- //创建导览
- that.editMiuse.init(this.data.data);
- that.sceneInformation.init(this.data.data, this.data.data2)
- // fyz 初始化导览需要两部分数据, 其中data2为data.js中的数据
- that.editGuide.init(this.data.data, this.data.data2);
-
-
-
- $("body").on("click", function() {
- $(".DelConfirm").removeClass("active");
- })
-
-
-
- $(" .MenuOptions li").on("click", (e)=>{
- var $elem = $(e.target);
- $elem.closest('.MenuOptions').find('li').removeClass("chosen");
- $elem.addClass("chosen");
- })
-
-
-
- }
- //点击的时候激活状态
- EditTools.prototype.active = function() {
- var that = this;
- var confirmSnap = $(".confirmSnap.innerBtn");
- var snapshotGui = $(".snapshotGui.overlayGui");
- $('.toolBottom .toolLeft li').click(function() {
- var name = $(this).data("name");
- $('.toolLeft li[data-name=' + name + ']').addClass("active").siblings().removeClass("active");
- $('.toolRight .' + name).removeClass("hide").siblings().addClass("hide");
- if (name == that.atPanel)
- return;
- console.log(`atPanel ${that.atPanel} name ${name}`)
- switch (that.atPanel) {
- //退出
- case "panoVisible":
- VisiSet.finishSetPanoVisible()
- break;
- case "panoLog":
- VisiSet.finishSetPanoLog()
- break;
- case "screen":
- confirmSnap.addClass("hide").removeClass("unable");
- snapshotGui.hide();
- break;
- case "overlay":
- EditOverlay.leave()
- break;
- case "hotpoint":
- $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click();
- VisiSet.finishSetTagVisible()
- break;
- }
- switch (name) {
- case "panoVisible":
- $(".toolLeft").addClass("unable")
- VisiSet.enterSet(VisiSet.beginSetPanoVisible.bind(VisiSet))
- break;
- case "panoLog":
- $(".toolLeft").addClass("unable")
- VisiSet.enterSet(VisiSet.beginSetPanoLog.bind(VisiSet))
- break;
- case "screen":
- confirmSnap.removeClass("hide");
- $('#camera-start').text("点此设置为初始画面")
- snapshotGui.show();
- if (player.modeTran.split("-")[1] != "panorama")
- $(".confirmSnap").addClass("unable")
- break;
- case "overlay":
- EditOverlay.enter()
- break;
- }
- that.atPanel = name;
- /* if(name != "hotpoint"){
- $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click()
- } */
- })
- //滚动阻止事件
- $(".toolRight div.content").on("mousewheel", function(event) {
- event.stopPropagation()
- });
- // 输入框阻止事件
- $('.toolRight').on('keydown', function(ev) {
- ev.stopPropagation();
- })
- }
- //保存按钮
- EditTools.prototype.initSaveAll = function() {
- var that = this;
- $('#save').on('click', function() {
- $(".edit-loading").removeClass("hide");
-
- var $shareImages = $(".information .edit-fun-images a.result");
- new Promise(function(resolve, reject) {//分享图
- upload($shareImages, 'images', resolve)
- }).then(function(imgUrls) {
-
- //导览的数据
- var guides = that.editGuide.getSavingInfo()/* Array.from($('.tourFolderList ul li')).map(function(dom) {
- return dom.data
- }) */
- var hots = {}
- // 热点数据
- var hotLength = 0;
- for (let i in player.model.hots) {
- let hot = player.model.hots[i];
- let hotData = {
- position: {
- x: toPrecision(hot.position.x, 3),
- y: toPrecision(hot.position.y, 3),
- z: toPrecision(hot.position.z, 3),
- },
- //有的定制场景代码是旧的,只能使用rotation,所以不输出quaternion :
- rotation: new THREE.Euler().setFromQuaternion(hot.quaternion).toObject(),
- isSprite: hot.isSprite ? 1 : 0,
- noAction: hot.noAction ? 1 : 0,
- linkType: hot.linkType,
- actionType: hot.actionType,
- infoAttribute: hot.infoAttribute,
- order: hotLength++//因为热点保存后在hots里的顺序会被修改,所以使用order来记录顺序
-
- }
- if (hot.visiblePanos)
- hotData.visiblePanos = hot.visiblePanos
- if (hot.hotIconScale)
- hotData.hotIconScale = hot.hotIconScale
-
- hotData.transformAtPanos = {}
- for(let i in hot.transformAtPanos){
- hotData.transformAtPanos[i] = {
- pos : toPrecision(hot.transformAtPanos[i].pos.toArray(), 3),
- }
- if(hot.transformAtPanos[i].qua){
- hotData.transformAtPanos[i].qua = toPrecision(hot.transformAtPanos[i].qua.toArray(), 5)
- }
- }
-
-
-
-
-
-
-
- if (hot.infoAttribute) {
- delete hot.infoAttribute.position;
- delete hot.infoAttribute.quaternion;
- delete hot.infoAttribute.rotation;
- delete hot.infoAttribute.transformAtPanos
- }
- hots[i] = hotData
- }
- var info = {
- name: $('#pjtName').val(),
- summary: $('#info-summary').val(),
- weixinDesc: $('#weixin-summary').val(),
- shareImgUrl: imgUrls[0] || '',
- backgroundMusic: $('#query-bgm').attr('href'),
- bgName: $(".music .audio.mediaUpload .title").text(),
- hoticon: JSON.parse($(".hotStyle-item li.active").attr("data-val")),
- camera_start: $('#camera-start')[0].data,
- loadlogo: $("#loadlogo").is(':checked'),
- special: $("#g_specialScene").is(':checked'),
- vision_version: $("#twoData").is(':checked') ? "1.1.562.17209" : false,
- /************************************** 方奕卓 场景可配置项 ******************************************/
- hotImageScale: $("#hotImgScale").is(':checked'),
- // 热点图片可放大
- hideFloorMarker: $("#hideFloorMarker").is(':checked'),
- // 地面标记
- hideMouseMarker: $("#hideMouseMarker").is(':checked'),
- // 鼠标标记
- floorMarkerColor: $('#floorMarkerColor').val(),
- // 地面/导览标志颜色
- mouseMarkerColor: $('#mouseMarkerColor').val(),
- // 鼠标标志颜色
- momentTour: $('#tourSwitch input').is(':checked') ? 'black' : 'walk',
- // 导览瞬间过渡
- showHotListSta: $('#hotListSwitch input').is(':checked'),
- // 开启热点列表
- hotIconScale: $('#hotIconScale input').val(),
- // 热点缩放
- supportsVR: $('#VRSwitch input').is(':checked'),
- // 开启VR功能
- /**************** 陈志广 小地图可配置项 *********** */
- cadSignColor: $('#cadSignColor').val(),
- cadBorderColor: $('#cadBorderColor').val(),
- cadBorderWidth: $('#cad-size').val(),
- showCad: $('input[name="show-cad"]').is(':checked'),
- }
- var overlayInfo = []
- player.overlayGroup.children.forEach((overlay)=>{
- var info = EditOverlay.getSavingInfo(overlay)
- if (info)
- overlayInfo.push(info);
- }
- )
-
-
-
-
- /* console.log("保存数据");
- console.log({
- guides: reData(guides, '[]'),
- info: info,
- })
- console.log(JSON.stringify(guides) )
-
- debugger; */
-
-
-
- let url = cmp ? ('/api/scene/edit/' + cmp) : '/manage/scene/edit'
- $.ajax({
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- token: token
- },
- dataType: 'json',
- contentType: 'application/json',
- url: ceshi + url,
- data: JSON.stringify({
- sceneCode: number,
- hots: reData(hots, '{}'),
- name: number,
- guides: reData(guides, '[]'),
- info: info,
- //tourAudio: reData(that.editGuide.getTourAudio(), '{}'),
- overlays: reData(overlayInfo, '[]')
- }),
- success: function(data) {
- if (data.code === 0) {
- location.reload()
- }
- if (data.code === 5001) {
- alert('请重新登录')
- localStorage.dcj_token = ''
- location.reload()
- }
- }
- })
- });
- })
- }
- //场景信息编辑
- var SceneInformation = function() {}
- SceneInformation.prototype.init = function(data, data2) {
-
-
-
- var $options = $('.hotStyle-item li');
- var $loadlogo = $("#loadlogo");
- var $hotImageScale = $("#hotImgScale");
- var $hideFloorMarker = $("#hideFloorMarker");
- var $hideMouseMarker = $("#hideMouseMarker");
- var $g_specialScene = $("#g_specialScene");
- var $twoData = $("#twoData");
- /*******************方奕卓 其他项需要用到data来初始化, 故一并放到这里 ******************/
- let momentTour = $('#tourSwitch input');
- // 导览瞬间过渡开关
- let hotListSwitch = $('#hotListSwitch input');
- // 热点列表开关
- let hotIconScale = $('#hotIconScale input');
- // 热点图标缩放
- let VRSwitch = $('#VRSwitch input');
- // VR功能开启
- /***********************************************************************************/
- $(".model-title2").text(data.name);
- $('#pjtName').val(data.name);
- $('#info-summary').val(data.summary);
- //if (data2) $('#weixin-summary').val(data2.weixinDesc);
- $('#weixin-summary').val(data.weixinDesc);
- for (var i = 0; i < $options.length; i++) {
- if ($options.eq(i).attr('data-val') === JSON.stringify(data.hoticon)) {
- $options.eq(i).addClass("active").siblings().removeClass("active");
- }
- }
- $('#camera-start')[0].data = data.camera_start;
- $(".shotImg.innerBtn").on("click", ()=>{
- var EntryInfo = $('#camera-start')[0].data
- if (EntryInfo) {
- var to = player.model.panos.get(EntryInfo.pano.uuid);
- var q = new THREE.Quaternion().fromArray(EntryInfo.camera.quaternion);
- var lookAtPoint = new THREE.Vector3(0,0,-1).applyQuaternion(q).add(to.position);
- player.flyToPano({
- pano: to,
- lookAtPoint: lookAtPoint
- })
- }
- }
- )
-
- if(data.shareImgUrl){
- var imagesHTML = '<div><a class=" result success"><span></span><img src="' + data.shareImgUrl + '"></a></div>'
- $(".information .edit-fun-images.list ").html(imagesHTML);
- $("#shareImgUpload").addClass("hide")
- }
-
- if(data.spotImgUrl){
-
- }
- /*************方奕卓 其他项的初始化操作 ************/
- initColorElem(data);
- addListener();
- // 给其他元素绑定事件
- if (data.momentTour === 'black') {
- momentTour.prop('checked', true);
- }
- if (data.showHotListSta) {
- hotListSwitch.prop('checked', true);
- }
-
- if (data.hotIconScale) {
- hotIconScale.val(parseFloat(data.hotIconScale));
- }
- hotIconScale.on('change',(e)=>{
- var s = THREE.Math.clamp(parseFloat(e.target.value), 0.1, 1.5)
- e.target.value = s
-
- for(let i in player.model.hots){
- if(!player.model.hots[i].hotIconScale){
- player.model.hots[i].mesh.scale.set(s,s,s)
- }
- }
- })
- $('#hotIconScale_2 input').on('change',(e)=>{
- var s = THREE.Math.clamp(parseFloat(e.target.value), 0.1, 1.5)
- e.target.value = s
- editTool.hotpoint.editSpot.mesh.scale.set(s,s,s)
- })
-
-
-
- if (data.supportsVR) {
- VRSwitch.prop('checked', true);
- }
- /************************************************/
- //隐藏公司logo
- if (data.loadlogo) {
- $loadlogo[0].checked = true
- showLogo();
- }
- // 热点图片放大
- if (data.hotImageScale) {
- $hotImageScale[0].checked = true
- }
- // 隐藏地面标记
- if (data.hideFloorMarker) {
- $hideFloorMarker[0].checked = true
- }
- // 隐藏鼠标标记
- if (data.hideMouseMarker) {
- $hideMouseMarker[0].checked = true
- }
- //特殊大场景
- if (data.special) {
- $g_specialScene[0].checked = true
- }
- //启动二代的数据
- if (data.vision_version === "1.1.562.17209" || data.vision_version) {
- $twoData[0].checked = true
- }
- }
- /**
- * 初始化颜色选择的html元素
- * @param {*} data
- * @param {*} elem
- */
- function initColorElem(data, elem) {
- let $floorMarkerColor = $('#floorMarkerColor');
- let $mouseMarkerColor = $('#mouseMarkerColor');
- let $floorMarkerColorTex = $('#floorMarkerColorTex');
- let $mouseMarkerColorTex = $('#mouseMarkerColorTex');
- let $cadSignColor = $('#cadSignColor');
- let $cadSignColorTex = $('#cadSignColorTex');
- let $cadBorderColor = $('#cadBorderColor');
- let $cadBorderColorTex = $('#cadBorderColorTex');
- var colorRe = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/;
- // 事件监听
- $floorMarkerColor.on('change', function(e) {
- $('#floorMarkerColorTex').attr('placeholder', e.target.value)
- })
- $floorMarkerColorTex.on('blur keydown', function(e) {
- (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $floorMarkerColor, this);
- })
- $mouseMarkerColor.on('change', function(e) {
- $('#mouseMarkerColorTex').attr('placeholder', e.target.value)
- })
- $mouseMarkerColorTex.on('blur keydown', function(e) {
- (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $mouseMarkerColor, this);
- })
-
- // 事件监听
- $cadSignColor.on('change', function(e) {
- $('#cadSignColorTex').attr('placeholder', e.target.value)
- })
-
- $cadSignColorTex.on('blur keydown', function(e) {
- (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadSignColor, this);
- })
-
- // 事件监听
- $cadBorderColor.on('change', function(e) {
- $('#cadBorderColorTex').attr('placeholder', e.target.value)
- })
-
- $cadBorderColorTex.on('blur keydown', function(e) {
- (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadBorderColor, this);
- })
- // 设置颜色值
- function setColor(e, colorElem, inputElem) {
- var isColor = colorRe.test(e.target.value);
- isColor && colorElem.val(e.target.value);
- // isColor ? colorElem.val(e.target.value): (inputElem.placeholder = colorElem.val());
- }
-
- // 判断data中是否有存在的颜色值, 否则设置默认值
- data.floorMarkerColor ? $floorMarkerColor.val(data.floorMarkerColor) : $floorMarkerColor.val('#4bcdfc');
- data.mouseMarkerColor ? $mouseMarkerColor.val(data.mouseMarkerColor) : $mouseMarkerColor.val('#4bcdfc');
-
- // 判断data中是否有存在的颜色值, 否则设置默认值
- data.cadSignColor ? $cadSignColor.val(data.cadSignColor) : $cadSignColor.val('#00c8af');
- data.cadBorderColor ? $cadBorderColor.val(data.cadBorderColor) : $cadBorderColor.val('#ffffff');
- $('input[name="show-cad"]')[0].checked = !!data.showCad
- $('#cad-size > option[value="'+(data.cadBorderWidth ? data.cadBorderWidth : '0.01')+'"]').attr("selected",true);
- if (data.showCad) {
- $('input[name="show-cad"]').trigger('change')
- }
- $('#panoIdColor').on('change', function(e) {
- $('#panoIdColorTex').val(e.target.value)
- VisiSet.changePanoIdColor(e.target.value)
- })
- $('#panoIdColorTex').on('blur keydown', function(e) {
- (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $('#panoIdColor'), this);
- VisiSet.changePanoIdColor(e.target.value)
- })
- $('#panoIdColor').val('#c13e3e')//初始颜色
- $('#panoIdColorTex').val('#c13e3e')
- }
- $('input[name="show-cad"]').on('change', function(ev) {
- if (!ev.target.checked) {
- return $('.cad').hide()
- }
-
- let taht = this
- if (!taht.floorJSON) {
- $.ajax({
- url: '//super.4dage.com/data/'+ window.number +'/floor.json',
- method: 'GET',
- success(res) {
- taht.floorJSON = res
- loadCAD(taht.floorJSON)
-
- $('#cadSignColor').on('change', function(ev) {
- loadCAD()
- })
- $('#cadBorderColor').on('change', function(ev) {
- loadCAD()
- })
- $('#cad-size').on('change', function(ev) {
- loadCAD()
- })
- },
- error() {
- alert('当前场景没有小地图floor.json文件,请联系三维部门添加')
- ev.target.checked = false
- }
- })
- } else {
- console.log('0000000000000000000')
- $('.cad').show()
- }
- })
- function loadCAD(data) {
- grendCAD(data, $('#player')[0], $('#cadSignColor').val(), $('#cadBorderColor').val(), $('#cad-size').val())
- }
- function addListener() {}
- //设置初始界面
- function getSeft(seft) {
- $('#camera-start').on('click', function() {
- if (VisiSet.setPanoVisible) {
- return VisiSet.savePanoVisibles()
- } else if (VisiSet.setTagVisible) {
- return VisiSet.saveTagVisibles()
- }
- // 这部分内容需要配合main_2018.js中来进行修改
- var snap = JSON.parse("{" + seft.getSnapAngleInfo() + "}")
- this.data = {
- camera: {
- position: snap.metadata.camera_position,
- quaternion: snap.metadata.camera_quaternion// 相机朝向
- },
- pano: {
- uuid: snap.metadata.scan_id // 起始点位的id
- }
- }
- var ev = document.createEvent("MouseEvent");
- //点击截取视图
- g_snapShotWidth = 240 * 4;
- g_snapShotHeight = 118 * 4;
- window.screenSta = 'startScreen';
- ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
- ev.__callback = (imgData,info)=>{
- uploadImg(imgData, (rs)=>{
- if (rs.code === 0) {
- $(".shotImg.innerBtn").css("background-image", "url(" + rs.data + ")")
- this.data.thumbImg = rs.data;
- }
- }
- , "thumbImg.jpg")
- }
- window.dispatchEvent(ev);
- });
- }
- //热点编辑
- var Hotpoint = function() {
- this.spotList = $(".spotList");
- this.hotpointDetail = $("#hotpointDetail");
- // fyz 导览编辑页面同样采取热点编辑的样式, 这里确保只查找到热点编辑
- }
- Hotpoint.prototype.init = function(n) {
- var that = this;
- this.active();
- this.addmedia();
- // 添加多媒体
- this.addMusicInit();
- // 添加音乐
- this.addModel();
- // 添加模型
- this.addwebPack();
- // 添加外链
- //this.initSaveHot();
- // 保存热点
-
- this.hotpointDetail.find(".tail .submit").on('click', this.saveHot.bind(this))
-
-
- $("#isSprite").on("change", function(e) {
- that.editSpot.isSprite = this.checked;
- if (this.checked) {
- that.editSpot.update(player.camera)
- } else {
- var curPanoTransform = that.editSpot.transformAtPanos[ getTransformSid()] || {}
- that.editSpot.mesh.quaternion.copy(curPanoTransform.qua || that.editSpot.quaternion)
- }
- })
-
-
- /* $("#noAction").on("change", function(e) {
- that.editSpot.noAction = this.checked;
- }) */
-
-
- let hotIconScale = $('#hotIconScale');
-
- //点击添加热点按钮
- $('#addHotSpots').on("click", function() {
- //点击添加热点
- g_HotStatus = g_HotStatus === "add" ? null : "add";
- $("#player").css("cursor", "cell");
- });
- //点击热点列表弹出按钮
- this.spotList.on("click", function(e) {
- var target = $(e.target);
- let li = searchParent(e.target, { className: 'listItem' }, 7);
- if(!li)return;
- var hotId = $(li).attr("data-spid");
- var hot = player.model.hots[hotId]
-
- if(VisiSet.setTagVisible){
- return VisiSet.SetOneTagVisible(hot)
- }
-
- if (target.hasClass("del")) {
- e.stopPropagation();
- target.siblings(".DelConfirm").addClass("active");
- that.spotList.find("i").text(that.spotList.find("ul li").length);
- } else {
- if (target.hasClass("DelConfirm")) {
- e.stopPropagation();
- that.removeHot(hot, $(li));
- } else {
- //点击热点列表弹出编辑热点窗口
- that.editHot(hot, $(li))
-
- }
- }
- });
- //点击热点编辑窗口右上角的关闭按钮
- this.hotpointDetail.find("a.close, button.cancel").on("click", function() {
- var spot_id = that.hotpointDetail.attr("data-id");
- var hot = player.model.hots[spot_id];
- //var info = hot.infoAttribute;
-
- that.styleList.recover()
- hot.setFromInfo()
-
- /* if (info) {
- info.position && hot.mesh.position.copy(info.position)
- info.quaternion && hot.mesh.quaternion.copy(info.quaternion)
- hot.isSprite = info.isSprite
- hot.noAction = info.noAction
- hot.linkOutside = info.linkOutside
- } */
-
- that.editSpot = null
- that.hotpointDetail.addClass("atRight");
- transformControls.detach()
-
-
-
- for(let i in player.model.hots){
- let hot_ = player.model.hots[i]
- hot_.styleImg = hot_.infoAttribute.styleImg.map((e)=>{return {src:e}});
- hot_.changeTex() //恢复贴图
- }
-
-
- });
- //创建列表
- for (let i in player.model.hots) {
- this.addHotList(player.model.hots[i]);
- }
- // 初始话的时候把热点信息添加到对应的热点中 直接使用data2.json的会怎样?
- /* $.ajax(g_Prefix + "data/" + window.number + "/hot/js/data.js" + "?" + Date.now(), { dataType: "json" })
- .then(function (infos) {
- that.infos = infos ;
- Object.keys(infos).forEach(function (key) {
- //sxm增加热点列表可读性,方便查看删除操作等
- that.spotList.find("ul li[data-spid=" + key + "]")[0] && (that.spotList.find("ul li[data-spid=" + key + "]")[0].infoAttribute = infos[key])&& (that.spotList.find("ul li[data-spid=" + key + "] .title").html(infos[key].title));
-
- })
- }) */
-
- $("#hotpointDetail .scale .MenuOptions li").on("click", (e)=>{ //更改大小
- curr = $(e.target).attr("index")
- if (curr == "default") {
- $("#userHotScale").addClass("hide")
- var s = parseFloat($("#hotIconScale input").val());
- editTool.hotpoint.editSpot.mesh.scale.set(s,s,s)
-
- } else {
- $("#userHotScale").removeClass("hide")
- var s = editTool.hotpoint.editSpot.mesh.scale.x;
- $('#hotIconScale_2 input').val(s)
- }
- })
-
- $("#hotpointDetail .MenuOptions[name='linkType'] li").on("click", (e)=>{ //链接打开方式切换
- editTool.hotpoint.editSpot.linkType = $(e.target).attr("index")
- $("#hotpointDetail .MenuOptions[name='linkType'] li").removeClass("chosen");
- $(e.target).addClass("chosen")
- })
-
- $("#hotpointDetail .MenuOptions[name='actionType'] li").on("click", (e)=>{ //
- editTool.hotpoint.editSpot.actionType = $(e.target).attr("index")
- $("#hotpointDetail .MenuOptions[name='actionType'] li").removeClass("chosen");
- $(e.target).addClass("chosen")
- })
-
-
-
- $('#setHotPosForPano input').on("change", ()=>{
- var on = $('#setHotPosForPano input').is(':checked')
-
- if(!on){
- delete this.editSpot.transformAtPanos[getTransformSid()]
-
- this.editSpot.mesh.position.copy(this.editSpot.position)
- this.editSpot.mesh.quaternion.copy(this.editSpot.quaternion)
- //this.editSpot.usingTransformData = false
- }
- })
- }
- Hotpoint.prototype.getTransformAtPano = function(type){
- var name = getTransformSid()
- var info = {
- pos : this.editSpot.mesh.position.clone()
- }
- if(!this.editSpot.isSprite){
- info.qua = this.editSpot.mesh.quaternion.clone()
- }else{
- if(type == 'quaternion')return; //如果恒朝向相机且调整的是quaternion,不要保存position
- }
- this.editSpot.transformAtPanos[name] = info
- //this.editSpot.usingTransformData = true
- }
- Hotpoint.prototype.updateTransform = function(type){
- var on = $('#setHotPosForPano input').is(':checked')
- var name = getTransformSid()
- if(on){
- this.getTransformAtPano(type)
- }else{
- if(type == 'position'){
- this.editSpot.position.copy(this.editSpot.mesh.position)
- }else if(type == 'quaternion'){
- if(!this.editSpot.isSprite){ //如果恒朝向相机就不保存quaternion
- this.editSpot.quaternion.copy(this.editSpot.mesh.quaternion)
- }
- }
- }
- }
- Hotpoint.prototype.updatePano = function(){
- if(!this.editSpot ) return;
- $('#setHotPosForPano input').prop('checked', !!this.editSpot.transformAtPanos[getTransformSid()]);
-
- }
- var ifSameTex = function(imgs0, imgs1){//是否是相同的图 (两个都是空的不算相同)
- return !!(imgs0[0] && imgs1[0] && imgs0[0].src == imgs1[0].src &&
- (imgs0[1] ? (imgs1[1] && imgs0[1].src == imgs1[1].src) : !imgs1[1] ))
- }
- Hotpoint.prototype.findSpotByImgs = (imgs=[])=>{////使用了该贴图的所有热点
- var spots = []
- for(var i in player.model.hots){
- var styleImg = player.model.hots[i].styleImg || [];
- if(ifSameTex(styleImg, imgs)){
- spots.push(player.model.hots[i])
- }
- }
- return spots
- }
- Hotpoint.prototype.initTexSelect = function(hots) {//热点样式图列表
-
- var countElem = $("<a></a>").css({"width":'40px','display': 'block', 'color':'#aeaeae', 'white-space':'break-spaces', 'line-height':'25px', 'margin-left':'10px'})
-
- var uploadInput = $('<input type="file" style="display:none" accept="image/*"></input>');
- var getListItem = ()=>{
- var elem = $('<li><ul class="hotTexUpload"><li class="upload"><div></div><a class="del hasHover"></a></li><li class="upload hide"><div></div><a class="del hasHover"></a></li></ul></li>')
- elem[0]._styleImg = []
- return elem
- }
- var editHotStyleInfo = {}
- var setImgContent = function($dom, index, src) {
- var li = $dom.find('li').eq(index)
- var div = li.find('>div');
- if (src) {
- li.addClass("uploaded")
- div.css("background-image", `url(${src})`)
- } else {
- li.removeClass("uploaded")
- div.css("background-image", '')
- }
- }
-
- var hotIcons = []; // 从所有热点tex中搜集
- for(let i in hots){
- let imgs = hots[i].infoAttribute.styleImg;
- if(imgs && imgs.length){
- if(!hotIcons.find(e=>e[0] == imgs[0] && e[1] == imgs[1])){
- hotIcons.push(imgs)
- }
- }
- }
-
- hotIcons = hotIcons.map(imgs=>imgs = imgs.map((a)=>{return {src:a}}))
- hotIcons.push([])//放末尾用来添加的
-
- var list = hotIcons.map(arr=>{//初始列表
- var elem = getListItem()
- elem[0]._styleImg = arr //每个li上绑定一个 _styleImg,存储它包含的图, 和热点的styleImg对应
- var divs = elem.find("li>div")
- arr.forEach((img,i)=>{
- setImgContent(elem, i, img.src)
- })
- arr.length && elem.find("li").eq(1).removeClass('hide')
- return elem
- })
-
- this.styleList = new ListBox(list, $('#spotTexSelect'), {//列表
- selectFun:()=>{//选中时要改变选中项selection缩略图 以及改变热点
- if(this.styleList.chosenItem == void 0){
- this.styleList.listTitle.find('li').addClass('hide')
- }else{
- this.styleList.listTitle.find('li').removeClass('hide')
- var divs = this.styleList.listTitle.find('li>div')//selection
- var imgs = this.styleList.chosenItem[0]._styleImg;
- if(imgs[0]){
- divs.eq(0).css("background-image", 'url("'+imgs[0].src+'")')
- divs.eq(0).parent().removeClass('hide')
- }else{
- divs.eq(0).parent().addClass('hide')
- }
-
- if(imgs[1]){
- divs.eq(1).css("background-image", 'url("'+imgs[1].src+'")')
- divs.eq(1).parent().removeClass('hide')
- }else{
- divs.eq(1).parent().addClass('hide')
- }
- //应用到热点:
- this.editSpot.changeTex(imgs)
- }
-
- Array.from(this.styleList.listDom.children()).forEach(li=>{//更新一下所有的li的使用的spot
- li.sameTexSpots = this.findSpotByImgs(li._styleImg)
- })
-
- },
- /* delFun: ()=>{
-
- }, */
- addFun: ($li)=>{ //列表新增时对li的操作
- $li[0].sameTexSpots = this.findSpotByImgs($li[0]._styleImg)
-
- $li.find('li').bind('click', (e)=>{
- e.stopPropagation()
- var index = $(e.currentTarget).index();
-
-
- if (e.target.classList.contains("del")) { //删除图片
- if ($li[0]._styleImg.length == 2 && index == 0) { //删除第一个 且有第二个的话
- setImgContent($li, 0, $li[0]._styleImg[1].src);
- setImgContent($li, 1, null);
- $li[0]._styleImg = [$li[0]._styleImg[1]]
- } else {
- setImgContent($li, index, null);
- $li[0]._styleImg.pop()
- if ($li[0]._styleImg.length == 0) {
- $li.find("li").eq(1).addClass("hide");
- }
- }
-
- $li[0].sameTexSpots.forEach(hot=>{
- hot.changeTex($li[0]._styleImg)
- })
-
- if($li.hasClass('selected')){//是当前spot的
- //this.editSpot.changeTex($li[0]._styleImg)
- this.styleList.options.selectFun()
- }
-
-
- } else {
- //添加图片
- uploadInput.click()
- editHotStyleInfo = {
- imgs : $li[0]._styleImg, index, $li
- };
- }
- })
-
- $li.bind('mouseover', (e)=>{
- this.showTitileSpots = $li[0].sameTexSpots;
- this.showTitileSpots.forEach(a=>a.showTitle())
- countElem.text("热点个数:"+this.showTitileSpots.length).removeClass('hide')
- $li.find("ul").append(countElem)
-
- })
- $li.bind('mouseout', (e)=>{
- this.showTitileSpots.forEach(a=>a.hideTitle())
- this.showTitileSpots = null;
- countElem.addClass('hide')
- })
-
- },
- saveTemp: (list)=>{//编辑热点时保存一份副本
- this._styleImgTemp = Array.from(list.listDom.children()).map((li)=>{
- return li._styleImg.slice()
- })
- },
- recover : (list)=>{//取消编辑时恢复
- Array.from(list.listDom.children()).forEach((li,i)=>{
- li._styleImg = this._styleImgTemp[i]
- })
- },
-
- })
- this.styleList.findChosenByImgs = (imgs=[])=>{//找到某图对应的li
- var list = Array.from(this.styleList.listDom.children())
- var item = list.find(e=>ifSameTex(e._styleImg, imgs ))
- return {index: item ? list.indexOf(item) : null, item: item }
- }
-
- this.styleList.clearVoid = ()=>{//清理空的
- var length = this.styleList.listDom.children().length;
- Array.from(this.styleList.listDom.children()).forEach((e, i)=>{
- if(i < length-1){
- if(e._styleImg.length == 0) this.styleList.removeItem($(e))
- }
- })
- }
- this.styleList.addNew = ()=>{//看是否在最后一行增加新的
- var lastOne = this.styleList.listDom.children().last();
- if(lastOne[0]._styleImg.length != 0){
- this.styleList.addItem(getListItem())
- }
- }
-
-
-
-
- uploadInput.on("change", (e)=>{
- inputMedia({
- enableTypes: ["photo"],
- photoDone: (resultImg)=>{
-
- editHotStyleInfo.imgs[editHotStyleInfo.index] = {file: resultImg.file, needSave:true, src:resultImg.src}//resultImg
- setImgContent(editHotStyleInfo.$li, editHotStyleInfo.index, resultImg.src)
- if (editHotStyleInfo.index == 0){
- editHotStyleInfo.$li.find('li').eq(1).removeClass("hide");
- }
-
- //resultImg.needSave = true
-
- editHotStyleInfo.$li[0].sameTexSpots.forEach(hot=>{
- hot.changeTex(editHotStyleInfo.$li[0]._styleImg)
- })
-
-
- if(editHotStyleInfo.$li.hasClass('selected')){//是当前spot的
- this.styleList.options.selectFun()//更新选中状态
- }
-
-
- this.styleList.addNew()
-
- }
- }, "photo", e);
-
- })
-
- $("#hotpointDetail .style .MenuOptions li").on("click", (e)=>{ //切换是默认还是自定义
- var currStyle = $(e.target).attr("index")
- if (currStyle == "default") {
- $("#spotTexSelect").addClass("hide")
- $("#hotpointDetail .style label").addClass("hide")
- editTool.hotpoint.editSpot.changeTex([])
-
- } else {
- this.styleList.options.selectFun()
- $("#hotpointDetail .style label").removeClass("hide")
- $("#spotTexSelect").removeClass("hide")
- }
- })
-
-
- }
- Hotpoint.prototype.initStyle = function(hot) { //每次开始编辑热点时更新样式
- if (!hot.styleImg)
- hot.styleImg = [];
-
-
-
- this.styleList.clearVoid();
-
- if(hot.styleImg.length){
- var info = this.styleList.findChosenByImgs(hot.styleImg)
- var chosenIndex = info.index
- this.styleList.selectFromOutSide(chosenIndex)
- $("#hotpointDetail .style .MenuOptions li").eq(1).click();
- }else{
- this.styleList.selectFromOutSide(null)
- $("#hotpointDetail .style .MenuOptions li").eq(0).click()
- }
-
-
- this.styleList.saveTemp()
-
-
- }
- /**
- * 显示编辑热点的窗口和初始化热点窗口的数据
- */
- Hotpoint.prototype.editHot = function(hot, $li) {
- this.hotpointDetail.removeClass("atRight");
- $("#hotpointDetail .audio.mediaUpload").find("input").val('');
- // 点击编辑导览清空上一次文件
- var playIcon = 'images/play.png';
- var $layout = $("#hotpointDetail")[0];
- //$layout.targetDOM = target.closest("li")[0];
- //closest匹配选择器的第一个祖先元素
- //编辑时将热点列表唯一标识带入,以便后期保存使用识别
- //var li_id = $li.attr("data-spid");
- this.editSpot = hot
- this.hotpointDetail.attr("data-id", hot.sid);
- var info = this.editSpot.infoAttribute || {}
- //$layout.targetDOM.infoAttribute || {}
-
- $(".MenuOptions[name='transform'] li[index='translate']").click()//transformControls.transCtlChangeMode("translate")
- // 参数初始化
- info.title = info.title || '';
- info.content = info.content || '';
- info.iframe = info.iframe || [];
- info.model = info.model || [];
- info.images = info.images || [];
- info.video = info.video || [];
- info.isSprite = this.editSpot.isSprite
- info.actionType = this.editSpot.actionType
- info.linkType = this.editSpot.linkType
- info.transformAtPanos = {}
- for(var i in this.editSpot.transformAtPanos){
- info.transformAtPanos[i] = {
- pos : this.editSpot.transformAtPanos[i].pos.clone(),
- qua : this.editSpot.transformAtPanos[i].qua && this.editSpot.transformAtPanos[i].qua.clone(),
- }
- }
-
- try {
- transformControls.attach(hot.mesh)
- if(player.mode == 'panorama'){
- hot.examine(player, {
- dontOpen: true,
- aimDuration : 600,
- duration : 600
- })
- }else{
- player.focusPoint({aim: hot.position, radius:hot.position.distanceTo(player.position)})
- }
-
- info.position = hot.position.clone()
- info.quaternion = hot.quaternion.clone()
- } catch (e) {}
-
-
-
- this.updatePano()
-
- this.initStyle(hot);
- if(hot.infoAttribute.hotIconScale){
- $("#hotpointDetail .scale .MenuOptions li[index=user]").click()
- }else $("#hotpointDetail .scale .MenuOptions li[index=default]").click()
- $("#hotpointDetail .MenuOptions[name='linkType'] li").removeClass("chosen")
- $("#hotpointDetail .MenuOptions[name='actionType'] li").removeClass("chosen")
- $("#hotpointDetail .MenuOptions[name='linkType'] li[index = " + this.editSpot.linkType+"]").addClass("chosen")
- $("#hotpointDetail .MenuOptions[name='actionType'] li[index = " + this.editSpot.actionType+"]").addClass("chosen")
-
-
-
- $("#isSprite")[0].checked = this.editSpot.isSprite
- //$("#noAction")[0].checked = this.editSpot.noAction
-
- var iframesHTML = info.iframe.map(function(iframe) {
- return this.inputList("请填写网页链接", iframe)
- }
- .bind(this))
- var modulesHTML = info.model.map(function(module) {
- return this.inputList("请填写网页链接", module)
- }
- .bind(this))
- var imagesHTML = info.images.map(function(image) {
- return '<div><a class=" result success" data-type="photo"><span></span><img src="' + image + '" class="bg"></a></div>'
- })
- var videosHTML = info.video.map(function(ly) {
- //var imgDom = (!ly.img || ly.img === "undefined") ? '' : 'success';
- //var imgUrl = (!ly.img || ly.img === "undefined") ? playIcon : ly.img;
- //return '<div><a class=" result success" data-type="video"><span></span><img class="play-video" videoURL="' + ly.url + '" src="' + imgUrl + '"></a ><span class="upload-thum ' + imgDom + ' result" attr-thum="' + ly.img + '">上传封面<i><input type="file"></i></span></div>'
- var thumb = (!ly.img || ly.img === "undefined") ? '' : '<img src='+ ly.img +' class="bg"></img>'
- var thumbResult = (!ly.img || ly.img === "undefined") ? '' : 'success';
- var dom = '<div><a class=" result success" data-type="video"><span></span>' + thumb + ' <img class="play-video" videoURL="' + ly.url + '" src="' + playIcon + '"></a> <span class="upload-thum ' + thumbResult + ' result" attr-thum="' + ly.img + '">上传封面<i><input type="file" accept="image/*"></i></span></div>'
- return dom
- })
- this.hotpointDetail.find(".name > input").val(info.title);
- this.hotpointDetail.find(".editText").val(info.content);
- this.hotpointDetail.find(".photo .list").html(imagesHTML);
- this.hotpointDetail.find(".video .list").html(videosHTML);
- this.hotpointDetail.find(".model .list").html(modulesHTML);
- this.hotpointDetail.find(".webPage .list").html(iframesHTML);
- let bgName = info.bgName || '热点背景音乐';
- if (info.backgroundMusic) {
- /* this.hotpointDetail.find(".audio .playBox").removeClass("hide");
- this.hotpointDetail.find("#upload-hotBgm").attr('data-hotBgm', info.backgroundMusic)
- this.hotpointDetail.find(".audio .playBox a").attr("href", info.backgroundMusic);
- this.hotpointDetail.find('#hotBgName')[0].innerHTML = bgName;
- this.hotpointDetail.find(".audio .submit").text("替换"); */
- this.musicBox.show(this.hotpointDetail.find(".audio.mediaUpload"), bgName, info.backgroundMusic)
- } else {
- this.musicBox.hide()
- /* this.hotpointDetail.find(".audio .playBox").addClass("hide");
- this.hotpointDetail.find("#upload-hotBgm").removeAttr('data-hotBgm') */
- // 没有背景音乐,则移除该属性, 避免其他热点的干扰
- }
- // $layout.targetDOM.infoAttribute = info
- this.editSpot.infoAttribute = info
- }
- //添加图片和视频
- Hotpoint.prototype.addmedia = function() {
- // 视频预览控制
- var $videoLayout = $('.fun-view-video')
- $videoLayout.find('span').on('click', function() {
- $videoLayout.hide();
- $videoLayout.find('video').attr('src', '')[0].pause()
- });
- // 图片加载回调
- function imageSuccess(file) {
- if (!/image\/\w+/.test(file.type)) {
- alert("文件必须为图片!");
- return false;
- }
- if (!restrictedSize(file, 9)) {
- return false;
- }
- var img = new Image()
- img.src = URL.createObjectURL(file);
- img.className = 'bg'
- return img
- }
- // 视频加载回调
- function videoSuccess(file, $elayout) {
- if (!/video\/\w+/.test(file.type)) {
- alert("视频必须为map4格式!");
- return false;
- }
- $elayout.append('<span class="upload-thum">上传封面<i><input type="file" accept="image/*"></i></span>')
- return '<img src="./images/play.png" class="play-video" videoURL="' + URL.createObjectURL(file) + '">'
- }
- // 视频封面回调
- function thumbSuccess(file, $elayout, $seft) {
- if (!/image\/\w+/.test(file.type)) {
- alert("文件必须为图片!");
- return false;
- }
- if (!restrictedSize(file, 2)) {
- return false;
- }
-
- var img = $seft.closest('div').find('img.bg');
- if(!img[0]){
- img = $("<img class='bg'></img>");
- $seft.closest('div').find('a').append(img)
- }
- img.attr('src', URL.createObjectURL(file));
- $seft.closest('span').removeClass("success")
-
-
- }
-
- // 图片与视频加载
- function fileHandle() {
- var $seft = $(this) //input
-
-
- var file = this.files[0];
- var type = this.activeElem ? this.activeElem.attr('data-type') : $seft.parent().attr('data-type');
-
- var $din = $(document.createElement('div'));
- var fnc = type === 'photo' ? imageSuccess : type === 'video' ? videoSuccess : thumbSuccess //再次传都会是thumSuccess
- var $dom = fnc(file, $din, $seft)
- if (type === 'photo' || type === 'video') {
- if (!$dom)
- return $seft.val('');
-
- if(!this.activeElem){//创建新的item
- var $layout = $seft.closest("li");
- var $addLayout = $(document.createElement('a'));
- $addLayout.attr("data-type", type)
-
- var $close = $(document.createElement('span'));
-
- $addLayout[0].file = file;
-
- $addLayout.append($close);
- $addLayout.append($dom);
- $addLayout.addClass("result");
- $din.prepend($addLayout);
- $layout.find('.edit-fun-images').append($din);
- }else{//重传
- if (type === 'photo'){
- this.activeElem.find("img.bg").remove();
- }else{
- this.activeElem.find(".play-video").remove();
- }
- this.activeElem.removeClass("success")
- this.activeElem.append($dom)
- this.activeElem[0].file = file;
- this.value = ''
- }
- }
- if (searchParent($seft[0], {
- id: 'shareImgUpload'
- })) {
- //信息页面的分享图片
- $("#shareImgUpload").addClass("hide")
- }else if(searchParent($seft[0], {
- id: 'SpotStyle'
- })){
- $("#SpotStyle").addClass("hide")
- }
-
-
- }
-
-
-
-
-
- //用于重传的input
- var imgInput = $("<input accept='image/*' type='file'></input>")
- var videoInput = $("<input accept='video/*' type='file'></input>")
-
-
-
- // 图片与视频加载
- $('.upload, .edit-fun-images').on('change', function(ev) {
- if (ev.target.tagName.toUpperCase() === 'INPUT') {
- ev.target.files.length && fileHandle.call(ev.target)
- }
- })
- imgInput.on('change', (ev)=>{fileHandle.call(ev.target)})
- videoInput.on('change', (ev)=>{fileHandle.call(ev.target)})
-
-
-
-
- $('.edit-fun-images').on('click', function(ev) {//点击item时
- var $tag = $(ev.target)
- var tagName = ev.target.tagName.toUpperCase()
-
- if (tagName === 'SPAN') {
- if (searchParent($tag[0], {
- className: 'forShareImg'
- })) {
- //信息页面的分享图片
- $("#shareImgUpload").removeClass('hide')
- }else if(searchParent($tag[0], {
- className: 'SpotStyle'
- })){
- $("#SpotStyle").removeClass('hide')
- }
- $tag.parent().parent().remove()
- }else if (tagName === 'IMG' && $tag.hasClass('play-video')) {
- $videoLayout.css('display', 'flex').find('video').attr('src', $tag.attr('videoURL'))[0].play()
- }else{// 替换
- var a = searchParent($tag[0], {
- tagName: 'a'
- })
- if(a) {
- var input
- if(searchParent($tag[0], {
- className: 'video'
- })){
- input = videoInput
- }else{
- input = imgInput
-
- }
- input[0].activeElem = $(a)
- input.click()
- }
- }
- })
- }
- //选择热点的样式
- Hotpoint.prototype.active = function() {
- $(".hotStyle-item li").on('click', function() {
- $(this).addClass('active').siblings().removeClass('active');
- })
- }
- //当前处于的状态,比如是否是添加热点的状态
- Hotpoint.prototype.state = function(that, Hot) {
- if (g_HotStatus === "add") {
- //console.log(Hot)
- this.addHot(that, Hot, (hot)=>{
- this.addHotList(hot);
- }
- );
- }
- }
- Hotpoint.prototype.updateNumDisplay = function() {
- this.spotList.find("i").text(this.spotList.find("ul li").length);
- }
- //删除热点
- Hotpoint.prototype.removeHot = function(hot, $li ) {
- hot.dispose();
- delete player.model.hots[hot.sid]
- $li.remove();
- this.updateNumDisplay()
- }
- //添加热点模型
- Hotpoint.prototype.addHot = function(that, Hot, fn) {
- if (!window.hotIntersect)
- return;
- // 没有正确的热点位置, return
- var position = hotIntersect.point.toArray();
- //var sid = g_HotMeshes.length > 0 ? "sprite_" + (parseInt(g_HotMeshes[g_HotMeshes.length - 1].name.substring(7)) + 1) : "sprite_" + g_HotMeshes.length;//这么写出bug了。因为当前热点名字不是按照从小到大
- var sid = getRandomSid()
- var hot = new Hot(sid,{
- position: position,
- rotation: [0, 0, 0],
- size: 1.05
- },that.model);
- that.model.hots[sid] = hot;
- if (player.getMouseDirection().angleTo(window.hotIntersect.face.normal) < Math.PI / 2) {
- hot.mesh.lookAt(window.hotIntersect.face.normal.clone().negate().add(hotIntersect.point));
- hot.mesh.position.add(window.hotIntersect.face.normal.clone().negate().multiplyScalar(0.01))
- //avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
- } else {
- hot.mesh.lookAt(window.hotIntersect.face.normal.clone().add(hotIntersect.point));
- hot.mesh.position.add(window.hotIntersect.face.normal.clone().multiplyScalar(0.01))
- }
- hot.quaternion.copy(hot.mesh.quaternion)
- hot.position.copy(hot.mesh.position)
- g_HotStatus = false;
- that.mouseCouldBeClickToMove = false;
- $("#player").css("cursor", "");
- //添加完热点之后的回调函数
- if (g_HotMeshes && g_newHot.length === g_newHot.length++) {
- var thisScene = that;
- //fn && fn.call(this, thisScene);
- fn && fn(hot)
- }
- }
- //添加热点列表
- Hotpoint.prototype.addHotList = function(hot) {
- var li = $("<li class='listItem' data-spid=" + hot.sid + ">" + "<div class=icon></div>" + "<div class=number title=热点>" + (++_hotNum) + "</div>" + "<div class=title title=热点>" + (hot.infoAttribute && hot.infoAttribute.title || "") + "</div>" + "<div class=DelConfirm>确定删除</div>" + "<div class=del></div>" + "</li>");
- li.hot = hot
- $(".spotList ul").append(li);
- this.updateNumDisplay()
- }
- //添加热点音乐
- Hotpoint.prototype.addMusicInit = function() {
- /* var mediaUpload = $("#hotpointDetail .audio.mediaUpload");
- mediaUpload.find("input").on("change", function() {
- var file = this.files[0];
- mediaUpload.find(".innerBtn").text("替换");
- mediaUpload.find(".playBox").removeClass("hide");
- mediaUpload.find(".title").text(file.name);
- mediaUpload.find('#query-bgm').attr('href', URL.createObjectURL(file));
- });
- //删除音乐
- mediaUpload.on("click", ".delete", function() {
- mediaUpload.find('#query-bgm').attr('href', "");
- mediaUpload.find(".playBox").addClass("hide");
- mediaUpload.find(".innerBtn").text("上传");
- mediaUpload.find("input").val("").removeAttr("data-hotbgm");
- }) */
- this.musicBox = musicPlayBoxBind($("#hotpointDetail .audio.mediaUpload"), null )
- }
- //添加热点模型列表dom
- Hotpoint.prototype.inputList = function(text, val) {
- var _val = '';
- if (arguments[1]) {
- _val = 'value=' + val;
- }
- return '<div class="link"> <input class="text" type="text" placeholder=' + text + ' spellcheck="false" ' + _val + ' > </div>'
- }
- //添加热点模型
- Hotpoint.prototype.addModel = function() {
- var text = this.inputList("请填写模型链接(https开头)");
- this.hotpointDetail.find(".model .add").on('click', function() {
- $(this).closest(".model").find(".list").append(text)
- });
- this.hotpointDetail.find(".model .delete").on('click', function() {
- $(this).closest(".model").find(".list > div:last").remove();
- });
- }
- //添加网页链接
- Hotpoint.prototype.addwebPack = function() {
- var text = this.inputList("请填写网页链接", "");
- this.hotpointDetail.find(".webPage .add").on('click', function() {
- $(this).closest(".webPage").find(".list").append(text)
- });
- this.hotpointDetail.find(".webPage .delete").on('click', function() {
- $(this).closest(".webPage").find(".list > div:last").remove();
- });
- }
- // 保存热点信息
- Hotpoint.prototype.saveHot = function() {
- var $layout = $(".edit-loading");
- var hotpointDetail = this.hotpointDetail;
-
- var that = this
- //获取唯一标识
- var spot_id = hotpointDetail.attr("data-id");
- var spot = this.spotList.find("li[data-spid=" + spot_id + "]");
- var hot = player.model.hots[spot_id];
- //显示loading
- $layout.removeClass('hide');
- var args = {};
- //热点标题
- var $title = hotpointDetail.find(".info input");
- //热点内容
- var $content = hotpointDetail.find(".info textarea");
- //热点图片
- var $images = hotpointDetail.find(".photo .edit-fun-images a.result");
- //热点视频
- var $videos = hotpointDetail.find(".video .edit-fun-images a.result");
- //热点视频的图片
- var $thums = hotpointDetail.find(".video .edit-fun-images .upload-thum");
- //热点模型
- var $modules = hotpointDetail.find(".model input");
- //热点内嵌网页
- var $iframes = hotpointDetail.find(".webPage input.text");
- //热点音乐
- var $miusc = hotpointDetail.find("#upload-hotBgm");
- let $bgName = hotpointDetail.find('.title');
- var promise = new Promise(function(resolve, reject) {
- //获取图片路径
- upload($images, 'images', resolve)
- }).then(function(imgUrls) {
- args.images = imgUrls
- //获取视频路径
- return new Promise(function(resolve, reject) {
- upload($videos, 'videos', resolve)
- }
- )
- }).then(function(videoUrls) {
- args.video = videoUrls
- //获取视频封面路径
- return new Promise(function(resolve, reject) {
- upload($thums, 'images', resolve)
- }
- )
- }).then(function(thums) {
- args.video = args.video.map(function(video, index) {//整合视频+封面
- return {
- url: video,
- img: thums[index]
- }
- })
- }).then(function() {
- //获取热点音乐所有的路径
- //console.log($miusc)
- if ($miusc[0].files.length > 0) {
- return new Promise(function(resolve) {
- upload($miusc, 'miusc', function(res) {
- resolve(res[0])
- })
- }
- )
- } else {
- return $miusc.attr('data-hotBgm')
- }
- }).then(function(src) {
- if(that.musicBox.hasMusic && !src){
- args.backgroundMusic = hot.infoAttribute.backgroundMusic
- args.bgName = hot.infoAttribute.bgName
- }else{
- args.backgroundMusic = src
- args.bgName = $bgName[0].innerHTML;
- }
-
- }).then(function() {
- //上传所有热点的style图片
- var a = $.Deferred();
- var doneNum = 0;
- var imgsNeedSave = [];
- Array.from(that.styleList.listDom.children()).forEach(li=>{
- if(li.sameTexSpots.length == 0)return;//没被热点用到就不保存
- li.sameTexSpots.forEach(spot=>spot.styleImg = li._styleImg)//同步下
-
- li._styleImg.forEach(img=>{
- if(img.needSave && !imgsNeedSave.includes(img)){
- imgsNeedSave.push(img)
- }
- })
- })
- if(imgsNeedSave.length){
- imgsNeedSave.forEach(img=>{
- uploadFile(img.file, 'hot/image', function(rs) {
- if (rs.code === 0) {
- img.needSave = false;
- //img.saveURL = rs.data;
- img.src = rs.data;
- if (++doneNum >= imgsNeedSave.length) {
- a.resolve();
- }
- } else {
- alert("样式图上传失败");
- a.reject();
- }
- })
- })
- return a.promise()
- }else{
- return a.resolve()
- }
-
-
- }).then(function() {
- //获取热点标题、内容、内嵌网页、模型网页。
- args.title = $title.val()
- args.content = $content.val()
- var iframes = []
- for (var i = 0; i < $iframes.length; i++) {
- var iframe = $iframes.eq(i).val()
- iframe && iframes.push(iframe)
- }
- args.iframe = iframes
- var modules = []
- for (var i = 0; i < $modules.length; i++) {
- var module = $modules.eq(i).val()
- module && modules.push(module)
- }
- args.model = modules
-
- if(!hot.isSprite){
- args.quaternion = hot.quaternion.clone()
- //hot.quaternion.copy(hot.mesh.quaternion)
- }
- args.position = hot.position.clone()
- //hot.position.copy(hot.mesh.position)
-
- return args
- }).then(function(args) {
-
-
- console.log(args);
- //把获取的所有信息都保存在对应热点的dom元素里面
- //hotpointDetail[0].targetDOM.infoAttribute = args;
-
- if($("#hotpointDetail .scale .MenuOptions li.chosen").attr('index') == 'user' ){
- args.hotIconScale = $("#hotIconScale_2 input").val();
- }else{
- delete args.hotIconScale
- }
- hot.infoAttribute = args;
-
-
- for(let i in player.model.hots){//修改所有的热点贴图数据
- let hot = player.model.hots[i];
- let li = that.styleList.findChosenByImgs(hot.styleImg).item
- if(li) hot.infoAttribute.styleImg = li._styleImg.map(img=> img.src)//将blob更换成线上链接
- }
-
-
- hot.setTitleElem()//更新名称
-
-
- $layout.addClass('hide');
- hotpointDetail.addClass("atRight");
- spot.find(".title").html(args.title);
- transformControls.detach()
- that.editSpot = null
-
-
- })
- return promise
- }
- //背景音乐
- var EditMiuse = function() {
- this.mediaUpload = $(".music .audio.mediaUpload");
-
- this.musicBox = musicPlayBoxBind(this.mediaUpload, (file)=>{
- uploadMiuse(file, (rs, file)=>{
- if (rs.code === 0) {
- this.musicBox.show(this.mediaUpload, file.name, rs.data)
- }else{
- this.musicBox.hide()
- }
- })
- }, null)
-
- /* this.success = function(text, url) {
- this.mediaUpload.find(".innerBtn").text("替换");
- this.mediaUpload.find(".playBox").removeClass("hide");
- this.mediaUpload.find(".title").text(text);
- this.mediaUpload.find('#query-bgm').attr('href', url)
- }
- ;
- this.delete = function() {
- this.mediaUpload.find('#query-bgm').attr('href', "");
- this.mediaUpload.find(".playBox").addClass("hide");
- this.mediaUpload.find(".innerBtn").text("上传");
- this.mediaUpload.find("input").val("");
- }
- ;
- var that = this;
- $('#upload-bgm').on('change', function(e) {
- var file = this.files[0];
- uploadMiuse(file, function(rs, file) {
- if (rs.code === 0) {
- that.success(file.name, rs.data)
- }
- })
- e.target.value = null
- });
- //删除音乐
- this.mediaUpload.on("click", ".delete", function() {
- that.delete();
- }) */
- }
- EditMiuse.prototype.init = function(data) {
- if (!data.backgroundMusic)
- return;
- this.musicBox.show(this.mediaUpload, data.bgName || "backgound", data.backgroundMusic);
-
- }
- //导览编辑
- var EditGuide = function() {
- this.$list = $('#guide-list')
- //$('#tourItemEdit') = $('#tourItemEdit');
- this.targetTourPoint = null;
- // fyz 记录当前编辑的导览点
- // fyz 导览音乐队列
- //this.tourAudio = {};
- }
- /**
- * @author fyz 2019.07.31
- * @description 新增参数data2, 表示data2.js中的数据
- */
-
- /* function snapATourView(that, renew) {
- var ev = document.createEvent("MouseEvent");
- ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
- g_snapShotWidth = 200;
- g_snapShotHeight = 140;
- window.screenSta = 'tour';
- // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
- ev.__callback = function(imgData, info) {
- that.uploadGuide(imgData, info, renew, that.targetTourPoint)
- }.bind(that);
- window.dispatchEvent(ev);
- } */
- EditGuide.prototype.snapATourView = function(renew, insideFolder){
- var ev = document.createEvent("MouseEvent");
- ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
- g_snapShotWidth = 200;
- g_snapShotHeight = 140;
- window.screenSta = 'tour';
- // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
- ev.__callback = (imgData, info)=> {
- this.uploadGuide(imgData, info, renew, insideFolder)
- };
- window.dispatchEvent(ev);
- }
- EditGuide.prototype.init = function(data, data2) {
-
-
-
- this.createDom(data, data2);
-
- //this.tourAudio = data2.tourAudio || {};
-
-
- var that = this;
-
-
- //点击添加导览
- $('.addTour .innerBtn').eq(0).on("click", function () {
- this.addFolderDom({name:"区域"+($("#tourList .listItem").length+1) } );//点击增加一段导览
- $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight //scroll to bottom
- }.bind(this));
-
- $('.addTour .innerBtn').eq(1).on("click", function () {
- this.snapATourView()//点击截取视图
- $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight
- }.bind(this));
-
-
- $('.snapATourView .innerBtn').on("click", function() {
- this.snapATourView(null,true);//folder内点击截取视图
- $("#tourItemList ul")[0].scrollTop = $("#tourItemList ul")[0].scrollHeight
- }.bind(this));
-
- $('#renewTourBtn').on("click", function() { // 重新截取视图
- this.snapATourView(this, !!this.editingFolderLi);
- }.bind(this));
-
-
- // 确认并保存导览信息
-
- $('#tourFolderEdit .tourSubmit').on("click", function() {
- this.completeFolder();
- }.bind(this));
- $('#tourItemEdit .tourSubmit').on("click", function() {
- this.completeItem();
- }.bind(this));
-
- //点击导览编辑窗口右上角的关闭按钮
- /* $("#tourItemEdit a.close, button.cancel").on("click", function() {
- that.targetTourPoint[0].musicSta = true; ///??????????
- // 取消操作, 重置状态
- that.tourDetail.addClass("atRight");
- }); */
-
-
-
- //导览目录
- $("#tourList").on("click", function(e) {
- var target = $(e.target);
- let folder = searchParent(e.target, { className: 'listItem' }, 7);
- if(!folder)return;//可能点到了item
- if (target.hasClass("del")) {
- e.stopPropagation();
- target.siblings(".DelConfirm").addClass("active");
- } else {
- if (target.hasClass("DelConfirm")) {
- e.stopPropagation();
- $(folder).remove()
- //that.removeFolder(folder);//删除
- } else {
- if (target.hasClass("title") || target.hasClass("icon")) {
- that.editFolder(folder)//编辑
- }
- }
- }
- });
-
-
-
- //编辑item
- $('.tourList ul').on('click', function(e) {
- var target = $(e.target);
- let itemDom = searchParent(e.target, { className: 'guideItem' }, 7);
- if(!itemDom)return;//可能点到了folder
- if(searchParent(e.target, { className: 'preview' })){
- var choice = confirm("你确定删除吗?");
- if (choice) {
- var ul = searchParent(e.target, { className: 'tourList' })
-
- target.closest('li').remove();
-
- reIndexTourList(ul)
- } else {
- return false
- }
- }else{
- that.editItem(itemDom);
- }
- })
-
-
- //fyz 拖拽以改变顺序
- let tourListNode = $("#tourList>ul")[0];
- let tourItemListNode = $("#tourItemList>ul")[0];
- let draging = null;
- let dragStart = (event)=> {
- event.dataTransfer.setData("te", event.target.innerText); //不能使用text,firefox会打开新tab
- draging = event.target;
- }
-
-
- let dragOver = (event)=>{
- event.preventDefault();
- let target = searchParent(event.target, { tagName: 'LI' }, 7); //event.target.parentNode.parentNode;
-
-
- // 判断dragover是否发生在LI元素上
- if ((target.classList.contains('guideItem') || target.classList.contains('listItem')) && target !== draging ) {
- let dragingIndex = $(draging).index()//draging.querySelector('#index');
- let targetIndex = $(target).index()//target.querySelector('#index');
-
-
- var targetRect = target.getBoundingClientRect();
- var dragingRect = draging.getBoundingClientRect();
- if (target && target.animated) {
- return;
- }
- let ulElem = target.parentNode;
- // 寻找到 ul节点
- if (getIndex(draging) < getIndex(target)) {
- //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
- // 交换两个节点的序号
-
- if(event.clientY<targetRect.top+targetRect.height*0.3)return
- ulElem.insertBefore(draging, target.nextSibling);
- //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];// 交换两个节点的序号
-
- } else {
- //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
- if(event.clientY>targetRect.bottom-targetRect.height*0.3)return
- ulElem.insertBefore(draging, target);
- //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
- }
- _animate(dragingRect, draging);
- _animate(targetRect, target);
-
- var ul = searchParent(event.target, { className: 'tourList' })
- reIndexTourList(ul)
-
- }
- }
-
-
- tourListNode.ondragstart = dragStart
- tourItemListNode.ondragstart = dragStart
- tourListNode.ondragover = dragOver
- tourItemListNode.ondragover = dragOver
-
-
-
-
- //音乐
-
- this.musicBox = musicPlayBoxBind($(".snapTour .audio.mediaUpload"), null, ()=>{
- (that.editingFolderLi || that.editingItemLi).tourData.musicInfo = {}//直接删除 不可逆
- })
-
- /*
- var mediaUpload = $(".snapTour .audio.mediaUpload");
- var that = this;
- mediaUpload.find("input").on("change", function(e) {
- if(!e.target.files.length) return;
- var mediaDom = $(searchParent(e.target, { className: 'mediaUpload' }));
- var file = e.target.files[0];
- mediaDom.find(".innerBtn").text("替换");
- mediaDom.find(".playBox").removeClass("hide");
- mediaDom.find(".title").text(file.name);
- mediaDom.find('#query-bgm').attr('href', URL.createObjectURL(file));
- //that.editingFolderLi.musicSta = true;
- });
- mediaUpload.find("input").on("click", function() {
- mediaUpload
- });
- //删除音乐
- mediaUpload.on("click", ".delete", function(e) {
- var mediaDom = $(searchParent(e.target, { className: '.mediaUpload' }));
- mediaDom.find('#query-bgm').attr('href', "");
- mediaDom.find(".playBox").addClass("hide");
- mediaDom.find(".innerBtn").text("上传");
- mediaDom.find("input").val("")//.removeAttr("data-hotbgm");
- //that.editingFolderLi.musicSta = false;
- (that.editingFolderLi || that.editingItemLi).data.musicInfo = {}//直接删除 不可逆
-
- }) */
-
-
-
-
-
-
- }
- function musicPlayBoxBind($dom, addCallback, delCallback){
- var musicBox = {
- hasMusic:false,
- show: function(mediaDom, name, url){
- mediaDom = mediaDom || $dom
- mediaDom.find(".innerBtn").text("替换");
- mediaDom.find(".playBox").removeClass("hide");
- mediaDom.find(".title").text(name);
- mediaDom.find('#query-bgm').attr('href', url);
- musicBox.hasMusic = true
- },
- addMusic : function(e) {
- if(!e.target.files.length) return;
- var file = e.target.files[0];
-
- if (!/audio\/\w+/.test(file.type)) {
- alert("文件必须为音乐!");
- return false;
- }
- //限制大小不大于8m
- if (!restrictedSize(file, _musicMaxWeight)) {
- return false
- }
- var mediaDom = $(searchParent(e.target, { className: 'mediaUpload' }));
- musicBox.show(mediaDom, file.name, URL.createObjectURL(file))
-
- addCallback && addCallback(file)
- },
- hide : function(e) {
- var mediaDom = e ? $(searchParent(e.target, { className: 'mediaUpload' })) : $dom
-
- mediaDom.find('#query-bgm').attr('href', "");
- mediaDom.find(".playBox").addClass("hide");
- mediaDom.find(".innerBtn").text("上传");
- mediaDom.find("input").val("")//.removeAttr("data-hotbgm");
- musicBox.hasMusic = false
- delCallback && delCallback()
-
-
- }
-
- }
-
- $dom.find("input").on("change", musicBox.addMusic)
-
- /* $dom.find("input").on("click", function() {
- mediaUpload
- }); */
- //删除音乐
- $dom.on("click", ".delete", musicBox.hide)
-
-
- return musicBox;
- }
- function reIndexTourList(ul) {
- Array.from($(ul).find('li.guideItem')).forEach((li,index)=>{
- $(li).find("div:first-child span").text(index + 1);
- })
-
- }
-
- EditGuide.prototype.addFolderDom = function( tourData){
- var $folder = $("<li class='listItem' draggable='true'>" + "<div class=icon></div>" + "<div class=title >" + (tourData.name || "") + "</div>" + "<div class=DelConfirm>确定删除</div>" + "<div class=del></div>" + "</li>");
-
- $folder[0].tourItemDoms = [] //记录所有item的li dom
- $folder[0].tourData = tourData //注: data中的locations不会更新,保存时直接读取li
- $("#tourList ul").append($folder);
-
- return $folder
-
- }
- EditGuide.prototype.getItemDom = function(title, img) {
- return '<li draggable="true" class="guideItem">' + '<div>' + '<span id="index"></span>' + '<div class="line"></div>' + '</div>' + '<div>' + '<span class="guide-name" >' + title + '</span>' + '<input maxlength="14" class="hide" data-oper=tour-input>' + '</div>' + '<div class="preview" >' + '<div id="tourBg" style="background-image: url(' + img + ');" >' + '</div>' + '</div>' + '</li >';
- }
-
-
- EditGuide.prototype.createDom = function(data, data2) {
-
- var that = this;
- var tourAudio = data2.tourAudio || {};
-
- data.model.images.forEach((Info,index)=>{
- if(Info.locations){//是folder
- var $folder = this.addFolderDom(Info)
- // 音频链接
- Info.locations = Info.locations.filter(e=>e)
- Info.locations.forEach(function(info, index) {
- if (info.thumbnail_signed_src) {
- var $li = $(that.getItemDom( info.name, info.thumbnail_signed_src));
- $li[0].tourData = info
- $folder[0].tourItemDoms.push($li[0])
-
- }
- })
- }else{//是散落在外的item
- if (Info.thumbnail_signed_src) {
- var $li = $(that.getItemDom(Info.name, Info.thumbnail_signed_src));
- $li[0].tourData = Info
- // 音频链接
- $li[0].tourData.musicInfo = $li[0].tourData.musicInfo || tourAudio[Info.sid] || {}//新的music数据统一写在每个info下
-
- $("#tourList ul").append($li)
-
- /* if (Info.sid in tourAudio && tourAudio[info.sid].music && tourAudio[info.sid].music !== '') {
- //$li[0].musicUrl = tourAudio[info.sid].music;
- $li[0].musicInfo = tourAudio[info.sid]
- } */
- }
- }
- })
- reIndexTourList($("#tourList")[0])
-
-
- }
-
- //暂时不实时更新左侧场景,所以信息全写在UI上,不保存data
-
- EditGuide.prototype.editFolder = function(folderDom){
-
- this.editingFolderLi = folderDom;
-
- $("#tourFolderEdit").removeClass('atRight');
- $("#tourFolderEdit .tourName input").val( $(folderDom).find('.title').text()||'');
- //$("#folderTourSwitch input").prop('checked', folderDom.tourData.momentTour === 'black');
-
- var momentTour = folderDom.tourData.momentTour || "default"
- $("#folderTourSwitch li").removeClass('chosen')
- $("#folderTourSwitch li[index="+ momentTour +"]").addClass('chosen');
-
-
- folderDom.tourItemDoms.forEach(li=>{
- $("#tourItemList>ul").append(li)
- })
- reIndexTourList($("#tourItemList>ul")[0])
- //判断当前点是否有导览音频
-
- //target[0].musicSta = true;
- //var audio = this.tourAudio[target.closest('li')[0].data.sid];
- var musicInfo = this.editingFolderLi.tourData.musicInfo //audio ? audio.music : null;
- if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
- var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
- /* $('#tourFolderEdit').find(".audio .playBox").removeClass("hide");
- $('#tourFolderEdit').find(".audio .playBox a").attr("href", "//" + musicInfo.music);
- $('#tourFolderEdit').find(".audio .submit").text("替换");
- $('#tourFolderEdit').find(".title").text(musicName); */
-
- this.musicBox.show($('#tourFolderEdit .mediaUpload'), musicName, "//" + musicInfo.music)
- } else {
- /* $('#tourFolderEdit').find(".audio .playBox").addClass("hide");
- $('#tourFolderEdit').find(".audio .submit").text("上传"); */
- this.musicBox.hide()
- }
-
- }
-
- /**
- * @author fyz 编辑单个导览item
- * @param {any} target 所点击的导览点
- */
- EditGuide.prototype.editItem = function(li) {
- //this.targetTourPoint = target;
-
- this.editingItemLi = li
-
- // 记录当前编辑的导览点
- var that = this;
- $('#tourItemEdit').removeClass('atRight');
- $('#tourItemEdit .tourName input').val( $(li).find('.guide-name').text() );
-
- var momentTour = li.tourData.momentTour || "default"
- $("#tourSwitch_Slice li").removeClass('chosen')
- $("#tourSwitch_Slice li[index="+ momentTour +"]").addClass('chosen');
-
- var metadata = JSON.parse(li.tourData.metadata);
- if(metadata.scan_id != 'outside'){
- var pano = player.model.panos.index[metadata.scan_id]
- if(pano){
- var q = new THREE.Quaternion().copy(metadata.camera_quaternion);
- player.flyToPano({
- pano: pano,
- quaternion: q,
- zoomLevel: metadata.zoom
- })
- }
- }
-
- if(!this.editingFolderLi){//在外的item, 可以上传音乐
- $('#tourItemEdit .mediaUpload').removeClass('hide')
- var musicInfo = li.tourData.musicInfo //audio ? audio.music : null;
- if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
- var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
- /* $('#tourItemEdit').find(".audio .playBox").removeClass("hide");
- $('#tourItemEdit').find(".audio .playBox a").attr("href", "//" + musicInfo.music);
- $('#tourItemEdit').find(".audio .submit").text("替换");
- $('#tourItemEdit').find(".title").text(musicName); */
- this.musicBox.show($('#tourItemEdit .mediaUpload'), musicName, "//" + musicInfo.music)
- } else {
- this.musicBox.hide()
- /* $('#tourItemEdit').find(".audio .playBox").addClass("hide");
- $('#tourItemEdit').find(".audio .submit").text("上传"); */
- }
-
- }else{
- $('#tourItemEdit .mediaUpload').addClass('hide')
- }
-
-
- }
- EditGuide.prototype.completeFolder = function(){//点击完成
-
-
- var tourName = $('#tourFolderEdit .tourName input').val() //|| this.targetTourPoint.context.innerText;
- $(this.editingFolderLi).find(".title").text(tourName)
- //this.editingFolderLi.tourData.momentTour = $("#folderTourSwitch input").is(':checked') ? "black" : 'walk'
-
- var momentTour = $("#folderTourSwitch li.chosen").attr("index");
- this.editingFolderLi.tourData.momentTour = momentTour != 'default' ? momentTour : null;
-
-
- this.editingFolderLi.tourItemDoms = Array.from($('#tourItemList ul li'));
-
- var done = ()=>{
- $("#tourFolderEdit .audio.mediaUpload").find("input").val(''); // 清空 文件
- this.editingFolderLi = null
- $("#tourFolderEdit").addClass('atRight');
- $(".edit-loading").addClass('hide');
- $("#tourItemList>ul").html('')
- }
-
- //save导览音乐
- var tourAudio = $('#tourFolderEdit .mediaUpload input');
-
- // 记录音频名称
-
-
-
- //判断当前编辑的导览点位是否已上传音乐
- if (tourAudio[0].files.length > 0/* && this.targetTourPoint[0].musicSta */) { //有input文件
- $(".edit-loading").removeClass('hide');
-
- var musicName = $('#tourFolderEdit .mediaUpload .title').text();
-
- new Promise( (resolve, reject)=> {
- uploadMiuse(tourAudio[0].files[0], function(res) {
- resolve(res.data);
- })
- } ).then( (src)=>{
- var audio = new Audio();
- audio.src = src;
- audio.onloadedmetadata = ()=>{
- var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
- srcArr[0] = '';
- src = srcArr.join('/');
- //var sid = this.editingFolderLi.data.sid
- //that.tourAudio[sid] = {
- this.editingFolderLi.tourData.musicInfo = {
- "name": musicName,
- "music": '/' + src,
- "time": Math.round(audio.duration * 1000 + 1000)
- }
- done()
- }
- })
- }else done()
-
-
- }
- EditGuide.prototype.completeItem = function() {//点击完成
-
- var done = ()=>{
- $("#tourItemEdit .audio.mediaUpload").find("input").val(''); // 清空 文件
- this.editingItemLi = null
- $("#tourItemEdit").addClass('atRight');
- $(".edit-loading").addClass('hide');
- }
-
-
- var tourName = $('#tourItemEdit .tourName input').val()
- $(this.editingItemLi).find('.guide-name').text(tourName)
-
- var momentTour = $("#tourSwitch_Slice li.chosen").attr("index");
- this.editingItemLi.tourData.momentTour = momentTour != 'default' ? momentTour : null;
-
- //save导览音乐
- var tourAudio = $('#tourItemEdit .mediaUpload input');
- //判断当前编辑的导览点位是否已上传音乐
- if (!this.editingFolderLi && tourAudio[0].files.length > 0) { //有input文件
- $(".edit-loading").removeClass('hide');
-
- var musicName = $('#tourItemEdit .mediaUpload .title').text();
-
- new Promise( (resolve, reject)=>{
- uploadMiuse(tourAudio[0].files[0], function(res) {
- resolve(res.data);
- })
- } ).then( (src)=>{
- var audio = new Audio();
- audio.src = src;
- audio.onloadedmetadata = ()=>{
- var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
- srcArr[0] = '';
- src = srcArr.join('/');
- //that.tourAudio[sid] = {
- this.editingItemLi.tourData.musicInfo = {
- "name": musicName,
- "music": '/' + src,
- "time": Math.round(audio.duration * 1000 + 1000)
- }
- done()
- }
- })
- }else done()
-
- }
-
- /**
- * @author fyz 2019.07.31
- * @description uploadGuide方法新增参数renew状态码, 表示是否重新录制当前导览, 新增targetTourPoint, 记录当前的导览点元素
- */
- EditGuide.prototype.uploadGuide = function(urlData, guide, renew, insideFolder) {
- var that = this;
- uploadImg(urlData, function(rs) {
- if (rs.code === 0) {
- //var editGuide = new EditGuide();
- var sid = rs.data.substring(rs.data.lastIndexOf('/') + 1, rs.data.lastIndexOf('.'));
- var thumbnail_signed_src = rs.data;
- var args = JSON.parse("{" + guide + "}");
- args.sid = sid;
- args.name = '';
- args.thumbnail_signed_src = thumbnail_signed_src;
- args.metadata = JSON.stringify({
- camera_mode: args.metadata.camera_mode,
- camera_position: {
- x: args.metadata.camera_position[0],
- y: args.metadata.camera_position[1],
- z: args.metadata.camera_position[2]
- },
- camera_quaternion: {
- x: args.metadata.camera_quaternion[0],
- y: args.metadata.camera_quaternion[1],
- z: args.metadata.camera_quaternion[2],
- w: args.metadata.camera_quaternion[3]
- },
- ortho_zoom: args.metadata.ortho_zoom,
- scan_id: args.metadata.scan_id || "outside",
- //这个"outside"不能随便改成别的
- /* final_angle: 110,
- is_ortho: false, */
- zoom: args.metadata.zoom // fyz zoom是内部计算的zoomLevel, 乘以系数1.06才是实际缩放倍数
- })
- if (renew/* && target */) { // 重新录制导览
- // 更新数据
-
- var musicInfo = insideFolder || that.editingItemLi.tourData.musicInfo;
- musicInfo && (args.musicInfo = musicInfo);
- $(that.editingItemLi).find('#tourBg')[0].style.backgroundImage = 'url(' + args.thumbnail_signed_src + ')';
- //args.name = insideFolder $('#tourItemEdit').find('#tourNameInput').val()
-
-
- /* var oldId = target.closest('li')[0].data.sid;
- that.tourAudio[args.sid] = that.tourAudio[oldId];
- // 新生成的id指向以前的导览音频
- delete that.tourAudio[oldId];
- // 删除导览音频中的旧导览id */
- that.editingItemLi.tourData = args;
-
- //target.text(args.name); // 更新导览列表中的导览名称 //不改名字
- //$('#tourItemEdit').find('#tourNameInput').val(args.name); // 修改输入框内容
- } else {
- var $li = $(that.getItemDom(args.name, args.thumbnail_signed_src));
-
- $li[0].tourData = args;
-
- var $ul = insideFolder ? $("#tourItemList>ul") : $("#tourList>ul")
- $ul.append($li);
- reIndexTourList($ul[0])
-
- }
- }
- })
- }
- EditGuide.prototype.getSavingInfo = function(){
- var data = []
-
-
- Array.from($("#tourList ul li")).forEach(dom=>{
- if(dom.classList.contains("guideItem")){//item
- dom.tourData.name = $(dom).find('.guide-name').text()
- data.push(dom.tourData)
- }else{//folder
- var dataFolder = dom.tourData;
- dataFolder.name = $(dom).find('.title').text()
- dataFolder.locations = dom.tourItemDoms.map(li => li.tourData )
- data.push(dataFolder)
- }
- })
-
-
- return data
- }
- /* -- 以下是一些公用的方法 -- */
- //限制大小
- var restrictedSize = function(file, _size) {
- //限制大小不大于8m
- var fileSize = 0;
- var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
- if (isIE && !file) {
- var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
- var _file = fileSystem.GetFile(filepath);
- fileSize = _file.Size;
- } else {
- fileSize = file.size;
- }
- var size = fileSize / 1024;
- var RSize = _size * 1024;
- if (size > RSize) {
- alert("文件不能大于" + _size + "M");
- return false;
- }
- if (size <= 0) {
- alert("文件大小不能为0M!");
- return false;
- }
- return true
- }
- //上传音乐
- var uploadMiuse = function(file, callback) {
- uploadFile(file, 'audio', callback);
- }
- $(".toolRight .music .itemTitle span").text(`背景音乐 (<${_musicMaxWeight}M)`)
- //上传图片
- function uploadImg(urlData, callback, fileName) {
- //console.log('urlData',urlData);
- if(!fileName)fileName = getRandomSid() + '.jpg'
- var bytes = window.atob(urlData.split(',')[1]);
- //去掉url的头,并转换为byte
- //处理异常,将ascii码小于0的转换为大于0
- var ab = new ArrayBuffer(bytes.length);
- var ia = new Uint8Array(ab);
- for (var i = 0; i < bytes.length; i++) {
- ia[i] = bytes.charCodeAt(i);
- }
- var blob = new Blob([ab],{
- type: 'image/jpeg',
- });
- uploadFile(blob, 'hot/images', callback, fileName);
- }
- //上传文件
- function uploadFile(file, type, callback, fileName) {
- $(".edit-loading").removeClass("hide");
- var formData = new FormData()
- formData.append('name', number)
- formData.append('dir', type)
- formData.append('random', true)
- //formData.append('file', file)
- formData.append("file", file, fileName);
- let url = cmp ? ('/api/scene/upload/' + number) : ('/manage/scene/upload/' + number)
- $.ajax({
- url: ceshi + url,
- data: formData,
- headers: {
- token: token
- },
- dataType: 'json',
- type: 'POST',
- cache: false,
- //上传文件无需缓存
- processData: false,
- //用于对data参数进行序列化处理 这里必须false
- contentType: false,
- //必须
- success: function(rs) {
- if (rs.code === 5001) {
- alert('请重新登录')
- localStorage.dcj_token = ''
- location.reload()
- }
- callback(rs, file);
- $(".edit-loading").addClass("hide");
- }
- })
- }
- function _animate(prevRect, target) {
- var ms = 300;
- if (ms) {
- var currentRect = target.getBoundingClientRect();
- if (prevRect.nodeType === 1) {
- prevRect = prevRect.getBoundingClientRect();
- }
- _css(target, 'transition', 'none');
- _css(target, 'transform', 'translate3d(' + (prevRect.left - currentRect.left) + 'px,' + (prevRect.top - currentRect.top) + 'px,0)');
- target.offsetWidth;
- // 触发重绘
- //放在timeout里面也可以
- // setTimeout(function() {
- // _css(target, 'transition', 'all ' + ms + 'ms');
- // _css(target, 'transform', 'translate3d(0,0,0)');
- // }, 0);
- _css(target, 'transition', 'all ' + ms + 'ms');
- _css(target, 'transform', 'translate3d(0,0,0)');
- clearTimeout(target.animated);
- target.animated = setTimeout(function() {
- _css(target, 'transition', '');
- _css(target, 'transform', '');
- target.animated = false;
- }, ms);
- }
- }
- //给元素添加style
- function _css(el, prop, val) {
- var style = el && el.style;
- if (style) {
- if (val === void 0) {
- if (document.defaultView && document.defaultView.getComputedStyle) {
- val = document.defaultView.getComputedStyle(el, '');
- } else if (el.currentStyle) {
- val = el.currentStyle;
- }
- return prop === void 0 ? val : val[prop];
- } else {
- if (!(prop in style)) {
- prop = '-webkit-' + prop;
- }
- style[prop] = val + (typeof val === 'string' ? '' : 'px');
- }
- }
- }
- function upload($files, type, cb) {
- var length = $files.length
- var rcount = 0
- var result = []
- Array.from($files).forEach(function(dFile, index) {
- //a 标签的success 是用来判断是否是已经上传过的文件
- //attr-thum 属性是视频的图片
- //videoURL 是判断是否有视频
- var $file = $(dFile)
- var $image = type == 'videos' ? $file.find('img.play-video') : $file.find('img')
- if ($file.hasClass('success')) {//已经上传过,有链接
- if ($file.attr('attr-thum')) {//视频的封面
- result[index] = $file.attr('attr-thum')
- } else if ($image.attr('videoURL')) {//视频
- result[index] = $image.attr('videoURL')
- } else {
- result[index] = $image.attr('src')
- }
- return success(++rcount);
- } else {
- switch ($file[0].localName) {
- case "input":
- dFile = $file[0]
- break;
- case "span"://封面
- dFile = $file.find('input')[0];
- break;
- case "a"://重传的图or视频
- dFile = {files:[$file[0].file]}
- //dFile = $file.find('input')[0];
- break;
- default:
- dFile = $file.closest("li").find('.upload input')[0];
- break;
- }
- // dFile = $file[0].localName === "input" ? $file[0] : $file[0].localName === "span" ? $file.find('input')[0] : $file.closest("li").find('.upload input')[0];
- }
- var file = (dFile.files && dFile.files[0]) || '';
- if (!file)
- return success(++rcount);
- uploadFile(file, 'hot/' + type, function(rs) {
- //似乎所有图保存路径都是这个hot/前缀。图地址 :"场景id/edit/重新生成的文件名.原后缀", 展示页面也是。
- if (rs.code === 0) {
- result[index] = rs.data
- }
- ;success(++rcount);
- })
- })
- //判断当前队列元素是否处理成功
- function success() {
- if (rcount === length) {
- cb(result)
- }
- }
- success()
- }
- function getIndex(el) {
- let index = 0;
- if (!el || !el.parentNode) {
- return -1;
- }
- while (el && (el = el.previousElementSibling)) {
- index++;
- }
- return index;
- }
- dataURLtoBlob = function(dataurl) {
- //将base64转换blob
- var arr = dataurl.split(',')
- , mime = arr[0].match(/:(.*?);/)[1]
- , bstr = atob(arr[1])
- , n = bstr.length
- , u8arr = new Uint8Array(n);
- while (n--) {
- u8arr[n] = bstr.charCodeAt(n);
- }
- return new Blob([u8arr],{
- type: mime
- });
- }
- ;
- //=========================
- var eachMaxWeights = {
- //大小限制
- "photo": 10,
- "video": 1000,//50, expand size for overlayVideo
- //20,
- "audio": 10 //5
- }
- var supportTypes = {
- //支持后缀
- "photo": ["jpg", "png", "jpeg", "bmp", "gif"],
- "audio": ["mp3", "aac", "ogg", "wav"/* , "m4a" */
- ],
- "video": ["mp4", "mov"/* ,"webm", "rmvb", "wmv" */
- ]//ios:mov
- }
- function getExt(name) {
- //后缀
- if (name.indexOf('.') > -1) {
- var a = name.split(".");
- return a.pop();
- } else {
- return '';
- }
- }
- function detectType(fileName) {
- //检测文件后缀类型
- console.log("名:" + fileName)
- var ext = getExt(fileName);
- console.log("后缀:" + ext)
- //不一定所有浏览器都可以
- var type;
- //仅能根据后缀判断类型,尽管后缀可能被修改。 其他方法如file.type和base64开头的字符串均是根据后缀。
- for (var i in supportTypes) {
- if (supportTypes[i].indexOf(ext.toLowerCase()) > -1) {
- type = i;
- break;
- }
- }
- if (type) {
- return type;
- } else {
- return false;
- }
- }
- //手机上的相片会不会太大?
- var detectWeights = function(file, type) {
- //检测大小
- var size = file.size / 1024 / 1024;
- console.log("weight" + size)
- var over;
- if (size > eachMaxWeights[type]) {
- over = Math.ceil(size * 100) / 100;
- }
- return over;
- }
- var exitUpload = function(input) {
- $('.waiting').removeClass('showloading');
- input.value = "";
- }
- var inputMedia = function(options, type, e) {
- var input = e.target;
- if (!window.FileReader) {
- alert('您的浏览器不支持上传文件');
- exitUpload(input);
- return;
- } else if (e.target.files.length === 0) {
- /* exitUpload(input); */
- return;
- }
- $('.waiting').addClass('showloading');
- var file = e.target.files[0];
- var elemType = type;
- var inputType = detectType(file.name);
- var chType = {
- "photo": '图片',
- "video": '视频',
- "audio": '音乐'
- }
- var overWeight = detectWeights(file, inputType);
- if (elemType) {
- //有指定其中一种类型
- if (inputType != elemType) {
- alert("您选择的不是浏览器支持的" + chType[elemType] + '文件,请重新选择');
- exitUpload(e.target);
- return;
- }
- } else {
- if (!options.enableTypes.includes(inputType)) {
- var text = "";
- options.enableTypes.forEach((type,index)=>{
- text += ((index != 0 ? " / " : "") + chType[elemType])
- }
- )
- alert("您选择的不是浏览器支持的" + text + '文件,请重新选择');
- exitUpload(e.target);
- return;
- }
- }
- if (overWeight) {
- alert(`文件过大(${overWeight}兆),不能大于${eachMaxWeights[inputType]} 兆`)
- exitUpload(e.target);
- return;
- }
- var loadError = function() {
- exitUpload(e.target);
- alert(`文件出错, 无法加载此${chType[inputType]}文件。 文件可能损坏,或者浏览器不支持,或者后缀与文件不匹配。建议在IE以外的浏览器上传`)
- }
- deal();
- function deal(fi) {
- console.log('开始deal文件')
- var reader = new FileReader();
- //reader.name = file.name;
- file = fi || file;
- reader.readAsDataURL(file);
- reader.onload = function(evt) {
- var blob = dataURLtoBlob(evt.target.result);
- var blobSrc = window.URL.createObjectURL(blob);
- if (inputType == "photo") {
- /* EXIF.getData(file, function () {
- //获取相片旋转
- EXIF.getAllTags(this);
- var orient = EXIF.getTag(this, 'Orientation');
- var img = new Image();
- img.src = evt.target.result;
- img.onload = function (e) { //这时img才有宽高,才能赋予texture宽高
- var smallerImg = CompressImg(e.target, {
- weight: blob.size,
- maxWeight: 0.5 * 1024 * 1024,
- maxSize: 1480
- });
- //最大500k
- smallerImg.onload = function () {
- var f = function (resultImg) {//处理结束回调
- options.photoDone(resultImg)
- $('.waiting').removeClass('showloading');
- }
- Rotate(smallerImg, orient, f)
- window.URL.revokeObjectURL(blobSrc);
- }
- }
- .bind(this)
- img.onerror = loadError;
- }); */
- var img = new Image();
- img.src = blobSrc;
- img.base64Src = evt.target.result;
- img.file = file;
- img.onload = function(e) {
- options.photoDone(img)
- $('.waiting').removeClass('showloading');
- }
- } else if (inputType == "video") {
- var video = $('<video controls="controls" x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload"></video>')[0]
- video.setAttribute("crossOrigin", 'Anonymous')
- //要在src设置好前解决跨域
- $(video).on('contextmenu', function() {
- return false;
- });
- //禁止右键点击出现选项(尤其是下载选项)
- $(video).attr('src', blobSrc);
- //华为无法使用blobSrc,否则加载不出来
- //$(video).attr('src', evt.target.result);
- video.base64Src = evt.target.result;
- var hasload = false;
- var error = false;
- var up = function() {
- if (hasload)
- return;
- hasload = true;
- options.videoDone(file, video)
- $('.waiting').removeClass('showloading');
- }
- video.addEventListener('loadeddata', function(e) {
- up()
- })
- //video.onerror = loadError;
- video.onerror = function(e) {
- console.log('error')
- error = true;
- loadError();
- //将mp4改成mov后缀会error
- }
- } else if (inputType == "audio") {
- //林俊波 new Howl For IE&Safari:
- var sound = new Howl({
- src: [blobSrc],
- format: ["mp3"]
- });
- // Clear listener after first call.
- sound.once('load', function() {
- console.log('loaded sound')
- sound.unload()
- console.log("audio.onloadeddata");
- var audio = new Audio;
- audio.controls = "controls";
- audio.src = blobSrc;
- audio.base64Src = evt.target.result;
- options.audioDone(file, audio)
- $('.waiting').removeClass('showloading');
- //}
- });
- sound.once('loaderror', function() {
- loadError.apply(this, arguments)
- console.log('loaderror sound')
- });
- // Fires when the sound finishes playing.
- sound.on('end', function() {
- console.log('Finished sound');
- });
- }
- }
- }
- e.target.value = "";
- //更改value会触发change
- }
- .bind(player)
- //滑动条控件
- var SlideBar = function(o) {
- var scope = this;
- this.name = o.name;
- this.value = o.value;
- //初始值
- this.min = o.min != void 0 ? o.min : 0;
- this.max = this.oriMax = o.max != void 0 ? o.max : 100;
- this.noValue = o.noValue;
- //是否数值输入
- this.precision = o.precision;
- //精度 保留几位小数
- var div = $('<div><div class="Main"><div class="scrollBar"><div class="scroll_Track"></div><div class="scroll_Thumb"></div></div>' + (o.noValue ? '' : '<div class="BarTxt"><input class="scrollBarTxt"></div></div>'))
- div.addClass('slider')
- if (o.unitStr) {
- div.find(".BarTxt").append($('<span>' + o.unitStr + '</span>'));
- }
- o.root.append(div);
- this.line = $(".scrollBar", div);
- this.knot = $(".scroll_Thumb", div);
- o.noValue || (this.textArea = $(".scrollBarTxt", div));
- this.track = $(".scroll_Track", div);
- this.unitStr = o.unitStr;
- //unitStr是单位字符串,比如角度的°。不能是数字
- this.onchange = o.onchange;
- this.percent = null;
- this.dragStart = false;
- this.offsetToBody = null;
- this.getOffset();
- this.checkError();
- this.percent = this.getPercent();
- o.noValue || this.displayValue();
- this.moveKnot();
- this.knotWidth = 0;
- this.lineWidth = 0;
- //this.waitValue;//等待要触发事件的值,防止崩溃
- this.avoidCrash = o.avoidCrash;
- this.realMax = !this.noValue ? o.realMax : null;
- //如果传入realMax,代表可以通过输入数字修改最大值范围,最大值不可以超过realMax。
- this.scrollUnit = (scope.max - scope.min) * 0.001;
- if (this.precision != void 0) {
- var prec = Math.pow(10, -this.precision);
- this.scrollUnit < prec && (this.scrollUnit = prec);
- } else {
- //默认化为整数
- this.scrollUnit < 1 && (this.scrollUnit = 1);
- }
- this.dragStartEvent = o.dragStartEvent;
- this.line.on("mousedown touchstart", function(event) {
- scope.dragStart = true;
- scope.dragChange(event);
- if (scope.dragStartEvent)
- scope.dragStartEvent()
- //if(o.avoidCrash && isMobile)scope.dealInterval();
- });
- !window.isMobile && this.line.on("mousewheel DOMMouseScroll wheel", function(event) {
- event.preventDefault();
- var v = event.originalEvent.deltaY > 0 ? -scope.scrollUnit : scope.scrollUnit;
- scope.setValue(scope.value + v);
- });
- this.dragEndEvent = o.dragEndEvent;
- var stop = function() {
- if (scope.dragStart) {
- scope.dragStart = false;
- if (scope.dragEndEvent)
- scope.dragEndEvent()
- }
- }
- $(document).on("mouseup touchend", stop)
- /* isMobile || */
- $("#player").on("mouseup", stop)
- var lastChangeTime = 0;
- $(document).on("mousemove touchmove", function() {
- if (scope.dragStart) {
- /* if(isMobile && o.avoidCrash){
- scope.lastDragEvent = event;
- }else */
- scope.dragChange(event);
- }
- })
- o.noValue || this.textArea.on("change", function() {
- var v = parseFloat(scope.textArea.val());
- if (v != v)
- //NaN
- return;
- scope.setValueFromOutside(v);
- });
- window.addEventListener("resize",()=>{
- if(this.line[0].clientWidth){
- this.getOffset()
- this.moveKnot();
- }
- })
- }
- SlideBar.prototype.dealInterval = function() {
- this.interval = setInterval(function() {
- this.lastDragEvent && this.dragChange(this.lastDragEvent);
- this.lastDragEvent = null
- if (!this.dragStart)
- clearInterval(this.interval)
- }
- .bind(this), 90)
- }
- SlideBar.prototype.changeLimit = function(o) {
- if (o.min)
- this.min = o.min;
- if (o.max)
- this.max = o.max;
- }
- SlideBar.prototype.getOffset = function() {
- //为了检测鼠标位置需要获得相对body的offset
- var left = this.line[0].offsetLeft;
- var element = this.line[0];
- while (element = element.offsetParent) {
- left += element.offsetLeft;
- }
- this.offsetToBody = (left == 0) ? (this.offsetToBody || 0) : left;
- //如果left为0,很可能是它不可见,那么最好使用旧的offsetToBody
- }
- SlideBar.prototype.InitOffset = function() {
- //如果一开始scroller没有显示,要在显示时获取一下offset
- this.getOffset();
- this.getWidth();
- this.moveKnot();
- }
- SlideBar.prototype.checkError = function() {
- if (this.min >= this.max) {
- console.log("scrollbar值有误 " + name);
- return;
- }
- }
- SlideBar.prototype.getPercent = function() {
- return (this.value - this.min) / (this.max - this.min);
- }
- SlideBar.prototype.displayValue = function(value) {
- //this.textArea.val(this.value + (this.unitStr ? " " + this.unitStr : ""));
- if (value != void 0)
- this.value = value;
- this.textArea.val(this.value)
- }
- SlideBar.prototype.getWidth = function() {
- this.knotWidth = this.knot.width();
- this.lineWidth = this.line.width() - this.knotWidth
- }
- SlideBar.prototype.moveKnot = function() {
- //this.getWidth();
- var width = this.percent * this.lineWidth;
- this.knot.css('left', width + "px")
- if (this.track)
- this.track.css('width', (width + this.knotWidth / 2) + "px")
- }
- SlideBar.prototype.bind = function(f) {
- this.onchange = f;
- }
- SlideBar.prototype.setValue = function(v, noEvent, changeMax) {
- //设置数值并改变knot位置 noEvent为true的话就可以不触发回调函数,仅仅改变显示
- //if(this.value==v)return; //因为换选材质需要执行后面onchange才会带动preview的改变,所以这里一样还是执行,而拉动滑动条的部分值不变就不执行
- if (this.precision != void 0) {
- this.value = parseFloat(v.toFixed(this.precision))
- } else {
- //默认化为整数
- this.value = Math.round(v);
- }
- if (changeMax && this.realMax != void 0) {
- if (this.value > this.oriMax) {
- this.value = Math.min(this.value, this.realMax);
- this.changeLimit({
- max: this.value
- })
- } else {
- this.changeLimit({
- max: this.oriMax
- })
- }
- }
- this.percent = this.getPercent();
- var makeit = true;
- if (this.onchange && !noEvent) {
- var result = this.onchange(this.value);
- //如果执行的函数不允许这个值,就不能变
- if (result === false) {
- makeit = false;
- }
- }
- if (makeit) {
- this.moveKnot();
- //console.log("SlideBarV-"+this.name + " : "+this.value)
- this.noValue || this.displayValue();
- }
- }
- SlideBar.prototype.dragChange = function(event) {
- //拖动时触发 计算数值
- //this.getWidth();
- //if(!this.offsetToBody || isNaN(this.offsetToBody)this.getOffset();
- if (event.clientX != void 0) {
- this.percent = (event.clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
- } else {
- if (event.touches != void 0) {
- this.percent = (event.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
- } else
- this.percent = (event.originalEvent.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
- }
- if (this.percent < 0)
- this.percent = 0;
- else if (this.percent > 1)
- this.percent = 1;
- //var v = this.percent * this.max;
- var v = this.percent * (this.max - this.min) + this.min;
- //var v = Math.round(this.percent * this.max * 10)/10; //精度为0.1
- if (this.value == v)
- return;
- this.setValue(v);
- }
- SlideBar.prototype.setValueFromOutside = function(v) {
- //外面的事件触发的
- if (this.line.width() == 0)
- return;
- //不可见就不执行。
- //v = Math.round(v*10)/10;
- if (this.realMax != void 0) {
- v = THREE.Math.clamp(v, this.min, this.realMax);
- if (v > this.max)
- this.changeLimit({
- max: v
- });
- } else
- v = THREE.Math.clamp(v, this.min, this.max);
- this.setValue(v);
- }
- //-----------------------------------------------------
- var LineDraw = {
- createLine: function(posArr, o) {
- var e = new THREE.BufferGeometry
- , p = new Float32Array(6);
- e.addAttribute("position", new THREE.BufferAttribute(p,3));
- //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
- var p = e.attributes.position.array;
- for (var i = 0; i < 2; i++) {
- p[i * 3] = posArr[i].x;
- p[i * 3 + 1] = posArr[i].y;
- p[i * 3 + 2] = posArr[i].z;
- }
- var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
- linewidth: o.width || 1,
- //windows无效。 似乎mac/ios上粗细有效 ?
- color: o.color || defaultColor,
- transparent: o.dontAlwaysSeen ? false : true,
- depthTest: o.dontAlwaysSeen ? true : false
- })
- var line = new THREE.Line(e,mat);
- line.renderOrder = o.renderOrder || 4
- //同tagStem; //如果不加高,可能会部分被model遮住
- return line;
- }
- }
- var toPrecision = function(e, t) {
- function i(e, t) {
- var i = Math.pow(10, t);
- return Math.round(e * i) / i
- }
- if (e instanceof Array) {
- for (var n = 0; n < e.length; n++)
- e[n] = i(e[n], t);
- return e
- }
- return i(e, t)
- }
- var transformControls;
- var initTransformCtl = function(THREE) {
- TransformControls.init(THREE)
- TransformControls.prototype.transCtlChangeMode = function(mode) {
- //if(!this.editing)return;
- if (mode && this.mode != mode) {
- this.mode = mode;
- }
- }
- ,
- transformControls = new TransformControls(player.camera,player.domElement,{
- player: player,
- dontHideWhenFaceCamera: true,
- scaleAxis: ["x", "y"],
- //隐藏了z轴。虽然参数没用上
- NoScaleZ: true //整体缩放时只缩放xy轴。
- });
- transformControls.space = 'local'//为了在当前方向上平移
- transformControls.setSize(1.5)
- player.model.add(transformControls)
- $(".MenuOptions[name='transform'] li").on("click", (e)=>{
- transformControls.transCtlChangeMode($(e.target).attr("index"))
- })
-
- }
- var EditOverlay = {
- editing: false,
- overlayMaxCount: 10,
- scroller: {
- videoDepth: new SlideBar({
- root: $('#videoDepth').eq(0),
- value: settings.overlay.depth * 100,
- min: 0 * 100,
- max: 1 * 100,
- name: "videoDepth",
- unitStr: "cm",
- avoidCrash: true,
- onchange: function(s) {
- if (s == 0) {
- EditOverlay.editPlane.addBox(false)
- } else {
- EditOverlay.editPlane.addBox(true)
- EditOverlay.editPlane.scale.z = s / 100 / settings.overlay.depth;
- }
- },
- dragEndEvent: function() {
- }
- })
- },
- panoPosSwitch : $('#setOverlayPosForPano input') // 当前漫游点独立调整位置开关
- ,
- init: function(THREE) {
- var mat = new THREE.MeshBasicMaterial({
- wireframe: true,
- opacity: 0.5,
- color: "#57e4f3",
- transparent: true
- })
- var wireframeModel = this.wireframeModel = new THREE.Object3D;
- wireframeModel.name = 'wireframeModel'
- player.model.chunks.forEach((mesh)=>{
- var chunk = mesh.clone();
- chunk.material = mat;
- wireframeModel.add(chunk)
- }
- )
- wireframeModel.visible = false
- player.model.add(wireframeModel)
- //------------------------------
- this.panoPosSwitch.on("change", this.panoPosSwitchOnChange.bind(this))
- $('.overlay .addBtn button').on("click", this.beginToAddPlane.bind(this))
- $("#overlayProp a.close").on("click", ()=>{
- this.closeOverlayPanel("cancel")
- }
- )
- $("#overlayProp button.submit").on("click", (e)=>{
- this.SaveOverlay()
- }
- )
- $("#overlayProp button.delete").on("click", (e)=>{
- this.DeleteOverlay();
- }
- )
- $('#overlayUpload [name="useImgRatio"] button').on("click", this.useImgRatio.bind(this));
- var uploadInputs = {
- video : $('<input type="file" style="display:none" accept="video/*"></input>'),
- photo : $('<input type="file" style="display:none" accept="image/*"></input>')
- }
-
- $('#overlayUpload [name="upload"] button').on('click', ()=>{
- uploadInputs[this.editType].click()
- })
- uploadInputs.video.on("change", (e)=>{
- inputMedia({
- enableTypes: [this.editType ],
-
- videoDone: (file,video)=>{
- var plane = this.editPlane.plane
- $(video).css('width', '100%')
- $(video).css('height', '100%')
- plane.material.map = new THREE.VideoTexture(video);
- plane.material.map.image.play();
- plane.material.map.minFilter = THREE.LinearFilter;
- this.editPlane.overlayType = "video";
- $('#overlayUpload .preview video').remove();
- //$('#overlayUpload .preview').css('background-image',"").append($(video));
- video.autoplay = true;
- video.loop = true;
- video.volume = 0
- video.muted = true
- this.useImgRatio()
- //自适应比例
- this.editPlane.file = file;
- plane.material.opacity = 1;
- plane.material.color = new THREE.Color(1,1,1)
- plane.material.needsUpdate = true;
- }
- }, "video", e);
- }
- )
-
- uploadInputs.photo.on("change", (e)=>{
- inputMedia({
- enableTypes: [this.editType ],
- photoDone: (photo)=>{
- var plane = this.editPlane.plane
- /* $(video).css('width', '100%')
- $(video).css('height', '100%') */
-
- plane.material.map = new THREE.Texture();
- plane.material.map.image = photo
- plane.material.map.needsUpdate = !0
- plane.material.map.minFilter = THREE.LinearFilter;
- this.editPlane.overlayType = "photo";
- $('#overlayUpload .preview video').remove();
- //$('#overlayUpload .preview').css('background-image',"").append($(video));
-
- this.useImgRatio()
- this.updateGifPanel(this.editPlane)
-
- if(this.editPlane.animateInfo){
- GifTexDeal.remove(this.editPlane.animation)
- this.editPlane.animation = GifTexDeal.addAnimation(this.editPlane.plane.material.map, this.editPlane, this.editPlane.animateInfo, this.editPlane.sid)
- GifTexDeal.start(this.editPlane.animation)
- }
-
- //自适应比例
- this.editPlane.file = photo.file;
- plane.material.opacity = 1;
- plane.material.color = new THREE.Color(1,1,1)
- plane.material.needsUpdate = true;
- }
- }, "photo", e);
- }
- )
-
-
-
- player.overlayGroup.children.forEach((overlay)=>{
- if(!overlay.plane.material.map || !overlay.plane.material.map.image){
- overlay._loadDones = [()=>{this.getOverlayInfo(overlay)}]
- }
- else {
- this.getOverlayInfo(overlay)
- }
- this.addToList(overlay)
- } )
-
- $("#gifSwitch input").on("change", (e)=>{
- var on = $("#gifSwitch input").is(':checked');
- $("#gifInfoEdit").css({display: on ? 'block' : 'none'})
- if(on){
- EditOverlay.editPlane.animateInfo = {
- cellXcount : parseInt($("#gifXCount").val()),
- cellYcount : parseInt($("#gifYCount").val()),
- loop : true,
- duration : parseFloat($("#gifDuration").val()) * 1000
- }
- EditOverlay.editPlane.animation = GifTexDeal.addAnimation(EditOverlay.editPlane.plane.material.map, EditOverlay.editPlane, EditOverlay.editPlane.animateInfo, EditOverlay.editPlane.sid)
- GifTexDeal.start(EditOverlay.editPlane.animation)
- }else{
- GifTexDeal.remove(EditOverlay.editPlane.animation)
- EditOverlay.editPlane.animateInfo = null
- }
- })
-
- {//gif动画 input
-
- let strictInputNum = function(e, precision, min=0,max){//precision:保留小数位数
- var value = e.target.value.trim();
- var lastOne = value[value.length-1];
- var preContent = value.substr(0,value.length-1)
- var hasPoint = precision > 0 && lastOne == '.' ;
-
- var a = Math.pow(10, precision)
- value = parseFloat(value) || 0;
- if(isNaN(value)){
- e.target.value = preContent //还原
- return
- }
- e.target.value = Math.max(min, parseInt(value * a) / a )
-
- hasPoint && (e.target.value += '.')//补小数点
- }
- let changeAnimation = function(){
- GifTexDeal.setRepeart(EditOverlay.editPlane.animation)
-
- }
- let restartAnimation = function(){
- GifTexDeal.stop(EditOverlay.editPlane.animation)
- GifTexDeal.start(EditOverlay.editPlane.animation)
- }
- let changeFrameCount = function(){
- var a = EditOverlay.editPlane.animateInfo
- var frameCount = a.cellXcount * a.cellYcount
- $("#gifFrameCount").text(frameCount)
- var fps = parseFloat($("#gifFps").val())
- a.duration = frameCount / fps * 1000
- $("#gifDuration").val(toPrecision(a.duration/1000, 2))
-
- }
-
- let gifXCountFun = function(value){
- EditOverlay.editPlane.animateInfo.cellXcount = value
- var gifImgWidth = parseFloat($("#gifImgWidth").text())
- var gifCellWidth = toPrecision(gifImgWidth / EditOverlay.editPlane.animateInfo.cellXcount,1);
- $("#gifCellWidth").val(gifCellWidth)
- changeFrameCount()
- changeAnimation()
- }
-
- $("#gifXCount").on('input',(e)=>{
- strictInputNum(e, 0)
- gifXCountFun(parseFloat(e.target.value))
-
- })
- $("#gifXCount").on('change',(e)=>{
- strictInputNum(e, 0, 1)
- gifXCountFun(parseFloat(e.target.value))
- restartAnimation()
- })
-
-
- let gifYCountFun = function(value){
- EditOverlay.editPlane.animateInfo.cellYcount = value
- var gifImgHeight = parseFloat($("#gifImgHeight").text())
- var gifCellHeight = toPrecision(gifImgHeight / EditOverlay.editPlane.animateInfo.cellYcount,1);
- $("#gifCellHeight").val(gifCellHeight)
- changeFrameCount()
- changeAnimation()
- }
- $("#gifYCount").on('input',(e)=>{
- strictInputNum(e, 0)
- gifYCountFun(parseFloat(e.target.value))
- })
- $("#gifYCount").on('change',(e)=>{
- strictInputNum(e, 0, 1)
- gifYCountFun(parseFloat(e.target.value))
- changeAnimation()
- restartAnimation()
- })
-
-
- let gifCellWidthFun = function(value){
- var gifCellWidth = value;
- var gifImgWidth = parseFloat($("#gifImgWidth").text())
- var cellXcount = toPrecision(gifImgWidth / gifCellWidth,2);
- $("#gifXCount").val(cellXcount)
- changeAnimation()
- }
- $("#gifCellWidth").on('input',(e)=>{
- strictInputNum(e, 0)
- gifCellWidthFun(parseFloat(e.target.value))
-
- })
- $("#gifCellWidth").on('change',(e)=>{
- strictInputNum(e, 0, 1)
- gifCellWidthFun(parseFloat(e.target.value))
- var cellXcount = $("#gifXCount").val();
- var cellXcountInt = Math.round(cellXcount)
- if(cellXcountInt != cellXcount){
- $("#gifXCount").val(cellXcountInt)
- gifXCountFun(cellXcountInt)
- changeAnimation()
- }
- restartAnimation()
- })
-
-
- let gifCellHeightFun = function(value){
- var gifCellHeight = parseFloat(e.target.value);
- var gifImgHeight = parseFloat($("#gifImgHeight").text())
- var cellYcount = toPrecision(gifImgHeight / gifCellHeight,2);
- $("#gifYCount").val(cellYcount)
-
- }
- $("#gifCellHeight").on('input',(e)=>{
- strictInputNum(e, 0)
- gifCellHeightFun(parseFloat(e.target.value))
-
- })
- $("#gifCellHeight").on('change',(e)=>{
- strictInputNum(e, 0, 1)
- gifCellHeightFun(parseFloat(e.target.value))
- var cellYcount = $("#gifYCount").val();
- var cellYcountInt = Math.round(cellYcount)
- if(cellYcountInt != cellYcount){
- $("#gifYCount").val(cellYcountInt)
- gifYCountFun(cellYcountInt)
- changeAnimation()
- }
- restartAnimation()
- })
-
-
- let gifDurationFun = function(value){
- var a = EditOverlay.editPlane.animateInfo
- let frameCount = a.cellXcount * a.cellYcount
- a.duration = value
- $("#gifFps").val(toPrecision(frameCount / a.duration * 1000, 1))
- }
- $("#gifDuration").on('input',(e)=>{
- strictInputNum(e, 1);
- gifDurationFun(parseFloat(e.target.value) * 1000)
- })
- $("#gifDuration").on('change',(e)=>{
- strictInputNum(e, 1, 0.01);
- gifDurationFun(parseFloat(e.target.value) * 1000)
- restartAnimation()
- })
-
- var gifFpsFun = function(e){
- strictInputNum(e, 0, 1);
- var fps = parseFloat(e.target.value)
- var a = EditOverlay.editPlane.animateInfo
- let frameCount = a.cellXcount * a.cellYcount
- a.duration = frameCount / fps * 1000
- $("#gifDuration").val(toPrecision(a.duration / 1000, 2))
- }
- $("#gifFps").on('input',(e)=>{
- gifFpsFun(e)
-
- })
- $("#gifFps").on('change',(e)=>{
- gifFpsFun(e)
- restartAnimation()
- })
- }
-
-
- },
- enter: function() {
- this.editing = true;
- this.wireframeModel.visible = true;
- },
- leave: function() {
- if (!this.editing)
- return;
- this.editing = false
- $("#overlayProp a.close").click();
- this.endAddPlane();
- this.wireframeModel.visible = false;
- },
- switchEditType : function(type){
- this.editType = type;
- $('#overlayUpload [name="upload"] button').text(type == 'video' ? "上传视频" : "上传图片")
- $('#overlayUpload .preview span').eq(0).text(type == 'video' ? "支持MP4、MOV等,<20M" : "支持jpg、png等,<20M");
- if(type != 'photo' || !this.editPlane) $('#overlayProp #gifEdit').css({display: 'none'})
-
- },
- beginToAddPlane: function(event) {
- this.switchEditType($(event.target).attr("data-type"))
- player.reticule.visible = false;
- this.objCursorType = 'overlay';
- player.currentCursor = 'url(images/edit/box_video.png), auto'
- $('#player').css('cursor', player.currentCursor)
- $('.overlay .addBtn button').addClass("unable")
- //可以加多个视频时的按钮
- },
- endAddPlane: function() {
- this.objCursorType = null;
- player.currentCursor = '';
- $('#player').css('cursor', '')
- $('.overlay .addBtn button').removeClass("unable")
- player.reticule.visible = true
- },
- addPlane: function(o) {
- if(!o.intersect)return;
- var pos = o.intersect.point;
- var overlay = new Overlay({
- sid: new Date().getTime() + ""
- })
- overlay.hasRequestLoad = true
- overlay.position.copy(pos);
- if (player.getMouseDirection().angleTo(o.intersect.face.normal) < Math.PI / 2) {
- overlay.lookAt(o.intersect.face.normal.clone().negate().add(pos));
- overlay.position.add(o.intersect.face.normal.clone().negate().multiplyScalar(0.01))
- //avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
- } else {
- overlay.lookAt(o.intersect.face.normal.clone().add(pos));
- overlay.position.add(o.intersect.face.normal.clone().multiplyScalar(0.01))
- }
- overlay.posCustom = overlay.position.clone();
- overlay.quaCustom = overlay.quaternion.clone();
- overlay.widthCustom = overlay.width;
- overlay.heightCustom = overlay.height;
-
-
- overlay.isNew = true
- player.clickOverlay(overlay)
- transformControls.transCtlChangeMode("translate")
- this.addToList(overlay)
- },
- updateOverlayScaleDisplay: function() {
- var overlay = this.editPlane;
- var maxWidth = 193
- , maxHeight = maxWidth
- //maxWidth/2;
- var ratioW = Math.abs(overlay.width) / maxWidth;
- var ratioH = Math.abs(overlay.height) / maxHeight;
- var ratio = 1 / Math.max(ratioW, ratioH);
- //缩放比例
- var w = Math.round(Math.abs(overlay.width) * ratio)
- var h = Math.round(Math.abs(overlay.height) * ratio)
- $('#overlayUpload .preview').css({
- "width": w + 'px',
- "height": h + 'px',
- });
- $('#overlayUpload .preview [attr-type="width"]').text(toPrecision(overlay.width, 2))
- $('#overlayUpload .preview [attr-type="height"]').text(toPrecision(overlay.height, 2))
- $("#gifSwitch input").prop('checked', !!overlay.animateInfo);
- $("#gifInfoEdit").css({display: !!overlay.animateInfo ? 'block' : 'none'})
- },
-
-
- updateOverlayPreview : function(overlay){
- var plane = overlay.plane
- var src = plane.material.map && (plane.material.map.image ? plane.material.map.image.src : overlay.fileSrc );
- $('#overlayUpload .preview video').remove();
-
-
-
-
- if (overlay.overlayType == "video") {
- var video = plane.material.map.image
- $('#overlayUpload .preview').css({'background-image':"", 'background-size':""}).append(video);
-
- } else if(overlay.overlayType == "photo" || overlay.overlayType == "text"){
- $('#overlayUpload .preview').css({
- 'background-image': src ? ("url(" + src + ")") : "",
- 'background-size': "100% 100%"
- })
- }else{
- $('#overlayUpload .preview').css({
- 'background-image': "",
- 'background-size': ""
- })
- }
-
-
- if (overlay.overlayType) {
- $('#overlayUpload [name="useImgRatio"]').removeClass("hide")
- $('#overlayUpload .preview').addClass('uploaded')
- } else {
- $('#overlayUpload [name="useImgRatio"]').addClass("hide")
- $('#overlayUpload .preview').removeClass('uploaded')
- }
- }
- ,
-
-
-
- updateOverlayPanel: function(overlay) {
- overlay.overlayType && this.switchEditType(overlay.overlayType)
- this.updateOverlayPreview(overlay)
- this.updateOverlayScaleDisplay()
- this.updateGifPanel(overlay)
-
-
- if (overlay.hasBox) {
- this.scroller.videoDepth.setValue(overlay.scale.z * settings.overlay.depth * 100, true)
- } else {
- this.scroller.videoDepth.setValue(0, true)
- }
- setTimeout(()=>{
- this.scroller.videoDepth.InitOffset()
- }
- , 201)
-
-
- this.updatePano()
- },
-
- //----------------------------
- updateGifPanel : function(overlay){
- if(this.editType == 'photo'){
- if(!overlay.plane.material.map)return;
- $('#overlayProp #gifEdit').css({display: 'block'})
-
- let w = overlay.plane.material.map.image.width
- let h = overlay.plane.material.map.image.height
- if(overlay.animateInfo){
- let a = overlay.animateInfo
- $("#gifXCount").val(a.cellXcount);
- $("#gifYCount").val(a.cellYcount);
- $("#gifImgWidth").text(w)
- $("#gifImgHeight").text(h)
- $("#gifCellWidth").val(toPrecision(w / a.cellXcount, 2));
- $("#gifCellHeight").val(toPrecision(h / a.cellYcount, 2));
- let frameCount = a.cellXcount * a.cellYcount
- $("#gifFrameCount").text(frameCount)
- $("#gifDuration").val(toPrecision(a.duration / 1000, 2));
- $("#gifFps").val(toPrecision(frameCount / a.duration * 1000, 1) );
- }else{
- $("#gifXCount").val(1);
- $("#gifYCount").val(1);
- $("#gifImgWidth").text(w)
- $("#gifImgHeight").text(h)
- $("#gifCellWidth").val(w);
- $("#gifCellHeight").val(h)
- $("#gifFrameCount").text(1)
- $("#gifDuration").val(1);
- $("#gifFps").val(1);
- }
- }
- }
-
- ,
- beginEdit : function(overlay){
- $('#overlayProp').removeClass('atRight').removeClass('hide')
- this.endAddPlane();
- this.editPlane = overlay;
-
-
- overlay.requestDownload()
- if(overlay._loadDones){
- $('.waiting').addClass('showloading');
- overlay._loadDones.push(()=>{
- $('.waiting').removeClass('showloading');
- })
- }
- overlay.visible = true
- this.updateOverlayPanel(overlay)
- transformControls.attach(overlay)
- }
- ,
- panoPosSwitchOnChange : function(){
- var on = this.panoPosSwitch.is(':checked')
-
- if(!on){
- delete this.editPlane.transformAtPanos[getTransformSid()]
-
- this.editPlane.position.copy(this.editPlane.posCustom)
- this.editPlane.quaternion.copy(this.editPlane.quaCustom)
- var scale = this.editPlane.getScaleBySize(this.editPlane.widthCustom, this.editPlane.heightCustom)
- this.editPlane.scale.set(scale.x, scale.y, this.editPlane.scale.z)
-
- //this.editPlane.usingTransformData = false
- }
- }
- ,
-
- getTransformAtPano : function(){
- var name = getTransformSid()
- this.editPlane.transformAtPanos[name] = {
- pos : this.editPlane.position.clone(),
- qua : this.editPlane.quaternion.clone(),
- width : this.editPlane.width,
- height : this.editPlane.height,
- }
- //this.editPlane.usingTransformData = true
- },
-
- updatePosition:function(){
- var on = this.panoPosSwitch.is(':checked')
- if(on){
- this.getTransformAtPano()
- }else{
- this.editPlane.posCustom.copy(this.editPlane.position)
- }
-
- },
- updateScale : function(){
- var on = this.panoPosSwitch.is(':checked')
- var size = this.editPlane.getSizeByScale( )
- this.editPlane.width = size.width
- this.editPlane.height = size.height
-
- if(on){
- this.getTransformAtPano()
- }else{
- this.editPlane.widthCustom = this.editPlane.width
- this.editPlane.heightCustom = this.editPlane.height
- }
-
- this.updateOverlayScaleDisplay()
- }
- ,
-
- updateQua : function(){
- var on = this.panoPosSwitch.is(':checked')
- if(on){
- this.getTransformAtPano()
- }else{
- this.editPlane.quaCustom.copy(this.editPlane.quaternion)
- }
-
- }
- ,
- updatePano:function(){
- if(!EditOverlay.editPlane ) return;
- this.panoPosSwitch.prop('checked', !!EditOverlay.editPlane.transformAtPanos[ getTransformSid()]);
-
- },
- //------------------------------
-
-
- closeOverlayPanel: function(type) {
- if (!this.editPlane)
- return;
- if (type == 'cancel') {
- if (!this.editPlane.isNew && !this.editPlane.needDelete)
- this.editPlane.setFromInfo(this.editPlane.info)
-
- else
- this.disposeOverlay(this.editPlane);
- //删除
- }
- this.editPlane = null;
- transformControls.detach()
- $("#overlayProp").addClass("atRight");
- //if(player.model.overlayPlanes.length < this.overlayMaxCount) this.beginToAddPlane()
- },
- useImgRatio: function(o) {
- var plane = this.editPlane.plane;
- if (!plane.material.map)
- return;
- var img = plane.material.map.image;
- var mintranRatio = 200;
- //default is 200 , 防止图片太小时在墙上依旧很大
- var width = this.editPlane.overlayType == "video" ? img.videoWidth : img.width;
- var height = this.editPlane.overlayType == "video" ? img.videoHeight : img.height;
- if (o == "suitSize") {
- var boundWidth = Math.min(Math.max(width, height) / mintranRatio, 1)
- if (width > height) {
- var w = boundWidth;
- var h = boundWidth * height / width
- } else {
- var h = boundWidth;
- var w = boundWidth * width / height;
- }
- } else {
- //假设不变总面积
- var k = Math.sqrt(Math.abs(this.editPlane.width * this.editPlane.height) / (width * height))
- var w = k * width * (this.editPlane.width < 0 ? -1 : 1);
- var h = k * height * (this.editPlane.height < 0 ? -1 : 1);
- }
- this.editPlane.scale.setX(w / settings.overlay.width)
- this.editPlane.scale.setY(h / settings.overlay.height)
- this.editPlane.width = w;
- this.editPlane.height = h;
-
- this.updateScale()
-
- this.updateOverlayPreview(this.editPlane)
- },
-
- getOverlayInfo: function(overlay) {
- //2 编辑前, 从当前状态获取info
- var plane = overlay.plane;
- var transformAtPanos = {}
- for(var i in overlay.transformAtPanos){
- transformAtPanos[i] = {
- width : overlay.transformAtPanos[i].width,
- height : overlay.transformAtPanos[i].height,
- pos : overlay.transformAtPanos[i].pos.clone(),
- qua : overlay.transformAtPanos[i].qua.clone(),
- }
- }
-
- overlay.info = {
- width: overlay.widthCustom,
- height: overlay.heightCustom,
- depth: settings.overlay.depth * overlay.scale.z,
- pos: overlay.posCustom.clone(),
- qua: overlay.quaCustom.clone(),
- media: plane.material.map.image,
- file: overlay.file,
- type: overlay.overlayType,
- hasBox: overlay.hasBox,
- transformAtPanos: transformAtPanos
- }
- if(overlay.animateInfo ){
- overlay.info.animateInfo = CloneObject(overlay.animateInfo)
- }
- },
- getSavingInfo: function(overlay) {
- if (!overlay.file && (!overlay.plane.material.map || !overlay.plane.material.map.image)) {
- return;
- }
- var transformAtPanos = {}
- for(var i in overlay.transformAtPanos){
- transformAtPanos[i] = {
- width : toPrecision(overlay.transformAtPanos[i].width, 4),
- height : toPrecision(overlay.transformAtPanos[i].height, 4),
- pos : toPrecision(overlay.transformAtPanos[i].pos.toArray(), 3),
- qua : toPrecision(overlay.transformAtPanos[i].qua.toArray(), 5)
- }
- }
- var info = {
- width: toPrecision(overlay.widthCustom, 4),
- height: toPrecision(overlay.heightCustom, 4),
- depth: toPrecision(settings.overlay.depth * overlay.scale.z, 4),
- pos: toPrecision(overlay.posCustom.toArray(), 3),
- qua: toPrecision(overlay.quaCustom.toArray(), 5),
- sid: overlay.sid,
- hasBox: overlay.hasBox ? 1 : 0,
- media: [overlay.overlayType],
- file: overlay.fileSrc || overlay.plane.material.map.image.src,
- transformAtPanos : transformAtPanos,
-
- }
- if(overlay.animateInfo && overlay.animateInfo.cellXcount * overlay.animateInfo.cellYcount > 1){
- info.animateInfo = overlay.animateInfo
- }
-
- return info
- },
- SaveOverlay: function() {
- var overlay = this.editPlane;
- if (!overlay.file && (!overlay.plane.material.map || !overlay.plane.material.map.image)) {
- this.editType == "video" ? alert("请上传视频") : alert("请上传图片");
- return;
- }
- var saveInfo = ()=>{
- //overlay.savingInfo = JSON.stringify(info)//准备写入的info
- //saveDone:
- overlay.isNew = false;
- overlay.getVisiblePanos()
-
- this.getOverlayInfo(overlay);
- this.closeOverlayPanel()
- $('.waiting').removeClass('showloading');
- }
- if (!overlay.info || overlay.file != overlay.info.file) {
- $('.waiting').addClass('showloading');
- uploadFile(overlay.file, 'overlay', function(rs) {
- if (rs.code === 0) {
- overlay.fileSrc = rs.data;
- saveInfo()
- }
- ;
- })
- } else
- saveInfo();
- },
- disposeOverlay: function(overlay) {
- var plane = overlay.plane
- if (overlay == player.hoveringPlane) {
- player.hoverOverlay(null, "soon");
- }
- if (plane.material.map) {//删除视频src
- //overlay.info && common.destroyBlob(overlay.info.media.src)
- //common.destroyBlob(plane.material.map.image.src)
- }
- plane.material.dispose();
- overlay.parent.remove(overlay);
- this.removeFromList(overlay)
- if(this.animation){
- GifTexDeal.remove(this.animation)
- }
- //this.beginToAddPlane()
- },
- DeleteOverlay: function() {
- var overlay = this.editPlane;
- if (!overlay.isNew) {
- if (confirm(overlay.overlayType== "photo" ? "确定删除该图片?" : "确定删除该视频?")) {
- overlay.needDelete = true;
- $("#overlayProp a.close").click()
- //this.closeOverlayPanel()
- }
- } else {
- //刚创建时的删除按钮等同于取消按钮
- $("#overlayProp a.close").click()
- //this.closeOverlayPanel()
- }
- },
- addToList: function(overlay) {
- var li = $(`<li class='listItem'><div class="icon"></div><div class="title">${(overlay.overlayType == "video" ? "视频 ":"图片 ")+ overlay.sid}</div></li>`)
- $(".overlayList ul").append(li);
- li.on("click", ()=>{
- player.clickOverlay(overlay)
- player.focusPoint({aim: overlay.position})
-
- })
- overlay.domLi = li;
- },
- removeFromList: function(overlay) {
- overlay.domLi.remove();
- }
- }
- //----------------漫游可见性---------------------------------
- var VisiSet = {
- setPanoVisible: false,
- setTagVisible: false,
- panoVLines: {},
- //线条
- panoVTemp: {},
- //修改后还没保存的临时数据
- tagVsetting: null,
- //正在设置的热点中心点
- tagsVLines: {},
- //线条
- //tagVTemp //修改后还没保存的临时数据
-
- $confirmSnap: $("#camera-start"),
-
- changeBtn : $(".toolMid .midBottom #midBtns>button").eq(1),
-
- colors: {
- green: "#00c8ae"
- },
- init: function() {
- this.footIconSizeRatio = Math.max(player.model.size.x, player.model.size.z) / 30;
- this.meshGroup = new THREE.Object3D;
- this.meshGroup.name = "setVisible-group"
- player.model.add(this.meshGroup)
- $("#hotVisible").on("click", ()=>{
- VisiSet.enterSet(VisiSet.beginSetTagVisible.bind(VisiSet))
-
- })
-
- this.changeBtn.on("click",()=>{//隐藏与显示该点
- if(this.changeBtn.attr("function") == "hide"){
- for(let i in this.panoVLines){
- this.panoVLines[i].visible && this.dealPanoVisible(i);
- }
- }else{
- //显示该点时,显示周围一定距离内、到该点没有遮挡的pano
- //?????
- var list = player.model.panos.sortByScore([e=>e.isAligned()], [(pano)=>{return -pano.position.distanceTo(this.panoVsetting.position)}])
-
-
- if(list.length == 1){
- console.log('仅有一个漫游点')
- return;
- }
- var ifBlock = function(panoA, panoB ){
- var A = panoA.position.clone();
- var B = panoB.position.clone();
- return convertTool.ifIntersectChunks(A, B, {})
- }
- var okList
- var s = Math.max(-list[1].score*2, 4); //i==1的一定显示
- for(var i=1;i<list.length;i++){
- if(-list[i].score < s){
- if(ifBlock(this.panoVsetting, list[i].pano)){
- list[i].block = true //有阻挡
- }
- list[i].good = true
- }else{
- okList || (okList = list.filter(e=>e.good && !e.block));//绝对可以使用的
-
- if(okList.length <2 ){
- if(!ifBlock(this.panoVsetting, list[i].pano)){
- if(okList.length == 0){
- okList.push(list[i])
- }else{//1
- var lastPos = okList[0].pano.position.clone().sub(this.panoVsetting.position).setY(0);
- var thisPos = list[i].pano.position.clone().sub(this.panoVsetting.position).setY(0);
- if(lastPos.angleTo(thisPos) > Math.PI / 2){
- console.log('再加一个 角度'+THREE.Math.radToDeg(lastPos.angleTo(thisPos)))
- break;
- }
-
- }
- }
- }else{
- break;
- }
- }
- }
- if(okList.length==0){//如果length为0,至少加一个pano, 虽然是遮挡的
- okList.push(list[0].pano)
- }
- okList.forEach(e=>this.dealPanoVisible(e.pano.id))
-
- console.log(okList)
-
- }
- })
-
-
-
-
- },
- enterSet: function(fun) {
- var enter = function() {
- if (player.modeTran.split('-')[1] != "floorplan") {
- setTimeout(fun, 300)
- //提前一点出现
- }
- player.flyToMode("floorplan", fun);
- }
- permitTranMode(false)
- if (!player.modeTran) {
- player.afterCModeFuc = ()=>{
- enter()
- }
- } else
- enter()
- },
- beginSetPanoLog: function() {
- player.flying || $(".toolLeft").removeClass("unable")
- if (this.setPanoLog)
- return;
- this.setPanoLog = true
- this.panosSelect = []
- this.updateFootIconSize()
- this.showFootIcons(null, true);
-
- for(let i in player.model.hots){
- player.model.hots[i].visi_ = player.model.hots[i].mesh.visible;
- player.model.hots[i].mesh.visible = false
- }
-
-
- player.model.panos.forEach(e=>{
- e.addTextSprite(e.id, $('#panoIdColorTex').val())
- })
- },
-
- finishSetPanoLog: function() {
- //结束 退出这个设置
- if (!this.setPanoLog)
- return;
- //否则会加多个侦听
- this.setPanoLog = false;
- this.hideFootIcons();
-
- this.recoverAllState2();
- this.panosSelect = null
- player.flyoutType = null
-
- permitTranMode(true)
-
-
- for(let i in player.model.hots){
- player.model.hots[i].mesh.visible = player.model.hots[i].visi_
- }
- $("#panosIdShow").val('')
-
- player.model.panos.forEach(e=>{
- e.removeTextSprite()
- })
-
-
-
- },
- dealPanoLogClick: function(id) {
- var panos = player.model.panos;
-
- var index = this.panosSelect.indexOf(id)
- if (index==-1) {
- this.changeFIconState(panos.index[id].footIcon, "linked" )
- this.panosSelect.push(id)
- }else{
- this.changeFIconState(panos.index[id].footIcon, false)
- this.panosSelect.splice(index,1)
- }
-
-
- $("#panosIdShow").val(this.panosSelect.join(', '));
-
- }
- ,
- changePanoIdColor:function(color){
- player.model.panos.forEach(e=>{
- e.removeTextSprite();
- e.addTextSprite(e.id,color)
- })
- }
- ,
- beginSetPanoVisible: function() {
- player.flying || $(".toolLeft").removeClass("unable")
- if (this.setPanoVisible)
- return;
- this.setPanoVisible = true;
- this.panoVTemp = {};
- this.SetOnePanoVisible(player.currentPano)
- //先设置currentPano
- this.$confirmSnap.text('保存当前设置').removeClass("hide")
- //objects.tagManager.hideAllTags();
- this.setDisplay(true)
- this.updateFootIconSize()
- //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
-
-
- for(let i in player.model.hots){
- player.model.hots[i].visi_ = player.model.hots[i].mesh.visible;
- player.model.hots[i].mesh.visible = false
- }
-
- },
- SetOnePanoVisible: function(pano) {
- //点击某个pano后就对该pano点进行设置
- if (this.panoVsetting == pano)
- return;
- //if (this.panoVsetting) saveLastPanoVi(this.panoVsetting);
- this.panoVsetting = pano;
- //记录正在修改的
- this.delVisibleLines();
- //删除线
- this.showFootIcons(pano, true);
- this.createPanoVisiLines(pano);
- //创线
-
- this.changeBtn.removeClass('hide')
- },
- saveLastPanoVi: function() {
- //保存刚设置过的pano
- var change = [];
- for (var r in this.panoVLines) {
- var line = this.panoVLines[r];
- if (line.name.indexOf("new") > -1 && line.visible) {
- //新设置为visible且没有取消
- change.push({
- type: "add",
- id: r
- })
- } else if (line.name.indexOf("new") == -1 && !line.visible) {
- //旧的且已经取消
- change.push({
- type: "sub",
- id: r
- })
- }
- }
- if (change.length) {
- //添加双向的neighbour:
- var self = this.searchNeib(this.panoVsetting.id)
- //var seeMarkers_self = self.seeMarkers;
- var neighbourUUIDs_self = self.neighbourUUIDs
- var neighbourPanos_self = self.neighbourPanos;
- for (var i = 0; i < change.length; i++) {
- var other = this.searchNeib(change[i].id)
- //var seeMarkers = other.seeMarkers;
- var neighbourUUIDs = other.neighbourUUIDs;
- var neighbourPanos = other.neighbourPanos;
- if (change[i].type == "add") {
- //seeMarkers.push(this.panoVsetting.id);
- neighbourUUIDs.push(this.panoVsetting.id);
- neighbourPanos[this.panoVsetting.id] = true;
- //seeMarkers_self.push(change[i].id);
- neighbourUUIDs_self.push(change[i].id);
- neighbourPanos_self[change[i].id] = true;
- } else {
- //var index = seeMarkers.indexOf(this.panoVsetting.id);
- //index > -1 && seeMarkers.splice(index, 1);
- var index = neighbourUUIDs.indexOf(this.panoVsetting.id);
- index > -1 && neighbourUUIDs.splice(index, 1);
- neighbourPanos[this.panoVsetting.id] = false;
- //var index = seeMarkers_self.indexOf(change[i].id);
- //index > -1 && seeMarkers_self.splice(index, 1);
- var index = neighbourUUIDs_self.indexOf(change[i].id);
- index > -1 && neighbourUUIDs_self.splice(index, 1);
- neighbourPanos_self[change[i].id] = false;
- }
- this.panoVTemp[change[i].id] = {
- //后面两个是作为保存到后台的数据存储,临时需要用到的是第一个
- neighbourPanos: neighbourPanos,
- //seeMarkers: seeMarkers,
- neighbourUUIDs: neighbourUUIDs
- }
- }
- this.panoVTemp[this.panoVsetting.id] = {
- //加上自己
- neighbourPanos: neighbourPanos_self,
- //seeMarkers: seeMarkers_self,
- neighbourUUIDs: neighbourUUIDs_self
- }
- }
- },
- pauseSetPanoVisible: function(type) {
- //暂停 因为点击了保存设置 但没有退出设置
- if (!this.setPanoVisible)
- return;
- if (type == "unsaved") {
- //中途点击pano从而停止一个热点的设置
- this.saveLastPanoVi();
- } else {
- this.panoVTemp = {};
- //清空数据
- }
- this.delVisibleLines();
- this.showFootIcons();
- //清空选择
- var lastPanoSetting = this.panoVsetting;
- this.panoVsetting = null;
- lastPanoSetting && this.changeFIconState2(lastPanoSetting.footIcon, this.checkHasNeighbor(lastPanoSetting))
- //这句要放在this.panoVsetting = null后。 根据可见性更改透明度
- this.changeBtn.addClass('hide')
- },
- //按理说改变了neighbourPano,tag的初始visible也要改。但是这样还要考虑已经改过的tag。。很麻烦
- finishSetPanoVisible: function() {
- //结束 退出这个设置
- if (!this.setPanoVisible)
- return;
- //否则会加多个侦听
- this.setPanoVisible = false;
- this.hideFootIcons();
- this.delVisibleLines();
- //objects.tagManager.showAllTags();
- this.recoverAllState2();
- this.panoVsetting = null;
- this.panoVTemp = {};
- player.flyoutType = null
- this.$confirmSnap.addClass("hide")
- permitTranMode(true)
- this.setDisplay(false)
-
- for(let i in player.model.hots){
- player.model.hots[i].mesh.visible = player.model.hots[i].visi_
- }
-
- },
- changeVisiBtnState: function(state){
- this.changeBtn.attr("function", state ? "hide" : "show")
- this.changeBtn.html(state ? "隐藏该点位置":"显示该点位置")
- },
- recoverAllState2: function() {
- //为了热点可视恢复成pano全部可见
- if(!this.footIcons)return;
- for (var i = 0; i < this.footIcons.length; i++) {
- this.footIcons[i].material.uniforms.opacity.value = 1;
- this.footIcons[i].material.uniforms.map.value = footTex1;
- }
- },
- afterSavePanoVisibles: function() {
- //实施:
- var panos = player.model.panos;
- for (var i in this.panoVTemp) {
- var pano = panos.index[i];
- //pano.seeMarkers = this.panoVTemp[i].seeMarkers;
- pano.neighbourUUIDs = this.panoVTemp[i].neighbourUUIDs;
- pano.neighbourPanos = this.panoVTemp[i].neighbourPanos;
- }
- if (!this.checkHasNeighbor(player.currentPano)) {
- //currentPano变为孤立点 就要换一个防止飞入
- var list = panos.sortByScore([pano=>{
- return this.checkHasNeighbor(pano)
- }
- ], [function(pano) {
- return -pano.position.distanceTo(player.currentPano.position)
- }
- ])
- if (list && list.length) {
- player.currentPano = list[0].pano;
- //找最近的一非孤立点
- //this.noPanoHasNeighbor = false; //更新状态
- } else {//this.noPanoHasNeighbor = true; //更新状态
- }
- } else {//this.noPanoHasNeighbor = false; //更新状态
- }
- //dataDeal.done();
- //暂时:
- this.pauseSetPanoVisible()
- this.updateFootIconSize()
- //更新一下center大小 写在最后
- },
- //最佳推荐操作顺序: 先设置pano可见性 再创建热点 这样热点的visible正确些,否则之后再设置热点可见性会改更多
- savePanoVisibles: function() {
- //保存
- if (this.panoVsetting)
- this.saveLastPanoVi(this.panoVsetting);
- //获取最后设置的那个热点的改动
- var PanoData = [];
- for (var i in this.panoVTemp) {
- PanoData.push({
- //希望算法部不会更改index排序,或者更改后能将visible信息一并更改
- panoID: i,
- //visibles: this.turnToPanoIndex(this.panoVTemp[i].seeMarkers),
- visibles3: this.turnToPanoIndex(this.panoVTemp[i].neighbourUUIDs)
- })
- }
- if (PanoData.length == 0) {
- //没改变
- alert("保存成功")
- return;
- }
- /* this.afterSavePanoVisibles()
- alert("保存成功")
- console.log(JSON.stringify(PanoData)) */
- let url = cmp ? ('/api/scene/roamViable/' + cmp) : '/manage/scene/roamViable'
- $.ajax({
- method: 'POST',
- url: ceshi + url,
- headers: {
- 'Content-Type': 'application/json',
- token: token
- },
- contentType: 'application/json',
- data: JSON.stringify({
- data: JSON.stringify(PanoData),
- sceneCode: window.number
- }),
- success: (data)=>{
- if (data.code === 0) {
- this.afterSavePanoVisibles()
- alert("保存漫游可行成功")
- } else
- alert("保存漫游可行失败")
- if (data.code === 5001) {
- alert('请重新登录')
- localStorage.dcj_token = ''
- location.reload()
- }
- }
- ,
- fail: function() {
- alert("保存漫游可行失败")
- }
- })
- /* var o = {
- name_t: "panoVisible",
- f: this.pauseSetPanoVisible,
- url: Config.prefixEditProPCApi+"/saveLinkPano",
- dialog: i18n.get('设置'),
- data: { data: JSON.stringify(PanoData) }
- }
-
- var dataDeal = uploadsSaving.saveFucforPC(o);
- dataDeal.group[0] = function () {
- //实施:
- for (var i in player.panoVTemp) {
- var pano = player.model.panos.index[i];
- pano.seeMarkers = player.panoVTemp[i].seeMarkers;
- pano.neighbourUUIDs = player.panoVTemp[i].neighbourUUIDs;
- pano.neighbourPanos = player.panoVTemp[i].neighbourPanos;
- }
- if(!player.model.checkHasNeighbor(player.currentPano)){//currentPano变为孤立点 就要换一个防止飞入
- var list = player.model.panos.sortByScore([function(pano){return player.model.checkHasNeighbor(pano)}],
- [function(pano){return -pano.position.distanceTo(player.currentPano.position)}])
- if(list && list.length){
- player.currentPano = list[0].pano;//找最近的一非孤立点
- player.model.noPanoHasNeighbor = false; //更新状态
- }else{
- player.model.noPanoHasNeighbor = true; //更新状态
- }
- }else{
- player.model.noPanoHasNeighbor = false; //更新状态
- }
-
- dataDeal.done();
- player.model.updateFootIconSize(player.cameraControls.activeControl)//更新一下center大小 写在最后
- } */
- },
- searchNeib: function(panoId) {
- //寻找某pano的相关neighbour 可能是修改过的
- var panos = player.model.panos;
- var o = {};
- if (this.panoVTemp[panoId]) {
- //o.seeMarkers = this.panoVTemp[panoId].seeMarkers;
- o.neighbourUUIDs = this.panoVTemp[panoId].neighbourUUIDs;
- o.neighbourPanos = this.panoVTemp[panoId].neighbourPanos;
- } else {
- //o.seeMarkers = panos.index[panoId].seeMarkers.slice(0);
- o.neighbourUUIDs = panos.index[panoId].neighbourUUIDs.slice(0);
- o.neighbourPanos = CloneObject(panos.index[panoId].neighbourPanos);
- }
- return o;
- },
- turnToPanoIndex: function(panoArr) {
- var panos = player.model.panos;
- var array = [];
- for (var i = 0; i < panoArr.length; i++) {
- var pano = panos.index[panoArr[i]];
- var index = panos.list.indexOf(pano)
- array.push(index);
- }
- return array;
- },
- setDisplay: function(state) {
- var panos = player.model.panos;
- if (state) {
- this.$confirmSnap.text('保存当前设置');
- this.$confirmSnap.removeClass('hide');
- } else {
- this.$confirmSnap.addClass('hide');
- this.changeBtn.addClass('hide')
- }
-
- player.path.currentPanoMarker.mesh.visible = !state;
- player.overlayGroup.visible = !state;
- player.reticule.visible = !state;
- },
- delVisibleLines: function() {
- //xzw add 所有线都删除
- for (var i in this.tagsVLines) {
- this.tagsVLines[i].geometry.dispose();
- this.tagsVLines[i].material.dispose();
- this.meshGroup.remove(this.tagsVLines[i]);
- delete this.tagsVLines[i];
- }
- for (var i in this.panoVLines) {
- this.panoVLines[i].geometry.dispose();
- this.panoVLines[i].material.dispose();
- this.meshGroup.remove(this.panoVLines[i]);
- delete this.panoVLines[i];
- }
- },
- //--------panoVisible
- createPanoVisiLines: function(pano) {
- // pano可见性线条
- var neighbours = this.panoVTemp[pano.id] && this.panoVTemp[pano.id].neighbourPanos || pano.neighbourPanos;
- for (var r in neighbours) {
- if (neighbours[r] && r != pano.id) {
- this.createPanoSingleLine(pano, "old", r)
- }
- }
- },
- createPanoSingleLine: function(pano, type, id) {
- //pano是中心
- var panos = player.model.panos;
- var p2 = panos.index[id].floorPosition.clone()
- /* .sub(player.model.position) */
- var line = LineDraw.createLine([pano.floorPosition.clone()/* .sub(this.position) */
- , p2], {
- color: this.colors.green
- });
- this.meshGroup.add(line);
- line.name = "PanoVL-" + type + "-" + id;
- this.panoVLines[id] = line;
- this.changeFIconState(panos.index[id].footIcon, "linked")
- },
- dealPanoVisible: function(id) {
- //外部调用
- var panos = player.model.panos;
- if (this.panoVsetting) {
- if (id == this.panoVsetting.id) {
- //关闭当前pano设置
- this.pauseSetPanoVisible('unsaved')
- } else {
- var link;
- //结果是否连接
- if (this.panoVLines[id]) {
- this.panoVLines[id].visible = !this.panoVLines[id].visible;
- link = this.panoVLines[id].visible;
- this.changeFIconState(panos.index[id].footIcon, this.panoVLines[id].visible ? "linked" : false)
-
- } else {
- this.createPanoSingleLine(this.panoVsetting, "new", id)
- link = true;
- }
- if (link) {
- //如果连接上了,直接判断该点是可见的(有附近点),(不能通过checkHasNeighbor来判断,因为新增的线条可能不在它的neighbour中
- this.changeFIconState2(panos.index[id].footIcon, true)
- this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, true)
- } else {
- //否则需要checkHasNeighbor
- this.changeFIconState2(panos.index[id].footIcon, this.checkHasNeighbor(panos.index[id]))
- this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, this.checkHasNeighbor(this.panoVsetting))
- }
-
-
- /* if(window.routeArray){
- if(this.panoVLines[id].visible)window.routeArray.push(id)
- else{
- let index = window.routeArray.indexOf(id)
- index > -1 && routeArray.splice(index, 1)
- }
-
- } */
-
-
- }
- } else {
- //点击开始设置要设置的pano
- this.SetOnePanoVisible(panos.index[id])
- }
- this.updateFootIconSize()
- },
- showFootIcons: function(pano, isPanovisible) {
- if (!this.footIcons) {
- footTex1 = Texture.load("images/edit/End_128.png");
- //Store.FootIcon);
- footTex2 = Texture.load("images/edit/End_unable_128.png");
- //Store.FootIcon_unable);
- this.footIcons = [];
- var scale = 0.4;
- scale *= 40 / Math.sqrt(Math.min($("#player").width(), $("#player").height()));
- //屏幕越小,放得越大
- scale = THREE.Math.clamp(scale, 0.3, 0.7)
- //console.log("scale"+scale)
- var geo = new THREE.PlaneGeometry(scale,scale,1,1)
- var panos = player.model.panos;
- for (var r in panos.index) {
- if (!panos.index[r].isAligned())
- continue;
- var t = THREE.UniformsUtils.clone(shaders.waypoint.uniforms);
- t.map.value = footTex1
- t.color.value.set("#ffffff");
- var mat = new THREE.RawShaderMaterial({
- vertexShader: shaders.waypoint.vertexShader,
- fragmentShader: shaders.waypoint.fragmentShader,
- uniforms: t,
- side: THREE.DoubleSide,
- transparent: !0,
- depthWrite: !1,
- depthTest: false,
- name: "footIcon"
- })
- var foot = new THREE.Mesh(geo,mat)
- foot.position.copy(panos.index[r].floorPosition.clone()/* .sub(player.model.position) */
- )
- foot.lookAt(foot.position.clone().add(new THREE.Vector3(0,1,0)));
- foot.name = panos.index[r].id;
- foot.visible = false;
- foot.renderOrder = 6,
- panos.index[r].footIcon = foot;
- this.meshGroup.add(foot);
- this.footIcons.push(foot)
- }
- }
- for (var i = 0; i < this.footIcons.length; i++) {
- this.footIcons[i].visible = true;
- this.changeFIconState(this.footIcons[i], false)
- var panos = player.model.panos;
- if (isPanovisible) {
- this.changeFIconState2(this.footIcons[i], this.checkHasNeighbor(panos.index[this.footIcons[i].name], "showFoot"))
- }
- if (pano && (this.footIcons[i].name == pano.id)) {
- //pano为中心 或者 currentPano 所以放大一点
- this.footIcons[i].oriScale = new THREE.Vector3(1.5,1.5,1.5)
- if (isPanovisible) {
- //currentPano特殊些:
- this.changeFIconState(this.footIcons[i], "center")
- //this.footIcons[i].Unclick = true;//不让点击和hover
- }
- } else {
- this.footIcons[i].oriScale = new THREE.Vector3(1,1,1)
- }
- }
- },
- checkHasNeighbor: function(pano, state) {
- //检查当前状态pano点是否有可通行点
- var neighbours = /* this.panoVTemp && */
- this.panoVTemp[pano.id] ? this.panoVTemp[pano.id].neighbourPanos : pano.neighbourPanos;
- if (state != "showFoot" && pano == this.panoVsetting) {
- //是中心点的话。state == "showFoot"代表是showFootIcon时, 这时候线还没创建,无法用线判断中心点有几个相邻点,直接用neighbourPanos
- for (var i in this.panoVLines) {
- if (this.panoVLines[i].visible) {
- return true;
- //有一条线即可
- }
- }
- return;
- }
- for (var i in neighbours) {
- if (i == pano.id)
- continue;
- if (neighbours[i]) {
- if (this.panoVsetting && this.panoVsetting.id == i && this.panoVLines[pano.id] && !this.panoVLines[pano.id].visible)
- continue;
- return true;
- }
- }
- return false;
- },
- /* ifAllPanoNoNeighbor : function(){//检查是否全是孤立点
- var panos = player.model.panos;
- for(var i in panos.index){
- if(this.checkHasNeighbor(panos.index[i])){
- return false;
- }
- }
- this.noPanoHasNeighbor = true;
- return true;//是全部没有neighbour
- }, */
- changeFIconState: function(footIcon, state) {
- var color = state == "linked" ? this.colors.green : (state == "center" ? /* "#d7f244" */
- "#d5f12e" : "#ffffff");
- footIcon.material.uniforms.color.value.set(color)
- },
- changeFIconState2: function(footIcon, state) {
- //是可见点还是不可见点
- if (state) {
- footIcon.material.uniforms.map.value = footTex1;
- if (this.panoVsetting) {
- if (this.panoVsetting.id != footIcon.name) {
- footIcon.material.uniforms.opacity.value = 1;
- } else {
- this.changeVisiBtnState(true)
- }
- }
- } else {
- //不可见
- footIcon.material.uniforms.map.value = footTex2;
- if (!this.panoVsetting || this.panoVsetting.id != footIcon.name) {
- //非中心点时
- footIcon.material.uniforms.opacity.value = 0.5;
- } else {
- //变为中心点时
- footIcon.material.uniforms.opacity.value = 1;
- this.changeVisiBtnState(false)
- }
- }
- },
- hideFootIcons: function() {
- if (!this.footIcons)
- return;
- for (var i = 0; i < this.footIcons.length; i++) {
- this.footIcons[i].visible = false;
- }
- },
- updateFootIconSize: function() {
- //根据相机位置 改变footIcon大小,使在范围内看到的热点大小一致,防止太小点击不到
- if (!this.footIcons)
- return;
- var s = player.cameraControls.controls.floorplan.absoluteScale * 2.8
- s = THREE.Math.clamp(s, 0.5 * this.footIconSizeRatio, 1.4 * this.footIconSizeRatio);
- this.footIcons.forEach(function(f) {
- try {
- f.scale.copy(f.oriScale).multiplyScalar(s);
- } catch (e) {
- console.log(e)
- }
- })
- }
- //========热点可见性==============
- ,
- beginSetTagVisible: function() {
- if (this.setTagVisible)
- return;
- $(".toolTop").addClass("unable")
- $("#hotVisible").addClass("unable")
- this.setTagVisible = true;
- this.tagVTemp = {};
- this.$confirmSnap.text('完成设置').removeClass("hide")
- //objects.tagManager.hideAllTags();
- for (let i in player.model.hots) {
- player.model.hots[i]._isSprite = player.model.hots[i].isSprite;
- player.model.hots[i].isSprite = true;
- player.model.hots[i].mesh.material.depthTest = false;
- }
- this.setDisplay(true)
- this.updateFootIconSize()
- //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
- },
- SetOneTagVisible: function(tag) {
- //点击某个热点后就对该热点进行设置,或者在热点修改时对其进行设置
- if (this.tagVsetting == tag)
- return;
- if (this.tagVsetting) {
- this.saveLastTagVi(this.tagVsetting);
- //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL);
- }
- this.tagVsetting = tag;
- //记录正在修改的
- this.delVisibleLines();
- //删除线
- this.showFootIcons(player.currentPano);
- this.createTagVisiLines(tag);
- //创线
- this.updateFootIconSize()
- //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
- },
- saveLastTagVi: function() {
- //保存刚设置过的tag
- var change = false;
- var newVPs = this.tagVTemp[this.tagVsetting.sid] || this.tagVsetting.visiblePanos.slice(0);
- for (var r in this.tagsVLines) {
- var line = this.tagsVLines[r];
- if (line.name.indexOf("new") > -1 && line.visible) {
- //新设置为visible且没有取消
- newVPs.push(r)
- change = true;
- //console.log("add: "+r)
- } else if (line.name.indexOf("new") == -1 && !line.visible) {
- //旧的且已经取消
- var i = newVPs.indexOf(r);
- if (i == -1) {
- console.log("visiblePanos删除error");
- continue;
- }
- newVPs.splice(i, 1);
- change = true;
- //console.log("sub: "+r)
- }
- }
- if (change) {
- this.tagVTemp[this.tagVsetting.sid] = newVPs;
- }
- },
- pauseSetTagVisible: function() {
- //pc保存后删除连线 但还在继续设置 点选热点即开始
- if (!this.setTagVisible || !this.tagVsetting)
- return;
- //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL );
- this.delVisibleLines();
- this.hideFootIcons();
- this.tagVTemp = {};
- this.tagVsetting = null;
- },
- finishSetTagVisible: function() {
- if (!this.setTagVisible)
- return;
- $(".toolTop").removeClass("unable")
- $("#hotVisible").removeClass("unable")
- this.pauseSetTagVisible();
- this.setTagVisible = false;
- this.setDisplay(false)
- this.$confirmSnap.addClass("hide")
- permitTranMode(true)
- /* for (var r in objects.tagManager.tags) {
- if(objects.tagManager.tags[r].state == "videoPanoFlag")continue;
- objects.tagManager.tags[r].disc.visible = false;
- objects.tagManager.tags[r].disc.material.depthTest = true;
- } */
- for (let i in player.model.hots) {
- player.model.hots[i].isSprite = player.model.hots[i]._isSprite;
- player.model.hots[i].isSprite || player.model.hots[i].mesh.quaternion.copy(player.model.hots[i].quaternion)
- player.model.hots[i].mesh.material.depthTest = true;
- }
- },
- /* saveTagVisibles : function () { //保存到服务器
- if (this.tagVsetting) this.saveLastTagVi(this.tagVsetting); //获取最后设置的那个热点的改动
- //可能出现数据没变但保存的情况。比如先改变了然后切换别的热点但切换回来时又改回来。
- var tags = [];
- for (var i in this.tagVTemp) {
- tags.push({
- sid: i,
- value: this.tagVTemp[i]//turnToPanoIndex(this.tagVTemp[i])
- })
- }
-
- if (tags.length == 0) {//没有需要保存的改动
-
- this.finishSetTagVisible()
- return;
- }
-
- return tags;
- } */
- //afterSaveTagVisibles : function(){
- saveTagVisibles: function() {
- if (this.tagVsetting)
- this.saveLastTagVi(this.tagVsetting);
- for (var i in this.tagVTemp) {
- //保持成功于是生效
- player.model.hots[i].visiblePanos = this.tagVTemp[i];
- }
- this.finishSetTagVisible()
- //还是保存完直接结束吧,因为现在热点可视不放在单独的设置页面了
- },
- createTagVisiLines: function(tag) {
- // 热点可见性线条
- var panos = player.model.panos;
- tag.visiblePanos || tag.setVisiblePanos("get")
- var visibleList = this.tagVTemp[tag.sid] || tag.visiblePanos;
- //如果是刚在设置的要读取设置过的数据
- for (var r = 0; r < visibleList.length; r++) {
- var pano = panos.index[visibleList[r]];
- this.createTagSingleLine(pano, "old", tag)
- }
- },
- createTagSingleLine: function(pano, type, tag) {
- var panos = player.model.panos;
- var line = LineDraw.createLine([pano.floorPosition.clone()/* .sub(this.position) */
- , tag.mesh.position.clone()], {
- color: this.colors.green
- });
- this.meshGroup.add(line);
- line.name = "tagVL-" + type + "-" + pano.id;
- this.tagsVLines[pano.id] = line;
- this.changeFIconState(panos.index[pano.id].footIcon, "linked")
- },
- dealTagVisible: function(tag, panoName) {
- //外部调用
- var panos = player.model.panos;
- if (this.tagsVLines[panoName]) {
- this.tagsVLines[panoName].visible = !this.tagsVLines[panoName].visible;
- this.changeFIconState(panos.index[panoName].footIcon, this.tagsVLines[panoName].visible ? "linked" : false)
- } else {
- this.createTagSingleLine(panos.index[panoName], "new", tag)
- }
- },
- delVisibleLines: function() {
- //xzw add 所有线都删除
- for (var i in this.tagsVLines) {
- this.tagsVLines[i].geometry.dispose();
- this.tagsVLines[i].material.dispose();
- this.meshGroup.remove(this.tagsVLines[i]);
- delete this.tagsVLines[i];
- }
- for (var i in this.panoVLines) {
- this.panoVLines[i].geometry.dispose();
- this.panoVLines[i].material.dispose();
- this.meshGroup.remove(this.panoVLines[i]);
- delete this.panoVLines[i];
- }
- }
- }
- function permitTranMode(state) {
- state ? $(".pinBottom.left").removeClass('hide') : $(".pinBottom.left").addClass('hide');
- }
-
- function randomWord(randomFlag, min, max) {
- //随机字符串
- var str = ""
- , range = min
- , arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
- if (randomFlag) {
- // 随机长度
- range = Math.round(Math.random() * (max - min)) + min;
- }
- for (var i = 0; i < range; i++) {
- var pos = Math.round(Math.random() * (arr.length - 1));
- str += arr[pos];
- }
- return str;
- }
- function getRandomSid() {
- //5-7位随机字符串 + 6位时间 为热点准备
- var pre = randomWord(true, 5, 7);
- var post = new Date().getTime() + "";
- var len = post.length;
- post = post.substring(len - 8, len - 5) + post.substring(len - 3, len)
- //其实还是有可能重复的....
- return pre + post;
- }
- function searchParent(searchArea, o, maxTimes) {
- //是否是某种元素的下级,并找出该元素
- maxTimes = maxTimes || 20;
- var count = 0
- var f = function(dom) {
- if (o.id && o.id == dom.id)
- return dom
- else if (o.className && dom.classList && dom.classList.contains(o.className))
- return dom
- else if (o.tagName && dom.tagName && o.tagName.toUpperCase() == dom.tagName.toUpperCase())
- return dom
- }
- var find;
- while (searchArea && count < maxTimes) {
- if (find = f(searchArea))
- return find
- searchArea = searchArea.parentNode;
- count++;
- }
- }
-
- class ListBox{//下拉列表
- //elemArr:初始的列表,内含每项的dom.
- constructor(elemArr, $rootDom, options={}){
-
- this.listDom = $rootDom.find('ul.list')
- this.listTitle = $rootDom.find('.selection')
-
- this.chosenItem = null
- this.options = options;
-
- this.bindEvents()
-
- elemArr.forEach(($dom, i)=>{
- this.addItem($dom)
- })
-
- }
- updateSelectDisplay(){
- this.listDom.children().removeClass('selected')
- this.chosenItem && this.chosenItem.addClass("selected")
- this.options.selectFun(this.chosenIndex)
-
- }
- selectFromOutSide(index ){
- this.chosenIndex = index;
- this.chosenItem = index == void 0 ? null : this.listDom.children().eq(index)
- this.updateSelectDisplay()
- }
-
- addItem($dom){
- this.listDom.append($dom)
- if(this.options.addFun){
- this.options.addFun($dom)
- }
-
- $dom.on('click',()=>{
- this.chosenItem = $dom;
- this.chosenIndex = $dom.index();
- this.updateSelectDisplay()
- })
- }
-
- removeItem($dom){
- $dom.remove()
- if(this.options.delFun){
- this.options.delFun($dom)
- }
- }
-
- saveTemp(){//编辑热点时保存一份副本
- this.temp = Array.from(this.listDom.children()).map((li)=>{
- return li.outerHTML
- })
- this.options.saveTemp && this.options.saveTemp(this)
-
- }
- recover(){//取消编辑时恢复
-
- this.listDom.html('')
- this.temp.forEach(html=>{
- this.addItem($(html));
- })
- this.options.recover && this.options.recover(this)
- this.selectFromOutSide(this.chosenIndex)
- }
-
- bindEvents(){
- this.listTitle.on('click',(e)=>{
- e.stopPropagation()
- this.listDom.toggleClass('hide')
- })
- document.addEventListener('click',()=>{
- this.listDom.addClass('hide')
- })
- }
- }
|