edit.js 103 KB

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