edit.js 104 KB

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