edit.js 229 KB

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