manage.js 95 KB

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