edit.js 112 KB

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