edit.js 113 KB

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