Hot.js 64 KB

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