edit.js 153 KB

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