edit.js 220 KB

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