edit.js 103 KB

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