edit.js 111 KB

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