@awayjs/graphics
Version:
AwayJS graphics classes
89 lines (88 loc) • 3.03 kB
JavaScript
import { __extends } from "tslib";
import { AssetBase } from '@awayjs/core';
/**
* A Skeleton object is a hierarchical grouping of joint objects that can be used for skeletal animation.
*
* @see away.animators.SkeletonJoint
*/
var Skeleton = /** @class */ (function (_super) {
__extends(Skeleton, _super);
/**
* Creates a new <code>Skeleton</code> object
*/
function Skeleton() {
var _this = _super.call(this) || this;
// in the long run, it might be a better idea to not store Joint objects, but keep all data in Vectors, that we can upload easily?
_this.joints = new Array();
return _this;
}
Object.defineProperty(Skeleton.prototype, "numJoints", {
/**
* The total number of joints in the skeleton.
*/
get: function () {
return this.joints.length;
},
enumerable: false,
configurable: true
});
/**
* Returns the joint object in the skeleton with the given name, otherwise returns a null object.
*
* @param jointName The name of the joint object to be found.
* @return The joint object with the given name.
*
* @see #joints
*/
Skeleton.prototype.jointFromName = function (jointName) {
var jointIndex = this.jointIndexFromName(jointName);
if (jointIndex != -1)
return this.joints[jointIndex];
else
return null;
};
/**
* Returns the joint index, given the joint name. -1 is returned if the joint name is not found.
*
* @param jointName The name of the joint object to be found.
* @return The index of the joint object in the joints Array
*
* @see #joints
*/
Skeleton.prototype.jointIndexFromName = function (jointName) {
// this is implemented as a linear search, rather than a possibly
// more optimal method (Dictionary lookup, for example) because:
// a) it is assumed that it will be called once for each joint
// b) it is assumed that it will be called only during load, and not during main loop
// c) maintaining a dictionary (for safety) would dictate an interface to access SkeletonJoints,
// rather than direct array access. this would be sub-optimal.
var jointIndex;
var joint;
for (var i; i < this.joints.length; i++) {
joint = this.joints[i];
if (joint.name == jointName)
return jointIndex;
jointIndex++;
}
return -1;
};
/**
* @inheritDoc
*/
Skeleton.prototype.dispose = function () {
this.joints.length = 0;
};
Object.defineProperty(Skeleton.prototype, "assetType", {
/**
* @inheritDoc
*/
get: function () {
return Skeleton.assetType;
},
enumerable: false,
configurable: true
});
Skeleton.assetType = '[asset Skeleton]';
return Skeleton;
}(AssetBase));
export { Skeleton };