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