edit.js 259 KB

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