@awayjs/graphics
Version:
AwayJS graphics classes
108 lines (107 loc) • 4.03 kB
JavaScript
import { __extends } from "tslib";
import { AssetBase } from '@awayjs/core';
import { JointPose } from './JointPose';
/**
* A collection of pose objects, determining the pose for an entire skeleton.
* The <code>jointPoses</code> vector object corresponds to a skeleton's <code>joints</code> vector object, however, there is no
* reference to a skeleton's instance, since several skeletons can be influenced by the same pose (eg: animation
* clips are added to any animator with a valid skeleton)
*
* @see away.animators.Skeleton
* @see away.animators.JointPose
*/
var SkeletonPose = /** @class */ (function (_super) {
__extends(SkeletonPose, _super);
/**
* Creates a new <code>SkeletonPose</code> object.
*/
function SkeletonPose() {
var _this = _super.call(this) || this;
_this.jointPoses = new Array();
return _this;
}
Object.defineProperty(SkeletonPose.prototype, "numJointPoses", {
/**
* The total number of joint poses in the skeleton pose.
*/
get: function () {
return this.jointPoses.length;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SkeletonPose.prototype, "assetType", {
/**
* @inheritDoc
*/
get: function () {
return SkeletonPose.assetType;
},
enumerable: false,
configurable: true
});
/**
* Returns the joint pose object with the given joint name, otherwise returns a null object.
*
* @param jointName The name of the joint object whose pose is to be found.
* @return The pose object with the given joint name.
*/
SkeletonPose.prototype.jointPoseFromName = function (jointName) {
var jointPoseIndex = this.jointPoseIndexFromName(jointName);
if (jointPoseIndex != -1)
return this.jointPoses[jointPoseIndex];
else
return null;
};
/**
* Returns the pose index, given the joint name. -1 is returned if the joint name is not found in the pose.
*
* @param The name of the joint object whose pose is to be found.
* @return The index of the pose object in the jointPoses Array
*
* @see #jointPoses
*/
SkeletonPose.prototype.jointPoseIndexFromName = 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 JointPoses,
// rather than direct array access. this would be sub-optimal.
var jointPoseIndex;
var jointPose;
for (var i; i < this.jointPoses.length; i++) {
jointPose = this.jointPoses[i];
if (jointPose.name == jointName)
return jointPoseIndex;
jointPoseIndex++;
}
return -1;
};
/**
* Creates a copy of the <code>SkeletonPose</code> object, with a dulpicate of its component joint poses.
*
* @return SkeletonPose
*/
SkeletonPose.prototype.clone = function () {
var clone = new SkeletonPose();
var numJointPoses = this.jointPoses.length;
for (var i = 0; i < numJointPoses; i++) {
var cloneJointPose = new JointPose();
var thisJointPose = this.jointPoses[i];
cloneJointPose.name = thisJointPose.name;
cloneJointPose.copyFrom(thisJointPose);
clone.jointPoses[i] = cloneJointPose;
}
return clone;
};
/**
* @inheritDoc
*/
SkeletonPose.prototype.dispose = function () {
this.jointPoses.length = 0;
};
SkeletonPose.assetType = '[asset SkeletonPose]';
return SkeletonPose;
}(AssetBase));
export { SkeletonPose };