edit.js 199 KB

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