edit.js 101 KB

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