edit.js 204 KB

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