edit.js 197 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967
  1. /* var ceshi = '';
  2. // var ceshi = 'http://192.168.0.135:8105';
  3. // var ceshi = 'http://47.107.252.54:8105';
  4. // var token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsInJvbGUiOm51bGwsIm1hbmFnZXIiOm51bGwsImlkIjoxLCJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNTk2NzAxNjAyLCJpYXQiOjE1OTY2MTUyMDIsImp0aSI6Ijk0YjA5YTg1LWViY2ItNDE1Yy04OGVmLWU0MDM1M2UzYmIxYyJ9.Uzi95n0kYXp7bdpY77MdLtTpPL_Fq-jn0tE7gjg6AzA"
  5. var token = window.localStorage.dcj_token
  6. */
  7. var _musicMaxWeight = 8
  8. //M
  9. var cmp = getQueryVariable('cmp') || ''
  10. var _hotNum = 0
  11. function reData(data, type) {
  12. return JSON.stringify(data) == type ? null : data
  13. }
  14. let strictInputNum = function(e, precision, min=0,max){//precision:保留小数位数
  15. var value = e.target.value.trim();
  16. var lastOne = value[value.length-1];
  17. var preContent = value.substr(0,value.length-1)
  18. var hasPoint = precision > 0 && lastOne == '.' ;
  19. var a = Math.pow(10, precision)
  20. value = parseFloat(value) || 0;
  21. if(isNaN(value)){
  22. e.target.value = preContent //还原
  23. return
  24. }
  25. e.target.value = Math.max(min, parseInt(value * a) / a )
  26. hasPoint && (e.target.value += '.')//补小数点
  27. }
  28. //新编辑界面
  29. var EditTools = function(n) {
  30. //main2018 里面的主要对象
  31. this.n = n;
  32. //当前状态
  33. this.atPanel = null;
  34. //场景信息
  35. this.sceneInformation = new SceneInformation();
  36. //热点
  37. this.hotpoint = new Hotpoint();
  38. //导览
  39. this.editGuide = new EditGuide();
  40. //音乐
  41. this.EditBGM = new EditBGM();
  42. //初始化界面
  43. //this.init();
  44. this.data = {}
  45. }
  46. EditTools.prototype.loadDone = function(name, data){
  47. this.data[name] = data
  48. if('data' in this.data && 'data2' in this.data){
  49. this.init();
  50. }
  51. }
  52. EditTools.prototype.init = function() {
  53. this.hotpoint.init(/* this.n */);
  54. var that = this;
  55. this.initSaveAll();
  56. this.active();
  57. if(player.mode != 'panorama'){
  58. $(".toolLeft li[data-name=panoVisible]").addClass('unable')
  59. player.once("pano.chosen",()=>{
  60. $(".toolLeft li[data-name=panoVisible]").removeClass('unable')
  61. })
  62. }
  63. //创建导览
  64. that.EditBGM.init(this.data.data);
  65. that.sceneInformation.init(this.data.data, this.data.data2)
  66. // fyz 初始化导览需要两部分数据, 其中data2为data.js中的数据
  67. that.editGuide.init(this.data.data, this.data.data2);
  68. $("body").on("click", function() {
  69. $(".DelConfirm").removeClass("active");
  70. })
  71. /* $(" .MenuOptions li").on("click", (e)=>{
  72. var $elem = $(e.target);
  73. $elem.closest('.MenuOptions').find('li').removeClass("chosen");
  74. $elem.addClass("chosen");
  75. }) */
  76. }
  77. //点击的时候激活状态
  78. EditTools.prototype.active = function() {
  79. var that = this;
  80. var confirmSnap = $(".confirmSnap.innerBtn");
  81. var snapshotGui = $(".snapshotGui.overlayGui");
  82. $('.toolBottom .toolLeft li').click(function() {
  83. var name = $(this).data("name");
  84. $('.toolLeft li[data-name=' + name + ']').addClass("active").siblings().removeClass("active");
  85. $('.toolRight .' + name).removeClass("hide").siblings().addClass("hide");
  86. if (name == that.atPanel)
  87. return;
  88. console.log(`atPanel ${that.atPanel} name ${name}`)
  89. switch (that.atPanel) {
  90. //退出
  91. case "panoVisible":
  92. VisiSet.finishSetPanoVisible()
  93. break;
  94. case "panoLog":
  95. VisiSet.finishSetPanoLog()
  96. break;
  97. case "screen":
  98. confirmSnap.addClass("hide").removeClass("unable");
  99. snapshotGui.hide();
  100. break;
  101. case "overlay":
  102. EditOverlay.leave()
  103. break;
  104. case "hotpoint":
  105. $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click();
  106. VisiSet.finishSetTagVisible()
  107. that.hotpoint.wireframeModel.visible = false
  108. break;
  109. }
  110. switch (name) {
  111. case "hotpoint":
  112. that.hotpoint.wireframeModel.visible = that.hotpoint.wireframeModel.shouldShow
  113. break;
  114. case "panoVisible":
  115. $(".toolLeft").addClass("unable")
  116. VisiSet.enterSet(VisiSet.beginSetPanoVisible.bind(VisiSet))
  117. break;
  118. case "panoLog":
  119. $(".toolLeft").addClass("unable")
  120. VisiSet.enterSet(VisiSet.beginSetPanoLog.bind(VisiSet))
  121. break;
  122. case "screen":
  123. confirmSnap.removeClass("hide");
  124. $('#camera-start').text("点此设置为初始画面")
  125. snapshotGui.show();
  126. if (player.modeTran.split("-")[1] != "panorama")
  127. $(".confirmSnap").addClass("unable")
  128. break;
  129. case "overlay":
  130. EditOverlay.enter()
  131. break;
  132. }
  133. that.atPanel = name;
  134. /* if(name != "hotpoint"){
  135. $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click()
  136. } */
  137. })
  138. //滚动阻止事件
  139. $(".toolRight div.content").on("mousewheel", function(event) {
  140. event.stopPropagation()
  141. });
  142. // 输入框阻止事件
  143. $('.toolRight').on('keydown', function(ev) {
  144. ev.stopPropagation();
  145. })
  146. }
  147. //保存按钮
  148. EditTools.prototype.initSaveAll = function() {
  149. var that = this;
  150. $('#save').on('click', function() {
  151. $(".edit-loading").removeClass("hide");
  152. var $shareImages = $(".information .edit-fun-images a.result");
  153. new Promise(function(resolve, reject) {//分享图
  154. upload($shareImages, 'images', resolve)
  155. }).then(function(imgUrls) {
  156. //导览的数据
  157. var guides = that.editGuide.getSavingInfo()/* Array.from($('.tourFolderList ul li')).map(function(dom) {
  158. return dom.data
  159. }) */
  160. var info = {
  161. name: $('#pjtName').val(),
  162. summary: $('#info-summary').val(),
  163. weixinDesc: $('#weixin-summary').val(),
  164. shareImgUrl: imgUrls[0] || '',
  165. backgroundMusic: that.EditBGM.musicBox.getSrc() || '',
  166. bgName: that.EditBGM.musicBox.getName(),
  167. hoticon: JSON.parse($(".hotStyle-item li.active").attr("data-val")),
  168. camera_start: $('#camera-start')[0].data,
  169. loadlogo: $("#loadlogo").is(':checked'),
  170. special: $("#g_specialScene").is(':checked'),
  171. vision_version: $("#twoData").is(':checked') ? "1.1.562.17209" : false,
  172. /************************************** 方奕卓 场景可配置项 ******************************************/
  173. hotImageScale: $("#hotImgScale").is(':checked'),
  174. // 热点图片可放大
  175. hideFloorMarker: $("#hideFloorMarker").is(':checked'),
  176. // 地面标记
  177. hideMouseMarker: $("#hideMouseMarker").is(':checked'),
  178. showingLabels: $("#showingLabels").is(':checked'),
  179. // 鼠标标记
  180. floorMarkerColor: $('#floorMarkerColor').val(),
  181. // 地面/导览标志颜色
  182. mouseMarkerColor: $('#mouseMarkerColor').val(),
  183. // 鼠标标志颜色
  184. momentTour: $('#tourSwitch input').is(':checked') ? 'black' : 'walk',
  185. // 导览瞬间过渡
  186. showHotListSta: $('#hotListSwitch').is(':checked'),
  187. // 开启热点列表
  188. hotIconScale: DATA.hotIconScale,
  189. // 热点缩放
  190. supportsVR: $('#VRSwitch input').is(':checked'),
  191. // 开启VR功能
  192. /**************** 陈志广 小地图可配置项 *********** */
  193. cadSignColor: $('#cadSignColor').val(),
  194. cadBorderColor: $('#cadBorderColor').val(),
  195. cadBorderWidth: $('#cad-size').val(),
  196. showCad: $('input[name="show-cad"]').is(':checked'),
  197. }
  198. var data = {
  199. sceneCode: number,
  200. hots: reData(that.hotpoint.getSavingInfo(), '{}'),
  201. //tourAudio: reData(that.editGuide.tourAudio,'{}'),//for 旧版
  202. name: number,
  203. guides: reData(guides, '[]'),
  204. info: info,
  205. }
  206. console.log(data)
  207. let url = cmp ? ('/api/scene/edit/' + cmp) : '/manage/scene/edit'
  208. $.ajax({
  209. method: 'POST',
  210. headers: {
  211. 'Content-Type': 'application/json',
  212. token: token
  213. },
  214. dataType: 'json',
  215. contentType: 'application/json',
  216. url: ceshi + url,
  217. data: JSON.stringify(data),
  218. success: function(data) {
  219. if (data.code === 0) {//成功
  220. //manage.showInfo("保存成功")
  221. location.reload()
  222. }else if (data.code === 5001) {
  223. alert('请重新登录')
  224. localStorage.dcj_token = ''
  225. location.reload()
  226. }else{
  227. alert(`saveAll (url:${url}) code : ${data.code} \n${data.msg}`)
  228. }
  229. }
  230. })
  231. });
  232. })
  233. }
  234. //场景信息编辑
  235. var SceneInformation = function() {}
  236. SceneInformation.prototype.init = function(data, data2) {
  237. var $options = $('.hotStyle-item li');
  238. var $loadlogo = $("#loadlogo");
  239. var $hotImageScale = $("#hotImgScale");
  240. var $hideFloorMarker = $("#hideFloorMarker");
  241. var $hideMouseMarker = $("#hideMouseMarker");
  242. var $showingLabels = $("#showingLabels");
  243. var $g_specialScene = $("#g_specialScene");
  244. var $twoData = $("#twoData");
  245. /*******************方奕卓 其他项需要用到data来初始化, 故一并放到这里 ******************/
  246. let momentTour = $('#tourSwitch input');
  247. // 导览瞬间过渡开关
  248. let hotListSwitch = $('#hotListSwitch');
  249. // 热点列表开关
  250. let hotIconScale = $('#hotIconScale');
  251. // 热点图标缩放
  252. let VRSwitch = $('#VRSwitch input');
  253. // VR功能开启
  254. /***********************************************************************************/
  255. $(".model-title2").text(data.name);
  256. $('#pjtName').val(data.name);
  257. $('#info-summary').val(data.summary);
  258. //if (data2) $('#weixin-summary').val(data2.weixinDesc);
  259. $('#weixin-summary').val(data.weixinDesc);
  260. for (var i = 0; i < $options.length; i++) {
  261. if ($options.eq(i).attr('data-val') === JSON.stringify(data.hoticon)) {
  262. $options.eq(i).addClass("active").siblings().removeClass("active");
  263. }
  264. }
  265. $('#camera-start')[0].data = data.camera_start;
  266. $(".shotImg.innerBtn").on("click", ()=>{
  267. var EntryInfo = $('#camera-start')[0].data
  268. if (EntryInfo) {
  269. var to = player.model.panos.get(EntryInfo.pano.uuid);
  270. var q = new THREE.Quaternion().fromArray(EntryInfo.camera.quaternion);
  271. var lookAtPoint = new THREE.Vector3(0,0,-1).applyQuaternion(q).add(to.position);
  272. player.flyToPano({
  273. pano: to,
  274. lookAtPoint: lookAtPoint
  275. })
  276. }
  277. }
  278. )
  279. if(data.shareImgUrl){
  280. var imagesHTML = '<div><a class=" result success"><span></span><img src="' + data.shareImgUrl + '"></a></div>'
  281. $(".information .edit-fun-images.list ").html(imagesHTML);
  282. $("#shareImgUpload").addClass("hide")
  283. }
  284. if(data.spotImgUrl){
  285. }
  286. /*************方奕卓 其他项的初始化操作 ************/
  287. initColorElem(data);
  288. addListener();
  289. // 给其他元素绑定事件
  290. if (data.momentTour === 'black') {
  291. momentTour.prop('checked', true);
  292. }
  293. if (data.showHotListSta) {
  294. hotListSwitch.prop('checked', true);
  295. }
  296. if (data.hotIconScale) {
  297. hotIconScale.val(parseFloat(data.hotIconScale));
  298. }
  299. /* $('#hotIconScale_2 input').on('change',(e)=>{
  300. var s = THREE.Math.clamp(parseFloat(e.target.value), 0.1, 100)
  301. e.target.value = s
  302. editTool.hotpoint.editSpot.mesh.scale.set(s,s,s)
  303. }) */
  304. if (data.supportsVR) {
  305. VRSwitch.prop('checked', true);
  306. }
  307. /************************************************/
  308. //隐藏公司logo
  309. if (data.loadlogo) {
  310. $loadlogo[0].checked = true
  311. showLogo();
  312. }
  313. // 热点图片放大
  314. if (data.hotImageScale) {
  315. $hotImageScale[0].checked = true
  316. }
  317. // 隐藏地面标记
  318. if (data.hideFloorMarker) {
  319. $hideFloorMarker[0].checked = true
  320. }
  321. // 隐藏鼠标标记
  322. if (data.hideMouseMarker) {
  323. $hideMouseMarker[0].checked = true
  324. }
  325. if (data.showingLabels) {
  326. $showingLabels[0].checked = true
  327. }
  328. //特殊大场景
  329. if (data.special) {
  330. $g_specialScene[0].checked = true
  331. }
  332. //启动二代的数据
  333. if (data.vision_version === "1.1.562.17209" || data.vision_version) {
  334. $twoData[0].checked = true
  335. }
  336. }
  337. /**
  338. * 初始化颜色选择的html元素
  339. * @param {*} data
  340. * @param {*} elem
  341. */
  342. function initColorElem(data, elem) {
  343. let $floorMarkerColor = $('#floorMarkerColor');
  344. let $mouseMarkerColor = $('#mouseMarkerColor');
  345. let $floorMarkerColorTex = $('#floorMarkerColorTex');
  346. let $mouseMarkerColorTex = $('#mouseMarkerColorTex');
  347. let $cadSignColor = $('#cadSignColor');
  348. let $cadSignColorTex = $('#cadSignColorTex');
  349. let $cadBorderColor = $('#cadBorderColor');
  350. let $cadBorderColorTex = $('#cadBorderColorTex');
  351. var colorRe = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/;
  352. // 事件监听
  353. $floorMarkerColor.on('change', function(e) {
  354. $('#floorMarkerColorTex').val(e.target.value)
  355. })
  356. $floorMarkerColorTex.on('blur keydown', function(e) {
  357. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $floorMarkerColor, this);
  358. })
  359. $mouseMarkerColor.on('change', function(e) {
  360. $('#mouseMarkerColorTex').val(e.target.value)
  361. })
  362. $mouseMarkerColorTex.on('blur keydown', function(e) {
  363. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $mouseMarkerColor, this);
  364. })
  365. // 事件监听
  366. $cadSignColor.on('change', function(e) {
  367. $('#cadSignColorTex').val( e.target.value)
  368. })
  369. $cadSignColorTex.on('blur keydown', function(e) {
  370. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadSignColor, this);
  371. })
  372. // 事件监听
  373. $cadBorderColor.on('change', function(e) {
  374. $('#cadBorderColorTex').val( e.target.value)
  375. })
  376. $cadBorderColorTex.on('blur keydown', function(e) {
  377. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadBorderColor, this);
  378. })
  379. // 设置颜色值
  380. function setColor(e, colorElem, inputElem) {
  381. var isColor = colorRe.test(e.target.value);
  382. isColor && colorElem.val(e.target.value);
  383. // isColor ? colorElem.val(e.target.value): (inputElem.placeholder = colorElem.val());
  384. }
  385. // 判断data中是否有存在的颜色值, 否则设置默认值
  386. data.floorMarkerColor ? $floorMarkerColor.val(data.floorMarkerColor) : $floorMarkerColor.val('#4bcdfc');
  387. data.mouseMarkerColor ? $mouseMarkerColor.val(data.mouseMarkerColor) : $mouseMarkerColor.val('#4bcdfc');
  388. // 判断data中是否有存在的颜色值, 否则设置默认值
  389. data.cadSignColor ? $cadSignColor.val(data.cadSignColor) : $cadSignColor.val('#00c8af');
  390. data.cadBorderColor ? $cadBorderColor.val(data.cadBorderColor) : $cadBorderColor.val('#ffffff');
  391. $('input[name="show-cad"]')[0].checked = !!data.showCad
  392. $('#cad-size > option[value="'+(data.cadBorderWidth ? data.cadBorderWidth : '0.01')+'"]').attr("selected",true);
  393. if (data.showCad) {
  394. $('input[name="show-cad"]').trigger('change')
  395. }
  396. $('#panoIdColor').on('change', function(e) {
  397. $('#panoIdColorTex').val(e.target.value)
  398. VisiSet.changePanoIdColor(e.target.value)
  399. })
  400. $('#panoIdColorTex').on('blur keydown', function(e) {
  401. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $('#panoIdColor'), this);
  402. VisiSet.changePanoIdColor(e.target.value)
  403. })
  404. $('#panoIdColor').val('#c13e3e')//初始颜色
  405. $('#panoIdColorTex').val('#c13e3e')
  406. }
  407. $('input[name="show-cad"]').on('change', function(ev) {
  408. if (!ev.target.checked) {
  409. return $('.cad').hide()
  410. }
  411. let taht = this
  412. if (!taht.floorJSON) {
  413. $.ajax({
  414. url: '//super.4dage.com/data/'+ window.number +'/floor.json',
  415. method: 'GET',
  416. success(res) {
  417. taht.floorJSON = res
  418. loadCAD(taht.floorJSON)
  419. $('#cadSignColor').on('change', function(ev) {
  420. loadCAD()
  421. })
  422. $('#cadBorderColor').on('change', function(ev) {
  423. loadCAD()
  424. })
  425. $('#cad-size').on('change', function(ev) {
  426. loadCAD()
  427. })
  428. },
  429. error() {
  430. alert('当前场景没有小地图floor.json文件,请联系三维部门添加')
  431. ev.target.checked = false
  432. }
  433. })
  434. } else {
  435. console.log('0000000000000000000')
  436. $('.cad').show()
  437. }
  438. })
  439. function loadCAD(data) {
  440. grendCAD(data, $('#player')[0], $('#cadSignColor').val(), $('#cadBorderColor').val(), $('#cad-size').val())
  441. }
  442. function addListener() {}
  443. //设置初始界面
  444. function getSeft(seft) {
  445. $('#camera-start').on('click', function() {
  446. if (VisiSet.setPanoVisible) {
  447. return VisiSet.savePanoVisibles()
  448. } else if (VisiSet.setTagVisible) {
  449. return VisiSet.saveTagVisibles()
  450. }
  451. // 这部分内容需要配合main_2018.js中来进行修改
  452. var snap = JSON.parse("{" + seft.getSnapAngleInfo() + "}")
  453. this.data = {
  454. camera: {
  455. position: snap.metadata.camera_position,
  456. quaternion: snap.metadata.camera_quaternion// 相机朝向
  457. },
  458. pano: {
  459. uuid: snap.metadata.scan_id // 起始点位的id
  460. }
  461. }
  462. var ev = document.createEvent("MouseEvent");
  463. //点击截取视图
  464. g_snapShotWidth = 240 * 4;
  465. g_snapShotHeight = 118 * 4;
  466. window.screenSta = 'startScreen';
  467. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  468. ev.__callback = (imgData,info)=>{
  469. uploadImg(imgData, (rs)=>{
  470. if (rs.code === 0) {
  471. $(".shotImg.innerBtn").css("background-image", "url(" + rs.data + ")")
  472. this.data.thumbImg = rs.data;
  473. }
  474. }
  475. , "thumbImg.jpg")
  476. }
  477. window.dispatchEvent(ev);
  478. });
  479. }
  480. //热点编辑
  481. var Hotpoint = function() {
  482. this.spotList = $(".spotList");
  483. this.hotpointDetail = $("#hotpointDetail");
  484. this._scale = {}
  485. this.scroller = {}
  486. this.scroller.boxDepth = new SlideBar({
  487. root: $('#boxDepth').eq(0),
  488. value: 0,
  489. min: 0 * 100,
  490. max: 1 * 100,
  491. name: "boxDepth",
  492. unitStr: "cm",
  493. avoidCrash: true,
  494. onchange: (s)=>{
  495. if (s == 0) {
  496. this.editSpot.addBox(false)
  497. } else {
  498. this.editSpot.addBox(true)
  499. this.editSpot.scale.z = s / 100 ;
  500. this.updateTransform("scale")
  501. }
  502. },
  503. dragEndEvent: function() {
  504. }
  505. })
  506. // fyz 导览编辑页面同样采取热点编辑的样式, 这里确保只查找到热点编辑
  507. }
  508. Hotpoint.prototype.init = function() {
  509. var that = this;
  510. $(".hotStyle-item li").on('click', function() {//默认样式
  511. $(this).addClass('active').siblings().removeClass('active');
  512. })
  513. // 添加多媒体
  514. this.musicBox = musicPlayBoxBind(this.hotpointDetail.find("[name=audio].mediaUpload"), null )
  515. this.addmediaInit();
  516. // 添加音乐
  517. this.addModel();
  518. // 添加模型
  519. this.addwebPack();
  520. // 添加外链
  521. this.wireframeModel = new THREE.Object3D;
  522. if(Hot.allPhotoLoaded && Hot.allModelLoaded) this.initListSelect()
  523. else Hot.whenAllFileLoaded = this.initListSelect.bind(this) //等全部photo加载完
  524. player.model.hotGroup.children.forEach(e=>this.addHotList(e) )//创建列表
  525. this.hotpointDetail.find(".tail .submit").on('click', this.saveHot.bind(this))
  526. {
  527. let ui = $('#hotIconScale input')
  528. let min = parseFloat(ui.attr('min'));
  529. let max = parseFloat(ui.attr('max'));
  530. ui.on("change", function(e) {
  531. var s = THREE.Math.clamp(parseFloat(e.target.value), min, max)
  532. if(isNaN(s))s = 1
  533. e.target.value = s
  534. DATA.hotIconScale = s
  535. })
  536. }
  537. this.isSpriteCheckBox = new CheckBox({dom: $("#isSprite"),
  538. uiCallBack : (checked)=>{
  539. },
  540. callbackWhenChose:(checked)=>{
  541. that.editSpot.info.isSprite = checked;
  542. if(checked) {
  543. that.editSpot.update(player)
  544. }else{
  545. that.editSpot.rotation.copy(that.editSpot.info.rotation)
  546. }
  547. }
  548. })
  549. //clickEvent
  550. this.actionCheckBox = new CheckBox({dom: this.hotpointDetail.find("li[name='clickEvent'] li.editCheckbox input"),
  551. uiCallBack : (checked, name)=>{
  552. if(name == 'openHot'){
  553. var content = that.hotpointDetail.find("li[name='content']")
  554. checked ? content.removeClass('hide') : content.addClass('hide')
  555. }
  556. },
  557. callbackWhenChose:(checked, name)=>{
  558. that.editSpot.info.actionType[name] = !!checked;
  559. }
  560. })
  561. //点击添加热点按钮
  562. $('.hotpoint .addBtn button').on("click", function(e) {
  563. g_HotStatus = $(e.target).attr('data-type');
  564. $("#player").css("cursor", "cell");
  565. });
  566. //点击热点列表弹出按钮
  567. this.spotList.on("click", function(e) {
  568. var target = $(e.target);
  569. let li = searchParent(e.target, { className: 'listItem' }, 7);
  570. if(!li)return;
  571. var hotId = $(li).attr("data-spid");
  572. var hot = player.model.hots[hotId]
  573. if(VisiSet.setTagVisible){
  574. return VisiSet.SetOneTagVisible(hot)
  575. }
  576. if (target.hasClass("del")) {
  577. e.stopPropagation();
  578. target.siblings(".DelConfirm").addClass("active");
  579. that.spotList.find("i").text(that.spotList.find("ul li").length);
  580. } else {
  581. if (target.hasClass("DelConfirm")) {
  582. e.stopPropagation();
  583. that.removeHot(hot);
  584. } else {
  585. //点击热点列表弹出编辑热点窗口
  586. that.editHot(hot, $(li))
  587. }
  588. }
  589. });
  590. //关闭、取消
  591. this.hotpointDetail.find("a.close, button.cancel").on("click", ()=>{
  592. var hot = this.editSpot
  593. if(hot.isNew){
  594. this.removeHot(hot)
  595. }else{
  596. this.recoverInfo(hot)
  597. hot.updateVisible([player.currentPano])
  598. }
  599. this.tempInfos && player.model.hotGroup.children.forEach(hot=>{//还原所有同时修改了的贴图和模型
  600. var info = this.tempInfos[hot.sid]
  601. if(hot.texType == 'shine'){
  602. hot.changeTexType(hot.texType, info.styleImg )
  603. hot.info.styleImg = info.styleImg.map(e=>e.src)
  604. }else{
  605. hot.changeTexType(hot.texType, info.texMedia )
  606. hot.info.texSrc = info.texMedia.src;
  607. if(hot.texType == 'photo' && hot.info.animateInfo){
  608. GifTexDeal.remove(hot.animation)
  609. hot.animation = GifTexDeal.addAnimation(hot.material_.map, hot, hot.info.animateInfo )
  610. GifTexDeal.start(hot.animation)
  611. }
  612. }
  613. if(hot.objObject != info.objObject){
  614. this.switchModel({add:info.objObject, spot:hot})
  615. hot.info.scale.copy(info.scale)
  616. hot.scale.copy(info.scale)
  617. }
  618. })
  619. if(this.texLists){
  620. for(let i in this.texLists){this.texLists[i].recover()}
  621. this.modelList.recover()
  622. }
  623. this.editDone();
  624. });
  625. this.linkTypeMenuOptions = new MenuOptions({ //链接打开方式切换
  626. dom: this.hotpointDetail.find(" .MenuOptions[name=linkType] "),
  627. uiCallBack : (o)=>{
  628. },
  629. callbackWhenChose:(o)=>{
  630. this.editSpot.info.linkType = o.$li.attr("index")
  631. }
  632. })
  633. this.panoTransformCheckBox = new CheckBox({dom: $('#setPosForPano input') ,
  634. uiCallBack : (checked, name)=>{
  635. },
  636. callbackWhenChose:(checked, name)=>{
  637. if(!checked){
  638. delete this.editSpot.info.transformAtPanos[getTransformSid()]
  639. this.editSpot.position.copy(this.editSpot.info.position)
  640. //this.editSpot.quaternion.copy(this.editSpot.quaternion)
  641. }else{
  642. this.getTransformAtPano('position')
  643. }
  644. }
  645. })
  646. /* $('#setPosForPano input').on("change", ()=>{
  647. var on = $('#setPosForPano input').is(':checked')
  648. if(!on){
  649. delete this.editSpot.info.transformAtPanos[getTransformSid()]
  650. this.editSpot.position.copy(this.editSpot.info.position)
  651. //this.editSpot.quaternion.copy(this.editSpot.quaternion)
  652. }else{
  653. this.getTransformAtPano('position')
  654. }
  655. }) */
  656. //是否显示模型线框
  657. this.wireframeModel = new THREE.Object3D;
  658. $('#wireframeSwitch input').on('change',(e)=>{
  659. var visi = e.target.checked;
  660. if(visi && this.wireframeModel.children.length == 0){
  661. var mat = new THREE.MeshBasicMaterial({
  662. wireframe: true,
  663. opacity: 0.5,
  664. color: "#57e4f3",
  665. transparent: true
  666. })
  667. this.wireframeModel.name = 'wireframeModel'
  668. player.model.chunks.forEach((mesh)=>{
  669. var chunk = mesh.clone();
  670. chunk.material = mat;
  671. this.wireframeModel.add(chunk)
  672. })
  673. this.wireframeModel.visible = false
  674. player.model.add(this.wireframeModel)
  675. }
  676. this.wireframeModel.visible = visi
  677. this.wireframeModel.shouldShow = visi
  678. })
  679. //动画
  680. this.gifCheckBox = new CheckBox({dom: $("#gifSwitch input"),
  681. uiCallBack : (checked )=>{
  682. $("#gifInfoEdit").css({display: checked ? 'block' : 'none'})
  683. },
  684. callbackWhenChose:(checked )=>{
  685. if(checked){
  686. that.editSpot.info.animateInfo = {
  687. cellXcount : parseInt($("#gifXCount").val()),
  688. cellYcount : parseInt($("#gifYCount").val()),
  689. voidCount : parseInt($("#voidCount").val()),
  690. loop : true,
  691. duration : parseFloat($("#gifDuration").val()) * 1000
  692. }
  693. that.editSpot.animation = GifTexDeal.addAnimation(that.editSpot.material_.map, that.editSpot, this.editSpot.info.animateInfo, this.editSpot.sid)
  694. GifTexDeal.start(that.editSpot.animation)
  695. }else{
  696. GifTexDeal.remove(that.editSpot.animation)
  697. that.editSpot.info.animateInfo = null
  698. }
  699. }
  700. })
  701. {//gif动画 input
  702. let changeAnimation = function(){
  703. GifTexDeal.setRepeart(that.editSpot.animation.animation)
  704. that.useSuitableRatio()
  705. }
  706. let restartAnimation = function(){
  707. GifTexDeal.stop(that.editSpot.animation)
  708. GifTexDeal.start(that.editSpot.animation)
  709. }
  710. let changeFrameCount = function(){
  711. var a = that.editSpot.info.animateInfo
  712. var frameCount = a.cellXcount * a.cellYcount - (a.voidCount||0)
  713. $("#gifFrameCount").text(frameCount)
  714. var fps = parseFloat($("#gifFps").val())
  715. a.duration = frameCount / fps * 1000
  716. $("#gifDuration").val(toPrecision(a.duration/1000, 2))
  717. }
  718. let gifXCountFun = function(value){
  719. that.editSpot.info.animateInfo.cellXcount = value
  720. var gifImgWidth = parseFloat($("#gifImgWidth").text())
  721. var gifCellWidth = toPrecision(gifImgWidth / that.editSpot.info.animateInfo.cellXcount,1);
  722. $("#gifCellWidth").text(gifCellWidth)
  723. changeFrameCount()
  724. changeAnimation()
  725. }
  726. $("#gifXCount").on('input',(e)=>{
  727. strictInputNum(e, 0)
  728. gifXCountFun(parseFloat(e.target.value))
  729. })
  730. $("#gifXCount").on('change',(e)=>{
  731. strictInputNum(e, 0, 1)
  732. gifXCountFun(parseFloat(e.target.value))
  733. restartAnimation()
  734. })
  735. let gifYCountFun = function(value){
  736. that.editSpot.info.animateInfo.cellYcount = value
  737. var gifImgHeight = parseFloat($("#gifImgHeight").text())
  738. var gifCellHeight = toPrecision(gifImgHeight / that.editSpot.info.animateInfo.cellYcount,1);
  739. $("#gifCellHeight").text(gifCellHeight)
  740. changeFrameCount()
  741. changeAnimation()
  742. }
  743. $("#gifYCount").on('input',(e)=>{
  744. strictInputNum(e, 0)
  745. gifYCountFun(parseFloat(e.target.value))
  746. })
  747. $("#gifYCount").on('change',(e)=>{
  748. strictInputNum(e, 0, 1)
  749. gifYCountFun(parseFloat(e.target.value))
  750. changeAnimation()
  751. restartAnimation()
  752. })
  753. /* let gifCellWidthFun = function(value){
  754. var gifCellWidth = value;
  755. var gifImgWidth = parseFloat($("#gifImgWidth").text())
  756. var cellXcount = toPrecision(gifImgWidth / gifCellWidth,2);
  757. $("#gifXCount").val(cellXcount)
  758. changeAnimation()
  759. }
  760. $("#gifCellWidth").on('input',(e)=>{
  761. strictInputNum(e, 0)
  762. gifCellWidthFun(parseFloat(e.target.value))
  763. })
  764. $("#gifCellWidth").on('change',(e)=>{
  765. strictInputNum(e, 0, 1)
  766. gifCellWidthFun(parseFloat(e.target.value))
  767. var cellXcount = $("#gifXCount").val();
  768. var cellXcountInt = Math.round(cellXcount)
  769. if(cellXcountInt != cellXcount){
  770. $("#gifXCount").val(cellXcountInt)
  771. gifXCountFun(cellXcountInt)
  772. changeAnimation()
  773. }
  774. restartAnimation()
  775. })
  776. let gifCellHeightFun = function(value){
  777. var gifCellHeight = parseFloat(e.target.value);
  778. var gifImgHeight = parseFloat($("#gifImgHeight").text())
  779. var cellYcount = toPrecision(gifImgHeight / gifCellHeight,2);
  780. $("#gifYCount").val(cellYcount)
  781. }
  782. $("#gifCellHeight").on('input',(e)=>{
  783. strictInputNum(e, 0)
  784. gifCellHeightFun(parseFloat(e.target.value))
  785. })
  786. $("#gifCellHeight").on('change',(e)=>{
  787. strictInputNum(e, 0, 1)
  788. gifCellHeightFun(parseFloat(e.target.value))
  789. var cellYcount = $("#gifYCount").val();
  790. var cellYcountInt = Math.round(cellYcount)
  791. if(cellYcountInt != cellYcount){
  792. $("#gifYCount").val(cellYcountInt)
  793. gifYCountFun(cellYcountInt)
  794. changeAnimation()
  795. }
  796. restartAnimation()
  797. })*/
  798. $("#voidCount").on('change',(e)=>{
  799. strictInputNum(e, 0);
  800. that.editSpot.info.animateInfo.voidCount = parseInt(e.target.value)
  801. changeFrameCount()
  802. restartAnimation()
  803. })
  804. let gifDurationFun = function(value){
  805. var a = that.editSpot.info.animateInfo
  806. let frameCount = a.cellXcount * a.cellYcount
  807. a.duration = value
  808. $("#gifFps").val(toPrecision(frameCount / a.duration * 1000, 1))
  809. }
  810. $("#gifDuration").on('input',(e)=>{
  811. strictInputNum(e, 1);
  812. gifDurationFun(parseFloat(e.target.value) * 1000)
  813. })
  814. $("#gifDuration").on('change',(e)=>{
  815. strictInputNum(e, 1, 0.01);
  816. gifDurationFun(parseFloat(e.target.value) * 1000)
  817. restartAnimation()
  818. })
  819. var gifFpsFun = function(e){
  820. strictInputNum(e, 0, 1);
  821. var fps = parseFloat(e.target.value)
  822. var a = that.editSpot.info.animateInfo
  823. let frameCount = a.cellXcount * a.cellYcount - (a.voidCount||0)
  824. a.duration = frameCount / fps * 1000
  825. $("#gifDuration").val(toPrecision(a.duration / 1000, 2))
  826. }
  827. $("#gifFps").on('input',(e)=>{
  828. gifFpsFun(e)
  829. })
  830. $("#gifFps").on('change',(e)=>{
  831. gifFpsFun(e)
  832. restartAnimation()
  833. })
  834. }
  835. this.modelMenuOptions = new MenuOptions({
  836. dom: this.hotpointDetail.find(".MenuOptions[name=modelType]"),
  837. uiCallBack : (o)=>{
  838. var name = o.name || o.$li.attr('index')
  839. if(name == "default"){
  840. this.hotpointDetail.find('[name=boxDepthPanel]').removeClass('hide')
  841. this.updateBoxDepthPanel()
  842. this.hotpointDetail.find('[name=uploadObj]').addClass('hide')
  843. transformControls.unableScaleZ()
  844. }else{
  845. this.hotpointDetail.find('[name=boxDepthPanel]').addClass('hide')
  846. this.hotpointDetail.find('[name=uploadObj]').removeClass('hide')
  847. }
  848. },
  849. callbackWhenChose:(o)=>{
  850. var name = o.$li.attr('index')
  851. if(name == "default"){
  852. /* transformControls.unableScaleZ()
  853. this.editSpot.removeModel() */
  854. this.switchModel({remove:true, spot:this.editSpot})
  855. if(this._scale[this.editSpot.texType]){//恢复大小
  856. this.editSpot.scale.copy(this._scale[this.editSpot.texType]);
  857. this.editSpot.info.scale.copy(this._scale[this.editSpot.texType]);
  858. }
  859. }else{
  860. this.modelList.options.selectFun()
  861. this._scale[this.editSpot.texType] = this.editSpot.scale.clone()
  862. }
  863. }
  864. })
  865. }
  866. Hotpoint.prototype.updateBoxDepthPanel = function(){
  867. var hot = this.editSpot
  868. if (hot.info.hasBox) {
  869. this.scroller.boxDepth.setValue(hot.scale.z * 100, true)
  870. } else {
  871. this.scroller.boxDepth.setValue(0, true)
  872. }
  873. setTimeout(()=>{
  874. this.scroller.boxDepth.InitOffset()
  875. }, 201)
  876. }
  877. /**
  878. * 显示编辑热点的窗口和初始化热点窗口的数据
  879. */
  880. Hotpoint.prototype.editHot = function(hot, $li) {
  881. try {
  882. transformControls.attach(hot)
  883. if(player.mode == 'panorama'){
  884. hot.examine( {
  885. dontOpen: true, examine:true,
  886. aimDuration : 600,
  887. duration : 600
  888. })
  889. }else{
  890. player.focusPoint({aim: hot.position, radius:hot.position.distanceTo(player.position)})
  891. }
  892. } catch (e) {}
  893. if(this.editSpot == hot)return
  894. this.hotpointDetail.removeClass("atRight");
  895. $("#hotpointDetail .audio.mediaUpload").find("input").val('');
  896. var playIcon = 'images/play.png';
  897. this.editSpot = hot
  898. transformControls.transformMenuOptions.updateChoseAtUI({name:'translate'}) //$(".MenuOptions[name='transform'] li[index='translate']").click()//transformControls.transCtlChangeMode("translate")
  899. this.getTempInfo(hot)
  900. hot.visible = true
  901. this.updatePano()
  902. this.updateListSelect(hot);
  903. //$("#isSprite")[0].checked = this.editSpot.info.isSprite
  904. this.isSpriteCheckBox.updateChoseAtUI(this.editSpot.info.isSprite)
  905. this.linkTypeMenuOptions.updateChoseAtUI({name:this.editSpot.info.linkType})
  906. this.updateClickEventUI();//根据actionType更新ui
  907. var iframesHTML = hot.info.iframe.map(function(iframe) {
  908. return this.inputList("请填写网页链接", iframe)
  909. }.bind(this))
  910. var modulesHTML = hot.info.model.map(function(module) {
  911. return this.inputList("请填写网页链接", module)
  912. }.bind(this))
  913. var imagesHTML = hot.info.images.map(function(image) {
  914. return '<div class="mediaItem" draggable="true" ><a class=" result success" data-type="photo"><span></span><img src="' + image + '" class="bg"></a></div>'
  915. })
  916. var videosHTML = hot.info.video.map(function(ly) {
  917. var thumb = (!ly.img || ly.img === "undefined") ? '' : '<img src='+ ly.img +' class="bg"></img>'
  918. var thumbResult = (!ly.img || ly.img === "undefined") ? '' : 'success';
  919. var dom = '<div class="mediaItem" draggable="true"><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>'
  920. return dom
  921. })
  922. this.hotpointDetail.find(".name > input").val(hot.info.title);
  923. this.hotpointDetail.find(".editText").val(hot.info.content);
  924. this.hotpointDetail.find("[name=photo] .list").html(imagesHTML);
  925. this.hotpointDetail.find("[name=video] .list").html(videosHTML);
  926. this.hotpointDetail.find("[name=modelSrc] .list").html(modulesHTML);
  927. this.hotpointDetail.find("[name=webPage] .list").html(iframesHTML);
  928. let bgName = hot.info.bgName || '热点背景音乐';
  929. if (hot.info.backgroundMusic) {
  930. this.musicBox.show(/* this.hotpointDetail.find(".audio.mediaUpload"), */bgName, hot.info.backgroundMusic)
  931. } else {
  932. this.musicBox.hide()
  933. }
  934. }
  935. Hotpoint.prototype.recoverInfo = function(hot) { // 恢復
  936. hot.info = hot.tempInfo;
  937. hot.setFromInfo(hot.info, hot.tempInfo.media, hot.tempInfo.objObject)
  938. delete hot.info.media
  939. delete hot.info.objObject
  940. }
  941. Hotpoint.prototype.getTempInfo = function(hot) { // 编辑前, 从当前状态获取info, 用於恢復
  942. var plane = hot.plane;
  943. var info = hot.info;
  944. hot.tempInfo = CloneObject(info);
  945. hot.tempInfo.media = hot.texMedia
  946. hot.tempInfo.objObject = hot.objObject
  947. this.getTempInfos()
  948. }
  949. Hotpoint.prototype.getTempInfos = function(){
  950. if(Hot.allPhotoLoaded && Hot.allModelLoaded){
  951. this.tempInfos = {}
  952. player.model.hotGroup.children.forEach(hot=>{
  953. this.tempInfos[hot.sid] = {
  954. styleImg : hot.styleImg,
  955. texMedia : hot.texMedia,
  956. objObject : hot.objObject,
  957. scale : hot.scale.clone()
  958. }
  959. })
  960. }
  961. }
  962. Hotpoint.prototype.getTransformAtPano = function(type){
  963. /* var name = getTransformSid()
  964. var info = {
  965. pos : this.editSpot.mesh.position.clone()
  966. }
  967. if(!this.editSpot.isSprite){
  968. info.qua = this.editSpot.mesh.quaternion.clone()
  969. }else{
  970. if(type == 'quaternion')return; //如果恒朝向相机且调整的是quaternion,不要保存position
  971. }
  972. this.editSpot.transformAtPanos[name] = info */
  973. //this.editSpot.usingTransformData = true
  974. var name = getTransformSid()
  975. this.editSpot.info.transformAtPanos[name] = {
  976. pos : this.editSpot.position.clone()
  977. }
  978. }
  979. Hotpoint.prototype.updateTransform = function(type){
  980. var on = this.panoTransformCheckBox.checked() //$('#setPosForPano input').is(':checked')
  981. //var name = getTransformSid()
  982. if(on && type == 'position'){
  983. this.getTransformAtPano(type)
  984. }else{
  985. if(type == 'position'){
  986. this.editSpot.info.position.copy(this.editSpot.position)
  987. }else if(type == 'quaternion'){
  988. if(!this.editSpot.isSprite){ //如果恒朝向相机就不保存quaternion
  989. this.editSpot.info.rotation.copy(this.editSpot.rotation)
  990. }
  991. }else if(type == 'scale'){
  992. this.editSpot.info.scale.copy(this.editSpot.scale)
  993. }
  994. }
  995. }
  996. Hotpoint.prototype.updatePano = function(){
  997. if(!this.editSpot ) return;
  998. //$('#setPosForPano input').prop('checked', !!this.editSpot.info.transformAtPanos[getTransformSid()]);
  999. this.panoTransformCheckBox.updateChoseAtUI(!!this.editSpot.info.transformAtPanos[getTransformSid()])
  1000. }
  1001. var ifSameTex = function(imgs0, imgs1){//是否是相同的图 (两个都是空的不算相同)
  1002. return !!(imgs0[0] && imgs1[0] && imgs0[0].src == imgs1[0].src &&
  1003. (imgs0[1] ? (imgs1[1] && imgs0[1].src == imgs1[1].src) : !imgs1[1] ))
  1004. }
  1005. Hotpoint.prototype.findSpotByContent = (media, type)=>{////使用了该贴图的所有热点
  1006. var spots = []
  1007. if(type == 'shine'){
  1008. media = media || []
  1009. for(var i in player.model.hots){
  1010. if(player.model.hots[i].texType != type)continue
  1011. var styleImg = player.model.hots[i].styleImg || [];
  1012. if(ifSameTex(styleImg, media)){
  1013. spots.push(player.model.hots[i])
  1014. }
  1015. }
  1016. }else if(type == 'photo' || type == 'video'){
  1017. if(type == 'photo' && !Hot.allPhotoLoaded)return spots
  1018. for(var i in player.model.hots){
  1019. if(player.model.hots[i].texType != type)continue
  1020. var texMedia = player.model.hots[i].texMedia
  1021. if(media && texMedia && media.src == texMedia.src){
  1022. spots.push(player.model.hots[i])
  1023. }
  1024. }
  1025. }else if(type == 'model'){
  1026. if(!Hot.allModelLoaded)return spots
  1027. for(var i in player.model.hots){
  1028. if(!player.model.hots[i].objObject)continue
  1029. var objObject = player.model.hots[i].objObject
  1030. if(media && objObject && media.src == objObject.src){
  1031. spots.push(player.model.hots[i])
  1032. }
  1033. }
  1034. }
  1035. return spots
  1036. }
  1037. Hotpoint.prototype.initListSelect = function(){//热点样式图列表
  1038. var that = this;
  1039. var countElem = $("<a class='showCount'></a>")
  1040. var uploadInputImage = $('<input type="file" style="display:none" accept="image/*"></input>');
  1041. var uploadInputVideo = $('<input type="file" style="display:none" accept="video/*"></input>');
  1042. var uploadInputModel = $('<input type="file" style="display:none" accept=".obj,.OBJ"></input>');
  1043. var getListItem = ()=>{
  1044. 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>')
  1045. elem[0]._styleImg = []
  1046. return elem
  1047. }
  1048. var editItemInfo = {}
  1049. var setImgContent = function($dom, index, src) {
  1050. var li = $dom.find('li').eq(index)
  1051. var div = li.find('>div');
  1052. if (src) {
  1053. li.addClass("uploaded")
  1054. div.css("background-image", `url(${src})`)
  1055. } else {
  1056. li.removeClass("uploaded")
  1057. div.css("background-image", '')
  1058. }
  1059. }
  1060. var hotIcons = []; // 从所有热点tex中搜集 。
  1061. player.model.hotGroup.children.forEach(e=>{// 从所有热点tex中搜集
  1062. if(e.texType == 'shine'){
  1063. let imgs = e.info.styleImg;
  1064. if(imgs && imgs.length){
  1065. if(!hotIcons.find(e=>e[0] == imgs[0] && e[1] == imgs[1])){
  1066. hotIcons.push(imgs)
  1067. }
  1068. }
  1069. }
  1070. })
  1071. hotIcons = hotIcons.map(imgs=>imgs = imgs.map((a)=>{return {src:a}}))
  1072. //hotIcons = [[], [g_HotImage.point, g_HotImage.point2], ...hotIcons]
  1073. hotIcons.push([{src:g_HotImage.point}, {src:g_HotImage.point2}],[] )//放末尾用来添加的 g_HotImage是默认
  1074. var list = hotIcons.map(arr=>{//初始列表
  1075. var elem = getListItem()
  1076. elem[0]._styleImg = arr //每个li上绑定一个 _styleImg,存储它包含的图, 和热点的styleImg对应
  1077. var divs = elem.find("li>div")
  1078. arr.forEach((img,i)=>{
  1079. setImgContent(elem, i, img.src)
  1080. })
  1081. arr.length && elem.find("li").eq(1).removeClass('hide')
  1082. return elem
  1083. })
  1084. list[list.length - 2].addClass('forbitEdit')
  1085. this.styleList = new ListBox(list, $('#shineTexSelect'), {//列表
  1086. selectFun:(o={})=>{//选中时要改变选中项selection缩略图 以及改变热点
  1087. if(this.styleList.chosenItem == void 0){
  1088. this.styleList.listTitle.find('li').addClass('hide')
  1089. }else{
  1090. this.styleList.listTitle.find('li').removeClass('hide')
  1091. var divs = this.styleList.listTitle.find('li>div')//selection
  1092. var imgs = this.styleList.chosenItem[0]._styleImg;
  1093. if(imgs[0]){
  1094. divs.eq(0).css("background-image", 'url("'+imgs[0].src+'")')
  1095. divs.eq(0).parent().removeClass('hide')
  1096. }else{
  1097. divs.eq(0).parent().addClass('hide')
  1098. }
  1099. if(imgs[1]){
  1100. divs.eq(1).css("background-image", 'url("'+imgs[1].src+'")')
  1101. divs.eq(1).parent().removeClass('hide')
  1102. }else{
  1103. divs.eq(1).parent().addClass('hide')
  1104. }
  1105. //应用到热点:
  1106. o.dontApplyToHot || this.editSpot.changeShineTex(imgs)
  1107. }
  1108. Array.from(this.styleList.listDom.children()).forEach(li=>{//更新一下所有的li的使用的spot
  1109. li.sameContentSpots = this.findSpotByContent(li._styleImg, 'shine')
  1110. })
  1111. },
  1112. /* delFun: ()=>{
  1113. }, */
  1114. addFun: ($li)=>{ //列表新增时对li的操作
  1115. $li[0].sameContentSpots = this.findSpotByContent($li[0]._styleImg, 'shine')
  1116. $li.find('li').bind('click', (e)=>{
  1117. e.stopPropagation()
  1118. var index = $(e.currentTarget).index();
  1119. if($li.hasClass('forbitEdit'))return
  1120. if (e.target.classList.contains("del")) { //删除图片
  1121. if ($li[0]._styleImg.length == 2 && index == 0) { //删除第一个 且有第二个的话
  1122. setImgContent($li, 0, $li[0]._styleImg[1].src);
  1123. setImgContent($li, 1, null);
  1124. $li[0]._styleImg = [$li[0]._styleImg[1]]
  1125. } else {
  1126. setImgContent($li, index, null);
  1127. $li[0]._styleImg.pop()
  1128. if ($li[0]._styleImg.length == 0) {
  1129. //$li.find("li").eq(1).addClass("hide");
  1130. this.styleList.removeItem($li)
  1131. }
  1132. }
  1133. $li[0].sameContentSpots.forEach(hot=>{
  1134. hot.changeShineTex($li[0]._styleImg)
  1135. })
  1136. if($li.hasClass('selected')){//是当前spot的
  1137. //this.editSpot.changeTex($li[0]._styleImg)
  1138. this.styleList.options.selectFun()
  1139. }
  1140. } else {
  1141. //添加图片
  1142. uploadInputImage.click()
  1143. editItemInfo = {
  1144. imgs : $li[0]._styleImg, index, $li , type:"shine"
  1145. };
  1146. }
  1147. })
  1148. $li.bind('mouseover', (e)=>{
  1149. /* this.showTitileSpots = $li[0].sameContentSpots;
  1150. this.showTitileSpots.forEach(a=>a.showTitle()) */
  1151. countElem.text("热点个数:"+$li[0].sameContentSpots.length).removeClass('hide')
  1152. $li.append(countElem)
  1153. $li[0].sameContentSpots.forEach(hot=>{
  1154. hot.changeBoxHelperDisplay(true)
  1155. })
  1156. })
  1157. $li.bind('mouseout', (e)=>{
  1158. /* this.showTitileSpots.forEach(a=>a.hideTitle())
  1159. this.showTitileSpots = null; */
  1160. countElem.addClass('hide')
  1161. $li[0].sameContentSpots.forEach(hot=>{
  1162. hot.changeBoxHelperDisplay(false)
  1163. })
  1164. })
  1165. },
  1166. saveTemp: (list)=>{//编辑热点时保存一份副本
  1167. list._styleImgTemp = Array.from(list.listDom.children()).map((li)=>{
  1168. return li._styleImg.slice()
  1169. })
  1170. },
  1171. recover : (list)=>{//取消编辑时恢复
  1172. Array.from(list.listDom.children()).forEach((li,i)=>{
  1173. li._styleImg = list._styleImgTemp[i]
  1174. li.sameContentSpots = this.findSpotByContent(li._styleImg, 'shine')
  1175. })
  1176. },
  1177. })
  1178. this.styleList.findChosenByContent = (imgs=[])=>{//找到某图对应的li
  1179. var list = Array.from(this.styleList.listDom.children())
  1180. var item = list.find(e=>ifSameTex(e._styleImg, imgs ))
  1181. return {index: item ? list.indexOf(item) : null, item: item }
  1182. }
  1183. /* this.styleList.clearVoid = ()=>{//清理空的
  1184. var length = this.styleList.listDom.children().length;
  1185. Array.from(this.styleList.listDom.children()).forEach((e, i)=>{
  1186. if(i > 0 ){
  1187. if(e._styleImg.length == 0) this.styleList.removeItem($(e))
  1188. }
  1189. })
  1190. } */
  1191. this.styleList.addNew = ()=>{//看是否在第一行增加新的
  1192. /* var lastOne = this.styleList.listDom.children().last();
  1193. if(lastOne[0]._styleImg.length != 0){
  1194. this.styleList.addItem(getListItem())
  1195. } */
  1196. let firstOne = this.styleList.listDom.children().first();
  1197. if(firstOne[0]._styleImg.length != 0){
  1198. this.styleList.addItem(getListItem())
  1199. }
  1200. }
  1201. //-----photo----video-----------------------
  1202. var getPhotoListItem = ()=>{
  1203. var elem = $('<li><div class="upload"><div></div><a class="del hasHover"></a></div></li>')
  1204. return elem
  1205. }
  1206. var getVideoListItem = ()=>{
  1207. var elem = $('<li><div class="upload"><div></div><a class="del hasHover"></a></div></li>')
  1208. return elem
  1209. }
  1210. var photos = [] ,videos = []
  1211. var photoList = [], videoList = []
  1212. player.model.hotGroup.children.forEach(hot=>{
  1213. if(hot.texType == 'photo'){
  1214. var media = hot.texMedia
  1215. if(!photos.find(u=>media == u)){
  1216. photos.push(media)
  1217. var elem = getPhotoListItem()
  1218. elem[0]._media = media
  1219. elem[0].animateInfo = CloneObject(hot.info.animateInfo)
  1220. elem.find(".upload>div").css("background-image", "url(" + hot.info.texSrc + ")")
  1221. elem.find(".upload").addClass("uploaded")
  1222. photoList.push(elem)
  1223. }
  1224. }else if(hot.texType == 'video'){
  1225. var media = hot.texMedia
  1226. if(!videos.find(u=>media == u)){
  1227. videos.push(media)
  1228. var elem = getVideoListItem()
  1229. elem[0]._media = media
  1230. elem.attr("title", media.name)
  1231. elem.find(".upload>div").text(media.name)
  1232. elem.find(".upload").addClass("uploaded")
  1233. videoList.push(elem)
  1234. }
  1235. }
  1236. })
  1237. photoList.push(getPhotoListItem())//放末尾用来添加的
  1238. this.photoList = new ListBox(photoList, $('#photoTexSelect'), {//列表
  1239. selectFun:(o={})=>{//选中时要改变选中项selection缩略图 以及改变热点
  1240. var div = this.photoList.listTitle.find('.uploaded')//selection
  1241. var media;
  1242. if(this.photoList.chosenItem){
  1243. media = this.photoList.chosenItem[0]._media;
  1244. }
  1245. if(media){
  1246. div.removeClass('hide')
  1247. div.css("background-image", 'url("'+media.src+'")')
  1248. //应用到热点:
  1249. if(!o.dontApplyToHot){
  1250. this.editSpot.changeTexType("photo", media || 'clear' )
  1251. this.updateGifPanel({animateInfo: this.photoList.chosenItem[0].animateInfo })
  1252. this.useSuitableRatio()
  1253. }else{
  1254. this.updateGifPanel({on: !!this.photoList.chosenItem[0].animateInfo })
  1255. }
  1256. $('#gifEdit').removeClass('hide');
  1257. }else{
  1258. !o.dontApplyToHot && this.editSpot.changeTexType("photo", 'clear' )
  1259. this.updateGifPanel({on:false})
  1260. $('#gifEdit').addClass('hide');
  1261. div.addClass('hide')
  1262. }
  1263. Array.from(this.photoList.listDom.children()).forEach(li=>{//更新一下所有的li的使用的spot
  1264. li.sameContentSpots = this.findSpotByContent(li._media, 'photo')
  1265. })
  1266. },
  1267. addFun: ($li)=>{ //photoList列表新增时对li的操作
  1268. $li[0].sameContentSpots = this.findSpotByContent($li[0]._media, 'photo')
  1269. $li.find('.upload').bind('click', (e)=>{
  1270. e.stopPropagation()
  1271. var index = $(e.currentTarget).index();
  1272. if (e.target.classList.contains("del")) { //删除图片
  1273. /* if($li.hasClass('selected')){//(肯定)是当前spot的
  1274. that.editSpot.changeTexType('photo', 'clear')
  1275. }
  1276. $li[0]._media = null */
  1277. this.photoList.removeItem($li)
  1278. } else {
  1279. //添加图片
  1280. uploadInputImage.click()
  1281. editItemInfo = {
  1282. $li , type:"photo"
  1283. };
  1284. }
  1285. })
  1286. $li.bind('mouseover', (e)=>{
  1287. /* this.showTitileSpots = $li[0].sameContentSpots;
  1288. this.showTitileSpots.forEach(a=>a.showTitle()) */
  1289. countElem.text("热点个数:"+$li[0].sameContentSpots.length).removeClass('hide')
  1290. $li.append(countElem)
  1291. $li[0].sameContentSpots.forEach(hot=>{
  1292. hot.changeBoxHelperDisplay(true)
  1293. })
  1294. })
  1295. $li.bind('mouseout', (e)=>{
  1296. /* this.showTitileSpots.forEach(a=>a.hideTitle())
  1297. this.showTitileSpots = null; */
  1298. countElem.addClass('hide')
  1299. $li[0].sameContentSpots.forEach(hot=>{
  1300. hot.changeBoxHelperDisplay(false)
  1301. })
  1302. })
  1303. },
  1304. saveTemp: (list)=>{//编辑热点时保存一份副本
  1305. list._mediaTemp = Array.from(list.listDom.children()).map((li)=>{
  1306. return li._media
  1307. })
  1308. list._animationTemp = Array.from(list.listDom.children()).map((li)=>{
  1309. return li.animateInfo
  1310. })
  1311. },
  1312. recover : (list)=>{//取消编辑时恢复
  1313. Array.from(list.listDom.children()).forEach((li,i)=>{
  1314. li._media = list._mediaTemp[i]
  1315. li.animateInfo = list._animationTemp[i]
  1316. li.sameContentSpots = this.findSpotByContent(li._media, 'photo')
  1317. })
  1318. },
  1319. })
  1320. this.photoList.addNew = ()=>{//看是否在第一行增加新的
  1321. let firstOne = this.photoList.listDom.children().first();
  1322. if(firstOne[0]._media){
  1323. this.photoList.addItem(getPhotoListItem())
  1324. }
  1325. }
  1326. //---videoList-------
  1327. videoList.push(getVideoListItem())//放末尾用来添加的
  1328. this.videoList = new ListBox(videoList, $('#videoTexSelect'), {//列表
  1329. selectFun:(o={})=>{
  1330. var div = this.videoList.listTitle//selection
  1331. var media;
  1332. if(this.videoList.chosenItem){
  1333. media = this.videoList.chosenItem[0]._media;
  1334. }
  1335. if(media){
  1336. //div.removeClass('hide')
  1337. div.text(media ? media.name : '')
  1338. //应用到热点:
  1339. this.editSpot.info.texSrc = media && media.src //视频不能共用一个,否则会一起播放暂停
  1340. this.editSpot.info.fileName = media.name
  1341. this.editSpot.videoWidth = media.videoWidth //记录。因为新new的话要等一会儿才不为0
  1342. this.editSpot.videoHeight = media.videoHeight
  1343. //media.currentTime = 0 //触发oncanplaythrough
  1344. if(!o.dontApplyToHot){
  1345. this.editSpot.changeTexType("video" , media ? null : 'clear' )
  1346. this.useSuitableRatio()
  1347. }
  1348. }else{
  1349. //div.addClass('hide')
  1350. div.text('')
  1351. if(!o.dontApplyToHot){
  1352. this.editSpot.changeTexType("video" , 'clear' )
  1353. }
  1354. }
  1355. Array.from(this.videoList.listDom.children()).forEach(li=>{//更新一下所有的li的使用的spot
  1356. li.sameContentSpots = this.findSpotByContent(li._media, 'video')
  1357. })
  1358. },
  1359. addFun: ($li)=>{
  1360. $li[0].sameContentSpots = this.findSpotByContent($li[0]._media, 'video')
  1361. $li.find('.upload').bind('click', (e)=>{
  1362. e.stopPropagation()
  1363. var index = $(e.currentTarget).index();
  1364. if (e.target.classList.contains("del")) { //删除
  1365. if($li.hasClass('selected')){//是当前spot的
  1366. that.editSpot.changeTexType('video', 'clear')
  1367. }
  1368. $li[0]._media = null
  1369. this.videoList.removeItem($li)
  1370. } else {
  1371. //添加
  1372. uploadInputVideo.click()
  1373. editItemInfo = {
  1374. $li , type:"video"
  1375. };
  1376. }
  1377. })
  1378. $li.bind('mouseover', (e)=>{
  1379. /* this.showTitileSpots = $li[0].sameContentSpots;
  1380. this.showTitileSpots.forEach(a=>a.showTitle()) */
  1381. countElem.text("热点个数:"+$li[0].sameContentSpots.length).removeClass('hide')
  1382. $li.append(countElem)
  1383. $li[0].sameContentSpots.forEach(hot=>{
  1384. hot.changeBoxHelperDisplay(true)
  1385. })
  1386. })
  1387. $li.bind('mouseout', (e)=>{
  1388. /* this.showTitileSpots.forEach(a=>a.hideTitle())
  1389. this.showTitileSpots = null; */
  1390. countElem.addClass('hide')
  1391. $li[0].sameContentSpots.forEach(hot=>{
  1392. hot.changeBoxHelperDisplay(false)
  1393. })
  1394. })
  1395. },
  1396. saveTemp: (list)=>{//编辑热点时保存一份副本
  1397. list._mediaTemp = Array.from(list.listDom.children()).map((li)=>{
  1398. return li._media
  1399. })
  1400. },
  1401. recover : (list)=>{//取消编辑时恢复
  1402. Array.from(list.listDom.children()).forEach((li,i)=>{
  1403. li._media = list._mediaTemp[i]
  1404. li.sameContentSpots = this.findSpotByContent(li._media, 'video')
  1405. })
  1406. },
  1407. })
  1408. this.videoList.addNew = ()=>{//看是否在第一行增加新的
  1409. let firstOne = this.videoList.listDom.children().first();
  1410. if(firstOne[0]._media){
  1411. this.videoList.addItem(getVideoListItem())
  1412. }
  1413. }
  1414. this.photoList.findChosenByContent = this.videoList.findChosenByContent = (list_, media)=>{//找到某图对应的li
  1415. var list = Array.from(list_.listDom.children())
  1416. var item = list.find(e=>e._media && media && e._media.src == media.src)
  1417. return {index: item ? list.indexOf(item) : null, item: item }
  1418. }
  1419. /* this.photoList.clearVoid = this.videoList.clearVoid = (list_)=>{//清理空的
  1420. var length = list_.listDom.children().length;
  1421. Array.from(list_.listDom.children()).forEach((e, i)=>{
  1422. if(i > 0 ){
  1423. if(!e._media ) list_.removeItem($(e))
  1424. }
  1425. })
  1426. } */
  1427. //----modelList---------------------
  1428. var objSrcs = []
  1429. var modelList = []
  1430. var getModelListItem = ()=>{
  1431. var elem = $('<li><div class="upload"><div></div><a class="del hasHover"></a></div></li>')
  1432. return elem
  1433. }
  1434. player.model.hotGroup.children.forEach(e=>{
  1435. if(e.info.objSrc && !objSrcs.find(u=>e.info.objSrc == u)){
  1436. objSrcs.push(e.info.objSrc)
  1437. var elem = getModelListItem()
  1438. elem[0].objObject = e.objObject
  1439. elem.attr("title", e.info.objName)
  1440. elem.find(".upload>div").text(e.info.objName)
  1441. elem.find(".upload").addClass("uploaded")
  1442. modelList.push(elem)
  1443. }
  1444. })
  1445. modelList.push(getModelListItem())//放末尾用来添加的
  1446. this.modelList = new ListBox(modelList, $('#ObjSelect'), {//列表
  1447. selectFun:(o={})=>{
  1448. var div = this.modelList.listTitle//selection
  1449. var model;
  1450. if(this.modelList.chosenItem){
  1451. model = this.modelList.chosenItem[0].objObject;
  1452. }
  1453. if(model){
  1454. //div.removeClass('hide')
  1455. div.text(model ? model.name : '')
  1456. //应用到热点:
  1457. if(!o.dontApplyToHot){
  1458. this.switchModel({add:model,spot:this.editSpot})
  1459. }
  1460. }else{
  1461. //div.addClass('hide')
  1462. div.text('')
  1463. this.switchModel({remove:true,spot:this.editSpot})
  1464. }
  1465. Array.from(this.modelList.listDom.children()).forEach(li=>{//更新一下所有的li的使用的spot
  1466. li.sameContentSpots = this.findSpotByContent(li.objObject, 'model')
  1467. })
  1468. },
  1469. addFun: ($li)=>{
  1470. $li[0].sameContentSpots = this.findSpotByContent($li[0].objObject, 'model')
  1471. $li.find('.upload').bind('click', (e)=>{
  1472. e.stopPropagation()
  1473. var index = $(e.currentTarget).index();
  1474. if (e.target.classList.contains("del")) { //删除
  1475. $li[0].sameContentSpots.forEach(e=>{
  1476. /* e.removeModel() */
  1477. that.switchModel({remove:true, spot:e})
  1478. })
  1479. if($li.hasClass('selected')){//是当前spot的 ui..
  1480. }
  1481. $li[0].objObject = null
  1482. this.modelList.removeItem($li)
  1483. } else {
  1484. //添加
  1485. uploadInputModel.click()
  1486. editItemInfo = {
  1487. $li , type:"model"
  1488. };
  1489. }
  1490. })
  1491. $li.bind('mouseover', (e)=>{
  1492. /* this.showTitileSpots = $li[0].sameContentSpots;
  1493. this.showTitileSpots.forEach(a=>a.showTitle()) */
  1494. countElem.text("热点个数:"+$li[0].sameContentSpots.length).removeClass('hide')
  1495. $li.append(countElem)
  1496. $li[0].sameContentSpots.forEach(hot=>{
  1497. hot.changeBoxHelperDisplay(true)
  1498. })
  1499. })
  1500. $li.bind('mouseout', (e)=>{
  1501. /* this.showTitileSpots.forEach(a=>a.hideTitle())
  1502. this.showTitileSpots = null; */
  1503. countElem.addClass('hide')
  1504. $li[0].sameContentSpots.forEach(hot=>{
  1505. hot.changeBoxHelperDisplay(false)
  1506. })
  1507. })
  1508. },
  1509. saveTemp: (list)=>{//编辑热点时保存一份副本
  1510. list._objTemp = Array.from(list.listDom.children()).map((li)=>{
  1511. return li.objObject
  1512. })
  1513. },
  1514. recover : (list)=>{//取消编辑时恢复
  1515. Array.from(list.listDom.children()).forEach((li,i)=>{
  1516. li.objObject = list._objTemp[i];
  1517. li.sameContentSpots = this.findSpotByContent(li.objObject, 'model')
  1518. })
  1519. },
  1520. })
  1521. this.modelList.addNew = ()=>{//看是否在第一行增加新的
  1522. let firstOne = this.modelList.listDom.children().first();
  1523. if(firstOne[0].objObject){
  1524. this.modelList.addItem(getModelListItem())
  1525. }
  1526. }
  1527. this.modelList.findChosenByContent = (objObject)=>{
  1528. var list = Array.from(this.modelList.listDom.children())
  1529. var item = list.find(e=>e.objObject && e.objObject.src == objObject.src)
  1530. return {index: item ? list.indexOf(item) : null, item: item }
  1531. }
  1532. this.photoList.updateDelBtns = this.videoList.updateDelBtns = (list_)=>{//每次开始编辑热点时更新删除按钮可见性
  1533. Array.from(list_.listDom.children()).forEach(li=>{
  1534. //li.sameContentSpots = this.findSpotByContent(li._media, 'photo')
  1535. if(li.sameContentSpots.find(e=>e!=this.editSpot)){
  1536. $(li).addClass('cannotDelete')
  1537. }else{
  1538. $(li).removeClass('cannotDelete')
  1539. }
  1540. })
  1541. }
  1542. //-----------------------------------
  1543. uploadInputImage.on("change", (e)=>{
  1544. inputMedia({
  1545. enableTypes: ["photo"],
  1546. photoDone: (resultImg)=>{
  1547. if(editItemInfo.type == 'shine'){
  1548. editItemInfo.imgs[editItemInfo.index] = resultImg //{file: resultImg.file, needSave:true, src:resultImg.src}//resultImg
  1549. setImgContent(editItemInfo.$li, editItemInfo.index, resultImg.src)
  1550. if (editItemInfo.index == 0){
  1551. editItemInfo.$li.find('li').eq(1).removeClass("hide");
  1552. }
  1553. resultImg.needSave = true
  1554. editItemInfo.$li[0].sameContentSpots.forEach(hot=>{
  1555. hot.changeShineTex(editItemInfo.$li[0]._styleImg)
  1556. })
  1557. }else{//"photo"
  1558. editItemInfo.$li.find(".upload").addClass("uploaded")
  1559. editItemInfo.$li.find(".upload div").css("background-image", `url(${resultImg.src})`)
  1560. editItemInfo.$li[0]._media = resultImg
  1561. editItemInfo.$li[0].sameContentSpots.forEach(hot=>{
  1562. hot.changeTexType("photo",resultImg)
  1563. })
  1564. resultImg.needSave = true
  1565. }
  1566. /* if(editItemInfo.$li.hasClass('selected')){//是当前spot的
  1567. this.texLists[editItemInfo.type].options.selectFun({dontApplyToHot:true})//更新选中状态
  1568. } */
  1569. this.texLists[editItemInfo.type].addNew()
  1570. this.texLists[editItemInfo.type].selectFromOutSide(editItemInfo.$li.index())
  1571. this.texLists[editItemInfo.type].listDom.addClass('hide')
  1572. }
  1573. }, "photo", e);
  1574. })
  1575. uploadInputVideo.on("change", (e)=>{
  1576. inputMedia({
  1577. enableTypes: ["video"],
  1578. videoDone: (file,video)=>{
  1579. editItemInfo.$li.find(".upload").addClass("uploaded")
  1580. editItemInfo.$li.find(".upload>div").text(file.name)
  1581. editItemInfo.$li.attr("title", file.name)
  1582. video.file = file
  1583. video.name = file.name
  1584. video.needSave = true
  1585. editItemInfo.$li[0]._media = video
  1586. editItemInfo.$li[0].sameContentSpots.forEach(hot=>{
  1587. hot.info.texSrc = video.src //视频不能共用一个,否则会一起播放暂停
  1588. hot.info.fileName = video.name
  1589. hot.videoWidth = video.videoWidth //记录。因为新new的话要等一会儿才不为0
  1590. hot.videoHeight = video.videoHeight
  1591. hot.changeTexType("video" )
  1592. })
  1593. /* if(editItemInfo.$li.hasClass('selected')){//是当前spot的
  1594. this.videoList.options.selectFun({dontApplyToHot:true})//更新选中状态
  1595. } */
  1596. this.videoList.addNew()
  1597. this.videoList.selectFromOutSide(editItemInfo.$li.index())
  1598. }
  1599. }, "video", e);
  1600. })
  1601. uploadInputModel.on("change", (e)=>{
  1602. inputMedia({
  1603. enableTypes: ["model"],
  1604. modelDone: (file,object)=>{
  1605. editItemInfo.$li.find(".upload").addClass("uploaded")
  1606. editItemInfo.$li.find(".upload>div").text(file.name)
  1607. editItemInfo.$li.attr("title", file.name)
  1608. object.file = file
  1609. object.name = file.name
  1610. object.src = object.uuid;//作为标识而已
  1611. object.needSave = true
  1612. {//adjustModelAuto
  1613. let bound = new THREE.Box3
  1614. object.traverse( function ( child ) {
  1615. if(child.geometry){
  1616. child.geometry.computeBoundingBox();
  1617. bound.union(child.geometry.boundingBox)
  1618. }
  1619. });
  1620. let standard = 1;
  1621. let size = bound.max.distanceTo(bound.min);
  1622. let s = standard / size
  1623. object.scale.set(s,s,s)
  1624. let center = bound.center()
  1625. object.position.copy(center).negate().multiplyScalar(s)//保证模型的中心点和hot中心点重合
  1626. object.modelBound = {
  1627. bound,
  1628. scaleRatio : s,
  1629. position: object.position.toArray()
  1630. }
  1631. }
  1632. editItemInfo.$li[0].objObject = object
  1633. editItemInfo.$li[0].sameContentSpots.forEach(hot=>{
  1634. //hot.addModel(object)
  1635. this.switchModel({add:object, spot:hot})
  1636. })
  1637. this.modelList.selectFromOutSide(editItemInfo.$li.index())
  1638. /* if(editItemInfo.$li.hasClass('selected')){//是当前spot的
  1639. this.modelList.options.selectFun({dontApplyToHot:true})//更新选中状态
  1640. } */
  1641. this.modelList.addNew()
  1642. }
  1643. }, "model", e);
  1644. })
  1645. this.texLists = {shine: this.styleList, photo:this.photoList, video: this.videoList}
  1646. this.texTypeMenuOptions = new MenuOptions({
  1647. dom: this.hotpointDetail.find(" li[name=style] .MenuOptions"),
  1648. uiCallBack : (o)=>{
  1649. var name = o.name || o.$li.attr('index')
  1650. for(let i in this.texLists){ this.texLists[i].listDom.parent().addClass("hide")}
  1651. this.texLists[name].listDom.parent().removeClass("hide")
  1652. if(name == 'photo'){
  1653. $('#gifEdit').removeClass('hide')
  1654. }else{
  1655. $('#gifEdit').addClass('hide')
  1656. this.updateGifPanel({on:false})
  1657. }
  1658. },
  1659. callbackWhenChose:(o)=>{
  1660. this.changeType( o.$li.attr('index'))
  1661. }
  1662. })
  1663. //编辑开放
  1664. this.hotpointDetail.find(" li[name=style]").removeClass('unable');
  1665. this.hotpointDetail.find(" li[name=model]").removeClass('unable');
  1666. this.hotpointDetail.find(" li[name=style] .itemTitle").attr('data-size','')
  1667. if(this.editSpot){//已经在编辑了,初始化下
  1668. this.updateListSelect(this.editSpot)
  1669. this.getTempInfos()
  1670. }
  1671. this.hotpointDetail.find(" li[name=setPos] button[name=setSpace] ").on('click',(e)=>{
  1672. var space = transformControls.space == 'world'?'local':'world'
  1673. transformControls.setSpace(space)
  1674. e.target.innerText = space == 'world'?'切换为世界坐标方向':'切换为本地坐标方向'
  1675. })
  1676. this.hotpointDetail.find(" li[name=setPos] button[name=useSuitableRatio] ").on('click',()=>{
  1677. this.useSuitableRatio()
  1678. })
  1679. this.hotpointDetail.find(" li[name=setPos] button[name=resetRot] ").on('click',()=>{
  1680. this.editSpot.rotation.x = 0
  1681. this.editSpot.rotation.z = 0
  1682. })
  1683. }
  1684. Hotpoint.prototype.switchModel = function(o={}){
  1685. if(o.add){
  1686. var model = o.add.clone();
  1687. o.spot.info.objSrc = o.add.src
  1688. o.spot.info.objName = o.add.name
  1689. o.spot.info.modelBound = o.add.modelBound;
  1690. o.spot.addModel(model)
  1691. var s = 1;//暂时
  1692. o.spot.scale.set(s,s,s)//恢复成等大比例,方便用户看清原始比例
  1693. o.spot.info.scale.set(s,s,s)
  1694. //this.updateTransform('scale')
  1695. if(o.spot == this.editSpot){
  1696. transformControls.enableScaleZ()
  1697. }
  1698. }else if(o.remove){
  1699. //如果没有出现plane,很可能是因为背面朝向镜头了!
  1700. o.spot.addPlane()
  1701. if(o.spot == this.editSpot) transformControls.unableScaleZ()
  1702. }
  1703. }
  1704. Hotpoint.prototype.changeType = function(type){
  1705. var hot = this.editSpot
  1706. var list
  1707. this._scale[hot.texType] = hot.scale.clone()
  1708. if(type == 'shine'){
  1709. hot.changeTexType(type, 'clear')
  1710. if(hot.styleImg){
  1711. hot.changeTexType(type, hot.styleImg )
  1712. }
  1713. list = this.styleList
  1714. list.selectFromOutSide(list.chosenIndex || 1)//触发选择函数
  1715. }else{
  1716. hot.changeTexType(type,'clear')
  1717. if(type == 'photo'){
  1718. list = this.photoList
  1719. }else{
  1720. list = this.videoList
  1721. }
  1722. list.selectFromOutSide(list.chosenIndex)
  1723. }
  1724. this.useSuitableRatio({setScaleAuto:true})
  1725. hot.info.actionType = CloneObject(settings.hotClickEvent[type]);//给一个默认 图和视频不打开热点
  1726. /* if(type == 'video'){
  1727. hot.info.actionType.playAndPause = true;
  1728. }else{
  1729. delete hot.info.actionType.playAndPause
  1730. } */
  1731. if(type != 'video'){
  1732. delete hot.info.fileName
  1733. }
  1734. this.updateClickEventUI();//根据actionType更新ui
  1735. }
  1736. Hotpoint.prototype.updateGifPanel = function(o={}){
  1737. var hot = this.editSpot
  1738. if(!hot.material_.map)return;
  1739. let a = o.animateInfo || hot.info.animateInfo
  1740. //换图时根据图片的animation更改开关,如果有的话还要更改面板,如果图没有animation用自己的
  1741. if(o.animateInfo){//更换animateInfo
  1742. hot.info.animateInfo = CloneObject(o.animateInfo);
  1743. }
  1744. if("animateInfo" in o ){
  1745. o.on = !!o.animateInfo
  1746. }
  1747. if(!a){
  1748. o.on = false
  1749. }
  1750. if(o.on != void 0){
  1751. this.gifCheckBox.updateChoseAtUI(o.on)
  1752. GifTexDeal.remove(hot.animation)
  1753. if(o.on){
  1754. hot.animation = GifTexDeal.addAnimation(hot.material_.map, hot, hot.info.animateInfo, hot.sid)
  1755. GifTexDeal.start(hot.animation)
  1756. }else{
  1757. hot.animation = null
  1758. hot.info.animateInfo = null
  1759. }
  1760. }
  1761. let w = hot.material_.map.image.width
  1762. let h = hot.material_.map.image.height
  1763. if(a){
  1764. $("#gifXCount").val(a.cellXcount);
  1765. $("#gifYCount").val(a.cellYcount);
  1766. $("#gifImgWidth").text(w)
  1767. $("#gifImgHeight").text(h)
  1768. $("#gifCellWidth").text(toPrecision(w / a.cellXcount, 2));
  1769. $("#gifCellHeight").text(toPrecision(h / a.cellYcount, 2));
  1770. $("#voidCount").val(a.voidCount || 0);
  1771. let frameCount = a.cellXcount * a.cellYcount - (a.voidCount || 0)
  1772. $("#gifFrameCount").text(frameCount)
  1773. $("#gifDuration").val(toPrecision(a.duration / 1000, 2));
  1774. $("#gifFps").val(toPrecision(frameCount / a.duration * 1000, 1) );
  1775. }else{
  1776. $("#gifXCount").val(1);
  1777. $("#gifYCount").val(1);
  1778. $("#gifImgWidth").text(w)
  1779. $("#gifImgHeight").text(h)
  1780. $("#gifCellWidth").text(w);
  1781. $("#gifCellHeight").text(h)
  1782. $("#voidCount").val(0);
  1783. $("#gifFrameCount").text(1)
  1784. $("#gifDuration").val(1);
  1785. $("#gifFps").val(1);
  1786. }
  1787. }
  1788. Hotpoint.prototype.updateListSelect = function(hot) { //每次开始编辑热点时更新样式
  1789. if(!Hot.allPhotoLoaded || !Hot.allModelLoaded)return
  1790. var list = this.texLists[hot.texType];
  1791. var chosenIndex = null;
  1792. this.texTypeMenuOptions.updateChoseAtUI({name:hot.texType})
  1793. for(let i in this.texLists){
  1794. //this.texLists[i].clearVoid(this.texLists[i]);
  1795. this.texLists[i].saveTemp(this.texLists[i])
  1796. }
  1797. this.modelList.saveTemp()
  1798. if(hot.texType == 'shine'){
  1799. if (!hot.styleImg) hot.styleImg = [];
  1800. if(hot.styleImg.length){
  1801. var info = this.styleList.findChosenByContent(hot.styleImg)
  1802. chosenIndex = info.index
  1803. }
  1804. }else{
  1805. var info = list.findChosenByContent(list, hot.texMedia)
  1806. chosenIndex = info.index
  1807. }
  1808. list.selectFromOutSide(chosenIndex, {dontApplyToHot:true})
  1809. this.photoList.updateDelBtns(this.photoList)
  1810. this.videoList.updateDelBtns(this.videoList)
  1811. {//model
  1812. let hasModel = !!hot.objObject
  1813. this.modelMenuOptions.updateChoseAtUI({name: hasModel ? 'user' : 'default'})
  1814. if(hasModel){
  1815. var info = this.modelList.findChosenByContent(hot.objObject)
  1816. this.modelList.selectFromOutSide(info.index, {dontApplyToHot:true})
  1817. transformControls.enableScaleZ()
  1818. }
  1819. }
  1820. }
  1821. Hotpoint.prototype.useSuitableRatio = function(o={}) {//自适应素材比例
  1822. var hot = this.editSpot
  1823. var plane = this.editSpot.plane;
  1824. var w, h, defaultS = 1, s, mediaW, mediaH
  1825. if(this._scale[hot.texType] && o.setScaleAuto){
  1826. w = this._scale[hot.texType].x; h = this._scale[hot.texType].y;
  1827. }else{
  1828. if(hot.texType == 'shine'){//默认使用热点大小,正方形
  1829. if(o.setScaleAuto){
  1830. w = h = DATA.hotIconScale * g_HotMeshSize.g_HotMeshWidth
  1831. }else{
  1832. s = hot.scale.x * hot.scale.y
  1833. w = h = Math.sqrt(Math.abs(s))
  1834. }
  1835. }else{
  1836. if(!hot.material_.map)return
  1837. //假设不变总面积
  1838. if(o.setScaleAuto){
  1839. s = defaultS
  1840. }else{
  1841. s = hot.scale.x * hot.scale.y
  1842. }
  1843. if(hot.texType == 'photo'){
  1844. mediaW = hot.texMedia.width;
  1845. mediaH = hot.texMedia.height;
  1846. //动画的话再变
  1847. if(hot.info.animateInfo){
  1848. mediaW /= hot.info.animateInfo.cellXcount
  1849. mediaH /= hot.info.animateInfo.cellYcount
  1850. }
  1851. }else{
  1852. mediaW = hot.texMedia.videoWidth || hot.videoWidth || 1;
  1853. mediaH = hot.texMedia.videoHeight || hot.videoHeight || 1;
  1854. }
  1855. var k = Math.sqrt(Math.abs(s) / (mediaW * mediaH))
  1856. w = k * mediaW * (hot.scale.x < 0 ? -1 : 1);
  1857. h = k * mediaH * (hot.scale.y < 0 ? -1 : 1);
  1858. }
  1859. }
  1860. hot.scale.setX(w)
  1861. hot.scale.setY(h)
  1862. if(hot.isUserModel){
  1863. hot.scale.setZ(z)
  1864. }
  1865. this.updateTransform('scale')
  1866. },
  1867. Hotpoint.prototype.updateClickEventUI = function() {//根据actionType更新ui
  1868. var hot = this.editSpot;
  1869. /* var checkboxs = this.hotpointDetail.find("li[name='clickEvent'] li.editCheckbox");
  1870. checkboxs.addClass('hide');
  1871. for(let i in hot.info.actionType){
  1872. var checkbox = checkboxs.find('[name='+ i +']')
  1873. checkbox.parent().removeClass('hide');
  1874. checkbox[0].checked = !!hot.info.actionType[i]
  1875. }
  1876. var content = this.hotpointDetail.find("li[name='content']")
  1877. hot.info.actionType.openHot ? content.removeClass('hide') : content.addClass('hide') */
  1878. for(let i in hot.info.actionType){
  1879. this.actionCheckBox.updateChoseAtUI(hot.info.actionType[i], i)
  1880. }
  1881. }
  1882. //添加图片和视频
  1883. Hotpoint.prototype.addmediaInit = function() {
  1884. // 视频预览控制
  1885. var $videoLayout = $('.fun-view-video')
  1886. $videoLayout.find('span').on('click', function() {
  1887. $videoLayout.hide();
  1888. $videoLayout.find('video').attr('src', '')[0].pause()
  1889. });
  1890. // 图片加载回调
  1891. function imageSuccess(file) {
  1892. if (!/image\/\w+/.test(file.type)) {
  1893. alert("文件必须为图片!");
  1894. return false;
  1895. }
  1896. if (!restrictedSize(file, 9)) {
  1897. return false;
  1898. }
  1899. var img = new Image()
  1900. img.src = URL.createObjectURL(file);
  1901. img.className = 'bg'
  1902. return img
  1903. }
  1904. // 视频加载回调
  1905. function videoSuccess(file, $elayout) {
  1906. if (!/video\/\w+/.test(file.type)) {
  1907. alert("视频必须为map4格式!");
  1908. return false;
  1909. }
  1910. $elayout.append('<span class="upload-thum">上传封面<i><input type="file" accept="image/*"></i></span>')
  1911. return '<img src="./images/play.png" class="play-video" videoURL="' + URL.createObjectURL(file) + '">'
  1912. }
  1913. // 视频封面回调
  1914. function thumbSuccess(file, $elayout, $seft) {
  1915. if (!/image\/\w+/.test(file.type)) {
  1916. alert("文件必须为图片!");
  1917. return false;
  1918. }
  1919. if (!restrictedSize(file, 2)) {
  1920. return false;
  1921. }
  1922. var img = $seft.closest('div').find('img.bg');
  1923. if(!img[0]){
  1924. img = $("<img class='bg'></img>");
  1925. $seft.closest('div').find('a').append(img)
  1926. }
  1927. img.attr('src', URL.createObjectURL(file));
  1928. $seft.closest('span').removeClass("success")
  1929. }
  1930. // 图片与视频加载
  1931. function fileHandle() {
  1932. var $seft = $(this) //input
  1933. var file = this.files[0];
  1934. var type = this.activeElem ? this.activeElem.attr('data-type') : $seft.parent().attr('data-type');
  1935. var $din = $('<div class="mediaItem" draggable="true"></div>')
  1936. var fnc = type === 'photo' ? imageSuccess : type === 'video' ? videoSuccess : thumbSuccess //再次传都会是thumSuccess
  1937. var $dom = fnc(file, $din, $seft)
  1938. if (type === 'photo' || type === 'video') {
  1939. if (!$dom)
  1940. return $seft.val('');
  1941. if(!this.activeElem){//创建新的item
  1942. var $layout = $seft.closest("li");
  1943. var $addLayout = $(document.createElement('a'));
  1944. $addLayout.attr("data-type", type)
  1945. var $close = $(document.createElement('span'));
  1946. $addLayout[0].file = file;
  1947. $addLayout.append($close);
  1948. $addLayout.append($dom);
  1949. $addLayout.addClass("result");
  1950. $din.prepend($addLayout);
  1951. $layout.find('.edit-fun-images').append($din);
  1952. }else{//重传
  1953. if (type === 'photo'){
  1954. this.activeElem.find("img.bg").remove();
  1955. }else{
  1956. this.activeElem.find(".play-video").remove();
  1957. }
  1958. this.activeElem.removeClass("success")
  1959. this.activeElem.append($dom)
  1960. this.activeElem[0].file = file;
  1961. this.value = ''
  1962. }
  1963. }
  1964. if (searchParent($seft[0], {
  1965. id: 'shareImgUpload'
  1966. })) {
  1967. //信息页面的分享图片
  1968. $("#shareImgUpload").addClass("hide")
  1969. }else if(searchParent($seft[0], {
  1970. id: 'SpotStyle'
  1971. })){
  1972. $("#SpotStyle").addClass("hide")
  1973. }
  1974. }
  1975. //用于重传的input
  1976. var imgInput = $("<input accept='image/*' type='file'></input>")
  1977. var videoInput = $("<input accept='video/*' type='file'></input>")
  1978. // 图片与视频加载
  1979. $('.upload, .edit-fun-images').on('change', function(ev) {
  1980. if (ev.target.tagName.toUpperCase() === 'INPUT') {
  1981. ev.target.files.length && fileHandle.call(ev.target)
  1982. }
  1983. })
  1984. imgInput.on('change', (ev)=>{fileHandle.call(ev.target)})
  1985. videoInput.on('change', (ev)=>{fileHandle.call(ev.target)})
  1986. $('.edit-fun-images').on('click', function(ev) {//点击item时
  1987. var $tag = $(ev.target)
  1988. var tagName = ev.target.tagName.toUpperCase()
  1989. if (tagName === 'SPAN') {
  1990. if (searchParent($tag[0], {
  1991. className: 'forShareImg'
  1992. })) {
  1993. //信息页面的分享图片
  1994. $("#shareImgUpload").removeClass('hide')
  1995. }else if(searchParent($tag[0], {
  1996. className: 'SpotStyle'
  1997. })){
  1998. $("#SpotStyle").removeClass('hide')
  1999. }
  2000. $tag.parent().parent().remove()
  2001. }else if (tagName === 'IMG' && $tag.hasClass('play-video')) {
  2002. $videoLayout.css('display', 'flex').find('video').attr('src', $tag.attr('videoURL'))[0].play()
  2003. }else{// 替换
  2004. var a = searchParent($tag[0], {
  2005. tagName: 'a'
  2006. })
  2007. if(a) {
  2008. var input
  2009. if(searchParent($tag[0], {
  2010. className: 'video'
  2011. })){
  2012. input = videoInput
  2013. }else{
  2014. input = imgInput
  2015. }
  2016. input[0].activeElem = $(a)
  2017. input.click()
  2018. }
  2019. }
  2020. })
  2021. }
  2022. //当前处于的状态,比如是否是添加热点的状态
  2023. /* Hotpoint.prototype.state = function(that, Hot) {
  2024. if (g_HotStatus === "add") {
  2025. //console.log(Hot)
  2026. this.addHot(that, Hot, (hot)=>{
  2027. this.addHotList(hot);
  2028. } );
  2029. }
  2030. } */
  2031. Hotpoint.prototype.updateNumDisplay = function() {
  2032. this.spotList.find("i").text(this.spotList.find("ul li").length);
  2033. }
  2034. //删除热点
  2035. Hotpoint.prototype.removeHot = function(hot ) {
  2036. //hot.dispose();
  2037. hot.parent.remove(hot)
  2038. delete player.model.hots[hot.sid]
  2039. hot.$li.remove();
  2040. this.updateNumDisplay()
  2041. }
  2042. //添加热点模型
  2043. Hotpoint.prototype.addHot = function(that) {
  2044. if (!player.intersect || !g_HotStatus) return;// 没有正确的热点位置, return
  2045. var sid = getRandomSid()
  2046. var s = g_HotStatus == 'shine' ? Hot.getDefaulScale() : 1
  2047. var hot = new Hot({
  2048. sid,
  2049. texType : g_HotStatus,
  2050. position : player.intersect.point.clone() ,
  2051. rotation : [0,0,0],
  2052. scale: new THREE.Vector3(s,s,0.02),
  2053. actionType : CloneObject(settings.hotClickEvent[g_HotStatus])
  2054. });
  2055. hot.photoHasRequestLoad = hot.modelHasRequestLoad = true;//防止requestDownload
  2056. player.model.hots[sid] = hot;
  2057. hot.hasRequestLoad = true
  2058. hot.isNew = true
  2059. if (player.getMouseDirection().angleTo(player.intersect.face.normal) < Math.PI / 2) {
  2060. hot.lookAt(player.intersect.face.normal.clone().negate().add(player.intersect.point));
  2061. hot.position.add(player.intersect.face.normal.clone().negate().multiplyScalar(0.01)) //avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
  2062. } else {
  2063. hot.lookAt(player.intersect.face.normal.clone().add(player.intersect.point));
  2064. hot.position.add(player.intersect.face.normal.clone().multiplyScalar(0.01))
  2065. }
  2066. g_HotStatus = false;
  2067. player.mouseCouldBeClickToMove = false;
  2068. $("#player").css("cursor", "");
  2069. this.addHotList(hot)
  2070. this.editHot(hot)
  2071. this.updateTransform('position');
  2072. this.updateTransform('quaternion');
  2073. }
  2074. //添加热点列表
  2075. Hotpoint.prototype.addHotList = function(hot) {
  2076. var li = $("<li class='listItem' data-spid=" + hot.sid + "><div class='icon'></div>" + "<div class=number>" + (++_hotNum) + "</div>" + "<div class=title >" + ( hot.info.title ) + "</div>" + "<div class=DelConfirm title='删除'>确定删除</div>" + "<div class=del></div>" + "</li>");
  2077. li.hot = hot
  2078. hot.$li = li
  2079. this.setListLi(hot)
  2080. $(".spotList ul").append(li);
  2081. li.on("mouseover",()=>{
  2082. hot.changeBoxHelperDisplay(true)
  2083. })
  2084. li.on("mouseout",()=>{
  2085. hot.changeBoxHelperDisplay(false)
  2086. })
  2087. this.updateNumDisplay()
  2088. }
  2089. Hotpoint.prototype.setListLi = function(hot){ //暂时用文字展示,最好有图标来表示包含gif和模型
  2090. var name = '';
  2091. if(hot.info.title) name = hot.info.title
  2092. else{
  2093. if(hot.info.objSrc)name = '包含模型的'
  2094. if(hot.texType == 'photo' && hot.info.animateInfo)name+= 'gif'
  2095. else name += (hot.texType == 'shine' ? '热点' : hot.texType == 'photo' ? '图片' : '视频' )
  2096. }
  2097. hot.$li.find(".title").html(name);
  2098. hot.$li.find('.icon').attr("type",hot.texType)
  2099. hot.$li.attr("title", hot.info.title) //显示没显示完的标题
  2100. }
  2101. //添加热点模型列表dom
  2102. Hotpoint.prototype.inputList = function(text, val) {
  2103. var _val = '';
  2104. if (arguments[1]) {
  2105. _val = 'value=' + val;
  2106. }
  2107. return '<div class="link"> <input class="text" type="text" placeholder=' + text + ' spellcheck="false" ' + _val + ' > </div>'
  2108. }
  2109. //添加热点模型
  2110. Hotpoint.prototype.addModel = function() {
  2111. var text = this.inputList("请填写模型链接(https开头)");
  2112. this.hotpointDetail.find("[name=modelSrc] .add").on('click', function() {
  2113. $(this).closest("[name=modelSrc] ").find(".list").append(text)
  2114. });
  2115. this.hotpointDetail.find("[name=modelSrc] .delete").on('click', function() {
  2116. $(this).closest("[name=modelSrc] ").find(".list > div:last").remove();
  2117. });
  2118. }
  2119. //添加网页链接
  2120. Hotpoint.prototype.addwebPack = function() {
  2121. var text = this.inputList("请填写网页链接", "");
  2122. this.hotpointDetail.find("[name=webPage] .add").on('click', function() {
  2123. $(this).closest("[name=webPage]").find(".list").append(text)
  2124. });
  2125. this.hotpointDetail.find("[name=webPage] .delete").on('click', function() {
  2126. $(this).closest("[name=webPage]").find(".list > div:last").remove();
  2127. });
  2128. }
  2129. Hotpoint.prototype.editDone = function(){
  2130. var hot = this.editSpot
  2131. this.editSpot = null;
  2132. hot.isNew = false;
  2133. transformControls.detach()
  2134. this.hotpointDetail.addClass("atRight");
  2135. }
  2136. // 保存热点信息
  2137. Hotpoint.prototype.saveHot = function() {
  2138. var $layout = $(".edit-loading");
  2139. var hotpointDetail = this.hotpointDetail;
  2140. var that = this
  2141. var hot = this.editSpot
  2142. if (hot.texType == "video" && !hot.texMedia ) {
  2143. alert("请添加视频")
  2144. return;
  2145. }else if(hot.texType == 'photo' && !hot.texMedia){
  2146. alert("请添加图片")
  2147. return;
  2148. }
  2149. //显示loading
  2150. $layout.removeClass('hide');
  2151. var args = hot.info//{};
  2152. //热点标题
  2153. var $title = hotpointDetail.find("[name=info] input");
  2154. //热点内容
  2155. var $content = hotpointDetail.find("[name=intro] textarea");
  2156. //热点图片
  2157. var $images = hotpointDetail.find("[name=content] [name=photo] .edit-fun-images a.result");
  2158. //热点视频
  2159. var $videos = hotpointDetail.find("[name=content] [name=video] .edit-fun-images a.result");
  2160. //热点视频的图片
  2161. var $thums = hotpointDetail.find("[name=content] [name=video] .edit-fun-images .upload-thum");
  2162. //热点模型
  2163. var $modules = hotpointDetail.find("[name=content] [name=modelSrc] input");
  2164. //热点内嵌网页
  2165. var $iframes = hotpointDetail.find("[name=content] [name=webPage] input.text");
  2166. //热点音乐
  2167. var $miusc = hotpointDetail.find("[name=content] #upload-hotBgm");
  2168. var promise = new Promise(function(resolve, reject) {
  2169. //获取图片路径
  2170. upload($images, 'images', resolve)
  2171. }).then(function(imgUrls) {
  2172. $layout.removeClass('hide');
  2173. args.images = imgUrls
  2174. //获取视频路径
  2175. return new Promise(function(resolve, reject) {
  2176. upload($videos, 'videos', resolve)
  2177. }
  2178. )
  2179. }).then(function(videoUrls) {
  2180. $layout.removeClass('hide');
  2181. args.video = videoUrls
  2182. //获取视频封面路径
  2183. return new Promise(function(resolve, reject) {
  2184. upload($thums, 'images', resolve)
  2185. }
  2186. )
  2187. }).then(function(thums) {
  2188. $layout.removeClass('hide');
  2189. args.video = args.video.map(function(video, index) {//整合视频+封面
  2190. return {
  2191. url: video,
  2192. img: thums[index]
  2193. }
  2194. })
  2195. }).then(function() {
  2196. //获取热点音乐所有的路径
  2197. //console.log($miusc)
  2198. $layout.removeClass('hide');
  2199. if ($miusc[0].files.length > 0) {
  2200. return new Promise(function(resolve) {
  2201. upload($miusc, 'miusc', function(res) {
  2202. resolve(res[0])
  2203. })
  2204. })
  2205. } else {
  2206. return $miusc.attr('data-hotBgm')
  2207. }
  2208. }).then(function(src) {
  2209. if(that.musicBox.hasMusic && !src){
  2210. args.backgroundMusic = hot.info.backgroundMusic
  2211. args.bgName = hot.info.bgName
  2212. }else{
  2213. args.backgroundMusic = src
  2214. args.bgName = that.musicBox.getName()
  2215. }
  2216. }).then(function() { //上传所有热点的tex file
  2217. var a = $.Deferred();
  2218. var doneNum = 0;
  2219. var filesNeedSave = [];
  2220. var liNeedSave = [], liNeedSave2 = []
  2221. $layout.removeClass('hide');
  2222. Array.from(that.styleList.listDom.children()).forEach(li=>{
  2223. if(li.sameContentSpots.length == 0)return;//没被热点用到就不保存
  2224. //li.sameContentSpots.forEach(spot=>spot.styleImg = li._styleImg)//提前同步下 等下就都是线上链接了
  2225. li._styleImg.forEach(img=>{
  2226. if(img.needSave && !filesNeedSave.includes(img)){
  2227. filesNeedSave.push(img)
  2228. liNeedSave.includes(li) || liNeedSave.push(li)
  2229. }
  2230. })
  2231. });
  2232. [that.photoList, that.videoList].forEach(list=>{
  2233. Array.from(list.listDom.children()).forEach(li=>{
  2234. if(li.sameContentSpots.length == 0)return;//没被热点用到就不保存
  2235. //li.sameContentSpots.forEach(spot=>spot.texMedia.src = li._media.src)//同步下 video不能同步,只能同步src
  2236. li._media.needSave && (filesNeedSave.push(li._media), liNeedSave.push(li))
  2237. })
  2238. })
  2239. Array.from(that.modelList.listDom.children()).forEach(li=>{
  2240. if(li.sameContentSpots.length == 0)return;//没被热点用到就不保存
  2241. li.objObject.needSave && (filesNeedSave.push(li.objObject), liNeedSave2.push(li))
  2242. })
  2243. if(filesNeedSave.length){
  2244. filesNeedSave.forEach(o=>{
  2245. uploadFile(o.file, 'hot', function(rs) {
  2246. if (rs.code === 0) {
  2247. o.needSave = false;
  2248. //o.saveURL = rs.data;
  2249. o.src = rs.data;
  2250. if (++doneNum >= filesNeedSave.length) {
  2251. a.resolve();
  2252. liNeedSave.forEach(li=>{//将blob更换成线上链接
  2253. li.sameContentSpots.forEach((spot)=>{
  2254. if(spot.texType == 'shine'){
  2255. spot.info.styleImg = li._styleImg.map(img=>img.src)
  2256. }else{
  2257. spot.info.texSrc = li._media.src
  2258. spot.texMedia.src = li._media.src
  2259. }
  2260. })
  2261. })
  2262. liNeedSave2.forEach(li=>{//将blob更换成线上链接
  2263. li.sameContentSpots.forEach((spot)=>{
  2264. spot.info.objSrc = spot.objObject.src = li.objObject.src
  2265. })
  2266. })
  2267. }
  2268. } else {
  2269. alert("文件上传失败");
  2270. a.reject();
  2271. }
  2272. })
  2273. })
  2274. return a.promise()
  2275. }else{
  2276. return a.resolve()
  2277. }
  2278. }).then(function() {
  2279. $layout.removeClass('hide');
  2280. //获取热点标题、内容、内嵌网页、模型网页。
  2281. args.title = $title.val()
  2282. args.content = $content.val()
  2283. var iframes = []
  2284. for (var i = 0; i < $iframes.length; i++) {
  2285. var iframe = $iframes.eq(i).val()
  2286. iframe && iframes.push(iframe)
  2287. }
  2288. args.iframe = iframes
  2289. var modules = []
  2290. for (var i = 0; i < $modules.length; i++) {
  2291. var module = $modules.eq(i).val()
  2292. module && modules.push(module)
  2293. }
  2294. args.model = modules
  2295. /* if(!hot.isSprite){
  2296. args.quaternion = hot.quaternion.clone()
  2297. //hot.quaternion.copy(hot.mesh.quaternion)
  2298. }
  2299. args.position = hot.position.clone()
  2300. //hot.position.copy(hot.mesh.position) */
  2301. return args
  2302. }).then(function(args) {
  2303. hot.info.texType = hot.texType
  2304. if(that.ifNeedResetVisi(hot)){
  2305. hot.getVisiblePanos();
  2306. }
  2307. if(hot.texType == 'photo'){//保存时绑定animateInfo到li
  2308. let info = that.photoList.findChosenByContent(that.photoList, hot.texMedia);
  2309. info.item.animateInfo = CloneObject(hot.info.animateInfo)
  2310. }
  2311. hot.setTitleElem()//更新名称
  2312. that.setListLi(hot);
  2313. $layout.addClass('hide');
  2314. console.log(args);
  2315. that.editDone()
  2316. })
  2317. return promise
  2318. }
  2319. Hotpoint.prototype.ifNeedResetVisi = function(hot){//修改过贴图或位置,导致这几个数值改变,就要重新计算可见性(会覆盖用户设置)
  2320. var need = !ifSame({
  2321. hasBox: hot.tempInfo.hasBox,
  2322. position: hot.tempInfo.position,
  2323. rotation: hot.tempInfo.rotation,
  2324. scale: hot.tempInfo.scale,
  2325. transformAtPanos: hot.tempInfo.transformAtPanos,
  2326. modelBound:hot.tempInfo.modelBound
  2327. }, {
  2328. hasBox: hot.info.hasBox,
  2329. position: hot.info.position,
  2330. rotation: hot.info.rotation,
  2331. scale: hot.info.scale,
  2332. transformAtPanos: hot.info.transformAtPanos,
  2333. modelBound:hot.info.modelBound
  2334. })
  2335. return need
  2336. }
  2337. Hotpoint.prototype.getSavingInfo = function(){//保存全部
  2338. var hots = {} // 热点数据
  2339. var shineHots = player.model.hotGroup.children.filter(e=>e.texType == 'shine')
  2340. var photoHots = player.model.hotGroup.children.filter(e=>e.texType == 'photo')
  2341. var videoHots = player.model.hotGroup.children.filter(e=>e.texType == 'video')
  2342. shineHots.concat(photoHots).concat(videoHots).forEach((hot,index)=>{
  2343. var hotData = CloneObject(hot.info)
  2344. if(hotData.texSrc){
  2345. hotData.texSrc = manage.removeSrcPostMark(hotData.texSrc)
  2346. }
  2347. hotData.position = toPrecision(hot.info.position.toArray(), 3)
  2348. hotData.scale = toPrecision(hot.info.scale.toArray(), 3)
  2349. hotData.rotation = toPrecision(hot.info.rotation.toArray().slice(0,3), 4)
  2350. hotData.order = index
  2351. hotData.transformAtPanos = {}
  2352. for(let i in hot.info.transformAtPanos){
  2353. hotData.transformAtPanos[i] = {
  2354. pos : toPrecision(hot.info.transformAtPanos[i].pos.toArray(), 3),
  2355. }
  2356. /* if(hot.transformAtPanos[i].qua){
  2357. hotData.transformAtPanos[i].qua = toPrecision(hot.transformAtPanos[i].qua.toArray(), 5)
  2358. } */
  2359. }
  2360. hotData.version = 'multi'
  2361. if(hotData.animateInfo && hotData.animateInfo.cellXcount * hotData.animateInfo.cellYcount - (hotData.animateInfo.voidCount || 0)<=1){
  2362. delete hotData.animateInfo
  2363. }
  2364. hotData.model = hotData.model.length ? hotData.model : ''
  2365. hotData.images = hotData.images.length ? hotData.images : ''
  2366. hotData.video = hotData.video.length ? hotData.video : ''
  2367. hotData.iframe = hotData.iframe.length ? hotData.iframe : ''
  2368. hots[hot.sid] = hotData
  2369. })
  2370. return hots
  2371. }
  2372. //背景音乐
  2373. var EditBGM = function() {
  2374. this.mediaUpload = $(".music .mediaUpload");
  2375. this.musicBox = musicPlayBoxBind(this.mediaUpload, (file)=>{
  2376. uploadMusic(file, (rs, file)=>{
  2377. if (rs.code === 0) {
  2378. this.musicBox.show(/* this.mediaUpload, */file.name, rs.data)
  2379. }else{
  2380. this.musicBox.hide()
  2381. }
  2382. })
  2383. }, null)
  2384. }
  2385. EditBGM.prototype.init = function(data) {
  2386. if (!data.backgroundMusic)
  2387. return;
  2388. this.musicBox.show(/* this.mediaUpload, */ data.bgName || "backgound", data.backgroundMusic);
  2389. }
  2390. //导览编辑
  2391. var EditGuide = function() {
  2392. this.$list = $('#guide-list')
  2393. //$('#tourItemEdit') = $('#tourItemEdit');
  2394. this.targetTourPoint = null;
  2395. // fyz 记录当前编辑的导览点
  2396. // fyz 导览音乐队列
  2397. //this.tourAudio = {};
  2398. }
  2399. /**
  2400. * @author fyz 2019.07.31
  2401. * @description 新增参数data2, 表示data2.js中的数据
  2402. */
  2403. EditGuide.prototype.snapATourView = function(renew, insideFolder){
  2404. var ev = document.createEvent("MouseEvent");
  2405. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  2406. g_snapShotWidth = 200;
  2407. g_snapShotHeight = 140;
  2408. window.screenSta = 'tour';
  2409. // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
  2410. ev.__callback = (imgData, info)=> {
  2411. this.uploadGuide(imgData, info, renew, insideFolder)
  2412. };
  2413. window.dispatchEvent(ev);
  2414. }
  2415. EditGuide.prototype.init = function(data, data2) {
  2416. this.createDom(data, data2);
  2417. //this.tourAudio = data2.tourAudio || {};
  2418. var that = this;
  2419. //点击添加导览
  2420. $('.addTour .innerBtn').eq(0).on("click", function () {
  2421. this.addFolderDom({name:"区域"+($("#tourList .listItem").length+1) } );//点击增加一段导览
  2422. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight //scroll to bottom
  2423. }.bind(this));
  2424. $('.addTour .innerBtn').eq(1).on("click", function () {
  2425. this.snapATourView()//点击截取视图
  2426. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight
  2427. }.bind(this));
  2428. $('.snapATourView .innerBtn').on("click", function() {
  2429. this.snapATourView(null,true);//folder内点击截取视图
  2430. $("#tourItemList ul")[0].scrollTop = $("#tourItemList ul")[0].scrollHeight
  2431. }.bind(this));
  2432. $('#renewTourBtn').on("click", function() { // 重新截取视图
  2433. this.snapATourView(this, !!this.editingFolderLi);
  2434. }.bind(this));
  2435. // 确认并保存导览信息
  2436. $('#tourFolderEdit .tail .submit').on("click", function() {
  2437. this.completeFolder();
  2438. }.bind(this));
  2439. $('#tourItemEdit .tail .submit').on("click", function() {
  2440. this.completeItem();
  2441. }.bind(this));
  2442. //点击导览编辑窗口右上角的关闭按钮
  2443. $("#tourItemEdit a.close, #tourItemEdit .tail .cancel").on("click", ()=>{
  2444. /* that.targetTourPoint[0].musicSta = true; ///??????????
  2445. // 取消操作, 重置状态
  2446. that.tourDetail.addClass("atRight"); */
  2447. this.cancelItem()
  2448. });
  2449. $("#tourFolderEdit a.close, #tourFolderEdit .tail .cancel").on("click", ()=>{
  2450. /* that.targetTourPoint[0].musicSta = true; ///??????????
  2451. // 取消操作, 重置状态
  2452. that.tourDetail.addClass("atRight"); */
  2453. this.cancelFolder()
  2454. });
  2455. //导览目录
  2456. $("#tourList").on("click", function(e) {
  2457. var target = $(e.target);
  2458. let folder = searchParent(e.target, { className: 'listItem' }, 7);
  2459. if(!folder)return;//可能点到了item
  2460. if (target.hasClass("del")) {
  2461. e.stopPropagation();
  2462. target.siblings(".DelConfirm").addClass("active");
  2463. } else {
  2464. if (target.hasClass("DelConfirm")) {
  2465. e.stopPropagation();
  2466. $(folder).remove()
  2467. //that.removeFolder(folder);//删除
  2468. } else {
  2469. if (target.hasClass("title") || target.hasClass("icon")) {
  2470. that.editFolder(folder)//编辑
  2471. }
  2472. }
  2473. }
  2474. });
  2475. //编辑item
  2476. $('.tourList ul').on('click', function(e) {
  2477. var target = $(e.target);
  2478. let itemDom = searchParent(e.target, { className: 'guideItem' }, 7);
  2479. if(!itemDom)return;//可能点到了folder
  2480. if(searchParent(e.target, { className: 'preview' })){
  2481. var choice = confirm("你确定删除吗?");
  2482. if (choice) {
  2483. var ul = searchParent(e.target, { className: 'tourList' })
  2484. target.closest('li').remove();
  2485. reIndexTourList(ul)
  2486. } else {
  2487. return false
  2488. }
  2489. }else{
  2490. that.editItem(itemDom);
  2491. }
  2492. })
  2493. //fyz 拖拽以改变顺序
  2494. {
  2495. let tourListNode = $("#tourList>ul")[0];
  2496. let tourItemListNode = $("#tourItemList>ul")[0];
  2497. let callback = function(ul){
  2498. reIndexTourList(ul)
  2499. }
  2500. setDraggable({ul:tourListNode, dragItemClassName:['guideItem', 'listItem'], callback})
  2501. setDraggable({ul:tourItemListNode, dragItemClassName:['guideItem'], callback })
  2502. setDraggable({ul:$('#hotpointDetail [name="video"] .list')[0], dragItemClassName:['mediaItem'] })
  2503. setDraggable({ul:$('#hotpointDetail [name="photo"] .list')[0], dragItemClassName:['mediaItem'] })
  2504. }
  2505. //音乐
  2506. this.musicBoxFolder = musicPlayBoxBind($("#tourFolderEdit .mediaUpload"), null, ()=>{
  2507. (that.editingFolderLi || that.editingItemLi).tourData.musicInfo = {}//直接删除 不可逆
  2508. })
  2509. this.musicBoxItem = musicPlayBoxBind($("#tourItemEdit .mediaUpload"), null, ()=>{
  2510. (that.editingFolderLi || that.editingItemLi).tourData.musicInfo = {}//直接删除 不可逆
  2511. })
  2512. this.momentFolderMenuOptions = new MenuOptions({ //链接打开方式切换
  2513. dom: $(" #folderTourSwitch ")
  2514. })
  2515. this.momentMenuOptions = new MenuOptions({ //链接打开方式切换
  2516. dom: $(" #tourSwitch_Slice ")
  2517. })
  2518. this.rotCheckBox = new CheckBox({dom: $('#tourItemEdit [name="rotSwitch"] input') ,
  2519. uiCallBack : (checked )=>{
  2520. },
  2521. callbackWhenChose:(checked )=>{
  2522. this.editingItemLi.tourData.dontRot = checked ? 0 : 1
  2523. }
  2524. })
  2525. {
  2526. let ui = $('#tourItemEdit [name="rotTime"] input')
  2527. let min = parseFloat(ui.attr('min'));
  2528. let max = parseFloat(ui.attr('max'));
  2529. ui.on("change", function(e) {
  2530. var s = THREE.Math.clamp(parseFloat(e.target.value), min, max)
  2531. if(isNaN(s))s = ''
  2532. e.target.value = s
  2533. that.editingItemLi.tourData.rotTime = s
  2534. })
  2535. }
  2536. }
  2537. function reIndexTourList(ul) {
  2538. Array.from($(ul).find('li.guideItem')).forEach((li,index)=>{
  2539. $(li).find("div:first-child span").text(index + 1);
  2540. })
  2541. }
  2542. EditGuide.prototype.addFolderDom = function( tourData){
  2543. 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>");
  2544. $folder[0].tourItemDoms = [] //记录所有item的li dom
  2545. $folder[0].tourData = tourData //注: data中的locations不会更新,保存时直接读取li
  2546. $("#tourList ul").append($folder);
  2547. return $folder
  2548. }
  2549. EditGuide.prototype.getItemDom = function(title, img) {
  2550. 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 >';
  2551. }
  2552. EditGuide.prototype.createDom = function(data, data2) {
  2553. var that = this;
  2554. var tourAudio = data2.tourAudio || {};
  2555. data.model.images.forEach((Info,index)=>{
  2556. if(Info.locations){//是folder
  2557. var $folder = this.addFolderDom(Info)
  2558. // 音频链接
  2559. Info.locations = Info.locations.filter(e=>e)
  2560. Info.locations.forEach(function(info, index) {
  2561. if (info.thumbnail_signed_src) {
  2562. info.thumbnail_signed_src = manage.dealURL(info.thumbnail_signed_src) //旧场景有的少了https://
  2563. var $li = $(that.getItemDom( info.name, info.thumbnail_signed_src));
  2564. $li[0].tourData = info
  2565. $folder[0].tourItemDoms.push($li[0])
  2566. }
  2567. })
  2568. }else{//是散落在外的item
  2569. if (Info.thumbnail_signed_src) {
  2570. Info.thumbnail_signed_src = manage.dealURL(Info.thumbnail_signed_src)
  2571. var $li = $(that.getItemDom(Info.name, Info.thumbnail_signed_src));
  2572. $li[0].tourData = Info
  2573. // 音频链接
  2574. $li[0].tourData.musicInfo = $li[0].tourData.musicInfo || tourAudio[Info.sid] || {}//新的music数据统一写在每个info下
  2575. $("#tourList ul").append($li)
  2576. }
  2577. }
  2578. })
  2579. reIndexTourList($("#tourList")[0])
  2580. }
  2581. EditGuide.prototype.editFolder = function(folderDom){
  2582. this.editingFolderLi = folderDom;
  2583. this.editingFolderLi.tempData = CloneObject(folderDom.tourData);
  2584. $("#tourFolderEdit").removeClass('atRight');
  2585. $("#tourFolderEdit .tourName input").val( $(folderDom).find('.title').text()||'');
  2586. var momentTour = folderDom.tourData.momentTour || "default"
  2587. this.momentFolderMenuOptions.updateChoseAtUI({name:momentTour})
  2588. folderDom.tourItemDoms.forEach(li=>{
  2589. $("#tourItemList>ul").append(li)
  2590. })
  2591. reIndexTourList($("#tourItemList>ul")[0])
  2592. //判断当前点是否有导览音频
  2593. var musicInfo = this.editingFolderLi.tourData.musicInfo //audio ? audio.music : null;
  2594. if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
  2595. var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
  2596. this.musicBoxFolder.show( musicName, "//" + musicInfo.music)
  2597. } else {
  2598. this.musicBoxFolder.hide()
  2599. }
  2600. }
  2601. EditGuide.prototype.editItem = function(li) {
  2602. this.editingItemLi = li
  2603. this.editingItemLi.tempData = CloneObject(li.tourData);
  2604. // 记录当前编辑的导览点
  2605. var that = this;
  2606. $('#tourItemEdit').removeClass('atRight');
  2607. $('#tourItemEdit .tourName input').val( $(li).find('.guide-name').text() );
  2608. $('#tourItemEdit [name="rotTime"] input').val(parseFloat(li.tourData.rotTime))
  2609. var momentTour = li.tourData.momentTour || "default"
  2610. /* $("#tourSwitch_Slice li").removeClass('chosen')
  2611. $("#tourSwitch_Slice li[index="+ momentTour +"]").addClass('chosen'); */
  2612. this.momentMenuOptions.updateChoseAtUI({name:momentTour})
  2613. this.rotCheckBox.updateChoseAtUI(!li.tourData.dontRot)
  2614. var metadata = JSON.parse(li.tourData.metadata);
  2615. if(metadata.scan_id != 'outside'){
  2616. var pano = player.model.panos.index[metadata.scan_id]
  2617. if(pano){
  2618. var q = new THREE.Quaternion().copy(metadata.camera_quaternion);
  2619. player.flyToPano({
  2620. pano: pano,
  2621. quaternion: q,
  2622. zoomLevel: metadata.zoom
  2623. })
  2624. }
  2625. }
  2626. if(!this.editingFolderLi){//在外的item, 可以上传音乐
  2627. //$('#tourItemEdit .mediaUpload').removeClass('hide')
  2628. var musicInfo = li.tourData.musicInfo //audio ? audio.music : null;
  2629. if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
  2630. var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
  2631. this.musicBoxItem.show( musicName, "//" + musicInfo.music)
  2632. } else {
  2633. this.musicBoxItem.hide()
  2634. }
  2635. }else{
  2636. //$('#tourItemEdit .mediaUpload').addClass('hide')
  2637. }
  2638. }
  2639. EditGuide.prototype.completeFolder = function(){//点击完成
  2640. var tourName = $('#tourFolderEdit .tourName input').val() //|| this.targetTourPoint.context.innerText;
  2641. $(this.editingFolderLi).find(".title").text(tourName)
  2642. //this.editingFolderLi.tourData.momentTour = $("#folderTourSwitch input").is(':checked') ? "black" : 'walk'
  2643. var momentTour = this.momentFolderMenuOptions.getSelectName()//$("#folderTourSwitch li.chosen").attr("index");
  2644. this.editingFolderLi.tourData.momentTour = momentTour != 'default' ? momentTour : null;
  2645. this.editingFolderLi.tourData.name = tourName
  2646. this.editingFolderLi.tourItemDoms = Array.from($('#tourItemList ul li'));
  2647. var done = ()=>{
  2648. //$("#tourFolderEdit .mediaUpload").find("input").val(''); // 清空 文件
  2649. this.musicBoxFolder.hide()// 清空 文件
  2650. this.editingFolderLi = null
  2651. $("#tourFolderEdit").addClass('atRight');
  2652. $(".edit-loading").addClass('hide');
  2653. $("#tourItemList>ul").html('')
  2654. }
  2655. //save导览音乐
  2656. var musicFile = this.musicBoxFolder.getFile()
  2657. if (musicFile) { //有input文件
  2658. $(".edit-loading").removeClass('hide');
  2659. var musicName = this.musicBoxFolder.getName()
  2660. new Promise( (resolve, reject)=> {
  2661. uploadMusic(musicFile, function(res) {
  2662. resolve(res.data);
  2663. })
  2664. } ).then( (src)=>{
  2665. $(".edit-loading").removeClass('hide'); //上传完继续显示loading
  2666. var audio = new Audio();
  2667. audio.src = src;
  2668. audio.onloadedmetadata = ()=>{
  2669. var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
  2670. srcArr[0] = '';
  2671. src = srcArr.join('/');
  2672. this.editingFolderLi.tourData.musicInfo = {
  2673. "name": musicName,
  2674. "music": '/' + src,
  2675. "time": Math.round(audio.duration * 1000 + 1000)
  2676. }
  2677. done()
  2678. }
  2679. })
  2680. }else done()
  2681. }
  2682. EditGuide.prototype.completeItem = function() {//点击完成
  2683. var done = ()=>{
  2684. this.musicBoxItem.hide()// 清空 文件
  2685. this.editingItemLi = null
  2686. $("#tourItemEdit").addClass('atRight');
  2687. $(".edit-loading").addClass('hide');
  2688. }
  2689. var tourName = $('#tourItemEdit .tourName input').val()
  2690. $(this.editingItemLi).find('.guide-name').text(tourName)
  2691. var momentTour = this.momentMenuOptions.getSelectName()
  2692. this.editingItemLi.tourData.momentTour = momentTour != 'default' ? momentTour : null;
  2693. this.editingItemLi.tourData.name = tourName
  2694. //save导览音乐
  2695. var musicFile = this.musicBoxItem.getFile()
  2696. if (!this.editingFolderLi && musicFile) { //有input文件
  2697. $(".edit-loading").removeClass('hide');
  2698. var musicName = this.musicBoxItem.getName() //$('#tourItemEdit .mediaUpload .title').text();
  2699. new Promise( (resolve, reject)=>{
  2700. uploadMusic(musicFile, function(res) {
  2701. resolve(res.data);
  2702. })
  2703. } ).then( (src)=>{
  2704. $(".edit-loading").removeClass('hide'); //上传完继续显示loading
  2705. var audio = new Audio();
  2706. audio.src = src;
  2707. audio.onloadedmetadata = ()=>{
  2708. var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
  2709. srcArr[0] = '';
  2710. src = srcArr.join('/');
  2711. this.editingItemLi.tourData.musicInfo = {
  2712. "name": musicName,
  2713. "music": '/' + src,
  2714. "time": Math.round(audio.duration * 1000 + 1000)
  2715. }
  2716. done()
  2717. }
  2718. })
  2719. }else done()
  2720. }
  2721. EditGuide.prototype.cancelFolder = function(){//放弃编辑
  2722. this.musicBoxFolder.hide()// 清空 文件
  2723. this.editingFolderLi.tourData = this.editingFolderLi.tempData;//还原
  2724. this.editingFolderLi.tourItemDoms.forEach((e,i)=>{
  2725. e.tourData = this.editingFolderLi.tourData.locations[i]
  2726. $(e).find('.guide-name').text(e.tourData.name)
  2727. $(e).find('#tourBg')[0].style.backgroundImage = 'url(' + e.tourData.thumbnail_signed_src + ')';
  2728. })
  2729. this.editingFolderLi = null
  2730. $("#tourFolderEdit").addClass('atRight');
  2731. $("#tourItemList>ul").html('')
  2732. }
  2733. EditGuide.prototype.cancelItem = function(){//放弃编辑
  2734. this.musicBoxItem.hide()// 清空 文件
  2735. this.editingItemLi.tourData = this.editingItemLi.tempData;//还原
  2736. $(this.editingItemLi).find('#tourBg')[0].style.backgroundImage = 'url(' + this.editingItemLi.tourData.thumbnail_signed_src + ')';
  2737. this.editingItemLi = null
  2738. $("#tourItemEdit").addClass('atRight');
  2739. }
  2740. /**
  2741. * @author fyz 2019.07.31
  2742. * @description uploadGuide方法新增参数renew状态码, 表示是否重新录制当前导览, 新增targetTourPoint, 记录当前的导览点元素
  2743. */
  2744. EditGuide.prototype.uploadGuide = function(urlData, guide, renew, insideFolder) {
  2745. var that = this;
  2746. uploadImg(urlData, function(rs) {
  2747. if (rs.code === 0) {
  2748. //var editGuide = new EditGuide();
  2749. var sid = rs.data.substring(rs.data.lastIndexOf('/') + 1, rs.data.lastIndexOf('.'));
  2750. var thumbnail_signed_src = rs.data;
  2751. var args = JSON.parse("{" + guide + "}");
  2752. args.sid = sid;
  2753. args.name = sid;
  2754. args.thumbnail_signed_src = thumbnail_signed_src;
  2755. args.metadata = JSON.stringify({
  2756. camera_mode: args.metadata.camera_mode,
  2757. camera_position: {
  2758. x: args.metadata.camera_position[0],
  2759. y: args.metadata.camera_position[1],
  2760. z: args.metadata.camera_position[2]
  2761. },
  2762. camera_quaternion: {
  2763. x: args.metadata.camera_quaternion[0],
  2764. y: args.metadata.camera_quaternion[1],
  2765. z: args.metadata.camera_quaternion[2],
  2766. w: args.metadata.camera_quaternion[3]
  2767. },
  2768. ortho_zoom: args.metadata.ortho_zoom,
  2769. scan_id: args.metadata.scan_id || "outside",
  2770. //这个"outside"不能随便改成别的
  2771. /* final_angle: 110,
  2772. is_ortho: false, */
  2773. zoom: args.metadata.zoom // fyz zoom是内部计算的zoomLevel, 乘以系数1.06才是实际缩放倍数
  2774. })
  2775. if (renew ) { // 重新录制导览
  2776. // 更新数据
  2777. if(!insideFolder){
  2778. args.musicInfo = that.editingItemLi.tourData.musicInfo;
  2779. }
  2780. args.name = that.editingItemLi.tourData.name
  2781. $(that.editingItemLi).find('#tourBg')[0].style.backgroundImage = 'url(' + args.thumbnail_signed_src + ')';
  2782. that.editingItemLi.tourData = args;
  2783. } else {
  2784. var $li = $(that.getItemDom(args.name, args.thumbnail_signed_src));
  2785. $li[0].tourData = args;
  2786. var $ul = insideFolder ? $("#tourItemList>ul") : $("#tourList>ul")
  2787. $ul.append($li);
  2788. reIndexTourList($ul[0])
  2789. }
  2790. }
  2791. })
  2792. }
  2793. EditGuide.prototype.getSavingInfo = function(){
  2794. var data = []
  2795. Array.from($("#tourList ul li")).forEach(dom=>{
  2796. if(dom.classList.contains("guideItem")){//item
  2797. //dom.tourData.name = $(dom).find('.guide-name').text()
  2798. data.push(dom.tourData)
  2799. }else{//folder
  2800. var dataFolder = dom.tourData;
  2801. //dataFolder.name = $(dom).find('.title').text()
  2802. dataFolder.locations = dom.tourItemDoms.map(li => li.tourData )
  2803. data.push(dataFolder)
  2804. }
  2805. })
  2806. return data
  2807. }
  2808. /* -- 以下是一些公用的方法 -- */
  2809. //限制大小
  2810. var restrictedSize = function(file, _size) {
  2811. //限制大小不大于8m
  2812. var fileSize = 0;
  2813. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  2814. if (isIE && !file) {
  2815. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  2816. var _file = fileSystem.GetFile(filepath);
  2817. fileSize = _file.Size;
  2818. } else {
  2819. fileSize = file.size;
  2820. }
  2821. var size = fileSize / 1024;
  2822. var RSize = _size * 1024;
  2823. if (size > RSize) {
  2824. alert("文件不能大于" + _size + "M");
  2825. return false;
  2826. }
  2827. if (size <= 0) {
  2828. alert("文件大小不能为0M!");
  2829. return false;
  2830. }
  2831. return true
  2832. }
  2833. //上传音乐
  2834. var uploadMusic = function(file, callback) {
  2835. uploadFile(file, 'audio', callback);
  2836. }
  2837. $(".toolRight .music .itemTitle span").text(`背景音乐 (<${_musicMaxWeight}M)`)
  2838. //上传图片
  2839. function uploadImg(urlData, callback, fileName) {
  2840. //console.log('urlData',urlData);
  2841. var bytes = window.atob(urlData.split(',')[1]);
  2842. //去掉url的头,并转换为byte
  2843. //处理异常,将ascii码小于0的转换为大于0
  2844. var ab = new ArrayBuffer(bytes.length);
  2845. var ia = new Uint8Array(ab);
  2846. for (var i = 0; i < bytes.length; i++) {
  2847. ia[i] = bytes.charCodeAt(i);
  2848. }
  2849. var blob = new Blob([ab],{
  2850. type: 'image/jpeg',
  2851. });
  2852. uploadFile(blob, 'hot/images', callback, fileName);
  2853. }
  2854. //上传文件
  2855. function uploadFile(file, type, callback, fileName) {
  2856. $(".edit-loading").removeClass("hide");
  2857. var formData = new FormData()
  2858. formData.append('name', number)
  2859. formData.append('dir', type)
  2860. formData.append('random', true)
  2861. //formData.append('file', file)
  2862. formData.append("file", file, fileName);
  2863. let url = cmp ? ('/api/scene/upload/' + number) : ('/manage/scene/upload/' + number)
  2864. $.ajax({
  2865. url: ceshi + url,
  2866. data: formData,
  2867. headers: {
  2868. token: token
  2869. },
  2870. dataType: 'json',
  2871. type: 'POST',
  2872. cache: false,
  2873. //上传文件无需缓存
  2874. processData: false,
  2875. //用于对data参数进行序列化处理 这里必须false
  2876. contentType: false,
  2877. //必须
  2878. success: function(rs) {
  2879. if(rs.code === 0){
  2880. callback(rs, file);
  2881. $(".edit-loading").addClass("hide");
  2882. }else if (rs.code === 5001) {
  2883. alert('请重新登录')
  2884. localStorage.dcj_token = ''
  2885. location.reload()
  2886. }else{
  2887. alert(`uploadFile (url:${url}) code : ${rs.code} \n${rs.msg}`)
  2888. }
  2889. }
  2890. })
  2891. }
  2892. function _animate(prevRect, target) {
  2893. var ms = 300;
  2894. if (ms) {
  2895. var currentRect = target.getBoundingClientRect();
  2896. if (prevRect.nodeType === 1) {
  2897. prevRect = prevRect.getBoundingClientRect();
  2898. }
  2899. _css(target, 'transition', 'none');
  2900. _css(target, 'transform', 'translate3d(' + (prevRect.left - currentRect.left) + 'px,' + (prevRect.top - currentRect.top) + 'px,0)');
  2901. target.offsetWidth;
  2902. // 触发重绘
  2903. //放在timeout里面也可以
  2904. // setTimeout(function() {
  2905. // _css(target, 'transition', 'all ' + ms + 'ms');
  2906. // _css(target, 'transform', 'translate3d(0,0,0)');
  2907. // }, 0);
  2908. _css(target, 'transition', 'all ' + ms + 'ms');
  2909. _css(target, 'transform', 'translate3d(0,0,0)');
  2910. clearTimeout(target.animated);
  2911. target.animated = setTimeout(function() {
  2912. _css(target, 'transition', '');
  2913. _css(target, 'transform', '');
  2914. target.animated = false;
  2915. }, ms);
  2916. }
  2917. }
  2918. //给元素添加style
  2919. function _css(el, prop, val) {
  2920. var style = el && el.style;
  2921. if (style) {
  2922. if (val === void 0) {
  2923. if (document.defaultView && document.defaultView.getComputedStyle) {
  2924. val = document.defaultView.getComputedStyle(el, '');
  2925. } else if (el.currentStyle) {
  2926. val = el.currentStyle;
  2927. }
  2928. return prop === void 0 ? val : val[prop];
  2929. } else {
  2930. if (!(prop in style)) {
  2931. prop = '-webkit-' + prop;
  2932. }
  2933. style[prop] = val + (typeof val === 'string' ? '' : 'px');
  2934. }
  2935. }
  2936. }
  2937. function upload($files, type, cb) {
  2938. var length = $files.length
  2939. var rcount = 0
  2940. var result = []
  2941. Array.from($files).forEach(function(dFile, index) {
  2942. //a 标签的success 是用来判断是否是已经上传过的文件
  2943. //attr-thum 属性是视频的图片
  2944. //videoURL 是判断是否有视频
  2945. var $file = $(dFile)
  2946. var $image = type == 'videos' ? $file.find('img.play-video') : $file.find('img')
  2947. if ($file.hasClass('success')) {//已经上传过,有链接
  2948. if ($file.attr('attr-thum')) {//视频的封面
  2949. result[index] = $file.attr('attr-thum')
  2950. } else if ($image.attr('videoURL')) {//视频
  2951. result[index] = $image.attr('videoURL')
  2952. } else {
  2953. result[index] = $image.attr('src')
  2954. }
  2955. return success(++rcount);
  2956. } else {
  2957. switch ($file[0].localName) {
  2958. case "input":
  2959. dFile = $file[0]
  2960. break;
  2961. case "span"://封面
  2962. dFile = $file.find('input')[0];
  2963. break;
  2964. case "a"://重传的图or视频
  2965. dFile = {files:[$file[0].file]}
  2966. //dFile = $file.find('input')[0];
  2967. break;
  2968. default:
  2969. dFile = $file.closest("li").find('.upload input')[0];
  2970. break;
  2971. }
  2972. // dFile = $file[0].localName === "input" ? $file[0] : $file[0].localName === "span" ? $file.find('input')[0] : $file.closest("li").find('.upload input')[0];
  2973. }
  2974. var file = (dFile.files && dFile.files[0]) || '';
  2975. if (!file)
  2976. return success(++rcount);
  2977. uploadFile(file, 'hot/' + type, function(rs) {
  2978. //似乎所有图保存路径都是这个hot/前缀。图地址 :"场景id/edit/重新生成的文件名.原后缀", 展示页面也是。
  2979. if (rs.code === 0) {
  2980. result[index] = rs.data
  2981. }
  2982. ;success(++rcount);
  2983. })
  2984. })
  2985. //判断当前队列元素是否处理成功
  2986. function success() {
  2987. if (rcount === length) {
  2988. cb(result)
  2989. }
  2990. }
  2991. success()
  2992. }
  2993. function getIndex(el) {
  2994. let index = 0;
  2995. if (!el || !el.parentNode) {
  2996. return -1;
  2997. }
  2998. while (el && (el = el.previousElementSibling)) {
  2999. index++;
  3000. }
  3001. return index;
  3002. }
  3003. dataURLtoBlob = function(dataurl) {
  3004. //将base64转换blob
  3005. var arr = dataurl.split(',')
  3006. , mime = arr[0].match(/:(.*?);/)[1]
  3007. , bstr = atob(arr[1])
  3008. , n = bstr.length
  3009. , u8arr = new Uint8Array(n);
  3010. while (n--) {
  3011. u8arr[n] = bstr.charCodeAt(n);
  3012. }
  3013. return new Blob([u8arr],{
  3014. type: mime
  3015. });
  3016. }
  3017. ;
  3018. //=========================
  3019. var eachMaxWeights = {
  3020. //大小限制
  3021. "photo": 10,
  3022. "video": 1000,//50, expand size for overlayVideo
  3023. //20,
  3024. "audio": 10, //5
  3025. "model": 5
  3026. }
  3027. var supportTypes = {
  3028. //支持后缀
  3029. "photo": ["jpg", "png", "jpeg", "bmp", "gif"],
  3030. "audio": ["mp3", "aac", "ogg", "wav"/* , "m4a" */],
  3031. "video": ["mp4", "mov" ,"webm",/* "rmvb", "wmv" */],//ios:mov
  3032. 'model':["obj"]
  3033. }
  3034. function getExt(name) {
  3035. //后缀
  3036. if (name.indexOf('.') > -1) {
  3037. var a = name.split(".");
  3038. return a.pop();
  3039. } else {
  3040. return '';
  3041. }
  3042. }
  3043. function detectType(fileName) {
  3044. //检测文件后缀类型
  3045. console.log("名:" + fileName)
  3046. var ext = getExt(fileName);
  3047. console.log("后缀:" + ext)
  3048. //不一定所有浏览器都可以
  3049. var type;
  3050. //仅能根据后缀判断类型,尽管后缀可能被修改。 其他方法如file.type和base64开头的字符串均是根据后缀。
  3051. for (var i in supportTypes) {
  3052. if (supportTypes[i].indexOf(ext.toLowerCase()) > -1) {
  3053. type = i;
  3054. break;
  3055. }
  3056. }
  3057. if (type) {
  3058. return type;
  3059. } else {
  3060. return false;
  3061. }
  3062. }
  3063. //手机上的相片会不会太大?
  3064. var detectWeights = function(file, type) {
  3065. //检测大小
  3066. var size = file.size / 1024 / 1024;
  3067. console.log("weight" + size)
  3068. var over;
  3069. if (size > eachMaxWeights[type]) {
  3070. over = Math.ceil(size * 100) / 100;
  3071. }
  3072. return over;
  3073. }
  3074. var exitUpload = function(input) {
  3075. $('.waiting').removeClass('showloading');
  3076. input.value = "";
  3077. }
  3078. var inputMedia = function(options, type, e) {
  3079. var input = e.target;
  3080. if (!window.FileReader) {
  3081. alert('您的浏览器不支持上传文件');
  3082. exitUpload(input);
  3083. return;
  3084. } else if (e.target.files.length === 0) {
  3085. /* exitUpload(input); */
  3086. return;
  3087. }
  3088. $('.waiting').addClass('showloading');
  3089. var file = e.target.files[0];
  3090. var elemType = type;
  3091. var inputType = detectType(file.name);
  3092. var chType = {
  3093. "photo": '图片',
  3094. "video": '视频',
  3095. "audio": '音乐',
  3096. 'model': '模型'
  3097. }
  3098. var overWeight = detectWeights(file, inputType);
  3099. if (elemType) {
  3100. //有指定其中一种类型
  3101. if (inputType != elemType) {
  3102. alert("您选择的不是浏览器支持的" + chType[elemType] + '文件,请重新选择');
  3103. exitUpload(e.target);
  3104. return;
  3105. }
  3106. } else {
  3107. if (!options.enableTypes.includes(inputType)) {
  3108. var text = "";
  3109. options.enableTypes.forEach((type,index)=>{
  3110. text += ((index != 0 ? " / " : "") + chType[elemType])
  3111. }
  3112. )
  3113. alert("您选择的不是浏览器支持的" + text + '文件,请重新选择');
  3114. exitUpload(e.target);
  3115. return;
  3116. }
  3117. }
  3118. if (overWeight) {
  3119. alert(`文件过大(${overWeight}兆),不能大于${eachMaxWeights[inputType]} 兆`)
  3120. exitUpload(e.target);
  3121. return;
  3122. }
  3123. var loadError = function() {
  3124. exitUpload(e.target);
  3125. alert(`文件出错, 无法加载此${chType[inputType]}文件。 文件可能损坏,或者浏览器不支持,或者后缀与文件不匹配。建议在IE以外的浏览器上传`)
  3126. }
  3127. deal(type);
  3128. function deal(type) {
  3129. console.log('开始deal文件')
  3130. var reader = new FileReader();
  3131. //reader.name = file.name;
  3132. if(type == 'model'){
  3133. reader.readAsText( file );
  3134. }else{
  3135. reader.readAsDataURL(file);
  3136. }
  3137. reader.onload = function(evt) {
  3138. if (inputType == "model") {
  3139. var object = new THREE.OBJLoader().parse( evt.target.result );
  3140. options.modelDone(file, object)
  3141. $('.waiting').removeClass('showloading');
  3142. return;
  3143. }
  3144. var blob = dataURLtoBlob(evt.target.result);
  3145. var blobSrc = window.URL.createObjectURL(blob);
  3146. if (inputType == "photo") {
  3147. /* EXIF.getData(file, function () {
  3148. //获取相片旋转
  3149. EXIF.getAllTags(this);
  3150. var orient = EXIF.getTag(this, 'Orientation');
  3151. var img = new Image();
  3152. img.src = evt.target.result;
  3153. img.onload = function (e) { //这时img才有宽高,才能赋予texture宽高
  3154. var smallerImg = CompressImg(e.target, {
  3155. weight: blob.size,
  3156. maxWeight: 0.5 * 1024 * 1024,
  3157. maxSize: 1480
  3158. });
  3159. //最大500k
  3160. smallerImg.onload = function () {
  3161. var f = function (resultImg) {//处理结束回调
  3162. options.photoDone(resultImg)
  3163. $('.waiting').removeClass('showloading');
  3164. }
  3165. Rotate(smallerImg, orient, f)
  3166. window.URL.revokeObjectURL(blobSrc);
  3167. }
  3168. }
  3169. .bind(this)
  3170. img.onerror = loadError;
  3171. }); */
  3172. var img = new Image();
  3173. img.setAttribute("crossOrigin", 'Anonymous')//要在src设置好前解决跨域
  3174. img.src = blobSrc;
  3175. img.base64Src = evt.target.result;
  3176. img.file = file;
  3177. img.onload = function(e) {
  3178. options.photoDone(img)
  3179. $('.waiting').removeClass('showloading');
  3180. img.onload = null //防止src重新赋值后又触发
  3181. }
  3182. } else if (inputType == "video") {
  3183. var video = $('<video controls="controls" x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload"></video>')[0]
  3184. video.setAttribute("crossOrigin", 'Anonymous')
  3185. //要在src设置好前解决跨域
  3186. $(video).on('contextmenu', function() {
  3187. return false;
  3188. });
  3189. //禁止右键点击出现选项(尤其是下载选项)
  3190. $(video).attr('src', blobSrc);
  3191. //华为无法使用blobSrc,否则加载不出来
  3192. //$(video).attr('src', evt.target.result);
  3193. video.base64Src = evt.target.result;
  3194. var hasload = false;
  3195. var error = false;
  3196. var up = function() {
  3197. if (hasload)
  3198. return;
  3199. hasload = true;
  3200. options.videoDone(file, video)
  3201. $('.waiting').removeClass('showloading');
  3202. }
  3203. video.addEventListener('loadeddata', function(e) {
  3204. up()
  3205. })
  3206. //video.onerror = loadError;
  3207. video.onerror = function(e) {
  3208. console.log('error')
  3209. error = true;
  3210. loadError();
  3211. //将mp4改成mov后缀会error
  3212. }
  3213. } else if (inputType == "audio") {
  3214. //林俊波 new Howl For IE&Safari:
  3215. var sound = new Howl({
  3216. src: [blobSrc],
  3217. format: ["mp3"]
  3218. });
  3219. // Clear listener after first call.
  3220. sound.once('load', function() {
  3221. console.log('loaded sound')
  3222. sound.unload()
  3223. console.log("audio.onloadeddata");
  3224. var audio = new Audio;
  3225. audio.controls = "controls";
  3226. audio.src = blobSrc;
  3227. audio.base64Src = evt.target.result;
  3228. options.audioDone(file, audio)
  3229. $('.waiting').removeClass('showloading');
  3230. //}
  3231. });
  3232. sound.once('loaderror', function() {
  3233. loadError.apply(this, arguments)
  3234. console.log('loaderror sound')
  3235. });
  3236. // Fires when the sound finishes playing.
  3237. sound.on('end', function() {
  3238. console.log('Finished sound');
  3239. });
  3240. }
  3241. }
  3242. }
  3243. e.target.value = "";
  3244. //更改value会触发change
  3245. }
  3246. .bind(player)
  3247. //滑动条控件
  3248. var SlideBar = function(o) {
  3249. var scope = this;
  3250. this.name = o.name;
  3251. this.value = o.value;
  3252. //初始值
  3253. this.min = o.min != void 0 ? o.min : 0;
  3254. this.max = this.oriMax = o.max != void 0 ? o.max : 100;
  3255. this.noValue = o.noValue;
  3256. //是否数值输入
  3257. this.precision = o.precision;
  3258. //精度 保留几位小数
  3259. 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>'))
  3260. div.addClass('slider')
  3261. if (o.unitStr) {
  3262. div.find(".BarTxt").append($('<span>' + o.unitStr + '</span>'));
  3263. }
  3264. o.root.append(div);
  3265. this.line = $(".scrollBar", div);
  3266. this.knot = $(".scroll_Thumb", div);
  3267. o.noValue || (this.textArea = $(".scrollBarTxt", div));
  3268. this.track = $(".scroll_Track", div);
  3269. this.unitStr = o.unitStr;
  3270. //unitStr是单位字符串,比如角度的°。不能是数字
  3271. this.onchange = o.onchange;
  3272. this.percent = null;
  3273. this.dragStart = false;
  3274. this.offsetToBody = null;
  3275. this.getOffset();
  3276. this.checkError();
  3277. this.percent = this.getPercent();
  3278. o.noValue || this.displayValue();
  3279. this.moveKnot();
  3280. this.knotWidth = 0;
  3281. this.lineWidth = 0;
  3282. //this.waitValue;//等待要触发事件的值,防止崩溃
  3283. this.avoidCrash = o.avoidCrash;
  3284. this.realMax = !this.noValue ? o.realMax : null;
  3285. //如果传入realMax,代表可以通过输入数字修改最大值范围,最大值不可以超过realMax。
  3286. this.scrollUnit = (scope.max - scope.min) * 0.001;
  3287. if (this.precision != void 0) {
  3288. var prec = Math.pow(10, -this.precision);
  3289. this.scrollUnit < prec && (this.scrollUnit = prec);
  3290. } else {
  3291. //默认化为整数
  3292. this.scrollUnit < 1 && (this.scrollUnit = 1);
  3293. }
  3294. this.dragStartEvent = o.dragStartEvent;
  3295. this.line.on("mousedown touchstart", function(event) {
  3296. scope.dragStart = true;
  3297. scope.dragChange(event);
  3298. if (scope.dragStartEvent)
  3299. scope.dragStartEvent()
  3300. //if(o.avoidCrash && isMobile)scope.dealInterval();
  3301. });
  3302. !window.isMobile && this.line.on("mousewheel DOMMouseScroll wheel", function(event) {
  3303. event.preventDefault();
  3304. var v = event.originalEvent.deltaY > 0 ? -scope.scrollUnit : scope.scrollUnit;
  3305. scope.setValue(scope.value + v);
  3306. });
  3307. this.dragEndEvent = o.dragEndEvent;
  3308. var stop = function() {
  3309. if (scope.dragStart) {
  3310. scope.dragStart = false;
  3311. if (scope.dragEndEvent)
  3312. scope.dragEndEvent()
  3313. }
  3314. }
  3315. $(document).on("mouseup touchend", stop)
  3316. /* isMobile || */
  3317. $("#player").on("mouseup", stop)
  3318. var lastChangeTime = 0;
  3319. $(document).on("mousemove touchmove", function() {
  3320. if (scope.dragStart) {
  3321. /* if(isMobile && o.avoidCrash){
  3322. scope.lastDragEvent = event;
  3323. }else */
  3324. scope.dragChange(event);
  3325. }
  3326. })
  3327. o.noValue || this.textArea.on("change", function() {
  3328. var v = parseFloat(scope.textArea.val());
  3329. if (v != v)
  3330. //NaN
  3331. return;
  3332. scope.setValueFromOutside(v);
  3333. });
  3334. window.addEventListener("resize",()=>{
  3335. if(this.line[0].clientWidth){
  3336. this.getOffset()
  3337. this.moveKnot();
  3338. }
  3339. })
  3340. }
  3341. SlideBar.prototype.dealInterval = function() {
  3342. this.interval = setInterval(function() {
  3343. this.lastDragEvent && this.dragChange(this.lastDragEvent);
  3344. this.lastDragEvent = null
  3345. if (!this.dragStart)
  3346. clearInterval(this.interval)
  3347. }
  3348. .bind(this), 90)
  3349. }
  3350. SlideBar.prototype.changeLimit = function(o) {
  3351. if (o.min)
  3352. this.min = o.min;
  3353. if (o.max)
  3354. this.max = o.max;
  3355. }
  3356. SlideBar.prototype.getOffset = function() {
  3357. //为了检测鼠标位置需要获得相对body的offset
  3358. var left = this.line[0].offsetLeft;
  3359. var element = this.line[0];
  3360. while (element = element.offsetParent) {
  3361. left += element.offsetLeft;
  3362. }
  3363. this.offsetToBody = (left == 0) ? (this.offsetToBody || 0) : left;
  3364. //如果left为0,很可能是它不可见,那么最好使用旧的offsetToBody
  3365. }
  3366. SlideBar.prototype.InitOffset = function() {
  3367. //如果一开始scroller没有显示,要在显示时获取一下offset
  3368. this.getOffset();
  3369. this.getWidth();
  3370. this.moveKnot();
  3371. }
  3372. SlideBar.prototype.checkError = function() {
  3373. if (this.min >= this.max) {
  3374. console.log("scrollbar值有误 " + name);
  3375. return;
  3376. }
  3377. }
  3378. SlideBar.prototype.getPercent = function() {
  3379. return (this.value - this.min) / (this.max - this.min);
  3380. }
  3381. SlideBar.prototype.displayValue = function(value) {
  3382. //this.textArea.val(this.value + (this.unitStr ? " " + this.unitStr : ""));
  3383. if (value != void 0)
  3384. this.value = value;
  3385. this.textArea.val(this.value)
  3386. }
  3387. SlideBar.prototype.getWidth = function() {
  3388. this.knotWidth = this.knot.width();
  3389. this.lineWidth = this.line.width() - this.knotWidth
  3390. }
  3391. SlideBar.prototype.moveKnot = function() {
  3392. //this.getWidth();
  3393. var width = this.percent * this.lineWidth;
  3394. this.knot.css('left', width + "px")
  3395. if (this.track)
  3396. this.track.css('width', (width + this.knotWidth / 2) + "px")
  3397. }
  3398. SlideBar.prototype.bind = function(f) {
  3399. this.onchange = f;
  3400. }
  3401. SlideBar.prototype.setValue = function(v, noEvent, changeMax) {
  3402. //设置数值并改变knot位置 noEvent为true的话就可以不触发回调函数,仅仅改变显示
  3403. //if(this.value==v)return; //因为换选材质需要执行后面onchange才会带动preview的改变,所以这里一样还是执行,而拉动滑动条的部分值不变就不执行
  3404. if (this.precision != void 0) {
  3405. this.value = parseFloat(v.toFixed(this.precision))
  3406. } else {
  3407. //默认化为整数
  3408. this.value = Math.round(v);
  3409. }
  3410. this.value = THREE.Math.clamp(this.value, this.min, this.max)
  3411. if (changeMax && this.realMax != void 0) {
  3412. if (this.value > this.oriMax) {
  3413. this.value = Math.min(this.value, this.realMax);
  3414. this.changeLimit({
  3415. max: this.value
  3416. })
  3417. } else {
  3418. this.changeLimit({
  3419. max: this.oriMax
  3420. })
  3421. }
  3422. }
  3423. this.percent = this.getPercent();
  3424. var makeit = true;
  3425. if (this.onchange && !noEvent) {
  3426. var result = this.onchange(this.value);
  3427. //如果执行的函数不允许这个值,就不能变
  3428. if (result === false) {
  3429. makeit = false;
  3430. }
  3431. }
  3432. if (makeit) {
  3433. this.moveKnot();
  3434. //console.log("SlideBarV-"+this.name + " : "+this.value)
  3435. this.noValue || this.displayValue();
  3436. }
  3437. }
  3438. SlideBar.prototype.dragChange = function(event) {
  3439. //拖动时触发 计算数值
  3440. //this.getWidth();
  3441. //if(!this.offsetToBody || isNaN(this.offsetToBody)this.getOffset();
  3442. if (event.clientX != void 0) {
  3443. this.percent = (event.clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  3444. } else {
  3445. if (event.touches != void 0) {
  3446. this.percent = (event.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  3447. } else
  3448. this.percent = (event.originalEvent.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  3449. }
  3450. if (this.percent < 0)
  3451. this.percent = 0;
  3452. else if (this.percent > 1)
  3453. this.percent = 1;
  3454. //var v = this.percent * this.max;
  3455. var v = this.percent * (this.max - this.min) + this.min;
  3456. //var v = Math.round(this.percent * this.max * 10)/10; //精度为0.1
  3457. if (this.value == v)
  3458. return;
  3459. this.setValue(v);
  3460. }
  3461. SlideBar.prototype.setValueFromOutside = function(v) {
  3462. //外面的事件触发的
  3463. if (this.line.width() == 0)
  3464. return;
  3465. //不可见就不执行。
  3466. //v = Math.round(v*10)/10;
  3467. if (this.realMax != void 0) {
  3468. v = THREE.Math.clamp(v, this.min, this.realMax);
  3469. if (v > this.max)
  3470. this.changeLimit({
  3471. max: v
  3472. });
  3473. } else
  3474. v = THREE.Math.clamp(v, this.min, this.max);
  3475. this.setValue(v);
  3476. }
  3477. //-----------------------------------------------------
  3478. var LineDraw = {
  3479. createLine: function(posArr, o) {
  3480. var e = new THREE.BufferGeometry
  3481. , p = new Float32Array(6);
  3482. e.addAttribute("position", new THREE.BufferAttribute(p,3));
  3483. //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
  3484. var p = e.attributes.position.array;
  3485. for (var i = 0; i < 2; i++) {
  3486. p[i * 3] = posArr[i].x;
  3487. p[i * 3 + 1] = posArr[i].y;
  3488. p[i * 3 + 2] = posArr[i].z;
  3489. }
  3490. var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
  3491. linewidth: o.width || 1,
  3492. //windows无效。 似乎mac/ios上粗细有效 ?
  3493. color: o.color || defaultColor,
  3494. transparent: o.dontAlwaysSeen ? false : true,
  3495. depthTest: o.dontAlwaysSeen ? true : false
  3496. })
  3497. var line = new THREE.Line(e,mat);
  3498. line.renderOrder = o.renderOrder || 4
  3499. //同tagStem; //如果不加高,可能会部分被model遮住
  3500. return line;
  3501. }
  3502. }
  3503. var toPrecision = function(e, t) {
  3504. function i(e, t) {
  3505. var i = Math.pow(10, t);
  3506. return Math.round(e * i) / i
  3507. }
  3508. if (e instanceof Array) {
  3509. for (var n = 0; n < e.length; n++)
  3510. e[n] = i(e[n], t);
  3511. return e
  3512. }
  3513. return i(e, t)
  3514. }
  3515. var transformControls;
  3516. var initTransformCtl = function(THREE) {
  3517. TransformControls.init(THREE)
  3518. TransformControls.prototype.transCtlChangeMode = function(mode) {
  3519. //if(!this.editing)return;
  3520. if (mode && this.mode != mode) {
  3521. this.mode = mode;
  3522. transformControls.children[0].showZ = this.mode != 'scale' || transformControls.scaleShowZ
  3523. }
  3524. }
  3525. ,
  3526. transformControls = new TransformControls(player.camera,player.domElement,{
  3527. player: player,
  3528. dontHideWhenFaceCamera: true,
  3529. /* scaleAxis: ["x", "y"],
  3530. //隐藏了z轴。虽然参数没用上
  3531. NoScaleZ: true //整体缩放时只缩放xy轴。 */
  3532. });
  3533. transformControls.space = 'local'//为了在当前方向上平移
  3534. transformControls.setSize(1.5)
  3535. player.model.add(transformControls)
  3536. /* $(".MenuOptions[name='transform'] li").on("click", (e)=>{
  3537. transformControls.transCtlChangeMode($(e.target).attr("index"))
  3538. }) */
  3539. transformControls.transformMenuOptions = new MenuOptions({
  3540. dom: $(".MenuOptions[name='transform'] "),
  3541. uiCallBack : (o)=>{
  3542. var mode = o.name || o.$li.attr('index')
  3543. transformControls.transCtlChangeMode(mode)
  3544. var hotpointDetail = editTool.hotpoint.hotpointDetail
  3545. hotpointDetail.find(" li[name=setPos] button[name=setSpace] ").css('display',mode == 'scale' ? 'none' : 'block')
  3546. hotpointDetail.find(" li[name=setPos] button[name=useSuitableRatio] ").css('display',mode == 'scale' ? 'block' : 'none')
  3547. hotpointDetail.find(" li[name=setPos] button[name=resetRot] ").css('display',mode == 'rotate' ? 'block' : 'none')
  3548. },
  3549. callbackWhenChose:(o)=>{
  3550. }
  3551. })
  3552. transformControls.enableScaleZ = ()=>{
  3553. if(transformControls.mode == 'scale'){
  3554. transformControls.children[0].showZ = true
  3555. }
  3556. transformControls.scaleShowZ = true
  3557. }
  3558. transformControls.unableScaleZ = ()=>{
  3559. if(transformControls.mode == 'scale'){
  3560. transformControls.children[0].showZ = false
  3561. }
  3562. transformControls.scaleShowZ = false
  3563. }
  3564. }
  3565. //----------------漫游可见性---------------------------------
  3566. var VisiSet = {
  3567. setPanoVisible: false,
  3568. setTagVisible: false,
  3569. setPanoLog:false,
  3570. panoVLines: {},
  3571. //线条
  3572. panoVTemp: {},
  3573. //修改后还没保存的临时数据
  3574. tagVsetting: null,
  3575. //正在设置的热点中心点
  3576. tagsVLines: {},
  3577. //线条
  3578. //tagVTemp //修改后还没保存的临时数据
  3579. $confirmSnap: $("#camera-start"),
  3580. changeBtn : $(".toolMid .midBottom #midBtns>button").eq(1),
  3581. colors: {
  3582. green: "#00c8ae"
  3583. },
  3584. init: function() {
  3585. this.footIconSizeRatio = Math.max(player.model.size.x, player.model.size.z) / 30;
  3586. this.meshGroup = new THREE.Object3D;
  3587. this.meshGroup.name = "setVisible-group"
  3588. player.model.add(this.meshGroup)
  3589. $("#hotVisible button").on("click", ()=>{
  3590. VisiSet.enterSet(VisiSet.beginSetTagVisible.bind(VisiSet))
  3591. })
  3592. this.changeBtn.on("click",()=>{//隐藏与显示该点
  3593. if(this.changeBtn.attr("function") == "hide"){
  3594. for(let i in this.panoVLines){
  3595. this.panoVLines[i].visible && this.dealPanoVisible(i);
  3596. }
  3597. }else{
  3598. //显示该点时,显示周围一定距离内、到该点没有遮挡的pano
  3599. //?????
  3600. var list = player.model.panos.sortByScore([e=>e.isAligned()], [(pano)=>{return -pano.position.distanceTo(this.panoVsetting.position)}])
  3601. if(list.length == 1){
  3602. console.log('仅有一个漫游点')
  3603. return;
  3604. }
  3605. var ifBlock = function(panoA, panoB ){
  3606. var A = panoA.position.clone();
  3607. var B = panoB.position.clone();
  3608. return convertTool.ifIntersectChunks(A, B, {})
  3609. }
  3610. var okList
  3611. var s = Math.max(-list[1].score*2, 4); //i==1的一定显示
  3612. for(var i=1;i<list.length;i++){
  3613. if(-list[i].score < s){
  3614. if(ifBlock(this.panoVsetting, list[i].pano)){
  3615. list[i].block = true //有阻挡
  3616. }
  3617. list[i].good = true
  3618. }else{
  3619. okList || (okList = list.filter(e=>e.good && !e.block));//绝对可以使用的
  3620. if(okList.length <2 ){
  3621. if(!ifBlock(this.panoVsetting, list[i].pano)){
  3622. if(okList.length == 0){
  3623. okList.push(list[i])
  3624. }else{//1
  3625. var lastPos = okList[0].pano.position.clone().sub(this.panoVsetting.position).setY(0);
  3626. var thisPos = list[i].pano.position.clone().sub(this.panoVsetting.position).setY(0);
  3627. if(lastPos.angleTo(thisPos) > Math.PI / 2){
  3628. console.log('再加一个 角度'+THREE.Math.radToDeg(lastPos.angleTo(thisPos)))
  3629. break;
  3630. }
  3631. }
  3632. }
  3633. }else{
  3634. break;
  3635. }
  3636. }
  3637. }
  3638. if(okList.length==0){//如果length为0,至少加一个pano, 虽然是遮挡的
  3639. okList.push(list[0].pano)
  3640. }
  3641. okList.forEach(e=>this.dealPanoVisible(e.pano.id))
  3642. console.log(okList)
  3643. }
  3644. })
  3645. },
  3646. enterSet: function(fun) {
  3647. var enter = function() {
  3648. if (player.modeTran.split('-')[1] != "floorplan") {
  3649. setTimeout(fun, 300)
  3650. //提前一点出现
  3651. }
  3652. player.flyToMode("floorplan", fun);
  3653. }
  3654. permitTranMode(false)
  3655. if (!player.modeTran) {
  3656. player.afterCModeFuc = ()=>{
  3657. enter()
  3658. }
  3659. } else
  3660. enter()
  3661. },
  3662. beginSetPanoLog: function() {
  3663. player.flying || $(".toolLeft").removeClass("unable")
  3664. if (this.setPanoLog)
  3665. return;
  3666. this.setPanoLog = true
  3667. this.panosSelect = []
  3668. this.updateFootIconSize()
  3669. this.showFootIcons(null, true);
  3670. for(let i in player.model.hots){
  3671. player.model.hots[i].visi_ = player.model.hots[i].visible;
  3672. player.model.hots[i].visible = false
  3673. }
  3674. player.model.panos.forEach(e=>{
  3675. e.addTextSprite(e.id, $('#panoIdColorTex').val(), e.footIcon)
  3676. })
  3677. },
  3678. finishSetPanoLog: function() {
  3679. //结束 退出这个设置
  3680. if (!this.setPanoLog)
  3681. return;
  3682. //否则会加多个侦听
  3683. this.setPanoLog = false;
  3684. this.hideFootIcons();
  3685. this.recoverAllState2();
  3686. this.panosSelect = null
  3687. player.flyoutType = null
  3688. permitTranMode(true)
  3689. for(let i in player.model.hots){
  3690. player.model.hots[i].visible = player.model.hots[i].visi_
  3691. }
  3692. $("#panosIdShow").val('')
  3693. player.model.panos.forEach(e=>{
  3694. e.removeTextSprite()
  3695. })
  3696. },
  3697. dealPanoLogClick: function(object) {
  3698. var id = object.name == '' ? object.parent.name : object.name
  3699. var panos = player.model.panos;
  3700. var index = this.panosSelect.indexOf(id)
  3701. if (index==-1) {
  3702. this.changeFIconState(panos.index[id].footIcon, "linked" )
  3703. this.panosSelect.push(id)
  3704. }else{
  3705. this.changeFIconState(panos.index[id].footIcon, false)
  3706. this.panosSelect.splice(index,1)
  3707. }
  3708. $("#panosIdShow").val('"'+this.panosSelect.join('","')+'"');
  3709. }
  3710. ,
  3711. changePanoIdColor:function(color){
  3712. player.model.panos.forEach(e=>{
  3713. e.removeTextSprite();
  3714. e.addTextSprite(e.id,color, e.footIcon)
  3715. })
  3716. }
  3717. ,
  3718. //--------------
  3719. beginSetPanoVisible: function() {
  3720. player.flying || $(".toolLeft").removeClass("unable")
  3721. if (this.setPanoVisible)
  3722. return;
  3723. this.setPanoVisible = true;
  3724. this.panoVTemp = {};
  3725. this.SetOnePanoVisible(player.currentPano)
  3726. //先设置currentPano
  3727. this.$confirmSnap.text('保存当前设置').removeClass("hide")
  3728. //objects.tagManager.hideAllTags();
  3729. this.setDisplay(true)
  3730. this.updateFootIconSize()
  3731. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  3732. for(let i in player.model.hots){
  3733. player.model.hots[i].visi_ = player.model.hots[i].mesh.visible;
  3734. player.model.hots[i].mesh.visible = false
  3735. }
  3736. },
  3737. SetOnePanoVisible: function(pano) {
  3738. //点击某个pano后就对该pano点进行设置
  3739. if (this.panoVsetting == pano)
  3740. return;
  3741. //if (this.panoVsetting) saveLastPanoVi(this.panoVsetting);
  3742. this.panoVsetting = pano;
  3743. //记录正在修改的
  3744. this.delVisibleLines();
  3745. //删除线
  3746. this.showFootIcons(pano, true);
  3747. this.createPanoVisiLines(pano);
  3748. //创线
  3749. this.changeBtn.removeClass('hide')
  3750. },
  3751. saveLastPanoVi: function() {
  3752. //保存刚设置过的pano
  3753. var change = [];
  3754. for (var r in this.panoVLines) {
  3755. var line = this.panoVLines[r];
  3756. if (line.name.indexOf("new") > -1 && line.visible) {
  3757. //新设置为visible且没有取消
  3758. change.push({
  3759. type: "add",
  3760. id: r
  3761. })
  3762. } else if (line.name.indexOf("new") == -1 && !line.visible) {
  3763. //旧的且已经取消
  3764. change.push({
  3765. type: "sub",
  3766. id: r
  3767. })
  3768. }
  3769. }
  3770. if (change.length) {
  3771. //添加双向的neighbour:
  3772. var self = this.searchNeib(this.panoVsetting.id)
  3773. //var seeMarkers_self = self.seeMarkers;
  3774. var neighbourUUIDs_self = self.neighbourUUIDs
  3775. var neighbourPanos_self = self.neighbourPanos;
  3776. for (var i = 0; i < change.length; i++) {
  3777. var other = this.searchNeib(change[i].id)
  3778. //var seeMarkers = other.seeMarkers;
  3779. var neighbourUUIDs = other.neighbourUUIDs;
  3780. var neighbourPanos = other.neighbourPanos;
  3781. if (change[i].type == "add") {
  3782. //seeMarkers.push(this.panoVsetting.id);
  3783. neighbourUUIDs.push(this.panoVsetting.id);
  3784. neighbourPanos[this.panoVsetting.id] = true;
  3785. //seeMarkers_self.push(change[i].id);
  3786. neighbourUUIDs_self.push(change[i].id);
  3787. neighbourPanos_self[change[i].id] = true;
  3788. } else {
  3789. //var index = seeMarkers.indexOf(this.panoVsetting.id);
  3790. //index > -1 && seeMarkers.splice(index, 1);
  3791. var index = neighbourUUIDs.indexOf(this.panoVsetting.id);
  3792. index > -1 && neighbourUUIDs.splice(index, 1);
  3793. neighbourPanos[this.panoVsetting.id] = false;
  3794. //var index = seeMarkers_self.indexOf(change[i].id);
  3795. //index > -1 && seeMarkers_self.splice(index, 1);
  3796. var index = neighbourUUIDs_self.indexOf(change[i].id);
  3797. index > -1 && neighbourUUIDs_self.splice(index, 1);
  3798. neighbourPanos_self[change[i].id] = false;
  3799. }
  3800. this.panoVTemp[change[i].id] = {
  3801. //后面两个是作为保存到后台的数据存储,临时需要用到的是第一个
  3802. neighbourPanos: neighbourPanos,
  3803. //seeMarkers: seeMarkers,
  3804. neighbourUUIDs: neighbourUUIDs
  3805. }
  3806. }
  3807. this.panoVTemp[this.panoVsetting.id] = {
  3808. //加上自己
  3809. neighbourPanos: neighbourPanos_self,
  3810. //seeMarkers: seeMarkers_self,
  3811. neighbourUUIDs: neighbourUUIDs_self
  3812. }
  3813. }
  3814. },
  3815. pauseSetPanoVisible: function(type) {
  3816. //暂停 因为点击了保存设置 但没有退出设置
  3817. if (!this.setPanoVisible)
  3818. return;
  3819. if (type == "unsaved") {
  3820. //中途点击pano从而停止一个热点的设置
  3821. this.saveLastPanoVi();
  3822. } else {
  3823. this.panoVTemp = {};
  3824. //清空数据
  3825. }
  3826. this.delVisibleLines();
  3827. this.showFootIcons();
  3828. //清空选择
  3829. var lastPanoSetting = this.panoVsetting;
  3830. this.panoVsetting = null;
  3831. lastPanoSetting && this.changeFIconState2(lastPanoSetting.footIcon, this.checkHasNeighbor(lastPanoSetting))
  3832. //这句要放在this.panoVsetting = null后。 根据可见性更改透明度
  3833. this.changeBtn.addClass('hide')
  3834. },
  3835. //按理说改变了neighbourPano,tag的初始visible也要改。但是这样还要考虑已经改过的tag。。很麻烦
  3836. finishSetPanoVisible: function() {
  3837. //结束 退出这个设置
  3838. if (!this.setPanoVisible)
  3839. return;
  3840. //否则会加多个侦听
  3841. this.setPanoVisible = false;
  3842. this.hideFootIcons();
  3843. this.delVisibleLines();
  3844. //objects.tagManager.showAllTags();
  3845. this.recoverAllState2();
  3846. this.panoVsetting = null;
  3847. this.panoVTemp = {};
  3848. player.flyoutType = null
  3849. this.$confirmSnap.addClass("hide")
  3850. permitTranMode(true)
  3851. this.setDisplay(false)
  3852. for(let i in player.model.hots){
  3853. player.model.hots[i].mesh.visible = player.model.hots[i].visi_
  3854. }
  3855. },
  3856. changeVisiBtnState: function(state){
  3857. this.changeBtn.attr("function", state ? "hide" : "show")
  3858. this.changeBtn.html(state ? "隐藏该点位置":"显示该点位置")
  3859. },
  3860. recoverAllState2: function() {
  3861. //为了热点可视恢复成pano全部可见
  3862. if(!this.footIcons)return;
  3863. for (var i = 0; i < this.footIcons.length; i++) {
  3864. this.footIcons[i].material.uniforms.opacity.value = 1;
  3865. this.footIcons[i].material.uniforms.map.value = footTex1;
  3866. }
  3867. },
  3868. afterSavePanoVisibles: function() {
  3869. //实施:
  3870. var panos = player.model.panos;
  3871. for (var i in this.panoVTemp) {
  3872. var pano = panos.index[i];
  3873. //pano.seeMarkers = this.panoVTemp[i].seeMarkers;
  3874. pano.neighbourUUIDs = this.panoVTemp[i].neighbourUUIDs;
  3875. pano.neighbourPanos = this.panoVTemp[i].neighbourPanos;
  3876. }
  3877. if (!this.checkHasNeighbor(player.currentPano)) {
  3878. //currentPano变为孤立点 就要换一个防止飞入
  3879. var list = panos.sortByScore([pano=>{
  3880. return this.checkHasNeighbor(pano)
  3881. }
  3882. ], [function(pano) {
  3883. return -pano.position.distanceTo(player.currentPano.position)
  3884. }
  3885. ])
  3886. if (list && list.length) {
  3887. player.currentPano = list[0].pano;
  3888. //找最近的一非孤立点
  3889. //this.noPanoHasNeighbor = false; //更新状态
  3890. } else {//this.noPanoHasNeighbor = true; //更新状态
  3891. }
  3892. } else {//this.noPanoHasNeighbor = false; //更新状态
  3893. }
  3894. //dataDeal.done();
  3895. //暂时:
  3896. this.pauseSetPanoVisible()
  3897. this.updateFootIconSize()
  3898. //更新一下center大小 写在最后
  3899. },
  3900. //最佳推荐操作顺序: 先设置pano可见性 再创建热点 这样热点的visible正确些,否则之后再设置热点可见性会改更多
  3901. savePanoVisibles: function() {
  3902. //保存
  3903. if (this.panoVsetting)
  3904. this.saveLastPanoVi(this.panoVsetting);
  3905. //获取最后设置的那个热点的改动
  3906. var PanoData = [];
  3907. for (var i in this.panoVTemp) {
  3908. PanoData.push({
  3909. //希望算法部不会更改index排序,或者更改后能将visible信息一并更改
  3910. panoID: i,
  3911. //visibles: this.turnToPanoIndex(this.panoVTemp[i].seeMarkers),
  3912. visibles3: this.turnToPanoIndex(this.panoVTemp[i].neighbourUUIDs)
  3913. })
  3914. }
  3915. if (PanoData.length == 0) {
  3916. //没改变
  3917. alert("保存成功")
  3918. return;
  3919. }
  3920. /* this.afterSavePanoVisibles()
  3921. alert("保存成功")
  3922. console.log(JSON.stringify(PanoData)) */
  3923. let url = cmp ? ('/api/scene/roamViable/' + cmp) : '/manage/scene/roamViable'
  3924. $.ajax({
  3925. method: 'POST',
  3926. url: ceshi + url,
  3927. headers: {
  3928. 'Content-Type': 'application/json',
  3929. token: token
  3930. },
  3931. contentType: 'application/json',
  3932. data: JSON.stringify({
  3933. data: JSON.stringify(PanoData),
  3934. sceneCode: window.number
  3935. }),
  3936. success: (data)=>{
  3937. if (data.code === 0) {
  3938. this.afterSavePanoVisibles()
  3939. alert("保存漫游可行成功")
  3940. } else
  3941. alert("保存漫游可行失败")
  3942. if (data.code === 5001) {
  3943. alert('请重新登录')
  3944. localStorage.dcj_token = ''
  3945. location.reload()
  3946. }
  3947. }
  3948. ,
  3949. fail: function() {
  3950. alert("保存漫游可行失败")
  3951. }
  3952. })
  3953. /* var o = {
  3954. name_t: "panoVisible",
  3955. f: this.pauseSetPanoVisible,
  3956. url: Config.prefixEditProPCApi+"/saveLinkPano",
  3957. dialog: i18n.get('设置'),
  3958. data: { data: JSON.stringify(PanoData) }
  3959. }
  3960. var dataDeal = uploadsSaving.saveFucforPC(o);
  3961. dataDeal.group[0] = function () {
  3962. //实施:
  3963. for (var i in player.panoVTemp) {
  3964. var pano = player.model.panos.index[i];
  3965. pano.seeMarkers = player.panoVTemp[i].seeMarkers;
  3966. pano.neighbourUUIDs = player.panoVTemp[i].neighbourUUIDs;
  3967. pano.neighbourPanos = player.panoVTemp[i].neighbourPanos;
  3968. }
  3969. if(!player.model.checkHasNeighbor(player.currentPano)){//currentPano变为孤立点 就要换一个防止飞入
  3970. var list = player.model.panos.sortByScore([function(pano){return player.model.checkHasNeighbor(pano)}],
  3971. [function(pano){return -pano.position.distanceTo(player.currentPano.position)}])
  3972. if(list && list.length){
  3973. player.currentPano = list[0].pano;//找最近的一非孤立点
  3974. player.model.noPanoHasNeighbor = false; //更新状态
  3975. }else{
  3976. player.model.noPanoHasNeighbor = true; //更新状态
  3977. }
  3978. }else{
  3979. player.model.noPanoHasNeighbor = false; //更新状态
  3980. }
  3981. dataDeal.done();
  3982. player.model.updateFootIconSize(player.cameraControls.activeControl)//更新一下center大小 写在最后
  3983. } */
  3984. },
  3985. searchNeib: function(panoId) {
  3986. //寻找某pano的相关neighbour 可能是修改过的
  3987. var panos = player.model.panos;
  3988. var o = {};
  3989. if (this.panoVTemp[panoId]) {
  3990. //o.seeMarkers = this.panoVTemp[panoId].seeMarkers;
  3991. o.neighbourUUIDs = this.panoVTemp[panoId].neighbourUUIDs;
  3992. o.neighbourPanos = this.panoVTemp[panoId].neighbourPanos;
  3993. } else {
  3994. //o.seeMarkers = panos.index[panoId].seeMarkers.slice(0);
  3995. o.neighbourUUIDs = panos.index[panoId].neighbourUUIDs.slice(0);
  3996. o.neighbourPanos = CloneObject(panos.index[panoId].neighbourPanos);
  3997. }
  3998. return o;
  3999. },
  4000. turnToPanoIndex: function(panoArr) {
  4001. var array = [];
  4002. for (var i = 0; i < panoArr.length; i++) {
  4003. var pano = player.model.panos.index[panoArr[i]]//可能undefined,只是存在在panoListOriData中,因在this.data.sweeps[e.uuid].enabled是false
  4004. if(pano){
  4005. var index = window.panoListOriData.indexOf(pano.id)
  4006. array.push(index);
  4007. }
  4008. }
  4009. return array;
  4010. },
  4011. setDisplay: function(state) {
  4012. var panos = player.model.panos;
  4013. if (state) {
  4014. this.$confirmSnap.text('保存当前设置');
  4015. this.$confirmSnap.removeClass('hide');
  4016. } else {
  4017. this.$confirmSnap.addClass('hide');
  4018. this.changeBtn.addClass('hide')
  4019. }
  4020. player.path.currentPanoMarker.mesh.visible = !state;
  4021. player.reticule.visible = !state;
  4022. },
  4023. delVisibleLines: function() {
  4024. //xzw add 所有线都删除
  4025. for (var i in this.tagsVLines) {
  4026. this.tagsVLines[i].geometry.dispose();
  4027. this.tagsVLines[i].material.dispose();
  4028. this.meshGroup.remove(this.tagsVLines[i]);
  4029. delete this.tagsVLines[i];
  4030. }
  4031. for (var i in this.panoVLines) {
  4032. this.panoVLines[i].geometry.dispose();
  4033. this.panoVLines[i].material.dispose();
  4034. this.meshGroup.remove(this.panoVLines[i]);
  4035. delete this.panoVLines[i];
  4036. }
  4037. },
  4038. //--------panoVisible
  4039. createPanoVisiLines: function(pano) {
  4040. // pano可见性线条
  4041. var neighbours = this.panoVTemp[pano.id] && this.panoVTemp[pano.id].neighbourPanos || pano.neighbourPanos;
  4042. for (var r in neighbours) {
  4043. if (neighbours[r] && r != pano.id) {
  4044. this.createPanoSingleLine(pano, "old", r)
  4045. }
  4046. }
  4047. },
  4048. createPanoSingleLine: function(pano, type, id) {
  4049. //pano是中心
  4050. var panos = player.model.panos;
  4051. var p2 = panos.index[id].footIcon.position.clone()
  4052. /* .sub(player.model.position) */
  4053. var line = LineDraw.createLine([pano.footIcon.position.clone()/* .sub(this.position) */
  4054. , p2], {
  4055. color: this.colors.green
  4056. });
  4057. this.meshGroup.add(line);
  4058. line.name = "PanoVL-" + type + "-" + id;
  4059. this.panoVLines[id] = line;
  4060. this.changeFIconState(panos.index[id].footIcon, "linked")
  4061. },
  4062. dealPanoVisible: function(id) {
  4063. //外部调用
  4064. var panos = player.model.panos;
  4065. if (this.panoVsetting) {
  4066. if (id == this.panoVsetting.id) {
  4067. //关闭当前pano设置
  4068. this.pauseSetPanoVisible('unsaved')
  4069. } else {
  4070. var link;
  4071. //结果是否连接
  4072. if (this.panoVLines[id]) {
  4073. this.panoVLines[id].visible = !this.panoVLines[id].visible;
  4074. link = this.panoVLines[id].visible;
  4075. this.changeFIconState(panos.index[id].footIcon, this.panoVLines[id].visible ? "linked" : false)
  4076. } else {
  4077. this.createPanoSingleLine(this.panoVsetting, "new", id)
  4078. link = true;
  4079. }
  4080. if (link) {
  4081. //如果连接上了,直接判断该点是可见的(有附近点),(不能通过checkHasNeighbor来判断,因为新增的线条可能不在它的neighbour中
  4082. this.changeFIconState2(panos.index[id].footIcon, true)
  4083. this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, true)
  4084. } else {
  4085. //否则需要checkHasNeighbor
  4086. this.changeFIconState2(panos.index[id].footIcon, this.checkHasNeighbor(panos.index[id]))
  4087. this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, this.checkHasNeighbor(this.panoVsetting))
  4088. }
  4089. /* if(window.routeArray){//箭头路线
  4090. if(this.panoVLines[id].visible)window.routeArray.push(id)
  4091. else{
  4092. let index = window.routeArray.indexOf(id)
  4093. index > -1 && routeArray.splice(index, 1)
  4094. }
  4095. } */
  4096. }
  4097. } else {
  4098. //点击开始设置要设置的pano
  4099. this.SetOnePanoVisible(panos.index[id])
  4100. }
  4101. this.updateFootIconSize()
  4102. },
  4103. showFootIcons: function(pano, isPanovisible) {
  4104. if (!this.footIcons) {
  4105. footTex1 = Texture.load("images/edit/End_128.png");
  4106. //Store.FootIcon);
  4107. footTex2 = Texture.load("images/edit/End_unable_128.png");
  4108. //Store.FootIcon_unable);
  4109. this.footIcons = [];
  4110. var scale = 0.4;
  4111. scale *= 40 / Math.sqrt(Math.min($("#player").width(), $("#player").height()));
  4112. //屏幕越小,放得越大
  4113. scale = THREE.Math.clamp(scale, 0.3, 0.7)
  4114. //console.log("scale"+scale)
  4115. var geo = new THREE.PlaneGeometry(scale,scale,1,1)
  4116. var panos = player.model.panos;
  4117. for (var r in panos.index) {
  4118. if (!panos.index[r].isAligned())
  4119. continue;
  4120. var t = THREE.UniformsUtils.clone(shaders.waypoint.uniforms);
  4121. t.map.value = footTex1
  4122. t.color.value.set("#ffffff");
  4123. var mat = new THREE.RawShaderMaterial({
  4124. vertexShader: shaders.waypoint.vertexShader,
  4125. fragmentShader: shaders.waypoint.fragmentShader,
  4126. uniforms: t,
  4127. side: THREE.DoubleSide,
  4128. transparent: !0,
  4129. depthWrite: !1,
  4130. depthTest: false,
  4131. name: "footIcon"
  4132. })
  4133. var foot = new THREE.Mesh(geo,mat)
  4134. foot.position.copy( panos.index[r].position.clone().setY(player.model.center.y) ) /* panos.index[r].floorPosition.clone() *///不用floorPosition是因为有出现和position的水平位置不一样的点,一般是偏移很远的不可见点,拍摄的bug
  4135. foot.lookAt(foot.position.clone().add(new THREE.Vector3(0,1,0)));
  4136. foot.name = panos.index[r].id;
  4137. foot.visible = false;
  4138. foot.renderOrder = 6,
  4139. panos.index[r].footIcon = foot;
  4140. this.meshGroup.add(foot);
  4141. this.footIcons.push(foot)
  4142. }
  4143. }
  4144. for (var i = 0; i < this.footIcons.length; i++) {
  4145. this.footIcons[i].visible = true;
  4146. this.changeFIconState(this.footIcons[i], false)
  4147. var panos = player.model.panos;
  4148. if (isPanovisible) {
  4149. this.changeFIconState2(this.footIcons[i], this.checkHasNeighbor(panos.index[this.footIcons[i].name], "showFoot"))
  4150. }
  4151. if (pano && (this.footIcons[i].name == pano.id)) {
  4152. //pano为中心 或者 currentPano 所以放大一点
  4153. this.footIcons[i].oriScale = new THREE.Vector3(1.5,1.5,1.5)
  4154. if (isPanovisible) {
  4155. //currentPano特殊些:
  4156. this.changeFIconState(this.footIcons[i], "center")
  4157. //this.footIcons[i].Unclick = true;//不让点击和hover
  4158. }
  4159. } else {
  4160. this.footIcons[i].oriScale = new THREE.Vector3(1,1,1)
  4161. }
  4162. }
  4163. },
  4164. checkHasNeighbor: function(pano, state) {
  4165. //检查当前状态pano点是否有可通行点
  4166. var neighbours = /* this.panoVTemp && */
  4167. this.panoVTemp[pano.id] ? this.panoVTemp[pano.id].neighbourPanos : pano.neighbourPanos;
  4168. if (state != "showFoot" && pano == this.panoVsetting) {
  4169. //是中心点的话。state == "showFoot"代表是showFootIcon时, 这时候线还没创建,无法用线判断中心点有几个相邻点,直接用neighbourPanos
  4170. for (var i in this.panoVLines) {
  4171. if (this.panoVLines[i].visible) {
  4172. return true;
  4173. //有一条线即可
  4174. }
  4175. }
  4176. return;
  4177. }
  4178. for (var i in neighbours) {
  4179. if (i == pano.id)
  4180. continue;
  4181. if (neighbours[i]) {
  4182. if (this.panoVsetting && this.panoVsetting.id == i && this.panoVLines[pano.id] && !this.panoVLines[pano.id].visible)
  4183. continue;
  4184. return true;
  4185. }
  4186. }
  4187. return false;
  4188. },
  4189. /* ifAllPanoNoNeighbor : function(){//检查是否全是孤立点
  4190. var panos = player.model.panos;
  4191. for(var i in panos.index){
  4192. if(this.checkHasNeighbor(panos.index[i])){
  4193. return false;
  4194. }
  4195. }
  4196. this.noPanoHasNeighbor = true;
  4197. return true;//是全部没有neighbour
  4198. }, */
  4199. changeFIconState: function(footIcon, state) {
  4200. var color = state == "linked" ? this.colors.green : (state == "center" ? /* "#d7f244" */
  4201. "#d5f12e" : "#ffffff");
  4202. footIcon.material.uniforms.color.value.set(color)
  4203. },
  4204. changeFIconState2: function(footIcon, state) {
  4205. //是可见点还是不可见点
  4206. if (state) {
  4207. footIcon.material.uniforms.map.value = footTex1;
  4208. if (this.panoVsetting) {
  4209. if (this.panoVsetting.id != footIcon.name) {
  4210. footIcon.material.uniforms.opacity.value = 1;
  4211. } else {
  4212. this.changeVisiBtnState(true)
  4213. }
  4214. }
  4215. } else {
  4216. //不可见
  4217. footIcon.material.uniforms.map.value = footTex2;
  4218. if (!this.panoVsetting || this.panoVsetting.id != footIcon.name) {
  4219. //非中心点时
  4220. footIcon.material.uniforms.opacity.value = 0.5;
  4221. } else {
  4222. //变为中心点时
  4223. footIcon.material.uniforms.opacity.value = 1;
  4224. this.changeVisiBtnState(false)
  4225. }
  4226. }
  4227. },
  4228. hideFootIcons: function() {
  4229. if (!this.footIcons)
  4230. return;
  4231. for (var i = 0; i < this.footIcons.length; i++) {
  4232. this.footIcons[i].visible = false;
  4233. }
  4234. },
  4235. updateFootIconSize: function() {
  4236. //根据相机位置 改变footIcon大小,使在范围内看到的热点大小一致,防止太小点击不到
  4237. if (!this.footIcons)
  4238. return;
  4239. var s = player.cameraControls.controls.floorplan.absoluteScale * 2.8
  4240. s = THREE.Math.clamp(s, 0.5 * this.footIconSizeRatio, 1.4 * this.footIconSizeRatio);
  4241. this.footIcons.forEach(function(f) {
  4242. try {
  4243. f.scale.copy(f.oriScale).multiplyScalar(s);
  4244. } catch (e) {
  4245. console.log(e)
  4246. }
  4247. })
  4248. }
  4249. //========热点可见性==============
  4250. ,
  4251. beginSetTagVisible: function() {
  4252. if (this.setTagVisible)
  4253. return;
  4254. $(".toolTop").addClass("unable")
  4255. $("#hotVisible button").addClass("unable")
  4256. $("#hotVisible label").removeClass('hide')
  4257. this.setTagVisible = true;
  4258. this.tagVTemp = {};
  4259. this.$confirmSnap.text('完成设置').removeClass("hide")
  4260. //objects.tagManager.hideAllTags();
  4261. for (let i in player.model.hots) {
  4262. player.model.hots[i]._isSprite = player.model.hots[i].info.isSprite;
  4263. player.model.hots[i].info.isSprite = true;
  4264. player.model.hots[i].material_.depthTest = false;
  4265. player.model.hots[i].position.copy(player.model.hots[i].info.position);//覆盖transformAtPanos
  4266. player.model.hots[i].update(player)
  4267. }
  4268. this.setDisplay(true)
  4269. this.updateFootIconSize()
  4270. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  4271. },
  4272. SetOneTagVisible: function(tag) {
  4273. //点击某个热点后就对该热点进行设置,或者在热点修改时对其进行设置
  4274. if (this.tagVsetting == tag)
  4275. return;
  4276. if (this.tagVsetting) {
  4277. this.saveLastTagVi(this.tagVsetting);
  4278. //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL);
  4279. }
  4280. this.tagVsetting = tag;
  4281. //记录正在修改的
  4282. this.delVisibleLines();
  4283. //删除线
  4284. this.showFootIcons(player.currentPano);
  4285. this.createTagVisiLines(tag);
  4286. //创线
  4287. this.updateFootIconSize()
  4288. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  4289. },
  4290. saveLastTagVi: function() {
  4291. //保存刚设置过的tag
  4292. var change = false;
  4293. var newVPs = this.tagVTemp[this.tagVsetting.sid] || this.tagVsetting.info.visiblePanos.slice(0);
  4294. for (var r in this.tagsVLines) {
  4295. var line = this.tagsVLines[r];
  4296. if (line.name.indexOf("new") > -1 && line.visible) {
  4297. //新设置为visible且没有取消
  4298. newVPs.push(r)
  4299. change = true;
  4300. //console.log("add: "+r)
  4301. } else if (line.name.indexOf("new") == -1 && !line.visible) {
  4302. //旧的且已经取消
  4303. var i = newVPs.indexOf(r);
  4304. if (i == -1) {
  4305. console.log("visiblePanos删除error");
  4306. continue;
  4307. }
  4308. newVPs.splice(i, 1);
  4309. change = true;
  4310. //console.log("sub: "+r)
  4311. }
  4312. }
  4313. if (change) {
  4314. this.tagVTemp[this.tagVsetting.sid] = newVPs;
  4315. }
  4316. },
  4317. pauseSetTagVisible: function() {
  4318. //pc保存后删除连线 但还在继续设置 点选热点即开始
  4319. if (!this.setTagVisible || !this.tagVsetting)
  4320. return;
  4321. //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL );
  4322. this.delVisibleLines();
  4323. this.hideFootIcons();
  4324. this.tagVTemp = {};
  4325. this.tagVsetting = null;
  4326. },
  4327. finishSetTagVisible: function() {
  4328. if (!this.setTagVisible)
  4329. return;
  4330. $(".toolTop").removeClass("unable")
  4331. $("#hotVisible button").removeClass("unable")
  4332. $("#hotVisible label").addClass('hide')
  4333. this.pauseSetTagVisible();
  4334. this.setTagVisible = false;
  4335. this.setDisplay(false)
  4336. this.$confirmSnap.addClass("hide")
  4337. permitTranMode(true)
  4338. /* for (var r in objects.tagManager.tags) {
  4339. if(objects.tagManager.tags[r].state == "videoPanoFlag")continue;
  4340. objects.tagManager.tags[r].disc.visible = false;
  4341. objects.tagManager.tags[r].disc.material.depthTest = true;
  4342. } */
  4343. for (let i in player.model.hots) {
  4344. player.model.hots[i].info.isSprite = player.model.hots[i]._isSprite;
  4345. player.model.hots[i].info.isSprite || player.model.hots[i].rotation.copy(player.model.hots[i].info.rotation)
  4346. player.model.hots[i].material_.depthTest = true;
  4347. }
  4348. },
  4349. /* saveTagVisibles : function () { //保存到服务器
  4350. if (this.tagVsetting) this.saveLastTagVi(this.tagVsetting); //获取最后设置的那个热点的改动
  4351. //可能出现数据没变但保存的情况。比如先改变了然后切换别的热点但切换回来时又改回来。
  4352. var tags = [];
  4353. for (var i in this.tagVTemp) {
  4354. tags.push({
  4355. sid: i,
  4356. value: this.tagVTemp[i]//turnToPanoIndex(this.tagVTemp[i])
  4357. })
  4358. }
  4359. if (tags.length == 0) {//没有需要保存的改动
  4360. this.finishSetTagVisible()
  4361. return;
  4362. }
  4363. return tags;
  4364. } */
  4365. //afterSaveTagVisibles : function(){
  4366. saveTagVisibles: function() {
  4367. if (this.tagVsetting)
  4368. this.saveLastTagVi(this.tagVsetting);
  4369. for (var i in this.tagVTemp) {
  4370. //保持成功于是生效
  4371. player.model.hots[i].setVisiblePanos(this.tagVTemp[i])
  4372. }
  4373. this.finishSetTagVisible()
  4374. //还是保存完直接结束吧,因为现在热点可视不放在单独的设置页面了
  4375. },
  4376. createTagVisiLines: function(tag) {
  4377. // 热点可见性线条
  4378. var panos = player.model.panos;
  4379. var visibleList = this.tagVTemp[tag.sid] || tag.info.visiblePanos;
  4380. //如果是刚在设置的要读取设置过的数据
  4381. for (var r = 0; r < visibleList.length; r++) {
  4382. var pano = panos.index[visibleList[r]];
  4383. this.createTagSingleLine(pano, "old", tag)
  4384. }
  4385. },
  4386. createTagSingleLine: function(pano, type, tag) {
  4387. var panos = player.model.panos;
  4388. var line = LineDraw.createLine([pano.footIcon.position.clone()/* .sub(this.position) */
  4389. , tag.info.position.clone()], {
  4390. color: this.colors.green
  4391. });
  4392. this.meshGroup.add(line);
  4393. line.name = "tagVL-" + type + "-" + pano.id;
  4394. this.tagsVLines[pano.id] = line;
  4395. this.changeFIconState(panos.index[pano.id].footIcon, "linked")
  4396. },
  4397. dealTagVisible: function(tag, panoName) {
  4398. //外部调用
  4399. var panos = player.model.panos;
  4400. if (this.tagsVLines[panoName]) {
  4401. this.tagsVLines[panoName].visible = !this.tagsVLines[panoName].visible;
  4402. this.changeFIconState(panos.index[panoName].footIcon, this.tagsVLines[panoName].visible ? "linked" : false)
  4403. } else {
  4404. this.createTagSingleLine(panos.index[panoName], "new", tag)
  4405. }
  4406. },
  4407. delVisibleLines: function() {
  4408. //xzw add 所有线都删除
  4409. for (var i in this.tagsVLines) {
  4410. this.tagsVLines[i].geometry.dispose();
  4411. this.tagsVLines[i].material.dispose();
  4412. this.meshGroup.remove(this.tagsVLines[i]);
  4413. delete this.tagsVLines[i];
  4414. }
  4415. for (var i in this.panoVLines) {
  4416. this.panoVLines[i].geometry.dispose();
  4417. this.panoVLines[i].material.dispose();
  4418. this.meshGroup.remove(this.panoVLines[i]);
  4419. delete this.panoVLines[i];
  4420. }
  4421. }
  4422. }
  4423. function permitTranMode(state) {
  4424. state ? $(".pinBottom.left").removeClass('hide') : $(".pinBottom.left").addClass('hide');
  4425. }
  4426. function randomWord(randomFlag, min, max) {
  4427. //随机字符串
  4428. var str = ""
  4429. , range = min
  4430. , 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'];
  4431. if (randomFlag) {
  4432. // 随机长度
  4433. range = Math.round(Math.random() * (max - min)) + min;
  4434. }
  4435. for (var i = 0; i < range; i++) {
  4436. var pos = Math.round(Math.random() * (arr.length - 1));
  4437. str += arr[pos];
  4438. }
  4439. return str;
  4440. }
  4441. function getRandomSid() {
  4442. //5-7位随机字符串 + 6位时间 为热点准备
  4443. var pre = randomWord(true, 5, 7);
  4444. var post = new Date().getTime() + "";
  4445. var len = post.length;
  4446. post = post.substring(len - 8, len - 5) + post.substring(len - 3, len)
  4447. //其实还是有可能重复的....
  4448. return pre + post;
  4449. }
  4450. function searchParent(searchArea, o, maxTimes) {
  4451. //是否是某种元素的下级,并找出该元素
  4452. maxTimes = maxTimes || 20;
  4453. var count = 0
  4454. var f = function(dom) {
  4455. if (o.id && o.id == dom.id)
  4456. return dom
  4457. else if (o.className && dom.classList && dom.classList.contains(o.className))
  4458. return dom
  4459. else if (o.tagName && dom.tagName && o.tagName.toUpperCase() == dom.tagName.toUpperCase())
  4460. return dom
  4461. }
  4462. var find;
  4463. while (searchArea && count < maxTimes) {
  4464. if (find = f(searchArea))
  4465. return find
  4466. searchArea = searchArea.parentNode;
  4467. count++;
  4468. }
  4469. }
  4470. function musicPlayBoxBind($dom, addCallback, delCallback){
  4471. var musicBox = {
  4472. hasMusic:false,
  4473. show: function(/* mediaDom, */name, url){
  4474. /* mediaDom = mediaDom || $dom
  4475. mediaDom.find(".innerBtn").text("替换");
  4476. mediaDom.find(".playBox").removeClass("hide");
  4477. mediaDom.find(".title").text(name);
  4478. mediaDom.find('a').attr('href', url);
  4479. musicBox.hasMusic = true */
  4480. $dom.find(".innerBtn").text("替换");
  4481. $dom.find(".playBox").removeClass("hide");
  4482. $dom.find(".title").text(name);
  4483. $dom.find('a').attr('href', url);
  4484. musicBox.hasMusic = true
  4485. },
  4486. addMusic : function(e) {
  4487. if(!e.target.files.length) return;
  4488. var file = e.target.files[0];
  4489. if (!/audio\/\w+/.test(file.type)) {
  4490. alert("文件必须为音乐!");
  4491. return false;
  4492. }
  4493. //限制大小不大于8m
  4494. if (!restrictedSize(file, _musicMaxWeight)) {
  4495. return false
  4496. }
  4497. //var mediaDom = $(searchParent(e.target, { className: 'mediaUpload' }));
  4498. musicBox.show(/* mediaDom, */file.name, URL.createObjectURL(file))
  4499. addCallback && addCallback(file)
  4500. },
  4501. delMusic:function(){//手动点击删除
  4502. musicBox.hide()
  4503. delCallback && delCallback()
  4504. },
  4505. hide : function(e) {//清空并隐藏
  4506. //var mediaDom = e ? $(searchParent(e.target, { className: 'mediaUpload' })) : $dom
  4507. $dom.find('a').attr('href', "");
  4508. $dom.find(".playBox").addClass("hide");
  4509. $dom.find(".innerBtn").text("上传");
  4510. $dom.find("input").val("")//.removeAttr("data-hotbgm");
  4511. musicBox.hasMusic = false
  4512. },
  4513. getSrc:function(){
  4514. return this.hasMusic && $dom.find('a').attr('href');
  4515. },
  4516. getName:function(){
  4517. return this.hasMusic && $dom.find(".title").text();
  4518. },
  4519. getFile:function(){//获取刚上传的文件
  4520. return this.hasMusic && $dom.find("input")[0].files[0]
  4521. }
  4522. }
  4523. $dom.find("input").on("change", musicBox.addMusic)
  4524. /* $dom.find("input").on("click", function() {
  4525. mediaUpload
  4526. }); */
  4527. //删除音乐
  4528. $dom.on("click", ".delete", musicBox.delMusic)
  4529. return musicBox;
  4530. }
  4531. class ListBox{//下拉列表
  4532. //elemArr:初始的列表,内含每项的dom.
  4533. constructor(elemArr, $rootDom, options={}){
  4534. this.listDom = $rootDom.find('ul.list')
  4535. this.listTitle = $rootDom.find('.selection')
  4536. this.chosenItem = null
  4537. this.options = options;
  4538. this.bindEvents()
  4539. elemArr.forEach(($dom, i)=>{
  4540. this.addItem($dom)
  4541. })
  4542. }
  4543. updateSelectDisplay(o){
  4544. this.listDom.children().removeClass('selected')
  4545. this.chosenItem && this.chosenItem.addClass("selected")
  4546. this.options.selectFun( o)
  4547. }
  4548. selectFromOutSide(index , o){
  4549. if(index == null){
  4550. var defaultItem = this.listDom.find('.forbitEdit'); //若存在默认选项
  4551. if(defaultItem.length){
  4552. index = defaultItem.index()
  4553. }
  4554. }
  4555. this.chosenIndex = index;
  4556. this.chosenItem = index == void 0 ? null : this.listDom.children().eq(index)
  4557. this.updateSelectDisplay(o)
  4558. }
  4559. addItem($dom){
  4560. this.listDom.prepend($dom)
  4561. if(this.options.addFun){
  4562. this.options.addFun($dom)
  4563. }
  4564. $dom.on('click',()=>{
  4565. this.chosenItem = $dom;
  4566. this.chosenIndex = $dom.index();
  4567. this.updateSelectDisplay()
  4568. })
  4569. }
  4570. removeItem($dom){
  4571. $dom.remove()
  4572. if(this.chosenItem && this.chosenItem[0] == $dom[0]){
  4573. this.selectFromOutSide(null)
  4574. //this.chosenItem = this.chosenIndex = null
  4575. }
  4576. if(this.options.delFun){
  4577. this.options.delFun($dom)
  4578. }
  4579. }
  4580. saveTemp(){//编辑热点时保存一份副本
  4581. this.temp = Array.from(this.listDom.children()).reverse().map((li)=>{
  4582. return li.outerHTML
  4583. })
  4584. this.options.saveTemp && this.options.saveTemp(this)
  4585. }
  4586. recover(){//取消编辑时恢复
  4587. this.listDom.html('')
  4588. this.temp.forEach(html=>{
  4589. this.addItem($(html));
  4590. })
  4591. this.options.recover && this.options.recover(this)
  4592. this.chosenItem = this.chosenIndex = null
  4593. //this.selectFromOutSide(this.chosenIndex)
  4594. }
  4595. bindEvents(){
  4596. this.listTitle.on('click',(e)=>{
  4597. e.stopPropagation()
  4598. this.listDom.toggleClass('hide')
  4599. })
  4600. document.addEventListener('click',()=>{
  4601. this.listDom.addClass('hide')
  4602. })
  4603. }
  4604. }
  4605. class ButtonBase{
  4606. constructor(o={}){
  4607. this.dom = o.dom
  4608. this.uiCallBack = o.uiCallBack
  4609. this.callbackWhenChose = o.callbackWhenChose //只有点击选择才会触发
  4610. }
  4611. }
  4612. class MenuOptions extends ButtonBase{
  4613. constructor(o={}){
  4614. super(o)
  4615. this.dom.find("li").on("click", (e)=>{
  4616. var $elem = $(e.target);
  4617. this.updateChoseAtUI({$li:$elem})
  4618. this.callbackWhenChose && this.callbackWhenChose({$li:$elem})
  4619. })
  4620. }
  4621. updateChoseAtUI(o={}){
  4622. this.dom.find('li').removeClass("chosen");
  4623. if(o.$li){
  4624. o.$li.addClass("chosen");
  4625. }else{
  4626. this.dom.find("li[index="+o.name+"]").addClass("chosen");
  4627. }
  4628. this.uiCallBack && this.uiCallBack(o)
  4629. }
  4630. getSelectName(){
  4631. return this.dom.find('li.chosen').attr('index')
  4632. }
  4633. }
  4634. class CheckBox extends ButtonBase{
  4635. constructor(o={}){
  4636. super(o)
  4637. this.dom.on("change",(e)=>{
  4638. var name = $(e.target).attr('name')
  4639. this.uiCallBack && this.uiCallBack(e.target.checked, name)
  4640. this.callbackWhenChose && this.callbackWhenChose(e.target.checked, name)
  4641. })
  4642. }
  4643. updateChoseAtUI(checked, name){
  4644. var dom
  4645. if(name) dom = this.dom.filter('[name='+name+']')[0]
  4646. else dom = this.dom[0]
  4647. dom.checked = checked //this.dom.prop("checked")
  4648. this.uiCallBack && this.uiCallBack(checked, name)
  4649. }
  4650. checked(name){
  4651. var dom
  4652. if(name) dom = this.dom.filter('[name='+name+']')[0]
  4653. else dom = this.dom[0]
  4654. return dom.checked
  4655. }
  4656. }
  4657. function setDraggable(o={}){
  4658. let findTarget = (event)=>{
  4659. let target;
  4660. for(let name of o.dragItemClassName){
  4661. let tar = searchParent(event.target, { className: name }, o.maxDepth || 7);
  4662. if(tar){
  4663. target = tar; break;
  4664. }
  4665. }
  4666. return target
  4667. }
  4668. let draging = null;
  4669. let dragStart = (event)=> {
  4670. event.dataTransfer.setData("te", event.target.innerText); //不能使用text,firefox会打开新tab
  4671. draging = findTarget(event);
  4672. }
  4673. let dragOver = (event)=>{
  4674. event.preventDefault();
  4675. let target = findTarget(event);
  4676. // 判断dragover是否发生在LI元素上
  4677. if (target && target !== draging ) {
  4678. let dragingIndex = $(draging).index()//draging.querySelector('#index');
  4679. let targetIndex = $(target).index()//target.querySelector('#index');
  4680. var targetRect = target.getBoundingClientRect();
  4681. var dragingRect = draging.getBoundingClientRect();
  4682. if (target && target.animated) {
  4683. return;
  4684. }
  4685. let ulElem = target.parentNode;
  4686. // 寻找到 ul节点
  4687. if (getIndex(draging) < getIndex(target)) {
  4688. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  4689. // 交换两个节点的序号
  4690. if(event.clientY<targetRect.top+targetRect.height*0.3)return
  4691. ulElem.insertBefore(draging, target.nextSibling);
  4692. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];// 交换两个节点的序号
  4693. } else {
  4694. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  4695. if(event.clientY>targetRect.bottom-targetRect.height*0.3)return
  4696. ulElem.insertBefore(draging, target);
  4697. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  4698. }
  4699. _animate(dragingRect, draging);
  4700. _animate(targetRect, target);
  4701. o.callback && o.callback(o.ul, target)
  4702. //var ul = searchParent(event.target, { className: 'tourList' })
  4703. //reIndexTourList(ul)
  4704. }
  4705. }
  4706. o.ul.ondragstart = dragStart
  4707. o.ul.ondragover = dragOver
  4708. }
  4709. /* class OnOffSwitch extends CheckBox{
  4710. constructor(o={}){
  4711. super(o)
  4712. }
  4713. }
  4714. */
  4715. /*
  4716. 待加功能:
  4717. //boxhelper改成粗线
  4718. 热点可视时改成一样大小
  4719. 热点可视insight优化
  4720. hover到热点时列表滚动到这一项
  4721. 释放geometry内存 、texture
  4722. */