manage.js 90 KB

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