edit.js 145 KB

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