edit.js 220 KB

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