edit.js 136 KB

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