edit.js 111 KB

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