Public Member Functions | Static Public Member Functions | Properties

CC3SkinSection Class Reference

A CC3SkinSection defines a section of the skin mesh, and contains a collection of bones from the skeleton that influence the locations of the vertices in that section. More...

#import <CC3VertexSkinning.h>

Inheritance diagram for CC3SkinSection:
Inheritance graph
[legend]
Collaboration diagram for CC3SkinSection:
Collaboration graph
[legend]

List of all members.

Public Member Functions

(void) - addBone:
(id) - copyForNode:
(id) - copyForNode:withZone:
(void) - drawVerticesOfMesh:withVisitor:
(NSString *) - fullDescription
(id) - initForNode:
(void) - reattachBonesFrom:

Static Public Member Functions

(id) + boneBatchForNode:

Properties

CCArray * bones
GLint vertexCount
GLint vertexStart

Detailed Description

A CC3SkinSection defines a section of the skin mesh, and contains a collection of bones from the skeleton that influence the locations of the vertices in that section.

The skin section is expressed as a range of consecutive vertices from the mesh, as specified by the vertexStart and vertexCount properties. These properties define the first vertex of the section and the number of vertices in the section, respectively.

The skin section also contains a collection of bones that influence the vertices in the skin section. The bones are ordered in that collection such that the index of a bone in the collection corresponds to the index held for a vertex in the boneMatrixIndices vertex array of the CC3SkinMesh.

Through the CC3VertexMatrixIndices vertex array in the boneMatrixIndices property of the mesh, each vertex identifies several distinct indices into the bones collection of this skin section. The transform matrices from those bones are combined in a weighted fashion, and used to transform the location of the vertex. Each vertex defines its own set of weights through the CC3VertexWeights vertex array in the boneWeights property of the mesh.


Member Function Documentation

- (void) addBone: (CC3Bone *)  aNode

Adds the specified bone node to the collection of bones in the bones property.

See the notes for the bones property for more information about bones.

When the vertices are drawn, all of the vertices in this skin section are drawn with a single call to the GL engine. All of the bone transforms that affect any of the vertices being drawn are loaded into the GL engine by this skin section prior to drawing the vertices.

The number of transform matrices that can be simultaneously loaded into the GL engine matrix palette is limited by the platform, and that limit defines the maximum number of bones in the collection in this property. This platform limit can be retrieved from [CC3OpenGLES11Engine engine].platform.maxPaletteMatrices.value.

+ (id) boneBatchForNode: (CC3SkinMeshNode *)  aNode

Allocates and initializes an autoreleased instance that will be used by the specified skin mesh node.

- (id) copyForNode: (CC3SkinMeshNode *)  aNode

Returns a copy of this skin section, for use by the specified skin mesh node.

- (id) copyForNode: (CC3SkinMeshNode *)  aNode
withZone: (NSZone *)  zone 

Returns a copy of this skin section, for use by the specified skin mesh node.

- (void) drawVerticesOfMesh: (CC3Mesh *)  mesh
withVisitor: (CC3NodeDrawingVisitor *)  visitor 

Draws the mesh vertices of this skin section.

Prior to drawing the vertices, this method iterates through the CC3Bones in the bones property, and loads a transform matrix into the GL matrix palette for each bone. During drawing, each vertex is then transformed by a weighted average of the transform matrices that it identifies as influencing its location.

The actual matrix loaded for each bone is derived from a combination of:

  • the modelview matrix of the world (MV)
  • the transform of the bone (B), relative to the world
  • the inverse transform of rest pose of the bone (Br(-1)), relative to the world
  • the transform of the skin mesh node (M)

as follows, with * representing matrix multiplication:

MV * B * Br(-1) * M

In practice, to avoid calculating the inverse transform for the rest pose of each bone on every frame render, we can separate each of the rest pose of the bone and the skin mesh node into two components: the transform of the CC3SoftBodyNode, relative to the world, and the transform of the bone and skin mesh node relative to the CC3SoftBodyNode. The above matrix calculation can be expanded and then reduced as follows, with:

  • the modelview matrix of the world (MV)
  • the transform of the bone (B)
  • the transform of the Soft-body node (SB), and its inverse (SB(-1))
  • the transform of the rest pose of the bone relative to the soft-body node (Brsb), and its inverse (Brsb(-1))
  • the transform of the skin mesh node relative to the soft-body node (Msb)

MV * B * Br(-1) * M MV * B * (SB * Brsb)(-1) * (SB * Msb) MV * B * Brsb(-1) * SB(-1) * SB * Msb MV * B * Brsb(-1) * (SB(-1) * SB) * Msb MV * B * Brsb(-1) * Msb

The result is dependent only on the inverted rest pose of the bone relative to the soft-body node, and the skin mesh node, also relative to the soft-body node. In practice, neither of these parameters should change as the character moves.

Since the two cached matrices are relative to the soft-body node, we can move the soft-body node around, and transform it, without having to recalculate the inverse rest pose matrix on each movement for each bone. The movement of the soft-body node and the bones are the only factors that need to be rebuilt on each update.

We can capture the inverse rest pose transform of the bone relative to the soft-body node once and cache it. If we make the assumption that the transform of the skin mesh node, relative to the soft-body node will not change (a fairly safe assumption since it would affect the alignment of the bones to the mesh vertices), we can determine it once and cache it as well. This caching is handled by the bindRestPose method on the respective CC3Bone and CC3SkinMeshNode nodes.

This arrangement also has the benefit of avoiding artifacts that sometimes appear in the matrix inversion of the full bone and skin transforms if the CC3SoftBodyNode is set at rotations of exactly 90 degrees (the cosine of the angle is zero).

This method is invoked automatically when a CC3SkinMeshNode is drawn. Usually, the application never needs to invoke this method directly.

- (NSString*) fullDescription

Returns a description of this skin section that includes a list of the bones.

- (id) initForNode: (CC3SkinMeshNode *)  aNode

Initializes an instance that will be used by the specified skin mesh node.

- (void) reattachBonesFrom: (CC3Node *)  aNode

Creating a copy of a skin section is typically done as part of creating a copy of a skin mesh node.

After copying, the newly created copy will still be influenced by the original skeleton. The result is that both the original mesh and the copy will move and be deformed in tandem as the skeleton moves.

If you are creating a chorus line of dancing characters, this may be the effect you are after. However, if you are creating a squadron of similar, but independently moving characters, each skin mesh node copy should be controlled by a separate skeleton.

After creating a copy of the skeleton bone node assembly, you can use this method to attach the skin mesh node to the new skeleton. The node that is provided as the argument to this method is the root bone node of the skeleton, or a structural ancestor of the skeleton that does not also include the original skeleton as a descendant.

This method iterates through all the bones referenced by this skin section, and retrieves a bone with the same name from the structural descendants of the specified node.

Typically, you would not invoke this method on the skin section directly. Instead, you would invoke a similar method on the CC3SkinMeshNode, or one of its structural ancestors.

When copying a CC3SoftBodyNode instance, this method is automatically invoked as part of the copying of the soft-body object, and you do not need to invoke this method directly.


Property Documentation

- (CCArray *) bones [read, retain]

The collection of bones from the skeleton that influence the subset of mesh vertices that is managed and drawn by this batch.

Each vertex holds a set of indices into this array, to identify the bones that contribute to the transforming of that vertex. The contribution that each bone makes is weighted by the corresponding weights held by the vertex.

Any particular vertex will typically only be directly influenced by two or three bones. The maximum number of bones that any vertex can be directly influenced by is determined by the number of vertex units supported by the platform. This limit can be retreived from [CC3OpenGLES11Engine engine].platform.maxVertexUnits.value.

Because different vertices of the skin section may be influenced by different combinations of bones, the number of bones in the collection in this property will generally be larger than the number of bones used per vertex.

However, when the vertices are drawn, all of the vertices in this skin section are drawn with a single call to the GL engine. All of the bone transforms that affect any of the vertices being drawn are loaded into the GL engine by this skin section prior to drawing the vertices.

The number of transform matrices that can be simultaneously loaded into the GL engine matrix palette is limited by the platform, and that limit defines the maximum number of bones in the collection in this property. This platform limit can be retrieved from [CC3OpenGLES11Engine engine].platform.maxPaletteMatrices.value.

- (GLint) vertexCount [read, write, assign]

Indicates the number of vertices in this skin section.

This value is a count of the nubmer of vertices, not of the number of underlying primitives (floats or bytes).

For example, if a mesh has ten vertices, the value of this property can be set to some value between zero and ten, even though each of the vertices contains several components of data (locations, normals, texture coordinates, bone indices and bone weights, making the actual array much longer than ten, in terms of primatives or bytes)

- (GLint) vertexStart [read, write, assign]

An index that indicates which vertex in the mesh begins this skin section.

This value is an index of vertices, not of the underlying primitives (floats or bytes).

For example, if a mesh has ten vertices, the value of this property can be set to some value between zero and ten, even though each of the vertices contains several components of data (locations, normals, texture coordinates, bone indices and bone weights, making the actual array much longer than ten, in terms of primatives or bytes)


The documentation for this class was generated from the following file: