awayjs-display
Version:
AwayJS displaylist classes
204 lines • 7.06 kB
JavaScript
"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");
/**
* LightPickerBase provides an abstract base clase for light picker classes. These classes are responsible for
* feeding materials with relevant lights. Usually, StaticLightPicker can be used, but LightPickerBase can be
* extended to provide more application-specific dynamic selection of lights.
*
* @see StaticLightPicker
*/
var LightPickerBase = (function (_super) {
__extends(LightPickerBase, _super);
/**
* Creates a new LightPickerBase object.
*/
function LightPickerBase() {
_super.call(this);
this._pNumPointLights = 0;
this._pNumDirectionalLights = 0;
this._pNumCastingPointLights = 0;
this._pNumCastingDirectionalLights = 0;
this._pNumLightProbes = 0;
}
/**
* Disposes resources used by the light picker.
*/
LightPickerBase.prototype.dispose = function () {
};
Object.defineProperty(LightPickerBase.prototype, "assetType", {
/**
* @inheritDoc
*/
get: function () {
return LightPickerBase.assetType;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "numDirectionalLights", {
/**
* The maximum amount of directional lights that will be provided.
*/
get: function () {
return this._pNumDirectionalLights;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "numPointLights", {
/**
* The maximum amount of point lights that will be provided.
*/
get: function () {
return this._pNumPointLights;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "numCastingDirectionalLights", {
/**
* The maximum amount of directional lights that cast shadows.
*/
get: function () {
return this._pNumCastingDirectionalLights;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "numCastingPointLights", {
/**
* The amount of point lights that cast shadows.
*/
get: function () {
return this._pNumCastingPointLights;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "numLightProbes", {
/**
* The maximum amount of light probes that will be provided.
*/
get: function () {
return this._pNumLightProbes;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "pointLights", {
/**
* The collected point lights to be used for shading.
*/
get: function () {
return this._pPointLights;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "directionalLights", {
/**
* The collected directional lights to be used for shading.
*/
get: function () {
return this._pDirectionalLights;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "castingPointLights", {
/**
* The collected point lights that cast shadows to be used for shading.
*/
get: function () {
return this._pCastingPointLights;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "castingDirectionalLights", {
/**
* The collected directional lights that cast shadows to be used for shading.
*/
get: function () {
return this._pCastingDirectionalLights;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "lightProbes", {
/**
* The collected light probes to be used for shading.
*/
get: function () {
return this._pLightProbes;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "lightProbeWeights", {
/**
* The weights for each light probe, defining their influence on the object.
*/
get: function () {
return this._pLightProbeWeights;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LightPickerBase.prototype, "allPickedLights", {
/**
* A collection of all the collected lights.
*/
get: function () {
return this._pAllPickedLights;
},
enumerable: true,
configurable: true
});
/**
* Updates set of lights for a given renderable and EntityCollector. Always call super.collectLights() after custom overridden code.
*/
LightPickerBase.prototype.collectLights = function (entity) {
this.updateProbeWeights(entity);
};
/**
* Updates the weights for the light probes, based on the renderable's position relative to them.
* @param renderable The renderble for which to calculate the light probes' influence.
*/
LightPickerBase.prototype.updateProbeWeights = function (entity) {
// todo: this will cause the same calculations to occur per TriangleGraphic. See if this can be improved.
var objectPos = entity.scenePosition;
var lightPos;
var rx = objectPos.x, ry = objectPos.y, rz = objectPos.z;
var dx, dy, dz;
var w, total = 0;
var i;
// calculates weights for probes
for (i = 0; i < this._pNumLightProbes; ++i) {
lightPos = this._pLightProbes[i].scenePosition;
dx = rx - lightPos.x;
dy = ry - lightPos.y;
dz = rz - lightPos.z;
// weight is inversely proportional to square of distance
w = dx * dx + dy * dy + dz * dz;
// just... huge if at the same spot
w = w > .00001 ? 1 / w : 50000000;
this._pLightProbeWeights[i] = w;
total += w;
}
// normalize
total = 1 / total;
for (i = 0; i < this._pNumLightProbes; ++i)
this._pLightProbeWeights[i] *= total;
};
LightPickerBase.assetType = "[asset LightPicker]";
return LightPickerBase;
}(AssetBase_1.default));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = LightPickerBase;
//# sourceMappingURL=LightPickerBase.js.map