edit.js 101 KB

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