edit.js 135 KB

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