edit.js 134 KB

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