edit.js 104 KB

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