edit.js 110 KB

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