Hot.js 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888
  1. //合并热点和展览
  2. g_currentHot = null
  3. const playVideoWhenFlyOut = false
  4. //同时可播放的最大个数:
  5. const playVideoMax = window.isEdit ? 3 : browser.isMobile() ? 1 : 3
  6. const playAniMax = window.isEdit ? 6 : browser.isMobile() ? 3 : 5
  7. const playSyncGroup = [
  8. //需要播放同步的视频。 每次都单独定制
  9. // ['okh1UR466371', 'LGmLHP2615503' , 'VNyBI6614896'] //中,左,右 场景SHANGJJ
  10. ]
  11. window.initHot = function (model) {
  12. var objLoader = new THREE.OBJLoader()
  13. var _planeGeometry = new THREE.PlaneGeometry(1, 1)
  14. var _boxGeometry = new THREE.BoxBufferGeometry(1, 1, 1)
  15. {
  16. //ie的mesh 加了polygonOffset也是会重叠。所以去掉前面的face: (但是突然ie又播放不了videoTexture)
  17. var newIndex = [..._boxGeometry.index.array]
  18. newIndex.splice(4 * 6, 12)
  19. _boxGeometry.setIndex(new THREE.BufferAttribute(new Uint16Array(newIndex), 1))
  20. }
  21. var originPhotoCount = (photoLoaded = originModelCount = modelLoaded = 0)
  22. var defaultTex1 = Texture.load(g_HotImage.point)
  23. var defaultTex2 = Texture.load(g_HotImage.point2)
  24. dealMap(defaultTex1, { ignoreResize: true })
  25. dealMap(defaultTex2, { ignoreResize: true }) //这张图改为linear有黑边。 但即使不改,chrome调试手机版也有黑边和锯齿
  26. /* var _boxMat = new THREE.MeshBasicMaterial({
  27. color: "#eeeeee",
  28. transparent: !0,
  29. opacity: 0.8
  30. }) */
  31. var _boxMat = new THREE.MeshPhongMaterial({
  32. color: '#eeeeee',
  33. transparent: !0,
  34. opacity: 0.8,
  35. side: THREE.DoubleSide
  36. })
  37. var autoSizeInfo = /* {width2d:50}// */ { minSize: 120, maxSize: 600, nearBound: 1, farBound: 15 }
  38. var hotGroup = new THREE.Object3D()
  39. hotGroup.name = 'hotGroup'
  40. model.add(hotGroup)
  41. model.hotGroup = hotGroup
  42. var animateTexSrcs = {}
  43. var getLink = function (link) {
  44. var src = ''
  45. var r = link.substring(link.indexOf('html') + 4),
  46. o = 'en' == manage.number('lang') ? '&lang=' + manage.number('lang') : ''
  47. ;-1 == r.indexOf('?')
  48. ? (src = link + '?time=' + randomTime().getTime() + '&id=' + window.number + o)
  49. : (src = link + '&time=' + randomTime().getTime() + '&id=' + window.number + o)
  50. return src
  51. }
  52. var removeSrcPostMark = function (url) {
  53. //去除texture.load时自动加上的'?'
  54. var index = url.indexOf('?')
  55. if (index > -1) {
  56. return url.slice(0, index)
  57. } else return url
  58. }
  59. {
  60. //get plane Bound
  61. var planeBound = new THREE.Box3()
  62. var cornerPoint = [
  63. new THREE.Vector3(-0.5, 0.5, 0),
  64. new THREE.Vector3(0.5, 0.5, 0),
  65. new THREE.Vector3(0.5, -0.5, 0),
  66. new THREE.Vector3(-0.5, -0.5, 0)
  67. ]
  68. cornerPoint.forEach(e => {
  69. planeBound.expandByPoint(e)
  70. })
  71. }
  72. var shineMats = []
  73. var getShineMat = function (texture1, texture2) {
  74. var mat = shineMats.find(
  75. e => e.uniforms.texture1.value == texture1 && e.uniforms.texture2.value == texture2
  76. )
  77. if (mat) return mat
  78. else {
  79. var mat = new THREE.ShaderMaterial({
  80. uniforms: {
  81. opac: {
  82. type: 'f',
  83. value: 0
  84. },
  85. texture1: {
  86. type: 't',
  87. value: texture1
  88. },
  89. texture2: {
  90. type: 't',
  91. value: texture2
  92. }
  93. },
  94. vertexShader:
  95. 'varying vec2 vUv;\n\nvoid main() {\n\n vUv = uv ;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n}\n',
  96. fragmentShader:
  97. 'varying vec3 vNormal;\n\nvarying vec2 vUv;\n\nuniform float opac;\n\n uniform sampler2D texture1;\n\nuniform sampler2D texture2;\n\nvoid main() {\n\nvec4 tcolor1 = texture2D( texture1, vUv );\n\nvec4 tcolor2 = texture2D( texture2, vUv );\n\ngl_FragColor = mix(tcolor1,tcolor2 ,opac) + tcolor2*0.2; }\n',
  98. transparent: !0
  99. })
  100. shineMats.push(mat)
  101. return mat
  102. }
  103. }
  104. var modelGeos = []
  105. var getModelGeo = function (url) {
  106. var geo = modelGeos.find(e => (e.url = url))
  107. if (geo) return geo
  108. else {
  109. var geo = null
  110. geo.url = url
  111. }
  112. }
  113. class Hot extends THREE.Object3D {
  114. constructor(info, source) {
  115. super()
  116. this.sid = info.sid
  117. this.preDeal(info, source) // source:旧版来源
  118. this.info = info
  119. this.cornerPoints = []
  120. this.build(info)
  121. this.name = 'hot_' + this.sid
  122. model.hots[info.sid] = this
  123. }
  124. build(info) {
  125. hotGroup.add(this)
  126. this.setTitleElem()
  127. this.setFromInfo(info)
  128. }
  129. setFromInfo(info, media, objObject) {
  130. //1 恢复到编辑之前 2 初始加载
  131. var plane = this.plane
  132. /* var transformAtPanos = {}
  133. for(var i in info.transformAtPanos){
  134. transformAtPanos[i] = {//只保留一个位移,主要原因是大小变化和热点大小设置冲突了, isSprite和qutaernion衝突
  135. pos : info.transformAtPanos[i].pos && info.transformAtPanos[i].pos.clone(),
  136. //qua : info.transformAtPanos[i].qua && info.transformAtPanos[i].qua.clone(),
  137. }
  138. }
  139. this.transformAtPanos = transformAtPanos */
  140. //2024.3.18恢复transformAtPanos三个属性,isSprite优先级高于quaternion, 全局的热点大小改变不会影响当前有transformAtPanos的大小
  141. //在每个漫游点独立设置的position。
  142. var curPanoTransform = this.info.transformAtPanos[getTransformSid()] || {}
  143. //没有单独设置position的漫游点使用的position
  144. this.position.copy(curPanoTransform.pos || info.position)
  145. this.quaternion.copy(curPanoTransform.quaternion || info.quaternion)
  146. this.scale.copy(curPanoTransform.scale || info.scale)
  147. this.changeTexType(info.texType, media)
  148. if (!info.objSrc) {
  149. this.addPlane()
  150. if (!!this.hasBox != !!info.hasBox) {
  151. this.addBox(!this.hasBox)
  152. }
  153. } else {
  154. this.addModel(objObject || new THREE.Mesh()) //暂时创建个空的
  155. }
  156. this.updateMatrixWorld()
  157. /* if(!this.info.visiblePanos){//移到model.build时,在collider建好之后
  158. this.getVisiblePanos()
  159. } */
  160. {
  161. //gif
  162. if (this.animation) {
  163. GifTexDeal.remove(this.animation)
  164. }
  165. if (this.info.animateInfo && this.material_.map) {
  166. this.animation = GifTexDeal.addAnimation(
  167. this.material_.map,
  168. this,
  169. this.info.animateInfo,
  170. this.sid
  171. )
  172. this.visible && this.inSight() && GifTexDeal.start(this.animation)
  173. }
  174. }
  175. /* if(this.info.modelBound){
  176. this.mesh.updateMatrixWorld()
  177. this.mesh.boxHelper2 = new THREE.Box3Helper( new THREE.Box3().copy(this.info.modelBound.bound).applyMatrix4(this.mesh.matrixWorld), new THREE.Color("#00aaee"));
  178. model.add(this.mesh.boxHelper2)
  179. }else{
  180. var bound = new THREE.Box3()
  181. var cornerPoint = [
  182. new THREE.Vector3(-0.5, 0.5, 0),
  183. new THREE.Vector3(0.5, 0.5, 0),
  184. new THREE.Vector3(0.5, -0.5, 0),
  185. new THREE.Vector3(-0.5, -0.5, 0),
  186. ]
  187. cornerPoint.forEach(e=>{
  188. bound.expandByPoint(e)
  189. })
  190. this.mesh.updateMatrixWorld()
  191. this.mesh.boxHelper2 = new THREE.Box3Helper( bound.applyMatrix4(this.mesh.matrixWorld), new THREE.Color("#00aaee"));
  192. model.add(this.mesh.boxHelper2)
  193. } */
  194. }
  195. changeTexType(texType, media) {
  196. var plane = this.plane
  197. if (this.texType != texType || media == 'clear') {
  198. //删除旧的
  199. if (this.texType == 'shine') {
  200. /* this.material_.uniforms.texture1.value.dispose()
  201. this.material_.uniforms.texture2.value.dispose() */
  202. //为了恢复 不删
  203. } else {
  204. //this.material_.map.dispose()
  205. if (this.texType == 'video') {
  206. this.texMedia && this.texMedia.pause()
  207. } else {
  208. }
  209. }
  210. if (
  211. this.material_ &&
  212. !hotGroup.children.find(e => e != this && e.material_ == this.material_)
  213. ) {
  214. this.material_.dispose()
  215. }
  216. //添加新的
  217. if (texType == 'shine') {
  218. } else {
  219. this.changeMaterial(
  220. new THREE.MeshBasicMaterial({
  221. color: '#00c8af',
  222. opacity: 0.4,
  223. transparent: !0,
  224. polygonOffset: true,
  225. //是否开启多边形偏移 //ie不开启时blank也不会闪烁
  226. polygonOffsetFactor: -0.9,
  227. //多边形偏移因子
  228. polygonOffsetUnits: -4.0
  229. //多边形偏移单位
  230. })
  231. )
  232. if (texType == 'video') {
  233. } else {
  234. }
  235. }
  236. }
  237. this.texType = texType
  238. if (media == 'clear') {
  239. this.material_.opacity = 0.4
  240. this.texMedia = null
  241. return
  242. }
  243. if (texType == 'video') {
  244. //视频不能共用一个,否则会一起播放暂停
  245. var video
  246. if (media) {
  247. video = media
  248. } else {
  249. if (!this.info.texSrc) return
  250. var video = $(
  251. `<video controls="controls" loop x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload" preload="meta" ></video>`
  252. )[0]
  253. if (window.isEdit) video.src = manage.dealURL(this.info.texSrc) //注意,src赋值就会自动加载, preload="meta" 只加载元数据,提高加载速度,否则一开始卡
  254. /* let src = this.info.texSrc
  255. if(window.isEdit) src = manage.dealURL(src);
  256. var video = window.videoPlayer.getVideo(src)*/
  257. video.name = this.info.fileName
  258. }
  259. video.setAttribute('crossOrigin', 'Anonymous') //要在src设置好前解决跨域
  260. $(video).on('contextmenu', function () {
  261. return false
  262. }) //禁止右键点击出
  263. this.texMedia = video
  264. video.oncanplaythrough = e => {
  265. if (this.texMedia == video) {
  266. /* if(video.paused) */
  267. //console.log({str:'oncanplaythrough '+this.sid, level:1})
  268. //this.material_.map.needsUpdate = !0 //当初为何加这句?
  269. //this.update(player)
  270. }
  271. }
  272. /* video.onloadstart = (e)=> {
  273. console.log({str:'onloadstart '+this.sid, level:1})
  274. }
  275. video.onloadedmetadata = (e)=> {
  276. console.log({str:'onloadedmetadata '+this.sid, level:1})
  277. }
  278. video.onloadeddata = (e)=> {
  279. console.log({str:'onloadeddata '+this.sid, level:1})
  280. }
  281. video.oncanplay = (e)=> {
  282. console.log({str:'oncanplay '+this.sid, level:1})
  283. } */
  284. video.volume = 0
  285. video.muted = true
  286. video.currentTime = 0
  287. if (!window.isEdit) this.material_.opacity = 0.3
  288. this.material_.map = new THREE.VideoTexture(video)
  289. this.material_.map.wrapS = this.material_.map.wrapT = THREE.ClampToEdgeWrapping
  290. this.material_.map.generateMipmaps = true
  291. } else if (texType == 'photo') {
  292. if (media) {
  293. this.texMedia = media
  294. this.info.texSrc = media.src
  295. this.material_.map = new THREE.Texture() //texture也不能共用一个,因为有的会有动画,就不一样
  296. this.material_.map.image = media //image可以共用
  297. this.material_.map.needsUpdate = !0
  298. this.material_.opacity = 1
  299. } else {
  300. if (!this.info.texSrc) return
  301. this._loadDones = []
  302. this.material_.opacity = 0.1
  303. }
  304. } else if (texType == 'shine') {
  305. if (media) {
  306. this.changeShineTex(media)
  307. } else {
  308. this.styleImg = /* this.styleImg || */ []
  309. if (this.info.styleImg) {
  310. this.styleImg = this.info.styleImg.map(src => {
  311. return { src: /* manage.dealURL( */ src } //如果要dealURL,在predeal里
  312. })
  313. }
  314. this.changeShineTex(this.styleImg)
  315. }
  316. this.info.texSrc = null
  317. }
  318. if (this.material_.map) {
  319. /* this.material_.map.minFilter = THREE.LinearFilter;
  320. this.material_.map.magFilter = THREE.LinearFilter; */
  321. dealMap(this.material_.map)
  322. this.material_.color.set('#FFFFFF')
  323. this.material_.needsUpdate = true
  324. }
  325. }
  326. changeShineTex(styleImg) {
  327. styleImg = styleImg || this.styleImg
  328. var tex1, tex2
  329. if (styleImg.length) {
  330. tex1 = Texture.load(styleImg[0].src)
  331. tex2 = Texture.load((styleImg[1] && styleImg[1].src) || styleImg[0].src)
  332. dealMap(tex1, { ignoreResize: true })
  333. dealMap(tex2, { ignoreResize: true })
  334. } else {
  335. tex1 = defaultTex1
  336. tex2 = defaultTex2
  337. }
  338. this.changeMaterial(getShineMat(tex1, tex2))
  339. this.styleImg = styleImg
  340. this.info.styleImg = styleImg.map(img => img.src)
  341. }
  342. changeMaterial(mat) {
  343. this.material_ = mat
  344. this.mesh &&
  345. this.mesh.traverse(mesh => {
  346. if (mesh.material && !(mesh instanceof THREE.Box3Helper)) {
  347. mesh.material = this.material_
  348. }
  349. })
  350. }
  351. preDeal(info, source) {
  352. // source:来源
  353. var convertValue = function (v, Type) {
  354. var value
  355. if (v instanceof Array) {
  356. v.forEach(v1 => {
  357. v1 = parseFloat(v1)
  358. })
  359. value = new Type().fromArray(v)
  360. } else {
  361. if (!(v instanceof Type)) {
  362. for (let i in v) {
  363. v[i] = parseFloat(v[i])
  364. }
  365. value = new Type().copy(v)
  366. } else {
  367. value = v
  368. }
  369. }
  370. return value
  371. }
  372. if (!info.transformAtPanos) info.transformAtPanos = {}
  373. if (source == 'byHot') {
  374. var infoAttribute = info.infoAttribute || {}
  375. info.title = infoAttribute.title || info.title
  376. info.model = infoAttribute.model || info.model || [] //模型链接
  377. info.images = infoAttribute.images || info.images || []
  378. info.video = infoAttribute.video || info.video || []
  379. info.bgName = infoAttribute.bgName || info.bgName
  380. info.backgroundMusic = info.backgroundMusic || info.backgroundMusic
  381. info.iframe = infoAttribute.iframe || info.iframe || []
  382. info.styleImg = infoAttribute.styleImg || info.styleImg || []
  383. info.content = infoAttribute.content || info.content
  384. {
  385. let action = CloneObject(settings.hotClickEvent.shine)
  386. if (info.actionType == 'noAction' || info.noAction) {
  387. ;(action.examine = false), (action.openHot = false)
  388. } else if (info.actionType == 'dontExam') {
  389. action.examine = false
  390. }
  391. info.actionType = action
  392. }
  393. if (info.quaternion) {
  394. info.quaternion = convertValue(info.quaternion, THREE.Quaternion)
  395. } else {
  396. info.rotation = convertValue(info.rotation, THREE.Vector3)
  397. info.quaternion = new THREE.Quaternion().setFromEuler(
  398. new THREE.Euler().setFromVector3(info.rotation)
  399. ) //热点的旧数据很多是字符串
  400. }
  401. var s = Hot.getDefaulScale(info.hotIconScale) //旧版的大小,统一转换成新版
  402. info.scale = new THREE.Vector3(s, s, 0.02)
  403. delete info.infoAttribute
  404. /* for (let i in this.transformAtPanos) {
  405. info.transformAtPanos[i].pos = new THREE.Vector3().fromArray(info.transformAtPanos[i].pos)
  406. info.transformAtPanos[i].qua && (info.transformAtPanos[i].qua = new THREE.Quaternion().fromArray(info.transformAtPanos[i].qua))
  407. } */
  408. info.texType = 'shine'
  409. } else {
  410. if (source == 'byOverlay') {
  411. info.texType = info.media[0]
  412. //info.title = info.texType == 'video'?'视频':'图片'
  413. info.texSrc = info.file
  414. info.actionType = CloneObject(settings.hotClickEvent[info.texType]) //给一个默认
  415. delete info.media
  416. info.quaternion = convertValue(info.qua, THREE.Quaternion)
  417. info.position = info.pos
  418. delete info.pos
  419. delete info.qua
  420. let a = info.texSrc.split('/')
  421. info.fileName = a.pop()
  422. info.scale = new THREE.Vector3(info.width, info.height, info.depth)
  423. delete info.width
  424. delete info.height
  425. delete info.depth
  426. delete info.file
  427. } else {
  428. info.quaternion = new THREE.Quaternion().setFromEuler(
  429. new THREE.Euler().fromArray(info.rotation)
  430. ) //.setFromVector3(info.rotation)
  431. }
  432. info.model = info.model || [] //模型链接
  433. info.images = info.images || []
  434. info.video = info.video || []
  435. info.iframe = info.iframe || []
  436. info.styleImg = info.styleImg || []
  437. info.imagesDesc = info.imagesDesc || []
  438. info.videosDesc = info.videosDesc || []
  439. info.titleShowType = info.titleShowType || 'hover'
  440. info.titlePos = info.titlePos || 'right'
  441. }
  442. if (info.texSrc) {
  443. info.texSrc = manage.removeSrcPostMark(info.texSrc)
  444. }
  445. //whole:
  446. //为了兼容旧数据,尽量和hot的数据靠近,最后保存在hot里
  447. info.position = convertValue(info.position, THREE.Vector3)
  448. info.scale = convertValue(info.scale, THREE.Vector3)
  449. delete info.rotation //暂时不用,只有保存时才存为roration
  450. info.linkType = info.linkType || 'common'
  451. for (let i in info.transformAtPanos) {
  452. info.transformAtPanos[i].pos = new THREE.Vector3().fromArray(info.transformAtPanos[i].pos)
  453. info.transformAtPanos[i].qua &&
  454. (info.transformAtPanos[i].qua = new THREE.Quaternion().fromArray(
  455. info.transformAtPanos[i].qua
  456. ))
  457. info.transformAtPanos[i].scale &&
  458. (info.transformAtPanos[i].scale = new THREE.Vector3().fromArray(
  459. info.transformAtPanos[i].scale
  460. ))
  461. }
  462. }
  463. addBox(state) {
  464. if (state == !!this.hasBox) {
  465. return
  466. }
  467. if (state) {
  468. var box = new THREE.Mesh(_boxGeometry, _boxMat)
  469. box.position.set(0, 0, 1 / 2)
  470. box.renderOrder = 3
  471. this.plane.position.set(0, 0, 1)
  472. this.add(box)
  473. this.box = box
  474. } else {
  475. this.plane.position.set(0, 0, 0)
  476. this.remove(this.box)
  477. this.box = null
  478. }
  479. this.hasBox = this.info.hasBox = state
  480. }
  481. /* getSizeByScale() {
  482. return {
  483. width: settings.defaultOverlaySize[0] * this.scale.x,
  484. height: settings.defaultOverlaySize[1] * this.scale.y
  485. }
  486. }
  487. getScaleBySize(width, height) {
  488. return {
  489. x: width / settings.defaultOverlaySize[0],
  490. y: height / settings.defaultOverlaySize[1],
  491. }
  492. }*/
  493. setVisiblePanos(visibleData) {
  494. if (visibleData) this.info.visiblePanos = visibleData
  495. else if (!this.info.visiblePanos) this.getVisiblePanos()
  496. }
  497. getVisiblePanos() {
  498. //在不同点还不一样
  499. var depth = this.hasBox ? this.scale.z : 0
  500. var width = this.scale.x,
  501. height = this.scale.y
  502. var cornerPoint
  503. if (this.plane) {
  504. cornerPoint = [
  505. new THREE.Vector3(0, 0, depth),
  506. new THREE.Vector3(-width / 2, height / 2, depth),
  507. new THREE.Vector3(width / 2, height / 2, depth),
  508. new THREE.Vector3(width / 2, -height / 2, depth),
  509. new THREE.Vector3(-width / 2, -height / 2, depth)
  510. ]
  511. } else {
  512. var bound = new THREE.Box3().copy(this.info.modelBound.bound)
  513. var center = bound.center()
  514. cornerPoint = [
  515. new THREE.Vector3(center.x, center.y, center.z),
  516. new THREE.Vector3(bound.min.x, bound.min.y, bound.min.z),
  517. new THREE.Vector3(bound.min.x, bound.min.y, bound.max.z),
  518. new THREE.Vector3(bound.min.x, bound.max.y, bound.min.z),
  519. new THREE.Vector3(bound.max.x, bound.min.y, bound.min.z),
  520. new THREE.Vector3(bound.max.x, bound.max.y, bound.min.z),
  521. new THREE.Vector3(bound.max.x, bound.min.y, bound.max.z),
  522. new THREE.Vector3(bound.min.x, bound.max.y, bound.max.z),
  523. new THREE.Vector3(bound.max.x, bound.max.y, bound.max.z)
  524. ]
  525. }
  526. var getPos = position => {
  527. //每个overlay位置对应5个坐标,plane中心和四个角的位置
  528. if (this.plane) {
  529. return cornerPoint.map(e => {
  530. return e.clone().applyQuaternion(this.info.quaternion).add(position)
  531. })
  532. } else {
  533. var matrixWorld = new THREE.Matrix4().compose(position, this.quaternion, this.scale)
  534. matrixWorld.multiplyMatrices(matrixWorld, this.mesh.matrix)
  535. return cornerPoint.map(e => {
  536. return e.clone().applyMatrix4(matrixWorld)
  537. })
  538. }
  539. }
  540. this.info.visiblePanos = []
  541. var customPositions = getPos(this.info.position)
  542. var posAtPanos = {}
  543. for (let panoId in this.info.transformAtPanos) {
  544. if (panoId == 'outSide') continue
  545. posAtPanos[panoId] = getPos(this.info.transformAtPanos[panoId].pos)
  546. }
  547. let maxCount = browser.isMobile() ? 2000 : 5000
  548. let possiblePanos = model.panos.list
  549. if (this.plane) {
  550. //目前都是单面,所以只要可以看到的一面的热点
  551. let dir1 = new THREE.Vector3(0, 0, -1).applyQuaternion(this.quaternion).negate()
  552. possiblePanos = possiblePanos.filter(pano => {
  553. let dir2 = new THREE.Vector3().subVectors(pano.position, this.position).normalize()
  554. return dir1.dot(dir2) > 0
  555. })
  556. }
  557. let c = model.panos.list.length * model.colliders.length
  558. if (window.isEdit || c < maxCount) {
  559. //编辑页面保险起见还是全部算完后才可浏览,就能保证保存全部的visiblePano
  560. this.info.visiblePanos = common.getVisiblePano(customPositions, possiblePanos, {
  561. model: model.colliders,
  562. posAtPanos
  563. })
  564. } else {
  565. let start = 0
  566. let interval = setInterval(() => {
  567. let end = start + Hot.visiPanosCountSlice
  568. end = Math.min(end, possiblePanos.length)
  569. let i = start
  570. start = end
  571. let panos = possiblePanos.slice(i, end)
  572. this.info.visiblePanos = this.info.visiblePanos.concat(
  573. common.getVisiblePano(customPositions, panos, {
  574. model: model.colliders,
  575. posAtPanos
  576. })
  577. )
  578. if (end >= possiblePanos.length) {
  579. //console.log(window.hotsi ?(++window.hotsi): (window.hotsi = 1))
  580. clearInterval(interval)
  581. }
  582. }, Hot.visiEveryDurSlice) // visiEveryDurSlice 等在main中定义
  583. }
  584. }
  585. updateVisible(panos, visibility, type) {
  586. if (window.isEdit && editTool.hotpoint.editSpot == this) {
  587. return convertTool.updateVisible(this, 'visi', true)
  588. }
  589. let visible =
  590. visibility != void 0
  591. ? visibility
  592. : !this.info.visiblePanos ||
  593. (type == 'every'
  594. ? panos.every(pano => this.info.visiblePanos.includes(pano.id))
  595. : panos.some(pano => this.info.visiblePanos.includes(pano.id))) //type为every时,需要panos中每个都可见才显示
  596. convertTool.updateVisible(this, 'visi', visible)
  597. this.titleElem && this.titleElem.setVisible(this.visible, 'hotVisible', 1)
  598. if (this.texType == 'video') {
  599. //this.switchPlay(this.visible, this.visible ? null : 'stop' );//可见时不操作;不可见时停止
  600. this.update(player)
  601. }
  602. }
  603. getBoundOri() {
  604. let bound
  605. if (this.objObject) {
  606. bound = new THREE.Box3().copy(this.info.modelBound.bound)
  607. } else {
  608. bound = planeBound.clone()
  609. }
  610. return bound
  611. }
  612. getCornerPoint() {
  613. //获取在每个漫游点上的视觉边界点 可以打开boxHelper和addBall来观测是否准确
  614. if (this.cornerPoints[player.currentPano.id]) {
  615. return this.cornerPoints[player.currentPano.id]
  616. } else {
  617. var boundPoint, cornerPoint
  618. var center //中心点
  619. if (this.plane) {
  620. center = this.plane.getWorldPosition()
  621. boundPoint = [
  622. new THREE.Vector3(-0.5, 0.5, 0),
  623. new THREE.Vector3(0.5, 0.5, 0),
  624. new THREE.Vector3(0.5, -0.5, 0),
  625. new THREE.Vector3(-0.5, -0.5, 0)
  626. ]
  627. } else {
  628. var bound = new THREE.Box3().copy(this.info.modelBound.bound)
  629. boundPoint = [
  630. new THREE.Vector3(bound.min.x, bound.min.y, bound.min.z),
  631. new THREE.Vector3(bound.min.x, bound.min.y, bound.max.z),
  632. new THREE.Vector3(bound.min.x, bound.max.y, bound.min.z),
  633. new THREE.Vector3(bound.max.x, bound.min.y, bound.min.z),
  634. new THREE.Vector3(bound.max.x, bound.max.y, bound.min.z),
  635. new THREE.Vector3(bound.max.x, bound.min.y, bound.max.z),
  636. new THREE.Vector3(bound.min.x, bound.max.y, bound.max.z),
  637. new THREE.Vector3(bound.max.x, bound.max.y, bound.max.z)
  638. ]
  639. }
  640. var maxLon = -Infinity
  641. var minLon = +Infinity
  642. var maxLat = -Infinity
  643. var minLat = +Infinity
  644. var pos1 = player.currentPano.position.clone()
  645. center = this.position.clone() //模型bound的中心点已经位移到了hot中心点。 注意不能用getWorldPosition,得到的会是偏移的
  646. var dir = center.clone().sub(pos1).normalize()
  647. var centerDirInfo = {}
  648. player.cameraControls.controls.panorama.lookAt.call(centerDirInfo, null, dir)
  649. boundPoint.forEach(e => {
  650. //lon左右
  651. var point = e.applyMatrix4(this.mesh.matrixWorld)
  652. var dir = point.clone().sub(pos1).normalize()
  653. var dirInfo = {}
  654. player.cameraControls.controls.panorama.lookAt.call(dirInfo, null, dir)
  655. var diffLon = (dirInfo.lon - centerDirInfo.lon) % 360
  656. if (Math.abs(diffLon) > 180) {
  657. //因为有时需要根据符号判断是在中心的左边还是右边,所以限制在180内
  658. diffLon += diffLon > 0 ? -360 : 360
  659. }
  660. var diffLat = dirInfo.lat - centerDirInfo.lat
  661. maxLon = Math.max(diffLon, maxLon)
  662. minLon = Math.min(diffLon, minLon)
  663. maxLat = Math.max(diffLat, maxLat)
  664. minLat = Math.min(diffLat, minLat)
  665. })
  666. var diffLon = maxLon - minLon
  667. var diffLat = maxLat - minLat
  668. if (diffLat > 180) {
  669. //可能是到了反面。不好算,直接返回所有boundPoint
  670. cornerPoint = boundPoint
  671. } else {
  672. //读取lon lat的最大最小值,勾勒出一个没有倾斜的矩形 。它比boundPoint看起来范围更大些
  673. maxLon = maxLon + centerDirInfo.lon
  674. maxLat = maxLat + centerDirInfo.lat
  675. minLon = minLon + centerDirInfo.lon
  676. minLat = minLat + centerDirInfo.lat
  677. var dirs = [
  678. math.getDirByLonLat(maxLon, maxLat),
  679. math.getDirByLonLat(minLon, minLat),
  680. math.getDirByLonLat(maxLon, minLat),
  681. math.getDirByLonLat(minLon, maxLat)
  682. ]
  683. cornerPoint = dirs.map(e => {
  684. return e.clone().add(pos1)
  685. })
  686. cornerPoint = [center, ...cornerPoint] //最后增加一个中心点
  687. }
  688. /* if(this.objObject){
  689. cornerPoint = [pos2, ...cornerPoint]
  690. } */
  691. //addPoints(cornerPoint)
  692. this.cornerPoints[player.currentPano.id] = { cornerPoint, diffLon, diffLat }
  693. return this.cornerPoints[player.currentPano.id]
  694. }
  695. }
  696. getMediaSize() {
  697. let size = new THREE.Vector2()
  698. if (this.texMedia) {
  699. if (this.texType == 'photo') {
  700. size.x = this.texMedia.width
  701. size.y = this.texMedia.height
  702. //动画的话再变
  703. if (this.info.animateInfo) {
  704. size.x /= this.info.animateInfo.cellXcount
  705. size.y /= this.info.animateInfo.cellYcount
  706. }
  707. } else {
  708. size.x = this.texMedia.videoWidth || this.videoWidth
  709. size.y = this.texMedia.videoHeight || this.videoHeight
  710. }
  711. }
  712. return size
  713. }
  714. inSight() {
  715. //return true
  716. if (window.isEdit) return true // 太容易move了
  717. if (player.mode == 'panorama' && player.currentPano) {
  718. if (!player.camera) return
  719. var cornerPointInfo = this.getCornerPoint()
  720. var cornerPoint
  721. let min = new THREE.Vector2(5, 5)
  722. let scaleRatio = 1 / player.zoomLevel
  723. //根据media原始大小来调整阈值: media的原始大小能代表期望显示的大小,如果显示大小的远小于期望大小,就不显示(此时能感受到贴图锯齿严重,清晰度被浪费)。比如如果gif是一个很小的按钮,即使diffLon很小也要显示。缺点:需要用户根据所需上传合适清晰度的图。
  724. let size = this.getMediaSize()
  725. if (size.x > 0) {
  726. scaleRatio *= Math.sqrt(size.x * size.y) / 1000
  727. }
  728. min.multiplyScalar(scaleRatio)
  729. if (cornerPointInfo.diffLon < min.x || cornerPointInfo.diffLat < min.y) {
  730. //console.log('two far and small')
  731. return false
  732. }
  733. if (cornerPointInfo.diffLon < 15 && cornerPointInfo.diffLat < 15) {
  734. //当很小的时候,只判断中心点即可
  735. cornerPoint = [cornerPointInfo.cornerPoint[0]]
  736. } else {
  737. cornerPoint = cornerPointInfo.cornerPoint
  738. }
  739. for (let i = 0, j = cornerPoint.length; i < j; i++) {
  740. //只要有一点可见就算看见
  741. var pos2d = math.getPos2d(cornerPoint[i], player.camera, $('#player')[0])
  742. if (pos2d.trueSide && pos2d.inSight) return true
  743. }
  744. } else {
  745. //飞出 只判断在不在画面内
  746. //return playVideoWhenFlyOut//true
  747. let frustumMatrix = new THREE.Matrix4()
  748. frustumMatrix.multiplyMatrices(
  749. player.camera.projectionMatrix,
  750. player.camera.matrixWorldInverse
  751. )
  752. let frustum = new THREE.Frustum()
  753. frustum.setFromMatrix(frustumMatrix)
  754. let bound = this.getBoundOri()
  755. bound.applyMatrix4(this.matrixWorld)
  756. return frustum.intersectsBox(bound)
  757. }
  758. }
  759. update(player) {
  760. if (this.info.isSprite) {
  761. this.quaternion.copy(player.camera.quaternion)
  762. }
  763. this.updateScale()
  764. this.updateTitle()
  765. }
  766. updateScale(e, t) {
  767. //自适应调节大小
  768. if (!DATA.autoAdjustHotScale || this.texType != 'shine' || !this.plane) return
  769. var scale = convertTool.getScaleForConstantSize(
  770. $.extend({}, autoSizeInfo, {
  771. position: this.position.clone()
  772. })
  773. )
  774. this.plane.scale.set(scale, scale, scale)
  775. }
  776. switchPlay(state) {
  777. //手动播放暂停
  778. this.pausedByUser = !state
  779. this.videoControl(state)
  780. }
  781. loadVideo(video) {
  782. if (video.src_) return
  783. video.src = video.src_ = manage.dealURL(this.info.texSrc)
  784. }
  785. videoControl(state) {
  786. if (this.texType != 'video' || !this.material_.map) return
  787. var video = this.texMedia
  788. this.shouldPlay = state
  789. if (!state || state == 'stop') {
  790. if (!video.paused) {
  791. video.pause()
  792. //console.log({str: "paused " + this.sid, level:1})
  793. }
  794. /* video.lastCurTime = state == 'stop' ? 0 : video.currentTime //记录
  795. video.src = video.src_ = '' */
  796. if (state == 'stop') {
  797. video.currentTime = 0
  798. }
  799. } else if (state) {
  800. if (/* !isVideoPlayed(video) */ video.paused) {
  801. //console.log({str: 'videoControl play ' +", "+ this.sid, level:1})
  802. this.loadVideo(video)
  803. video.play()
  804. //video.currentTime = video.lastCurTime || 0
  805. this.changeOpaWhenPlay(video)
  806. //处理同步播放
  807. let group = playSyncGroup.find(e => e.includes(this.sid))
  808. if (group) {
  809. let others = group.filter(e => e != this.sid).map(e => player.model.hots[e].texMedia)
  810. //console.log('controlVideo play', this.id, 'other currentTime', others.map(e=>e.currentTime))
  811. video.currentTime = others[0].currentTime
  812. }
  813. //if(isVideoPlayed(video))console.log({str:"played " + this.sid + video.duration ,level:1})
  814. }
  815. }
  816. }
  817. changeOpaWhenPlay(video) {
  818. //当播放成功后,恢复为不透明
  819. if (isNaN(video.duration)) {
  820. //未加载好
  821. return setTimeout(() => {
  822. this.changeOpaWhenPlay(video)
  823. }, 100)
  824. }
  825. const minPlayedTime = Math.min(video.duration / 10, 0.1) //到这个时间说明加载成功
  826. if (!video.hasInitedOpacity) {
  827. setTimeout(e => {
  828. //console.log('trychangeOpa ',this.sid,video.currentTime)
  829. if (video.currentTime > minPlayedTime) {
  830. this.material_.opacity = 1
  831. video.hasInitedOpacity = true
  832. //console.log('changeOpaWhenPlay',this.sid)
  833. } else {
  834. if (!video.paused) {
  835. //再次尝试
  836. return setTimeout(() => {
  837. this.changeOpaWhenPlay(video)
  838. }, 500)
  839. }
  840. }
  841. }, minPlayedTime * 1000 + 500)
  842. }
  843. }
  844. /* setDefaultHotScale = function(){//设置成默认热点大小
  845. var w = DATA.hotIconScale) * g_HotMeshSize.g_HotMeshWidth
  846. this.scale.set( w, w, this.scale.z)
  847. } */
  848. setTitleElem() {
  849. var title = this.info.title
  850. if (title) {
  851. if (!this.titleElem) {
  852. this.titleElem = new Label2D({
  853. position: this.position,
  854. innerHTML: `<div>${title}</div>`,
  855. domElement: $('#hot')[0],
  856. shelterByModel: true
  857. })
  858. } else {
  859. this.titleElem.elem.html(`<div>${title}</div>`)
  860. }
  861. this.titleElem.setVisible(this.visible, 'hotVisible')
  862. this.setHoverState(false)
  863. this.setTitleDir()
  864. } else {
  865. if (this.titleElem) {
  866. this.titleElem.dispose()
  867. this.titleElem = null
  868. }
  869. }
  870. }
  871. setTitleDir() {
  872. this.titleElem && this.titleElem.elem.attr('pos', this.info.titlePos)
  873. }
  874. updateTitle() {
  875. this.titleElem && this.titleElem.update()
  876. }
  877. setHoverState(state) {
  878. if (!this.titleElem) return
  879. this.hovered = !!state
  880. var v =
  881. this.info.titleShowType != 'unvisible' &&
  882. (this.info.titleShowType == 'always' || this.hovered)
  883. this.titleElem.setVisible(v, 'hoveredVisi', 1)
  884. //this.updateTitle()
  885. }
  886. closestPanoTowardTag(e, t) {
  887. var i = [],
  888. n = [],
  889. r = this.mesh.getWorldPosition()
  890. if (e === 'panorama') {
  891. /* var o = t.position.clone().sub(r).normalize();
  892. n.push(function(t, i) {//scoreFunctions.direction 最好这个漫游点在currentPano到热点之间的路径上。但是这样的话可能就看不到热点正面,所以删掉
  893. return function(e) {
  894. return e.position.clone().sub(t).normalize().dot(i) * window._settings.navigation.directionFactor
  895. }}(r, o)
  896. ) */
  897. }
  898. var a = new THREE.Vector3()
  899. i.push(
  900. function (e) {
  901. return (
  902. Math.abs(e.position.x - r.x) > window._settings.tags.visibility.cameraClearance ||
  903. Math.abs(e.position.z - r.z) > window._settings.tags.visibility.cameraClearance
  904. )
  905. },
  906. function (e) {
  907. a.copy(r).sub(e.position)
  908. var t = -THREE.Math.radToDeg(Math.atan(a.y / Math.sqrt(a.x * a.x + a.z * a.z))),
  909. i = window._settings.tags.navigate.tiltTolerance
  910. return (
  911. window._settings.insideLookLimitDown - i < t &&
  912. t < window._settings.insideLookLimitUp + i
  913. )
  914. },
  915. pano => {
  916. // add
  917. return player.checkHasNeighbor(pano)
  918. },
  919. pano => {
  920. // add
  921. // 周恩光改 解决visiblePanos为undefined时的bug
  922. return !this.info.visiblePanos || this.info.visiblePanos.includes(pano.id)
  923. }
  924. )
  925. n.push(
  926. (function (hot, i) {
  927. //scoreFunctions.distanceSquared
  928. return function (pano) {
  929. //i = a.navigation.distanceFactor
  930. return hot ? hot.position.distanceToSquared(pano.position) * i : 0
  931. }
  932. })(this, -2),
  933. pano => {
  934. //尽量正对hot
  935. let dir = new THREE.Vector3(0, 0, 1).applyQuaternion(this.quaternion)
  936. let dir2 = new THREE.Vector3().subVectors(pano.position, this.position).normalize()
  937. let s = dir.dot(dir2) * 60
  938. //console.log(pano.id + ":" + s)
  939. return s
  940. }
  941. )
  942. /* var tanD = player.domElement.clientWidth / player.domElement.clientHeight * Math.tan((THREE.Math.degToRad(player.zoomFov/2))) ;
  943. var goodDistance = overlay.width / 2 / tanD;
  944. n.push(
  945. function (pano) { //寻找正对着overlay的pano
  946. var overlayDir = new THREE.Vector3(0,0,1).applyQuaternion(overlay.quaternion)
  947. var v1 = overlayDir//.setY(0); 朝上的话set0会得到0,0,0 无法求angle
  948. var v2 = pano.position.clone().sub(overlay.position)//.setY(0)
  949. var angle = v1.angleTo(v2)
  950. angles[pano.id] = angle;
  951. angle = -angle * 100
  952. return angle
  953. },
  954. function (pano) { //寻找正对着overlay的pano
  955. var dis = pano.position.clone().distanceToSquared(overlay.position)
  956. var goodDistance2 = goodDistance * Math.abs(Math.cos(angles[pano.id]))//考虑了倾斜角度后的最佳距离
  957. var result = - 300 * Math.abs(dis-goodDistance2) / goodDistance2 //dis和goodDistance2差距越大分数越低
  958. return result;
  959. }
  960. ) */
  961. var s = t.model.panos.sortByScore(i, n)
  962. //console.log(s)
  963. return s && 0 < s.length && s[0].item
  964. }
  965. examine(options = {}) {
  966. var openHot = this.info.link && this.info.actionType.openHot && !options.dontOpen
  967. var fastTran =
  968. !options.dontFastTran &&
  969. (this.info.actionType.fastTran || settings.hotFastTran || options.fastTran)
  970. if (fastTran) {
  971. //瞬间过渡 1到固定方位 2到和普通过渡一样的位置,也就是最适合的位置
  972. let info = this.info.cameraData
  973. if (info) {
  974. player.blackToPano({
  975. pano: player.model.panos.index[info.pano.uuid],
  976. quaternion: new THREE.Quaternion().fromArray(info.camera.quaternion)
  977. })
  978. }
  979. }
  980. var needExamine =
  981. !fastTran && (options.examine || (!settings.dontExamHot && this.info.actionType.examine))
  982. if (!openHot && !needExamine) return
  983. if (openHot && this.info.linkType != 'common' && this.info.iframe && this.info.iframe[0]) {
  984. var src = getLink(this.info.iframe[0])
  985. if (this.info.linkType == 'jumpLink') {
  986. var newPage = window.open(src, '_blank')
  987. newPage.focus()
  988. } else if (this.info.linkType == 'iframeDiv') {
  989. var div = document.createElement('div')
  990. div.style.position = 'fixed'
  991. div.style.width = div.style.height = '100%'
  992. div.style.left = div.style.top = '0'
  993. div.style['z-index'] = '999'
  994. var exit = document.createElement('div')
  995. exit.style['background-image'] = 'url(images/vrOffImg.png)'
  996. exit.style.position = 'absolute'
  997. exit.style.width = exit.style.height = '50px'
  998. exit.style.left = '17px'
  999. exit.style.top = '20px'
  1000. exit.style.cursor = 'pointer'
  1001. exit.style['background-repeat'] = 'no-repeat'
  1002. exit.style['background-size'] = '25%'
  1003. exit.style['background-position'] = 'center center'
  1004. exit.style['background-color'] = 'rgba(0, 0, 0, 0.2)'
  1005. exit.style['border-radius'] = '50%'
  1006. exit.style['z-index'] = '3'
  1007. exit.onclick = () => {
  1008. $(div).remove()
  1009. Hot.closePopup()
  1010. }
  1011. var myElement = document.createElement('iframe')
  1012. myElement.style.position = 'absolute'
  1013. myElement.style.width = myElement.style.height = '100%'
  1014. myElement.style.left = myElement.style.top = '0'
  1015. myElement.src = src
  1016. $('body').append(div)
  1017. div.appendChild(exit)
  1018. div.appendChild(myElement)
  1019. SoundManager.play('hot')
  1020. }
  1021. return
  1022. }
  1023. if (!player.currentPano) return
  1024. var popup = document.getElementById('popup')
  1025. if (openHot) {
  1026. ;(g_currentHot = this), (popup.style.display = 'block'), popup.classList.add('wait')
  1027. var n = document.createElement('iframe')
  1028. SoundManager.play('hot')
  1029. var src = getLink(this.info.link)
  1030. n.src = src
  1031. ;(n.id = 'id1'), (n.allowTransparency = 'true')
  1032. var a = document.getElementById('id1')
  1033. if (void 0 === a || null == a) {
  1034. document.querySelector('.popup-content').appendChild(n)
  1035. var s = !1
  1036. ;(window.loaddingSuccess = function () {
  1037. s = !0
  1038. }),
  1039. setTimeout(function e() {
  1040. if (s) {
  1041. var t = document.querySelector('#id1').contentWindow.document
  1042. t.querySelector('video') &&
  1043. (t.querySelector('video').play(),
  1044. !t.querySelector('video').paused &&
  1045. t.querySelector('.playPause') &&
  1046. t.querySelector('.playPause').classList.add('fa-pause')),
  1047. t.querySelector('audio') && t.querySelector('audio').play()
  1048. } else setTimeout(e, 300)
  1049. }, 800)
  1050. }
  1051. }
  1052. var done = function () {
  1053. player.flyingToTag = !1
  1054. openHot && popup.classList.remove('wait')
  1055. }
  1056. if (!needExamine) {
  1057. done()
  1058. return
  1059. }
  1060. var c = this.closestPanoTowardTag(player.mode, player.currentPano) || player.currentPano,
  1061. h = this.mesh.getWorldPosition()
  1062. player.flyingToTag = !0
  1063. if (player.mode === 'panorama') {
  1064. var d = {
  1065. pano: c,
  1066. lookAtPoint: h,
  1067. duration: options.duration,
  1068. maxDistanceOverride: null,
  1069. skipWarpingCheck: !1,
  1070. aimDuration: options.aimDuration
  1071. }
  1072. if (fastTran) {
  1073. let f = new THREE.Matrix4().lookAt(c.position, h, new THREE.Vector3(0, 1, 0))
  1074. let quaternion = new THREE.Quaternion().setFromRotationMatrix(f)
  1075. player.blackToPano({
  1076. pano: c,
  1077. quaternion
  1078. })
  1079. done()
  1080. } else {
  1081. player.flyToPano(d, done)
  1082. }
  1083. } else {
  1084. var p = {
  1085. pano: c
  1086. }
  1087. if (h) {
  1088. var f = new THREE.Matrix4().lookAt(c.position, h, new THREE.Vector3(0, 1, 0))
  1089. p.quaternion = new THREE.Quaternion().setFromRotationMatrix(f)
  1090. }
  1091. ;(p.callback = done),
  1092. (p.duration = options.duration || 1500),
  1093. (p.mode = 'panorama'),
  1094. (p.aimDuration = options.aimDuration)
  1095. player.flyToNewMode(p)
  1096. }
  1097. }
  1098. addModel(object) {
  1099. if (this.objObject) {
  1100. this.remove(this.objObject)
  1101. }
  1102. this.objObject = object
  1103. /* object.traverse((mesh)=>{
  1104. if(mesh.material && mesh.type == "hotSprite"){
  1105. mesh.material = this.material_;
  1106. }
  1107. }) */
  1108. object.name = this.info.objName
  1109. object.src = this.info.objSrc
  1110. this.info.hasBox = false
  1111. this.addBox(false)
  1112. this.remove(this.plane)
  1113. this.plane = null
  1114. this.setMesh(this.objObject)
  1115. //this.adjustModelAuto()
  1116. if (this.info.modelBound) {
  1117. //应该不会改变
  1118. var s = this.info.modelBound.scaleRatio
  1119. this.mesh.scale.set(s, s, s)
  1120. this.mesh.position.fromArray(this.info.modelBound.position)
  1121. this.mesh.modelBound = this.info.modelBound
  1122. }
  1123. this.material_.side = THREE.DoubleSide //模型单面的话不好校准位置
  1124. this.changeBoxHelperDisplay(false)
  1125. //this.mesh.boxHelper.visible = true
  1126. }
  1127. addPlane() {
  1128. //换成plane
  1129. if (this.plane) return
  1130. this.plane = new THREE.Mesh(_planeGeometry, this.material_)
  1131. this.remove(this.objObject)
  1132. this.objObject = null
  1133. delete this.info.objSrc
  1134. delete this.info.objName
  1135. delete this.info.modelBound
  1136. this.setMesh(this.plane)
  1137. this.material_.side = THREE.FrontSide //双面的话飞出来会看到热点悬空的
  1138. }
  1139. setMesh(mesh) {
  1140. this.mesh = mesh
  1141. this.add(this.mesh)
  1142. this.changeMaterial(this.material_) //re applyTo every mesh
  1143. this.mesh.traverse(mesh => {
  1144. mesh.type = 'hotSprite' //raycaster use
  1145. mesh.renderOrder = 3
  1146. })
  1147. if (!this.mesh.boxHelper) {
  1148. var boxHelper = this.mesh.children.find(e => e instanceof THREE.Box3Helper)
  1149. if (boxHelper) {
  1150. this.mesh.boxHelper = boxHelper
  1151. } else {
  1152. var bound = this.getBoundOri()
  1153. bound.expandByVector(new THREE.Vector3(0.0001, 0.0001, 0.0001))
  1154. this.mesh.boxHelper = new THREE.Box3Helper(bound, new THREE.Color('#00ffff'))
  1155. this.mesh.add(this.mesh.boxHelper)
  1156. this.mesh.boxHelper.material.depthTest = false
  1157. this.mesh.boxHelper.material.transparent = true
  1158. this.mesh.boxHelper.visible = false
  1159. }
  1160. }
  1161. }
  1162. changeBoxHelperDisplay(show) {
  1163. if (show) {
  1164. //暂时先把模型强制显示,以展示 boxHelper
  1165. convertTool.updateVisible(this, 'showBoxHelper', true, 2, 'add')
  1166. this.mesh.boxHelper.visible = true
  1167. } else {
  1168. convertTool.updateVisible(this, 'showBoxHelper', false, 2, 'cancel')
  1169. this.mesh.boxHelper.visible = false
  1170. }
  1171. }
  1172. /* addToLoadQueue() {
  1173. if (this.texType == 'photo') {
  1174. Hot.loadQueue.includes(this) || Hot.loadQueue.push(this)
  1175. }
  1176. } */
  1177. requestDownload(type, callback) {
  1178. var plane = this.plane
  1179. if (type == 'photo') {
  1180. if (this.photoHasRequestLoad || this.texType != 'photo') {
  1181. return //为什么之前1191需要在这加callback() 才能呢。现在又没事了
  1182. }
  1183. //console.log(' beginDownload : ' + this.sid)
  1184. /* this.material_.map = */ Texture.load(this.info.texSrc, tex => {
  1185. callback && callback()
  1186. if (!tex.image) {
  1187. return //只是单纯用了相同src的tex,但image仍未加载完
  1188. }
  1189. if (!this._loadDones) {
  1190. return
  1191. }
  1192. dealMap(tex)
  1193. setTimeout(Hot.loadNext, 50)
  1194. hotGroup.children.forEach(e => {
  1195. if (e.info.texSrc == this.info.texSrc && e.info.texType == type) {
  1196. e.material_.color.set('#FFFFFF')
  1197. e.material_.opacity = 1
  1198. //console.log('overlay loaded: ' + e.sid + " - " + this.info.texSrc.split('/').pop());
  1199. e.texMedia = tex.image
  1200. {
  1201. //animation不同致使的不能使用同一个texture
  1202. if (window.isEdit) {
  1203. if (animateTexSrcs[e.info.texSrc]) {
  1204. e.material_.map = tex.clone() //编辑动画直接不用一个texture, 故而animation也不同
  1205. e.material_.map.needsUpdate = true
  1206. } else {
  1207. e.material_.map = tex
  1208. animateTexSrcs[e.info.texSrc] = 1
  1209. }
  1210. } else {
  1211. if (animateTexSrcs[e.info.texSrc]) {
  1212. //已有该texSrc
  1213. let finded = false
  1214. for (let i of animateTexSrcs[e.info.texSrc]) {
  1215. if (ifSame(i[0], e.info.animateInfo)) {
  1216. e.material_.map = i[1]
  1217. finded = true
  1218. break
  1219. }
  1220. }
  1221. if (!finded) {
  1222. let tex_ = tex.clone()
  1223. tex_.needsUpdate = true //clone后不写这句会黑块
  1224. animateTexSrcs[e.info.texSrc].set(e.info.animateInfo, tex_)
  1225. e.material_.map = tex_
  1226. }
  1227. } else {
  1228. let object = new Map()
  1229. object.set(e.info.animateInfo, tex)
  1230. animateTexSrcs[e.info.texSrc] = object //注册第一个texSrc
  1231. e.material_.map = tex
  1232. }
  1233. }
  1234. }
  1235. if (e.info.animateInfo && !e.animation) {
  1236. e.animation = GifTexDeal.addAnimation(e.material_.map, e, e.info.animateInfo, e.sid)
  1237. e.visible && e.inSight() && GifTexDeal.start(e.animation)
  1238. }
  1239. if (++photoLoaded == originPhotoCount) {
  1240. //data2.js中的所有photo加载完毕
  1241. Hot.allPhotoLoaded = true
  1242. Hot.whenAllFileLoaded && Hot.allModelLoaded && Hot.whenAllFileLoaded()
  1243. }
  1244. {
  1245. e._loadDones.forEach(a => a())
  1246. e._loadDones = null
  1247. //e.photoHasRequestLoad = true //这句不能加,否则会无法执行callback
  1248. }
  1249. e.material_.needsUpdate = true
  1250. }
  1251. })
  1252. })
  1253. this.photoHasRequestLoad = true
  1254. } else if (type == 'model') {
  1255. if (this.modelHasRequestLoad || !this.info.objSrc) return
  1256. //需要处理重复?
  1257. objLoader.load(this.info.objSrc, object => {
  1258. this.remove(this.mesh)
  1259. this.addModel(object)
  1260. callback && callback()
  1261. if (++modelLoaded == originModelCount) {
  1262. //data2.js中的所有photo加载完毕
  1263. Hot.allModelLoaded = true
  1264. Hot.whenAllFileLoaded && Hot.allPhotoLoaded && Hot.whenAllFileLoaded()
  1265. }
  1266. })
  1267. this.modelHasRequestLoad = true
  1268. }
  1269. }
  1270. dispose() {
  1271. this.parent.remove(this)
  1272. this.titleElem && this.titleElem.dispose()
  1273. delete player.model.hots[this.sid]
  1274. }
  1275. }
  1276. Hot.updateVisibles = function (panos, type) {
  1277. //只显示没被遮挡的,否则会卡
  1278. if (panos === true) {
  1279. model.hotGroup.children.forEach(e => e.updateVisible(null, true, type))
  1280. } else {
  1281. model.hotGroup.children.forEach(e => e.updateVisible(panos, null, type))
  1282. }
  1283. }
  1284. Hot.beginShineHot = function () {
  1285. if (!window.isEdit && shineMats.length == 0) return
  1286. transitions.trigger({
  1287. func: function (e) {
  1288. var opa = e <= 0.5 ? 2 * e : -2 * e + 2
  1289. shineMats.forEach(mat => {
  1290. mat.uniforms.opac.value = opa
  1291. })
  1292. },
  1293. cycling: !0,
  1294. duration: 3e3,
  1295. name: 'hotShine'
  1296. })
  1297. }
  1298. Hot.getDefaulScale = function (hotIconScale) {
  1299. return (hotIconScale || DATA.hotIconScale) * g_HotMeshSize.g_HotMeshWidth
  1300. }
  1301. var loadings = []
  1302. Hot.loadQueue = [] //等待下载的overlay,目前只针对photo
  1303. Hot.maxLoadingCount = 3 //同时正在load图片的数量
  1304. Hot.loadNext = () => {
  1305. //继续requestDownload loadQueue中前排的item
  1306. let count = Hot.maxLoadingCount - loadings.length
  1307. Hot.loadQueue.slice(0, count).forEach(e => {
  1308. loadings.push(e)
  1309. //console.log('requestDownload', e.hot.info.texSrc)
  1310. e.hot.requestDownload(e.type, () => {
  1311. var i = loadings.indexOf(e)
  1312. //console.log('requestDownloaded index', i)
  1313. i > -1 && loadings.splice(i, 1)
  1314. })
  1315. })
  1316. Hot.loadQueue.splice(0, count)
  1317. }
  1318. Hot.getNeedLoad = function () {
  1319. //计算获取loadQueue,每次都重新计算,覆盖旧的
  1320. if (!player || !player.domElement || !player.mode) return
  1321. var hots1, hots2
  1322. if (player.mode != 'panorama') {
  1323. if (Hot.loadQueue.length == 0) {
  1324. hots1 = model.hotGroup.children.filter(e => e.texType == 'photo' && !e.photoHasRequestLoad)
  1325. hots2 = model.hotGroup.children.filter(e => e.info.objSrc && !e.modelHasRequestLoad)
  1326. Hot.loadQueue = hots1
  1327. .map(e => {
  1328. return { hot: e, type: 'photo' }
  1329. })
  1330. .concat(
  1331. hots2.map(e => {
  1332. return { hot: e, type: 'model' }
  1333. })
  1334. )
  1335. }
  1336. return
  1337. }
  1338. //Hot.loadWhenOutside = true
  1339. hots1 = model.hotGroup.children.filter(
  1340. e =>
  1341. e.texType == 'photo' &&
  1342. !e.photoHasRequestLoad &&
  1343. (!e.info.visiblePanos || e.info.visiblePanos.includes(player.currentPano.id))
  1344. )
  1345. hots2 = model.hotGroup.children.filter(
  1346. e =>
  1347. e.info.objSrc &&
  1348. !e.modelHasRequestLoad &&
  1349. (!e.info.visiblePanos || e.info.visiblePanos.includes(player.currentPano.id))
  1350. )
  1351. if (hots1.length + hots2.length == 0) {
  1352. hots1 = model.hotGroup.children.filter(e => e.texType == 'photo' && !e.photoHasRequestLoad)
  1353. hots2 = model.hotGroup.children.filter(e => e.info.objSrc && !e.modelHasRequestLoad)
  1354. }
  1355. var cameraDir = player.getDirection()
  1356. Hot.loadQueue = hots1
  1357. .map(e => {
  1358. return { hot: e, type: 'photo' }
  1359. })
  1360. .concat(
  1361. hots2.map(e => {
  1362. return { hot: e, type: 'model' }
  1363. })
  1364. )
  1365. var request = [
  1366. item => {
  1367. return true
  1368. }
  1369. ]
  1370. var rank = [
  1371. item => {
  1372. var dis = item.hot.mesh.getWorldPosition().distanceTo(player.position)
  1373. return -dis
  1374. },
  1375. item => {
  1376. var tagDir = item.hot.mesh.getWorldPosition().sub(player.position)
  1377. var angle = tagDir.angleTo(cameraDir)
  1378. return -angle * 20
  1379. }
  1380. ]
  1381. var result = common.sortByScore(Hot.loadQueue, request, rank)
  1382. //Hot.loadQueue = result ? result.slice(0, 5).map(e=>e.item) : model.hotGroup.children.filter(e=>e.texType == 'photo' && !e.hasRequestLoad).slice(0, 2);
  1383. Hot.loadQueue = result ? result.slice(0, 5).map(e => e.item) : []
  1384. }
  1385. Hot.load = () => {
  1386. //开始下载图片
  1387. Hot.getNeedLoad()
  1388. Hot.loadNext()
  1389. var hots1 = model.hotGroup.children.filter(e => e.texType == 'photo' && !e.photoHasRequestLoad)
  1390. var hots2 = model.hotGroup.children.filter(e => e.info.objSrc && !e.modelHasRequestLoad)
  1391. if (hots1.length + hots2.length > 0) {
  1392. setTimeout(Hot.load, 200)
  1393. } else {
  1394. Hot.allRequestLoad = true
  1395. console.log('allRequestLoad')
  1396. }
  1397. }
  1398. Hot.startLoad = () => {
  1399. originPhotoCount = hotGroup.children.filter(e => e.texType == 'photo').length
  1400. originModelCount = hotGroup.children.filter(e => !!e.info.objSrc).length
  1401. if (originPhotoCount == 0) Hot.allPhotoLoaded = true
  1402. if (originModelCount == 0) Hot.allModelLoaded = true
  1403. if (Hot.allModelLoaded && Hot.allPhotoLoaded)
  1404. Hot.whenAllFileLoaded && Hot.whenAllFileLoaded() //所有加载完毕
  1405. else {
  1406. Hot.load()
  1407. }
  1408. setTimeout(Hot.beginShineHot, 1000)
  1409. if (!window.isEdit) {
  1410. if (playSyncGroup.length) {
  1411. //每过一段时间校准同步视频的时间,使与第一个视频同步
  1412. setInterval(() => {
  1413. playSyncGroup.forEach(group => {
  1414. group = group.map(e => player.model.hots[e].texMedia).filter(e => !e.paused)
  1415. if (group.length < 2) return
  1416. //console.log('同步',group.map(e=>e.currentTime))
  1417. for (let i = group.length - 1; i > 0; i--) {
  1418. group[i].currentTime = group[0].currentTime
  1419. }
  1420. })
  1421. }, 4000)
  1422. }
  1423. }
  1424. player.emit('gotHotAndStartload')
  1425. }
  1426. window.Hot = Hot
  1427. /* var ball = new THREE.Mesh(new THREE.SphereBufferGeometry(0.01),new THREE.MeshBasicMaterial({color:"#f00",depthTest:false,transparent:true}))
  1428. var balls = []
  1429. var addPoint = function(point){
  1430. console.log(point)
  1431. var ball1 = ball.clone()
  1432. model.add(ball1);
  1433. ball1.position.copy(point)
  1434. balls.push(ball1)
  1435. }
  1436. var addPoints = function(points){
  1437. balls.forEach(e=>model.remove(e))
  1438. balls = []
  1439. points.forEach(e=>addPoint(e))
  1440. }
  1441. */
  1442. //判断是否是移动端,如果是给关闭按钮添加touchstart事件
  1443. Hot.closePopup = () => {
  1444. // 关闭热点页面
  1445. if (!g_currentHot) return
  1446. g_currentHot = null
  1447. var hotPop = document.getElementById('popup')
  1448. hotPop.style.display = 'none'
  1449. document.querySelector('.popup-content').removeChild(document.getElementById('id1'))
  1450. $('#popup iframe:last').remove()
  1451. SoundManager.pause('hot', true) //自动播放被中断的音频 (bgm
  1452. return false
  1453. }
  1454. if (browser.isMobile()) {
  1455. $('#closepop').on('touchstart', Hot.closePopup)
  1456. } else {
  1457. $('#closepop').on('click', Hot.closePopup)
  1458. }
  1459. Hot.createHotList = function () {
  1460. // 备注sg
  1461. // if(!window.DATA.showHotListSta)return
  1462. var docFragment = document.createDocumentFragment()
  1463. var hots = hotGroup.children.filter(hot => hot.info.actionType.openHot)
  1464. hots = hots.sort((a, b) => {
  1465. return a.order - b.order
  1466. })
  1467. window.myHotList = hots
  1468. hots.forEach(hot => {
  1469. var li = document.createElement('li')
  1470. var span = document.createElement('span')
  1471. span.innerHTML = hot.info.title || '热点'
  1472. // console.log(span.innerHTML);
  1473. li.hot = hot // 列表每一项对应一个热点
  1474. li.appendChild(span)
  1475. docFragment.appendChild(li)
  1476. })
  1477. setTimeout(() => {
  1478. var ul = document.querySelector('#hotListContent ul')
  1479. ul && ul.appendChild(docFragment)
  1480. }, 3000) //部分安卓手机的钉钉和支付宝浏览器如果立即添加到列表会卡住
  1481. }
  1482. Hot.mobileAutoPlay = function (player) {
  1483. //移动端。不这么写video不会播放 . (2022.11.29: 可为何加了Hot.updateHots之后又会自动播了?https有关?
  1484. if (browser.isMobile()) {
  1485. hotGroup.children.forEach(hot => {
  1486. /* if(hot.texType == 'video' && hot.shouldPlay){
  1487. console.log(1)
  1488. } */
  1489. if (
  1490. !hot.clickToPlayInited &&
  1491. hot.texType == 'video' &&
  1492. !isVideoPlayed(hot.texMedia) &&
  1493. hot.shouldPlay
  1494. ) {
  1495. //hot.update(player)
  1496. console.log({ str: 'try mobileAutoPlay ' + hot.sid, level: 1 })
  1497. hot.videoControl(true)
  1498. if (isVideoPlayed(hot.texMedia)) {
  1499. console.log({ str: 'clickToPlayInited ' + hot.sid, level: 1 })
  1500. hot.clickToPlayInited = true
  1501. hot.changeOpaWhenPlay(video)
  1502. }
  1503. }
  1504. })
  1505. }
  1506. }
  1507. Hot.updateHots = function () {
  1508. for (var i in player.model.hots) {
  1509. player.model.hots[i].update(player)
  1510. }
  1511. if (!player.ready) return
  1512. this.needUpdate = true
  1513. common.intervalTool.isWaiting(
  1514. 'updateHots',
  1515. () => {
  1516. //延时update,防止卡顿
  1517. if (!this.needUpdate) return
  1518. this.needUpdate = false
  1519. let videoCanPlay = [],
  1520. aniCanPlay = []
  1521. for (var i in player.model.hots) {
  1522. let hot = player.model.hots[i]
  1523. {
  1524. //实时监测播放
  1525. if (hot.texType == 'video' && !player.flying) {
  1526. //飞行时不判断
  1527. if (hot.visible && !hot.pausedByUser && hot.inSight()) {
  1528. //注意edit时insight一直为true
  1529. //this.videoControl(true)
  1530. videoCanPlay.push(hot)
  1531. } else {
  1532. hot.videoControl(false)
  1533. }
  1534. } else if (hot.info.animateInfo) {
  1535. if (hot.visible && hot.inSight()) {
  1536. aniCanPlay.push(hot)
  1537. } else {
  1538. GifTexDeal.stop(hot.animation)
  1539. }
  1540. }
  1541. }
  1542. }
  1543. let filter = (type, max, list, playFun) => {
  1544. if (list.length < max) {
  1545. list.forEach(hot =>
  1546. type == 'video' ? hot.videoControl(true) : GifTexDeal.start(hot.animation)
  1547. )
  1548. } else {
  1549. let playerDir = player.getDirection()
  1550. let request = []
  1551. let planeDir = new Map()
  1552. if (player.mode != 'panorama') {
  1553. request.push(hot => {
  1554. if (hot.plane) {
  1555. //考虑plane的方向,它甚至可能背对镜头
  1556. let dir = new THREE.Vector3(0, 0, -1).applyQuaternion(hot.quaternion)
  1557. let angle = dir.dot(playerDir)
  1558. planeDir.set(hot, angle)
  1559. return angle > 0
  1560. } else return true
  1561. })
  1562. }
  1563. let r = common.sortByScore(list, request, [
  1564. hot => {
  1565. //方向因素
  1566. var cornerPointInfo = hot.getCornerPoint() //仅支持漫游模式
  1567. let dir = new THREE.Vector3().subVectors(hot.position, player.position).normalize()
  1568. score = dir.dot(playerDir)
  1569. player.mode == 'panorama' && (score *= Math.pow(cornerPointInfo.diffLat, 0.5)) // pow降低高度的权重,因为宽度更重要些。之所以两个函数都乘以diffLat,也是为了防止在两个item的分数相同diffLon不同时,diffLat增长相同倍数却能造成分数差异的情况
  1570. return score
  1571. },
  1572. hot => {
  1573. //面积因素
  1574. if (player.mode == 'panorama') {
  1575. var cornerPointInfo = hot.getCornerPoint() //仅支持漫游模式
  1576. let area =
  1577. (cornerPointInfo.diffLon * Math.pow(cornerPointInfo.diffLat, 0.5)) / 1000 //占据面积
  1578. return area
  1579. } else {
  1580. let dis = player.position.distanceTo(hot.position)
  1581. let size =
  1582. hot
  1583. .getBoundOri()
  1584. .applyMatrix4(hot.matrixWorld)
  1585. .size(new THREE.Vector3())
  1586. .length() / 2
  1587. let score = Math.atan(size / Math.pow(dis, 1.2)) * 50 // 在镜头中所占fov angle 的一半 。 pow是因为实际感受还是尽量显示近处的
  1588. if (hot.plane) {
  1589. //考虑plane的方向,越倾斜分越低
  1590. score *= planeDir.get(hot)
  1591. }
  1592. return score
  1593. }
  1594. }
  1595. ])
  1596. //getCornerPoint仅支持漫游模式 Lat高度(纬度).
  1597. //console.log(r)
  1598. r &&
  1599. r.forEach((e, j) => {
  1600. let hot = e.item
  1601. if (j < max) {
  1602. type == 'video' ? hot.videoControl(true) : GifTexDeal.start(hot.animation)
  1603. } else {
  1604. type == 'video' ? hot.videoControl(false) : GifTexDeal.stop(hot.animation)
  1605. }
  1606. })
  1607. }
  1608. }
  1609. filter('video', playVideoMax, videoCanPlay)
  1610. filter('animateInfo', playAniMax, aniCanPlay)
  1611. //console.log('updateHots')
  1612. return true
  1613. },
  1614. 800
  1615. )
  1616. }
  1617. }
  1618. function isVideoPlayed(video) {
  1619. return !video.paused && !isNaN(video.duration) //注意,有的手机首次play时会立即paused为false,但其实没加载好, duration为NAN
  1620. }
  1621. /*
  1622. 保存 JSON.stringify(editTool.hotpoint.getSavingInfo())
  1623. 可能需要再写一份保存到overlay 给旧场景项目使用
  1624. 最好后台有针对手机版的做一个压缩。压缩成几个档位。
  1625. 安卓手机firefox出现过视频mesh不可见或者闪烁的情况。
  1626. 视频最容易导致崩溃, 模型还好
  1627. 数据速率为4064kbps,1920*1080px 时测试部门电脑崩溃
  1628. 数据速率为1824kbps,720 *576px 时正常
  1629. 所以尽量降到2000以下 同时播放个数最好不超过2个 可能需要将src归零 并延迟加载、不自动播放
  1630. 有遇到某张图在ios里显示不出,但在ps重新输出后就可以。这张图的dpi高达500,不知道是否与此有关。
  1631. 遇到过ios14.8.1、14.7.1 无法播放webm(来自1050)。 onloadedmetadata失败
  1632. 显示故障的机型:
  1633. 视频黑屏(4dkk视频漫游点也无法播放):小米10(自带浏览器)、红米K40(微信浏览器)、
  1634. */