edit.js 104 KB

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