Character.kl

Types

Character (object)

An object defining a high level character.

The Character object defining a characters by combining a skeleton, pose and a set of geometries to be deformed.

参考

Skeleton, Pose

/*
** Example: character.kl
*/

require Characters;

operator entry(){

  //////////////////////////////////
  // Generate a chain of bones with a random shape.
  Bone bones[];
  bones.resize(5);
  Xfo parentXfo();
  for(Integer i=0; i<bones.size(); i++) {

    Bone bone;
    bone.name = "Bone"+i;
    bone.parentIndex = i-1;

    // compute the angles
    Scalar random = 0.5 - mathRandomScalar(12, i);
    Scalar xAngle = sin(random * 0.4 + Scalar(i) * 0.03) * 0.5;
    Scalar zAngle = cos(0.11 + Scalar(i) * 0.01) * 0.1;

    Scalar boneLength = 5.0;
    Xfo xfo;
    xfo.tr = Vec3(boneLength, 0.0, 0.0);
    xfo.ori.setFromEulerAngles(Vec3(xAngle, 0.0f, zAngle));
    bone.referencePose = parentXfo * xfo;
    bone.length = boneLength;
    bone.radius = 1.0;
    bone.setFlag(BONEFLAG_DEFORMER);
    bones[i] = bone;
    parentXfo = bone.referencePose;
  }

  Skeleton skeleton = Skeleton("", bones);
  Character character('Clip');
  character.setSkeleton(skeleton);

  report(character.getDesc());

  LocalBoundingVolume bvol = character.getBoundingVolume();
  report(bvol);


}

/*
** Output:

Character:{ 
  name: Clip 
  skeleton:  Skeleton { 
    name:  
    bones:[ 
      Bone { 
        name: Bone0
        length: +5.0
        radius: +1.0
        parent: -1
        childIndices: [1]
        mirrorBoneID: -1
        flags: 8
        color: {r:+1.0,g:+1.0,b:+0.0,a:+1.0}
        referencePose: {tr:{x:+5.0,y:+0.0,z:+0.0},ori:{v:{x:-2.880096e-2,y:+1.432657e-3,z:+0.049659},w:+0.998291},sc:{x:+1.0,y:+1.0,z:+1.0}}
      } 
      Bone { 
        name: Bone1
        length: +5.0
        radius: +1.0
        parent: 0
        childIndices: [2]
        mirrorBoneID: -1
        flags: 8
        color: {r:+1.0,g:+1.0,b:+0.0,a:+1.0}
        referencePose: {tr:{x:+9.974609,y:+0.495361,z:-2.860641e-2},ori:{v:{x:-0.040725,y:+2.859115e-3,z:+0.099121},w:+0.994262},sc:{x:+1.0,y:+1.0,z:+1.0}}
      } 
      Bone { 
        name: Bone2
        length: +5.0
        radius: +1.0
        parent: 1
        childIndices: [3]
        mirrorBoneID: -1
        flags: 8
        color: {r:+1.0,g:+1.0,b:+0.0,a:+1.0}
        referencePose: {tr:{x:+14.87695,y:+1.479736,z:-0.097396},ori:{v:{x:-1.088905e-2,y:+0.634861e-2,z:+0.148193},w:+0.988891},sc:{x:+1.0,y:+1.0,z:+1.0}}
      } 
      Bone { 
        name: Bone3
        length: +5.0
        radius: +1.0
        parent: 2
        childIndices: [4]
        mirrorBoneID: -1
        flags: 8
        color: {r:+1.0,g:+1.0,b:+0.0,a:+1.0}
        referencePose: {tr:{x:+19.65625,y:+2.944336,z:-0.17633},ori:{v:{x:+1.734161e-2,y:+0.965499e-2,z:+0.196716},w:+0.980224},sc:{x:+1.0,y:+1.0,z:+1.0}}
      } 
      Bone { 
        name: Bone4
        length: +5.0
        radius: +1.0
        parent: 3
        childIndices: []
        mirrorBoneID: -1
        flags: 8
        color: {r:+1.0,g:+1.0,b:+0.0,a:+1.0}
        referencePose: {tr:{x:+24.26953,y:+4.874023,z:-0.236846},ori:{v:{x:+0.055099,y:+1.436615e-2,z:+0.244323},w:+0.968017},sc:{x:+1.0,y:+1.0,z:+1.0}}
      } 
    ]
  } 
  pose:  Pose { 
    xfos:[ 
    {tr:{x:+5.0,y:+0.0,z:+0.0},ori:{v:{x:-2.880096e-2,y:+1.432657e-3,z:+0.049659},w:+0.998291},sc:{x:+1.0,y:+1.0,z:+1.0}}
    {tr:{x:+9.974609,y:+0.495361,z:-2.860641e-2},ori:{v:{x:-0.040725,y:+2.859115e-3,z:+0.099121},w:+0.994262},sc:{x:+1.0,y:+1.0,z:+1.0}}
    {tr:{x:+14.87695,y:+1.479736,z:-0.097396},ori:{v:{x:-1.088905e-2,y:+0.634861e-2,z:+0.148193},w:+0.988891},sc:{x:+1.0,y:+1.0,z:+1.0}}
    {tr:{x:+19.65625,y:+2.944336,z:-0.17633},ori:{v:{x:+1.734161e-2,y:+0.965499e-2,z:+0.196716},w:+0.980224},sc:{x:+1.0,y:+1.0,z:+1.0}}
    {tr:{x:+24.26953,y:+4.874023,z:-0.236846},ori:{v:{x:+0.055099,y:+1.436615e-2,z:+0.244323},w:+0.968017},sc:{x:+1.0,y:+1.0,z:+1.0}}
    ]
  } 
  num geometries:0 
  geometries:[ 
  ]
}
{type:1,pt1:{x:+0.0,y:+0.0,z:+0.0},pt2:{x:+0.0,y:+0.0,z:+0.0},sc1:-1.0,sc2:+0.0,sc3:+0.0,sc4:+0.0}

*/

Members

String name The name of the character.
Geometry[] geometries The array fo geometries that make up the character
Mat44[] bindShapeTransforms  
Mat44[] skinningMatrices  
Skeleton skeleton The Skeleton defining the hierarchy of bones of the character.
IPose pose The pose of the character.
Xfo globalXfo The global transform of the character.
Geometry[] deformedGeometries The cache of deformed geometries that make up the character. When deforming on the CPU, we cache the cloned meshes here.
LocalBoundingVolume localBVol The bounding volume of the deformed character.

Methods

  Character ( in Character other )
  Character ( in Character other, in String nameSuffix )
  Character ( in String name )
  Character ()
Character clone ? ()
Mat44 getBindShapeTransform ? ( in Index index )
LocalBoundingVolume getBoundingVolume ? ()
Geometry getDeformedGeometry ! ( in Index index )
PolygonMesh getDeformedMesh ! ( in Index index )
String getDesc ? ( in String indent, in Boolean includeGeometries )
String getDesc ? ()
Geometry getGeometry ? ( in Index index )
Xfo getGlobalXfo ? ()
PolygonMesh getMesh ? ( in Index index )
String getName ? ()
Size getNumGeometries ? ()
IPose getPose ? ()
ISkeleton getSkeleton ? ()
Mat44[] getSkinningMatrices ? ()
UInt64 getVersion ? ()
  incrementVersion ! ()
  setClipPoseTime ! ( in Float32 time )
  setGlobalXfo ! ( in Xfo globalXfo )
  setPose ! ( in IPose pose )
  setSkeleton ! ( in Skeleton skeleton )