edit.js 136 KB

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