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

130 lines
3.5 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)
2017-01-19 17:50:11 +01:00
* @param parentEntity
2016-12-23 16:07:10 +01:00
* @constructor
*/
GameLib.D3.API.Skeleton = function (
id,
name,
bones,
boneInverses,
useVertexTexture,
boneTextureWidth,
boneTextureHeight,
boneMatrices,
2017-01-19 17:50:11 +01:00
boneTexture,
parentEntity
2016-12-23 16:07:10 +01:00
) {
2017-01-19 17:50:11 +01:00
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SKELETON,
{
'bones' : [GameLib.D3.Bone]
},
false,
parentEntity
);
2016-12-23 16:07:10 +01:00
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-19 17:50:11 +01:00
GameLib.D3.API.Skeleton.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Skeleton.prototype.constructor = GameLib.D3.API.Skeleton;
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);
}
),
2017-01-19 17:50:11 +01:00
objectSkeleton.boneTexture,
objectSkeleton.parentEntity
2017-01-05 19:34:28 +01:00
);
};