edit.js 145 KB

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