edit.js 187 KB

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