manage.js 91 KB

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