Skeleton (object)¶
The Skeleton object defines a skeleton hierarchy made up of an array of bones.
The Skeleton object defines a skeleton hierarchy made up of an array of bones. The bones arrays is assumed to be sorted in order of hierarchical traversal meaning that no bones parent can occur after it in the array.
/*
** Example: skeleton.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("MySkeleton", bones);
report(skeleton.getDesc());
}
/*
** Output:
Skeleton {
name: MySkeleton
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}}
}
]
}
*/
Members¶
String | name | The name of the skeleton. |
Bone[] | bones | The array of bones in the skeleton. |
Xfo[] | referenceLocalPoses | A cache of the local reference poses for the skeleton. Solvers often use these values to compute offsets during animation. |
UInt64 | version | /private. |
Size[] | deformerIndices | a cache of the bone indices used as deformers. |
Methods¶
Skeleton ( in Skeleton other ) | |
Skeleton ( in String name ) | |
Skeleton ( in String name, in Bone bones[] ) | |
Skeleton () | |
addBone ! ( in Bone bone ) | |
Skeleton | clone ? () |
computeSymmetry ! () | |
Integer | findBone ? ( in String boneName ) |
Integer | findBone ? ( in String boneName, in Index startingPoint ) |
Bone[] | getAllBones ? () |
Bone | getBone ? ( in Index index ) |
Bone[] | getBones ? () |
Size[] | getDeformerIndices ? () |
Bone[] | getDeformers ? () |
String | getDesc ? ( in String indent, in Boolean includeBones ) |
String | getDesc ? () |
String | getName ? () |
Size | getNumBones ? () |
Xfo | getReferenceLocalPose ? ( in Index index ) |
Xfo | getReferencePose ? ( in Index index ) |
UInt64 | getVersion ? () |
incrementVersion ! () | |
recomputeHierarchy ! () |
Methods in detail¶
Skeleton ( in Skeleton other )
copy constructor
Constructs a skeleton using the given name.
Skeleton ( in String name, in Bone bones[] )
Constructs a skeleton using the given name and bones array.
Skeleton ()
default constructor
Skeleton.addBone! ( in Bone bone )
Adds a new bone to the skeleton.
clone method
Skeleton.computeSymmetry! ()
Updates the symmetry information in the skeleton by comparing the reference transform of bones in the hierarchy.
注釈
this method is unreliable, as multiple joints are often overlaid at the same reference position.
Integer Skeleton.findBone? ( in String boneName )
Finds a bone in the skeleton by name.
Integer Skeleton.findBone? ( in String boneName, in Index startingPoint )
Finds a bone in the skeleton by name, and a starting point.
Bone[] Skeleton.getAllBones? ()
Returns a bone based on the given index.
Bone Skeleton.getBone? ( in Index index )
Returns a bone based on the given index.
Finds a bone in the skeleton by name.
Size[] Skeleton.getDeformerIndices? ()
Returns the array of indices of bones which have the BONEFLAG_DEFORMER flag set.
Bone[] Skeleton.getDeformers? ()
Returns an array of bones which have the BONEFLAG_DEFORMER flag set.
String Skeleton.getDesc? ( in String indent, in Boolean includeBones )
Generates a Description string of this skeleton. Used when debugging skeleton hierarchies.
indent | The indentation to use when generating the string. |
Generates a Description string of this skeleton. Used when debugging skeleton hierarchies.
Returns the name of the skeleton
Size Skeleton.getNumBones? ()
Returns the number of bones in the bones array.
Xfo Skeleton.getReferenceLocalPose? ( in Index index )
Returns the reference local pose for a bone based on the given index.
Xfo Skeleton.getReferencePose? ( in Index index )
Returns the reference pose for a bone based on the given index.
UInt64 Skeleton.getVersion? ()
Returns the current version of the skeleton
Skeleton.incrementVersion! ()
Increments the version of the skeleton. skeleton to become invalid.
注釈
this will cause any caches based on the
Skeleton.recomputeHierarchy! ()
Recomputes the relationships between bones in the hierarchy. The child indices for each bone are updated bases on the bones listing each bone as a parent. The referenceLocalPoses are updated based on the referencePoses of the bones and thier hierarchical relationships.