94 lines
2.3 KiB
TypeScript
94 lines
2.3 KiB
TypeScript
import { Point_Pool } from './Point_Pool'
|
|
import { Point } from './Point'
|
|
import {
|
|
AbstractMesh,
|
|
ArcRotateCamera,
|
|
Engine,
|
|
Matrix,
|
|
Scene,
|
|
Vector3,
|
|
Texture,
|
|
StandardMaterial,
|
|
MeshBuilder,
|
|
TransformNode
|
|
} from '@babylonjs/core'
|
|
import { HotspotPrams } from './HotspotPrams'
|
|
import type { MainApp } from '../babylonjs/MainApp'
|
|
|
|
class HotSpot {
|
|
_point_Pool!: Point_Pool
|
|
body!: HTMLElement
|
|
_camera!: ArcRotateCamera
|
|
mainApp!: MainApp
|
|
hotspotTexture!: Texture
|
|
hotspotMaterial!: StandardMaterial
|
|
hotspotContainer!: TransformNode
|
|
|
|
vector!: Vector3
|
|
halfW!: number
|
|
halfH!: number
|
|
annotation!: HTMLElement
|
|
modedl!: AbstractMesh
|
|
|
|
|
|
constructor(mainAPP: MainApp) {
|
|
this.mainApp = mainAPP
|
|
}
|
|
|
|
Awake() {
|
|
this._camera = this.mainApp.appCamera.object
|
|
this._point_Pool = new Point_Pool()
|
|
|
|
// 创建热点容器
|
|
this.hotspotContainer = new TransformNode('hotspotContainer', this.mainApp.appScene.object)
|
|
}
|
|
|
|
|
|
//创建圆点并且生成事件 类型
|
|
Point_Event(prams: HotspotPrams) {
|
|
const iconPath = prams.icon
|
|
|
|
|
|
// 为每个热点创建独立的材质
|
|
const texture = new Texture(iconPath, this.mainApp.appScene.object)
|
|
texture.hasAlpha = true
|
|
texture.getAlphaFromRGB = false
|
|
|
|
const material = new StandardMaterial(`hotspotMaterial_${Math.random()}`, this.mainApp.appScene.object)
|
|
material.diffuseTexture = texture
|
|
material.emissiveTexture = texture
|
|
material.opacityTexture = texture
|
|
material.useAlphaFromDiffuseTexture = true
|
|
material.transparencyMode = 2 // ALPHABLEND 模式
|
|
material.disableLighting = true
|
|
material.backFaceCulling = false
|
|
|
|
// 检查纹理是否已加载
|
|
|
|
this.createPointPlane(prams, material)
|
|
|
|
|
|
}
|
|
|
|
// 创建点平面的具体实现
|
|
createPointPlane(prams: HotspotPrams, material: StandardMaterial) {
|
|
let { position, disposition, onload, onCallBack } = prams
|
|
let _point = new Point(material, this.hotspotContainer, this.mainApp.appScene.object)
|
|
_point.init(position, disposition, onload, onCallBack, prams.radius)
|
|
|
|
// 将热点添加到热点池中
|
|
this._point_Pool.Add_point(_point)
|
|
|
|
}
|
|
|
|
|
|
|
|
Enable_All(visible: boolean) {
|
|
if (this._point_Pool) {
|
|
this._point_Pool.Enable_All(visible)
|
|
}
|
|
}
|
|
}
|
|
|
|
export { HotSpot }
|