edit.js 153 KB

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