@awayjs/view
Version:
View for AwayJS
90 lines (89 loc) • 4.16 kB
JavaScript
import { __extends } from "tslib";
import { AbstractMethodError, AbstractionBase, TransformEvent } from '@awayjs/core';
import { ContainerNodeEvent } from '../events/ContainerNodeEvent';
var BoundingVolumeBase = /** @class */ (function (_super) {
__extends(BoundingVolumeBase, _super);
function BoundingVolumeBase() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(BoundingVolumeBase.prototype, "pool", {
//protected _boundsPrimitive:Sprite;
get: function () {
return this._useWeak ? this._pool.deref() : this._pool;
},
enumerable: false,
configurable: true
});
BoundingVolumeBase.prototype.init = function (asset, pool) {
var _this = this;
_super.prototype.init.call(this, asset, pool, true);
var picker = this.pool.picker;
this._targetCoordinateSpace = asset;
this._strokeFlag = pool.strokeFlag;
this._fastFlag = pool.fastFlag;
this._onInvalidateMatrix3DDelegate = function (event) { return _this._onInvalidateMatrix3D(event); };
picker.addBoundingVolume(this);
if (this._targetCoordinateSpace != picker.node) {
var targetEntity = picker.node;
while (targetEntity && targetEntity != this._targetCoordinateSpace) {
targetEntity.container.transform.addEventListener(TransformEvent.INVALIDATE_MATRIX3D, this._onInvalidateMatrix3DDelegate);
targetEntity = targetEntity.parent;
}
if (!targetEntity) //case when targetCoordinateSpace is not part of the same displaylist ancestry
this._targetCoordinateSpace.addEventListener(ContainerNodeEvent.INVALIDATE_MATRIX3D, this._onInvalidateMatrix3DDelegate);
}
};
BoundingVolumeBase.prototype._onInvalidateMatrix3D = function (event) {
this._invalid = true;
};
BoundingVolumeBase.prototype.onClear = function (event) {
var _a;
var picker = (_a = this.pool) === null || _a === void 0 ? void 0 : _a.picker;
if (picker) {
picker.removeBoundingVolume(this);
if (this._targetCoordinateSpace != picker.node) {
var targetEntity = picker.node;
while (targetEntity && targetEntity != this._targetCoordinateSpace) {
targetEntity.container.transform.removeEventListener(TransformEvent.INVALIDATE_MATRIX3D, this._onInvalidateMatrix3DDelegate);
targetEntity = targetEntity.parent;
}
if (!targetEntity) //case when targetCoordinateSpace is not part of the same displaylist ancestry
this._targetCoordinateSpace.removeEventListener(ContainerNodeEvent.INVALIDATE_MATRIX3D, this._onInvalidateMatrix3DDelegate);
}
}
this._targetCoordinateSpace = null;
_super.prototype.onClear.call(this, event);
//this._boundsPrimitive = null;
};
// public get boundsPrimitive():DisplayObject
// {
// if (this._boundsPrimitive == null) {
// this._boundsPrimitive = this._createBoundsPrimitive();
// this._invalid = true;
// }
// if(this._invalid)
// this._update();
// this._boundsPrimitive.transform.matrix3D = this._boundingEntity.transform.concatenatedMatrix3D;
// return this._boundsPrimitive;
// }
BoundingVolumeBase.prototype.nullify = function () {
throw new AbstractMethodError();
};
BoundingVolumeBase.prototype.isInFrustum = function (planes, numPlanes) {
throw new AbstractMethodError();
};
BoundingVolumeBase.prototype.clone = function () {
throw new AbstractMethodError();
};
BoundingVolumeBase.prototype.rayIntersection = function (position, direction, targetNormal) {
return -1;
};
BoundingVolumeBase.prototype.classifyToPlane = function (plane) {
throw new AbstractMethodError();
};
BoundingVolumeBase.prototype._update = function () {
this._invalid = false;
};
return BoundingVolumeBase;
}(AbstractionBase));
export { BoundingVolumeBase };