manage.js 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868
  1. var g_ProjectName = window.location.pathname.substring(window.location.pathname.indexOf('/') + 1, window.location.pathname.lastIndexOf('/'))
  2. var g_Prefix = 'https://super.4dage.com/'
  3. // var g_Prefix=window.location.href.substring(0,window.location.href.indexOf("/index.html")+1);
  4. var s = window.location.href.split('/')
  5. s.pop()
  6. //var g_Prefix = s.join('/');
  7. var g_index = null
  8. var g_modeldata = null
  9. var g_weixinTitle = null
  10. var g_Hots = null
  11. var g_HotMeshes = []
  12. var g_HotMeshSize = {
  13. g_HotMeshWidth: 0.3,
  14. g_HotMeshHeight: 0.3
  15. }
  16. //add表示添加,delete表示删除
  17. var g_HotStatus = null
  18. var g_newHot = [] //存储新加热点
  19. var g_HotImage = {
  20. point: 'https://super.4dage.com/images/4dagePoint2.png',
  21. point2: 'https://super.4dage.com/images/4dagePoint.png'
  22. }
  23. var g_saveHot = false
  24. var g_TextColor = 0x7777ff
  25. var g_Text = null
  26. var g_TextPlaneMesh = []
  27. var g_TextIconMesh = []
  28. var g_TextIcon = './images/text.png'
  29. var g_SelectTextIndex = null
  30. var g_TextShow = null
  31. var g_audioPlay = false
  32. var g_background = null
  33. var g_roof = null
  34. var g_data2 = null //加载的data2.js的内容
  35. var g_bgAudio = null //背景音乐
  36. var g_tourAudio = null //导览音乐
  37. var g_play = 1 //表示播放图标状态
  38. var g_playAudio = null //当前在播放或当继续播放时应该播放的,是g_bgAudio或g_tourAudio
  39. //var g_Texture=null;
  40. //var g_ChunknameTexture={}; //chunkname和贴图名称对应
  41. var g_NormalTexture = false
  42. var g_SpecularTexture = false
  43. var g_DirectionalLight = null
  44. var g_snapShotWidth = 200 //截图下载图片的大小
  45. var g_snapShotHeight = 140
  46. //微信分享
  47. var g_weixinObj = {
  48. title: document.querySelector('head title').innerHTML,
  49. lineLink: window.location.href,
  50. imgUrl: 'https://www.4dmodel.com/SuperPanoramic/images/weixintitle.jpg',
  51. desc: '四维时代提供技术支持'
  52. }
  53. window.browser = {
  54. //提前定义
  55. isMobile: function () {
  56. var e = navigator.userAgent || navigator.vendor || window.opera
  57. return (
  58. /(android|bb\d+|meego).+mobile|android|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
  59. e
  60. ) ||
  61. /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(
  62. e.substr(0, 4)
  63. )
  64. )
  65. },
  66. isFullscreen: function () {
  67. return document.fullscreenElement || document.mozFullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement
  68. },
  69. valueFromHash: function (e, t) {
  70. var i = new RegExp('[#&?]' + e + '=([^#&?]*)'),
  71. n = i.exec(window.location.href)
  72. if (!n) return t
  73. var r = n[1]
  74. return 'boolean' == typeof t ? 'true' === r || '1' === r : 'number' == typeof t ? parseFloat(r) : window.decodeURIComponent(r)
  75. },
  76. urlHasValue: function (key, isGetValue) {
  77. let querys = window.location.search.substr(1).split('&')
  78. if (isGetValue) {
  79. for (let i = 0; i < querys.length; i++) {
  80. let keypair = querys[i].split('=')
  81. if (keypair.length === 2 && keypair[0] === key) {
  82. return keypair[1]
  83. }
  84. }
  85. return ''
  86. } else {
  87. for (let i = 0; i < querys.length; i++) {
  88. let keypair = querys[i].split('=')
  89. if (keypair[0] == key) {
  90. return true
  91. }
  92. }
  93. return false
  94. }
  95. }
  96. }
  97. var settings = {
  98. hotClickEvent: {
  99. video: {
  100. playAndPause: true,
  101. examine: false,
  102. openHot: false
  103. },
  104. photo: {
  105. examine: false,
  106. openHot: false
  107. },
  108. shine: {
  109. examine: true,
  110. openHot: true
  111. }
  112. },
  113. hotClickActions: ['playAndPause', 'examine', 'openHot', 'fastTran'],
  114. markerHeight: 0.05, //距离地板高出多少,
  115. //默认的:
  116. teleportTime: 1500, //瞬间过渡的时间
  117. /* flytimeDistanceMultiplier:150,
  118. flyTime:750, */
  119. tourRotTime: 2, //默认停留2秒
  120. //dontExamHot:true,
  121. hotFastTran: false,
  122. transparentBg: false,
  123. bgImg: null,
  124. tileClass: {
  125. //默认全景贴图加载的清晰度
  126. pc: {
  127. nav: '2k',
  128. max: '4k'
  129. },
  130. bigMobile: {
  131. //width和height都超过一定值
  132. nav: browser.urlHasValue('padNav', true) || '2k',
  133. max: browser.urlHasValue('padMax', true) || '4k' //'2k',
  134. },
  135. mobile: {
  136. nav: browser.urlHasValue('phoneNav', true) || '1k', //不放大时
  137. max: browser.urlHasValue('phoneMax', true) || '4k' //放到最大
  138. }
  139. } //可以稍后自行修改
  140. /* extractFloor : { //提取一部分chunk作为新的floor,该floor不在楼层列表里显示,一般用于飞出后隐藏屋顶
  141. 'KJ-t-tHpdpKvb0ew' : [1,2,3,4,5,6,7,8], //第0层的第1,2,3个chunk是屋顶
  142. } */
  143. }
  144. if (window.number == '725' || window.number == '724') {
  145. //settings.mobileNavHigh = true
  146. settings.tileClass.mobile = { nav: '2k', max: '2k' }
  147. }
  148. //共用函数:
  149. window.common = null
  150. window.MathLight = null
  151. window.math = null
  152. window.easing = null
  153. window.lerp = null
  154. window.transitions = null
  155. function watch(object, propName, initialValue) {
  156. //监听某个属性的变化
  157. let v = initialValue
  158. Object.defineProperty(object, propName, {
  159. get: function () {
  160. return v
  161. },
  162. set: function (e) {
  163. console.log('watch:', propName, e)
  164. v = e
  165. }
  166. })
  167. }
  168. var toPrecision = function (e, t) {
  169. function i(e, t) {
  170. var i = Math.pow(10, t)
  171. return Math.round(e * i) / i
  172. }
  173. if (e instanceof Array) {
  174. for (var n = 0; n < e.length; n++) e[n] = i(e[n], t)
  175. return e
  176. }
  177. return i(e, t)
  178. }
  179. var dealMap = (map, o = {}) => {
  180. //使不resize when image is not power of two ,但缩小时会有锯齿
  181. if (!o.ignoreResize) {
  182. if (!map.image || !THREE.Math.isPowerOfTwo(map.image.width) || !THREE.Math.isPowerOfTwo(map.image.height)) {
  183. map.wrapS = map.wrapT = THREE.ClampToEdgeWrapping
  184. map.minFilter = THREE.LinearFilter
  185. //map.generateMipmaps = true;
  186. }
  187. }
  188. if (!browser.isMobile()) map.anisotropy = 3
  189. }
  190. var dom = {
  191. getOffset: function (type, element, parent) {
  192. left = type == 'left' ? element.offsetLeft : element.offsetTop
  193. if (!parent) parent = $('body')[0]
  194. while ((element = element.offsetParent)) {
  195. if (element == parent) break
  196. left += type == 'left' ? element.offsetLeft : element.offsetTop
  197. }
  198. return left
  199. }
  200. }
  201. var getTransformSid = function () {
  202. var name
  203. if (player.mode == 'panorama') {
  204. name = player.currentPano ? player.currentPano.id : 'outside'
  205. } else {
  206. name = 'outside'
  207. }
  208. return name
  209. }
  210. var LineDraw = {
  211. /* createLine: function(posArr, o) {
  212. var e = new THREE.BufferGeometry
  213. , p = new Float32Array(6);
  214. e.addAttribute("position", new THREE.BufferAttribute(p,3));
  215. //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
  216. var p = e.attributes.position.array;
  217. for (var i = 0; i < 2; i++) {
  218. p[i * 3] = posArr[i].x;
  219. p[i * 3 + 1] = posArr[i].y;
  220. p[i * 3 + 2] = posArr[i].z;
  221. }
  222. var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
  223. linewidth: o.width || 1,
  224. //windows无效。 似乎mac/ios上粗细有效 ?
  225. color: o.color || defaultColor,
  226. transparent: o.dontAlwaysSeen ? false : true,
  227. depthTest: o.dontAlwaysSeen ? true : false
  228. })
  229. var line = new THREE.Line(e,mat);
  230. line.renderOrder = o.renderOrder || 4
  231. //同tagStem; //如果不加高,可能会部分被model遮住
  232. return line;
  233. } */
  234. createLine: function (posArr, o = {}) {
  235. //多段普通线 (第二个点和第三个点之间是没有线段的, 所以不用在意线段顺序)
  236. var mat
  237. if (o.mat) {
  238. mat = o.mat
  239. } else {
  240. let prop = {
  241. color: o.color || defaultColor,
  242. transparent: o.dontAlwaysSeen ? false : true,
  243. depthTest: o.dontAlwaysSeen ? true : false,
  244. opacity: o.opacity != void 0 ? o.opacity : 1
  245. }
  246. if (o.deshed) {
  247. ;(prop.dashSize = o.dashSize || 0.1), (prop.gapSize = o.gapSize || 0.1)
  248. }
  249. mat = new THREE[o.deshed ? 'LineDashedMaterial' : 'LineBasicMaterial'](prop)
  250. }
  251. var line = new THREE.LineSegments(new THREE.BufferGeometry(), mat)
  252. line.renderOrder = o.renderOrder || 4
  253. this.moveLine(line, posArr)
  254. return line
  255. },
  256. moveLine: function (line, posArr) {
  257. if (posArr.length == 0) return
  258. let position = new Float32Array(posArr.length * 3) //[]
  259. for (var i = 0; i < 2; i++) {
  260. position[i * 3] = posArr[i].x
  261. position[i * 3 + 1] = posArr[i].y
  262. position[i * 3 + 2] = posArr[i].z
  263. }
  264. line.geometry.addAttribute('position', new THREE.BufferAttribute(position, 3))
  265. //line.geometry.setAttribute('position', new THREE.Float32BufferAttribute(new Float32Array(position), 3));
  266. line.geometry.attributes.position.needsUpdate = true
  267. line.geometry.computeBoundingSphere()
  268. /* if(line.material instanceof THREE.LineDashedMaterial){
  269. line.computeLineDistances() //只有非buffer的geometry才有
  270. } */
  271. }
  272. }
  273. var convertTool = {
  274. getPos2d: function (point, camera, dom) {
  275. //获取一个三维坐标对应屏幕中的二维坐标
  276. var camera = camera || player.camera
  277. var dom = dom || player.domElement
  278. if (!camera) return
  279. var pos = point.clone().project(camera) //比之前hotspot的计算方式写得简单 project用于3转2(求法同shader); unproject用于2转3 :new r.Vector3(e.x, e.y, -1).unproject(this.camera);
  280. var x, y
  281. x = ((pos.x + 1) / 2) * dom.clientWidth
  282. y = (1 - (pos.y + 1) / 2) * dom.clientHeight
  283. var inSight =
  284. x <= dom.clientWidth &&
  285. x >= 0 && //是否在屏幕中
  286. y <= dom.clientHeight &&
  287. y >= 0
  288. return {
  289. pos: new THREE.Vector2(x, y), // 屏幕像素坐标
  290. vector: pos, //(范围 -1 ~ 1)
  291. trueSide: pos.z < 1, //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点 参见Tag.update
  292. inSight: inSight //在屏幕范围内可见
  293. }
  294. },
  295. ifShelter: function (pos3d, pos2d, camera, floorIndex) {
  296. //检测某点在视线中是否被mesh遮挡
  297. if (!pos2d) pos2d = convertTool.getPos2d(pos3d)
  298. camera = camera || player.camera
  299. var ori = new THREE.Vector3(pos2d.x, pos2d.y, -1).unproject(camera) //找到视线原点
  300. var dir = pos3d.clone().sub(ori).normalize()
  301. var ray = new THREE.Raycaster(ori, dir) //由外向里 因为模型从内侧是可见的所以从外侧
  302. /* if(config.isEdit && publicObjectSet.editor.mainDesign.editing){
  303. var o = ray.intersectObjects(publicObjectSet.editor.mainDesign.wallMeshes);
  304. }else{ */
  305. let colliders = player.model.allFloorsVisible ? player.model.colliders : (floorIndex != void 0 ? player.model.floors.index[floorIndex] : player.model.currentFloor).collider.children
  306. //let colliders = (floorIndex == void 0 ) ? player.model.colliders : player.model.floors.index[floorIndex].collider.children
  307. var o = ray.intersectObjects(colliders)
  308. //}
  309. var len = pos3d.distanceTo(ori)
  310. if (o && o.length) {
  311. for (var i = 0; i < o.length; i++) {
  312. if (o[i].distance < len) {
  313. return true
  314. } //有遮挡
  315. }
  316. }
  317. },
  318. /*
  319. 拖拽时,获取鼠标在拖拽面上的位置(需要借助另一个intersectPlane面来计算,即和相机方向一样的面,可保证铺满屏幕)
  320. 但是不一定能获取到,比如鼠标射线不朝向拖拽面时,即使获取也会是一个意外的反方向的交点。
  321. */
  322. getPosAtPlane: function (pos, info /* , mouse, camera */) {
  323. //pos:与intersectPlane的交点 见笔记
  324. var A = pos
  325. var player = player
  326. var mouse = player.mouse
  327. var O = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(player.camera)
  328. if (info.y != void 0) {
  329. //地面线的
  330. var y = info.y
  331. if (player.mode == 'floorplan' /* || Math.abs(O.x-pos.x)<0.0001 && Math.abs(O.z-pos.z)<0.0001) */) {
  332. //intersectPlane和地面平行,无交点
  333. var x = pos.x,
  334. z = pos.z
  335. } else {
  336. if (y < player.camera.position.y && O.y <= A.y /* || y>player.camera.position.y && O.y >= A.y */) return null //鼠标射线向上。因为相机一定位于地面以上(地面不会抬高到相机上吧?),所以无交点。
  337. if (O.y == A.y) {
  338. console.log('一样??')
  339. return
  340. }
  341. if (A.y == y) {
  342. console.log('一样2??')
  343. return
  344. }
  345. var r = (O.y - y) / (A.y - y)
  346. var x = (r * A.x - O.x) / (r - 1)
  347. var z = (r * A.z - O.z) / (r - 1)
  348. }
  349. } else {
  350. //垂直的也有越过消失点以后反向变化的情况,但使用时影响不大
  351. var N = info.normalVec
  352. var P = info.pullPos
  353. if (N.y != 0) {
  354. console.log('N.y != 0')
  355. return
  356. } //仅仅支持垂直于地面的的墙壁,目前都是
  357. if (O.z == A.z) {
  358. console.log('O.z==A.z?')
  359. return
  360. }
  361. if (N.z != 0 && N.x != 0) {
  362. //直接用这个通用的也可以,支持斜线的墙
  363. //console.log('N.z==0 && N.x == 0?');
  364. var c = N.x * (A.x - O.x) + N.y * (A.y - O.y) + N.z * (A.z - O.z)
  365. if (c == 0) {
  366. console.log('分母为0?? return;')
  367. return
  368. }
  369. var t = -(N.x * O.x + N.y * O.y + N.z * O.z - (P.x * N.x + P.y * N.y + P.z * N.z)) / c
  370. var x = t * (A.x - O.x) + O.x
  371. var y = t * (A.y - O.y) + O.y
  372. var z = t * (A.z - O.z) + O.z
  373. /*原理: 已知空间直线L:(x-a)/m=(x-b)/n=(z-c)/p和空间平面π:Ax+By+Cz+D=0;
  374. 求直线L与平面π的交点的坐标。
  375. 把直线方程改写成参数形式:设(x-a)/m=(x-b)/n=(z-c)/p=t;
  376. 则x=mt+a;y=nt+b;z=pt+c;代入平面π的方程得:
  377. A(mt+a)+B(nt+b)+C(pt+c)+D=0
  378. 由此解得t=-(Aa+Bb+Cc+D)/(Am+Bn+Cp)
  379. 再代入参数方程即得交点的坐标(x,y,z). */
  380. } else if (N.x == 0) {
  381. //z与pullPos相等
  382. var z = P.z
  383. if (O.y == A.y) {
  384. console.log('一样??')
  385. return
  386. }
  387. if (A.y == y) {
  388. console.log('一样2??')
  389. return
  390. }
  391. if (A.z == z) {
  392. console.log('一样3??')
  393. return
  394. }
  395. var r = (O.z - z) / (A.z - z)
  396. var x = (r * A.x - O.x) / (r - 1)
  397. var y = (r * A.y - O.y) / (r - 1)
  398. } else if (N.z == 0) {
  399. //x与pullPos相等
  400. var x = P.x
  401. if (O.y == A.y) {
  402. console.log('一样??')
  403. return
  404. }
  405. if (A.y == y) {
  406. console.log('一样2??')
  407. return
  408. }
  409. if (A.x == x) {
  410. console.log('一样3??')
  411. return
  412. }
  413. var r = (O.x - x) / (A.x - x)
  414. var y = (r * A.y - O.y) / (r - 1)
  415. var z = (r * A.z - O.z) / (r - 1)
  416. }
  417. }
  418. return new THREE.Vector3(x, y, z)
  419. },
  420. getMouseIntersect: function (camera, meshes, mouse) {
  421. //获取鼠标和meshes交点
  422. var raycaster = new THREE.Raycaster()
  423. camera.updateMatrixWorld()
  424. var origin = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(camera),
  425. end = new THREE.Vector3(mouse.x, mouse.y, 1).unproject(camera)
  426. var dir = end.sub(origin).normalize()
  427. raycaster.set(origin, dir)
  428. var n = raycaster.intersectObjects(meshes)
  429. if (0 === n.length) return null
  430. return n[0]
  431. },
  432. ifIntersectChunks: function (A, B, options = {}) {
  433. //获取某个线段/射线和meshes的交点
  434. var dir = B.clone().sub(A).normalize()
  435. var len = options.InfinityLen ? Infinity : A.distanceTo(B) + (options.extLen || 0)
  436. var ray = new THREE.Raycaster(A.clone(), dir, 0, len)
  437. var o = ray.intersectObjects(options.model || player.model.colliders)
  438. if (o && o.length) return o
  439. if (options.throughWidth) {
  440. //允许最小宽度,防止穿过极小的缝隙导致撞墙感
  441. var normal = math.getNormal({
  442. points: [
  443. { x: A.x, y: A.z },
  444. { x: B.x, y: B.z }
  445. ]
  446. }) //线段法线
  447. normal.multiplyScalar(options.throughWidth)
  448. var normalVec3 = new THREE.Vector3(normal.x, 0, normal.y)
  449. var A2 = A.clone().add(normalVec3)
  450. ray.set(A2, dir)
  451. var o2 = ray.intersectObjects(options.model || player.model.colliders)
  452. ray.set(A.clone().add(normalVec3.negate()), dir)
  453. if (o2 && o2.length) return o2
  454. var o3 = ray.intersectObjects(options.model || player.model.colliders)
  455. if (o3 && o3.length) return o3
  456. }
  457. return null
  458. },
  459. getPosAtSphere: function (pos3d, toPanoPos) {
  460. var dir = pos3d.clone().sub(toPanoPos)
  461. dir.normalize() //然后计算在球中
  462. dir.multiplyScalar(Constants.skyRadius)
  463. dir.add(toPanoPos)
  464. return dir
  465. },
  466. getScaleForConstantSize: function (op = {}) {
  467. //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  468. var w
  469. var i = new THREE.Vector3(),
  470. o = new THREE.Vector3(),
  471. l = new THREE.Vector3(),
  472. c = new THREE.Vector3(),
  473. h = new THREE.Vector3()
  474. if (!op.resolution) {
  475. let renderSize = player.sceneRenderer.renderer.getSize()
  476. op.resolution = { x: renderSize.width, y: renderSize.height }
  477. }
  478. if (!op.camera) {
  479. let camera = player.cameraControls.activeControl ? player.cameraControls.activeControl.camera : player.camera
  480. let camera2 = camera.clone()
  481. camera2.matrixWorld.copy(player.camera.matrixWorld) //因为其他原因该camera的matrixWorld被还原了,而player.camera的是正确的
  482. op.camera = camera2
  483. }
  484. if (op.width2d) w = op.width2d //如果恒定二维宽度
  485. else {
  486. //否则考虑上距离,加一丢丢近大远小的效果
  487. var currentDis, nearBound, farBound
  488. if (op.camera.type == 'OrthographicCamera') {
  489. currentDis = (op.camera.right - op.camera.left) / op.camera.zoom
  490. } else {
  491. currentDis = op.position.distanceTo(op.camera.position)
  492. }
  493. w = op.maxSize - (op.maxSize - op.minSize) * THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound)
  494. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  495. }
  496. i.copy(op.position).project(op.camera), //tag中心在屏幕上的二维坐标
  497. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i), //转化成px -w/2 到 w/2的范围
  498. l.set(w / 2, 0, 0).add(o), //加上tag宽度的一半
  499. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l), //再转回 -1 到 1的范围
  500. h.copy(c).unproject(op.camera) //再转成三维坐标,求得tag边缘的位置
  501. let halfMeter = h.distanceTo(op.position) //就能得到tag的三维半径
  502. return halfMeter //可能NAN 当相机和position重叠时
  503. },
  504. updateVisible: function (object, reason, ifShow, level = 0, type) {
  505. //当所有加入的条件都不为false时才显示. reason='force'一般是强制、临时的
  506. if (!object.unvisibleReasons) object.unvisibleReasons = [] //如果length>0代表不可见
  507. if (!object.visibleReasons) object.visibleReasons = [] //在同级时,优先可见
  508. var update = function () {
  509. //先按从高到低的level排列
  510. object.unvisibleReasons = object.unvisibleReasons.sort((a, b) => b.level - a.level)
  511. object.visibleReasons = object.visibleReasons.sort((a, b) => b.level - a.level)
  512. var maxVisiLevel = object.visibleReasons[0] ? object.visibleReasons[0].level : -1
  513. var maxunVisiLevel = object.unvisibleReasons[0] ? object.unvisibleReasons[0].level : -1
  514. var shouldVisi = maxVisiLevel >= maxunVisiLevel
  515. var visiBefore = object.visible
  516. if (visiBefore != shouldVisi) {
  517. object.visible = shouldVisi
  518. object.dispatchEvent({
  519. type: 'isVisible',
  520. visible: shouldVisi,
  521. reason
  522. })
  523. }
  524. }
  525. if (ifShow) {
  526. var index = object.unvisibleReasons.findIndex(e => e.reason == reason)
  527. if (index > -1) {
  528. type = 'cancel'
  529. object.unvisibleReasons.splice(index, 1)
  530. }
  531. if (type == 'add') {
  532. if (!object.visibleReasons.some(e => e.reason == reason)) {
  533. object.visibleReasons.push({ reason, level })
  534. }
  535. }
  536. } else {
  537. var index = object.visibleReasons.findIndex(e => e.reason == reason)
  538. if (index > -1) {
  539. type = 'cancel'
  540. object.visibleReasons.splice(index, 1)
  541. }
  542. if (type != 'cancel') {
  543. if (!object.unvisibleReasons.some(e => e.reason == reason)) {
  544. object.unvisibleReasons.push({ reason, level })
  545. }
  546. }
  547. }
  548. update()
  549. },
  550. getObjVisiByReason: function (object, reason) {
  551. //获取在某条件下是否可见. 注: 用户在数据集选择可不可见为"datasetSelection"
  552. if (object.visible) return true
  553. else {
  554. return !object.unvisibleReasons || !object.unvisibleReasons.some(e => e.reason == reason)
  555. }
  556. }
  557. }
  558. window.expandCommon = function (common) {
  559. Object.assign(common, {
  560. intervalTool: {
  561. //延时update,防止卡顿
  562. list: [],
  563. isWaiting: function (name, func, delayTime /* , autoCycle */) {
  564. let item = this.list.find(e => e.name == name)
  565. if (!item) {
  566. //如果没有该项, 则加入循环
  567. let ifContinue = func()
  568. item = { name, func, delayTime }
  569. this.list.push(item)
  570. setTimeout(() => {
  571. var a = this.list.indexOf(item)
  572. this.list.splice(a, 1)
  573. let { func, delayTime } = item
  574. if (item.requestUpdate || ifContinue) this.isWaiting(name, func, delayTime) //循环
  575. }, delayTime)
  576. } else {
  577. //如果有该项,说明现在请求下一次继续更新
  578. //更新属性
  579. item.func = func
  580. item.delayTime = delayTime
  581. item.requestUpdate = true
  582. }
  583. }
  584. },
  585. sortByScore: function (list, request, rank) {
  586. var i = request ? common.filterAll(list, request) : list
  587. return 0 === i.length
  588. ? null
  589. : (i = i
  590. .map(function (e) {
  591. let scores = rank.map(function (f) {
  592. return f(e)
  593. }) //add
  594. return {
  595. item: e,
  596. scores,
  597. score: scores.reduce(function (t, i) {
  598. return t + i
  599. }, 0)
  600. }
  601. })
  602. .sort(function (e, t) {
  603. return t.score - e.score
  604. }))
  605. },
  606. getVisiblePano: function (positions = [], panos, options = {}) {
  607. //add
  608. var visiblePanos = []
  609. options.posAtPanos = options.posAtPanos || {} //在不同漫游点的positions
  610. panos.forEach(pano => {
  611. if (!pano.isAligned()) return
  612. var A = pano.position.clone()
  613. var posB = options.posAtPanos[pano.id] || positions
  614. var posLength = posB.length
  615. for (let i = 0; i < posLength; i++) {
  616. var B = posB[i]
  617. var ray = new THREE.Raycaster(A.clone(), B.clone().sub(A).normalize(), 0, A.distanceTo(B) - (options.tolerance || 0))
  618. var o = ray.intersectObjects(options.model || player.model.colliders, true)
  619. if (!o || !o.length) {
  620. //只要有一点可见,就算整体可见
  621. visiblePanos.push(pano.id)
  622. break
  623. }
  624. }
  625. })
  626. return visiblePanos
  627. },
  628. realVisible: function (object) {
  629. var v = true
  630. var parent = object
  631. var lastParent
  632. while (parent) {
  633. if (parent.visible === false) {
  634. v = false
  635. break
  636. }
  637. lastParent = parent
  638. parent = parent.parent
  639. }
  640. if (v && !(lastParent instanceof THREE.Scene)) {
  641. //已被删除
  642. v = false
  643. }
  644. return v
  645. },
  646. getMaxCubemapSize() {
  647. //在renderer创建完前获取
  648. let size = player.sceneRenderer?.renderer?.capabilities.maxCubemapSize
  649. if (size) {
  650. return size
  651. }
  652. try {
  653. var e = document.createElement('canvas'),
  654. t = e.getContext('webgl')
  655. t || (t = e.getContext('experimental-webgl'))
  656. var i = t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE)
  657. return i
  658. } catch (e) {
  659. return 0
  660. }
  661. }
  662. })
  663. }
  664. window.expandMath = function (math) {
  665. Object.assign(math, {
  666. linearClamp(value, xArr, yArr) {
  667. if (arguments.length == 5) {
  668. xArr = [arguments[1], arguments[2]]
  669. yArr = [arguments[3], arguments[4]]
  670. }
  671. let len = xArr.length
  672. if (value <= xArr[0]) return yArr[0]
  673. if (value >= xArr[len - 1]) return yArr[len - 1]
  674. let i = 0
  675. while (++i < len) {
  676. if (value < xArr[i]) {
  677. let x1 = xArr[i - 1],
  678. x2 = xArr[i],
  679. y1 = yArr[i - 1],
  680. y2 = yArr[i]
  681. value = y1 + ((y2 - y1) * (value - x1)) / (x2 - x1)
  682. break
  683. }
  684. }
  685. return value
  686. },
  687. getBaseLog(x, y) {
  688. //返回以 x 为底 y 的对数(即 logx y) . Math.log 返回一个数的自然对数
  689. return Math.log(y) / Math.log(x)
  690. },
  691. getSpreadRatio(n) {
  692. //n为整数,返回的0-1的数。 目的是获得较为平均的数字,主要用于颜色hue。数字含义:按顺序将1不停平分下去,每刀都切在每段的二分之一处,则第n刀在原先整体的几分之几处
  693. if (n == 0) return 0
  694. let k = Math.floor(math.getBaseLog(2, n)) //是2的几次幂
  695. let r = ((n - Math.pow(2, k)) * 2 + 1) / Math.pow(2, k + 1)
  696. console.log('getSpreadRatio', n, r)
  697. return r
  698. }
  699. })
  700. }
  701. //--------------------------------------
  702. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  703. var Manage = function () {
  704. ;(this.weixinURL = 'https://res.wx.qq.com/open/js/jweixin-1.2.0.js'), (this.time = '?' + new Date().getTime())
  705. this.loadAudio()
  706. this.loadWeixin()
  707. }
  708. //动态加载js文件
  709. Manage.prototype.LoadJs = function (_files, succes) {
  710. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  711. var classcodes = []
  712. var FileArray = []
  713. if (typeof _files === 'object') {
  714. FileArray = _files
  715. } else {
  716. /*如果文件列表是字符串,则用,切分成数组*/
  717. if (typeof _files === 'string') {
  718. FileArray = _files.split(',')
  719. }
  720. }
  721. if (FileArray != null && FileArray.length > 0) {
  722. var LoadedCount = 0
  723. for (var i = 0; i < FileArray.length; i++) {
  724. loadFile(FileArray[i], function () {
  725. LoadedCount++
  726. if (LoadedCount == FileArray.length) {
  727. try {
  728. succes()
  729. } catch (err) {
  730. console.log('err: 您未定义回调')
  731. }
  732. }
  733. })
  734. }
  735. }
  736. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  737. function loadFile(url, success) {
  738. if (!FileIsExt(classcodes, url)) {
  739. var _ThisType = GetFileType(url)
  740. var ThisType = _ThisType.indexOf('?') == -1 ? _ThisType : _ThisType.substring(0, _ThisType.indexOf('?'))
  741. var fileObj = null
  742. if (ThisType == '.js') {
  743. fileObj = document.createElement('script')
  744. fileObj.src = url
  745. } else if (ThisType == '.css') {
  746. fileObj = document.createElement('link')
  747. fileObj.href = url
  748. fileObj.type = 'text/css'
  749. fileObj.rel = 'stylesheet'
  750. } else if (ThisType == '.less') {
  751. fileObj = document.createElement('link')
  752. fileObj.href = url
  753. fileObj.type = 'text/css'
  754. fileObj.rel = 'stylesheet/less'
  755. }
  756. success = success || function () {}
  757. fileObj.onload = fileObj.onreadystatechange = function () {
  758. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  759. success()
  760. classcodes.push(url)
  761. }
  762. }
  763. document.getElementsByTagName('head')[0].appendChild(fileObj)
  764. } else {
  765. success()
  766. }
  767. }
  768. /*获取文件类型,后缀名,小写*/
  769. function GetFileType(url) {
  770. if (url != null && url.length > 0) {
  771. return url.substr(url.lastIndexOf('.')).toLowerCase()
  772. }
  773. return ''
  774. }
  775. /*文件是否已加载*/
  776. function FileIsExt(FileArray, _url) {
  777. if (FileArray != null && FileArray.length > 0) {
  778. var len = FileArray.length
  779. for (var i = 0; i < len; i++) {
  780. if (FileArray[i] == _url) {
  781. return true
  782. }
  783. }
  784. }
  785. return false
  786. }
  787. }
  788. //获取页面url后面的参数
  789. Manage.prototype.number = function (variable) {
  790. var query = window.location.search.substring(1)
  791. var vars = query.split('&')
  792. for (var i = 0; i < vars.length; i++) {
  793. var pair = vars[i].split('=')
  794. if (pair[0] == variable) {
  795. return pair[1]
  796. }
  797. }
  798. return false
  799. }
  800. Manage.prototype.loadWeixin = function () {
  801. var that = this
  802. this.LoadJs(that.weixinURL + that.time, function () {})
  803. }
  804. Manage.prototype.weixinShare = function () {
  805. console.log({ str: 'weixinShare', level: 1 })
  806. $.ajax({
  807. url: 'https://www.4dage.com/wechat/jssdk/',
  808. type: 'post',
  809. data: {
  810. url: location.href.split('#')[0]
  811. },
  812. dataType: 'jsonp',
  813. jsonpCallback: 'success_jsonp',
  814. success: function (data, textStatus) {
  815. console.log({ str: '微信 success,' + data.appId, level: 1 })
  816. wx.config({
  817. // debug : true,
  818. appId: data.appId,
  819. timestamp: data.timestamp,
  820. nonceStr: data.nonceStr,
  821. signature: data.signature,
  822. jsApiList: [
  823. 'checkJsApi',
  824. 'onMenuShareTimeline',
  825. 'onMenuShareAppMessage',
  826. 'onMenuShareQQ',
  827. 'onMenuShareWeibo',
  828. 'hideMenuItems',
  829. 'showMenuItems',
  830. 'hideAllNonBaseMenuItem',
  831. 'showAllNonBaseMenuItem',
  832. 'translateVoice',
  833. 'startRecord',
  834. 'stopRecord',
  835. 'onRecordEnd',
  836. 'playVoice',
  837. 'pauseVoice',
  838. 'stopVoice',
  839. 'uploadVoice',
  840. 'downloadVoice',
  841. 'chooseImage',
  842. 'previewImage',
  843. 'uploadImage',
  844. 'downloadImage',
  845. 'getNetworkType',
  846. 'openLocation',
  847. 'getLocation',
  848. 'hideOptionMenu',
  849. 'showOptionMenu',
  850. 'closeWindow',
  851. 'scanQRCode',
  852. 'chooseWXPay',
  853. 'openProductSpecificView',
  854. 'addCard',
  855. 'chooseCard',
  856. 'openCard'
  857. ]
  858. })
  859. },
  860. error: function (XMLHttpRequest, textStatus, errorThrown) {
  861. console.error({ str: '微信分享失败! textStatus:' + textStatus, level: 1 })
  862. }
  863. })
  864. var success_jsonp = function (json) {
  865. console.log({ str: 'success_jsonp:' + json, level: 1 })
  866. }
  867. wx.ready(function () {
  868. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  869. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  870. //分享到朋友圈
  871. console.log({ str: '微信 ready', level: 1 })
  872. wx.onMenuShareTimeline({
  873. title: g_weixinObj.title, // 分享标题
  874. link: g_weixinObj.lineLink, // 分享链接
  875. imgUrl: g_weixinObj.imgUrl, // 分享图标
  876. desc: g_weixinObj.desc
  877. })
  878. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  879. wx.onMenuShareAppMessage({
  880. title: g_weixinObj.title, // 分享标题
  881. desc: g_weixinObj.desc, // 分享描述
  882. link: g_weixinObj.lineLink, // 分享链接
  883. imgUrl: g_weixinObj.imgUrl, // 分享图标
  884. type: '', // 分享类型,music、video或link,不填默认为link
  885. dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
  886. })
  887. wx.onMenuShareWeibo({
  888. title: g_weixinObj.title, // 分享标题
  889. desc: g_weixinObj.desc, // 分享描述
  890. link: g_weixinObj.lineLink, // 分享链接
  891. imgUrl: g_weixinObj.imgUrl, // 分享图标
  892. success: function () {
  893. // 用户确认分享后执行的回调函数
  894. },
  895. cancel: function () {
  896. // 用户取消分享后执行的回调函数
  897. }
  898. })
  899. wx.onMenuShareQZone({
  900. title: g_weixinObj.title, // 分享标题
  901. desc: g_weixinObj.desc, // 分享描述
  902. link: g_weixinObj.lineLink, // 分享链接
  903. imgUrl: g_weixinObj.imgUrl, // 分享图标
  904. success: function () {
  905. // 用户确认分享后执行的回调函数
  906. },
  907. cancel: function () {
  908. // 用户取消分享后执行的回调函数
  909. }
  910. })
  911. wx.onMenuShareQQ({
  912. title: g_weixinObj.title, // 分享标题
  913. desc: g_weixinObj.desc, // 分享描述
  914. link: g_weixinObj.lineLink, // 分享链接
  915. imgUrl: g_weixinObj.imgUrl, // 分享图标
  916. success: function () {
  917. // 用户确认分享后执行的回调函数
  918. },
  919. cancel: function () {
  920. // 用户取消分享后执行的回调函数
  921. }
  922. })
  923. wx.error(function (res) {
  924. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  925. })
  926. })
  927. }
  928. Manage.prototype.dealURL = function (src, type) {
  929. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  930. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  931. if (window.isLocal && settings.localPrefix != void 0) {
  932. //本地将线上的前缀替换
  933. var oldPrefix = 'super.4dage.com/' //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  934. var index = src.indexOf(oldPrefix)
  935. if (index > -1) {
  936. var wholeOldPrefix = src.slice(0, index + oldPrefix.length)
  937. return src.replace(wholeOldPrefix, settings.localPrefix)
  938. } else console.error('没有找到合适的本地链接')
  939. return src
  940. } else {
  941. //add https://
  942. var prefix = g_Prefix.replace('https://', '').replace('http://', '')
  943. if (!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)) {
  944. src = 'https://' + src
  945. }
  946. return src
  947. }
  948. }
  949. Manage.prototype.removeSrcPostMark = function (url) {
  950. //去除texture.load时自动加上的'?'
  951. var index = url.indexOf('?')
  952. if (index > -1) {
  953. return url.slice(0, index)
  954. } else return url
  955. }
  956. Manage.prototype.showInfo = function (o) {
  957. // ({result:true, title:"发布成功"});
  958. var box = $('.resultBox')
  959. var title = o.title || o || i18n.get('保存成功')
  960. box.children().eq(0).html(title)
  961. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  962. var time = o.time || THREE.Math.clamp(title.length * 130, 1300, 5000)
  963. o.time || console.log('showtime ' + time)
  964. //实际有一半的时间在渐变透明度
  965. this.showInfoTimer && clearTimeout(this.showInfoTimer)
  966. box.removeClass('animate') //如果之后不久又要showinfo一个的话,先停止前面的animate
  967. setTimeout(
  968. function () {
  969. box.css({
  970. '-webkit-animation-duration': time + 'ms',
  971. 'animation-duration': time + 'ms'
  972. })
  973. if (o.top) {
  974. box.children().css('top', o.top + '%')
  975. } else {
  976. box.children().css('top', '')
  977. }
  978. box.removeClass('hide')
  979. box.addClass('animate')
  980. if (o.dontInteract) {
  981. //遮挡对屏幕的操作
  982. box.css('pointer-events', 'auto')
  983. } else {
  984. box.css('pointer-events', 'none')
  985. }
  986. this.showInfoTimer = setTimeout(
  987. function () {
  988. box.removeClass('animate')
  989. box.addClass('hide')
  990. this.showInfoTimer = null
  991. }.bind(this),
  992. time + 20
  993. )
  994. }.bind(this),
  995. 50
  996. ) //这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  997. } //like: manage.showInfo({title:'a', top:20})
  998. //公用的函数
  999. function getQueryVariable(variable) {
  1000. var query = window.location.search.substring(1)
  1001. var vars = query.split('&')
  1002. for (var i = 0; i < vars.length; i++) {
  1003. var pair = vars[i].split('=')
  1004. if (pair[0] == variable) {
  1005. return pair[1]
  1006. }
  1007. }
  1008. return false
  1009. }
  1010. //隐藏公司Logo
  1011. function showLogo() {
  1012. $('#myCompany').hide()
  1013. $('#loaderCoBrandName').hide()
  1014. $('#title-logo').hide()
  1015. $('.title-container').css('justify-content', 'center')
  1016. }
  1017. // 隐藏顶部介绍
  1018. function topTextHide() {
  1019. console.log('------------------隐藏顶部')
  1020. $('.pinTop').hide()
  1021. }
  1022. //czj 添加随机的时间
  1023. function randomTime() {
  1024. return new Date()
  1025. }
  1026. function matcher(data) {
  1027. if (!data || !g_version) return data
  1028. delete data.model.vision_version
  1029. var _data = {
  1030. files: {
  1031. templates: ['images/images{{number}}/{{filename}}']
  1032. },
  1033. model: {
  1034. sid: window.number,
  1035. camera_start:
  1036. data.model.images && data.model.images.length != 0
  1037. ? {
  1038. camera: {
  1039. zoom: '-1',
  1040. quaternion: [
  1041. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  1042. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  1043. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  1044. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  1045. ]
  1046. },
  1047. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  1048. mode: '0'
  1049. }
  1050. : ''
  1051. },
  1052. sid: window.number,
  1053. hoticon: {
  1054. default: 'https://super.4dage.com/images/4dagePoint2.png',
  1055. higt: 'https://super.4dage.com/images/4dagePoint.png'
  1056. },
  1057. special: 'false',
  1058. weixinDesc: ''
  1059. }
  1060. $.extend(true, data, _data)
  1061. return data
  1062. }
  1063. function hotMatcher(data = {}) {
  1064. //if(!data || !g_version) return data;
  1065. if (g_version) {
  1066. data.tourAudio = data.audio || {}
  1067. } else {
  1068. data.tourAudio = {}
  1069. }
  1070. return data
  1071. }
  1072. var GifTexDeal = {
  1073. animateObjects: [],
  1074. animateTexs: [],
  1075. addAnimation: function (texture, owner, info, id) {
  1076. /* if(this.animateObjects.find(e=>
  1077. e.texture == texture && !ifSame(info, e.info)
  1078. )) */
  1079. var animation
  1080. var tex = this.animateTexs.find(e => e.texture == texture)
  1081. if (tex) {
  1082. animation = tex
  1083. } else {
  1084. animation = { texture, info }
  1085. this.animateTexs.push(animation)
  1086. this.setRepeart(animation)
  1087. }
  1088. var object = {
  1089. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  1090. owner
  1091. }
  1092. this.animateObjects.push(object)
  1093. return object
  1094. },
  1095. remove: function (object) {
  1096. var index = this.animateObjects.indexOf(object)
  1097. if (index > -1) {
  1098. this.animateObjects.splice(index, 1)
  1099. if (!this.animateObjects.find(e => e.animation == object.animation)) {
  1100. let i = this.animateTexs.indexOf(object.animation)
  1101. this.animateTexs.splice(i, 1)
  1102. object.animation.texture.repeat.set(1, 1)
  1103. }
  1104. this.stop(object)
  1105. }
  1106. },
  1107. setRepeart: function (animation) {
  1108. animation.texture.repeat.set(1 / animation.info.cellXcount, 1 / animation.info.cellYcount)
  1109. },
  1110. start: function (object) {
  1111. if (!object || object.started) return
  1112. object.started = true
  1113. if (object.animation.started) return
  1114. object.animation.started = true
  1115. var info = object.animation.info
  1116. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0)
  1117. if (count <= 1) return
  1118. transitions.start(
  1119. progress => {
  1120. var index = Math.floor((count - 1) * progress)
  1121. var indexX = index % info.cellXcount
  1122. var indexY = info.cellYcount - Math.floor(index / info.cellXcount) - 1 //uv.offset.y是从下到上的
  1123. object.animation.texture.offset.x = indexX / info.cellXcount
  1124. object.animation.texture.offset.y = indexY / info.cellYcount
  1125. //console.log(object.id + " : "+ object.texture.offset.toArray())
  1126. },
  1127. info.duration * -1,
  1128. null,
  1129. /* ()=>{//done (-1):循环
  1130. object.started = false
  1131. object.texture.offset.x = 0;
  1132. object.texture.offset.y = 0;
  1133. this.start(object)
  1134. }, */ 0,
  1135. null,
  1136. object.id,
  1137. 'gif_' + object.animation.texture.id
  1138. )
  1139. },
  1140. stop: function (object) {
  1141. if (!object || !object.started) return
  1142. object.started = false
  1143. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  1144. if (this.animateObjects.find(e => e.animation == object.animation && e.started)) return
  1145. transitions.cancelById('gif_' + object.animation.texture.id)
  1146. object.animation.texture.offset.set(0, 0)
  1147. object.animation.started = false
  1148. }
  1149. }
  1150. var CloneObject = function (copyObj, result, isSimpleCopy, extraReplace) {
  1151. //isSimpleCopy只复制最外层
  1152. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  1153. if (!copyObj) return copyObj //0 null undefined ''
  1154. result = result || {}
  1155. if (copyObj instanceof Array) {
  1156. /* if (copyObj[0]instanceof Object) {
  1157. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  1158. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  1159. }
  1160. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  1161. return copyObj.map(e => {
  1162. if (e instanceof Object) {
  1163. return CloneObject(e)
  1164. } else return e
  1165. })
  1166. } else {
  1167. if (copyObj.clone instanceof Function) {
  1168. //解决一部分
  1169. return copyObj.clone()
  1170. }
  1171. }
  1172. for (var key in copyObj) {
  1173. if (copyObj[key] instanceof Object && !isSimpleCopy) result[key] = CloneObject(copyObj[key])
  1174. else result[key] = copyObj[key]
  1175. //如果是函数类同基本数据,即复制引用
  1176. }
  1177. return result
  1178. }
  1179. var ifSame = function (object1, object2) {
  1180. if (object1 == object2) return true // 0 != undefined , 0 == ''
  1181. else if (!object1 || !object2) return false
  1182. else if (object1.constructor != object2.constructor) {
  1183. return false
  1184. } else if (object1 instanceof Array) {
  1185. if (object1.length != object2.length) return false
  1186. var _object2 = object2.slice(0)
  1187. for (let i = 0; i < object1.length; i++) {
  1188. var u = _object2.find(e => ifSame(object1[i], e))
  1189. if (u == void 0 && !_object2.includes(u) && !object1.includes(u)) return false
  1190. else {
  1191. let index = _object2.indexOf(u)
  1192. _object2.splice(index, 1)
  1193. }
  1194. }
  1195. return true
  1196. } else if (object1.equals instanceof Function) {
  1197. //复杂数据仅支持这种,其他的可能卡住?
  1198. return object1.equals(object2)
  1199. } else if (typeof object1 == 'number' || typeof object1 == 'string') {
  1200. if (isNaN(object1) && isNaN(object2)) return true
  1201. else return object1 == object2
  1202. } else if (typeof object1 == 'object') {
  1203. var keys1 = Object.keys(object1)
  1204. var keys2 = Object.keys(object2)
  1205. if (!ifSame(keys1, keys2)) return false
  1206. for (let i in object1) {
  1207. var same = ifSame(object1[i], object2[i])
  1208. if (!same) return false
  1209. }
  1210. return true
  1211. } else {
  1212. console.log('isSame出现例外')
  1213. }
  1214. }
  1215. function initByTHREE(THREE) {
  1216. window.bus = new THREE.EventDispatcher() //因为player一开始总是没创建好,所以加一个事件传递器
  1217. THREE.TransitionPass = function (scene, camera) {
  1218. this.renderScene = scene
  1219. this.renderCamera = camera
  1220. this.coverRenderTarget = new THREE.WebGLRenderTarget(100, 100, {
  1221. minFilter: THREE.LinearFilter,
  1222. magFilter: THREE.LinearFilter,
  1223. format: THREE.RGBAFormat
  1224. })
  1225. this.coverTex = this.coverRenderTarget.texture
  1226. this.enabled = false
  1227. this.oldClearColor = new THREE.Color()
  1228. this.oldClearAlpha = 1
  1229. this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1)
  1230. this.scene = new THREE.Scene()
  1231. this.material = this.getMaskMaterial()
  1232. var copyShader = THREE.CopyShader
  1233. this.materialCopy = new THREE.ShaderMaterial({
  1234. uniforms: this.copyUniforms,
  1235. vertexShader: copyShader.vertexShader,
  1236. fragmentShader: copyShader.fragmentShader,
  1237. blending: THREE.NoBlending,
  1238. depthTest: false,
  1239. depthWrite: false,
  1240. transparent: true
  1241. })
  1242. this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), this.material)
  1243. this.quad.frustumCulled = false // Avoid getting clipped
  1244. this.scene.add(this.quad)
  1245. }
  1246. THREE.TransitionPass.prototype = {
  1247. //波形扩散,出下一个画面
  1248. constructor: THREE.TransitionPass,
  1249. setSize: function (width, height) {
  1250. this.coverRenderTarget.setSize(width, height)
  1251. },
  1252. render: function (renderer, writeBuffer, readBuffer, delta, maskActive) {
  1253. var oldAutoClear = renderer.autoClear
  1254. renderer.autoClear = false
  1255. var uniforms = this.quad.material.uniforms
  1256. uniforms.bgTex.value = readBuffer.texture //更新
  1257. uniforms.coverTex.value = this.coverTex
  1258. uniforms.progress.value = player.model.skybox.material.uniforms.progress.value //
  1259. uniforms.screenRatio.value = player.domElement.clientWidth / player.domElement.clientHeight // 使波纹为圆形
  1260. uniforms.screenRatio.value *= uniforms.screenRatio.value
  1261. renderer.render(this.scene, this.camera)
  1262. renderer.autoClear = oldAutoClear
  1263. },
  1264. start: function (sceneRenderer) {
  1265. this.enabled = true
  1266. //draw coverTex
  1267. this.quad.material.uniforms.progress.value = 1
  1268. sceneRenderer.renderer.render(sceneRenderer.scene, sceneRenderer.camera, this.coverRenderTarget, true)
  1269. },
  1270. stop: function () {
  1271. this.enabled = false
  1272. },
  1273. getMaskMaterial: function () {
  1274. return new THREE.ShaderMaterial({
  1275. uniforms: {
  1276. coverTex: {
  1277. type: 't',
  1278. value: null
  1279. },
  1280. bgTex: {
  1281. type: 't',
  1282. value: null
  1283. },
  1284. progress: {
  1285. type: 'f',
  1286. value: 0
  1287. },
  1288. screenRatio: {
  1289. type: 'f',
  1290. value: 1
  1291. }
  1292. },
  1293. vertexShader: `
  1294. varying vec2 vUv;
  1295. void main()
  1296. {
  1297. vUv = uv;
  1298. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  1299. }
  1300. `,
  1301. fragmentShader: `
  1302. uniform sampler2D coverTex;
  1303. uniform sampler2D bgTex;
  1304. uniform float progress;
  1305. uniform float screenRatio;
  1306. varying vec2 vUv;
  1307. void main() {
  1308. const float maxRadius = 0.708; // sqrt(0.5^2+0.5^2)
  1309. const float minRadius = 0.0 ;
  1310. float radius = screenRatio>1.0 ? sqrt((vUv.x - 0.5)*(vUv.x - 0.5) + (vUv.y - 0.5)*(vUv.y - 0.5)/screenRatio) : sqrt((vUv.x - 0.5)*(vUv.x - 0.5)*screenRatio+ (vUv.y - 0.5)*(vUv.y - 0.5));
  1311. float diff = 0.292; //1.0-maxRadius;
  1312. float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
  1313. float radiusOut = radiusIn + diff;
  1314. if(radius < radiusIn) {
  1315. gl_FragColor = texture2D(bgTex, vUv);
  1316. //gl_FragColor = vec4(0.0,0.0,1.0,1.0);//
  1317. }else if(radius>radiusOut){
  1318. gl_FragColor = texture2D(coverTex, vUv) ;
  1319. //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
  1320. }else{
  1321. vec4 color1 = texture2D(bgTex, vUv);
  1322. vec4 color2 = texture2D(coverTex, vUv);
  1323. float rotio = smoothstep(radiusIn ,radiusOut,radius);
  1324. gl_FragColor = mix(color1, color2, rotio);
  1325. }
  1326. }
  1327. `
  1328. })
  1329. }
  1330. }
  1331. Object.assign(Manage.prototype, THREE.EventDispatcher.prototype)
  1332. THREE.Quaternion.prototype.angleTo = function (q) {
  1333. return 2 * Math.acos(Math.abs(THREE.Math.clamp(this.dot(q), -1, 1)))
  1334. }
  1335. let labels = []
  1336. class Label2D extends THREE.EventDispatcher {
  1337. constructor(o = {}) {
  1338. super()
  1339. this.position = o.position
  1340. this.elem = $(o.innerHTML || '<div ><a></a></div>')
  1341. $(o.domElement).append(this.elem)
  1342. this.pos2d = new THREE.Vector3()
  1343. this.elem.css({ position: 'absolute', 'z-index': 999 })
  1344. this.clickFun = o.clickFun
  1345. this.clickFun && this.elem.on('click', this.clickFun.bind(this))
  1346. if (o.autoUpdate) {
  1347. let update = e => {
  1348. if (e.cameraChanged) this.update()
  1349. }
  1350. player.on('view.changed', update) //确保player存在
  1351. this.addEventListener('dispose', e => {
  1352. player.removeListener('view.changed', update)
  1353. })
  1354. }
  1355. this.visible = true
  1356. this.shelterByModel = o.shelterByModel
  1357. this.floorIndex = o.floorIndex
  1358. labels.push(this)
  1359. if (window.player.model) {
  1360. this.init()
  1361. } else {
  1362. let f = () => {
  1363. window.bus.removeEventListener('playerAndModelReady', f)
  1364. this.init()
  1365. }
  1366. window.bus.addEventListener('playerAndModelReady', f)
  1367. }
  1368. }
  1369. init() {
  1370. if (this.floorIndex != void 0) {
  1371. player.model.on('floor.changed', (currentFloor, mode, oldFloor) => {
  1372. this.update(currentFloor) //注: currentFloor 这时候还没成为 model.currentFloor
  1373. })
  1374. }
  1375. }
  1376. update(currentFloor) {
  1377. if (!this.position) return
  1378. if (!this.visible && this.unvisibleReasons.some(e => e.level == 1) && !this.unvisibleReasons.some(e => e.level > 1)) return
  1379. /*
  1380. 规定一下level共四层
  1381. level3 是notTrueSide层,权重最高。
  1382. level2 是强制可见层,如editSelected
  1383. level1 是强制不可见,如isPanorama
  1384. level0 是shelter层
  1385. 其中当visible==false时, 若导致不可见的原因是level1 代表不需要计算直接return, 否则还是要执行update 以计算更新可见性
  1386. 所以外部写的setVisible的level必须>0
  1387. */
  1388. var p = convertTool.getPos2d(this.position)
  1389. if (!p || !p.trueSide) {
  1390. return this.setVisible(false, 'notTrueSide', 3, null, true)
  1391. //this.elem.css('display','none'); return;
  1392. }
  1393. this.setVisible(true, 'notTrueSide', 3, null, true)
  1394. this.setVisible(true, 'shelter', 0, null, true)
  1395. //判断label是否被模型遮挡,遮挡则消失(如果是漫游模式最好提前计算visiblePanos)
  1396. if (player.mode != 'panorama') {
  1397. currentFloor = currentFloor || player.model.currentFloor
  1398. if (!player.model.allFloorsVisible && this.floorIndex != void 0 && this.floorIndex != currentFloor.floorIndex) {
  1399. this.setVisible(false, 'shelter', 0, null, true)
  1400. //this.elem.css('display','none'); return;
  1401. if (!this.visible) return
  1402. }
  1403. if (this.shelterByModel && convertTool.ifShelter(this.position, p.vector, player.camera, this.floorIndex)) {
  1404. //this.elem.css('display','none'); return;
  1405. this.setVisible(false, 'shelter', 0, null, true)
  1406. if (!this.visible) return
  1407. }
  1408. }
  1409. this.elem.css({
  1410. left: p.pos.x + 'px',
  1411. top: p.pos.y + 'px'
  1412. })
  1413. /* if(settings.vrEnabled){
  1414. this.elem.css({transform:'rotate('+window.screenFaceOrient+'deg)'})
  1415. }else{
  1416. this.elem.css({transform:''})
  1417. } */
  1418. //this.elem.css('display','block');
  1419. this.pos2d = p.vector
  1420. }
  1421. setVisible(visi, reason, level = 1, type, updating) {
  1422. let visiOld = this.visible
  1423. convertTool.updateVisible(this, reason, visi, level, type)
  1424. updating || this.update() //再次更新可见性并计算位置
  1425. this.elem.css('display', this.visible ? 'block' : 'none')
  1426. /* if(!this.visible){
  1427. this.elem.css('display','none');
  1428. }else{
  1429. if(!visiOld){
  1430. updating || this.update()
  1431. this.elem.css('display','block');
  1432. }
  1433. } */
  1434. }
  1435. setPos(pos) {
  1436. this.position = pos
  1437. this.update()
  1438. }
  1439. dispose() {
  1440. this.elem.remove()
  1441. this.dispatchEvent({ type: 'dispose' })
  1442. let index = labels.indexOf(this)
  1443. index > -1 && labels.splice(index, 1)
  1444. }
  1445. }
  1446. window.Label2D = Label2D
  1447. class RoomLabel extends Label2D {
  1448. constructor(o) {
  1449. if (o.position instanceof Array) o.position = new THREE.Vector3().fromArray(o.position)
  1450. o.innerHTML = `<div class="room-label" ><a><p><span>${o.title}</span></p></a></div>`
  1451. o.domElement = $('.widgets-doll-labels')[0]
  1452. ;(o.shelterByModel = true), (o.autoUpdate = true)
  1453. o.clickFun = () => {
  1454. if (player.roomLebelClickUnabled) return
  1455. let result = common.sortByScore(
  1456. player.model.floors.index[this.floorIndex].panos,
  1457. [],
  1458. [
  1459. pano => {
  1460. return -pano.position.distanceToSquared(this.position)
  1461. }
  1462. ]
  1463. )
  1464. let pano = result && result[0] && result[0].item
  1465. if (pano) {
  1466. const minDisSquard = 200
  1467. if (pano.position.distanceToSquared(this.position) > minDisSquard) {
  1468. pano = null
  1469. }
  1470. }
  1471. if (pano) {
  1472. player.flyToPano({
  1473. pano
  1474. })
  1475. } else {
  1476. player.focusPoint({ aim: this.position, radius: 20, dur: 1000 })
  1477. }
  1478. }
  1479. super(o)
  1480. this.setTitle(o.title)
  1481. }
  1482. init() {
  1483. super.init()
  1484. //飞入后不可见
  1485. player.on('mode.changing', (oldMode, mode, pano, duration) => {
  1486. //准备飞
  1487. this.setStyle(oldMode, mode, duration)
  1488. })
  1489. this.setStyle()
  1490. }
  1491. setStyle(oldMode, mode, duration) {
  1492. if (!mode) mode = player.modeTran.split('-')[1] || player.mode //要变成的mode或当前mode
  1493. if (mode == 'panorama') {
  1494. this.setVisible(false, 'isPanorama', 1)
  1495. } else if (oldMode == 'panorama') {
  1496. setTimeout(() => {
  1497. this.setVisible(true, 'isPanorama', 1)
  1498. }, duration * 0.7)
  1499. }
  1500. }
  1501. setTitle(title) {
  1502. this.title = title || ''
  1503. this.elem.html(`<a><p><span>${this.title}</span></p></a>`)
  1504. }
  1505. setEditSelect(state) {
  1506. //编辑页面用
  1507. this.editing = !!state
  1508. this.setVisible(state, 'editSelected', 2, state ? 'add' : 'cancel') //强制可见
  1509. }
  1510. }
  1511. window.RoomLabel = RoomLabel
  1512. class HistoryRecord extends THREE.EventDispatcher {
  1513. constructor(o) {
  1514. super()
  1515. this.undoList = []
  1516. this.redoList = []
  1517. this.applyData = o.applyData //应用数据的方法
  1518. this.getData = o.getData //获取数据的方法
  1519. this.dataBefore
  1520. window.addEventListener('keydown', e => {
  1521. if (e.keyCode == 90 && e.ctrlKey) {
  1522. //Z
  1523. this.undo()
  1524. } else if (e.keyCode == 89 && e.ctrlKey) {
  1525. //Y
  1526. this.redo()
  1527. }
  1528. })
  1529. }
  1530. undo() {
  1531. //回退
  1532. let length = this.undoList.length
  1533. if (length > 0) {
  1534. let unExist
  1535. let last = this.undoList.pop()
  1536. this.applyData && (unExist = !this.applyData(last.before))
  1537. unExist || this.redoList.push(last)
  1538. unExist && this.undo() //找不到就回退下一个。
  1539. this.dispatchEvent('undo')
  1540. //console.log('undo',last)
  1541. }
  1542. }
  1543. redo() {
  1544. //撤销回退
  1545. let length = this.undoList.length
  1546. let last = this.redoList.pop()
  1547. if (last) {
  1548. //注意:每行的顺序不能乱
  1549. this.undoList.push(last)
  1550. this.applyData && this.applyData(last.after)
  1551. this.dispatchEvent('redo')
  1552. //console.log('redo',last)
  1553. }
  1554. }
  1555. beforeChange(o) {
  1556. //在变化之前(可能执行好几次直到变化完,但只有第一次有效)。 o的内容完全根据getData怎么定义
  1557. if (!this.dataBefore) {
  1558. let data = this.getData(o)
  1559. data && (this.dataBefore = data)
  1560. }
  1561. }
  1562. afterChange(o) {
  1563. //变化结束,从beforeChange到此算一次操作。
  1564. if (this.dataBefore) {
  1565. this.writeIn({ before: this.dataBefore, after: this.getData(o) }) //写入某物体变化前和变化后的状态
  1566. this.dataBefore = null
  1567. }
  1568. }
  1569. writeIn(data) {
  1570. this.redoList.length = 0 //一旦录入新的操作,就不允许undo了
  1571. this.undoList.push(data)
  1572. //console.log('新增undo', data)
  1573. }
  1574. clear() {
  1575. this.redoList.length = 0
  1576. this.undoList.length = 0
  1577. this.dataBefore = null
  1578. }
  1579. }
  1580. window.HistoryRecord = HistoryRecord
  1581. let planeGeo = new THREE.PlaneBufferGeometry(1, 1, 1, 1)
  1582. class TextSprite extends THREE.Object3D {
  1583. constructor(options = {}) {
  1584. super()
  1585. let map = new THREE.Texture()
  1586. this.root = options.root || this
  1587. this.sprite = new THREE.Mesh(
  1588. planeGeo,
  1589. new THREE.MeshBasicMaterial({
  1590. map,
  1591. color: 0xffffff,
  1592. transparent: true,
  1593. depthTest: false,
  1594. depthWrite: false
  1595. })
  1596. )
  1597. this.add(this.sprite)
  1598. this.sprite.renderOrder = options.renderOrder != void 0 ? options.renderOrder : 2
  1599. this.fontWeight = options.fontWeight == void 0 ? /* 'Bold' */ '' : options.fontWeight
  1600. this.rectBorderThick = options.rectBorderThick || 0
  1601. this.textBorderThick = options.textBorderThick || 0
  1602. this.fontface = 'Arial'
  1603. this.fontsize = options.fontsize || 16
  1604. this.textBorderColor = options.textBorderColor || { r: 0, g: 0, b: 0, a: 0.0 }
  1605. this.backgroundColor = options.backgroundColor || { r: 255, g: 255, b: 255, a: 1.0 }
  1606. this.textColor = options.textColor || { r: 0, g: 0, b: 0, a: 1.0 }
  1607. this.borderColor = options.borderColor || { r: 0, g: 0, b: 0, a: 0.0 }
  1608. this.borderRadius = options.borderRadius == void 0 ? 6 : options.borderRadius
  1609. this.margin = options.margin
  1610. this.textshadowColor = options.textshadowColor
  1611. this.name = options.name
  1612. this.sizeInfo = options.sizeInfo
  1613. this.addEventListener('dispose', this.dispose.bind(this))
  1614. this.fixOrient = options.fixOrient
  1615. this.events = {
  1616. updatePose: e => {
  1617. e.cameraChanged && this.updatePose()
  1618. }
  1619. }
  1620. player.on('view.changed', this.events.updatePose)
  1621. this.addEventListener('isVisible', e => {
  1622. if (e.visible) {
  1623. this.updatePose()
  1624. }
  1625. })
  1626. if (options.text != void 0) this.setText(options.text)
  1627. setTimeout(() => {
  1628. this.updatePose()
  1629. }, 1)
  1630. }
  1631. updatePose() {
  1632. //if (lastFrameChanged) this.needsUpdate = true
  1633. if (!common.realVisible(this) /* || !this.needsUpdate */) return
  1634. //this.needsUpdate = false
  1635. let camera = player.mode == 'floorplan' ? player.cameraControls.activeControl.camera : player.camera //floorplan 时要用到OrthographicCamera
  1636. if (!this.fixOrient) {
  1637. let parentQua = this.root.parent.getWorldQuaternion(new THREE.Quaternion())
  1638. this.root.quaternion.multiplyQuaternions(parentQua.inverse(), camera.quaternion) //乘上parentQua.invert()是为了中和掉父结点的qua,使只剩下camera.quaternion
  1639. }
  1640. if (this.sizeInfo) {
  1641. var s = convertTool.getScaleForConstantSize(
  1642. Object.assign({}, this.sizeInfo, {
  1643. farBound: player.mode == 'floorplan' ? this.sizeInfo.farBoundPlan || this.sizeInfo.farBound : this.sizeInfo.farBound,
  1644. position: this.root.getWorldPosition(new THREE.Vector3())
  1645. })
  1646. )
  1647. this.scale.set(s, s, s)
  1648. }
  1649. }
  1650. setText(text) {
  1651. if (this.text !== text) {
  1652. if (!(text instanceof Array)) {
  1653. this.text = [text + '']
  1654. } else this.text = text
  1655. this.updateTexture()
  1656. this.needsUpdate = true
  1657. }
  1658. }
  1659. setPos(pos) {
  1660. this.position.copy(pos)
  1661. this.needsUpdate = true //updatePose
  1662. }
  1663. setTextColor(color) {
  1664. this.textColor = color
  1665. this.updateTexture()
  1666. }
  1667. setBorderColor(color) {
  1668. this.borderColor = color
  1669. this.updateTexture()
  1670. }
  1671. setBackgroundColor(color) {
  1672. this.backgroundColor = color
  1673. this.updateTexture()
  1674. }
  1675. setVisible(v) {
  1676. this.visible = v
  1677. }
  1678. setUniforms(name, value) {
  1679. this.sprite.setUniforms(name, value)
  1680. }
  1681. updateTexture() {
  1682. let canvas = document.createElement('canvas')
  1683. let context = canvas.getContext('2d')
  1684. context.font = this.fontWeight + ' ' + this.fontsize + 'px ' + this.fontface
  1685. //context["font-weight"] = 100; //语法与 CSS font 属性相同。
  1686. // get size data (height depends only on font size)
  1687. //this.text = 'f 啊啊啊 jg'
  1688. let textMaxWidth = 0,
  1689. infos = []
  1690. for (let text of this.text) {
  1691. let metrics = context.measureText(text)
  1692. let textWidth = metrics.width
  1693. infos.push(metrics)
  1694. textMaxWidth = Math.max(textMaxWidth, textWidth)
  1695. }
  1696. let margin = this.margin || new THREE.Vector2(this.fontsize, Math.max(this.fontsize * 0.4, 10))
  1697. const lineSpace = (this.fontsize + margin.y) * 0.5
  1698. let spriteWidth = 2 * margin.x + textMaxWidth + 2 * this.rectBorderThick
  1699. let spriteHeight = 2 * margin.y + this.fontsize * this.text.length + 2 * this.rectBorderThick + lineSpace * (this.text.length - 1)
  1700. context.canvas.width = spriteWidth
  1701. context.canvas.height = spriteHeight
  1702. context.font = this.fontWeight + ' ' + this.fontsize + 'px ' + this.fontface
  1703. let expand = Math.max(1, Math.pow(this.fontsize / 12, 1.4)) // 针对英文大部分在baseLine之上所以降低一点,或者可以识别当不包含jgqp时才加这个值
  1704. //canvas原点在左上角
  1705. context.textBaseline = 'alphabetic' // "middle" //设置文字基线。当起点y设置为0时,只有该线以下的部分被绘制出来。middle时文字显示一半(但是对该字体所有字的一半,有的字是不一定显示一半的,尤其汉字),alphabetic时是英文字母的那条基线。
  1706. // border color
  1707. context.strokeStyle = 'rgba(' + this.borderColor.r + ',' + this.borderColor.g + ',' + this.borderColor.b + ',' + this.borderColor.a + ')'
  1708. context.lineWidth = this.rectBorderThick
  1709. // background color
  1710. context.fillStyle = 'rgba(' + this.backgroundColor.r + ',' + this.backgroundColor.g + ',' + this.backgroundColor.b + ',' + this.backgroundColor.a + ')'
  1711. this.roundRect(context, this.rectBorderThick / 2, this.rectBorderThick / 2, spriteWidth - this.rectBorderThick, spriteHeight - this.rectBorderThick, this.borderRadius)
  1712. context.fillStyle = 'rgba(' + this.textColor.r + ',' + this.textColor.g + ',' + this.textColor.b + ',' + this.textColor.a + ')'
  1713. let y = margin.y
  1714. for (let i = 0; i < this.text.length; i++) {
  1715. //let actualHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent // 当前文本字符串在这个字体下用的实际高度
  1716. //文字y向距离从textBaseline向上算
  1717. let actualBoundingBoxAscent = infos[i].actualBoundingBoxAscent == void 0 ? this.fontsize * 0.8 : infos[i].actualBoundingBoxAscent //有的流览器没有。只能大概给一个
  1718. y += actualBoundingBoxAscent + expand
  1719. //console.log(actualBoundingBoxAscent)
  1720. //console.log(this.text, 'y' , y, 'actualBoundingBoxAscent', metrics.actualBoundingBoxAscent,'expand',expand )
  1721. let textLeftSpace = (textMaxWidth - infos[i].width) / 2
  1722. let x = this.rectBorderThick + margin.x + textLeftSpace
  1723. // text color
  1724. if (this.textBorderThick) {
  1725. context.strokeStyle = 'rgba(' + this.textBorderColor.r + ',' + this.textBorderColor.g + ',' + this.textBorderColor.b + ',' + this.textBorderColor.a + ')'
  1726. context.lineWidth = this.textBorderThick
  1727. context.strokeText(this.text[i], x, y)
  1728. }
  1729. if (this.textshadowColor) {
  1730. context.shadowOffsetX = 0
  1731. context.shadowOffsetY = 0
  1732. context.shadowColor = this.textshadowColor
  1733. context.shadowBlur = 0.3 * this.fontsize
  1734. }
  1735. context.fillText(this.text[i], x, y)
  1736. y += lineSpace
  1737. }
  1738. let texture = new THREE.Texture(canvas)
  1739. texture.minFilter = THREE.LinearFilter
  1740. texture.magFilter = THREE.LinearFilter
  1741. texture.anisotropy = 4
  1742. texture.needsUpdate = true
  1743. //this.material.needsUpdate = true;
  1744. if (this.sprite.material.map) {
  1745. this.sprite.material.map.dispose()
  1746. }
  1747. this.sprite.material.map = texture
  1748. this.sprite.scale.set(spriteWidth * 0.01, spriteHeight * 0.01, 1.0)
  1749. }
  1750. roundRect(ctx, x, y, w, h, r) {
  1751. ctx.beginPath()
  1752. ctx.moveTo(x + r, y)
  1753. ctx.lineTo(x + w - r, y)
  1754. ctx.arcTo(x + w, y, x + w, y + r, r) //圆弧。前四个参数同quadraticCurveTo
  1755. //ctx.quadraticCurveTo(x + w, y, x + w, y + r); //二次贝塞尔曲线需要两个点。第一个点是用于二次贝塞尔计算中的控制点,第二个点是曲线的结束点。
  1756. ctx.lineTo(x + w, y + h - r)
  1757. ctx.arcTo(x + w, y + h, x + w - r, y + h, r)
  1758. ctx.lineTo(x + r, y + h)
  1759. ctx.arcTo(x, y + h, x, y + h - r, r)
  1760. ctx.lineTo(x, y + r)
  1761. ctx.arcTo(x, y, x + r, y, r)
  1762. ctx.closePath()
  1763. ctx.fill()
  1764. ctx.stroke()
  1765. }
  1766. dispose() {
  1767. this.sprite.material.map.dispose()
  1768. this.sprite.material.dispose()
  1769. this.parent && this.parent.remove(this)
  1770. this.sprite.dispatchEvent({ type: 'dispose' })
  1771. this._listeners = []
  1772. this.events.updatePos && player.removeEventListener('view.changed', this.events.updatePose)
  1773. }
  1774. }
  1775. window.TextSprite = TextSprite
  1776. /* class VideoPlayer extends THREE.EventDispatcher{
  1777. constructor(player) {
  1778. super()
  1779. this.instances = new Map()
  1780. this.isFlv = false
  1781. }
  1782. addVideo(src) {
  1783. let video = this._createVideo(src)
  1784. this.instances.set(src, video)
  1785. return video
  1786. }
  1787. getVideo(src) {
  1788. let video = this.instances.get(src)
  1789. if (!video) {
  1790. video = this.addVideo(src)
  1791. }
  1792. return video
  1793. }
  1794. _createVideo(src) {
  1795. let video = document.createElement('video')
  1796. video.setAttribute('crossOrigin', 'anonymous')
  1797. video.setAttribute('playsinline', 'true')
  1798. video.setAttribute('x5-playsinline', 'true')
  1799. video.setAttribute('webkit-playsinline', 'true')
  1800. video.setAttribute('x5-video-player-type', 'h5')
  1801. video.setAttribute('controls', 'true')
  1802. video.setAttribute('controlslist', 'nodownload')
  1803. video.setAttribute('preload', 'meta') //注意,src赋值就会自动加载, preload="meta" 只加载元数据,提高加载速度,否则一开始卡
  1804. video.autoplay = false
  1805. video.muted = true
  1806. video.loop = true
  1807. video.style.position = 'fixed'
  1808. video.style.left = '0'
  1809. video.style.top = '0'
  1810. video.style.zIndex = '1000'
  1811. video.style.width = '200px'
  1812. video.style.display = 'none'
  1813. //document.body.appendChild(video)
  1814. //video.style.display = browser.urlHasValue('debug') ? 'block' : 'none'
  1815. video.src = src
  1816. if(this.isFlv) this.attachFlv(video)
  1817. return video
  1818. }
  1819. attachFlv(video){ 四维看看的会把视频转码成flv和mp4存在服务器, 但是大场景不会,所以安卓(如vivo)加载不了。flv必须用flvjs播放,且苹果有的支持不了
  1820. if(video.flvjsPlayer)return
  1821. let player = flvjs.createPlayer({ type: 'flv', url: video.src }) //需要是flv格式才行
  1822. player.videoElement = video
  1823. player.attachMediaElement(video)
  1824. player.on(flvjs.Events.ERROR, this._onPlayerError.bind(this))
  1825. player.load()
  1826. video.flvjsPlayer = player;
  1827. }
  1828. _onPlayerError() {
  1829. console.warn('视频加载失败')
  1830. }
  1831. changeTypeToFlv(){
  1832. this.isFlv = true
  1833. for(let [key,value] of this.instances){
  1834. this.attachFlv(value)
  1835. }
  1836. }
  1837. } */
  1838. window.initRouteArrow = () => {
  1839. if (window.isEdit) return
  1840. if (!window.DATA.route?.data || Object.keys(window.DATA.route.data).length == 0) return
  1841. let { hide, gradualShow, opacityShine, data = {} } = window.DATA.route || {} //hide 默认是否隐藏,若隐藏也可以通过函数展示
  1842. let panos = player.model.panos
  1843. panos.routeNextMap = {} //下一个
  1844. panos.routePreMap = {} //上一个
  1845. panos.list.forEach((pano, i) => {
  1846. panos.routePreMap[pano.id] = []
  1847. panos.routeNextMap[pano.id] = data[pano.id] ? data[pano.id].map(id => panos.get(id)) : []
  1848. })
  1849. for (let panoId in data) {
  1850. data[panoId].forEach(id => {
  1851. panos.routePreMap[id].push(panos.get(panoId))
  1852. })
  1853. }
  1854. var arrowInfo = {
  1855. animateDur: 5000,
  1856. showDur: 1000,
  1857. minOpa: 0.2,
  1858. maxOpa: 0.5
  1859. }
  1860. let arrowTex = Texture.load('images/arrow.png')
  1861. arrowTex.anisotropy = 4
  1862. let arrowMat = new THREE.MeshBasicMaterial({
  1863. name: 'arrow',
  1864. transparent: true,
  1865. map: arrowTex,
  1866. side: 2,
  1867. opacity: arrowInfo.maxOpa,
  1868. //depthTest:false
  1869. depthWrite: false //防止和导览路线重叠闪烁
  1870. })
  1871. let mats = {
  1872. default: arrowMat,
  1873. fadeIn: arrowMat.clone()
  1874. }
  1875. mats.fadeIn.name = 'fadeInArrow'
  1876. let plane = new THREE.PlaneBufferGeometry(1, 1)
  1877. let arrows = new THREE.Object3D()
  1878. arrows.name = 'groundArrows'
  1879. player.model.add(arrows)
  1880. var createArrow = function (mat) {
  1881. var arrow = new THREE.Mesh(plane, mat)
  1882. arrow.name = 'arrow'
  1883. let s = 0.15
  1884. arrow.scale.set(s, s, s)
  1885. arrows.add(arrow)
  1886. return arrow
  1887. }
  1888. var updateArrowPose = function (from, to, mat) {
  1889. var vec = to.floorPosition.clone().clone().sub(from.floorPosition).setY(0)
  1890. let spaceDis = 0.4 //箭头之间的间距
  1891. let margin = 0.3 //marker端需要留一点距离
  1892. let sliceCount = Math.max(2, Math.round((vec.length() - margin) / spaceDis)) //分段
  1893. let arrowCount = sliceCount - 1
  1894. let dir = vec.clone().normalize()
  1895. let dir2d = new THREE.Vector2(dir.x, dir.z)
  1896. let angle = dir2d.angle() - Math.PI / 2
  1897. let sliceLen = (vec.length() - margin) / sliceCount
  1898. let i = arrowCount
  1899. while (i > 0) {
  1900. let pos = from.floorPosition.clone().add(dir.clone().multiplyScalar(margin / 2 + i * sliceLen))
  1901. pos.y += settings.markerHeight
  1902. let arrow = createArrow(mat)
  1903. arrow.name = 'arrow:' + from.id + '-' + to.id + '|' + i
  1904. arrow.rotation.set(Math.PI / 2, 0, angle)
  1905. arrow.position.copy(pos)
  1906. i--
  1907. }
  1908. }
  1909. var updateArrowOpacity = function (e) {
  1910. //不停更新所有arrow的透明度
  1911. var transition = function (a) {
  1912. if (!arrows.visible) return
  1913. var opa = a > 0.5 ? 2 - a * 2 : 2 * a
  1914. opa = arrowInfo.maxOpa * opa + arrowInfo.minOpa * (1 - opa)
  1915. mats.default.opacity = opa
  1916. mats.fadeIn.opacity = opa * mats.fadeIn.opacity2
  1917. }
  1918. transitions.start(transition, arrowInfo.animateDur, updateArrowOpacity, 0, easing.easeInOutCubic, 'updateArrowOpacity')
  1919. }
  1920. var fadeInArrow = function () {
  1921. transitions.cancelById('updateArrowOpacity2')
  1922. var arrows_ = arrows.children.filter(e => e.material == mats.fadeIn)
  1923. if (arrows_.length == 0) return
  1924. mats.fadeIn.opacity = 0
  1925. var transition = function (a) {
  1926. if (!opacityShine) mats.fadeIn.opacity = a * arrowInfo.maxOpa
  1927. else mats.fadeIn.opacity2 = a
  1928. }
  1929. transitions.start(
  1930. transition,
  1931. arrowInfo.showDur,
  1932. function done() {
  1933. arrows_.forEach(e => (e.material = mats.default))
  1934. },
  1935. 0,
  1936. easing.easeInOutCubic,
  1937. 'updateArrowOpacity',
  1938. 'updateArrowOpacity2'
  1939. )
  1940. }
  1941. var lastArrowPanos = []
  1942. var updateArrow = function () {
  1943. //根据当前pano更新
  1944. if (player.mode != 'panorama' || hide) {
  1945. //飞出
  1946. arrows.visible = false
  1947. lastArrowPanos = []
  1948. return
  1949. }
  1950. arrows.visible = true
  1951. let currentPano = player.currentPano
  1952. //先获取所有需要箭头的pano
  1953. var maxDistance = 6 //该距离内pano可见箭头
  1954. var maxPathCount = 8
  1955. var dis = 0
  1956. var curPano = currentPano
  1957. var panos_ = []
  1958. var getAngle = function (pano1, pano2) {
  1959. let dir = new THREE.Vector3().subVectors(pano1.position, pano2.position)
  1960. dir = new THREE.Vector2(dir.x, dir.z)
  1961. return dir.angle()
  1962. }
  1963. var search = function (pano, path = [pano], angles = []) {
  1964. //多分支搜寻
  1965. var neighbor = panos.routeNextMap[pano.id]
  1966. if (!neighbor || !neighbor.length) return //path.length>1 && console.log('branchPath',path);
  1967. neighbor.forEach(e => {
  1968. let branchPath = path.slice(),
  1969. angles_ = angles.slice()
  1970. if (panos_.find(arr => arr[0] == e)) return //console.log('不回头branchPath',branchPath); //不回头
  1971. dis = e.floorPosition.distanceTo(currentPano.floorPosition)
  1972. branchPath.push(e)
  1973. if (branchPath.length > 2) {
  1974. //不折回,否则感觉在面前饶了一圈回来很难看
  1975. let i = 0
  1976. while (i < branchPath.length - 1) {
  1977. //补全angles
  1978. if (angles_[i] == void 0) {
  1979. angles_[i] = getAngle(branchPath[i], branchPath[i + 1])
  1980. }
  1981. i++
  1982. }
  1983. let lastAngle = angles_[branchPath.length - 2] //getAngle(branchPath[i], e)
  1984. let reverse = angles_.find((angle, n) => {
  1985. let angleDiff = Math.abs((lastAngle - angle) % (Math.PI * 2)) //越远限制越大
  1986. let minDiff = math.linearClamp(branchPath.length, [3, 6], [0.2, 0.5])
  1987. if (Math.abs(angleDiff - Math.PI) < minDiff) {
  1988. //console.log('因为折回而提前结束', n, branchPath)
  1989. return true
  1990. }
  1991. })
  1992. if (reverse != void 0) {
  1993. return
  1994. }
  1995. }
  1996. if (branchPath.length < 3 || dis < maxDistance) {
  1997. panos_.push([pano, e])
  1998. search(e, branchPath, angles_)
  1999. } else {
  2000. //console.log('branchPath',branchPath)
  2001. }
  2002. })
  2003. }
  2004. //search(currentPano)
  2005. let disMap = new Map(),
  2006. cosMap = new Map()
  2007. let camDir = player.getDirection()
  2008. let neighbors = currentPano.neighbourUUIDs
  2009. .map(e => panos.get(e))
  2010. .filter(p => {
  2011. let dir = new THREE.Vector3().subVectors(p.position, currentPano.position)
  2012. let d = dir.lengthSq()
  2013. if (d < 15) {
  2014. //最大距离
  2015. disMap.set(p, d)
  2016. cosMap.set(p, dir.normalize().dot(camDir))
  2017. return true
  2018. }
  2019. })
  2020. .sort((a, b) => {
  2021. let score = disMap.get(a) - disMap.get(b)
  2022. score += (cosMap.get(b) - cosMap.get(a)) * 5
  2023. return score
  2024. }) //从近到远,尽量在前方
  2025. let seedPanos = [currentPano, ...neighbors] //如果没有从当前点出发的箭头,就展示隔壁点的(缺点是隔壁点可能是指向当前点的,原规则是不展示来的路径的,所以会有点奇怪。虽然也可以在search后剔除啦)
  2026. for (let seed of seedPanos) {
  2027. search(seed)
  2028. if (panos_.length != 0) {
  2029. break
  2030. }
  2031. }
  2032. arrows.children.slice().forEach(child => arrows.remove(child))
  2033. panos_.forEach((panoArr, i) => {
  2034. var isNew = !lastArrowPanos.find(e => e[0] == panoArr[0] && e[1] == panoArr[1]) //新出现的点 渐变出现
  2035. updateArrowPose(panoArr[0], panoArr[1], isNew ? mats.fadeIn : mats.default) //更新位置
  2036. })
  2037. fadeInArrow()
  2038. lastArrowPanos = panos_
  2039. }
  2040. let inited
  2041. let init = () => {
  2042. if (inited) return
  2043. if (gradualShow) {
  2044. player.on('flying.ended', updateArrow)
  2045. } else {
  2046. //展示全部
  2047. for (let id1 in panos.routeNextMap) {
  2048. for (let pano2 of panos.routeNextMap[id1]) {
  2049. updateArrowPose(panos.get(id1), pano2, mats.default)
  2050. }
  2051. }
  2052. player.on('mode.changed', () => {
  2053. if (hide) return
  2054. arrows.visible = player.mode == 'panorama'
  2055. })
  2056. }
  2057. opacityShine && updateArrowOpacity()
  2058. inited = true
  2059. }
  2060. {
  2061. //ui控制显示
  2062. let changeShow = e => {
  2063. hide = !e.show
  2064. e.show && init()
  2065. gradualShow ? updateArrow() : (arrows.visible = e.show)
  2066. }
  2067. player.on('changeArrowShow', changeShow)
  2068. changeShow({ show: !hide })
  2069. }
  2070. }
  2071. {
  2072. let f = () => {
  2073. window.bus.removeEventListener('playerAndModelReady', f)
  2074. player.on('mode.changing', (currentMode, mode, pano, duration) => {
  2075. let noLine = mode == 'floorplan'
  2076. if (noLine) {
  2077. $('.widgets-doll-labels').addClass('noLine').addClass('noCorner')
  2078. } else {
  2079. $('.widgets-doll-labels').removeClass('noLine').removeClass('noCorner')
  2080. }
  2081. })
  2082. player.on('view.changed', e => {
  2083. if (e.cameraChanged) {
  2084. //if(needUpdateZIndex){ //如果某个label显示时需要更新index的话,加个参数
  2085. let label_ = labels.filter(e => e.elem[0].style.display == 'block')
  2086. label_.sort((a, b) => b.pos2d.z - a.pos2d.z)
  2087. label_.forEach((e, index) => e.elem.css('z-index', index + 1000))
  2088. //}
  2089. }
  2090. })
  2091. player.model.hotGroup.children.length ? logSth() : player.on('gotHotAndStartload', logSth)
  2092. /* {//如果是flv格式的话
  2093. window.videoPlayer = new VideoPlayer()
  2094. if(browser.detectAndroidMobile()){//安卓常常播放不了
  2095. let scriptdom = document.querySelector('#flvJs')
  2096. if(scriptdom){
  2097. scriptdom.src = 'js/lib/flv.min.js'
  2098. scriptdom.onload = ()=>{
  2099. window.videoPlayer.changeTypeToFlv()
  2100. window.bus.dispatchEvent('VideoPlayerReady' )
  2101. //Hot.startLoad()
  2102. }
  2103. }
  2104. }
  2105. } */
  2106. initRouteArrow()
  2107. browser.urlHasValue('panoLabel') && player.model.panos.forEach(p => p.addLabel())
  2108. /* if(number == 'SG-LF0SeEdxWjv'){ //---如果要将其中一块chunk提取出来成为单独的floor(或说在该楼层隐藏)的话
  2109. let roof = new player.model.floors.list[0].constructor(player.model, 2);//放在第三层
  2110. roof.build()
  2111. roof.addChunk(player.model.floors.list[0].chunks[1])
  2112. player.model.floors.add(roof)
  2113. player.model.floors.list[0].chunks.splice(1,1)
  2114. } */
  2115. if (settings.extractFloor) {
  2116. let data = settings.extractFloor[number]
  2117. if (data) {
  2118. setTimeout(() => {
  2119. let roof = new player.model.floors.list[0].constructor(player.model, player.model.floors.length) //放在第三层 隐藏起来
  2120. roof.build()
  2121. player.model.floors.add(roof)
  2122. for (let i = 0; i < data.length; i++) {
  2123. let chunk = player.model.chunks[data[i]]
  2124. let oldFloor = chunk.parent
  2125. roof.addChunk(chunk)
  2126. let index = oldFloor.chunks.indexOf(chunk)
  2127. oldFloor.chunks.splice(index, 1)
  2128. }
  2129. }, 10)
  2130. }
  2131. }
  2132. {
  2133. //根据漫游点切换音频
  2134. let curAudio
  2135. let bgmObject = SoundManager.list.find(e => e.name == 'bgm')
  2136. let setCurBgm = pano => {
  2137. if (!window.DATA.panoAreas) return
  2138. let item = window.DATA.panoAreas.find(e => e.panos.some(a => a == pano.id))
  2139. let areaAudio = item?.audio && item.audio[1]
  2140. if (areaAudio != curAudio) {
  2141. let canPlay = !bgmObject.audio.paused || (bgmObject.canplay() && !(SoundManager.currentAudio && SoundManager.currentAudio != bgmObject && SoundManager.currentAudio.src)) //没有其他音频在播放的话就可以播 //!pl
  2142. SoundManager.setSrc('bgm', areaAudio || window.DATA.backgroundMusic, areaAudio ? item.name + ':' + item.audio[0] : '全局背景音')
  2143. curAudio = areaAudio
  2144. if (canPlay) {
  2145. SoundManager.play('bgm')
  2146. $('#volume').show()
  2147. }
  2148. if (areaAudio || window.DATA.backgroundMusic) {
  2149. $('#volume').show()
  2150. } else {
  2151. $('#volume').hide()
  2152. }
  2153. }
  2154. }
  2155. player.on('flying.ended', (a, b, pano, d) => {
  2156. pano && setCurBgm(pano)
  2157. })
  2158. manage.addEventListener('pauseSound', e => {
  2159. if (SoundManager.playHistory.length == 0 && e.object != bgmObject) {
  2160. //其他都停了的话
  2161. //console.log('SoundManager.playHistory.length == 0')
  2162. setCurBgm(player.currentPano)
  2163. }
  2164. })
  2165. player.currentPano && setCurBgm(player.currentPano)
  2166. /*player.on("view.changed",(e)=>{//位移和旋转时都要判断最近item
  2167. if(!player.director.highlightItem && e.cameraWorldMatrixChanged && !player.flying && !player.isWarping() ){
  2168. common.intervalTool.isWaiting('tourUpdateCurItem',()=>{
  2169. console.log('setCurrentItem')
  2170. player.director.setCurrentItem( player.director.findNearestItem(true,true) )
  2171. }, 521)
  2172. }
  2173. }) */
  2174. }
  2175. }
  2176. window.bus.addEventListener('playerAndModelReady', f) //player model currentPano都已有
  2177. }
  2178. window.bus.dispatchEvent({ type: 'THREE_inited' })
  2179. }
  2180. {
  2181. let infoPannel = $('<div id="alert" class="closed"><div name="content"></div><div class="close"></div></div>')
  2182. $('body').append(infoPannel)
  2183. let showDur
  2184. let close = () => {
  2185. infoPannel.addClass('closed')
  2186. clearTimeout(timer)
  2187. timer = null
  2188. }
  2189. let timer, currName //定时器
  2190. infoPannel.find('.close').on('click', close)
  2191. window.alertInfo = function (text, { dur, dontAutoClose, hideCloseBtn, name } = {}) {
  2192. if (timer) {
  2193. clearTimeout(timer)
  2194. }
  2195. infoPannel.find('[name=content]').html(text)
  2196. infoPannel.removeClass('closed')
  2197. if (hideCloseBtn) {
  2198. infoPannel.find('.close').addClass('hide')
  2199. } else {
  2200. infoPannel.find('.close').removeClass('hide')
  2201. }
  2202. showDur = dur || 1500 + Math.round(text.length * 20)
  2203. if (!dontAutoClose) {
  2204. timer = setTimeout(close, showDur)
  2205. }
  2206. currName = name
  2207. }
  2208. window.alertClose = function (name) {
  2209. if (currName == name) {
  2210. close()
  2211. }
  2212. }
  2213. }
  2214. //最好能知道应该播放到的currentTime
  2215. var SoundManager = {
  2216. //暂不支持同时播放
  2217. currentAudio: null, //当前正在播放list中的哪一个
  2218. enableSound: true, //是否允许有声音
  2219. playHistory: [], //被打断的加入播放历史
  2220. list: [], //同一级别可以互相打断 //暂时不做多级别
  2221. play: function (name, src, currentTime) {
  2222. var object = this.list.find(e => e.name == name)
  2223. if (object) {
  2224. if (this.currentAudio) {
  2225. this.pause(this.currentAudio.name, false, true)
  2226. }
  2227. {
  2228. //将当前要播放的播放历史中清除
  2229. let index = this.playHistory.indexOf(object)
  2230. if (index > -1) this.playHistory.splice(index, 1)
  2231. }
  2232. this.currentAudio = object
  2233. if (src) {
  2234. this.setSrc(name, src)
  2235. }
  2236. if (currentTime != void 0) {
  2237. object.audio.currentTime = currentTime
  2238. }
  2239. if (object.audio && object.src) {
  2240. object.audio.load() // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  2241. object.audio.play()
  2242. object.audio.paused || (object.callback && object.callback(true))
  2243. Log(name + ' 播放 ')
  2244. }
  2245. }
  2246. },
  2247. pause: function (name, autoReplayLast, isInterrupt) {
  2248. //需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放
  2249. var object = this.list.find(e => e.name == name)
  2250. if (object && this.currentAudio == object) {
  2251. this.currentAudio = null
  2252. if (object.audio) {
  2253. !object.audio.paused && Log(name + ' 中断音频 ' + '(' + common.getFileNameFromUrl(object.audio.src) + ')')
  2254. object.audio.pause()
  2255. object.callback && object.callback(false)
  2256. }
  2257. if (isInterrupt) {
  2258. //一般主动调用不需要加这个
  2259. this.playHistory.push(object) //如果是被中断的,加入播放历史,等待恢复播放
  2260. }
  2261. if (autoReplayLast) {
  2262. //播放之前的音频。它们是被打断过的。
  2263. while (this.playHistory.length) {
  2264. var last = this.playHistory.pop()
  2265. if (last.src && last.canplay(last.audio)) {
  2266. this.play(last.name)
  2267. }
  2268. }
  2269. }
  2270. manage.dispatchEvent({ type: 'pauseSound', object })
  2271. }
  2272. },
  2273. setSrc: function (name, src = '', desc = '') {
  2274. //不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接
  2275. var object = this.list.find(e => e.name == name)
  2276. object.src = src
  2277. object.audio.src = src
  2278. Log(`${object.name} ${desc} 设置src: ${src} `)
  2279. },
  2280. createAudio: function (object = {}) {
  2281. //name, level, canplay
  2282. if (!object.fake) {
  2283. object.audio = new Audio()
  2284. object.audio.loop = !!object.loop
  2285. //object.audio.autoplay = true;
  2286. object.audio.addEventListener('ended', () => {
  2287. if (object.loop) {
  2288. //循环
  2289. Log(`${object.name} 播放完毕,重新播放`)
  2290. object.audio.play()
  2291. } else {
  2292. this.pause(object.name, true) //停止后的后续处理
  2293. }
  2294. })
  2295. object.audio.oncanplaythrough = () => {
  2296. //Log(`${object.name} canplaythrough `)
  2297. }
  2298. }
  2299. this.list.push(object)
  2300. },
  2301. initAutoPlay: function () {
  2302. //处理设备自动播放限制
  2303. let play = function () {
  2304. if (this.currentAudio && this.currentAudio.audio && this.currentAudio.src && this.currentAudio.audio.paused) {
  2305. this.currentAudio.audio.play() //一般触屏了都会播放成功,就不识别paused了
  2306. this.currentAudio.callback && this.currentAudio.callback(true)
  2307. Log(`${this.currentAudio.name} 自动播放`) //即使设置src在这之后好像也能成功播放
  2308. } else {
  2309. }
  2310. document.removeEventListener('touchstart', play)
  2311. document.removeEventListener('click', play)
  2312. $('#player')[0].removeEventListener('touchstart', play)
  2313. }.bind(this)
  2314. document.addEventListener('WeixinJSBridgeReady', play, false)
  2315. document.addEventListener('touchstart', play) //ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  2316. document.addEventListener('click', play)
  2317. $('#player')[0].addEventListener('touchstart', play)
  2318. }
  2319. }
  2320. function Log(value, color, fontSize) {
  2321. color = color || '#13f'
  2322. fontSize = fontSize || 14
  2323. console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`)
  2324. }
  2325. Manage.prototype.loadAudio = function () {
  2326. //相关:g_tourAudio \ g_playAudio
  2327. //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能
  2328. //box视频都静音,所以暂时不考虑
  2329. SoundManager.createAudio({
  2330. name: 'bgm',
  2331. level: 0,
  2332. src: '',
  2333. loop: true,
  2334. canplay: audio => {
  2335. return this.bgmShouldPlay
  2336. },
  2337. callback: state => {
  2338. //play或pause时随之触发的函数(即使还没开始播放)
  2339. if (state) {
  2340. $('#volume a img').attr('src', './images/Volume btn_off.png')
  2341. $('#volume').attr('title', '关闭声音')
  2342. } else {
  2343. $('#volume a img').attr('src', './images/Volume btn_on.png')
  2344. $('#volume').attr('title', '打开声音')
  2345. }
  2346. }
  2347. })
  2348. SoundManager.createAudio({
  2349. name: 'tour',
  2350. level: 1,
  2351. src: '',
  2352. loop: false,
  2353. canplay: audio => {
  2354. return player.director && player.director.tourIsPlaying && player.director.getAudio()
  2355. }
  2356. })
  2357. SoundManager.createAudio({
  2358. name: 'hot',
  2359. fake: true, //实际上没有audio. 只是为了来停止和续播其他音频
  2360. level: 2,
  2361. src: '',
  2362. loop: false,
  2363. canplay: audio => {}
  2364. })
  2365. /* SoundManager.createAudio({//区域bgm //暂定背景音乐按钮 同时控制整体和局部的播放。之后可能会改成仅单独控制bgm,或者分为两个按钮,需要再createAudio。
  2366. name:'pano',
  2367. level:1,
  2368. src:'',
  2369. loop:true,
  2370. canplay:(audio)=>{
  2371. return true
  2372. }
  2373. }) */
  2374. $('#volume')
  2375. .find('a')
  2376. .on('click', () => {
  2377. if ($('#volume img')[0].src.indexOf('btn_on.png') > -1) {
  2378. this.switchBgmState(true)
  2379. } else if ($('#volume img')[0].src.indexOf('btn_off.png') > -1) {
  2380. this.switchBgmState(false)
  2381. }
  2382. })
  2383. this.switchBgmState(true) //初始设置允许播放bgm
  2384. SoundManager.initAutoPlay()
  2385. }
  2386. Manage.prototype.switchBgmState = function (state) {
  2387. //按钮的状态完全代表是否应该播放bgm,即使还没加载完
  2388. this.bgmShouldPlay = state
  2389. if (state) {
  2390. SoundManager.play('bgm')
  2391. } else {
  2392. SoundManager.pause('bgm')
  2393. }
  2394. this.dispatchEvent && this.dispatchEvent({ type: 'switchBgmState' })
  2395. }
  2396. var manage = new Manage()
  2397. //处理cursor优先级
  2398. var CursorDeal = {
  2399. priorityEvent: [
  2400. //在前面的优先级高
  2401. { noIntersect: 'not-allowed' },
  2402. { addHot: 'cell' },
  2403. { hoverRouteLine: 'url(images/coordinateClose.png),auto' },
  2404. { hoverPano: 'pointer' },
  2405. { hoverFootIcon: 'pointer' },
  2406. { hoverHot: 'pointer' },
  2407. { addLabel: 'cell' },
  2408. { moveLabel: 'grab' }
  2409. ],
  2410. domElements: [$('#player')[0]],
  2411. list: [], //当前存在的cursor状态
  2412. currentCursorIndex: null,
  2413. /* init : function(viewer){
  2414. this.priorityEvent.forEach(e=>{//刚开始Potree.resourcePath没值,现在换
  2415. for(let i in e){
  2416. e[i] = Common.replaceAll(e[i],'{Potree.resourcePath}',Potree.resourcePath)
  2417. }
  2418. })
  2419. this.domElements = [viewer.renderArea, viewer.mapViewer.renderArea];
  2420. viewer.addEventListener("CursorChange",(e)=>{
  2421. if(e.action == 'add'){
  2422. this.add(e.name)
  2423. }else{
  2424. this.remove(e.name)
  2425. }
  2426. })
  2427. }, */
  2428. add: function (name) {
  2429. var priorityItem = this.priorityEvent.find(e => e[name])
  2430. if (!priorityItem) {
  2431. console.error('CursorDeal 未定义优先级 name:' + name)
  2432. return
  2433. }
  2434. if (!this.list.includes(name)) {
  2435. this.judge({ addItem: priorityItem, name })
  2436. this.list.push(name)
  2437. }
  2438. },
  2439. remove: function (name) {
  2440. var index = this.list.indexOf(name)
  2441. if (index > -1) {
  2442. this.list.splice(index, 1)
  2443. this.judge()
  2444. }
  2445. },
  2446. judge: function (o = {}) {
  2447. //console.log(o,this.list)
  2448. if (o.addItem) {
  2449. var addIndex = this.priorityEvent.indexOf(o.addItem)
  2450. if (addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0) {
  2451. this.domElements.forEach(e => (e.style.cursor = o.addItem[o.name]))
  2452. this.currentCursorIndex = addIndex
  2453. }
  2454. } else {
  2455. var levelMax = { index: Infinity, cursor: null }
  2456. this.list.forEach(name => {
  2457. var priorityItem = this.priorityEvent.find(e => e[name])
  2458. var index = this.priorityEvent.indexOf(priorityItem)
  2459. if (index < levelMax.index) {
  2460. levelMax.index = index
  2461. levelMax.cursor = priorityItem[name]
  2462. }
  2463. })
  2464. this.currentCursorIndex = levelMax.index
  2465. this.domElements.forEach(e => (e.style.cursor = levelMax.cursor || ''))
  2466. }
  2467. }
  2468. }
  2469. function logSth() {
  2470. let hotCount = player.model.hotGroup.children.length
  2471. let videoCount = player.model.hotGroup.children.filter(e => e.texType == 'video').length
  2472. let photoCount = player.model.hotGroup.children.filter(e => e.texType == 'photo').length
  2473. let shineCount = player.model.hotGroup.children.filter(e => e.texType == 'shine').length
  2474. let aniCount = player.model.hotGroup.children.filter(e => e.info.animateInfo).length
  2475. let objCount = player.model.hotGroup.children.filter(e => e.objObject).length
  2476. let chunkLen = player.model.chunks.length
  2477. let vertexC = player.model.chunks.reduce(function (total, chunk) {
  2478. return total + chunk.geometry.attributes.position.count
  2479. }, 0)
  2480. let panoCount = player.model.panos.list.length
  2481. Log(
  2482. `共有chunk个数 ${chunkLen} ( 顶点数 ${vertexC} )
  2483. 热点个数 ${hotCount} ( vedio ${videoCount} 个,photo ${photoCount} 个,shine ${shineCount}个。 gif ${aniCount} 个,obj ${objCount} 个
  2484. 漫游点数 ${panoCount} 个)`,
  2485. '#FF4399',
  2486. 14
  2487. )
  2488. }
  2489. /* let kankanNames = ['SG-','KJ-'] */
  2490. window.sceneFrom = (number.length > 6 && number.slice(0, 3).includes('-')) || browser.urlHasValue('kankan') ? 'kankan' : '' //看看or看见转来的
  2491. //兼容一代的場景
  2492. //請求地址統一管理
  2493. var g_onePregix = 'https://bigscene.4dage.com/' //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  2494. var g_version = manage.number('version')
  2495. g_version === 'one' ? (g_Prefix = g_onePregix) : ''