edit_zh.js 135 KB

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