edit.js 101 KB

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