edit.js 222 KB

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