edit.js 101 KB

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