edit.js 134 KB

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