edit.js 113 KB

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