edit.js 145 KB

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