in packages/core/gsi/src/polaris/PolarisGSI.ts [110:202]
constructor(props: PolarisGSIProps) {
const mergedProps = {
...defaultPolarisGSIProps,
...props,
}
super(mergedProps)
this.matrixProcessor = mergedProps.matrixProcessor
this.boundingProcessor = mergedProps.boundingProcessor
this.graphProcessor = mergedProps.graphProcessor
this.cullingProcessor = mergedProps.cullingProcessor
this.view = {
html: new HtmlView(),
gsi: new GSIView(),
}
for (const key in this.view) {
this.view[key].init(this)
}
/**
* init html / canvas
*/
const container = mergedProps.container as HTMLDivElement
// render html view
this.view.html.element
this.view.html.element.style.position = 'relative'
this.view.html.element.style.width = this.width + 'px'
this.view.html.element.style.height = this.height + 'px'
this.view.html.element.style.overflow = 'hidden'
this.view.html.element.className = 'polaris-wrapper'
container.appendChild(this.view.html.element)
this.addEventListener('dispose', () => this.view.html.element.remove())
// pointer 事件
this._initPointerEvents()
// 相机控制事件
if (mergedProps.cameraControl) {
if (isTouchDevice) {
this.cameraControl = new TouchControl({
camera: this.cameraProxy,
element: this.view.html.element as HTMLElement,
})
} else {
this.cameraControl = new PointerControl({
camera: this.cameraProxy,
element: this.view.html.element as HTMLElement,
})
}
this.cameraControl.scale = 1.0 / (this.ratio ?? 1.0)
this.addEventListener('dispose', () => this.cameraControl?.dispose())
}
/**
* Props listener
*/
// Responsive for container resize
this.watchProps(
['autoResize'],
() => {
const autoResize = this.getProp('autoResize')
if (autoResize) {
if (!this._resizeListener) {
this._resizeListener = setInterval(() => {
const width = container.clientWidth
const height = container.clientHeight
if (width !== this.width || height !== this.height) {
this.resize(width, height, this.ratio)
}
}, 200)
}
} else if (this._resizeListener) {
clearInterval(this._resizeListener)
this._resizeListener = undefined
}
},
true
)
// static props (shall not change these props)
this.watchProps(
['matrixProcessor', 'boundingProcessor', 'graphProcessor', 'cullingProcessor'],
(e) => {
const msg = `Do not modify static props: [${e.changedKeys.join(',')}]`
this.dispatchEvent({ type: 'error', error: new Error(msg) })
console.error(msg)
}
)
}