edit.js 112 KB

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