edit.js 180 KB

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