edit.js 101 KB

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