edit.js 104 KB

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