edit.js 111 KB

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