edit.js 196 KB

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