edit.js 131 KB

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