edit_zh.js 121 KB

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