UNPKG

awayjs-display

Version:
142 lines 4.89 kB
"use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var AssetBase_1 = require("awayjs-core/lib/library/AssetBase"); var RenderableEvent_1 = require("../events/RenderableEvent"); var StyleEvent_1 = require("../events/StyleEvent"); /** * Graphic wraps a Elements as a scene graph instantiation. A Graphic is owned by a Sprite object. * * * @see away.base.ElementsBase * @see away.entities.Sprite * * @class away.base.Graphic */ var Graphic = (function (_super) { __extends(Graphic, _super); /** * Creates a new Graphic object */ function Graphic(index, parent, elements, material, style) { var _this = this; if (material === void 0) { material = null; } if (style === void 0) { style = null; } _super.call(this); this._iIndex = 0; this._onInvalidatePropertiesDelegate = function (event) { return _this._onInvalidateProperties(event); }; this._iIndex = index; this.parent = parent; this.elements = elements; this.material = material; this.style = style; } Object.defineProperty(Graphic.prototype, "assetType", { /** * */ get: function () { return Graphic.assetType; }, enumerable: true, configurable: true }); Object.defineProperty(Graphic.prototype, "animator", { /** * */ get: function () { return this.parent.animator; }, enumerable: true, configurable: true }); Object.defineProperty(Graphic.prototype, "material", { //TODO test shader picking // public get shaderPickingDetails():boolean // { // // return this.sourceEntity.shaderPickingDetails; // } /** * The material used to render the current TriangleGraphic. If set to null, its parent Sprite's material will be used instead. */ get: function () { return this._material || this.parent.material; }, set: function (value) { if (this.material) this.material.iRemoveOwner(this); this._material = value; if (this.material) this.material.iAddOwner(this); }, enumerable: true, configurable: true }); Object.defineProperty(Graphic.prototype, "style", { /** * The style used to render the current TriangleGraphic. If set to null, its parent Sprite's style will be used instead. */ get: function () { return this._style || this.parent.style; }, set: function (value) { if (this._style == value) return; if (this._style) this._style.removeEventListener(StyleEvent_1.default.INVALIDATE_PROPERTIES, this._onInvalidatePropertiesDelegate); this._style = value; if (this._style) this._style.addEventListener(StyleEvent_1.default.INVALIDATE_PROPERTIES, this._onInvalidatePropertiesDelegate); this.invalidateSurface(); }, enumerable: true, configurable: true }); /** * */ Graphic.prototype.dispose = function () { _super.prototype.dispose.call(this); this.parent.removeGraphic(this); this.parent = null; Graphic._available.push(this); }; Graphic.prototype.invalidateElements = function () { this.dispatchEvent(new RenderableEvent_1.default(RenderableEvent_1.default.INVALIDATE_ELEMENTS, this)); }; Graphic.prototype.invalidateSurface = function () { this.dispatchEvent(new RenderableEvent_1.default(RenderableEvent_1.default.INVALIDATE_RENDER_OWNER, this)); }; Graphic.prototype._iGetExplicitMaterial = function () { return this._material; }; Graphic.prototype._iGetExplicitStyle = function () { return this._style; }; Graphic.prototype._onInvalidateProperties = function (event) { this.invalidateSurface(); }; /** * //TODO * * @param shortestCollisionDistance * @param findClosest * @returns {boolean} * * @internal */ Graphic.prototype._iTestCollision = function (pickingCollision, pickingCollider) { return this.elements._iTestCollision(pickingCollider, this.material, pickingCollision); }; Graphic._available = new Array(); Graphic.assetType = "[asset Graphic]"; return Graphic; }(AssetBase_1.default)); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = Graphic; //# sourceMappingURL=Graphic.js.map