edit.js 134 KB

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