UNPKG

@awayjs/renderer

Version:
147 lines (146 loc) 5 kB
import { __extends } from "tslib"; import { AssetBase } from '@awayjs/core'; import { StyleEvent } from '../events/StyleEvent'; /** * */ var Style = /** @class */ (function (_super) { __extends(Style, _super); function Style() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._samplers = {}; _this._images = {}; _this._color = 0xFFFFFF; return _this; } Object.defineProperty(Style.prototype, "sampler", { get: function () { return this._sampler; }, set: function (value) { if (this._sampler == value) return; this._sampler = value; this._invalidateProperties(); }, enumerable: false, configurable: true }); Object.defineProperty(Style.prototype, "image", { get: function () { return this._image; }, set: function (value) { if (this._image == value) return; if (this._image) this._image.removeOwner(this); this._image = value; if (this._image) this._image.addOwner(this); this._invalidateProperties(); }, enumerable: false, configurable: true }); Object.defineProperty(Style.prototype, "uvMatrix", { get: function () { return this._uvMatrix; }, set: function (value) { if (this._uvMatrix == value) return; this._uvMatrix = value; this._invalidateProperties(); }, enumerable: false, configurable: true }); Object.defineProperty(Style.prototype, "color", { /** * The diffuse reflectivity color of the surface. */ get: function () { return this._color; }, set: function (value) { if (this._color == value) return; this._color = value; this._invalidateProperties(); }, enumerable: false, configurable: true }); Style.prototype.getImageAt = function (texture, index) { var _a; if (index === void 0) { index = 0; } return ((_a = this._images[texture.id]) === null || _a === void 0 ? void 0 : _a[index]) || this._image; }; Style.prototype.getSamplerAt = function (texture, index) { var _a; if (index === void 0) { index = 0; } return ((_a = this._samplers[texture.id]) === null || _a === void 0 ? void 0 : _a[index]) || this._sampler; }; Style.prototype.addImageAt = function (image, texture, index) { if (index === void 0) { index = 0; } if (!this._images[texture.id]) this._images[texture.id] = {}; this._images[texture.id][index] = image; this._image.addOwner(this); this._invalidateProperties(); }; Style.prototype.addSamplerAt = function (sampler, texture, index) { if (index === void 0) { index = 0; } if (!this._samplers[texture.id]) this._samplers[texture.id] = {}; this._samplers[texture.id][index] = sampler; this._invalidateProperties(); }; Style.prototype.removeImageAt = function (texture, index) { var _a; if (index === void 0) { index = 0; } var image = (_a = this._images[texture.id]) === null || _a === void 0 ? void 0 : _a[index]; if (!image) return; this._image.removeOwner(this); this._images[texture.id][index] = null; this._invalidateProperties(); }; Style.prototype.removeSamplerAt = function (texture, index) { if (index === void 0) { index = 0; } if (!this._samplers[texture.id]) return; this._samplers[texture.id][index] = null; this._invalidateProperties(); }; Style.prototype._invalidateProperties = function () { this.dispatchEvent(new StyleEvent(StyleEvent.INVALIDATE_PROPERTIES, this)); }; Style.prototype.onImageInvalidate = function (image) { this.dispatchEvent(new StyleEvent(StyleEvent.INVALIDATE_IMAGES, this)); }; Style.prototype.onImageClear = function (image) { //remove image if it has been disposed if (image.isDisposed) { if (this._image == image) { this.image = null; } else { //find and remove diposed image loop: for (var id in this._images) { var images = this._images[id]; for (var index in images) { if (images[index] == image) { delete images[index]; break loop; } } } } } this._invalidateProperties(); }; return Style; }(AssetBase)); export { Style };