Logo   Home Table of Contents    News  Dev Blogs  Gallery  Timeline  Legend  Tags  Sponsors 
Join us on... 
Banner

Current: Month Day, Year

9.1.11 Code of opengl/skeleton.py

obj3d/skeleton provides all methods to deal with skeletons. The file contains only one class:

Class skeleton

This class is used to work with a skeleton.

Variables

These variables are all preset by __init__ and by a method called newSkeleton.
namedescription
glob reference to global object.
env reference to global environment.
name name of the skeleton.
filename filename the skeleton was loaded from.
jointVerts dictionary of vertices for position (used in median calculation).
planes dictionary of planes for rotation.
bones list of bones (class cBone).
bWeights reference to bone weights.
root reference to root bone.
offset QVector3D offset of skeleton from e.g ground.
use_offset boolean value to indicate the offset is used.
mesh reference to mesh from baseclass.
bonegroups dictionary of bonegroups (use for e.g. wings, tail).
bonesWithWeights dictionary used for skeleton reduction.
is_reduced boolean value, true when skeleton is reduced.

Methods:

nameparametersreturnsdescription
newSkeleton NoneNone Resets nearly all values to standard, usually called when skeleton is loaded or changed.
loadJSON pathboolean value for success Reads skeleton json file, replaces name and does a few checks (joints, bones must be part of the JSON file). Then reads a joint list, then planes, tests if bones are valid (have head or tail). Checks rotation planes and existence of parent bones and if only one root bone is available. Then read bone groups and weights, if any.

After loading it creates a list of ordered bones starting with root, which guarantees that parent is always available before child. The list of class cBone is then populated with all available values and a dictionary of bones is also created.

The rest matrix is calculated and the filename is set to path.

reloadSkeleton NoneNone Reloads the current skeleton, when it was reduced before.
setOffset positionNone Set the offset postion.
useOffset boolNone Setter for use_offset.
copyScaled source
scale
offset
useOrigRotation
None Generates a resized skeleton. From source skeleton the new skeleton is created with new bones using assignJointPos function with scale and offset.

Then rest matrix is calculated and in case of useOrigRotation the global rest matrix is copied from source to destination skeleton.

getNormal plane_namenormalized vector If plane name is in planes the vertices are used counter-clockwise and create a normal vector by using the cross product of two differences which then is returned as a normalized vector. If no plane is available a standard vector pointing in y direction is returned.
calcRestMat Nonesuccess Calculates rest matrix of skeleton, it can return False for incorrect bones
newGeometry NoneNone If geometry changes, the joint positions and the rest matrix are recalculated.
calcLocalPoseMat posesNone Calculates all local pose matrixes for all bones.
calcGlobalPoseMat NoneNone Calculates the global pose matrix for skeleton.
skinBasemesh NoneNone Call skinMesh with base mesh and weights
skinMesh mesh
bWeights
None Calculates the new positions of gl_coord_w. It uses the dot product on matPoseVerts and the original coordinates. Then it flattens the mesh and does the overflow correction.
noWeightsBasemesh NoneNone Reset all bonesWithWeights to empty dictionary and calls noWeights
noWeights mesh
bWeights
None Calculates highest visible vertex (body, no helper). Then checks, which bones are used for weighting. These bones are added to bonesWithWeights dictionary. This function is used for basemesh and assets.
unusedGroups Noneunused list Checks bonesWithWeights against bonegroups. If a complete group is unused, it is returned in the list.
reduceSkeleton NoneNone Calls noWeightsBasemesh, then each asset is tested for bone weights using noWeights. After that unusedGroups is called and the bones are deleted and is_reduced is set.
getVirtualBonePosition name
posemode
coordinates
bone
Used to get virtual bones from base info and returns tail position of the original bone (so translates e.g. hand to wrist) The position and also a reference to the bone found is returned.
restPose bones_onlyNone Set whole skeleton to rest pose. If bones_only is nor set, skinBasemesh is called and also an update of attached assets is done.
poseFromRestPose changes
bones_only
None Pose the skeleton starting from rest pose for corrections only. Then each bone mentioned in changes is calculated by local and global pose matrix. If not bones_only, skinBasemesh is called and also an update of attached assets is done.
pose joints
frame
bones_only
None Pose the skeleton according to a frame mentioned. It is calculate by each bones local and global pose matrix. If not bones_only, skinBasemesh is called and also an update of attached assets is done.
poseByReference joints
frame
None Pose the skeleton by reference of another skeleton. Either bone is found with the same name in default skeleton or one bone references one or more other bones of default skeleton. Pose each cBone reference which is mentioned in joints, multiply pose matrices, if root is referenced do not multiply other matrices. In case of no reference, try it directly (skeletons like default-notoes).
rootLowestDistance joints
fromframe
toframe
mdiff Get difference between root-bone and floor to calculate distance from ground, this is an estimation. Returns lowest position of a bone.
posebyBlends blends
mask
bones_only
None Check bonewise if blend is used, then use quaternionsSlerpFromMatrix with ratio to pose. In case the bone is posed by more than one posemat, multiply quaternion matrices. Calculate local and global pose matrices. Only allow bones mentioned in mask, set others to rest matrix. If not bones_only, skinBasemesh is called and also an update of attached assets is done.