edit.js 101 KB

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