edit.js 134 KB

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