edit.js 200 KB

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