/** * 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) * @param parentEntity * @constructor */ GameLib.D3.API.Skeleton = function ( id, name, bones, boneInverses, useVertexTexture, boneTextureWidth, boneTextureHeight, boneMatrices, boneTexture, parentEntity ) { if (GameLib.Utils.UndefinedOrNull(parentEntity)) { parentEntity = null; } this.parentEntity = parentEntity; GameLib.Component.call( this, GameLib.Component.COMPONENT_SKELETON, { 'bones' : [GameLib.D3.Bone] }, false, parentEntity ); 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; }; GameLib.D3.API.Skeleton.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Skeleton.prototype.constructor = GameLib.D3.API.Skeleton; /** * 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, objectSkeleton.parentEntity ); };