@awayjs/stage
Version:
Stage for AwayJS
149 lines (148 loc) • 5.31 kB
JavaScript
import { __extends } from "tslib";
import { Point } from '@awayjs/core';
import { BitmapImage2D } from './BitmapImage2D';
import { BitmapImageChannel } from './BitmapImageChannel';
import { Image2D } from './Image2D';
/**
*
*/
var SpecularImage2D = /** @class */ (function (_super) {
__extends(SpecularImage2D, _super);
/**
*
*/
function SpecularImage2D(specularSource, glossSource) {
if (specularSource === void 0) { specularSource = null; }
if (glossSource === void 0) { glossSource = null; }
var _this = _super.call(this, 1, 1) || this;
_this._specularSource = specularSource;
_this._glossSource = glossSource;
_this._output = new BitmapImage2D(1, 1, false, 0xffffff);
_this._testSize();
return _this;
}
Object.defineProperty(SpecularImage2D.prototype, "assetType", {
/**
*
* @returns {string}
*/
get: function () {
return SpecularImage2D.assetType;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SpecularImage2D.prototype, "specularSource", {
get: function () {
return this._specularSource;
},
set: function (value) {
if (this._specularSource == value)
return;
this._specularSource = value;
this.invalidate();
this._testSize();
},
enumerable: false,
configurable: true
});
Object.defineProperty(SpecularImage2D.prototype, "glossSource", {
get: function () {
return this._glossSource;
},
set: function (value) {
if (this._glossSource == value)
return;
this._glossSource = value;
this.invalidate();
this._testSize();
},
enumerable: false,
configurable: true
});
/**
* Returns a new SpecularImage2D object that is a clone of the original instance
* with an exact copy of the contained bitmap.
*
* @return A new SpecularImage2D object that is identical to the original.
*/
SpecularImage2D.prototype.clone = function () {
return new SpecularImage2D(this._specularSource, this._glossSource);
};
/**
* Frees memory that is used to store the SpecularImage2D object.
*
* <p>When the <code>dispose()</code> method is called on an image, the width
* and height of the image are set to 0. All subsequent calls to methods or
* properties of this SpecularImage2D instance fail, and an exception is thrown.
* </p>
*
* <p><code>SpecularImage2D.dispose()</code> releases the memory occupied by the
* actual bitmap data, immediately(a bitmap can consume up to 64 MB of
* memory). After using <code>SpecularImage2D.dispose()</code>, the SpecularImage2D
* object is no longer usable and an exception may be thrown if
* you call functions on the SpecularImage2D object. However,
* <code>SpecularImage2D.dispose()</code> does not garbage collect the SpecularImage2D
* object(approximately 128 bytes); the memory occupied by the actual
* SpecularImage2D object is released at the time the SpecularImage2D object is
* collected by the garbage collector.</p>
*
*/
SpecularImage2D.prototype.dispose = function () {
_super.prototype.dispose.call(this);
this._rect = null;
this._output.dispose();
};
Object.defineProperty(SpecularImage2D.prototype, "data", {
/**
*
* @returns {ImageData}
*/
get: function () {
var origin = new Point();
this._output.fillRect(this._rect, 0xffffff);
if (this._glossSource)
this._output.copyChannel(this._glossSource, this._rect, origin, BitmapImageChannel.GREEN, BitmapImageChannel.GREEN);
if (this._specularSource)
this._output.copyChannel(this._specularSource, this._rect, origin, BitmapImageChannel.RED, BitmapImageChannel.RED);
return this._output.data;
},
enumerable: false,
configurable: true
});
/**
*
* @param width
* @param height
* @private
*/
SpecularImage2D.prototype._setSize = function (width, height) {
_super.prototype._setSize.call(this, width, height);
this._output._setSize(width, height);
};
SpecularImage2D.prototype._testSize = function () {
var w, h;
if (this._specularSource) {
w = this._specularSource.width;
h = this._specularSource.height;
}
else if (this._glossSource) {
w = this._glossSource.width;
h = this._glossSource.height;
}
else {
w = 1;
h = 1;
}
if (w != this._output.width && h != this._output.height) {
this._output.dispose();
this._output = new BitmapImage2D(w, h, false, 0xffffff);
}
this._setSize(w, h);
};
SpecularImage2D.assetType = '[asset SpecularImage2D]';
return SpecularImage2D;
}(Image2D));
export { SpecularImage2D };
// MOVED TO LIB INDEX
// Stage.registerAbstraction(_Stage_BitmapImage2D, SpecularImage2D);