@awayjs/view
Version:
View for AwayJS
89 lines (75 loc) • 3.54 kB
text/typescript
import { IAbstractionPool, IAbstractionClass, IAsset, UUID, IAbstraction } from '@awayjs/core';
import { BoundingVolumeType } from './BoundingVolumeType';
import { BoundingBox } from './BoundingBox';
import { BoundingSphere } from './BoundingSphere';
import { NullBounds } from './NullBounds';
import { IBoundsPicker } from '../pick/IBoundsPicker';
export class BoundingVolumePool implements IAbstractionPool {
private static _boundingBoxStore: IAbstraction[] = [];
private static _boundingSphereStore: IAbstraction[] = [];
private static _nullStore: IAbstraction[] = [];
private static _storeDict: Object = {
[] : BoundingVolumePool._boundingBoxStore,
[] : BoundingVolumePool._boundingBoxStore,
[] : BoundingVolumePool._boundingBoxStore,
[] : BoundingVolumePool._boundingBoxStore,
[] : BoundingVolumePool._boundingSphereStore,
[] : BoundingVolumePool._boundingSphereStore,
[] : BoundingVolumePool._boundingSphereStore,
[] : BoundingVolumePool._boundingSphereStore,
[] : BoundingVolumePool._nullStore
}
private static _strokeDict: Object = {
[] : false,
[] : false,
[] : true,
[] : true,
[] : false,
[] : false,
[] : true,
[] : true,
[] : false
}
private static _fastDict: Object = {
[] : false,
[] : true,
[] : false,
[] : true,
[] : false,
[] : true,
[] : false,
[] : true,
[] : false
}
private static _boundsDict: Object = {
[] : BoundingBox,
[] : BoundingBox,
[] : BoundingBox,
[] : BoundingBox,
[] : BoundingSphere,
[] : BoundingSphere,
[] : BoundingSphere,
[] : BoundingSphere,
[] : NullBounds
}
private readonly _boundingVolumeClass: IAbstractionClass;
private readonly _store: IAbstraction[];
public readonly picker: IBoundsPicker;
public readonly strokeFlag: boolean;
public readonly fastFlag: boolean;
public readonly id: number;
constructor(picker: IBoundsPicker, boundingVolumeType: BoundingVolumeType) {
this.id = UUID.Next();
this.picker = picker;
this.strokeFlag = BoundingVolumePool._strokeDict[boundingVolumeType];
this.fastFlag = BoundingVolumePool._fastDict[boundingVolumeType];
this._boundingVolumeClass = BoundingVolumePool._boundsDict[boundingVolumeType];
this._store = BoundingVolumePool._storeDict[boundingVolumeType];
}
public requestAbstraction(asset: IAsset): IAbstraction {
return this._store.length ? this._store.pop() : new this._boundingVolumeClass();
}
public storeAbstraction(abstraction: IAbstraction): void {
this._store.push(abstraction);
}
}