r3-legacy/src/game-lib-d3-api-skeleton.js

109 lines
2.9 KiB
JavaScript
Raw Normal View History

2016-12-23 16:07:10 +01:00
/**
* API Skeleton
* @param id
* @param name
* @param bones GameLib.D3.API.Bone[]
* @param boneInverses GameLib.API.Matrix4[]
* @param useVertexTexture boolean
* @param boneTextureWidth Number
* @param boneTextureHeight Number
* @param boneMatrices GameLib.API.Matrix4[]
* @param boneTexture null (not implemented)
* @constructor
*/
GameLib.D3.API.Skeleton = function (
id,
name,
bones,
boneInverses,
useVertexTexture,
boneTextureWidth,
boneTextureHeight,
boneMatrices,
boneTexture
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Skeleton';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(bones)) {
bones = [];
}
this.bones = bones;
/**
* An array of Matrix4s that represent the inverse of the matrixWorld of the individual bones.
*/
if (GameLib.Utils.UndefinedOrNull(boneInverses)) {
boneInverses = [];
}
this.boneInverses = boneInverses;
/**
* Use a vertex texture in the shader - allows for more than 4 bones per vertex, not supported by all devices
*/
if (GameLib.Utils.UndefinedOrNull(useVertexTexture)) {
useVertexTexture = false;
}
this.useVertexTexture = useVertexTexture;
if (useVertexTexture) {
console.warn('support for vertex texture bones is not supported yet - something could break somewhere');
}
if (GameLib.Utils.UndefinedOrNull(boneTextureWidth)) {
boneTextureWidth = 0;
}
this.boneTextureWidth = boneTextureWidth;
if (GameLib.Utils.UndefinedOrNull(boneTextureHeight)) {
boneTextureHeight = 0;
}
this.boneTextureHeight = boneTextureHeight;
if (GameLib.Utils.UndefinedOrNull(boneMatrices)) {
boneMatrices = [];
}
this.boneMatrices = boneMatrices;
if (GameLib.Utils.UndefinedOrNull(boneTexture)) {
boneTexture = null;
}
this.boneTexture = boneTexture;
};
2017-01-05 19:34:28 +01:00
/**
* Creates an API skeleton from an Object skeleton
* @param objectSkeleton
* @constructor
*/
GameLib.D3.API.Skeleton.FromObjectSkeleton = function(objectSkeleton) {
return new GameLib.D3.API.Skeleton(
objectSkeleton.id,
objectSkeleton.name,
objectSkeleton.bones.map(
function (objectBone) {
return GameLib.D3.API.Bone.FromObjectBone(objectBone);
}
),
objectSkeleton.boneInverses.map(
function (boneInverse) {
return GameLib.D3.API.Matrix4.FromObjectMatrix(boneInverse);
}
),
objectSkeleton.useVertexTexture,
objectSkeleton.boneTextureWidth,
objectSkeleton.boneTextureHeight,
objectSkeleton.boneMatrices.map(
function (boneMatrix) {
return GameLib.D3.API.Matrix4.FromObjectMatrix(boneMatrix);
}
),
objectSkeleton.boneTexture
);
};