Hot.js 64 KB

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