convex-pixel
Version:
The library for creating pseudo 3d interactive scenes based on webgl
88 lines • 3.5 kB
JavaScript
import { __extends } from "tslib";
import * as PIXI from "pixi.js";
import { BaseConvexObject } from "./base";
var ConvexObject = /** @class */ (function (_super) {
__extends(ConvexObject, _super);
function ConvexObject(appContext, config) {
var _this = _super.call(this, appContext, config) || this;
_this.appContext = appContext;
_this._pointerOverHandler = function () {
_this.pointerHover();
};
_this._pointerOutHandler = function () {
_this.pointerOutside();
};
_this._pointerTapHandler = function () {
_this.pointerTap();
};
return _this;
}
ConvexObject.prototype.setPOV = function (x, y) {
if (!this._displacementFilter) {
return;
}
var depth = this._config.isBackground ? 1 : this._config.depth;
this._displacementFilter.scale.x = x * depth * this.appContext.room.camera.maxZoom;
this._displacementFilter.scale.y = y * depth * this.appContext.room.camera.maxZoom;
};
/**
* Recalculation POV
* Repeat сalls are blocked
*/
ConvexObject.prototype.recalculateCameraPOV = function () {
this.appContext.room.recalculateCameraPOV();
};
ConvexObject.prototype.dispose = function () {
if (this._container) {
this._container.removeAllListeners();
}
_super.prototype.destroy.call(this);
};
ConvexObject.prototype.pointerHover = function () { };
ConvexObject.prototype.pointerOutside = function () { };
ConvexObject.prototype.pointerTap = function () { };
Object.defineProperty(ConvexObject.prototype, "originalWidth", {
get: function () {
var scale = this._container ? this._container.scale.x : 1;
return this._originalWidth * scale;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ConvexObject.prototype, "originalHeight", {
get: function () {
var scale = this._container ? this._container.scale.y : 1;
return this._originalHeight * scale;
},
enumerable: true,
configurable: true
});
ConvexObject.prototype.loadingComplete = function () {
if (!this._container) {
throw Error("Propery \"_container\" is not defined.");
}
if (this._config.interactive) {
this._container.interactive = Boolean(this._config.interactive);
if (this._config.hitArea) {
this._container.hitArea = new PIXI.Polygon(this._config.hitArea);
}
this._container.addListener("pointerover", this._pointerOverHandler);
this._container.addListener("pointerout", this._pointerOutHandler);
this._container.addListener("pointertap", this._pointerTapHandler);
}
// set pivot and scale
this._container.scale.x = this._container.scale.y = this._config.scale;
this.pivot.set(this.width * 0.5, this.height * 0.5);
_super.prototype.loadingComplete.call(this);
};
Object.defineProperty(ConvexObject.prototype, "container", {
get: function () {
return this._container;
},
enumerable: true,
configurable: true
});
return ConvexObject;
}(BaseConvexObject));
export { ConvexObject };
//# sourceMappingURL=convex-object.js.map