edit.js 243 KB

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