edit.js 259 KB

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