edit.js 227 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837
  1. /* var ceshi = '';
  2. // var ceshi = 'http://192.168.0.135:8105';
  3. // var ceshi = 'http://47.107.252.54:8105';
  4. // var token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsInJvbGUiOm51bGwsIm1hbmFnZXIiOm51bGwsImlkIjoxLCJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNTk2NzAxNjAyLCJpYXQiOjE1OTY2MTUyMDIsImp0aSI6Ijk0YjA5YTg1LWViY2ItNDE1Yy04OGVmLWU0MDM1M2UzYmIxYyJ9.Uzi95n0kYXp7bdpY77MdLtTpPL_Fq-jn0tE7gjg6AzA"
  5. var token = window.localStorage.dcj_token
  6. */
  7. var confirmSnap = $(".confirmSnap.innerBtn");
  8. var snapshotGui = $(".snapshotGui.overlayGui");
  9. var _musicMaxWeight = 8
  10. //M
  11. var cmp = getQueryVariable('cmp') || ''
  12. var _hotNum = 0
  13. function reData(data, type) {
  14. return JSON.stringify(data) == type ? null : data
  15. }
  16. let strictInputNum = function(e, precision, min=0,max){//precision:保留小数位数
  17. var value = e.target.value.trim();
  18. var lastOne = value[value.length-1];
  19. var preContent = value.substr(0,value.length-1)
  20. var hasPoint = precision > 0 && lastOne == '.' ;
  21. var a = Math.pow(10, precision)
  22. value = parseFloat(value) || 0;
  23. if(isNaN(value)){
  24. e.target.value = preContent //还原
  25. return
  26. }
  27. e.target.value = Math.max(min, parseInt(value * a) / a )
  28. hasPoint && (e.target.value += '.')//补小数点
  29. }
  30. //新编辑界面
  31. var EditTools = function(n) {
  32. //main2018 里面的主要对象
  33. this.n = n;
  34. //当前状态
  35. this.atPanel = null;
  36. //场景信息
  37. this.sceneInformation = new SceneInformation();
  38. //热点
  39. this.hotpoint = new Hotpoint();
  40. //导览
  41. this.editGuide = new EditGuide();
  42. //音乐
  43. this.EditBGM = new EditBGM();
  44. //初始化界面
  45. //this.init();
  46. this.data = {}
  47. this.editLabel = new EditLabel();
  48. }
  49. EditTools.prototype.loadDone = function(name, data){
  50. this.data[name] = data
  51. if('data' in this.data && 'data2' in this.data){
  52. this.init();
  53. }
  54. }
  55. EditTools.prototype.init = function() {
  56. this.hotpoint.init(/* this.n */);
  57. var that = this;
  58. this.initSaveAll();
  59. this.active();
  60. if(player.mode != 'panorama'){
  61. $(".toolLeft li[data-name=panoVisible]").addClass('unable')
  62. player.once("pano.chosen",()=>{
  63. $(".toolLeft li[data-name=panoVisible]").removeClass('unable')
  64. })
  65. }
  66. //创建导览
  67. that.EditBGM.init(this.data.data);
  68. that.sceneInformation.init(this.data.data, this.data.data2)
  69. // fyz 初始化导览需要两部分数据, 其中data2为data.js中的数据
  70. that.editGuide.init(this.data.data, this.data.data2);
  71. that.editLabel.init()
  72. $("body").on("click", function() {
  73. $(".DelConfirm").removeClass("active");
  74. })
  75. player.on("mode.changing",(currentMode, mode, pano)=>{ //起飞
  76. if(this.atPanel != "screen" && !editTool.hotpoint.gettingCameraData) return
  77. if(currentMode == "panorama") confirmSnap.addClass("unable")
  78. })
  79. player.on("flying.ended",(/* toPos, fromPos, pano */)=>{ //飞结束
  80. if(this.atPanel != "screen" && !editTool.hotpoint.gettingCameraData) return
  81. if(player.mode == "panorama") confirmSnap.removeClass("unable")
  82. })
  83. /* $(" .MenuOptions li").on("click", (e)=>{
  84. var $elem = $(e.target);
  85. $elem.closest('.MenuOptions').find('li').removeClass("chosen");
  86. $elem.addClass("chosen");
  87. }) */
  88. //fyz 拖拽以改变顺序
  89. {
  90. let tourListNode = $("#tourList>ul")[0];
  91. let tourItemListNode = $("#tourItemList>ul")[0];
  92. let callback = function(ul){
  93. reIndexTourList(ul)
  94. }
  95. //导览拖拽
  96. setDraggable({ul:tourListNode, dragItemClassName:['guideItem', 'listItem'], callback})
  97. setDraggable({ul:tourItemListNode, dragItemClassName:['guideItem'], callback })
  98. //热点媒体拖拽
  99. setDraggable({ul:$('#hotpointDetail [name="video"] .list')[0], dragItemClassName:['mediaItem'] })
  100. setDraggable({ul:$('#hotpointDetail [name="photo"] .list')[0], dragItemClassName:['mediaItem'] })
  101. //热点列表拖拽
  102. setDraggable({ul:$('.toolRight .spotList')[0], dragItemClassName:['listItem']})
  103. //roomLabel列表拖拽
  104. setDraggable({ul:$('.toolRight .roomLabels [name="list"]>ul')[0], dragItemClassName:['listItem']})
  105. }
  106. $(".toolRight .panoVisible [name=autoCompute]").on('click',()=>{
  107. VisiSet.resetPanosVisiByModel()
  108. })
  109. //平面图方向固定
  110. this.fpAngleOptions = new MenuOptions({
  111. dom: $(".toolRight .information [data-name=floorPlanAngle] .MenuOptions"),
  112. uiCallBack : (o)=>{
  113. var name = o.name == void 0 ? o.$li.attr('index') : o.name
  114. _settings.floorPlanAngle = parseFloat(name) * Math.PI/2 //设置好方向 (0是无效的,将不设置)
  115. if(name != 0 && player.ready){
  116. if(player.mode != 'floorplan' && player.modeTran.split('-')!= 'floorplan'){
  117. player.flyToMode('floorplan')
  118. }else{
  119. player.flyToMode('floorplan',()=>{
  120. player.cameraControls.controls.floorplan.rotateToAngle(_settings.floorPlanAngle)
  121. })
  122. }
  123. }
  124. },
  125. callbackWhenChose:(o)=>{
  126. var name = o.$li.attr('index')
  127. }
  128. })
  129. this.fpAngleOptions.updateChoseAtUI({name: Math.round(_settings.floorPlanAngle/(Math.PI/2))})
  130. }
  131. //点击的时候激活状态
  132. EditTools.prototype.active = function() {
  133. var that = this;
  134. $('.toolBottom .toolLeft li').click(function() {
  135. var name = $(this).data("name");
  136. $('.toolLeft li[data-name=' + name + ']').addClass("active").siblings().removeClass("active");
  137. $('.toolRight .' + name).removeClass("hide").siblings().addClass("hide");
  138. if (name == that.atPanel)
  139. return;
  140. console.log(`atPanel ${that.atPanel} name ${name}`)
  141. switch (that.atPanel) {
  142. //退出
  143. case "panoVisible":
  144. VisiSet.finishSetPanoVisible()
  145. break;
  146. case "panoLog":
  147. VisiSet.finishSetPanoLog()
  148. break;
  149. case "screen":
  150. confirmSnap.addClass("hide").removeClass("unable");
  151. snapshotGui.hide();
  152. break;
  153. /* case "overlay":
  154. EditOverlay.leave()
  155. break; */
  156. case "hotpoint":
  157. $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click();
  158. VisiSet.finishSetTagVisible()
  159. that.hotpoint.wireframeModel.visible = false
  160. break;
  161. case 'roomLabels':
  162. that.editLabel.leave()
  163. break;
  164. }
  165. switch (name) {
  166. case "hotpoint":
  167. that.hotpoint.wireframeModel.visible = that.hotpoint.wireframeModel.shouldShow
  168. break;
  169. case "panoVisible":
  170. $(".toolLeft").addClass("unable")
  171. VisiSet.enterSet(VisiSet.beginSetPanoVisible.bind(VisiSet))
  172. break;
  173. case "panoLog":
  174. $(".toolLeft").addClass("unable")
  175. VisiSet.enterSet(VisiSet.beginSetPanoLog.bind(VisiSet))
  176. break;
  177. case "screen":
  178. confirmSnap.removeClass("hide");
  179. $('#camera-start').text("点此设置为初始画面")
  180. snapshotGui.show();
  181. if (player.mode != "panorama")
  182. confirmSnap.addClass("unable")
  183. break;
  184. /* case "overlay":
  185. EditOverlay.enter()
  186. break; */
  187. case 'snapTour':
  188. that.editGuide.scroller.tourBlackSpeed.InitOffset()
  189. that.editGuide.scroller.tourWalkSpeed.InitOffset()
  190. break;
  191. case 'roomLabels':
  192. that.editLabel.enter()
  193. break;
  194. }
  195. that.atPanel = name;
  196. /* if(name != "hotpoint"){
  197. $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click()
  198. } */
  199. })
  200. //滚动阻止事件
  201. $(".toolRight div.content").on("mousewheel", function(event) {
  202. event.stopPropagation()
  203. });
  204. // 输入框阻止事件
  205. $('.toolRight').on('keydown', function(ev) {
  206. ev.stopPropagation();
  207. })
  208. //加空格和回车字符
  209. $(".buttons[name='addSign'] button").on('click',function(e){
  210. let forAttr = $(this).parent().attr('for')
  211. let textarea = forAttr ? $('#'+forAttr) : $(this).parent().parent().find('textarea')
  212. let sign = $(this).attr('name') == 'space' ? '&nbsp;' : '<br>'
  213. var v = textarea.val();
  214. textarea.val(v + sign)
  215. })
  216. }
  217. //保存按钮
  218. EditTools.prototype.initSaveAll = function() {
  219. var that = this;
  220. $('#save').on('click', function() {
  221. $(".edit-loading").removeClass("hide");
  222. var $shareImages = $(".information .edit-fun-images a.result");
  223. new Promise(function(resolve, reject) {//分享图
  224. upload($shareImages, 'images', resolve)
  225. }).then(function(imgUrls) {
  226. //导览的数据
  227. var guides = that.editGuide.getSavingInfo()/* Array.from($('.tourFolderList ul li')).map(function(dom) {
  228. return dom.data
  229. }) */
  230. let tourRotTime = parseFloat($('.toolRight .snapTour [name="rotTime"] input').val())
  231. isNaN(tourRotTime) && (tourRotTime = '')
  232. var info = {
  233. name: $('#pjtName').val(),
  234. summary: $('#info-summary').val(),
  235. weixinDesc: $('#weixin-summary').val(),
  236. shareImgUrl: imgUrls[0] || '',
  237. backgroundMusic: that.EditBGM.musicBox.getSrc() || '',
  238. bgName: that.EditBGM.musicBox.getName(),
  239. hoticon: JSON.parse($(".hotStyle-item li.active").attr("data-val")),
  240. camera_start: $(".screen .shotImg.innerBtn")[0].cameraData,
  241. loadlogo: $("#loadlogo").is(':checked'),
  242. special: $("#g_specialScene").is(':checked'),
  243. vision_version: $("#twoData").is(':checked') ? "1.1.562.17209" : false,
  244. roomLabels: that.editLabel.getSavingInfo(),
  245. /************************************** 方奕卓 场景可配置项 ******************************************/
  246. hotImageScale: $("#hotImgScale").is(':checked'),
  247. // 热点图片可放大
  248. autoAdjustHotScale : $("#autoAdjustHotScale").is(':checked'),
  249. hideFloorMarker: $("#hideFloorMarker").is(':checked'),
  250. // 地面标记
  251. hideMouseMarker: $("#hideMouseMarker").is(':checked'),
  252. showingLabels: $("#showingLabels").is(':checked'),
  253. // 鼠标标记
  254. floorMarkerColor: $('#floorMarkerColor').val(),
  255. // 地面/导览标志颜色
  256. mouseMarkerColor: $('#mouseMarkerColor').val(),
  257. // 鼠标标志颜色
  258. momentTour: $('#tourSwitch input').is(':checked') ? 'black' : 'walk',
  259. tourBlackSpeed : that.editGuide.scroller.tourBlackSpeed.value,
  260. tourWalkSpeed : that.editGuide.scroller.tourWalkSpeed.value,
  261. tourRotTime,
  262. momentTourBlackNewType : $('#newBlack').is(':checked'),
  263. showHotListSta: $('#hotListSwitch').is(':checked'),
  264. // 开启热点列表
  265. hotIconScale: DATA.hotIconScale,
  266. // 热点缩放
  267. supportsVR: $('#VRSwitch input').is(':checked'),
  268. // 开启VR功能
  269. /**************** 陈志广 小地图可配置项 *********** */
  270. cadSignColor: $('#cadSignColor').val(),
  271. cadBorderColor: $('#cadBorderColor').val(),
  272. cadBorderWidth: $('#cad-size').val(),
  273. showCad: $('input[name="show-cad"]').is(':checked'),
  274. /**********/
  275. floorPlanAngle: _settings.floorPlanAngle || 0 //俯视图旋转角
  276. }
  277. var data = {
  278. sceneCode: number,
  279. hots: reData(that.hotpoint.getSavingInfo(), '{}'),
  280. //tourAudio: reData(that.editGuide.tourAudio,'{}'),//for 旧版
  281. name: number,
  282. guides: reData(guides, '[]'),
  283. info: info,
  284. }
  285. console.log(data)
  286. let url = cmp ? ('/api/scene/edit/' + cmp) : '/manage/scene/edit'
  287. $.ajax({
  288. method: 'POST',
  289. headers: {
  290. 'Content-Type': 'application/json',
  291. token: token
  292. },
  293. dataType: 'json',
  294. contentType: 'application/json',
  295. url: ceshi + url,
  296. data: JSON.stringify(data),
  297. success: function(data) {
  298. if (data.code === 0) {//成功
  299. //manage.showInfo("保存成功")
  300. location.reload()
  301. }else if (data.code === 5001) {
  302. alert('请重新登录')
  303. localStorage.dcj_token = ''
  304. location.reload()
  305. }else{
  306. alert(`saveAll (url:${url}) code : ${data.code} \n${data.msg}`)
  307. }
  308. }
  309. })
  310. });
  311. })
  312. }
  313. class EditLabel{
  314. constructor(){
  315. }
  316. init(){
  317. let reverse = player.model.roomLabels.slice(0).reverse()
  318. reverse.forEach(e=>this.addLebelCallback(e))
  319. $('.toolRight .roomLabels .addBtn button').on('click',()=>{//准备添加
  320. if(this.editingLabel){
  321. this.setEditLabel(false, this.editingLabel)
  322. }
  323. this.setAddState(true)
  324. })
  325. $('.toolRight .roomLabels [name="title"] input').on('input',(e)=>{//标题
  326. this.editingLabel.setTitle(e.target.value)
  327. this.editingLabel.$li.find('.title').text(e.target.value)
  328. })
  329. /* $('.toolRight .roomLabels [name="delete"] button').on('click',(e)=>{//删除
  330. this.deleteLabel(this.editingLabel)
  331. this.setEditLabel(false,this.editingLabel)
  332. }) */
  333. player.on('getIntersect',(intersect, consume)=>{//添加
  334. if(this.adding){
  335. var position = intersect.point.clone();
  336. position.y += 0.5
  337. //var floorIndex = player.model.allFloorsVisible ? null : player.model.currentFloor.floorIndex
  338. var floorIndex = intersect.object.parent.parent.floorIndex
  339. var label = new RoomLabel({position, title:'' , floorIndex })
  340. player.model.roomLabels.push(label)
  341. this.setAddState(false)
  342. this.addLebelCallback(label)
  343. this.setEditLabel(true, label) //开始编辑
  344. this.adding = false
  345. label.update()
  346. consume(true)
  347. }
  348. })
  349. //点击列表弹出按钮
  350. $('.toolRight .roomLabels [name="list"]>ul').on("click", (e)=>{
  351. var target = $(e.target);
  352. let li = searchParent(e.target, { className: 'listItem' }, 7);
  353. if(!li)return;
  354. let label = li.label
  355. if (target.hasClass("del")) {
  356. e.stopPropagation();
  357. target.siblings(".DelConfirm").addClass("active");
  358. } else {
  359. if (target.hasClass("DelConfirm")) {
  360. e.stopPropagation();
  361. this.deleteLabel(label);
  362. }else{
  363. this.setEditLabel(true, label) //开始编辑
  364. }
  365. }
  366. });
  367. }
  368. deleteLabel(label){
  369. let index = player.model.roomLabels.indexOf(label)
  370. index > -1 && player.model.roomLabels.splice(index,1)
  371. label.dispose()
  372. label.$li.remove()
  373. if(this.editingLabel == label){
  374. this.setEditLabel(false,this.editingLabel)
  375. }
  376. }
  377. addLebelCallback(label){
  378. this.addLebelEvent(label)
  379. this.addToList(label)
  380. }
  381. addToList(label){
  382. 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>");
  383. $li[0].label = label
  384. label.$li = $li;
  385. $('.toolRight .roomLabels [name="list"]>ul').prepend($li)
  386. }
  387. setAddState(state){
  388. state ? CursorDeal.add('addLabel') : CursorDeal.remove('addLabel')
  389. this.adding = state
  390. }
  391. setEditLabel(state, label){
  392. let pannel = $('.toolRight .roomLabels li[name="prop"]')
  393. if(state){
  394. if(this.editingLabel){
  395. this.setEditLabel(false, this.editingLabel)
  396. }
  397. label.elem.addClass('selected')
  398. pannel.removeClass('hide')
  399. pannel.find('[name="title"] input').val(label.title)
  400. label.setEditSelect(true)
  401. pannel.insertAfter(label.$li)
  402. this.editingLabel = label
  403. player.focusPoint({aim: label.position, radius: label.position.distanceTo(player.position)})
  404. }else{
  405. label.elem.removeClass('selected')
  406. pannel.addClass('hide')
  407. label.setEditSelect(false)
  408. this.editingLabel = null
  409. }
  410. }
  411. addLebelEvent(label){
  412. //拖拽
  413. let dragElemShift = {}
  414. let dragging = false
  415. const startDrag = (evt) => {
  416. if(!this.editing )return
  417. dragging = true
  418. $('#player').on("mousemove", drag);
  419. label.elem.find('a').css('pointer-events','none')
  420. /* if(player.mode != 'floorplan'){ //换算到elem的底部
  421. let lebelWidth = label.elem.children(0).width()
  422. let lebelHeight = label.elem.children(0).height() * (68+24) / 24 ;//
  423. dragElemShift = {x: -evt.offsetX + lebelWidth/2, y: 100 } //y向不准确,因为原本添加时提高了0.5,而0.5对应的像素需要根据视角,那就算了吧
  424. }else{
  425. dragElemShift = {x:0,y:0}
  426. } */
  427. CursorDeal.add('moveLabel')
  428. };
  429. const endDrag = (evt) => {
  430. dragging = false
  431. $('#player').off("mousemove", drag);
  432. label.elem.find('a').css('pointer-events','')
  433. CursorDeal.remove('moveLabel')
  434. };
  435. const drag = (evt) => {
  436. if (dragging) {
  437. evt.preventDefault();
  438. let mouse = new THREE.Vector3()
  439. let meshes = player.model.allFloorsVisible ? player.model.colliders : player.model.currentFloor.collider.children
  440. math.convertScreenPositionToNDC(evt.offsetX/* +dragElemShift.x */, evt.offsetY/* +dragElemShift.y */, mouse);
  441. var intersect = convertTool.getMouseIntersect(player.camera, meshes, mouse)
  442. if(intersect){
  443. let position = intersect.point.clone()
  444. position.y += 0.5
  445. label.setPos(position)
  446. var floorIndex = intersect.object.parent.parent.floorIndex
  447. label.floorIndex = floorIndex
  448. }
  449. //this.dispatchEvent({type:'dragged', position: this.position})
  450. }
  451. };
  452. label.elem.on('mousedown', startDrag);
  453. $(document).on('mouseup', endDrag);
  454. $("#player").on('mouseup', endDrag);
  455. //点击编辑:
  456. label.elem.on('click',(e)=>{
  457. if(this.editing){
  458. this.setEditLabel(true,label)
  459. }
  460. e.stopPropagation()
  461. })
  462. }
  463. enter(){
  464. this.editing = true
  465. player.roomLebelClickUnabled = true
  466. }
  467. leave(){
  468. this.editing = false
  469. this.editingLabel && this.setEditLabel(false, this.editingLabel)
  470. player.roomLebelClickUnabled = false
  471. this.setAddState(false)
  472. }
  473. getSavingInfo(){
  474. var info = Array.from($('.toolRight .roomLabels [name="list"] .listItem')).map((li,index)=>{
  475. let label = li.label
  476. return {
  477. //order: index,
  478. title : label.title,
  479. position : toPrecision(label.position.toArray(), 4),
  480. floorIndex: label.floorIndex
  481. }
  482. })
  483. console.log(info)
  484. return info
  485. }
  486. }
  487. //场景信息编辑
  488. var SceneInformation = function() {}
  489. SceneInformation.prototype.init = function(data, data2) {
  490. var $options = $('.hotStyle-item li');
  491. var $loadlogo = $("#loadlogo");
  492. var $hotImageScale = $("#hotImgScale");
  493. var $hideFloorMarker = $("#hideFloorMarker");
  494. var $hideMouseMarker = $("#hideMouseMarker");
  495. var $showingLabels = $("#showingLabels");
  496. var $g_specialScene = $("#g_specialScene");
  497. var $twoData = $("#twoData");
  498. /*******************方奕卓 其他项需要用到data来初始化, 故一并放到这里 ******************/
  499. let momentTour = $('#tourSwitch input');
  500. // 导览瞬间过渡开关
  501. let hotListSwitch = $('#hotListSwitch');
  502. // 热点图标缩放
  503. let VRSwitch = $('#VRSwitch input');
  504. // VR功能开启
  505. /***********************************************************************************/
  506. $(".model-title2").text(data.name);
  507. $('#pjtName').val(data.name);
  508. $('#info-summary').val(data.summary);
  509. //if (data2) $('#weixin-summary').val(data2.weixinDesc);
  510. $('#weixin-summary').val(data.weixinDesc);
  511. for (var i = 0; i < $options.length; i++) {
  512. if ($options.eq(i).attr('data-val') === JSON.stringify(data.hoticon)) {
  513. $options.eq(i).addClass("active").siblings().removeClass("active");
  514. }
  515. }
  516. let hasCameraStart = !!data.camera_start && data.camera_start.thumbImg //最初始的数据camera_start是默认值,但无thumbImg
  517. $(".screen .shotImg.innerBtn")[0].cameraData = hasCameraStart && data.camera_start;
  518. if(hasCameraStart) $(".screen .itemTitle button").removeClass('hide')
  519. $(".shotImg.innerBtn").on("click", function(){
  520. var EntryInfo = this.cameraData
  521. if (EntryInfo) {
  522. var to = player.model.panos.get(EntryInfo.pano.uuid);
  523. var q = new THREE.Quaternion().fromArray(EntryInfo.camera.quaternion);
  524. var lookAtPoint = new THREE.Vector3(0,0,-1).applyQuaternion(q).add(to.position);
  525. player.flyToPano({
  526. pano: to,
  527. lookAtPoint: lookAtPoint
  528. })
  529. }
  530. })
  531. $(".screen .itemTitle button").on('click',()=>{
  532. $(".screen .itemTitle button").addClass('hide')
  533. $(".screen .shotImg.innerBtn")[0].cameraData = {};
  534. $(".screen .shotImg.innerBtn").addClass('blank').css("background-image", "")
  535. })
  536. if(data.shareImgUrl){
  537. var imagesHTML = '<div><a class=" result success"><span></span><img src="' + data.shareImgUrl + '"></a></div>'
  538. $(".information .edit-fun-images.list ").html(imagesHTML);
  539. $("#shareImgUpload").addClass("hide")
  540. }
  541. if(data.spotImgUrl){
  542. }
  543. /*************方奕卓 其他项的初始化操作 ************/
  544. initColorElem(data);
  545. // 给其他元素绑定事件
  546. if (data.momentTour === 'black') {
  547. momentTour.prop('checked', true);
  548. }
  549. if (data.showHotListSta) {
  550. hotListSwitch.prop('checked', true);
  551. }
  552. if (data.momentTourBlackNewType) {
  553. $('#newBlack').prop('checked', true);
  554. }
  555. /* if (data.hotIconScale) {
  556. $('#hotIconScale input').val(parseFloat(data.hotIconScale));
  557. } */
  558. /* $('#hotIconScale_2 input').on('change',(e)=>{
  559. var s = THREE.Math.clamp(parseFloat(e.target.value), 0.1, 100)
  560. e.target.value = s
  561. editTool.hotpoint.editSpot.mesh.scale.set(s,s,s)
  562. }) */
  563. if (data.supportsVR) {
  564. VRSwitch.prop('checked', true);
  565. }
  566. /************************************************/
  567. //隐藏公司logo
  568. if (data.loadlogo) {
  569. $loadlogo[0].checked = true
  570. showLogo();
  571. }
  572. // 热点图片放大
  573. if (data.hotImageScale) {
  574. $hotImageScale[0].checked = true
  575. }
  576. // 隐藏地面标记
  577. if (data.hideFloorMarker) {
  578. $hideFloorMarker[0].checked = true
  579. }
  580. // 隐藏鼠标标记
  581. if (data.hideMouseMarker) {
  582. $hideMouseMarker[0].checked = true
  583. }
  584. if (data.showingLabels) {
  585. $showingLabels[0].checked = true
  586. }
  587. //特殊大场景
  588. if (data.special) {
  589. $g_specialScene[0].checked = true
  590. }
  591. //启动二代的数据
  592. if (data.vision_version === "1.1.562.17209" || data.vision_version) {
  593. $twoData[0].checked = true
  594. }
  595. }
  596. /**
  597. * 初始化颜色选择的html元素
  598. * @param {*} data
  599. * @param {*} elem
  600. */
  601. function initColorElem(data, elem) {
  602. let $floorMarkerColor = $('#floorMarkerColor');
  603. let $mouseMarkerColor = $('#mouseMarkerColor');
  604. let $floorMarkerColorTex = $('#floorMarkerColorTex');
  605. let $mouseMarkerColorTex = $('#mouseMarkerColorTex');
  606. let $cadSignColor = $('#cadSignColor');
  607. let $cadSignColorTex = $('#cadSignColorTex');
  608. let $cadBorderColor = $('#cadBorderColor');
  609. let $cadBorderColorTex = $('#cadBorderColorTex');
  610. var colorRe = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/;
  611. // 事件监听
  612. $floorMarkerColor.on('change', function(e) {
  613. $('#floorMarkerColorTex').val(e.target.value)
  614. })
  615. $floorMarkerColorTex.on('blur keydown', function(e) {
  616. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $floorMarkerColor, this);
  617. })
  618. $mouseMarkerColor.on('change', function(e) {
  619. $('#mouseMarkerColorTex').val(e.target.value)
  620. })
  621. $mouseMarkerColorTex.on('blur keydown', function(e) {
  622. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $mouseMarkerColor, this);
  623. })
  624. // 事件监听
  625. $cadSignColor.on('change', function(e) {
  626. $('#cadSignColorTex').val( e.target.value)
  627. })
  628. $cadSignColorTex.on('blur keydown', function(e) {
  629. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadSignColor, this);
  630. })
  631. // 事件监听
  632. $cadBorderColor.on('change', function(e) {
  633. $('#cadBorderColorTex').val( e.target.value)
  634. })
  635. $cadBorderColorTex.on('blur keydown', function(e) {
  636. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadBorderColor, this);
  637. })
  638. // 设置颜色值
  639. function setColor(e, colorElem, inputElem) {
  640. var isColor = colorRe.test(e.target.value);
  641. isColor && colorElem.val(e.target.value);
  642. // isColor ? colorElem.val(e.target.value): (inputElem.placeholder = colorElem.val());
  643. }
  644. // 判断data中是否有存在的颜色值, 否则设置默认值
  645. data.floorMarkerColor ? $floorMarkerColor.val(data.floorMarkerColor) : $floorMarkerColor.val('#4bcdfc');
  646. data.mouseMarkerColor ? $mouseMarkerColor.val(data.mouseMarkerColor) : $mouseMarkerColor.val('#4bcdfc');
  647. // 判断data中是否有存在的颜色值, 否则设置默认值
  648. data.cadSignColor ? $cadSignColor.val(data.cadSignColor) : $cadSignColor.val('#00c8af');
  649. data.cadBorderColor ? $cadBorderColor.val(data.cadBorderColor) : $cadBorderColor.val('#ffffff');
  650. $('input[name="show-cad"]')[0].checked = !!data.showCad
  651. $('#cad-size > option[value="'+(data.cadBorderWidth ? data.cadBorderWidth : '0.01')+'"]').attr("selected",true);
  652. if (data.showCad) {
  653. $('input[name="show-cad"]').trigger('change')
  654. }
  655. $('#panoIdColor').on('change', function(e) {
  656. $('#panoIdColorTex').val(e.target.value)
  657. VisiSet.changePanoIdColor(e.target.value)
  658. })
  659. $('#panoIdColorTex').on('blur keydown', function(e) {
  660. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $('#panoIdColor'), this);
  661. VisiSet.changePanoIdColor(e.target.value)
  662. })
  663. $('#panoIdColor').val('#c13e3e')//初始颜色
  664. $('#panoIdColorTex').val('#c13e3e')
  665. }
  666. $('input[name="show-cad"]').on('change', function(ev) {
  667. if (!ev.target.checked) {
  668. return $('.cad').hide()
  669. }
  670. let taht = this
  671. if (!taht.floorJSON) {
  672. $.ajax({
  673. url: '//super.4dage.com/data/'+ window.number +'/floor.json',
  674. method: 'GET',
  675. success(res) {
  676. taht.floorJSON = res
  677. loadCAD(taht.floorJSON)
  678. $('#cadSignColor').on('change', function(ev) {
  679. loadCAD()
  680. })
  681. $('#cadBorderColor').on('change', function(ev) {
  682. loadCAD()
  683. })
  684. $('#cad-size').on('change', function(ev) {
  685. loadCAD()
  686. })
  687. },
  688. error() {
  689. alert('当前场景没有小地图floor.json文件,请联系三维部门添加')
  690. ev.target.checked = false
  691. }
  692. })
  693. } else {
  694. console.log('0000000000000000000')
  695. $('.cad').show()
  696. }
  697. })
  698. function loadCAD(data) {
  699. grendCAD(data, $('#player')[0], $('#cadSignColor').val(), $('#cadBorderColor').val(), $('#cad-size').val())
  700. }
  701. //设置初始界面
  702. function getSeft(seft) {
  703. $('#camera-start').on('click', function(e) {
  704. if (VisiSet.setPanoVisible) {
  705. return VisiSet.savePanoVisibles()
  706. } else if (VisiSet.setTagVisible) {
  707. return VisiSet.saveTagVisibles()
  708. }
  709. var snapType = editTool.hotpoint.editSpot ? 'hot' : 'screen'
  710. var preview = snapType == 'screen' ? $(".screen .shotImg.innerBtn")[0] : $('#hotpointDetail .shotImg.innerBtn')[0]
  711. var snap = JSON.parse("{" + seft.getSnapAngleInfo() + "}")
  712. preview.cameraData = {
  713. camera: {
  714. position: snap.metadata.camera_position,
  715. quaternion: snap.metadata.camera_quaternion// 相机朝向
  716. },
  717. pano: {
  718. uuid: snap.metadata.scan_id // 起始点位的id
  719. }
  720. }
  721. var ev = document.createEvent("MouseEvent");//截取视图
  722. g_snapShotWidth = snapType == 'screen' ? 240 * 4 : 240;
  723. g_snapShotHeight = snapType == 'screen' ? 118 * 4 : 118;
  724. //window.screenSta = 'startScreen';
  725. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  726. ev.__callback = (imgData,info)=>{
  727. uploadImg(imgData, (rs)=>{
  728. if (rs.code === 0) {
  729. preview.cameraData.thumbImg = rs.data;
  730. preview.style['background-image'] = "url(" + rs.data + ")"
  731. }
  732. }
  733. , "thumbImg.jpg")
  734. }
  735. $(".screen .itemTitle button").removeClass('hide')
  736. window.dispatchEvent(ev);
  737. });
  738. }
  739. //热点编辑
  740. var Hotpoint = function() {
  741. this.spotList = $(".spotList");
  742. this.hotpointDetail = $("#hotpointDetail");
  743. this._scale = {}
  744. this.scroller = {}
  745. this.scroller.boxDepth = new SlideBar({
  746. root: $('#boxDepth').eq(0),
  747. value: 0,
  748. min: 0 * 100,
  749. max: 1 * 100,
  750. name: "boxDepth",
  751. unitStr: "cm",
  752. avoidCrash: true,
  753. onchange: (s)=>{
  754. if (s == 0) {
  755. this.editSpot.addBox(false)
  756. } else {
  757. this.editSpot.addBox(true)
  758. this.editSpot.scale.z = s / 100 ;
  759. this.updateTransform("scale")
  760. }
  761. },
  762. dragEndEvent: function() {
  763. }
  764. })
  765. // fyz 导览编辑页面同样采取热点编辑的样式, 这里确保只查找到热点编辑
  766. }
  767. Hotpoint.prototype.init = function() {
  768. var that = this;
  769. $(".hotStyle-item li").on('click', function() {//默认样式
  770. $(this).addClass('active').siblings().removeClass('active');
  771. })
  772. // 添加多媒体
  773. this.musicBox = musicPlayBoxBind(this.hotpointDetail.find("[name=audio].mediaUpload"), null )
  774. this.addmediaInit();
  775. // 添加音乐
  776. this.addModel();
  777. // 添加模型
  778. this.addwebPack();
  779. // 添加外链
  780. this.wireframeModel = new THREE.Object3D;
  781. if(Hot.allPhotoLoaded && Hot.allModelLoaded) this.initListSelect()
  782. else Hot.whenAllFileLoaded = this.initListSelect.bind(this) //等全部photo加载完
  783. player.model.hotGroup.children.forEach(e=>this.addHotList(e) )//创建列表
  784. this.hotpointDetail.find(".tail .submit").on('click', this.saveHot.bind(this))
  785. this.hotpointDetail.find("[name=info] input").on('change',(e)=>{//标题
  786. this.editSpot.info.title = e.target.value
  787. this.editSpot.setTitleElem()
  788. })
  789. //media简介
  790. {
  791. let textarea = this.hotpointDetail.find('li[name="photo"] textarea, li[name="video"] textarea');
  792. textarea.on('change',(e)=>{
  793. if(!e.target.currentBtn)return
  794. e.target.currentBtn.desc = e.target.value;
  795. this.descBtnUpdate(e.target.currentBtn )
  796. })
  797. //应用到所有
  798. let applyAll = (type)=>{
  799. var choice = confirm(`确定将文字应用到此热点的所有${type == 'photo' ? '图片' : '视频'}吗?`);
  800. if (choice) {
  801. Array.from(that.hotpointDetail.find(`[name=${type}] .list .descBtn`)).forEach(btn=>{
  802. btn.desc = this.hotpointDetail.find(`li[name=${type}] textarea`)[0].value
  803. this.descBtnUpdate(btn)
  804. })
  805. }
  806. }
  807. this.hotpointDetail.find('li[name="photo"] button').on('click',()=>{
  808. applyAll("photo")
  809. })
  810. this.hotpointDetail.find('li[name="video"] button').on('click',()=>{
  811. applyAll("video")
  812. })
  813. }
  814. /* {
  815. let ui = $('#hotIconScale input')
  816. let min = parseFloat(ui.attr('min'));
  817. let max = parseFloat(ui.attr('max'));
  818. ui.on("change", function(e) {
  819. var s = THREE.Math.clamp(parseFloat(e.target.value), min, max)
  820. if(isNaN(s))s = 1
  821. e.target.value = s
  822. DATA.hotIconScale = s
  823. })
  824. } */
  825. $(".hotpoint [name='adjustSize'] button").on('click',(e)=>{
  826. let type = $(e.target).attr('index')
  827. var c = 1.1
  828. if(type == '-'){
  829. s = 1/c
  830. }else{
  831. s = c
  832. }
  833. s = Math.max(0.001, s)
  834. player.model.hotGroup.children.forEach(hot=>{
  835. if(hot.texType == 'shine'){
  836. hot.info.scale.multiplyScalar(s)
  837. hot.scale.multiplyScalar(s)
  838. }
  839. })
  840. DATA.hotIconScale *= s
  841. })
  842. this.isSpriteCheckBox = new CheckBox({dom: $("#isSprite"),
  843. uiCallBack : (checked)=>{
  844. },
  845. callbackWhenChose:(checked)=>{
  846. that.editSpot.info.isSprite = checked;
  847. if(checked) {
  848. that.editSpot.update(player)
  849. }else{
  850. that.editSpot.rotation.copy(that.editSpot.info.rotation)
  851. }
  852. }
  853. })
  854. //clickEvent
  855. this.actionCheckBox = new CheckBox({dom: this.hotpointDetail.find("li[name='clickEvent'] li.editCheckbox input"),
  856. uiCallBack : (checked, name)=>{
  857. if(name == 'openHot'){
  858. var content = that.hotpointDetail.find("li[name='content']")
  859. checked ? content.removeClass('hide') : content.addClass('hide')
  860. }else if(name == 'fastTran'){//瞬间过渡
  861. var fastTran = that.hotpointDetail.find("li[name='fastTran']")
  862. checked ? fastTran.removeClass('hide') : fastTran.addClass('hide')
  863. }
  864. },
  865. callbackWhenChose:(checked, name)=>{
  866. that.editSpot.info.actionType[name] = !!checked;
  867. }
  868. })
  869. this.imgDescCheckBox = new CheckBox({dom: this.hotpointDetail.find("#addImgDesc"),
  870. uiCallBack : (checked, name)=>{
  871. var textarea = this.hotpointDetail.find('li[name="photo"] textarea');
  872. var title = this.hotpointDetail.find('li[name="photo"] [name="descTitle"]')
  873. if(!checked){
  874. textarea.addClass('hide'), title.addClass('hide')
  875. /* textarea.val('');
  876. textarea[0].currentBtn = null */
  877. }else{
  878. textarea.removeClass('hide'), title.removeClass('hide')
  879. }
  880. var imgArea = this.hotpointDetail.find('li[name="photo"] .edit-fun-images');
  881. checked ? imgArea.addClass('hasDescBtn') : imgArea.removeClass('hasDescBtn')
  882. },
  883. callbackWhenChose:(checked, name)=>{
  884. that.editSpot.info.useImgDesc = !!checked;
  885. }
  886. })
  887. this.videoDescCheckBox = new CheckBox({dom: this.hotpointDetail.find("#addVideoDesc"),
  888. uiCallBack : (checked, name)=>{
  889. var textarea = this.hotpointDetail.find('li[name="video"] textarea');
  890. var title = this.hotpointDetail.find('li[name="video"] [name="descTitle"]')
  891. if(!checked){
  892. textarea.addClass('hide'), title.addClass('hide')
  893. /* textarea.val('');
  894. textarea[0].currentBtn = null */
  895. }else{
  896. textarea.removeClass('hide'), title.removeClass('hide')
  897. }
  898. var Area = this.hotpointDetail.find('li[name="video"] .edit-fun-images');
  899. checked ? Area.addClass('hasDescBtn') : Area.removeClass('hasDescBtn')
  900. },
  901. callbackWhenChose:(checked, name)=>{
  902. that.editSpot.info.useVideoDesc = !!checked;
  903. }
  904. })
  905. //点击添加热点按钮
  906. $('.hotpoint .addBtn button').on("click", function(e) {
  907. g_HotStatus = $(e.target).attr('data-type');
  908. //$("#player").css("cursor", "cell");
  909. CursorDeal.add('addHot' )
  910. });
  911. //点击热点列表弹出按钮
  912. this.spotList.on("click", function(e) {
  913. var target = $(e.target);
  914. let li = searchParent(e.target, { className: 'listItem' }, 7);
  915. if(!li)return;
  916. var hotId = $(li).attr("data-spid");
  917. var hot = player.model.hots[hotId]
  918. if(VisiSet.setTagVisible){
  919. return VisiSet.SetOneTagVisible(hot)
  920. }
  921. if (target.hasClass("del")) {
  922. e.stopPropagation();
  923. target.siblings(".DelConfirm").addClass("active");
  924. that.spotList.find("i").text(that.spotList.find("ul li").length);
  925. } else {
  926. if (target.hasClass("DelConfirm")) {
  927. e.stopPropagation();
  928. that.removeHot(hot);
  929. } else {
  930. //点击热点列表弹出编辑热点窗口
  931. that.editHot(hot, $(li))
  932. }
  933. }
  934. });
  935. this.hotpointDetail.find(".tail button.delete").on("click", ()=>{
  936. var choice = confirm(`确定删除热点?`);
  937. if (choice) {
  938. that.removeHot(this.editSpot);
  939. cancelEdit(this.editSpot)
  940. }
  941. })
  942. let cancelEdit = (hot)=>{
  943. this.tempInfos && player.model.hotGroup.children.forEach(hot=>{//还原所有同时修改了的贴图和模型
  944. var info = this.tempInfos[hot.sid]
  945. if(hot.texType == 'shine'){
  946. hot.changeTexType(hot.texType, info.styleImg )
  947. hot.info.styleImg = info.styleImg.map(e=>e.src)
  948. }else{
  949. hot.changeTexType(hot.texType, info.texMedia )
  950. hot.info.texSrc = info.texMedia.src;
  951. if(hot.texType == 'photo' && hot.info.animateInfo){
  952. GifTexDeal.remove(hot.animation)
  953. hot.animation = GifTexDeal.addAnimation(hot.material_.map, hot, hot.info.animateInfo )
  954. GifTexDeal.start(hot.animation)
  955. }
  956. }
  957. if(hot.objObject != info.objObject){
  958. this.switchModel({add:info.objObject, spot:hot})
  959. hot.info.scale.copy(info.scale)
  960. hot.scale.copy(info.scale)
  961. }
  962. })
  963. if(this.texLists){
  964. for(let i in this.texLists){this.texLists[i].recover()}
  965. this.modelList.recover()
  966. }
  967. this.editDone();
  968. }
  969. //关闭、取消
  970. this.hotpointDetail.find(".head a.close, .tail button.cancel").on("click", ()=>{
  971. var hot = this.editSpot
  972. if(hot.isNew){
  973. this.removeHot(hot)
  974. }else{
  975. this.recoverInfo(hot)
  976. hot.updateVisible([player.currentPano])
  977. }
  978. cancelEdit(hot)
  979. });
  980. this.linkTypeMenuOptions = new MenuOptions({ //链接打开方式切换
  981. dom: this.hotpointDetail.find(" .MenuOptions[name=linkType] "),
  982. uiCallBack : (o)=>{
  983. },
  984. callbackWhenChose:(o)=>{
  985. this.editSpot.info.linkType = o.$li.attr("index")
  986. }
  987. })
  988. this.panoTransformCheckBox = new CheckBox({dom: $('#setPosForPano input') ,
  989. uiCallBack : (checked, name)=>{
  990. },
  991. callbackWhenChose:(checked, name)=>{
  992. if(!checked){
  993. delete this.editSpot.info.transformAtPanos[getTransformSid()]
  994. this.editSpot.position.copy(this.editSpot.info.position)
  995. //this.editSpot.quaternion.copy(this.editSpot.quaternion)
  996. }else{
  997. this.getTransformAtPano('position')
  998. }
  999. }
  1000. })
  1001. /* $('#setPosForPano input').on("change", ()=>{
  1002. var on = $('#setPosForPano input').is(':checked')
  1003. if(!on){
  1004. delete this.editSpot.info.transformAtPanos[getTransformSid()]
  1005. this.editSpot.position.copy(this.editSpot.info.position)
  1006. //this.editSpot.quaternion.copy(this.editSpot.quaternion)
  1007. }else{
  1008. this.getTransformAtPano('position')
  1009. }
  1010. }) */
  1011. //是否显示模型线框
  1012. this.wireframeModel = new THREE.Object3D;
  1013. $('#wireframeSwitch input').on('change',(e)=>{
  1014. var visi = e.target.checked;
  1015. if(visi && this.wireframeModel.children.length == 0){
  1016. var mat = new THREE.MeshBasicMaterial({
  1017. wireframe: true,
  1018. opacity: 0.5,
  1019. color: "#57e4f3",
  1020. transparent: true
  1021. })
  1022. this.wireframeModel.name = 'wireframeModel'
  1023. player.model.chunks.forEach((mesh)=>{
  1024. var chunk = mesh.clone();
  1025. chunk.material = mat;
  1026. this.wireframeModel.add(chunk)
  1027. })
  1028. this.wireframeModel.visible = false
  1029. player.model.add(this.wireframeModel)
  1030. }
  1031. this.wireframeModel.visible = visi
  1032. this.wireframeModel.shouldShow = visi
  1033. })
  1034. $("#autoAdjustHotScale")[0].checked = !!DATA.autoAdjustHotScale;
  1035. //动画
  1036. this.gifCheckBox = new CheckBox({dom: $("#gifSwitch input"),
  1037. uiCallBack : (checked )=>{
  1038. $("#gifInfoEdit").css({display: checked ? 'block' : 'none'})
  1039. },
  1040. callbackWhenChose:(checked )=>{
  1041. if(checked){
  1042. that.editSpot.info.animateInfo = {
  1043. cellXcount : parseInt($("#gifXCount").val()),
  1044. cellYcount : parseInt($("#gifYCount").val()),
  1045. voidCount : parseInt($("#voidCount").val()),
  1046. loop : true,
  1047. duration : parseFloat($("#gifDuration").val()) * 1000
  1048. }
  1049. that.editSpot.animation = GifTexDeal.addAnimation(that.editSpot.material_.map, that.editSpot, this.editSpot.info.animateInfo, this.editSpot.sid)
  1050. GifTexDeal.start(that.editSpot.animation)
  1051. }else{
  1052. GifTexDeal.remove(that.editSpot.animation)
  1053. that.editSpot.info.animateInfo = null
  1054. }
  1055. }
  1056. })
  1057. {//gif动画 input
  1058. let changeAnimation = function(){
  1059. GifTexDeal.setRepeart(that.editSpot.animation.animation)
  1060. that.useSuitableRatio()
  1061. }
  1062. let restartAnimation = function(){
  1063. GifTexDeal.stop(that.editSpot.animation)
  1064. GifTexDeal.start(that.editSpot.animation)
  1065. }
  1066. let changeFrameCount = function(){
  1067. var a = that.editSpot.info.animateInfo
  1068. var frameCount = a.cellXcount * a.cellYcount - (a.voidCount||0)
  1069. $("#gifFrameCount").text(frameCount)
  1070. var fps = parseFloat($("#gifFps").val())
  1071. a.duration = frameCount / fps * 1000
  1072. $("#gifDuration").val(toPrecision(a.duration/1000, 2))
  1073. }
  1074. let gifXCountFun = function(value){
  1075. that.editSpot.info.animateInfo.cellXcount = value
  1076. var gifImgWidth = parseFloat($("#gifImgWidth").text())
  1077. var gifCellWidth = toPrecision(gifImgWidth / that.editSpot.info.animateInfo.cellXcount,1);
  1078. $("#gifCellWidth").text(gifCellWidth)
  1079. changeFrameCount()
  1080. changeAnimation()
  1081. }
  1082. $("#gifXCount").on('input',(e)=>{
  1083. strictInputNum(e, 0, 1)
  1084. gifXCountFun(parseFloat(e.target.value))
  1085. })
  1086. $("#gifXCount").on('change',(e)=>{
  1087. strictInputNum(e, 0, 1)
  1088. gifXCountFun(parseFloat(e.target.value))
  1089. restartAnimation()
  1090. })
  1091. let gifYCountFun = function(value){
  1092. that.editSpot.info.animateInfo.cellYcount = value
  1093. var gifImgHeight = parseFloat($("#gifImgHeight").text())
  1094. var gifCellHeight = toPrecision(gifImgHeight / that.editSpot.info.animateInfo.cellYcount,1);
  1095. $("#gifCellHeight").text(gifCellHeight)
  1096. changeFrameCount()
  1097. changeAnimation()
  1098. }
  1099. $("#gifYCount").on('input',(e)=>{
  1100. strictInputNum(e, 0, 1)
  1101. gifYCountFun(parseFloat(e.target.value))
  1102. })
  1103. $("#gifYCount").on('change',(e)=>{
  1104. strictInputNum(e, 0, 1)
  1105. gifYCountFun(parseFloat(e.target.value))
  1106. changeAnimation()
  1107. restartAnimation()
  1108. })
  1109. /* let gifCellWidthFun = function(value){
  1110. var gifCellWidth = value;
  1111. var gifImgWidth = parseFloat($("#gifImgWidth").text())
  1112. var cellXcount = toPrecision(gifImgWidth / gifCellWidth,2);
  1113. $("#gifXCount").val(cellXcount)
  1114. changeAnimation()
  1115. }
  1116. $("#gifCellWidth").on('input',(e)=>{
  1117. strictInputNum(e, 0)
  1118. gifCellWidthFun(parseFloat(e.target.value))
  1119. })
  1120. $("#gifCellWidth").on('change',(e)=>{
  1121. strictInputNum(e, 0, 1)
  1122. gifCellWidthFun(parseFloat(e.target.value))
  1123. var cellXcount = $("#gifXCount").val();
  1124. var cellXcountInt = Math.round(cellXcount)
  1125. if(cellXcountInt != cellXcount){
  1126. $("#gifXCount").val(cellXcountInt)
  1127. gifXCountFun(cellXcountInt)
  1128. changeAnimation()
  1129. }
  1130. restartAnimation()
  1131. })
  1132. let gifCellHeightFun = function(value){
  1133. var gifCellHeight = parseFloat(e.target.value);
  1134. var gifImgHeight = parseFloat($("#gifImgHeight").text())
  1135. var cellYcount = toPrecision(gifImgHeight / gifCellHeight,2);
  1136. $("#gifYCount").val(cellYcount)
  1137. }
  1138. $("#gifCellHeight").on('input',(e)=>{
  1139. strictInputNum(e, 0)
  1140. gifCellHeightFun(parseFloat(e.target.value))
  1141. })
  1142. $("#gifCellHeight").on('change',(e)=>{
  1143. strictInputNum(e, 0, 1)
  1144. gifCellHeightFun(parseFloat(e.target.value))
  1145. var cellYcount = $("#gifYCount").val();
  1146. var cellYcountInt = Math.round(cellYcount)
  1147. if(cellYcountInt != cellYcount){
  1148. $("#gifYCount").val(cellYcountInt)
  1149. gifYCountFun(cellYcountInt)
  1150. changeAnimation()
  1151. }
  1152. restartAnimation()
  1153. })*/
  1154. $("#voidCount").on('change',(e)=>{
  1155. strictInputNum(e, 0);
  1156. that.editSpot.info.animateInfo.voidCount = parseInt(e.target.value)
  1157. changeFrameCount()
  1158. restartAnimation()
  1159. })
  1160. let gifDurationFun = function(value){
  1161. var a = that.editSpot.info.animateInfo
  1162. let frameCount = a.cellXcount * a.cellYcount
  1163. a.duration = value
  1164. $("#gifFps").val(toPrecision(frameCount / a.duration * 1000, 1))
  1165. }
  1166. $("#gifDuration").on('input',(e)=>{
  1167. strictInputNum(e, 1);
  1168. gifDurationFun(parseFloat(e.target.value) * 1000)
  1169. })
  1170. $("#gifDuration").on('change',(e)=>{
  1171. strictInputNum(e, 1, 0.01);
  1172. gifDurationFun(parseFloat(e.target.value) * 1000)
  1173. restartAnimation()
  1174. })
  1175. var gifFpsFun = function(e){
  1176. strictInputNum(e, 0, 1);
  1177. var fps = parseFloat(e.target.value)
  1178. var a = that.editSpot.info.animateInfo
  1179. let frameCount = a.cellXcount * a.cellYcount - (a.voidCount||0)
  1180. a.duration = frameCount / fps * 1000
  1181. $("#gifDuration").val(toPrecision(a.duration / 1000, 2))
  1182. }
  1183. $("#gifFps").on('input',(e)=>{
  1184. gifFpsFun(e)
  1185. })
  1186. $("#gifFps").on('change',(e)=>{
  1187. gifFpsFun(e)
  1188. restartAnimation()
  1189. })
  1190. }
  1191. this.modelMenuOptions = new MenuOptions({
  1192. dom: this.hotpointDetail.find(".MenuOptions[name=modelType]"),
  1193. uiCallBack : (o)=>{
  1194. var name = o.name == void 0 ? o.$li.attr('index') : o.name
  1195. if(name == "default"){
  1196. this.hotpointDetail.find('[name=boxDepthPanel]').removeClass('hide')
  1197. this.updateBoxDepthPanel()
  1198. this.hotpointDetail.find('[name=uploadObj]').addClass('hide')
  1199. transformControls.unableScaleZ()
  1200. }else{
  1201. this.hotpointDetail.find('[name=boxDepthPanel]').addClass('hide')
  1202. this.hotpointDetail.find('[name=uploadObj]').removeClass('hide')
  1203. }
  1204. },
  1205. callbackWhenChose:(o)=>{
  1206. var name = o.$li.attr('index')
  1207. if(name == "default"){
  1208. /* transformControls.unableScaleZ()
  1209. this.editSpot.removeModel() */
  1210. this.switchModel({remove:true, spot:this.editSpot})
  1211. if(this._scale[this.editSpot.texType]){//恢复大小
  1212. this.editSpot.scale.copy(this._scale[this.editSpot.texType]);
  1213. this.editSpot.info.scale.copy(this._scale[this.editSpot.texType]);
  1214. }
  1215. }else{
  1216. this.modelList.options.selectFun()
  1217. this._scale[this.editSpot.texType] = this.editSpot.scale.clone()
  1218. }
  1219. }
  1220. })
  1221. this.titleShowOptions = new MenuOptions({ //何时显示
  1222. dom: this.hotpointDetail.find(".MenuOptions[name=titleShowType]"),
  1223. uiCallBack : (o)=>{
  1224. },
  1225. callbackWhenChose:(o)=>{
  1226. var name = o.name == void 0 ? o.$li.attr('index') : o.name
  1227. this.editSpot.info.titleShowType = name
  1228. this.editSpot.setHoverState(false) //update
  1229. }
  1230. })
  1231. this.titlePosOptions = new MenuOptions({ //相对热点的位置
  1232. dom: this.hotpointDetail.find(".MenuOptions[name=titlePos]"),
  1233. uiCallBack : (o)=>{
  1234. },
  1235. callbackWhenChose:(o)=>{
  1236. var name = o.name == void 0 ? o.$li.attr('index') : o.name
  1237. this.editSpot.info.titlePos = name
  1238. this.editSpot.setTitleDir();
  1239. this.latestTitlePos = this.editSpot.info.titlePos//最近一次设置的,运用到新的热点中
  1240. }
  1241. })
  1242. this.hotpointDetail.find("li[name='fastTran'] button").on('click',(e)=>{
  1243. this.setCameraBtn(!this.gettingCameraData)
  1244. })
  1245. {
  1246. let pos = new THREE.Vector3(Infinity,Infinity,Infinity)
  1247. player.on("view.changed",(e)=>{
  1248. if(e.cameraChanged && !pos.equals(player.position)){
  1249. this.updateDis();
  1250. pos.copy(player.position)
  1251. }
  1252. })
  1253. }
  1254. }
  1255. Hotpoint.prototype.setCameraBtn = function(state){
  1256. let btn = this.hotpointDetail.find("li[name='fastTran'] button")
  1257. if(!state){
  1258. confirmSnap.addClass("hide");
  1259. snapshotGui.hide();
  1260. btn.text('设置')
  1261. this.gettingCameraData = false
  1262. }else{
  1263. confirmSnap.removeClass("hide");
  1264. $('#camera-start').text("点此设置跳转到此方位")
  1265. snapshotGui.show();
  1266. if (player.mode != "panorama"){
  1267. $(".confirmSnap").addClass("unable")
  1268. }else{
  1269. $(".confirmSnap").removeClass("unable")
  1270. }
  1271. btn.text('结束设置')
  1272. this.gettingCameraData = true
  1273. }
  1274. }
  1275. Hotpoint.prototype.updateBoxDepthPanel = function(){
  1276. var hot = this.editSpot
  1277. if (hot.info.hasBox) {
  1278. this.scroller.boxDepth.setValue(hot.scale.z * 100, true)
  1279. } else {
  1280. this.scroller.boxDepth.setValue(0, true)
  1281. }
  1282. setTimeout(()=>{
  1283. this.scroller.boxDepth.InitOffset()
  1284. }, 201)
  1285. }
  1286. /**
  1287. * 显示编辑热点的窗口和初始化热点窗口的数据
  1288. */
  1289. Hotpoint.prototype.editHot = function(hot, $li) {
  1290. try {
  1291. transformControls.attach(hot)
  1292. if(player.mode == 'panorama'){
  1293. hot.examine( {
  1294. dontOpen: true, examine:true,
  1295. dontFastTran: true,
  1296. aimDuration : 600,
  1297. duration : 600
  1298. })
  1299. }else{
  1300. player.focusPoint({aim: hot.position, radius:hot.position.distanceTo(player.position)})
  1301. }
  1302. } catch (e) {}
  1303. if(this.editSpot == hot)return
  1304. this.hotpointDetail.removeClass("atRight");
  1305. $("#hotpointDetail .audio.mediaUpload").find("input").val('');
  1306. var playIcon = 'images/play.png';
  1307. this.editSpot = hot
  1308. transformControls.transformMenuOptions.updateChoseAtUI({name:'translate'}) //$(".MenuOptions[name='transform'] li[index='translate']").click()//transformControls.transCtlChangeMode("translate")
  1309. this.getTempInfo(hot)
  1310. hot.visible = true
  1311. this.updatePano()
  1312. this.updateListSelect(hot);
  1313. //$("#isSprite")[0].checked = this.editSpot.info.isSprite
  1314. this.isSpriteCheckBox.updateChoseAtUI(this.editSpot.info.isSprite)
  1315. this.imgDescCheckBox.updateChoseAtUI(this.editSpot.info.useImgDesc)
  1316. this.videoDescCheckBox.updateChoseAtUI(this.editSpot.info.useVideoDesc)
  1317. this.linkTypeMenuOptions.updateChoseAtUI({name:this.editSpot.info.linkType})
  1318. this.updateClickEventUI();//根据actionType更新ui
  1319. var iframesHTML = hot.info.iframe.map(function(iframe) {
  1320. return this.inputList("请填写网页链接", iframe)
  1321. }.bind(this))
  1322. var modulesHTML = hot.info.model.map(function(module) {
  1323. return this.inputList("请填写网页链接", module)
  1324. }.bind(this))
  1325. var imagesHTML = hot.info.images.map(function(image,index) {
  1326. 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>'
  1327. })
  1328. var videosHTML = hot.info.video.map(function(ly) {
  1329. var thumb = (!ly.img || ly.img === "undefined") ? '' : '<img src='+ ly.img +' class="bg"></img>'
  1330. var thumbResult = (!ly.img || ly.img === "undefined") ? '' : 'success';
  1331. 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>'
  1332. return dom
  1333. })
  1334. this.hotpointDetail.find(".name > input").val(hot.info.title);
  1335. this.hotpointDetail.find('[name="intro"] .editText').val(hot.info.content);
  1336. this.hotpointDetail.find("[name=photo] .list").html(imagesHTML);
  1337. this.hotpointDetail.find("[name=video] .list").html(videosHTML);
  1338. this.hotpointDetail.find("[name=modelSrc] .list").html(modulesHTML);
  1339. this.hotpointDetail.find("[name=webPage] .list").html(iframesHTML);
  1340. Array.from(this.hotpointDetail.find("[name=photo] .list .descBtn")).forEach((btn,index)=>{
  1341. this.descBtnBind(btn, 'photo', this.editSpot.info.imagesDesc[index])
  1342. this.descBtnUpdate(btn,index)
  1343. })
  1344. Array.from(this.hotpointDetail.find("[name=video] .list .descBtn")).forEach((btn,index)=>{
  1345. this.descBtnBind(btn, 'video', this.editSpot.info.videosDesc[index])
  1346. this.descBtnUpdate(btn,index)
  1347. })
  1348. this.descBtnChose(null, 'photo')
  1349. this.descBtnChose(null, 'video')
  1350. let bgName = hot.info.bgName || '热点背景音乐';
  1351. if (hot.info.backgroundMusic) {
  1352. this.musicBox.show(/* this.hotpointDetail.find(".audio.mediaUpload"), */bgName, hot.info.backgroundMusic)
  1353. } else {
  1354. this.musicBox.hide()
  1355. }
  1356. {//跳转方位设置
  1357. var preview = $('#hotpointDetail .shotImg.innerBtn')[0]
  1358. preview.cameraData = hot.info.cameraData
  1359. if(hot.info.cameraData){
  1360. preview.style['background-image'] = "url(" + hot.info.cameraData.thumbImg + ")"
  1361. }else{
  1362. preview.style['background-image'] = ''
  1363. }
  1364. }
  1365. {//标题显示
  1366. this.titleShowOptions.updateChoseAtUI({name:this.editSpot.info.titleShowType})
  1367. this.titlePosOptions.updateChoseAtUI({name:this.editSpot.info.titlePos})
  1368. }
  1369. $('#setPosForPano [name="dis"]').removeClass('hide');
  1370. this.updateDis()
  1371. }
  1372. Hotpoint.prototype.updateDis = function(){
  1373. if(!this.editSpot)return
  1374. var pos = this.editSpot.position;
  1375. var playerPos = player.position;
  1376. var dis1 = pos.clone().setY(0).distanceTo(playerPos.clone().setY(0))
  1377. var disY = pos.y - playerPos.y
  1378. var dir = disY>0 ? '上' : '下'
  1379. $('#setPosForPano [name="dis"]').html(`与相机水平距离: ${toPrecision(dis1, 2)}m , <br>在相机之${dir}: ${toPrecision(Math.abs(disY), 2)}m`)
  1380. }
  1381. Hotpoint.prototype.recoverInfo = function(hot) { // 恢復
  1382. hot.info = hot.tempInfo;
  1383. hot.setFromInfo(hot.info, hot.tempInfo.media, hot.tempInfo.objObject)
  1384. delete hot.info.media
  1385. delete hot.info.objObject
  1386. }
  1387. Hotpoint.prototype.getTempInfo = function(hot) { // 编辑前, 从当前状态获取info, 用於恢復
  1388. var plane = hot.plane;
  1389. var info = hot.info;
  1390. hot.tempInfo = CloneObject(info);
  1391. hot.tempInfo.media = hot.texMedia
  1392. hot.tempInfo.objObject = hot.objObject
  1393. this.getTempInfos()
  1394. }
  1395. Hotpoint.prototype.getTempInfos = function(){
  1396. if(Hot.allPhotoLoaded && Hot.allModelLoaded){
  1397. this.tempInfos = {}
  1398. player.model.hotGroup.children.forEach(hot=>{
  1399. this.tempInfos[hot.sid] = {
  1400. styleImg : hot.styleImg,
  1401. texMedia : hot.texMedia,
  1402. objObject : hot.objObject,
  1403. scale : hot.scale.clone()
  1404. }
  1405. })
  1406. }
  1407. }
  1408. Hotpoint.prototype.getTransformAtPano = function(type){
  1409. /* var name = getTransformSid()
  1410. var info = {
  1411. pos : this.editSpot.mesh.position.clone()
  1412. }
  1413. if(!this.editSpot.isSprite){
  1414. info.qua = this.editSpot.mesh.quaternion.clone()
  1415. }else{
  1416. if(type == 'quaternion')return; //如果恒朝向相机且调整的是quaternion,不要保存position
  1417. }
  1418. this.editSpot.transformAtPanos[name] = info */
  1419. //this.editSpot.usingTransformData = true
  1420. var name = getTransformSid()
  1421. this.editSpot.info.transformAtPanos[name] = {
  1422. pos : this.editSpot.position.clone()
  1423. }
  1424. }
  1425. Hotpoint.prototype.updateTransform = function(type){
  1426. var on = this.panoTransformCheckBox.checked() //$('#setPosForPano input').is(':checked')
  1427. //var name = getTransformSid()
  1428. if(on && type == 'position'){
  1429. this.getTransformAtPano(type)
  1430. }else{
  1431. if(type == 'position'){
  1432. this.editSpot.info.position.copy(this.editSpot.position)
  1433. }else if(type == 'quaternion'){
  1434. if(!this.editSpot.isSprite){ //如果恒朝向相机就不保存quaternion
  1435. this.editSpot.info.rotation.copy(this.editSpot.rotation)
  1436. }
  1437. }else if(type == 'scale'){
  1438. this.editSpot.info.scale.copy(this.editSpot.scale)
  1439. }
  1440. }
  1441. type == 'position' && this.updateDis()
  1442. }
  1443. Hotpoint.prototype.updatePano = function(){
  1444. if(!this.editSpot ) return;
  1445. //$('#setPosForPano input').prop('checked', !!this.editSpot.info.transformAtPanos[getTransformSid()]);
  1446. this.panoTransformCheckBox.updateChoseAtUI(!!this.editSpot.info.transformAtPanos[getTransformSid()])
  1447. }
  1448. var ifSameTex = function(imgs0, imgs1){//是否是相同的图 (两个都是空的不算相同)
  1449. return !!(imgs0[0] && imgs1[0] && imgs0[0].src == imgs1[0].src &&
  1450. (imgs0[1] ? (imgs1[1] && imgs0[1].src == imgs1[1].src) : !imgs1[1] ))
  1451. }
  1452. Hotpoint.prototype.findSpotByContent = (media, type)=>{////使用了该贴图的所有热点
  1453. var spots = []
  1454. if(type == 'shine'){
  1455. media = media || []
  1456. for(var i in player.model.hots){
  1457. if(player.model.hots[i].texType != type)continue
  1458. var styleImg = player.model.hots[i].styleImg || [];
  1459. if(ifSameTex(styleImg, media)){
  1460. spots.push(player.model.hots[i])
  1461. }
  1462. }
  1463. }else if(type == 'photo' || type == 'video'){
  1464. if(type == 'photo' && !Hot.allPhotoLoaded)return spots
  1465. for(var i in player.model.hots){
  1466. if(player.model.hots[i].texType != type)continue
  1467. var texMedia = player.model.hots[i].texMedia
  1468. if(media && texMedia && media.src == texMedia.src){
  1469. spots.push(player.model.hots[i])
  1470. }
  1471. }
  1472. }else if(type == 'model'){
  1473. if(!Hot.allModelLoaded)return spots
  1474. for(var i in player.model.hots){
  1475. if(!player.model.hots[i].objObject)continue
  1476. var objObject = player.model.hots[i].objObject
  1477. if(media && objObject && media.src == objObject.src){
  1478. spots.push(player.model.hots[i])
  1479. }
  1480. }
  1481. }
  1482. return spots
  1483. }
  1484. Hotpoint.prototype.initListSelect = function(){//热点样式图列表
  1485. var that = this;
  1486. var countElem = $("<a class='showCount'></a>")
  1487. var uploadInputImage = $('<input type="file" style="display:none" accept="image/*"></input>');
  1488. var uploadInputVideo = $('<input type="file" style="display:none" accept="video/*"></input>');
  1489. var uploadInputModel = $('<input type="file" style="display:none" accept=".obj,.OBJ"></input>');
  1490. var getListItem = ()=>{
  1491. 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>')
  1492. elem[0]._styleImg = []
  1493. return elem
  1494. }
  1495. var editItemInfo = {}
  1496. var setImgContent = function($dom, index, src) {
  1497. var li = $dom.find('li').eq(index)
  1498. var div = li.find('>div');
  1499. if (src) {
  1500. li.addClass("uploaded")
  1501. div.css("background-image", `url(${src})`)
  1502. } else {
  1503. li.removeClass("uploaded")
  1504. div.css("background-image", '')
  1505. }
  1506. }
  1507. var hotIcons = []; // 从所有热点tex中搜集 。
  1508. player.model.hotGroup.children.forEach(e=>{// 从所有热点tex中搜集
  1509. if(e.texType == 'shine'){
  1510. let imgs = e.info.styleImg;
  1511. if(imgs && imgs.length){
  1512. if(!hotIcons.find(e=>e[0] == imgs[0] && e[1] == imgs[1])){
  1513. hotIcons.push(imgs)
  1514. }
  1515. }
  1516. }
  1517. })
  1518. hotIcons = hotIcons.map(imgs=>imgs = imgs.map((a)=>{return {src:a}}))
  1519. //hotIcons = [[], [g_HotImage.point, g_HotImage.point2], ...hotIcons]
  1520. hotIcons.push([{src:g_HotImage.point}, {src:g_HotImage.point2}],[] )//放末尾用来添加的 g_HotImage是默认
  1521. var list = hotIcons.map(arr=>{//初始列表
  1522. var elem = getListItem()
  1523. elem[0]._styleImg = arr //每个li上绑定一个 _styleImg,存储它包含的图, 和热点的styleImg对应
  1524. var divs = elem.find("li>div")
  1525. arr.forEach((img,i)=>{
  1526. setImgContent(elem, i, img.src)
  1527. })
  1528. arr.length && elem.find("li").eq(1).removeClass('hide')
  1529. return elem
  1530. })
  1531. list[list.length - 2].addClass('forbitEdit')
  1532. this.styleList = new ListBox(list, $('#shineTexSelect'), {//列表
  1533. selectFun:(o={})=>{//选中时要改变选中项selection缩略图 以及改变热点
  1534. if(this.styleList.chosenItem == void 0){
  1535. this.styleList.listTitle.find('li').addClass('hide')
  1536. }else{
  1537. this.styleList.listTitle.find('li').removeClass('hide')
  1538. var divs = this.styleList.listTitle.find('li>div')//selection
  1539. var imgs = this.styleList.chosenItem[0]._styleImg;
  1540. if(imgs[0]){
  1541. divs.eq(0).css("background-image", 'url("'+imgs[0].src+'")')
  1542. divs.eq(0).parent().removeClass('hide')
  1543. }else{
  1544. divs.eq(0).parent().addClass('hide')
  1545. }
  1546. if(imgs[1]){
  1547. divs.eq(1).css("background-image", 'url("'+imgs[1].src+'")')
  1548. divs.eq(1).parent().removeClass('hide')
  1549. }else{
  1550. divs.eq(1).parent().addClass('hide')
  1551. }
  1552. //应用到热点:
  1553. o.dontApplyToHot || this.editSpot.changeShineTex(imgs)
  1554. }
  1555. Array.from(this.styleList.listDom.children()).forEach(li=>{//更新一下所有的li的使用的spot
  1556. li.sameContentSpots = this.findSpotByContent(li._styleImg, 'shine')
  1557. })
  1558. },
  1559. /* delFun: ()=>{
  1560. }, */
  1561. addFun: ($li)=>{ //列表新增时对li的操作
  1562. $li[0].sameContentSpots = this.findSpotByContent($li[0]._styleImg, 'shine')
  1563. $li.find('li').bind('click', (e)=>{
  1564. e.stopPropagation()
  1565. var index = $(e.currentTarget).index();
  1566. if($li.hasClass('forbitEdit'))return
  1567. if (e.target.classList.contains("del")) { //删除图片
  1568. if ($li[0]._styleImg.length == 2 && index == 0) { //删除第一个 且有第二个的话
  1569. setImgContent($li, 0, $li[0]._styleImg[1].src);
  1570. setImgContent($li, 1, null);
  1571. $li[0]._styleImg = [$li[0]._styleImg[1]]
  1572. } else {
  1573. setImgContent($li, index, null);
  1574. $li[0]._styleImg.pop()
  1575. if ($li[0]._styleImg.length == 0) {
  1576. //$li.find("li").eq(1).addClass("hide");
  1577. this.styleList.removeItem($li)
  1578. }
  1579. }
  1580. $li[0].sameContentSpots.forEach(hot=>{
  1581. hot.changeShineTex($li[0]._styleImg)
  1582. })
  1583. if($li.hasClass('selected')){//是当前spot的
  1584. //this.editSpot.changeTex($li[0]._styleImg)
  1585. this.styleList.options.selectFun()
  1586. }
  1587. } else {
  1588. //添加图片
  1589. uploadInputImage.click()
  1590. editItemInfo = {
  1591. imgs : $li[0]._styleImg, index, $li , type:"shine"
  1592. };
  1593. }
  1594. })
  1595. $li.bind('mouseover', (e)=>{
  1596. /* this.showTitileSpots = $li[0].sameContentSpots;
  1597. this.showTitileSpots.forEach(a=>a.showTitle()) */
  1598. countElem.text("热点个数:"+$li[0].sameContentSpots.length).removeClass('hide')
  1599. $li.append(countElem)
  1600. $li[0].sameContentSpots.forEach(hot=>{
  1601. hot.changeBoxHelperDisplay(true)
  1602. })
  1603. })
  1604. $li.bind('mouseout', (e)=>{
  1605. /* this.showTitileSpots.forEach(a=>a.hideTitle())
  1606. this.showTitileSpots = null; */
  1607. countElem.addClass('hide')
  1608. $li[0].sameContentSpots.forEach(hot=>{
  1609. hot.changeBoxHelperDisplay(false)
  1610. })
  1611. })
  1612. },
  1613. saveTemp: (list)=>{//编辑热点时保存一份副本
  1614. list._styleImgTemp = Array.from(list.listDom.children()).map((li)=>{
  1615. return li._styleImg.slice()
  1616. })
  1617. },
  1618. recover : (list)=>{//取消编辑时恢复
  1619. Array.from(list.listDom.children()).forEach((li,i)=>{
  1620. li._styleImg = list._styleImgTemp[i]
  1621. li.sameContentSpots = this.findSpotByContent(li._styleImg, 'shine')
  1622. })
  1623. },
  1624. })
  1625. this.styleList.findChosenByContent = (imgs=[])=>{//找到某图对应的li
  1626. var list = Array.from(this.styleList.listDom.children())
  1627. var item = list.find(e=>ifSameTex(e._styleImg, imgs ))
  1628. return {index: item ? list.indexOf(item) : null, item: item }
  1629. }
  1630. /* this.styleList.clearVoid = ()=>{//清理空的
  1631. var length = this.styleList.listDom.children().length;
  1632. Array.from(this.styleList.listDom.children()).forEach((e, i)=>{
  1633. if(i > 0 ){
  1634. if(e._styleImg.length == 0) this.styleList.removeItem($(e))
  1635. }
  1636. })
  1637. } */
  1638. this.styleList.addNew = ()=>{//看是否在第一行增加新的
  1639. /* var lastOne = this.styleList.listDom.children().last();
  1640. if(lastOne[0]._styleImg.length != 0){
  1641. this.styleList.addItem(getListItem())
  1642. } */
  1643. let firstOne = this.styleList.listDom.children().first();
  1644. if(firstOne[0]._styleImg.length != 0){
  1645. this.styleList.addItem(getListItem())
  1646. }
  1647. }
  1648. //-----photo----video-----------------------
  1649. var getPhotoListItem = ()=>{
  1650. var elem = $('<li><div class="upload"><div></div><a class="del hasHover"></a></div></li>')
  1651. return elem
  1652. }
  1653. var getVideoListItem = ()=>{
  1654. var elem = $('<li><div class="upload"><div></div><a class="del hasHover"></a></div></li>')
  1655. return elem
  1656. }
  1657. var photos = [] ,videos = []
  1658. var photoList = [], videoList = []
  1659. player.model.hotGroup.children.forEach(hot=>{
  1660. if(hot.texType == 'photo'){
  1661. var media = hot.texMedia
  1662. if(!photos.find(u=>media == u)){
  1663. photos.push(media)
  1664. var elem = getPhotoListItem()
  1665. elem[0]._media = media
  1666. elem[0].animateInfo = CloneObject(hot.info.animateInfo)
  1667. elem.find(".upload>div").css("background-image", "url(" + hot.info.texSrc + ")")
  1668. elem.find(".upload").addClass("uploaded")
  1669. photoList.push(elem)
  1670. }else{
  1671. //尽量使用带ani的
  1672. if(hot.info.animateInfo){
  1673. let elem = photoList.find(elem=>elem[0]._media == media)
  1674. if(!elem[0].animateInfo) elem[0].animateInfo = CloneObject(hot.info.animateInfo)
  1675. }
  1676. }
  1677. }else if(hot.texType == 'video'){
  1678. var media = hot.texMedia
  1679. if(!videos.find(u=>media.src == u.src)){ //if(!videos.find(u=>media == u)){
  1680. videos.push(media)
  1681. var elem = getVideoListItem()
  1682. elem[0]._media = media
  1683. elem.attr("title", media.name)
  1684. elem.find(".upload>div").text(media.name)
  1685. elem.find(".upload").addClass("uploaded")
  1686. videoList.push(elem)
  1687. }
  1688. }
  1689. })
  1690. photoList.push(getPhotoListItem())//放末尾用来添加的
  1691. this.photoList = new ListBox(photoList, $('#photoTexSelect'), {//列表
  1692. selectFun:(o={})=>{//选中时要改变选中项selection缩略图 以及改变热点
  1693. var div = this.photoList.listTitle.find('.uploaded')//selection
  1694. var media;
  1695. if(this.photoList.chosenItem){
  1696. media = this.photoList.chosenItem[0]._media;
  1697. }
  1698. if(media){
  1699. div.removeClass('hide')
  1700. div.css("background-image", 'url("'+media.src+'")')
  1701. //应用到热点:
  1702. if(!o.dontApplyToHot){
  1703. this.editSpot.changeTexType("photo", media || 'clear' )
  1704. this.updateGifPanel({animateInfo: this.photoList.chosenItem[0].animateInfo })
  1705. this.useSuitableRatio()
  1706. }else{
  1707. this.updateGifPanel({on: !!this.photoList.chosenItem[0].animateInfo })
  1708. }
  1709. $('#gifEdit').removeClass('hide');
  1710. }else{
  1711. !o.dontApplyToHot && this.editSpot.changeTexType("photo", 'clear' )
  1712. this.updateGifPanel({on:false})
  1713. $('#gifEdit').addClass('hide');
  1714. div.addClass('hide')
  1715. }
  1716. Array.from(this.photoList.listDom.children()).forEach(li=>{//更新一下所有的li的使用的spot
  1717. li.sameContentSpots = this.findSpotByContent(li._media, 'photo')
  1718. })
  1719. },
  1720. addFun: ($li)=>{ //photoList列表新增时对li的操作
  1721. $li[0].sameContentSpots = this.findSpotByContent($li[0]._media, 'photo')
  1722. $li.find('.upload').bind('click', (e)=>{
  1723. e.stopPropagation()
  1724. var index = $(e.currentTarget).index();
  1725. if (e.target.classList.contains("del")) { //删除图片
  1726. /* if($li.hasClass('selected')){//(肯定)是当前spot的
  1727. that.editSpot.changeTexType('photo', 'clear')
  1728. }
  1729. $li[0]._media = null */
  1730. this.photoList.removeItem($li)
  1731. } else {
  1732. //添加图片
  1733. uploadInputImage.click()
  1734. editItemInfo = {
  1735. $li , type:"photo"
  1736. };
  1737. }
  1738. })
  1739. $li.bind('mouseover', (e)=>{
  1740. /* this.showTitileSpots = $li[0].sameContentSpots;
  1741. this.showTitileSpots.forEach(a=>a.showTitle()) */
  1742. countElem.text("热点个数:"+$li[0].sameContentSpots.length).removeClass('hide')
  1743. $li.append(countElem)
  1744. $li[0].sameContentSpots.forEach(hot=>{
  1745. hot.changeBoxHelperDisplay(true)
  1746. })
  1747. })
  1748. $li.bind('mouseout', (e)=>{
  1749. /* this.showTitileSpots.forEach(a=>a.hideTitle())
  1750. this.showTitileSpots = null; */
  1751. countElem.addClass('hide')
  1752. $li[0].sameContentSpots.forEach(hot=>{
  1753. hot.changeBoxHelperDisplay(false)
  1754. })
  1755. })
  1756. },
  1757. saveTemp: (list)=>{//编辑热点时保存一份副本
  1758. list._mediaTemp = Array.from(list.listDom.children()).map((li)=>{
  1759. return li._media
  1760. })
  1761. list._animationTemp = Array.from(list.listDom.children()).map((li)=>{
  1762. return li.animateInfo
  1763. })
  1764. },
  1765. recover : (list)=>{//取消编辑时恢复
  1766. Array.from(list.listDom.children()).forEach((li,i)=>{
  1767. li._media = list._mediaTemp[i]
  1768. li.animateInfo = list._animationTemp[i]
  1769. li.sameContentSpots = this.findSpotByContent(li._media, 'photo')
  1770. })
  1771. },
  1772. })
  1773. this.photoList.addNew = ()=>{//看是否在第一行增加新的
  1774. let firstOne = this.photoList.listDom.children().first();
  1775. if(firstOne[0]._media){
  1776. this.photoList.addItem(getPhotoListItem())
  1777. }
  1778. }
  1779. //---videoList-------
  1780. videoList.push(getVideoListItem())//放末尾用来添加的
  1781. this.videoList = new ListBox(videoList, $('#videoTexSelect'), {//列表
  1782. selectFun:(o={})=>{
  1783. var div = this.videoList.listTitle//selection
  1784. var media;
  1785. if(this.videoList.chosenItem){
  1786. media = this.videoList.chosenItem[0]._media;
  1787. }
  1788. if(media){
  1789. //div.removeClass('hide')
  1790. div.text(media ? media.name : '')
  1791. //应用到热点:
  1792. this.editSpot.info.texSrc = media && media.src //视频不能共用一个,否则会一起播放暂停
  1793. this.editSpot.info.fileName = media.name
  1794. this.editSpot.videoWidth = media.videoWidth //记录。因为新new的话要等一会儿才不为0
  1795. this.editSpot.videoHeight = media.videoHeight
  1796. //media.currentTime = 0 //触发oncanplaythrough
  1797. if(!o.dontApplyToHot){
  1798. this.editSpot.changeTexType("video" , media ? null : 'clear' )
  1799. this.useSuitableRatio()
  1800. }
  1801. }else{
  1802. //div.addClass('hide')
  1803. div.text('')
  1804. if(!o.dontApplyToHot){
  1805. this.editSpot.changeTexType("video" , 'clear' )
  1806. }
  1807. }
  1808. Array.from(this.videoList.listDom.children()).forEach(li=>{//更新一下所有的li的使用的spot
  1809. li.sameContentSpots = this.findSpotByContent(li._media, 'video')
  1810. })
  1811. },
  1812. addFun: ($li)=>{
  1813. $li[0].sameContentSpots = this.findSpotByContent($li[0]._media, 'video')
  1814. $li.find('.upload').bind('click', (e)=>{
  1815. e.stopPropagation()
  1816. var index = $(e.currentTarget).index();
  1817. if (e.target.classList.contains("del")) { //删除
  1818. if($li.hasClass('selected')){//是当前spot的
  1819. that.editSpot.changeTexType('video', 'clear')
  1820. }
  1821. $li[0]._media = null
  1822. this.videoList.removeItem($li)
  1823. } else {
  1824. //添加
  1825. uploadInputVideo.click()
  1826. editItemInfo = {
  1827. $li , type:"video"
  1828. };
  1829. }
  1830. })
  1831. $li.bind('mouseover', (e)=>{
  1832. /* this.showTitileSpots = $li[0].sameContentSpots;
  1833. this.showTitileSpots.forEach(a=>a.showTitle()) */
  1834. countElem.text("热点个数:"+$li[0].sameContentSpots.length).removeClass('hide')
  1835. $li.append(countElem)
  1836. $li[0].sameContentSpots.forEach(hot=>{
  1837. hot.changeBoxHelperDisplay(true)
  1838. })
  1839. })
  1840. $li.bind('mouseout', (e)=>{
  1841. /* this.showTitileSpots.forEach(a=>a.hideTitle())
  1842. this.showTitileSpots = null; */
  1843. countElem.addClass('hide')
  1844. $li[0].sameContentSpots.forEach(hot=>{
  1845. hot.changeBoxHelperDisplay(false)
  1846. })
  1847. })
  1848. },
  1849. saveTemp: (list)=>{//编辑热点时保存一份副本
  1850. list._mediaTemp = Array.from(list.listDom.children()).map((li)=>{
  1851. return li._media
  1852. })
  1853. },
  1854. recover : (list)=>{//取消编辑时恢复
  1855. Array.from(list.listDom.children()).forEach((li,i)=>{
  1856. li._media = list._mediaTemp[i]
  1857. li.sameContentSpots = this.findSpotByContent(li._media, 'video')
  1858. })
  1859. },
  1860. })
  1861. this.videoList.addNew = ()=>{//看是否在第一行增加新的
  1862. let firstOne = this.videoList.listDom.children().first();
  1863. if(firstOne[0]._media){
  1864. this.videoList.addItem(getVideoListItem())
  1865. }
  1866. }
  1867. this.photoList.findChosenByContent = this.videoList.findChosenByContent = (list_, media)=>{//找到某图对应的li
  1868. var list = Array.from(list_.listDom.children())
  1869. var item = list.find(e=>e._media && media && e._media.src == media.src)
  1870. return {index: item ? list.indexOf(item) : null, item: item }
  1871. }
  1872. /* this.photoList.clearVoid = this.videoList.clearVoid = (list_)=>{//清理空的
  1873. var length = list_.listDom.children().length;
  1874. Array.from(list_.listDom.children()).forEach((e, i)=>{
  1875. if(i > 0 ){
  1876. if(!e._media ) list_.removeItem($(e))
  1877. }
  1878. })
  1879. } */
  1880. //----modelList---------------------
  1881. var objSrcs = []
  1882. var modelList = []
  1883. var getModelListItem = ()=>{
  1884. var elem = $('<li><div class="upload"><div></div><a class="del hasHover"></a></div></li>')
  1885. return elem
  1886. }
  1887. player.model.hotGroup.children.forEach(e=>{
  1888. if(e.info.objSrc && !objSrcs.find(u=>e.info.objSrc == u)){
  1889. objSrcs.push(e.info.objSrc)
  1890. var elem = getModelListItem()
  1891. elem[0].objObject = e.objObject
  1892. elem.attr("title", e.info.objName)
  1893. elem.find(".upload>div").text(e.info.objName)
  1894. elem.find(".upload").addClass("uploaded")
  1895. modelList.push(elem)
  1896. }
  1897. })
  1898. modelList.push(getModelListItem())//放末尾用来添加的
  1899. this.modelList = new ListBox(modelList, $('#ObjSelect'), {//列表
  1900. selectFun:(o={})=>{
  1901. var div = this.modelList.listTitle//selection
  1902. var model;
  1903. if(this.modelList.chosenItem){
  1904. model = this.modelList.chosenItem[0].objObject;
  1905. }
  1906. if(model){
  1907. //div.removeClass('hide')
  1908. div.text(model ? model.name : '')
  1909. //应用到热点:
  1910. if(!o.dontApplyToHot){
  1911. this.switchModel({add:model,spot:this.editSpot})
  1912. }
  1913. }else{
  1914. //div.addClass('hide')
  1915. div.text('')
  1916. this.switchModel({remove:true,spot:this.editSpot})
  1917. }
  1918. Array.from(this.modelList.listDom.children()).forEach(li=>{//更新一下所有的li的使用的spot
  1919. li.sameContentSpots = this.findSpotByContent(li.objObject, 'model')
  1920. })
  1921. },
  1922. addFun: ($li)=>{
  1923. $li[0].sameContentSpots = this.findSpotByContent($li[0].objObject, 'model')
  1924. $li.find('.upload').bind('click', (e)=>{
  1925. e.stopPropagation()
  1926. var index = $(e.currentTarget).index();
  1927. if (e.target.classList.contains("del")) { //删除
  1928. $li[0].sameContentSpots.forEach(e=>{
  1929. /* e.removeModel() */
  1930. that.switchModel({remove:true, spot:e})
  1931. })
  1932. if($li.hasClass('selected')){//是当前spot的 ui..
  1933. }
  1934. $li[0].objObject = null
  1935. this.modelList.removeItem($li)
  1936. } else {
  1937. //添加
  1938. uploadInputModel.click()
  1939. editItemInfo = {
  1940. $li , type:"model"
  1941. };
  1942. }
  1943. })
  1944. $li.bind('mouseover', (e)=>{
  1945. /* this.showTitileSpots = $li[0].sameContentSpots;
  1946. this.showTitileSpots.forEach(a=>a.showTitle()) */
  1947. countElem.text("热点个数:"+$li[0].sameContentSpots.length).removeClass('hide')
  1948. $li.append(countElem)
  1949. $li[0].sameContentSpots.forEach(hot=>{
  1950. hot.changeBoxHelperDisplay(true)
  1951. })
  1952. })
  1953. $li.bind('mouseout', (e)=>{
  1954. /* this.showTitileSpots.forEach(a=>a.hideTitle())
  1955. this.showTitileSpots = null; */
  1956. countElem.addClass('hide')
  1957. $li[0].sameContentSpots.forEach(hot=>{
  1958. hot.changeBoxHelperDisplay(false)
  1959. })
  1960. })
  1961. },
  1962. saveTemp: (list)=>{//编辑热点时保存一份副本
  1963. list._objTemp = Array.from(list.listDom.children()).map((li)=>{
  1964. return li.objObject
  1965. })
  1966. },
  1967. recover : (list)=>{//取消编辑时恢复
  1968. Array.from(list.listDom.children()).forEach((li,i)=>{
  1969. li.objObject = list._objTemp[i];
  1970. li.sameContentSpots = this.findSpotByContent(li.objObject, 'model')
  1971. })
  1972. },
  1973. })
  1974. this.modelList.addNew = ()=>{//看是否在第一行增加新的
  1975. let firstOne = this.modelList.listDom.children().first();
  1976. if(firstOne[0].objObject){
  1977. this.modelList.addItem(getModelListItem())
  1978. }
  1979. }
  1980. this.modelList.findChosenByContent = (objObject)=>{
  1981. var list = Array.from(this.modelList.listDom.children())
  1982. var item = list.find(e=>e.objObject && e.objObject.src == objObject.src)
  1983. return {index: item ? list.indexOf(item) : null, item: item }
  1984. }
  1985. this.photoList.updateDelBtns = this.videoList.updateDelBtns = (list_)=>{//每次开始编辑热点时更新删除按钮可见性
  1986. Array.from(list_.listDom.children()).forEach(li=>{
  1987. //li.sameContentSpots = this.findSpotByContent(li._media, 'photo')
  1988. if(li.sameContentSpots.find(e=>e!=this.editSpot)){
  1989. $(li).addClass('cannotDelete')
  1990. }else{
  1991. $(li).removeClass('cannotDelete')
  1992. }
  1993. })
  1994. }
  1995. //-----------------------------------
  1996. uploadInputImage.on("change", (e)=>{
  1997. inputMedia({
  1998. enableTypes: ["photo"],
  1999. photoDone: (resultImg)=>{
  2000. if(editItemInfo.type == 'shine'){
  2001. editItemInfo.imgs[editItemInfo.index] = resultImg //{file: resultImg.file, needSave:true, src:resultImg.src}//resultImg
  2002. setImgContent(editItemInfo.$li, editItemInfo.index, resultImg.src)
  2003. if (editItemInfo.index == 0){
  2004. editItemInfo.$li.find('li').eq(1).removeClass("hide");
  2005. }
  2006. resultImg.needSave = true
  2007. editItemInfo.$li[0].sameContentSpots.forEach(hot=>{
  2008. hot.changeShineTex(editItemInfo.$li[0]._styleImg)
  2009. })
  2010. }else{//"photo"
  2011. editItemInfo.$li.find(".upload").addClass("uploaded")
  2012. editItemInfo.$li.find(".upload div").css("background-image", `url(${resultImg.src})`)
  2013. editItemInfo.$li[0]._media = resultImg
  2014. editItemInfo.$li[0].sameContentSpots.forEach(hot=>{
  2015. hot.changeTexType("photo",resultImg)
  2016. })
  2017. resultImg.needSave = true
  2018. }
  2019. /* if(editItemInfo.$li.hasClass('selected')){//是当前spot的
  2020. this.texLists[editItemInfo.type].options.selectFun({dontApplyToHot:true})//更新选中状态
  2021. } */
  2022. this.texLists[editItemInfo.type].addNew()
  2023. this.texLists[editItemInfo.type].selectFromOutSide(editItemInfo.$li.index())
  2024. this.texLists[editItemInfo.type].listDom.addClass('hide')
  2025. }
  2026. }, "photo", e);
  2027. })
  2028. uploadInputVideo.on("change", (e)=>{
  2029. inputMedia({
  2030. enableTypes: ["video"],
  2031. videoDone: (file,video)=>{
  2032. editItemInfo.$li.find(".upload").addClass("uploaded")
  2033. editItemInfo.$li.find(".upload>div").text(file.name)
  2034. editItemInfo.$li.attr("title", file.name)
  2035. video.file = file
  2036. video.name = file.name
  2037. video.needSave = true
  2038. editItemInfo.$li[0]._media = video
  2039. editItemInfo.$li[0].sameContentSpots.forEach(hot=>{
  2040. hot.info.texSrc = video.src //视频不能共用一个,否则会一起播放暂停
  2041. hot.info.fileName = video.name
  2042. hot.videoWidth = video.videoWidth //记录。因为新new的话要等一会儿才不为0
  2043. hot.videoHeight = video.videoHeight
  2044. hot.changeTexType("video" )
  2045. })
  2046. /* if(editItemInfo.$li.hasClass('selected')){//是当前spot的
  2047. this.videoList.options.selectFun({dontApplyToHot:true})//更新选中状态
  2048. } */
  2049. this.videoList.addNew()
  2050. this.videoList.selectFromOutSide(editItemInfo.$li.index())
  2051. }
  2052. }, "video", e);
  2053. })
  2054. uploadInputModel.on("change", (e)=>{
  2055. inputMedia({
  2056. enableTypes: ["model"],
  2057. modelDone: (file,object)=>{
  2058. editItemInfo.$li.find(".upload").addClass("uploaded")
  2059. editItemInfo.$li.find(".upload>div").text(file.name)
  2060. editItemInfo.$li.attr("title", file.name)
  2061. object.file = file
  2062. object.name = file.name
  2063. object.src = object.uuid;//作为标识而已
  2064. object.needSave = true
  2065. {//adjustModelAuto
  2066. let bound = new THREE.Box3
  2067. object.traverse( function ( child ) {
  2068. if(child.geometry){
  2069. child.geometry.computeBoundingBox();
  2070. bound.union(child.geometry.boundingBox)
  2071. }
  2072. });
  2073. let standard = 1;
  2074. let size = bound.max.distanceTo(bound.min);
  2075. let s = standard / size
  2076. object.scale.set(s,s,s)
  2077. let center = bound.center()
  2078. object.position.copy(center).negate().multiplyScalar(s)//保证模型的中心点和hot中心点重合
  2079. object.modelBound = {
  2080. bound,
  2081. scaleRatio : s,
  2082. position: object.position.toArray()
  2083. }
  2084. }
  2085. editItemInfo.$li[0].objObject = object
  2086. editItemInfo.$li[0].sameContentSpots.forEach(hot=>{
  2087. //hot.addModel(object)
  2088. this.switchModel({add:object, spot:hot})
  2089. })
  2090. this.modelList.selectFromOutSide(editItemInfo.$li.index())
  2091. /* if(editItemInfo.$li.hasClass('selected')){//是当前spot的
  2092. this.modelList.options.selectFun({dontApplyToHot:true})//更新选中状态
  2093. } */
  2094. this.modelList.addNew()
  2095. }
  2096. }, "model", e);
  2097. })
  2098. this.texLists = {shine: this.styleList, photo:this.photoList, video: this.videoList}
  2099. this.texTypeMenuOptions = new MenuOptions({
  2100. dom: this.hotpointDetail.find(" li[name=style] .MenuOptions"),
  2101. uiCallBack : (o)=>{
  2102. var name = o.name == void 0 ? o.$li.attr('index') : o.name
  2103. for(let i in this.texLists){ this.texLists[i].listDom.parent().addClass("hide")}
  2104. this.texLists[name].listDom.parent().removeClass("hide")
  2105. if(name == 'photo'){
  2106. $('#gifEdit').removeClass('hide')
  2107. }else{
  2108. $('#gifEdit').addClass('hide')
  2109. this.updateGifPanel({on:false})
  2110. }
  2111. },
  2112. callbackWhenChose:(o)=>{
  2113. this.changeType( o.$li.attr('index'))
  2114. }
  2115. })
  2116. //编辑开放
  2117. this.hotpointDetail.find(" li[name=style]").removeClass('unable');
  2118. this.hotpointDetail.find(" li[name=model]").removeClass('unable');
  2119. this.hotpointDetail.find(" li[name=style] .itemTitle").attr('data-size','')
  2120. if(this.editSpot){//已经在编辑了,初始化下
  2121. this.updateListSelect(this.editSpot)
  2122. this.getTempInfos()
  2123. }
  2124. this.hotpointDetail.find(" li[name=setPos] button[name=setSpace] ").on('click',(e)=>{
  2125. var space = transformControls.space == 'world'?'local':'world'
  2126. transformControls.setSpace(space)
  2127. e.target.innerText = space == 'world'?'切换为世界坐标方向':'切换为本地坐标方向'
  2128. })
  2129. this.hotpointDetail.find(" li[name=setPos] button[name=useSuitableRatio] ").on('click',()=>{
  2130. this.useSuitableRatio()
  2131. })
  2132. this.hotpointDetail.find(" li[name=setPos] button[name=resetRot] ").on('click',()=>{
  2133. this.editSpot.rotation.x = 0
  2134. this.editSpot.rotation.z = 0
  2135. })
  2136. }
  2137. Hotpoint.prototype.switchModel = function(o={}){
  2138. if(o.add){
  2139. var model = o.add.clone();
  2140. o.spot.info.objSrc = o.add.src
  2141. o.spot.info.objName = o.add.name
  2142. o.spot.info.modelBound = o.add.modelBound;
  2143. o.spot.addModel(model)
  2144. var s = 1;//暂时
  2145. o.spot.scale.set(s,s,s)//恢复成等大比例,方便用户看清原始比例
  2146. o.spot.info.scale.set(s,s,s)
  2147. //this.updateTransform('scale')
  2148. if(o.spot == this.editSpot){
  2149. transformControls.enableScaleZ()
  2150. }
  2151. }else if(o.remove){
  2152. //如果没有出现plane,很可能是因为背面朝向镜头了!
  2153. o.spot.addPlane()
  2154. if(o.spot == this.editSpot) transformControls.unableScaleZ()
  2155. }
  2156. }
  2157. Hotpoint.prototype.changeType = function(type){
  2158. var hot = this.editSpot
  2159. var list
  2160. this._scale[hot.texType] = hot.scale.clone()
  2161. if(type == 'shine'){
  2162. hot.changeTexType(type, 'clear')
  2163. if(hot.styleImg){
  2164. hot.changeTexType(type, hot.styleImg )
  2165. }
  2166. list = this.styleList
  2167. list.selectFromOutSide(list.chosenIndex || 1)//触发选择函数
  2168. }else{
  2169. hot.changeTexType(type,'clear')
  2170. if(type == 'photo'){
  2171. list = this.photoList
  2172. }else{
  2173. list = this.videoList
  2174. }
  2175. list.selectFromOutSide(list.chosenIndex)
  2176. }
  2177. this.useSuitableRatio({setScaleAuto:true})
  2178. hot.info.actionType = CloneObject(settings.hotClickEvent[type]);//给一个默认 图和视频不打开热点
  2179. /* if(type == 'video'){
  2180. hot.info.actionType.playAndPause = true;
  2181. }else{
  2182. delete hot.info.actionType.playAndPause
  2183. } */
  2184. if(type != 'video'){
  2185. delete hot.info.fileName
  2186. }
  2187. this.updateClickEventUI();//根据actionType更新ui
  2188. }
  2189. Hotpoint.prototype.updateGifPanel = function(o={}){
  2190. var hot = this.editSpot
  2191. if(!hot.material_.map)return;
  2192. let a = o.animateInfo || hot.info.animateInfo
  2193. //换图时根据图片的animation更改开关,如果有的话还要更改面板,如果图没有animation用自己的
  2194. if(o.animateInfo){//更换animateInfo
  2195. hot.info.animateInfo = CloneObject(o.animateInfo);
  2196. }
  2197. if("animateInfo" in o ){
  2198. o.on = !!o.animateInfo
  2199. }
  2200. if(!a){
  2201. o.on = false
  2202. }
  2203. if(o.on != void 0){
  2204. this.gifCheckBox.updateChoseAtUI(o.on)
  2205. GifTexDeal.remove(hot.animation)
  2206. if(o.on){
  2207. hot.animation = GifTexDeal.addAnimation(hot.material_.map, hot, hot.info.animateInfo, hot.sid)
  2208. GifTexDeal.start(hot.animation)
  2209. }else{
  2210. hot.animation = null
  2211. hot.info.animateInfo = null
  2212. }
  2213. }
  2214. let w = hot.material_.map.image.width
  2215. let h = hot.material_.map.image.height
  2216. if(a){
  2217. $("#gifXCount").val(a.cellXcount);
  2218. $("#gifYCount").val(a.cellYcount);
  2219. $("#gifImgWidth").text(w)
  2220. $("#gifImgHeight").text(h)
  2221. $("#gifCellWidth").text(toPrecision(w / a.cellXcount, 2));
  2222. $("#gifCellHeight").text(toPrecision(h / a.cellYcount, 2));
  2223. $("#voidCount").val(a.voidCount || 0);
  2224. let frameCount = a.cellXcount * a.cellYcount - (a.voidCount || 0)
  2225. $("#gifFrameCount").text(frameCount)
  2226. $("#gifDuration").val(toPrecision(a.duration / 1000, 2));
  2227. $("#gifFps").val(toPrecision(frameCount / a.duration * 1000, 1) );
  2228. }else{
  2229. $("#gifXCount").val(1);
  2230. $("#gifYCount").val(1);
  2231. $("#gifImgWidth").text(w)
  2232. $("#gifImgHeight").text(h)
  2233. $("#gifCellWidth").text(w);
  2234. $("#gifCellHeight").text(h)
  2235. $("#voidCount").val(0);
  2236. $("#gifFrameCount").text(1)
  2237. $("#gifDuration").val(1);
  2238. $("#gifFps").val(1);
  2239. }
  2240. }
  2241. Hotpoint.prototype.updateListSelect = function(hot) { //每次开始编辑热点时更新样式
  2242. if(!Hot.allPhotoLoaded || !Hot.allModelLoaded)return
  2243. var list = this.texLists[hot.texType];
  2244. var chosenIndex = null;
  2245. this.texTypeMenuOptions.updateChoseAtUI({name:hot.texType})
  2246. for(let i in this.texLists){
  2247. //this.texLists[i].clearVoid(this.texLists[i]);
  2248. this.texLists[i].saveTemp(this.texLists[i])
  2249. }
  2250. this.modelList.saveTemp()
  2251. if(hot.texType == 'shine'){
  2252. if (!hot.styleImg) hot.styleImg = [];
  2253. if(hot.styleImg.length){
  2254. var info = this.styleList.findChosenByContent(hot.styleImg)
  2255. chosenIndex = info.index
  2256. }
  2257. }else{
  2258. var info = list.findChosenByContent(list, hot.texMedia)
  2259. chosenIndex = info.index
  2260. }
  2261. list.selectFromOutSide(chosenIndex, {dontApplyToHot:true})
  2262. this.photoList.updateDelBtns(this.photoList)
  2263. this.videoList.updateDelBtns(this.videoList)
  2264. {//model
  2265. let hasModel = !!hot.objObject
  2266. this.modelMenuOptions.updateChoseAtUI({name: hasModel ? 'user' : 'default'})
  2267. if(hasModel){
  2268. var info = this.modelList.findChosenByContent(hot.objObject)
  2269. this.modelList.selectFromOutSide(info.index, {dontApplyToHot:true})
  2270. transformControls.enableScaleZ()
  2271. }
  2272. }
  2273. }
  2274. Hotpoint.prototype.useSuitableRatio = function(o={}) {//自适应素材比例
  2275. var hot = this.editSpot
  2276. var plane = this.editSpot.plane;
  2277. var w, h, defaultS = 1, s, mediaW, mediaH
  2278. if(this._scale[hot.texType] && o.setScaleAuto){
  2279. w = this._scale[hot.texType].x; h = this._scale[hot.texType].y;
  2280. }else{
  2281. if(hot.texType == 'shine'){//默认使用热点大小,正方形
  2282. if(o.setScaleAuto){
  2283. w = h = 1 //DATA.hotIconScale * g_HotMeshSize.g_HotMeshWidth
  2284. }else{
  2285. s = hot.scale.x * hot.scale.y
  2286. w = h = Math.sqrt(Math.abs(s))
  2287. }
  2288. }else{
  2289. if(!hot.texMedia)return
  2290. //假设不变总面积
  2291. if(o.setScaleAuto){
  2292. s = defaultS
  2293. }else{
  2294. s = hot.scale.x * hot.scale.y
  2295. }
  2296. /* if(hot.texType == 'photo'){
  2297. mediaW = hot.texMedia.width;
  2298. mediaH = hot.texMedia.height;
  2299. //动画的话再变
  2300. if(hot.info.animateInfo){
  2301. mediaW /= hot.info.animateInfo.cellXcount
  2302. mediaH /= hot.info.animateInfo.cellYcount
  2303. }
  2304. }else{
  2305. mediaW = hot.texMedia.videoWidth || hot.videoWidth || 1;
  2306. mediaH = hot.texMedia.videoHeight || hot.videoHeight || 1;
  2307. } */
  2308. let size = hot.getMediaSize()
  2309. if(size.x == 0){
  2310. mediaW = mediaH = 1
  2311. }else{
  2312. mediaW = size.x; mediaH = size.y;
  2313. }
  2314. var k = Math.sqrt(Math.abs(s) / (mediaW * mediaH))
  2315. w = k * mediaW * (hot.scale.x < 0 ? -1 : 1);
  2316. h = k * mediaH * (hot.scale.y < 0 ? -1 : 1);
  2317. }
  2318. }
  2319. hot.scale.setX(w)
  2320. hot.scale.setY(h)
  2321. if(hot.isUserModel){
  2322. hot.scale.setZ(z)
  2323. }
  2324. this.updateTransform('scale')
  2325. },
  2326. Hotpoint.prototype.updateClickEventUI = function() {//根据actionType更新ui
  2327. var hot = this.editSpot;
  2328. /* var checkboxs = this.hotpointDetail.find("li[name='clickEvent'] li.editCheckbox");
  2329. checkboxs.addClass('hide');
  2330. for(let i in hot.info.actionType){
  2331. var checkbox = checkboxs.find('[name='+ i +']')
  2332. checkbox.parent().removeClass('hide');
  2333. checkbox[0].checked = !!hot.info.actionType[i]
  2334. }
  2335. var content = this.hotpointDetail.find("li[name='content']")
  2336. hot.info.actionType.openHot ? content.removeClass('hide') : content.addClass('hide') */
  2337. /* for(let i in hot.info.actionType){
  2338. this.actionCheckBox.updateChoseAtUI(hot.info.actionType[i], i)
  2339. } */
  2340. settings.hotClickActions.forEach(e=>{
  2341. this.actionCheckBox.updateChoseAtUI(hot.info.actionType[e], e)
  2342. })
  2343. }
  2344. //添加图片和视频
  2345. Hotpoint.prototype.addmediaInit = function() {
  2346. // 视频预览控制
  2347. var $videoLayout = $('.fun-view-video')
  2348. var that = this
  2349. $videoLayout.find('span').on('click', function() {
  2350. $videoLayout.hide();
  2351. $videoLayout.find('video').attr('src', '')[0].pause()
  2352. });
  2353. // 图片加载回调
  2354. function imageSuccess(file) {
  2355. if (!/image\/\w+/.test(file.type)) {
  2356. alert("文件必须为图片!");
  2357. return false;
  2358. }
  2359. if (!restrictedSize(file, 9)) {
  2360. return false;
  2361. }
  2362. var img = new Image()
  2363. img.src = URL.createObjectURL(file);
  2364. img.className = 'bg'
  2365. return img
  2366. }
  2367. // 视频加载回调
  2368. function videoSuccess(file, $elayout) {
  2369. if (!/video\/\w+/.test(file.type)) {
  2370. alert("视频必须为map4格式!");
  2371. return false;
  2372. }
  2373. $elayout.append('<span class="upload-thum">上传封面<i><input type="file" accept="image/*"></i></span>')
  2374. return '<img src="./images/play.png" class="play-video" videoURL="' + URL.createObjectURL(file) + '">'
  2375. }
  2376. // 视频封面回调
  2377. function thumbSuccess(file, $elayout, $seft) {
  2378. if (!/image\/\w+/.test(file.type)) {
  2379. alert("文件必须为图片!");
  2380. return false;
  2381. }
  2382. if (!restrictedSize(file, 2)) {
  2383. return false;
  2384. }
  2385. var img = $seft.closest('div').find('img.bg');
  2386. if(!img[0]){
  2387. img = $("<img class='bg'></img>");
  2388. $seft.closest('div').find('a').append(img)
  2389. }
  2390. img.attr('src', URL.createObjectURL(file));
  2391. $seft.closest('span').removeClass("success")
  2392. }
  2393. // 图片与视频加载
  2394. function fileHandle(that) {
  2395. var $seft = $(this) //input
  2396. var file = this.files[0];
  2397. var type = this.activeElem ? this.activeElem.attr('data-type') : $seft.parent().attr('data-type');
  2398. var $din = $('<div class="mediaItem" draggable="true"></div>')
  2399. var fnc = type === 'photo' ? imageSuccess : type === 'video' ? videoSuccess : thumbSuccess //再次传都会是thumSuccess
  2400. var $dom = fnc(file, $din, $seft)
  2401. if (type === 'photo' || type === 'video') {
  2402. if (!$dom)
  2403. return $seft.val('');
  2404. if(!this.activeElem){//创建新的item
  2405. var $layout = $seft.closest("li");
  2406. var $addLayout = $(document.createElement('a'));
  2407. $addLayout.attr("data-type", type)
  2408. var $close = $(document.createElement('span'));
  2409. $addLayout[0].file = file;
  2410. $addLayout.append($close);
  2411. $addLayout.append($dom);
  2412. $addLayout.addClass("result");
  2413. $din.prepend($addLayout);
  2414. $layout.find('.edit-fun-images').append($din);
  2415. var $btn = $('<div class="descBtn">添加描述</div>')
  2416. $addLayout.append($btn)
  2417. that.descBtnBind($btn[0], type)
  2418. }else{//重传
  2419. if (type === 'photo'){
  2420. this.activeElem.find("img.bg").remove();
  2421. }else{
  2422. this.activeElem.find(".play-video").remove();
  2423. }
  2424. this.activeElem.removeClass("success")
  2425. this.activeElem.append($dom)
  2426. this.activeElem[0].file = file;
  2427. this.value = ''
  2428. }
  2429. }
  2430. if (searchParent($seft[0], {
  2431. id: 'shareImgUpload'
  2432. })) {
  2433. //信息页面的分享图片
  2434. $("#shareImgUpload").addClass("hide")
  2435. }else if(searchParent($seft[0], {
  2436. id: 'SpotStyle'
  2437. })){
  2438. $("#SpotStyle").addClass("hide")
  2439. }
  2440. }
  2441. //用于重传的input
  2442. var imgInput = $("<input accept='image/*' type='file'></input>")
  2443. var videoInput = $("<input accept='video/*' type='file'></input>")
  2444. // 图片与视频加载
  2445. $('.upload, .edit-fun-images').on('change', function(ev) {
  2446. if (ev.target.tagName.toUpperCase() === 'INPUT') {
  2447. ev.target.files.length && fileHandle.call(ev.target, that)
  2448. }
  2449. })
  2450. imgInput.on('change', (ev)=>{fileHandle.call(ev.target, that)})
  2451. videoInput.on('change', (ev)=>{fileHandle.call(ev.target, that)})
  2452. $('.edit-fun-images').on('click', function(ev) {//点击item时
  2453. var $tag = $(ev.target)
  2454. var tagName = ev.target.tagName.toUpperCase()
  2455. if (tagName === 'SPAN') {
  2456. if (searchParent($tag[0], {
  2457. className: 'forShareImg'
  2458. })) {
  2459. //信息页面的分享图片
  2460. $("#shareImgUpload").removeClass('hide')
  2461. }else if(searchParent($tag[0], {
  2462. className: 'SpotStyle'
  2463. })){
  2464. $("#SpotStyle").removeClass('hide')
  2465. }
  2466. $tag.parent().parent().remove()
  2467. }else if (tagName === 'IMG' && $tag.hasClass('play-video')) {
  2468. $videoLayout.css('display', 'flex').find('video').attr('src', $tag.attr('videoURL'))[0].play()
  2469. }else{// 替换
  2470. if($tag.hasClass('descBtn'))return
  2471. var a = searchParent($tag[0], {
  2472. tagName: 'a'
  2473. })
  2474. if(a) {
  2475. var input
  2476. if(searchParent($tag[0], {
  2477. className: 'video'
  2478. })){
  2479. input = videoInput
  2480. }else{
  2481. input = imgInput
  2482. }
  2483. input[0].activeElem = $(a)
  2484. input.click()
  2485. }
  2486. }
  2487. })
  2488. }
  2489. Hotpoint.prototype.descBtnUpdate = function(btn){//图片描述按钮状态更新
  2490. var $btn = $(btn)
  2491. /* if(index == void 0){
  2492. var btns = Array.from(this.hotpointDetail.find("[name=photo] .list .descBtn"))
  2493. index = btns.indexOf(btn)
  2494. } */
  2495. var desc = btn.desc
  2496. if(desc == void 0 || desc === ''){
  2497. $btn.removeClass('hasDesc')
  2498. $btn.text('添加描述')
  2499. }else{
  2500. $btn.addClass('hasDesc')
  2501. $btn.text('查看描述')
  2502. }
  2503. }
  2504. Hotpoint.prototype.descBtnBind = function(btn, type, desc ){//单个图片or视频描述按钮事件
  2505. //console.log('descBtnBind',btn)
  2506. var textarea = this.hotpointDetail.find(`li[name="${type}"] textarea`);
  2507. var title = this.hotpointDetail.find(`li[name="${type}"] [name="descTitle"]`)
  2508. btn.addEventListener('click',(e)=>{
  2509. this.hotpointDetail.find(`[name=${type}] .list .descBtn`).removeClass('chosen')
  2510. $(btn).addClass('chosen');
  2511. textarea.removeClass('hide')
  2512. title.removeClass('hide')
  2513. /* textarea.val(btn.desc)
  2514. textarea[0].currentBtn = btn */
  2515. this.descBtnChose(btn, type)
  2516. e.preventDefault()
  2517. e.stopPropagation()
  2518. })
  2519. btn.desc = desc || ''
  2520. }
  2521. Hotpoint.prototype.descBtnChose = function(btn, type){
  2522. var textarea = this.hotpointDetail.find(`li[name="${type}"] textarea`);
  2523. textarea[0].currentBtn = btn
  2524. textarea.val(btn ? btn.desc : '');
  2525. }
  2526. //当前处于的状态,比如是否是添加热点的状态
  2527. /* Hotpoint.prototype.state = function(that, Hot) {
  2528. if (g_HotStatus === "add") {
  2529. //console.log(Hot)
  2530. this.addHot(that, Hot, (hot)=>{
  2531. this.addHotList(hot);
  2532. } );
  2533. }
  2534. } */
  2535. Hotpoint.prototype.updateNumDisplay = function() {
  2536. this.spotList.find("i").text(this.spotList.find("ul li").length);
  2537. }
  2538. //删除热点
  2539. Hotpoint.prototype.removeHot = function(hot ) {
  2540. //hot.dispose();
  2541. hot.dispose()
  2542. hot.$li.remove();
  2543. this.updateNumDisplay()
  2544. }
  2545. //添加热点模型
  2546. Hotpoint.prototype.addHot = function(that) {
  2547. if (!player.intersect || !g_HotStatus) return;// 没有正确的热点位置, return
  2548. var sid = getRandomSid()
  2549. var s = g_HotStatus == 'shine' ? Hot.getDefaulScale() : 1
  2550. var hot = new Hot({
  2551. sid,
  2552. texType : g_HotStatus,
  2553. position : player.intersect.point.clone() ,
  2554. rotation : [0,0,0],
  2555. scale: new THREE.Vector3(s,s,0.02),
  2556. actionType : CloneObject(settings.hotClickEvent[g_HotStatus]),
  2557. titlePos: this.latestTitlePos,
  2558. titleShowType: this.latestTitleShowType,
  2559. });
  2560. hot.photoHasRequestLoad = hot.modelHasRequestLoad = true;//防止requestDownload
  2561. player.model.hots[sid] = hot;
  2562. hot.hasRequestLoad = true
  2563. hot.isNew = true
  2564. if (player.getMouseDirection().angleTo(player.intersect.face.normal) < Math.PI / 2) {
  2565. hot.lookAt(player.intersect.face.normal.clone().negate().add(player.intersect.point));
  2566. hot.position.add(player.intersect.face.normal.clone().negate().multiplyScalar(0.01)) //avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
  2567. } else {
  2568. hot.lookAt(player.intersect.face.normal.clone().add(player.intersect.point));
  2569. hot.position.add(player.intersect.face.normal.clone().multiplyScalar(0.01))
  2570. }
  2571. g_HotStatus = false;
  2572. player.mouseCouldBeClickToMove = false;
  2573. //$("#player").css("cursor", "");
  2574. CursorDeal.remove('addHot' )
  2575. CursorDeal.remove('noIntersect' )
  2576. this.addHotList(hot)
  2577. this.editHot(hot)
  2578. this.updateTransform('position');
  2579. this.updateTransform('quaternion');
  2580. }
  2581. //添加热点列表
  2582. Hotpoint.prototype.addHotList = function(hot) {
  2583. 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>");
  2584. li.hot = hot
  2585. hot.$li = li
  2586. this.setListLi(hot)
  2587. $(".spotList ul").append(li);
  2588. li.on("mouseover",()=>{
  2589. hot.changeBoxHelperDisplay(true)
  2590. })
  2591. li.on("mouseout",()=>{
  2592. hot.changeBoxHelperDisplay(false)
  2593. })
  2594. this.updateNumDisplay()
  2595. }
  2596. Hotpoint.prototype.setListLi = function(hot){ //暂时用文字展示,最好有图标来表示包含gif和模型
  2597. var name = '';
  2598. if(hot.info.title) name = hot.info.title
  2599. else{
  2600. if(hot.info.objSrc)name = '包含模型的'
  2601. if(hot.texType == 'photo' && hot.info.animateInfo)name+= 'gif'
  2602. else name += (hot.texType == 'shine' ? '热点' : hot.texType == 'photo' ? '图片' : '视频' )
  2603. }
  2604. hot.$li.find(".title").html(name);
  2605. hot.$li.find('.icon').attr("type",hot.texType)
  2606. hot.$li.attr("title", hot.info.title) //显示没显示完的标题
  2607. }
  2608. //添加热点模型列表dom
  2609. Hotpoint.prototype.inputList = function(text, val) {
  2610. var _val = '';
  2611. if (arguments[1]) {
  2612. _val = 'value=' + val;
  2613. }
  2614. return '<div class="link"> <input class="text" type="text" placeholder=' + text + ' spellcheck="false" ' + _val + ' > </div>'
  2615. }
  2616. //添加热点模型
  2617. Hotpoint.prototype.addModel = function() {
  2618. var text = this.inputList("请填写模型链接(https开头)");
  2619. this.hotpointDetail.find("[name=modelSrc] .add").on('click', function() {
  2620. $(this).closest("[name=modelSrc] ").find(".list").append(text)
  2621. });
  2622. this.hotpointDetail.find("[name=modelSrc] .delete").on('click', function() {
  2623. $(this).closest("[name=modelSrc] ").find(".list > div:last").remove();
  2624. });
  2625. }
  2626. //添加网页链接
  2627. Hotpoint.prototype.addwebPack = function() {
  2628. var text = this.inputList("请填写网页链接", "");
  2629. this.hotpointDetail.find("[name=webPage] .add").on('click', function() {
  2630. $(this).closest("[name=webPage]").find(".list").append(text)
  2631. });
  2632. this.hotpointDetail.find("[name=webPage] .delete").on('click', function() {
  2633. $(this).closest("[name=webPage]").find(".list > div:last").remove();
  2634. });
  2635. }
  2636. Hotpoint.prototype.editDone = function(){
  2637. var hot = this.editSpot
  2638. this.editSpot = null;
  2639. hot.isNew = false;
  2640. transformControls.detach()
  2641. this.hotpointDetail.addClass("atRight");
  2642. $('#hotpointDetail .shotImg.innerBtn')[0].cameraData = null
  2643. this.setCameraBtn(false)
  2644. this.imgDescCheckBox.updateChoseAtUI(false)
  2645. this.videoDescCheckBox.updateChoseAtUI(false)
  2646. $('#setPosForPano [name="dis"]').addClass('hide');
  2647. }
  2648. // 保存热点信息
  2649. Hotpoint.prototype.saveHot = function() {
  2650. var $layout = $(".edit-loading");
  2651. var hotpointDetail = this.hotpointDetail;
  2652. var that = this
  2653. var hot = this.editSpot
  2654. if (hot.texType == "video" && !hot.texMedia ) {
  2655. alert("请添加视频")
  2656. return;
  2657. }else if(hot.texType == 'photo' && !hot.texMedia){
  2658. alert("请添加图片")
  2659. return;
  2660. }
  2661. //显示loading
  2662. $layout.removeClass('hide');
  2663. var args = hot.info//{};
  2664. //热点标题
  2665. var $title = hotpointDetail.find("[name=info] input");
  2666. //热点内容
  2667. var $content = hotpointDetail.find("[name=intro] textarea");
  2668. //热点图片
  2669. var $images = hotpointDetail.find("[name=content] [name=photo] .edit-fun-images a.result");
  2670. //热点视频
  2671. var $videos = hotpointDetail.find("[name=content] [name=video] .edit-fun-images a.result");
  2672. //热点视频的图片
  2673. var $thums = hotpointDetail.find("[name=content] [name=video] .edit-fun-images .upload-thum");
  2674. //热点模型
  2675. var $modules = hotpointDetail.find("[name=content] [name=modelSrc] input");
  2676. //热点内嵌网页
  2677. var $iframes = hotpointDetail.find("[name=content] [name=webPage] input.text");
  2678. //热点音乐
  2679. var $miusc = hotpointDetail.find("[name=content] #upload-hotBgm");
  2680. var promise = new Promise(function(resolve, reject) {
  2681. //获取图片路径
  2682. upload($images, 'images', resolve)
  2683. }).then(function(imgUrls) {
  2684. $layout.removeClass('hide');
  2685. args.images = imgUrls
  2686. //获取视频路径
  2687. return new Promise(function(resolve, reject) {
  2688. upload($videos, 'videos', resolve)
  2689. }
  2690. )
  2691. }).then(function(videoUrls) {
  2692. $layout.removeClass('hide');
  2693. args.video = videoUrls
  2694. //获取视频封面路径
  2695. return new Promise(function(resolve, reject) {
  2696. upload($thums, 'images', resolve)
  2697. }
  2698. )
  2699. }).then(function(thums) {
  2700. $layout.removeClass('hide');
  2701. args.video = args.video.map(function(video, index) {//整合视频+封面
  2702. return {
  2703. url: video,
  2704. img: thums[index]
  2705. }
  2706. })
  2707. }).then(function() {
  2708. //获取热点音乐所有的路径
  2709. //console.log($miusc)
  2710. $layout.removeClass('hide');
  2711. if ($miusc[0].files.length > 0) {
  2712. return new Promise(function(resolve) {
  2713. upload($miusc, 'miusc', function(res) {
  2714. resolve(res[0])
  2715. })
  2716. })
  2717. } else {
  2718. return $miusc.attr('data-hotBgm')
  2719. }
  2720. }).then(function(src) {
  2721. if(that.musicBox.hasMusic && !src){
  2722. args.backgroundMusic = hot.info.backgroundMusic
  2723. args.bgName = hot.info.bgName
  2724. }else{
  2725. args.backgroundMusic = src
  2726. args.bgName = that.musicBox.getName()
  2727. }
  2728. }).then(function() { //上传所有热点的tex file
  2729. var a = $.Deferred();
  2730. var doneNum = 0;
  2731. var filesNeedSave = [];
  2732. var liNeedSave = [], liNeedSave2 = []
  2733. $layout.removeClass('hide');
  2734. Array.from(that.styleList.listDom.children()).forEach(li=>{
  2735. if(li.sameContentSpots.length == 0)return;//没被热点用到就不保存
  2736. //li.sameContentSpots.forEach(spot=>spot.styleImg = li._styleImg)//提前同步下 等下就都是线上链接了
  2737. li._styleImg.forEach(img=>{
  2738. if(img.needSave && !filesNeedSave.includes(img)){
  2739. filesNeedSave.push(img)
  2740. liNeedSave.includes(li) || liNeedSave.push(li)
  2741. }
  2742. })
  2743. });
  2744. [that.photoList, that.videoList].forEach(list=>{
  2745. Array.from(list.listDom.children()).forEach(li=>{
  2746. if(li.sameContentSpots.length == 0)return;//没被热点用到就不保存
  2747. //li.sameContentSpots.forEach(spot=>spot.texMedia.src = li._media.src)//同步下 video不能同步,只能同步src
  2748. li._media.needSave && (filesNeedSave.push(li._media), liNeedSave.push(li))
  2749. })
  2750. })
  2751. Array.from(that.modelList.listDom.children()).forEach(li=>{
  2752. if(li.sameContentSpots.length == 0)return;//没被热点用到就不保存
  2753. li.objObject.needSave && (filesNeedSave.push(li.objObject), liNeedSave2.push(li))
  2754. })
  2755. if(filesNeedSave.length){
  2756. filesNeedSave.forEach(o=>{
  2757. uploadFile(o.file, 'hot', function(rs) {
  2758. if (rs.code === 0) {
  2759. o.needSave = false;
  2760. //o.saveURL = rs.data;
  2761. o.src = rs.data;
  2762. if (++doneNum >= filesNeedSave.length) {
  2763. a.resolve();
  2764. liNeedSave.forEach(li=>{//将blob更换成线上链接
  2765. li.sameContentSpots.forEach((spot)=>{
  2766. if(spot.texType == 'shine'){
  2767. spot.info.styleImg = li._styleImg.map(img=>img.src)
  2768. }else{
  2769. spot.info.texSrc = li._media.src
  2770. spot.texMedia.src = li._media.src
  2771. }
  2772. })
  2773. })
  2774. liNeedSave2.forEach(li=>{//将blob更换成线上链接
  2775. li.sameContentSpots.forEach((spot)=>{
  2776. spot.info.objSrc = spot.objObject.src = li.objObject.src
  2777. })
  2778. })
  2779. }
  2780. } else {
  2781. alert("文件上传失败");
  2782. a.reject();
  2783. }
  2784. })
  2785. })
  2786. return a.promise()
  2787. }else{
  2788. return a.resolve()
  2789. }
  2790. }).then(function() {
  2791. $layout.removeClass('hide');
  2792. //获取热点标题、内容、内嵌网页、模型网页。
  2793. args.title = $title.val()
  2794. args.content = $content.val()
  2795. var iframes = []
  2796. for (var i = 0; i < $iframes.length; i++) {
  2797. var iframe = $iframes.eq(i).val()
  2798. iframe && iframes.push(iframe)
  2799. }
  2800. args.iframe = iframes
  2801. var modules = []
  2802. for (var i = 0; i < $modules.length; i++) {
  2803. var module = $modules.eq(i).val()
  2804. module && modules.push(module)
  2805. }
  2806. args.model = modules
  2807. /* if(!hot.isSprite){
  2808. args.quaternion = hot.quaternion.clone()
  2809. //hot.quaternion.copy(hot.mesh.quaternion)
  2810. }
  2811. args.position = hot.position.clone()
  2812. //hot.position.copy(hot.mesh.position) */
  2813. return args
  2814. }).then(function(args) {
  2815. hot.info.texType = hot.texType
  2816. if(that.ifNeedResetVisi(hot)){
  2817. hot.getVisiblePanos();
  2818. }
  2819. if(hot.texType == 'photo'){//保存时绑定animateInfo到li
  2820. let info = that.photoList.findChosenByContent(that.photoList, hot.texMedia);
  2821. info.item.animateInfo = CloneObject(hot.info.animateInfo)
  2822. }
  2823. if(that.actionCheckBox.checked('fastTran')){
  2824. hot.info.cameraData = $('#hotpointDetail .shotImg.innerBtn')[0].cameraData //快速跳转方位
  2825. }else{
  2826. delete hot.info.cameraData
  2827. }
  2828. hot.info.imagesDesc = Array.from(that.hotpointDetail.find("[name=photo] .list .descBtn")).map(btn=>btn.desc)
  2829. hot.info.videosDesc = Array.from(that.hotpointDetail.find("[name=video] .list .descBtn")).map(btn=>btn.desc)
  2830. //hot.setTitleElem()//更新名称
  2831. that.setListLi(hot);
  2832. $layout.addClass('hide');
  2833. console.log(args);
  2834. that.editDone()
  2835. that._scale[hot.texType] = hot.scale.clone()
  2836. })
  2837. return promise
  2838. }
  2839. Hotpoint.prototype.ifNeedResetVisi = function(hot){//修改过贴图或位置或模型,导致这几个数值改变,就要重新计算可见性(会覆盖用户设置)
  2840. var need = !ifSame({
  2841. hasBox: hot.tempInfo.hasBox,
  2842. position: hot.tempInfo.position,
  2843. rotation: hot.tempInfo.rotation,
  2844. scale: hot.tempInfo.scale,
  2845. transformAtPanos: hot.tempInfo.transformAtPanos,
  2846. modelBound:hot.tempInfo.modelBound
  2847. }, {
  2848. hasBox: hot.info.hasBox,
  2849. position: hot.info.position,
  2850. rotation: hot.info.rotation,
  2851. scale: hot.info.scale,
  2852. transformAtPanos: hot.info.transformAtPanos,
  2853. modelBound:hot.info.modelBound
  2854. })
  2855. return need
  2856. }
  2857. Hotpoint.prototype.getSavingInfo = function(){//保存全部
  2858. var hots = {} // 热点数据
  2859. /* var shineHots = player.model.hotGroup.children.filter(e=>e.texType == 'shine')
  2860. var photoHots = player.model.hotGroup.children.filter(e=>e.texType == 'photo')
  2861. var videoHots = player.model.hotGroup.children.filter(e=>e.texType == 'video')
  2862. shineHots.concat(photoHots).concat(videoHots).forEach((hot,index)=>{ */
  2863. //按列表顺序存储
  2864. Array.from(this.spotList.find('li.listItem')).forEach((li,index)=>{
  2865. var sid = $(li).attr("data-spid");
  2866. var hot = player.model.hots[sid]
  2867. var hotData = CloneObject(hot.info)
  2868. if(hotData.texSrc){
  2869. hotData.texSrc = manage.removeSrcPostMark(hotData.texSrc)
  2870. }
  2871. hotData.position = toPrecision(hot.info.position.toArray(), 3)
  2872. hotData.scale = toPrecision(hot.info.scale.toArray(), 3)
  2873. hotData.rotation = toPrecision(hot.info.rotation.toArray().slice(0,3), 4)
  2874. hotData.order = index
  2875. hotData.transformAtPanos = {}
  2876. for(let i in hot.info.transformAtPanos){
  2877. hotData.transformAtPanos[i] = {
  2878. pos : toPrecision(hot.info.transformAtPanos[i].pos.toArray(), 3),
  2879. }
  2880. /* if(hot.transformAtPanos[i].qua){
  2881. hotData.transformAtPanos[i].qua = toPrecision(hot.transformAtPanos[i].qua.toArray(), 5)
  2882. } */
  2883. }
  2884. hotData.version = 'multi'
  2885. if(hotData.animateInfo && hotData.animateInfo.cellXcount * hotData.animateInfo.cellYcount - (hotData.animateInfo.voidCount || 0)<=1){
  2886. delete hotData.animateInfo
  2887. }
  2888. hotData.model = hotData.model.length ? hotData.model : ''
  2889. hotData.images = hotData.images.length ? hotData.images : ''
  2890. hotData.video = hotData.video.length ? hotData.video : ''
  2891. hotData.iframe = hotData.iframe.length ? hotData.iframe : ''
  2892. hots[hot.sid] = hotData
  2893. })
  2894. return hots
  2895. }
  2896. //背景音乐
  2897. var EditBGM = function() {
  2898. this.mediaUpload = $(".music .mediaUpload");
  2899. this.musicBox = musicPlayBoxBind(this.mediaUpload, (file)=>{
  2900. uploadMusic(file, (rs, file)=>{
  2901. if (rs.code === 0) {
  2902. this.musicBox.show(/* this.mediaUpload, */file.name, rs.data)
  2903. }else{
  2904. this.musicBox.hide()
  2905. }
  2906. })
  2907. }, null)
  2908. }
  2909. EditBGM.prototype.init = function(data) {
  2910. if (!data.backgroundMusic)
  2911. return;
  2912. this.musicBox.show(/* this.mediaUpload, */ data.bgName || "backgound", data.backgroundMusic);
  2913. }
  2914. //导览编辑
  2915. var EditGuide = function() {
  2916. this.$list = $('#guide-list')
  2917. //$('#tourItemEdit') = $('#tourItemEdit');
  2918. this.targetTourPoint = null;
  2919. // fyz 记录当前编辑的导览点
  2920. // fyz 导览音乐队列
  2921. //this.tourAudio = {};
  2922. }
  2923. /**
  2924. * @author fyz 2019.07.31
  2925. * @description 新增参数data2, 表示data2.js中的数据
  2926. */
  2927. EditGuide.prototype.snapATourView = function(renew, insideFolder){
  2928. var ev = document.createEvent("MouseEvent");
  2929. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  2930. g_snapShotWidth = 200;
  2931. g_snapShotHeight = 140;
  2932. //window.screenSta = 'tour';
  2933. // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
  2934. ev.__callback = (imgData, info)=> {
  2935. this.uploadGuide(imgData, info, renew, insideFolder)
  2936. };
  2937. window.dispatchEvent(ev);
  2938. }
  2939. EditGuide.prototype.init = function(data, data2) {
  2940. this.createDom(data, data2);
  2941. //this.tourAudio = data2.tourAudio || {};
  2942. var that = this;
  2943. //点击添加导览
  2944. $('.addTour .innerBtn').eq(0).on("click", function () {
  2945. this.addFolderDom({name:"区域"+($("#tourList .listItem").length+1) } );//点击增加一段导览
  2946. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight //scroll to bottom
  2947. }.bind(this));
  2948. $('.addTour .innerBtn').eq(1).on("click", function () {
  2949. this.snapATourView()//点击截取视图
  2950. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight
  2951. }.bind(this));
  2952. $('.snapATourView .innerBtn').on("click", function() {
  2953. this.snapATourView(null,true);//folder内点击截取视图
  2954. $("#tourItemList ul")[0].scrollTop = $("#tourItemList ul")[0].scrollHeight
  2955. }.bind(this));
  2956. $('#renewTourBtn').on("click", function() { // 重新截取视图
  2957. this.snapATourView(this, !!this.editingFolderLi);
  2958. }.bind(this));
  2959. // 确认并保存导览信息
  2960. $('#tourFolderEdit .tail .submit').on("click", function() {
  2961. this.completeFolder();
  2962. }.bind(this));
  2963. $('#tourItemEdit .tail .submit').on("click", function() {
  2964. this.completeItem();
  2965. }.bind(this));
  2966. //点击导览编辑窗口右上角的关闭按钮
  2967. $("#tourItemEdit a.close, #tourItemEdit .tail .cancel").on("click", ()=>{
  2968. /* that.targetTourPoint[0].musicSta = true; ///??????????
  2969. // 取消操作, 重置状态
  2970. that.tourDetail.addClass("atRight"); */
  2971. this.cancelItem()
  2972. });
  2973. $("#tourFolderEdit a.close, #tourFolderEdit .tail .cancel").on("click", ()=>{
  2974. /* that.targetTourPoint[0].musicSta = true; ///??????????
  2975. // 取消操作, 重置状态
  2976. that.tourDetail.addClass("atRight"); */
  2977. this.cancelFolder()
  2978. });
  2979. //导览目录
  2980. $("#tourList").on("click", function(e) {
  2981. var target = $(e.target);
  2982. let folder = searchParent(e.target, { className: 'listItem' }, 7);
  2983. if(!folder)return;//可能点到了item
  2984. if (target.hasClass("del")) {
  2985. e.stopPropagation();
  2986. target.siblings(".DelConfirm").addClass("active");
  2987. } else {
  2988. if (target.hasClass("DelConfirm")) {
  2989. e.stopPropagation();
  2990. $(folder).remove()
  2991. //that.removeFolder(folder);//删除
  2992. } else {
  2993. if (target.hasClass("title") || target.hasClass("icon")) {
  2994. that.editFolder(folder)//编辑
  2995. }
  2996. }
  2997. }
  2998. });
  2999. //编辑item
  3000. $('.tourList ul').on('click', function(e) {
  3001. var target = $(e.target);
  3002. let itemDom = searchParent(e.target, { className: 'guideItem' }, 7);
  3003. if(!itemDom)return;//可能点到了folder
  3004. if(searchParent(e.target, { className: 'preview' })){
  3005. var choice = confirm("你确定删除吗?");
  3006. if (choice) {
  3007. var ul = searchParent(e.target, { className: 'tourList' })
  3008. target.closest('li').remove();
  3009. reIndexTourList(ul)
  3010. } else {
  3011. return false
  3012. }
  3013. }else{
  3014. that.editItem(itemDom);
  3015. }
  3016. })
  3017. //音乐
  3018. this.musicBoxFolder = musicPlayBoxBind($("#tourFolderEdit .mediaUpload"), null, ()=>{
  3019. (that.editingFolderLi || that.editingItemLi).tourData.musicInfo = {}//直接删除 不可逆
  3020. })
  3021. this.musicBoxItem = musicPlayBoxBind($("#tourItemEdit .mediaUpload"), null, ()=>{
  3022. (that.editingFolderLi || that.editingItemLi).tourData.musicInfo = {}//直接删除 不可逆
  3023. })
  3024. this.momentFolderMenuOptions = new MenuOptions({ //链接打开方式切换
  3025. dom: $(" #folderTourSwitch ")
  3026. })
  3027. this.momentMenuOptions = new MenuOptions({ //链接打开方式切换
  3028. dom: $(" #tourSwitch_Slice ")
  3029. })
  3030. this.rotCheckBox = new CheckBox({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. let url = cmp ? ('/api/scene/upload/' + number) : ('/manage/scene/upload/' + number)
  3425. $.ajax({
  3426. url: ceshi + url,
  3427. data: formData,
  3428. headers: {
  3429. token: token
  3430. },
  3431. dataType: 'json',
  3432. type: 'POST',
  3433. cache: false,
  3434. //上传文件无需缓存
  3435. processData: false,
  3436. //用于对data参数进行序列化处理 这里必须false
  3437. contentType: false,
  3438. //必须
  3439. success: function(rs) {
  3440. if(rs.code === 0){
  3441. callback(rs, file);
  3442. $(".edit-loading").addClass("hide");
  3443. }else if (rs.code === 5001) {
  3444. alert('请重新登录')
  3445. localStorage.dcj_token = ''
  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. let url = cmp ? ('/api/scene/roamViable/' + cmp) : '/manage/scene/roamViable'
  4489. $.ajax({
  4490. method: 'POST',
  4491. url: ceshi + url,
  4492. headers: {
  4493. 'Content-Type': 'application/json',
  4494. token: token
  4495. },
  4496. contentType: 'application/json',
  4497. data: JSON.stringify({
  4498. data: JSON.stringify(PanoData),
  4499. sceneCode: window.number
  4500. }),
  4501. success: (data)=>{
  4502. if (data.code === 0) {
  4503. this.afterSavePanoVisibles()
  4504. alert("保存漫游可行成功")
  4505. } else
  4506. alert("保存漫游可行失败")
  4507. if (data.code === 5001) {
  4508. alert('请重新登录')
  4509. localStorage.dcj_token = ''
  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. */