Hot.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747
  1. //合并热点和展览
  2. g_currentHot = null
  3. window.initHot = function (model) {
  4. var objLoader = new THREE.OBJLoader()
  5. var _planeGeometry = new THREE.PlaneGeometry(1, 1)
  6. var _boxGeometry = new THREE.BoxBufferGeometry(1, 1, 1)
  7. {//ie的mesh 加了polygonOffset也是会重叠。所以去掉前面的face: (但是突然ie又播放不了videoTexture)
  8. var newIndex = [..._boxGeometry.index.array]
  9. newIndex.splice(4 * 6, 12)
  10. _boxGeometry.setIndex(new THREE.BufferAttribute(new Uint16Array(newIndex), 1))
  11. }
  12. var originPhotoCount = photoLoaded = originModelCount = modelLoaded = 0
  13. var defaultTex1 = Texture.load(g_HotImage.point)
  14. var defaultTex2 = Texture.load(g_HotImage.point2)
  15. /* var _boxMat = new THREE.MeshBasicMaterial({
  16. color: "#eeeeee",
  17. transparent: !0,
  18. opacity: 0.8
  19. }) */
  20. var _boxMat = new THREE.MeshPhongMaterial({
  21. color: "#eeeeee",
  22. transparent: !0,
  23. opacity: 0.8,
  24. side: THREE.DoubleSide
  25. })
  26. var autoSizeInfo = { minSize: 120, maxSize: 600, nearBound: 1, farBound: 15 }
  27. var hotGroup = new THREE.Object3D; hotGroup.name = "hotGroup"
  28. model.add(hotGroup); model.hotGroup = hotGroup
  29. var animateTexSrcs = {}
  30. var getCommonHotspotUrl = function (link) {
  31. var querySectionInLink = link.split('?')[1]
  32. var langParam = "en" == manage.number("lang") ? "&lang=" + manage.number("lang") : ""
  33. // return `http://192.168.20.16:8082/#/${browser.isMobile() ? 'mobile' : 'web'}/?${querySectionInLink}&time=${randomTime().getTime()}&id=${window.number}${langParam}`
  34. return `/XuzhouHanStoneReliefArtMuseum/hotspot/index.html#/${browser.isMobile() ? 'mobile' : 'web'}/?${querySectionInLink}&time=${randomTime().getTime()}&id=${window.number}${langParam}`
  35. }
  36. var removeSrcPostMark = function (url) {//去除texture.load时自动加上的'?'
  37. var index = url.indexOf('?')
  38. if (index > -1) {
  39. return url.slice(0, index)
  40. } else return url
  41. }
  42. {//get plane Bound
  43. var planeBound = new THREE.Box3()
  44. var cornerPoint = [
  45. new THREE.Vector3(-0.5, 0.5, 0),
  46. new THREE.Vector3(0.5, 0.5, 0),
  47. new THREE.Vector3(0.5, -0.5, 0),
  48. new THREE.Vector3(-0.5, -0.5, 0),
  49. ]
  50. cornerPoint.forEach(e => {
  51. planeBound.expandByPoint(e)
  52. })
  53. }
  54. var shineMats = []
  55. var getShineMat = function (texture1, texture2) {
  56. var mat = shineMats.find(e => e.uniforms.texture1.value == texture1 && e.uniforms.texture2.value == texture2)
  57. if (mat) return mat
  58. else {
  59. var mat = new THREE.ShaderMaterial({
  60. uniforms: {
  61. color: {
  62. type: "c",
  63. value: new THREE.Color(16720384)
  64. },
  65. opac: {
  66. type: "f",
  67. value: 0
  68. },
  69. texture1: {
  70. type: "t",
  71. value: texture1
  72. },
  73. texture2: {
  74. type: "t",
  75. value: texture2
  76. }
  77. },
  78. vertexShader: "varying vec2 vUv;\n\nvoid main() {\n\n vUv = uv ;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n}\n",
  79. fragmentShader: "varying vec3 vNormal;\n\nvarying vec2 vUv;\n\nuniform float opac;\n\nuniform vec3 color;\n\nuniform 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"
  80. , transparent: !0
  81. })
  82. shineMats.push(mat)
  83. return mat
  84. }
  85. }
  86. var modelGeos = []
  87. var getModelGeo = function (url) {
  88. var geo = modelGeos.find(e => e.url = url)
  89. if (geo) return geo
  90. else {
  91. var geo = null
  92. geo.url = url
  93. }
  94. }
  95. class Hot extends THREE.Object3D {
  96. constructor(info, source) {
  97. super()
  98. this.sid = info.sid
  99. this.preDeal(info, source)// source:来源
  100. this.info = info
  101. this.cornerPoints = []
  102. this.build(info)
  103. this.name = "hot_" + this.sid
  104. model.hots[info.sid] = this
  105. }
  106. build(info) {
  107. /* this.changeMaterial(new THREE.MeshBasicMaterial({
  108. color: "#00c8af",
  109. opacity: 0.4,
  110. transparent: !0,
  111. polygonOffset: true,
  112. //是否开启多边形偏移 //ie不开启时blank也不会闪烁
  113. polygonOffsetFactor: -0.9,
  114. //多边形偏移因子
  115. polygonOffsetUnits: -4.0,
  116. //多边形偏移单位
  117. }))
  118. if(!info.objSrc){
  119. this.addPlane()
  120. if (info.hasBox) this.addBox(true)
  121. }else{
  122. this.addModel(new THREE.Mesh())//暂时创建个空的
  123. } */
  124. hotGroup.add(this)
  125. this.setTitleElem()
  126. this.setFromInfo(info)
  127. }
  128. setFromInfo(info, media, objObject) {
  129. //1 恢复到编辑之前 2 初始加载
  130. var plane = this.plane
  131. /* var transformAtPanos = {}
  132. for(var i in info.transformAtPanos){
  133. transformAtPanos[i] = {//只保留一个位移,主要原因是大小变化和热点大小设置冲突了, isSprite和qutaernion衝突
  134. pos : info.transformAtPanos[i].pos && info.transformAtPanos[i].pos.clone(),
  135. //qua : info.transformAtPanos[i].qua && info.transformAtPanos[i].qua.clone(),
  136. }
  137. }
  138. this.transformAtPanos = transformAtPanos */
  139. //在每个漫游点独立设置的position。
  140. var curPanoTransform = this.info.transformAtPanos[getTransformSid()] || {}
  141. //没有单独设置position的漫游点使用的position
  142. this.position.copy(curPanoTransform.pos || info.position)
  143. this.rotation.copy(info.rotation)
  144. this.scale.copy(info.scale)
  145. this.changeTexType(info.texType, media)
  146. if (!info.objSrc) {
  147. this.addPlane()
  148. if (!!this.hasBox != !!info.hasBox) {
  149. this.addBox(!this.hasBox)
  150. }
  151. } else {
  152. this.addModel(objObject || new THREE.Mesh())//暂时创建个空的
  153. }
  154. this.updateMatrixWorld()
  155. /* if(!this.info.visiblePanos){//移到model.build时,在collider建好之后
  156. this.getVisiblePanos()
  157. } */
  158. {//gif
  159. if (this.animation) {
  160. GifTexDeal.remove(this.animation)
  161. }
  162. if (this.info.animateInfo && this.material_.map) {
  163. this.animation = GifTexDeal.addAnimation(this.material_.map, this, this.info.animateInfo, this.sid)
  164. this.visible && this.inSight() && GifTexDeal.start(this.animation)
  165. }
  166. }
  167. /* if(this.info.modelBound){
  168. this.mesh.updateMatrixWorld()
  169. this.mesh.boxHelper2 = new THREE.Box3Helper( new THREE.Box3().copy(this.info.modelBound.bound).applyMatrix4(this.mesh.matrixWorld), new THREE.Color("#00aaee"));
  170. model.add(this.mesh.boxHelper2)
  171. }else{
  172. var bound = new THREE.Box3()
  173. var cornerPoint = [
  174. new THREE.Vector3(-0.5, 0.5, 0),
  175. new THREE.Vector3(0.5, 0.5, 0),
  176. new THREE.Vector3(0.5, -0.5, 0),
  177. new THREE.Vector3(-0.5, -0.5, 0),
  178. ]
  179. cornerPoint.forEach(e=>{
  180. bound.expandByPoint(e)
  181. })
  182. this.mesh.updateMatrixWorld()
  183. this.mesh.boxHelper2 = new THREE.Box3Helper( bound.applyMatrix4(this.mesh.matrixWorld), new THREE.Color("#00aaee"));
  184. model.add(this.mesh.boxHelper2)
  185. } */
  186. }
  187. changeTexType(texType, media) {
  188. var plane = this.plane
  189. if (this.texType != texType || media == 'clear') {
  190. //删除旧的
  191. if (this.texType == 'shine') {
  192. /* this.material_.uniforms.texture1.value.dispose()
  193. this.material_.uniforms.texture2.value.dispose() */ //为了恢复 不删
  194. } else {
  195. //this.material_.map.dispose()
  196. if (this.texType == 'video') {
  197. this.texMedia && this.texMedia.pause()
  198. } else {
  199. }
  200. }
  201. if (this.material_ && !hotGroup.children.find(e => e != this && e.material_ == this.material_)) {
  202. this.material_.dispose()
  203. }
  204. //添加新的
  205. if (texType == 'shine') {
  206. } else {
  207. this.changeMaterial(new THREE.MeshBasicMaterial({
  208. color: "#00c8af",
  209. opacity: 0.4,
  210. transparent: !0,
  211. polygonOffset: true,
  212. //是否开启多边形偏移 //ie不开启时blank也不会闪烁
  213. polygonOffsetFactor: -0.9,
  214. //多边形偏移因子
  215. polygonOffsetUnits: -4.0,
  216. //多边形偏移单位
  217. }))
  218. if (texType == 'video') {
  219. } else {
  220. }
  221. }
  222. }
  223. this.texType = texType
  224. if (media == 'clear') {
  225. this.material_.opacity = 0.4
  226. this.texMedia = null
  227. return
  228. }
  229. if (texType == 'video') {//视频不能共用一个,否则会一起播放暂停
  230. var video
  231. if (media) {
  232. video = media
  233. } else {
  234. if (!this.info.texSrc) return
  235. var video = $(`<video controls="controls" loop autoplay x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload"></video>`)[0]
  236. video.src = manage.dealURL(this.info.texSrc)
  237. video.name = this.info.fileName
  238. }
  239. video.setAttribute("crossOrigin", 'Anonymous')//要在src设置好前解决跨域
  240. $(video).on('contextmenu', function () {
  241. return false
  242. })//禁止右键点击出
  243. this.texMedia = video
  244. video.oncanplaythrough = () => {
  245. if (this.texMedia == video) {
  246. this.material_.map.needsUpdate = !0
  247. video.play()
  248. }
  249. }
  250. video.volume = 0
  251. video.muted = true
  252. video.currentTime = 0
  253. this.material_.map = new THREE.VideoTexture(video)
  254. this.material_.map.wrapS = this.material_.map.wrapT = THREE.ClampToEdgeWrapping
  255. this.material_.map.generateMipmaps = true
  256. } else if (texType == 'photo') {
  257. if (media) {
  258. this.texMedia = media
  259. this.info.texSrc = media.src
  260. this.material_.map = new THREE.Texture() //texture也不能共用一个,因为有的会有动画,就不一样
  261. this.material_.map.image = media //image可以共用
  262. this.material_.map.needsUpdate = !0
  263. } else {
  264. if (!this.info.texSrc) return
  265. this._loadDones = []
  266. this.material_.opacity = 0.1
  267. }
  268. } else if (texType == 'shine') {
  269. if (media) {
  270. this.changeShineTex(media)
  271. } else {
  272. this.styleImg = /* this.styleImg || */[]
  273. if (this.info.styleImg) {
  274. this.styleImg = this.info.styleImg.map((src) => {
  275. return { src: /* manage.dealURL( */src } //如果要dealURL,在predeal里
  276. })
  277. }
  278. this.changeShineTex(this.styleImg)
  279. }
  280. this.info.texSrc = null
  281. }
  282. if (this.material_.map) {
  283. /* this.material_.map.minFilter = THREE.LinearFilter;
  284. this.material_.map.magFilter = THREE.LinearFilter; */
  285. dealMap(this.material_.map)
  286. this.material_.color.set("#FFFFFF")
  287. this.material_.opacity = 1
  288. this.material_.needsUpdate = true
  289. }
  290. }
  291. changeShineTex(styleImg) {
  292. styleImg = styleImg || this.styleImg
  293. var tex1, tex2
  294. if (styleImg.length) {
  295. tex1 = Texture.load(styleImg[0].src)
  296. tex2 = Texture.load(styleImg[1] && styleImg[1].src || styleImg[0].src)
  297. } else {
  298. tex1 = defaultTex1
  299. tex2 = defaultTex2
  300. }
  301. this.changeMaterial(getShineMat(tex1, tex2))
  302. this.styleImg = styleImg
  303. this.info.styleImg = styleImg.map(img => img.src)
  304. }
  305. changeMaterial(mat) {
  306. this.material_ = mat
  307. this.mesh && this.mesh.traverse((mesh) => {
  308. if (mesh.material && !(mesh instanceof THREE.Box3Helper)) {
  309. mesh.material = this.material_
  310. }
  311. })
  312. }
  313. /*
  314. actionType: "common"
  315. infoAttribute: {images: [], styleImg: [], model: [], video: [], bgName: "background", iframe: [], title: "11",…}
  316. bgName: "background"
  317. content: "111"
  318. iframe: []
  319. images: []
  320. model: []
  321. styleImg: []
  322. title: "11"
  323. video: []
  324. isSprite: 0
  325. link: "https://www.4dmodel.com/SuperTwo/hot_online1/index.html#/?m=EDwn769489868"
  326. linkType: "common"
  327. noAction: 0
  328. order: 4
  329. position: {x: -4.238, y: 1.32, z: -0.648}
  330. rotation: {x: 0, y: 0.018105110200249575, z: 0}
  331. transformAtPanos: {}
  332. IO4Kq7494332: {actionTy
  333. depth: 0.08
  334. file: "https://super.4dage.com/data/TEST/edit/20200805_172635119.mp4"
  335. hasBox: 1
  336. height: 0.7289
  337. media: ["video"]
  338. pos: [-5.562, 1.349, 1.994]
  339. qua: [0, 0.70672, 0, 0.70749]
  340. sid: "1596619585929"
  341. transformAtPanos: {,…} */
  342. preDeal(info, source) {// source:来源
  343. var convertValue = function (v, Type) {
  344. var value
  345. if (v instanceof Array) {
  346. v.forEach((v1) => { v1 = parseFloat(v1) })
  347. value = new Type().fromArray(v)
  348. } else {
  349. if (!(v instanceof Type)) {
  350. for (let i in v) { v[i] = parseFloat(v[i]) }
  351. value = new Type().copy(v)
  352. } else {
  353. value = v
  354. }
  355. }
  356. return value
  357. }
  358. if (!info.transformAtPanos) info.transformAtPanos = {}
  359. if (source == 'byHot') {
  360. var infoAttribute = info.infoAttribute || {}
  361. info.title = infoAttribute.title || info.title
  362. info.model = infoAttribute.model || info.model || [] //模型链接
  363. info.images = infoAttribute.images || info.images || []
  364. info.video = infoAttribute.video || info.video || []
  365. info.bgName = infoAttribute.bgName || info.bgName
  366. info.backgroundMusic = info.backgroundMusic || info.backgroundMusic
  367. info.iframe = infoAttribute.iframe || info.iframe || []
  368. info.styleImg = infoAttribute.styleImg || info.styleImg || []
  369. info.content = infoAttribute.content || info.content
  370. {
  371. let action = CloneObject(settings.hotClickEvent.shine)
  372. if (info.actionType == 'noAction' || info.noAction) {
  373. action.examine = false,
  374. action.openHot = false
  375. } else if (info.actionType == 'dontExam') {
  376. action.examine = false
  377. }
  378. info.actionType = action
  379. }
  380. if (info.quaternion) {
  381. info.rotation = new THREE.Euler().setFromVector3(convertValue(info.quaternion, THREE.Quaternion))
  382. } else {
  383. info.rotation = new THREE.Euler().setFromVector3(convertValue(info.rotation, THREE.Vector3)) //热点的旧数据很多是字符串
  384. }
  385. var s = Hot.getDefaulScale(info.hotIconScale)
  386. info.scale = new THREE.Vector3(s, s, 0.02)
  387. delete info.infoAttribute
  388. /* for (let i in this.transformAtPanos) {
  389. info.transformAtPanos[i].pos = new THREE.Vector3().fromArray(info.transformAtPanos[i].pos)
  390. info.transformAtPanos[i].qua && (info.transformAtPanos[i].qua = new THREE.Quaternion().fromArray(info.transformAtPanos[i].qua))
  391. } */
  392. info.texType = "shine"
  393. } else {
  394. if (source == 'byOverlay') {
  395. info.texType = info.media[0]
  396. //info.title = info.texType == 'video'?'视频':'图片'
  397. info.texSrc = info.file
  398. info.actionType = CloneObject(settings.hotClickEvent[info.texType])//给一个默认
  399. delete info.media
  400. info.rotation = new THREE.Euler().setFromQuaternion(convertValue(info.qua, THREE.Quaternion))
  401. info.position = info.pos
  402. delete info.pos
  403. delete info.qua
  404. let a = info.texSrc.split('/')
  405. info.fileName = a.pop()
  406. info.scale = new THREE.Vector3(
  407. info.width,
  408. info.height,
  409. info.depth
  410. )
  411. delete info.width; delete info.height; delete info.depth
  412. delete info.file
  413. } else {
  414. info.rotation = new THREE.Euler().fromArray(info.rotation)//.setFromVector3(info.rotation)
  415. }
  416. info.model = info.model || [] //模型链接
  417. info.images = info.images || []
  418. info.video = info.video || []
  419. info.iframe = info.iframe || []
  420. info.styleImg = info.styleImg || []
  421. }
  422. if (info.texSrc) {
  423. info.texSrc = manage.removeSrcPostMark(info.texSrc)
  424. }
  425. //whole:
  426. //为了兼容旧数据,尽量和hot的数据靠近,最后保存在hot里
  427. info.position = convertValue(info.position, THREE.Vector3)
  428. info.scale = convertValue(info.scale, THREE.Vector3)
  429. delete info.quaternion
  430. info.linkType = info.linkType || "common"
  431. for (let i in info.transformAtPanos) {
  432. info.transformAtPanos[i].pos = new THREE.Vector3().fromArray(info.transformAtPanos[i].pos)
  433. //info.transformAtPanos[i].qua = new THREE.Quaternion().fromArray(info.transformAtPanos[i].qua)
  434. }
  435. }
  436. addBox(state) {
  437. if (state == !!this.hasBox) {
  438. return
  439. }
  440. if (state) {
  441. var box = new THREE.Mesh(_boxGeometry, _boxMat)
  442. box.position.set(0, 0, 1 / 2)
  443. box.renderOrder = 3
  444. this.plane.position.set(0, 0, 1)
  445. this.add(box)
  446. this.box = box
  447. } else {
  448. this.plane.position.set(0, 0, 0)
  449. this.remove(this.box)
  450. this.box = null
  451. }
  452. this.hasBox = this.info.hasBox = state
  453. }
  454. /* getSizeByScale() {
  455. return {
  456. width: settings.defaultOverlaySize[0] * this.scale.x,
  457. height: settings.defaultOverlaySize[1] * this.scale.y
  458. }
  459. }
  460. getScaleBySize(width, height) {
  461. return {
  462. x: width / settings.defaultOverlaySize[0],
  463. y: height / settings.defaultOverlaySize[1],
  464. }
  465. }*/
  466. setVisiblePanos(visibleData) {
  467. if (visibleData) this.info.visiblePanos = visibleData
  468. else if (!this.info.visiblePanos) this.getVisiblePanos()
  469. }
  470. getVisiblePanos() {//在不同点还不一样
  471. var depth = this.hasBox ? this.scale.z : 0
  472. var width = this.scale.x, height = this.scale.y
  473. var cornerPoint
  474. if (this.plane) {
  475. cornerPoint = [
  476. new THREE.Vector3(0, 0, depth),
  477. new THREE.Vector3(-width / 2, height / 2, depth),
  478. new THREE.Vector3(width / 2, height / 2, depth),
  479. new THREE.Vector3(width / 2, -height / 2, depth),
  480. new THREE.Vector3(-width / 2, -height / 2, depth),
  481. ]
  482. } else {
  483. var bound = new THREE.Box3().copy(this.info.modelBound.bound)
  484. var center = bound.center()
  485. cornerPoint = [
  486. new THREE.Vector3(center.x, center.y, center.z),
  487. new THREE.Vector3(bound.min.x, bound.min.y, bound.min.z),
  488. new THREE.Vector3(bound.min.x, bound.min.y, bound.max.z),
  489. new THREE.Vector3(bound.min.x, bound.max.y, bound.min.z),
  490. new THREE.Vector3(bound.max.x, bound.min.y, bound.min.z),
  491. new THREE.Vector3(bound.max.x, bound.max.y, bound.min.z),
  492. new THREE.Vector3(bound.max.x, bound.min.y, bound.max.z),
  493. new THREE.Vector3(bound.min.x, bound.max.y, bound.max.z),
  494. new THREE.Vector3(bound.max.x, bound.max.y, bound.max.z),
  495. ]
  496. }
  497. var getPos = (position) => {//每个overlay位置对应5个坐标,plane中心和四个角的位置
  498. if (this.plane) {
  499. return cornerPoint.map(e => {
  500. return e.clone().applyEuler(this.info.rotation).add(position)
  501. })
  502. } else {
  503. var matrixWorld = new THREE.Matrix4().compose(position, this.quaternion, this.scale)
  504. matrixWorld.multiplyMatrices(matrixWorld, this.mesh.matrix)
  505. return cornerPoint.map(e => {
  506. return e.clone().applyMatrix4(matrixWorld)
  507. })
  508. }
  509. }
  510. this.info.visiblePanos = []
  511. var customPositions = getPos(this.info.position)
  512. var posAtPanos = {}
  513. for (let panoId in this.info.transformAtPanos) {
  514. if (panoId == 'outSide') continue
  515. posAtPanos[panoId] = getPos(this.info.transformAtPanos[panoId].pos)
  516. }
  517. let maxCount = browser.isMobile() ? 2000 : 5000
  518. let c = model.panos.list.length * model.colliders.length
  519. if (window.isEdit || c < maxCount) { //编辑页面保险起见还是全部算完后才可浏览,就能保证保存全部的visiblePano
  520. this.info.visiblePanos = common.getVisiblePano(customPositions, model.panos.list, {
  521. model: model.colliders, posAtPanos
  522. })
  523. } else {
  524. let start = 0
  525. let interval = setInterval(() => {
  526. let end = start + Hot.visiPanosCountSlice
  527. end = Math.min(end, model.panos.list.length)
  528. let i = start
  529. start = end
  530. let panos = model.panos.list.slice(i, end)
  531. this.info.visiblePanos = this.info.visiblePanos.concat(common.getVisiblePano(customPositions, panos, {
  532. model: model.colliders, posAtPanos
  533. }))
  534. if (end >= model.panos.list.length) {
  535. console.log(window.hotsi ? (++window.hotsi) : (window.hotsi = 1))
  536. clearInterval(interval)
  537. }
  538. }, Hot.visiEveryDurSlice)// visiEveryDurSlice 等在main中定义
  539. }
  540. }
  541. updateVisible(panos, visibility) {
  542. if (window.isEdit && editTool.hotpoint.editSpot == this) {
  543. return this.visible = true
  544. }
  545. this.visible = visibility != void 0 ? visibility : (!this.info.visiblePanos || !!panos.find(pano => this.info.visiblePanos.includes(pano.id)))
  546. if (this.texType == 'video') {
  547. //this.switchPlay(this.visible, this.visible ? null : 'stop' );//可见时不操作;不可见时停止
  548. this.update(player)
  549. }
  550. }
  551. getCornerPoint() {//获取在每个漫游点上的视觉边界点 可以打开boxHelper和addBall来观测是否准确
  552. if (this.cornerPoints[player.currentPano.id]) {
  553. return this.cornerPoints[player.currentPano.id]
  554. } else {
  555. var boundPoint, cornerPoint
  556. var center//中心点
  557. if (this.plane) {
  558. center = this.plane.getWorldPosition()
  559. boundPoint = [
  560. new THREE.Vector3(-0.5, 0.5, 0),
  561. new THREE.Vector3(0.5, 0.5, 0),
  562. new THREE.Vector3(0.5, -0.5, 0),
  563. new THREE.Vector3(-0.5, -0.5, 0),
  564. ]
  565. } else {
  566. var bound = new THREE.Box3().copy(this.info.modelBound.bound)
  567. boundPoint = [
  568. new THREE.Vector3(bound.min.x, bound.min.y, bound.min.z),
  569. new THREE.Vector3(bound.min.x, bound.min.y, bound.max.z),
  570. new THREE.Vector3(bound.min.x, bound.max.y, bound.min.z),
  571. new THREE.Vector3(bound.max.x, bound.min.y, bound.min.z),
  572. new THREE.Vector3(bound.max.x, bound.max.y, bound.min.z),
  573. new THREE.Vector3(bound.max.x, bound.min.y, bound.max.z),
  574. new THREE.Vector3(bound.min.x, bound.max.y, bound.max.z),
  575. new THREE.Vector3(bound.max.x, bound.max.y, bound.max.z),
  576. ]
  577. }
  578. var maxLon = -Infinity
  579. var minLon = +Infinity
  580. var maxLat = -Infinity
  581. var minLat = +Infinity
  582. var pos1 = player.currentPano.position.clone()
  583. center = this.position.clone() //模型bound的中心点已经位移到了hot中心点。 注意不能用getWorldPosition,得到的会是偏移的
  584. var dir = center.clone().sub(pos1).normalize()
  585. var centerDirInfo = {}
  586. player.cameraControls.controls.panorama.lookAt.call(centerDirInfo, null, dir)
  587. boundPoint.forEach(e => {//lon左右
  588. var point = e.applyMatrix4(this.mesh.matrixWorld)
  589. var dir = point.clone().sub(pos1).normalize()
  590. var dirInfo = {}
  591. player.cameraControls.controls.panorama.lookAt.call(dirInfo, null, dir)
  592. var diffLon = (dirInfo.lon - centerDirInfo.lon) % 360
  593. if (Math.abs(diffLon) > 180) {//因为有时需要根据符号判断是在中心的左边还是右边,所以限制在180内
  594. diffLon += (diffLon > 0 ? -360 : 360)
  595. }
  596. var diffLat = dirInfo.lat - centerDirInfo.lat
  597. maxLon = Math.max(diffLon, maxLon)
  598. minLon = Math.min(diffLon, minLon)
  599. maxLat = Math.max(diffLat, maxLat)
  600. minLat = Math.min(diffLat, minLat)
  601. })
  602. var diffLon = maxLon - minLon
  603. var diffLat = maxLat - minLat
  604. if (diffLat > 180) {//可能是到了反面。不好算,直接返回所有boundPoint
  605. cornerPoint = boundPoint
  606. } else {
  607. //读取lon lat的最大最小值,勾勒出一个没有倾斜的矩形 。它比boundPoint看起来范围更大些
  608. maxLon = maxLon + centerDirInfo.lon
  609. maxLat = maxLat + centerDirInfo.lat
  610. minLon = minLon + centerDirInfo.lon
  611. minLat = minLat + centerDirInfo.lat
  612. var dirs = [
  613. math.getDirByLonLat(maxLon, maxLat),
  614. math.getDirByLonLat(minLon, minLat),
  615. math.getDirByLonLat(maxLon, minLat),
  616. math.getDirByLonLat(minLon, maxLat),
  617. ]
  618. cornerPoint = dirs.map(e => {
  619. return e.clone().add(pos1)
  620. })
  621. cornerPoint = [center, ...cornerPoint] //最后增加一个中心点
  622. }
  623. /* if(this.objObject){
  624. cornerPoint = [pos2, ...cornerPoint]
  625. } */
  626. //addPoints(cornerPoint)
  627. this.cornerPoints[player.currentPano.id] = { cornerPoint, diffLon, diffLat }
  628. return this.cornerPoints[player.currentPano.id]
  629. }
  630. }
  631. inSight() {
  632. //return true
  633. if (window.isEdit) return true // 太容易move了
  634. if (player.mode == 'panorama') {
  635. if (!player.camera) return
  636. var cornerPointInfo = this.getCornerPoint()
  637. var cornerPoint
  638. if (cornerPointInfo.diffLon < 15 && cornerPointInfo.diffLat < 15) {//当很小的时候,只判断中心点即可
  639. cornerPoint = [cornerPointInfo.cornerPoint[0]]
  640. } else {
  641. cornerPoint = cornerPointInfo.cornerPoint
  642. }
  643. for (let i = 0, j = cornerPoint.length; i < j; i++) {//只要有一点可见就算看见
  644. var pos2d = math.getPos2d(cornerPoint[i], player.camera, $("#player")[0])
  645. if (pos2d.trueSide && pos2d.inSight) return true
  646. }
  647. } else {//飞出要判断模型阻挡,有点耗时就算了
  648. return true
  649. }
  650. }
  651. update(player) {
  652. if (player.mode == 'panorama') {//实时监测播放
  653. if (this.texType == "video") {
  654. if (this.visible && !this.pausedByUser && this.inSight()) {
  655. this.videoControl(true)
  656. } else {
  657. this.videoControl(false)
  658. }
  659. } else if (this.info.animateInfo) {
  660. if (this.visible && this.inSight()) {
  661. GifTexDeal.start(this.animation)
  662. } else {
  663. GifTexDeal.stop(this.animation)
  664. }
  665. }
  666. }
  667. if (this.info.isSprite) {
  668. this.quaternion.copy(player.camera.quaternion)
  669. }
  670. this.updateScale()
  671. }
  672. updateScale(e, t) {//自适应调节大小
  673. if (!DATA.autoAdjustHotScale || this.texType != 'shine') return
  674. //let renderSize = player.sceneRenderer.renderer.domElement
  675. let renderSize = player.sceneRenderer.renderer.getSize()
  676. var scale = convertTool.getScaleForConstantSize($.extend(autoSizeInfo, {
  677. camera: player.camera, resolution: { x: renderSize.width, y: renderSize.height },
  678. position: this.position.clone(),
  679. }))
  680. this.plane.scale.set(scale, scale, scale)
  681. }
  682. switchPlay(state) {//手动播放暂停
  683. this.pausedByUser = !state
  684. this.videoControl(state)
  685. }
  686. videoControl(state) {
  687. if (this.texType != "video" || !this.material_.map) return
  688. var video = this.material_.map.image
  689. if (!state || state == 'stop') {
  690. if (!video.paused) {
  691. video.pause()
  692. //console.log("pause " + this.sid)
  693. }
  694. if (state == 'stop') {
  695. video.currentTime = 0
  696. }
  697. } else if (state) {
  698. if (video.paused) {
  699. video.play()
  700. //console.log("play " + this.sid)
  701. }
  702. }
  703. }
  704. /* setDefaultHotScale = function(){//设置成默认热点大小
  705. var w = DATA.hotIconScale) * g_HotMeshSize.g_HotMeshWidth
  706. this.scale.set( w, w, this.scale.z)
  707. } */
  708. setTitleElem() {
  709. var root = $("#hot")
  710. var title = this.info.title
  711. if (title) {
  712. if (!this.titleElem) {
  713. var elem = $(`<div></div>`)
  714. root.append(elem)
  715. this.titleElem = elem
  716. }
  717. this.titleElem.text(title)
  718. } else {
  719. if (this.titleElem) {
  720. this.titleElem.remove()
  721. this.titleElem = null
  722. }
  723. }
  724. }
  725. showTitle() {
  726. if (!this.titleElem) return
  727. var pos = math.getPos2d(this.position, player.camera, $("#player")[0])
  728. if (pos.trueSide) {//inSight
  729. this.titleElem.css({ "left": `${pos.pos.x}px`, "top": `${pos.pos.y}px ` })
  730. this.titleElem.css("display", "block")
  731. } else {
  732. this.titleElem.css("display", "none")
  733. }
  734. }
  735. hideTitle() {
  736. if (!this.titleElem) return
  737. this.titleElem.css("display", "none")
  738. }
  739. closestPanoTowardTag(e, t) {
  740. var i = []
  741. , n = []
  742. , r = this.mesh.getWorldPosition()
  743. if (e === "panorama") {
  744. /* var o = t.position.clone().sub(r).normalize();
  745. n.push(function(t, i) {//scoreFunctions.direction 最好这个漫游点在currentPano到热点之间的路径上。但是这样的话可能就看不到热点正面,所以删掉
  746. return function(e) {
  747. return e.position.clone().sub(t).normalize().dot(i) * window._settings.navigation.directionFactor
  748. }}(r, o)
  749. ) */
  750. }
  751. var a = new THREE.Vector3
  752. i.push(function (e) {
  753. return Math.abs(e.position.x - r.x) > window._settings.tags.visibility.cameraClearance || Math.abs(e.position.z - r.z) > window._settings.tags.visibility.cameraClearance
  754. },
  755. function (e) {
  756. a.copy(r).sub(e.position)
  757. var t = -THREE.Math.radToDeg(Math.atan(a.y / Math.sqrt(a.x * a.x + a.z * a.z)))
  758. , i = window._settings.tags.navigate.tiltTolerance
  759. return window._settings.insideLookLimitDown - i < t && t < window._settings.insideLookLimitUp + i
  760. },
  761. (pano) => { // add
  762. return player.checkHasNeighbor(pano)
  763. },
  764. (pano) => { // add
  765. // if (this.info && this.info.visiblePanos)
  766. return this.info.visiblePanos.includes(pano.id)
  767. }
  768. )
  769. n.push(
  770. (function (hot, i) { //scoreFunctions.distanceSquared
  771. return function (pano) {
  772. //i = a.navigation.distanceFactor
  773. return hot ? hot.position.distanceToSquared(pano.position) * i : 0
  774. }
  775. })(this, -2)
  776. ,
  777. (pano) => {//尽量正对hot
  778. let dir = new THREE.Vector3(0, 0, 1).applyQuaternion(this.quaternion)
  779. let dir2 = new THREE.Vector3().subVectors(pano.position, this.position).normalize()
  780. let s = dir.dot(dir2) * 10
  781. //console.log(pano.id + ":" + s)
  782. return s
  783. }
  784. )
  785. var s = t.model.panos.sortByScore(i, n)
  786. console.log(s)
  787. return s && 0 < s.length && s[0].pano
  788. }
  789. examine(options = {}) {
  790. console.log('打开热点,关闭背景音乐')
  791. // 判断当前背景音乐是开的还是关的
  792. let tempp = document.querySelector('#openMusic')
  793. if (tempp.style.display === 'block') {
  794. // 背景音乐当前为关闭状态
  795. window.musicFlagNow = '音乐关'
  796. } else {
  797. window.musicFlagNow = '音乐开'
  798. SoundManager.pause('bgm')
  799. }
  800. /**
  801. * 图片、视频之类的热点
  802. *
  803. * link: 提供默认效果的链接
  804. * linkType: 'common'
  805. * iframe: []
  806. */
  807. /**
  808. * 热点编辑里添加网页链接——普通
  809. *
  810. * link: 提供默认效果的链接
  811. * linkType: 'jumpLink'
  812. * iframe: ['http://47.112.166.173:8105/editPage/edit.html?m=1308']
  813. */
  814. /**
  815. * 热点编辑里添加网页链接——跳转
  816. *
  817. * link: 提供默认效果的链接
  818. * linkType: 'jumpLink'
  819. * iframe: ['http://47.112.166.173:8105/editPage/edit.html?m=1308']
  820. */
  821. /**
  822. * 热点编辑里添加网页链接——iframe
  823. * 提供默认效果的链接
  824. * linkType: 'iframeDiv'
  825. * iframe: ['...']
  826. */
  827. var openHot = this.info.link && this.info.actionType.openHot && !options.dontOpen
  828. var needExamine = options.examine || (!settings.dontExamHot && this.info.actionType.examine)
  829. if (!openHot && !needExamine) {
  830. return
  831. }
  832. if (openHot && this.info.linkType != "common" && this.info.iframe && this.info.iframe[0]) {
  833. if (false) { // 场景跳转(热点编辑里添加网页链接——跳转)
  834. // 注意,因为网站用了vue router, url里看上去像是查询片段的那一段其实是放在hash片段中的。
  835. const hotspotWebQuerySection = new URLSearchParams(this.info.iframe[0].split('?')[1])
  836. const targetSceneCode = hotspotWebQuerySection.get('m')
  837. const currentLocationQuerySection = new URLSearchParams(location.href.split('?')[1])
  838. const currentSceneCode = currentLocationQuerySection.get('m')
  839. if (currentSceneCode === '1300' && targetSceneCode === '1302') {
  840. const iframeElem = document.createElement('iframe')
  841. iframeElem.style.position = 'absolute'
  842. iframeElem.style.top = '50%'
  843. iframeElem.style.left = '50%'
  844. iframeElem.style.width = '600px'
  845. iframeElem.style.height = '800px'
  846. iframeElem.style.transform = 'translate(-50%, -50%)'
  847. iframeElem.style.zIndex = '9999'
  848. iframeElem.style.boxShadow = '0 0 0 1000px rgba(0, 0, 0, 0.85)'
  849. // iframeElem.src = 'http://192.168.20.16:8081/#/topic'
  850. iframeElem.src = '/AnhuiDaily/quiz/index.html#/topic'
  851. document.documentElement.appendChild(iframeElem)
  852. const onMsg = (msg) => {
  853. console.log('message received!', msg)
  854. window.removeEventListener('message', onMsg, false)
  855. if (msg.data === 'quiz over') {
  856. // 跳转到新场景
  857. currentLocationQuerySection.set('m', targetSceneCode)
  858. const newLocation = location.href.split('?')[0] + '?' + currentLocationQuerySection.toString()
  859. location.assign(newLocation)
  860. location.reload(true)
  861. }
  862. }
  863. window.addEventListener('message', onMsg, false)
  864. } else {
  865. // 跳转到新场景
  866. currentLocationQuerySection.set('m', targetSceneCode)
  867. const newLocation = location.href.split('?')[0] + '?' + currentLocationQuerySection.toString()
  868. location.assign(newLocation)
  869. location.reload(true)
  870. }
  871. } else {
  872. // 不是场景跳转
  873. var src = this.info.iframe[0]
  874. if (this.info.linkType == "jumpLink") { // 新页面打开链接
  875. var newPage = window.open(src, "_blank")
  876. newPage.focus()
  877. } else if (this.info.linkType == "iframeDiv") { // iframe里打开链接
  878. var div = document.createElement("div")
  879. div.style.position = 'fixed'
  880. div.style.width = div.style.height = "100%"
  881. div.style.left = div.style.top = '0'
  882. div.style["z-index"] = "999"
  883. var exit = document.createElement("div")
  884. exit.style["background-image"] = "url(images/vrOffImg.png)"
  885. exit.style.position = 'absolute'
  886. exit.style.width = exit.style.height = "50px"
  887. exit.style.left = '17px'; exit.style.top = "20px"
  888. exit.style.cursor = "pointer"
  889. exit.style["background-repeat"] = "no-repeat"
  890. exit.style["background-size"] = "25%"
  891. exit.style["background-position"] = "center center"
  892. exit.style["background-color"] = "rgba(0, 0, 0, 0.2)"
  893. exit.style["border-radius"] = "50%"
  894. exit.style["z-index"] = "3"
  895. exit.onclick = () => {
  896. $(div).remove()
  897. Hot.closePopup()
  898. }
  899. var myElement = document.createElement("iframe")
  900. myElement.style.position = 'absolute'
  901. myElement.style.width = myElement.style.height = "100%"
  902. myElement.style.left = myElement.style.top = '0'
  903. myElement.src = this.info.iframe[0]
  904. $("body").append(div)
  905. div.appendChild(exit)
  906. div.appendChild(myElement)
  907. SoundManager.play('hot')
  908. }
  909. }
  910. } else {
  911. // 图片、视频之类的热点
  912. if (!player.currentPano) return
  913. var popup = document.getElementById("popup")
  914. if (openHot) {
  915. g_currentHot = this,
  916. popup.style.display = "block",
  917. popup.classList.add("wait")
  918. var n = document.createElement("iframe")
  919. SoundManager.play('hot')
  920. var src = getCommonHotspotUrl(this.info.link)
  921. n.src = src
  922. n.id = "id1",
  923. n.allowTransparency = "true"
  924. var a = document.getElementById("id1")
  925. if (void 0 === a || null == a) {
  926. document.querySelector(".popup-content").appendChild(n)
  927. document.body.classList.add('hotspot-detail-open')
  928. var s = !1
  929. window.loaddingSuccess = function () {
  930. s = !0
  931. }
  932. ,
  933. setTimeout(function e() {
  934. if (s) {
  935. var t = document.querySelector("#id1").contentWindow.document
  936. t.querySelector("video") && (t.querySelector("video").play(),
  937. !t.querySelector("video").paused && t.querySelector(".playPause") && t.querySelector(".playPause").classList.add("fa-pause")),
  938. t.querySelector("audio") && t.querySelector("audio").play()
  939. } else
  940. setTimeout(e, 300)
  941. }, 800)
  942. }
  943. }
  944. var done = function () {
  945. player.flyingToTag = !1
  946. openHot && popup.classList.remove("wait")
  947. }.bind(this)
  948. if (!needExamine) {
  949. done()
  950. return
  951. }
  952. var c = this.closestPanoTowardTag(player.mode, player.currentPano) || player.currentPano
  953. , h = this.mesh.getWorldPosition()
  954. player.flyingToTag = !0
  955. if (player.mode === 'panorama') {
  956. var d = {
  957. pano: c,
  958. lookAtPoint: h,
  959. duration: options.duration,
  960. maxDistanceOverride: null,
  961. skipWarpingCheck: !1,
  962. aimDuration: options.aimDuration,
  963. }
  964. player.flyToPano(d, done)
  965. } else {
  966. var p = {
  967. pano: c
  968. }
  969. if (h) {
  970. var f = (new THREE.Matrix4).lookAt(c.position, h, new THREE.Vector3(0, 1, 0))
  971. p.quaternion = (new THREE.Quaternion).setFromRotationMatrix(f)
  972. }
  973. p.callback = done,
  974. p.duration = options.duration || 1500,
  975. p.mode = 'panorama',
  976. p.aimDuration = options.aimDuration
  977. player.flyToNewMode(p)
  978. }
  979. }
  980. }
  981. addModel(object) {
  982. if (this.objObject) {
  983. this.remove(this.objObject)
  984. }
  985. this.objObject = object
  986. /* object.traverse((mesh)=>{
  987. if(mesh.material && mesh.type == "hotSprite"){
  988. mesh.material = this.material_;
  989. }
  990. }) */
  991. object.name = this.info.objName
  992. object.src = this.info.objSrc
  993. this.info.hasBox = false
  994. this.addBox(false)
  995. this.remove(this.plane)
  996. this.plane = null
  997. this.setMesh(this.objObject)
  998. //this.adjustModelAuto()
  999. if (this.info.modelBound) {//应该不会改变
  1000. var s = this.info.modelBound.scaleRatio
  1001. this.mesh.scale.set(s, s, s)
  1002. this.mesh.position.fromArray(this.info.modelBound.position)
  1003. this.mesh.modelBound = this.info.modelBound
  1004. }
  1005. this.material_.side = THREE.FrontSide
  1006. this.changeBoxHelperDisplay(false)
  1007. //this.mesh.boxHelper.visible = true
  1008. }
  1009. addPlane() {//换成plane
  1010. if (this.plane) return
  1011. this.plane = new THREE.Mesh(_planeGeometry, this.material_)
  1012. this.remove(this.objObject)
  1013. this.objObject = null
  1014. delete this.info.objSrc
  1015. delete this.info.objName
  1016. delete this.info.modelBound
  1017. this.setMesh(this.plane)
  1018. //this.material_.side = THREE.DoubleSide //双面的话飞出来会看到悬空的
  1019. }
  1020. setMesh(mesh) {
  1021. this.mesh = mesh
  1022. this.add(this.mesh)
  1023. this.mesh.renderOrder = 3
  1024. this.changeMaterial(this.material_) //re applyTo every mesh
  1025. this.mesh.traverse((mesh) => {
  1026. mesh.type = "hotSprite" //raycaster use
  1027. })
  1028. if (!this.mesh.boxHelper) {
  1029. var boxHelper = this.mesh.children.find(e => e instanceof THREE.Box3Helper)
  1030. if (boxHelper) {
  1031. this.mesh.boxHelper = boxHelper
  1032. } else {
  1033. var bound
  1034. if (this.objObject) {
  1035. bound = new THREE.Box3().copy(this.info.modelBound.bound)
  1036. } else {
  1037. bound = planeBound
  1038. }
  1039. bound.expandByVector(new THREE.Vector3(0.0001, 0.0001, 0.0001))
  1040. this.mesh.boxHelper = new THREE.Box3Helper(bound, new THREE.Color("#00ffff"))
  1041. this.mesh.add(this.mesh.boxHelper)
  1042. this.mesh.boxHelper.material.depthTest = false
  1043. this.mesh.boxHelper.material.transparent = true
  1044. this.mesh.boxHelper.visible = false
  1045. }
  1046. }
  1047. }
  1048. changeBoxHelperDisplay(show) {
  1049. if (show) {
  1050. this.visible_ = this.visible
  1051. this.visible = true
  1052. this.mesh.boxHelper.visible = true
  1053. } else {
  1054. if (this.visible_ != void 0) {
  1055. this.visible = this.visible_
  1056. }
  1057. this.mesh.boxHelper.visible = false
  1058. }
  1059. }
  1060. /* addToLoadQueue() {
  1061. if (this.texType == 'photo') {
  1062. Hot.loadQueue.includes(this) || Hot.loadQueue.push(this)
  1063. }
  1064. } */
  1065. requestDownload(type, callback) {
  1066. var plane = this.plane
  1067. if (type == 'photo') {
  1068. if (this.photoHasRequestLoad || this.texType != 'photo') return
  1069. //console.log('overlay beginDownload : ' + this.sid)
  1070. /* this.material_.map = */Texture.load(this.info.texSrc, (tex) => {
  1071. callback && callback()
  1072. if (!tex.image) {
  1073. return //只是单纯用了相同src的tex,但image仍未加载完
  1074. }
  1075. if (!this._loadDones) return
  1076. dealMap(tex)
  1077. setTimeout(Hot.loadNext, 50)
  1078. hotGroup.children.forEach(e => {
  1079. if (e.info.texSrc == this.info.texSrc && e.info.texType == type) {
  1080. e.material_.color.set("#FFFFFF")
  1081. e.material_.opacity = 1
  1082. console.log('overlay loaded: ' + e.sid + " - " + this.info.texSrc.split('/').pop())
  1083. e.texMedia = tex.image
  1084. {//animation不同致使的不能使用同一个texture
  1085. if (window.isEdit) {
  1086. if (animateTexSrcs[e.info.texSrc]) {
  1087. e.material_.map = tex.clone() //编辑动画直接不用一个texture, 故而animation也不同
  1088. e.material_.map.needsUpdate = true
  1089. } else {
  1090. e.material_.map = tex
  1091. animateTexSrcs[e.info.texSrc] = 1
  1092. }
  1093. } else {
  1094. if (animateTexSrcs[e.info.texSrc]) {//已有该texSrc
  1095. let finded = false
  1096. for (let i of animateTexSrcs[e.info.texSrc]) {
  1097. if (ifSame(i[0], e.info.animateInfo)) {
  1098. e.material_.map = i[1]; finded = true; break
  1099. }
  1100. }
  1101. if (!finded) {
  1102. let tex_ = tex.clone()
  1103. animateTexSrcs[e.info.texSrc].set(e.info.animateInfo, tex_)
  1104. e.material_.map = tex_
  1105. }
  1106. } else {
  1107. let object = new Map()
  1108. object.set(e.info.animateInfo, tex)
  1109. animateTexSrcs[e.info.texSrc] = object//注册第一个texSrc
  1110. e.material_.map = tex
  1111. }
  1112. }
  1113. }
  1114. if (e.info.animateInfo && !e.animation) {
  1115. e.animation = GifTexDeal.addAnimation(e.material_.map, e, e.info.animateInfo, e.sid)
  1116. e.visible && e.inSight() && GifTexDeal.start(e.animation)
  1117. }
  1118. if (++photoLoaded == originPhotoCount) {//data2.js中的所有photo加载完毕
  1119. Hot.allPhotoLoaded = true
  1120. Hot.whenAllFileLoaded && Hot.allModelLoaded && Hot.whenAllFileLoaded()
  1121. }
  1122. {
  1123. e._loadDones.forEach(a => a())
  1124. e._loadDones = null
  1125. e.photoHasRequestLoad = true
  1126. }
  1127. e.material_.needsUpdate = true
  1128. }
  1129. })
  1130. })
  1131. this.photoHasRequestLoad = true
  1132. } else if (type == 'model') {
  1133. if (this.modelHasRequestLoad || !this.info.objSrc) return
  1134. //需要处理重复?
  1135. objLoader.load(this.info.objSrc, (object) => {
  1136. this.remove(this.mesh)
  1137. this.addModel(object)
  1138. callback && callback()
  1139. if (++modelLoaded == originModelCount) {//data2.js中的所有photo加载完毕
  1140. Hot.allModelLoaded = true
  1141. Hot.whenAllFileLoaded && Hot.allPhotoLoaded && Hot.whenAllFileLoaded()
  1142. }
  1143. })
  1144. this.modelHasRequestLoad = true
  1145. }
  1146. }
  1147. }
  1148. Hot.updateVisibles = function (panos) {
  1149. if (panos === true) {
  1150. model.hotGroup.children.forEach(e => e.updateVisible(null, true))
  1151. } else {
  1152. model.hotGroup.children.forEach(e => e.updateVisible(panos))
  1153. }
  1154. }
  1155. Hot.beginShineHot = function () {
  1156. if (!window.isEdit && shineMats.length == 0) return
  1157. transitions.trigger({
  1158. func: function (e) {
  1159. var opa = e <= .5 ? 2 * e : -2 * e + 2
  1160. shineMats.forEach(mat => {
  1161. mat.uniforms.opac.value = opa
  1162. })
  1163. },
  1164. cycling: !0,
  1165. duration: 3e3,
  1166. name: "hotShine"
  1167. })
  1168. }
  1169. Hot.getDefaulScale = function (hotIconScale) {
  1170. return (hotIconScale || DATA.hotIconScale) * g_HotMeshSize.g_HotMeshWidth
  1171. }
  1172. var loadings = []
  1173. Hot.loadQueue = [] //等待下载的overlay,目前只针对photo
  1174. Hot.maxLoadingCount = 3 //同时正在load图片的数量
  1175. Hot.loadNext = () => {//继续requestDownload loadQueue中前排的item
  1176. let count = Hot.maxLoadingCount - loadings.length
  1177. Hot.loadQueue.slice(0, count).forEach(e => {
  1178. loadings.push(e)
  1179. //console.log(e)
  1180. e.hot.requestDownload(e.type, () => {
  1181. var i = loadings.indexOf(e)
  1182. loadings.splice(i, 1)
  1183. })
  1184. })
  1185. Hot.loadQueue.splice(0, count)
  1186. }
  1187. Hot.getNeedLoad = function () {//计算获取loadQueue,每次都重新计算,覆盖旧的
  1188. if (!player || !player.domElement || !player.mode)
  1189. return
  1190. var hots1, hots2
  1191. if (player.mode != 'panorama') {
  1192. if (Hot.loadQueue.length == 0) {
  1193. hots1 = model.hotGroup.children.filter(e => e.texType == 'photo' && !e.photoHasRequestLoad)
  1194. hots2 = model.hotGroup.children.filter(e => e.info.objSrc && !e.modelHasRequestLoad)
  1195. Hot.loadQueue = hots1.map(e => { return { hot: e, type: "photo" } }).concat(
  1196. hots2.map(e => { return { hot: e, type: "model" } })
  1197. )
  1198. }
  1199. return
  1200. }
  1201. //Hot.loadWhenOutside = true
  1202. hots1 = model.hotGroup.children.filter(e => e.texType == 'photo' && !e.photoHasRequestLoad && (!e.info.visiblePanos || e.info.visiblePanos.includes(player.currentPano.id)))
  1203. hots2 = model.hotGroup.children.filter(e => e.info.objSrc && !e.modelHasRequestLoad && (!e.info.visiblePanos || e.info.visiblePanos.includes(player.currentPano.id)))
  1204. if (hots1.length + hots2.length == 0) {
  1205. hots1 = model.hotGroup.children.filter(e => e.texType == 'photo' && !e.photoHasRequestLoad)
  1206. hots2 = model.hotGroup.children.filter(e => e.info.objSrc && !e.modelHasRequestLoad)
  1207. }
  1208. var cameraDir = player.getDirection()
  1209. Hot.loadQueue = hots1.map(e => { return { hot: e, type: "photo" } }).concat(
  1210. hots2.map(e => { return { hot: e, type: "model" } })
  1211. )
  1212. var request = [(item) => {
  1213. return true
  1214. }]
  1215. var rank = [(item) => {
  1216. var dis = item.hot.mesh.getWorldPosition().distanceTo(player.position)
  1217. return -dis
  1218. }
  1219. , (item) => {
  1220. var tagDir = item.hot.mesh.getWorldPosition().sub(player.position)
  1221. var angle = tagDir.angleTo(cameraDir)
  1222. return -angle * 20
  1223. }]
  1224. var result = common.sortByScore(Hot.loadQueue, request, rank)
  1225. //Hot.loadQueue = result ? result.slice(0, 5).map(e=>e.item) : model.hotGroup.children.filter(e=>e.texType == 'photo' && !e.hasRequestLoad).slice(0, 2);
  1226. Hot.loadQueue = result ? result.slice(0, 5).map(e => e.item) : []
  1227. }
  1228. Hot.load = () => {//开始下载图片
  1229. Hot.getNeedLoad()
  1230. Hot.loadNext()
  1231. var hots1 = model.hotGroup.children.filter(e => e.texType == 'photo' && !e.photoHasRequestLoad)
  1232. var hots2 = model.hotGroup.children.filter(e => e.info.objSrc && !e.modelHasRequestLoad)
  1233. if (hots1.length + hots2.length > 0) {
  1234. setTimeout(Hot.load, 200)
  1235. } else {
  1236. Hot.allRequestLoad = true
  1237. console.log('allRequestLoad')
  1238. }
  1239. }
  1240. Hot.startLoad = () => {
  1241. originPhotoCount = hotGroup.children.filter(e => e.texType == 'photo').length
  1242. originModelCount = hotGroup.children.filter(e => !!e.info.objSrc).length
  1243. if (originPhotoCount == 0) Hot.allPhotoLoaded = true
  1244. if (originModelCount == 0) Hot.allModelLoaded = true
  1245. if (Hot.allModelLoaded && Hot.allPhotoLoaded) Hot.whenAllFileLoaded && Hot.whenAllFileLoaded()//所有加载完毕
  1246. else {
  1247. Hot.load()
  1248. }
  1249. }
  1250. window.Hot = Hot
  1251. /* var ball = new THREE.Mesh(new THREE.SphereBufferGeometry(0.01),new THREE.MeshBasicMaterial({color:"#f00",depthTest:false,transparent:true}))
  1252. var balls = []
  1253. var addPoint = function(point){
  1254. console.log(point)
  1255. var ball1 = ball.clone()
  1256. model.add(ball1);
  1257. ball1.position.copy(point)
  1258. balls.push(ball1)
  1259. }
  1260. var addPoints = function(points){
  1261. balls.forEach(e=>model.remove(e))
  1262. balls = []
  1263. points.forEach(e=>addPoint(e))
  1264. }
  1265. */
  1266. //判断是否是移动端,如果是给关闭按钮添加touchstart事件
  1267. Hot.closePopup = () => {// 关闭热点页面
  1268. if (!g_currentHot) return
  1269. console.log('关闭热点,打开背景音乐')
  1270. if (window.musicFlagNow === '音乐开') SoundManager.play('bgm')
  1271. g_currentHot = null
  1272. var hotPop = document.getElementById('popup')
  1273. hotPop.style.display = "none"
  1274. document.querySelector(".popup-content").removeChild(document.getElementById("id1"))
  1275. $("#popup iframe:last").remove()
  1276. document.body.classList.remove('hotspot-detail-open')
  1277. SoundManager.pause('hot', true)//自动播放被中断的音频 (bgm
  1278. return false
  1279. }
  1280. $('#closepop').on("click", () => {
  1281. Hot.closePopup()
  1282. })
  1283. Hot.createHotList = function () {
  1284. var docFragment = document.createDocumentFragment()
  1285. var hots = hotGroup.children.filter(hot => hot.info.actionType.openHot)
  1286. hots = hots.sort((a, b) => { return a.order - b.order })
  1287. window.myHotList = hots
  1288. hots.forEach((hot) => {
  1289. var li = document.createElement('li')
  1290. var span = document.createElement('span')
  1291. span.innerHTML = hot.info.title || '热点'
  1292. // console.log(span.innerHTML);
  1293. li.hot = hot // 列表每一项对应一个热点
  1294. li.appendChild(span)
  1295. docFragment.appendChild(li)
  1296. })
  1297. var ul = document.querySelector('#hotListContent ul')
  1298. ul && ul.appendChild(docFragment)
  1299. }
  1300. }
  1301. /*
  1302. 保存 JSON.stringify(editTool.hotpoint.getSavingInfo())
  1303. 可能需要再写一份保存到overlay 给旧场景项目使用
  1304. 最好后台有针对手机版的做一个压缩。压缩成几个档位。
  1305. 安卓手机firefox出现过视频mesh不可见或者闪烁的情况。
  1306. 视频最容易导致崩溃, 模型还好
  1307. 数据速率为4064kbps,1920*1080px 时测试部门电脑崩溃
  1308. 数据速率为1824kbps,720 *576px 时正常
  1309. 所以尽量降到2000以下 同时播放个数最好不超过2个 可能需要将src归零 并延迟加载、不自动播放
  1310. */