edit.js 225 KB

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