edit.js 227 KB

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