edit.js 136 KB

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