edit.js 193 KB

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