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
|
|
|
) {
|
|
|
|
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-12-04 13:23:15 +01:00
|
|
|
|
|
|
|
GameLib.API.Component.call(
|
|
|
|
this,
|
|
|
|
GameLib.Component.SKELETON,
|
|
|
|
parentEntity
|
|
|
|
);
|
2016-12-23 16:07:10 +01:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
*/
|
2017-06-14 14:21:57 +02:00
|
|
|
GameLib.D3.API.Skeleton.FromObject = function(objectSkeleton) {
|
2017-01-05 19:34:28 +01:00
|
|
|
return new GameLib.D3.API.Skeleton(
|
|
|
|
objectSkeleton.id,
|
|
|
|
objectSkeleton.name,
|
|
|
|
objectSkeleton.bones.map(
|
|
|
|
function (objectBone) {
|
2017-06-14 14:21:57 +02:00
|
|
|
return GameLib.D3.API.Bone.FromObject(objectBone);
|
2017-01-05 19:34:28 +01:00
|
|
|
}
|
|
|
|
),
|
|
|
|
objectSkeleton.boneInverses.map(
|
|
|
|
function (boneInverse) {
|
2017-06-14 14:21:57 +02:00
|
|
|
return GameLib.D3.API.Matrix4.FromObject(boneInverse);
|
2017-01-05 19:34:28 +01:00
|
|
|
}
|
|
|
|
),
|
|
|
|
objectSkeleton.useVertexTexture,
|
|
|
|
objectSkeleton.boneTextureWidth,
|
|
|
|
objectSkeleton.boneTextureHeight,
|
|
|
|
objectSkeleton.boneMatrices.map(
|
|
|
|
function (boneMatrix) {
|
2017-06-14 14:21:57 +02:00
|
|
|
return GameLib.D3.API.Matrix4.FromObject(boneMatrix);
|
2017-01-05 19:34:28 +01:00
|
|
|
}
|
|
|
|
),
|
2017-01-19 17:50:11 +01:00
|
|
|
objectSkeleton.boneTexture,
|
|
|
|
objectSkeleton.parentEntity
|
2017-01-05 19:34:28 +01:00
|
|
|
);
|
|
|
|
};
|