edit.js 103 KB

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