edit.js 226 KB

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