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