Hot.js 64 KB

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