bvh

bvhsdk.bvh.GetBVHDataFromFile(path, skipmotion=False, supresswarnings=False)[source]

Auxiliary function to bvh.ReadFile(), it is not intended to be used by the user. It is the parser of the bvh file.

Parameters:
  • path (str) – Full path to the bvh file

  • skipmotion (bool) – If set to True, skip everything after “Frame Time”, only the skeleton specification is stored. Default set to False.

  • supresswarnings (bool) – If set to True, warnings will not be printed. Default set to False.

Returns:

Animation object containing the information from the bvh file.

Return type:

anim.Animation

bvhsdk.bvh.GetPositions(joint, frame=0, parentTransform=[], surfaceinfo=None, calibrating=None)[source]

Recursevely compute the global position of each joint for the given frame. The global position is stored in joint.position. This function is not used anymore and could be removed or moved to the anim.Animation class in the future.

Parameters:
  • joint (anim.Joint) – Joint to calculate the global position

  • frame (int) – Frame to calculate the global position, default set to 0.

  • parentTransform (list) – Parameter not intended for user input, used in recursion. List of 4x4 matrices, each matrix is the local transformation of the parent joint.

  • surfaceinfo (surface.Surface) – Legacy parameter, not used anymore. Should be removed in the future.

  • calibrating (bool) – Legacy parameter, not used anymore. Should be removed in the future.

bvhsdk.bvh.ReadFile(path, surfaceinfo=None, skipmotion=False)[source]

Read BVH file and returns an anim.Animation object. The anim.Animation holds the information about the animation file and contain reference to anim.Joint objects. The global position of each joint is not computed when calling bvh.ReadFile().

Parameters:
  • surfaceinfo (surface.Surface) – Attach the surface information of the corresponding character to the anim.Animation object. The surface information is only required for computing the egocentric coordinates. Default set to None. (*)

  • skipmotion (bool) – If set to True, the motion of the BVH file will not be read (skip everything after “Frame Time”), only the skeleton specification is stored. Default set to False.

Returns:

Animation object containing the information from the bvh file.

Return type:

anim.Animation

bvhsdk.bvh.WriteBVH(animation, path, name='_export', frametime=None, writeTranslation=True, refTPose=True, precision=4)[source]

Create a bvh file with the motion contained in the anim.Animation object using the information contained in joint.rotation and joint.translation.

Parameters:
  • animation (anim.Animation) – anim.Animation containing the motion

  • path (str) – Full path to save the file

  • name (str) – Filename without the ‘.bvh’ extension.

  • frametime (float) – 1/(frame per second), the time duration of each frame. Default set to 120 fps.

  • writeTranslation (bool) – If set to True (default), translations (local positions) are written for every joint. Each joint will have six channels, with the first three representing X, Y, and Z translations. If set to False, only the translation (global position) for the root joint will be written.

  • refTPose (bool) – If set to True, the first frame of the BVH file will be the input TPose reference (default). Note that the TPose reference must be set manually for each joint and stored in joint.tposetrans and joint.tposerot as in retarget.MotionRetargeting().

  • precision (int) – Number of decimal places to include when saving floating-point results to the bvh file. A higher precision results in larger file sizes. Default is set to 4 decimal places.

anim

class bvhsdk.anim.Animation(filename, root)[source]

Bases: object

MLPreProcess(skipjoints=[], root_translation=False, root_rotation=False, local_rotation=False)[source]

An example of how to preprocess the animation to be used in a machine learning algorithm. Returns two numpy arrays with the global position and local rotation of each joint in each frame. The shape of the arrays are (number of joints, 3, number of frames).

Parameters:
  • skipjoints (list) – List of joints (and their children) to skip in the preprocessing. Default is [] and will account for every joint.

  • root_translation (bool) – If True, the root joint will be forced to the origin in every frame. Default is False.

  • root_rotation (bool) – If True, the root joint will be forced to have zero rotation in every frame. Default is False.

  • local_rotation (bool) – If True, the local rotation of each joint will be returned in a second array. Default is False.

Returns:

Numpy array with the global position of each joint in each frame; Numpy array with the local rotation of each joint in each frame.

Return type:

numpy.ndarray; numpy.ndarray

PlotAnimation(surface=None)[source]

Legacy function, a similar version should be available in bvhsdk.plotanimation.

PlotPose(frame=0, surface=None)[source]

Legacy function, a similar version should be available in bvhsdk.plotanimation.

RecalculatePositions()[source]

Legacy function, may be removed in the future. It used to recalculate the global positions and orientations of the joints based on the local rotations and translations for all frames. It used the deprecated function bvh.GetPositions() to do so.

RootReferences()[source]

Get references points for the root. Used to calculate the egocentric coordinates (*).

Returns:

List of root joint’s position projected on the XY plane normalized by the root’s height in the first frame; list of the root’s height normalized by the root’s height in the first frame.

Return type:

List[float, float], List[float]

arrayParent()[source]

Create a numpy array that contains the index of the parent of each joint. Jérôme Eippers offers a fine visualization of this array in his YouTube channel Animation Tech, available at https://www.youtube.com/watch?v=cwmrRvw2mPM

Returns:

List of int.

Return type:

List[int]

checkExtraRoot()[source]

Legacy function, may be removed in the future. Some BVH files have an extra root joint that is not on the base of the spine, some times it is on the floor or behind the hips. If you application assumes that the root joint is at the base of the spine, you may want to remove this extra joints. Remebember to also recompute the global positions and orientations of the “new” root joint after removing the extra root joint. This function used the name of the desired root joint defined in skeletonmap.SkeletonMap to check it and set it as the root of the animation.

checkPose()[source]

Legacy function, may be removed in the future. Check the first frame of the animation for a valid T Pose, that is, hips facing the positive direction of the Z axis, the arms parallel to the X axis (left arm along positive X) and standing in the positive direction of Y.

doubleSample()[source]

Up sample the animation to the double of the current frame rate. TODO: Create an upsample method that uses interpolation.

downSample(target_fps)[source]

Downsample the animation to the target frame rate. If the target frame rate is higher than the current frame rate, it will return False and print a warning. Useful for reducing the size of the animation file from 120 fps to 30 fps, for example.

Parameters:

target_fps (int) – Target frame rate.

expandFrames(frames, set_empty=False)[source]

Expand the number of frames of the animation by coping the rotation and translation of frame zero several times.

Parameters:
  • frames (int) – Total of frames after expansion.

  • set_empty (bool) – If False, stacks the rotation and translation of frame zero (default). If True, set the translation and rotation of the joints to empty arrays.

getBonesInFrames(*args)[source]

Legacy function, it will be removed in the next release.

getJoint(jointname)[source]

Find a joint in the animation by its name.

Parameters:

jointname (str) – Name of the joint to be found.

Returns:

Joint object.

Return type:

anim.Joints

getJointPositions()[source]

Get the global position of each joint in each frame.

Returns:

Numpy array with the global position of each joint in each frame.

Return type:

numpy.ndarray

getlistofjoints()[source]

Get list of joints in the animation in a Depth First Search order.

Returns:

List of joints.

Return type:

List[anim.Joints]

insertFrame(index, rotation=None, translation=None)[source]

Insert a frame in the animation at the index position

Parameters:
  • index (int) – Index position to insert the frame. If -1, insert at the end of the animation.

  • rotation (numpy.ndarray) – Rotation of the joints in the new frame. If None (default), set the rotation to zero.

  • translation (numpy.ndarray) – Local translation of the joints in the new frame. If None (default), use the same value store in anim.Joints.offset.

newRotationOrder(newOrder)[source]

Change the rotation order of all joints in the animation to the newOrder provided. This method assumes that every joint has the same rotation order.

Note: This method was only tested for changing rotation order from ZXY to ZYX. It will not work for other rotation orders. To add another convertion, you will need to update the mathutils.matrixR(), mathutils.eulerFromMatrix() and Joint.getLocalTransform() methods. You’ll also need to make sure that the bvh.ReadFile() and bvh.WriteBVH() methods are updated to read and write the new rotation order. Additionally, that does not mean that the new order will work with the rest of the code.

Parameters:

newOrder (str) – New rotation order. Can be “XYZ”, “ZYX” or “ZXY”.

old_getBones(frame=0, bonesPositions=[], joint=None, include_endsite=False)[source]

Create a list of bones useful for plotting the skeleton in the frame provided. Each entry of the list contains six values, the first three are the coordinates of the parent joint and the last three are the coordinates of the child joint. Can be thought as a list of lines, each line is a bone starting at p0 (first three values) end ending at p1 (last three values).

Parameters:
  • frame (int) – Frame to get the bones. Default is 0.

  • bonesPositions (list) – Not intended for user input. List of bones to be returned.

  • joint (anim.Joints) – Not intended for user input. Current joint being evaluated.

  • include_endsite (bool) – If True, include endsites in the list of bones. Default is False.

Returns:

List of bones’ begin and end.

Return type:

List[[float, float, float, float, float, float]]

plotPoseSurfFrame(surfaceinfo, frame=0)[source]

Legacy function, a similar version should be available in bvhsdk.plotanimation.

printlist()[source]

Calls Animation.gestlistofjoints() and prints the name of each joint

removeFrame(index)[source]

Remove a frame in the animation at the index position

Parameters:

index (int) – Index position to remove the frame. If -1, remove the last frame.

class bvhsdk.anim.Joints(name, depth=0, parent=None)[source]

Bases: object

PoseBottomUp(value=array([0., 0., 0.]))[source]
RotateGlobal(R, frame)[source]

Rotates the joint by a rotation defined by the R array (rx, ry, rz rotations) and update the local rotation angles accordingly. Note that R represents a global rotation and not a rotation relative to the parent joint.

Parameters:
  • R (numpy.ndarray) – Global rotation (rx, ry, rz).

  • frame (int) – Frame to update the rotation angles.

addChild(item)[source]

Called after initialization of every joint except root

Parameters:

items (anim.Joints) – Joint to be added as a child

addEndSite(endsite=None)[source]

Add the endsite of the joint. The endsite is the local translation of the endsite from the current anim.Joints object defined at the header of the BVH files.

Parameters:

endsite (numpy.ndarray) – Endsite of the joint

addEndSitePosition(pos, frame)[source]

Add the position of the endsite of an endeffector joint.

Parameters:
  • pos (numpy.ndarray) – Position of the endsite of the joint in the frame

  • frame (int) – Frame to add the position

addOffset(offset)[source]

Add the offset of the joint. This offset is the local translation of the joint from its parent joint defined at the header of the BVH files.

Parameters:

offset (numpy.ndarray) – Offset of the joint

addOrientation(ori, frame)[source]

In the first time, instantiate the global orientation variable of a joint. Then fill in values at the frame provided. Similar to Joints.addPosition().

Parameters:
  • ori (numpy.ndarray) – Global orientation of an endeffector joint.

  • frame (int) – Frame to add the orientation

addPosition(pos, frame)[source]

In the first time, instantiate the global position variable of a joint. Then fill in values at the frame provided. Note: manually changing the (global) position does not update the local rotation of the joint and it will not change the animation if saved to a BVH file. The (global) position values stored in Joints.position only exists for easily accessing the position of the joint in the animation. If you want to change the position of the joint, you need to compute and change its local rotation.

Parameters:
  • pos (numpy.ndarray) – Position of the joint in the frame

  • frame (int) – Frame to add the position

getBaseRotation()[source]

Don’t use it (it’s not necessary). Deprecated function, should be removed in the next release along with everything related to baserotation. Function based on the description of “Motion Capture File Formats Explained.” by M. Meredith S.Maddock

Returns the base rotation matrix of the bone associated with this joint. The base rotation matrix rotates the vector [0 length 0] to the offset vector. “length” is computed through self.getLength and “offset” through self.offset.

getByName(name)[source]

Traverse the hierarchy using Depth First Search (DFS) and returns the joint object with the provided name.

Parameters:

name (str) – Name of the joint to be returned.

Returns:

Joint object with the provided name.

Return type:

anim.Joints

getChildren(index=-1)[source]

Returns a list of references to the childrens of the joint. If index is equal or bigger than 0, return the index-th child

Parameters:

index (int) – Index-th child to be returned

Returns:

List of childrens of the joint if index is -1, otherwise return the index-th child

Return type:

List[anim.Joints] or anim.Joints

getDepth()[source]

Computes the depth of the joint in the hierarchy

Returns:

Depth of the joint in the hierarchy

Return type:

int

getEndSitePosition(frame=0)[source]

Returns the position of the EndSite of the joint at the specified frame if the joint has an EndSite (is an endeffector joint).

Parameters:

frame (int) – Frame to get the EndSite position.

Returns:

EndSite position.

Return type:

numpy.ndarray

getGlobalRotation(frame=0, includeBaseRotation=False)[source]

Get global rotation angles (Euler angles) of the joint at the specified frame. It first computes the global transformation matrix, then extracts the euler angles from it.

Parameters:
  • frame (int) – Frame to get the global rotation angles.

  • includeBaseRotation (bool) – Deprecated parameter, should be removed from the next release. Default is False.

Returns:

Global rotation angles.

Return type:

numpy.ndarray

getGlobalTransform(frame=0, includeBaseRotation=False)[source]

Compute the 4x4 global transformation matrix of the joint at the specified frame. This is the function to be used if you want to get the global rotation or (global) position of the joint. If the global transformation matrix was already computed for the current frame, it will return it without recomputing.

Parameters:
  • frame (int) – Frame to get the global transformation matrix.

  • includeBaseRotation (bool) – Deprecated parameter, should be removed from the next release. Default is False.

Returns:

Global transformation matrix (4x4).

Return type:

numpy.ndarray

getGlobalTranslation(frame=0)[source]

The same as Joints.getPosition().

Returns:

Global translation (position).

Return type:

numpy.ndarray

getJointsBelow(first=True)[source]

Generator for all joints below the hierarchy

Parameters:

first (bool) – Internal control, do not change. Default is True.

Returns:

Yields joints below the hierarchy.

Return type:

anim.Joints

getLastDepth(depth, jointsInDepth=[])[source]

Returns the last joint initializated with the depth provided. This function is misplaced, it probably should be in the anim.Animation class.

Parameters:
  • depth (int) – Depth of the joint in the hierarchy

  • jointsInDepth (list) – Don’t use, internal control

Returns:

Last joint initializated with the depth provided

Return type:

anim.Joints

getLength()[source]

Returns the length of the bone (distance between the joint to its first child)

Returns:

Length of the bone

Return type:

float

getLocalRotation(frame=0)[source]

Get local rotation angles of the joint at the specified frame. Same as joint.rotation[frame].

Parameters:

frame (int) – Frame to get the local rotation angles.

Returns:

Local rotation angles.

Return type:

numpy.ndarray

getLocalTransform(frame=0)[source]

Get joint 4x4 local transformation matrix at the specified frame.

Parameters:

frame (int) – Frame to get the local transformation matrix.

Returns:

Local transformation matrix (4x4).

Return type:

numpy.ndarray

getLocalTransformBaseRotation(frame)[source]

Deprecated. Please use getLocalTransform() instead. It should be removed in the next release.

getLocalTranslation(frame=0)[source]

Get local translation of the joint at the specified frame. Same as joint.translation[frame].

Parameters:

frame (int) – Frame to get the local translation.

Returns:

Local rotation translation.

Return type:

numpy.ndarray

getPosition(frame=0)[source]

Computes the global position of the joint at the specified frame. It first computes the global transformation matrix, then extracts the position from it using the last column.

Parameters:

frame (int) – Frame to get the global position.

Returns:

Global position.

Return type:

numpy.ndarray

getRecalcRotationMatrix(frame)[source]

Don’t use it. Deprecated. Please use getLocalTransform() instead. It should be removed in the next release. Function based on Equation 4.9 from “Motion Capture File Formats Explained.” by M. Meredith S.Maddock Returns the recalculated local rotation matrix.

getRoot()[source]

Returns the root of the hierarchy

Returns:

Root of the hierarchy

Return type:

anim.Joints

pathFromDepthToJoint(depth=-1)[source]

Generator of the path between the joint located depth nodes up the hierarchy to the joint.

Example: Given the subtree root, node1, node2, node3, node4, node5 and node6. node5.pathFromDepthToJoint(2) will return the joints node3, node4 and node5.

Parameters:

depth (int) – Position above the current joint in the hierarchy

Returns:

Yields joints from the joint located depth nodes up the hierarchy to the current joint.

Return type:

anim.Joints

pathFromJointToJoint(parentjoint)[source]

Returns the kinematic path between a parentjoint up in the hierarchy to the current joint. If they are not in the same kinematic path (same subtree), raises error. Note: Returns a list, not a generator.

Example: Given the subtree root, node1, node2, node3, node4, node5 and node6. node5.pathFromJointToJoint(node2) will return the joints node2, node3, node4 and node5.

Parameters:

parentjoint (anim.Joints) – Joint to start the path

Returns:

List of joints from the parentjoint to the current joint.

Return type:

List[anim.Joints]

pathFromRootToJoint()[source]

Generator of the path between the root and the joint.

Example: Given the subtree root, node1, node2, node3, node4, node5 and node6. node5.pathFromRootToJoint() will yield the joints root, node1, node2, node3, node4 and node5.

Returns:

Yields joints from the root to the current joint.

Return type:

anim.Joints

printHierarchy(hierarchy=[], endsite=False)[source]

Print hierarchy of the joint.

Parameters:
  • hierarchy (list) – Don’t use, internal control

  • endsite (bool) – Don’t use, internal control

setGlobalRotation(R, frame)[source]

Set the global rotation of the joint as the R array (rx, ry, rz rotations) and update the local rotation angles accordingly.

Parameters:
  • R (numpy.ndarray) – Global rotation (rx, ry, rz).

  • frame (int) – Frame to update the rotation angles.

setLocalRotation(frame, rotation)[source]

Updates local rotation angles in the current frame and sets all global transform matrices down the hierarchy to not reliable. That is, the global transformation matrix of the current joint and all its children will be recomputed if Joints.GetGlobalTransform() is called.

Parameters:
  • frame (int) – Frame to update the rotation angles.

  • rotation (numpy.ndarray) – Rotation angles.

setTranslation(frame, translation)[source]

Updates translation values in the current frame and sets all global transform matrices down the hierarchy to not reliable. That is, the global transformation matrix of the current joint and all its children will be recomputed if Joints.GetGlobalTransform() is called.

Parameters:
  • frame (int) – Frame to update the translation.

  • translation (numpy.ndarray) – Translation values.

mathutils

Created on Wed Aug 8 10:29:18 2018

@author: Rodolfo Luis Tonoli

bvhsdk.mathutils.alignVectors(a, b, shape=3)[source]

Returns a rotation matrix to align vector a onto vector b. This matrix is not constructed as RxRyRz, but from an axis-angle representation.

Based on the algorithm available at https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d

Parameters:
  • a (numpy.ndarray) – vector to be aligned

  • b (numpy.ndarray) – vector to be aligned to

Returns:

rotation matrix

Return type:

numpy.ndarray

bvhsdk.mathutils.angleBetween(a, b)[source]

Returns the euler angle between the vectors (from a to b) and the rotation axis https://stackoverflow.com/questions/15101103/euler-angles-between-two-3d-vectors http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToEuler/index.htm https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions

Parameters:
  • a (numpy.ndarray) – vector to be aligned

  • b (numpy.ndarray) – vector to be aligned to

Returns:

angle between the vectors, axis of rotation

Return type:

float, numpy.ndarray

bvhsdk.mathutils.barycentric2cartesian(bary, v1, v2, v3)[source]

Convert baricentric coordinates to cartesian coordinates

Parameters:
  • bary (numpy.ndarray) – baricentric coordinates

  • v1 (numpy.ndarray) – first point of the triangle

  • v2 (numpy.ndarray) – second point of the triangle

  • v3 (numpy.ndarray) – third point of the triangle

Returns:

cartesian coordinates, normal vector

Return type:

numpy.ndarray, numpy.ndarray

bvhsdk.mathutils.capsuleCartesian(capsulecoord, p0, p1, capradius)[source]

Transforms the normalized cylindrical coordinates from capsuleCollision to denormalized cartesian coordinates

Parameters:
  • point – Normalized capsule coordinates from capsuleCollision()

  • p0 (numpy.ndarray) – Cylinder “bottom” point, first point

  • p1 (numpy.ndarray) – Cylinder “top” point, first point

  • capradius (int) – Cylinder (and half spheres) radius

bvhsdk.mathutils.capsuleCollision(point, p0, p1, capradius)[source]

Creates a capsule (extruded sphere): a cylinder with radius capradius and two half spheres (top and bottom) with radius capradius Returns the normalized intersection LOCAL cylindric coordinates and the intersection GLOBAL euclidean coordinates

Surface: x^2+y^2+(1/4)*(|z-caplength|+|z+caplength| - 2*caplength)^2 - capradius^2 = 0

Example: caplength = 10 capradius = 2 if z=5:

x^2+y^2+(1/4)*(|5-10|+|5+10| - 2*10)^2 - 2^2 = 0 x^2+y^2+(1/4)*(20 - 20)^2 - 2^2 = 0 x^2+y^2 - 4 = 0 if x^2+y^2 = 4:

(On the surface of the cylinder)

elif x^2+y^2 > 4:

(Outside cylinder)

elif x^2+y^2 < 4:

(Inside cylinder)

if z=15:

x^2+y^2+(1/4)*(|15-10|+|15+10| - 2*10)^2 - 2^2 = 0 x^2+y^2+(1/4)*(30 - 20)^2 - 2^2 = 0 x^2+y^2+ 25 - 2^2 = 0 x^2+y^2+ 21 > 0 (Outside cylinder)

if z=11:

x^2+y^2+(1/4)*(|11-10|+|11+10| - 2*10)^2 - 2^2 = 0 x^2+y^2+(1/4)*(22 - 20)^2 - 2^2 = 0 x^2+y^2+ 1 - 4 = 0 x^2+y^2 - 3 = 0 (Analogous to z=5)

Finding surface starting from [0,0,0] and moving along direction=[a,b,c] with step=t (a*t)^2+(b*t)^2+(1/4)*(|(z*t)-caplength|+|(z*t)+caplength| - 2*caplength)^2 - capradius^2 = 0

Parameters:
  • point (numpy.ndarray) – Point outside the capsule to give the direction of the collinsion vector (from the origin to the point)

  • p0 (numpy.ndarray) – Cylinder “bottom” point, first point

  • p1 (numpy.ndarray) – Cylinder “top” point, first point

  • capradius (int) – Cylinder (and half spheres) radius

bvhsdk.mathutils.clampedBarycentric(p, p1, p2, p3)[source]

Compute the baricentric coordinates of a point p projected onto a triangle defined by p1, p2 and p3. Different from mathutils.projectedBarycentricCoord(), if p is outside the triangle, the baricentric coordinates are clamped to the triangle edges. Algorithm from “Computing the barycentric coordinates of a projected point.” by Heidrich, Wolfgang, Journal of Graphics Tools 10, no. 3 (2005): 9-12.

Parameters:
  • p (numpy.ndarray) – point to be projected

  • p1 (numpy.ndarray) – first point of the triangle

  • p2 (numpy.ndarray) – second point of the triangle

  • p3 (numpy.ndarray) – third point of the triangle

Returns:

normal vector, baricentric coordinates, displacement vector, baricentric coordinates in cartesian space and a boolean indicating if the point is inside the triangle

Return type:

numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, bool

bvhsdk.mathutils.cosBetween(a, b, absolute=True)[source]

Return the cosine of the angle between vectors a and b, the absolute value is returned is absolute = True.

Parameters:
  • a (numpy.ndarray) – Vector one

  • b (numpy.ndarray) – Vector two

  • absolute (int) – Return absolute value. True for yes, False for no.

bvhsdk.mathutils.distFromCentroid(p, p1, p2, p3)[source]

Compute the distance from a point p to the centroid of a triangle defined by p1, p2 and p3.

Parameters:
  • p (numpy.ndarray) – point of interest

  • p1 (numpy.ndarray) – first point of the triangle

  • p2 (numpy.ndarray) – second point of the triangle

  • p3 (numpy.ndarray) – third point of the triangle

Returns:

centroid, distance vector, normal vector

Return type:

numpy.ndarray, numpy.ndarray, numpy.ndarray

bvhsdk.mathutils.eulerFromMatrix(matrix, order='ZXY')[source]

Return the euler angles from Computing Euler angles from a rotation matrix by Gregory G. Slabaugh available online at: http://www.close-range.com/docs/Computing_Euler_angles_from_a_rotation_matrix.pdf Other references: https://en.wikipedia.org/wiki/Euler_angles#Extrinsic_rotations https://gist.github.com/crmccreary/1593090 https://research.cs.wisc.edu/graphics/Courses/cs-838-1999/Jeff/BVH.html https://www.geometrictools.com/Documentation/EulerAngles.pdf NOTE: This function will work only with matrices created using RxRyRz

order = ‘XYZ’ ((RxRy)Rz) =

cos(y) -sen(z)cos(y) sen(y) sen(x)sen(y) -sen(x)sen(y)sen(z)+cos(x)cos(z) -sen(x)cos(y) -sen(y)cos(x) sen(y)cos(x)sen(z)+sen(x)cos(z) cos(x)cos(y)

order = ‘ZXY’ ((RzRx)Ry) =

cos(y)cos(z)-sen(x)sen(y)sen(z) -cos(x)sen(z) cos(z)sen(y)+sen(x)sen(z)cos(y) cos(y)sen(z)+sen(x)sen(y)cos(z) cos(x)cos(z) sen(y)sen(z)-sen(x)cos(y)cos(z) -cos(x)sen(y) sen(x) cos(x)cos(y)

if cosX = 0 and sen(x) = -1:

x = -pi/2 matrix[0,0] = cy*cz+sy*sz = cos(z-y) matrix[1,0] = cy*sz-sy*cz = sen(z-y) matrix[0,2] = sy*cz-cy*sz = -sen(z-y) = -matrix[1,0] matrix[1,2] = sy*sz+cy*cz = cos(z-y) = matrix[0,0] z - y = atan2(-matrix[1,0], matrix[0,0]) z = y + atan2(-matrix[1,0], matrix[0,0])

if cosX = 0 and sen(x) = 1:

x = pi/2 matrix[0,0] = cy*cz-sy*sz = cos(y+z) matrix[1,0] = cy*sz+sy*cz = sen(y+z) matrix[0,2] = sy*cz+sz*cy = sen(y+z) = matrix[1,0] matrix[1,2] = sy*sz-cy*cz = -cos(y+z) = -matrix[0,0] z + y = atan2(matrix[1,0], -matrix[0,0]) z = -y + atan2(matrix[1,0], -matrix[0,0])

order = ‘ZYX’ ((RzRx)Ry) =

cos(y)cos(z) sin(x)sin(y)cos(z)-cos(x)sen(z) cos(x)sin(y)cos(z)+sen(x)sen(z) cos(y)sin(z) sin(x)sin(y)sin(z)+cos(x)cos(z) cos(x)sin(y)sin(z)-sen(x)cos(z) -sin(y) sin(x)cos(y) cos(x)cos(y)

order = ‘YXZ’ ((RyRx)Rz) =

cos(y)cos(z)+sen(x)sen(y)sen(z) cos(z)sen(x)sen(y)-cos(y)sen(z) cos(x)sen(y) cos(x)sen(z) cos(x)cos(z) -sen(x) sen(y)cos(z)+sen(x)cos(y)sen(z) sen(x)cos(y)cos(z)+sen(y)sen(z) cos(x)cos(y)

Parameters:
  • matrix (numpy.ndarray) – 3x3 rotation matrix or 4x4 transform matrix

  • order (string) – order of rotation (working only for ZXY)

bvhsdk.mathutils.eulerFromVector(vector, twistaxis='y')[source]
bvhsdk.mathutils.getCentroid(p1, p2, p3)[source]

Compute the centroid of a triangle defined by p1, p2 and p3.

Parameters:
  • p1 (numpy.ndarray) – first point of the triangle

  • p2 (numpy.ndarray) – second point of the triangle

  • p3 (numpy.ndarray) – third point of the triangle

Returns:

centroid, normal vector

Return type:

numpy.ndarray, numpy.ndarray

bvhsdk.mathutils.inverseMatrix(m0)[source]

Tries to invert matrix m0 using numpy.linalg.inv(). If it is not possible, returns None.

Parameters:

m0 (numpy.ndarray) – matrix to be inverted

Returns:

inverted matrix

Return type:

numpy.ndarray

bvhsdk.mathutils.isNear(value, constant, e=1e-06)[source]

Test if value is near the constant inside the range giving by e constant - e <= value <= constant + e

bvhsdk.mathutils.isRotationMatrix(matrix)[source]

Check if matrix is a valid rotation matrix

bvhsdk.mathutils.isequal(a1, a2, epsilon=0.0001)[source]

Check if array v1 and array v2 are equal element-wise

Parameters:
  • a1 (numpy.ndarray) – First array

  • a2 (numpy.ndarray) – Second array

  • epsilon (numpy.ndarray) – Error margin

bvhsdk.mathutils.isnear(x, y, epsilon=0.0001)[source]
bvhsdk.mathutils.matrixError(m1, m2)[source]

Calcula a diferença entre as duas matrizes.

Parameters:
  • m1 (numpy.ndarray) – Matrix to subtract

  • m2 (numpy.ndarray) – Matrix to be subtracted

bvhsdk.mathutils.matrixIdentity(shape=3)[source]

Return identity matrix of shape 3x3 or 4x4

Parameters:

shape (int) – shape of the matrix. 3 for 3x3 and 4 for 4x4

Returns:

identity matrix

Return type:

numpy.ndarray

bvhsdk.mathutils.matrixMultiply(m0, m1)[source]

Perform matrix multiplication between m0 and m1. m0 and m1 can be 3x3 or 4x4 matrices. For performance reasons, use numpy.dot() instead.

Parameters:
  • m0 (numpy.ndarray) – matrix 0

  • m1 (numpy.ndarray) – matrix 1

Returns:

matrix resulting from the multiplication

Return type:

numpy.ndarray

bvhsdk.mathutils.matrixR(R, order='ZXY', shape=3)[source]

Creates rotation matrix

Parameters

orderstring, optional

Order to create the rotation matrix. Only ‘ZXY’ and ‘XYZ’ implemented. The default is ‘ZXY’.

shapeTYPE, optional

Matrix shape, 3x3 or 4x4. The default is 3.

Returns

matrixnumpy array

Rotation matrix.

bvhsdk.mathutils.matrixRotation(angle, x=0, y=0, z=0, shape=4)[source]

Construct a transformation matrix for rotation of angle degrees around the axis defined by x, y and z. If shape is 4 it will append create a 4x4 transformation matrix with translation equals to zero.

Parameters:
  • angle (float) – angle in degrees

  • x (float) – x axis

  • y (float) – y axis

  • z (float) – z axis

  • shape (int) – shape of the matrix. 3 for 3x3 and 4 for 4x4

Returns:

rotation matrix

Return type:

numpy.ndarray

bvhsdk.mathutils.matrixSkew(vec)[source]

Construct a skew-symmetric matrix from a vector. If the vector is 3D, the matrix will be 3x3. If the vector is 4D, the matrix will be 4x4.

Parameters:

vec (numpy.ndarray) – vector to be converted to skew-symmetric matrix

Returns:

skew-symmetric matrix

Return type:

numpy.ndarray

bvhsdk.mathutils.matrixTranslation(tx, ty, tz)[source]

Construct a transformation matrix for translation of tx, ty and tz

Parameters:
  • tx (float) – translation in x axis

  • ty (float) – translation in y axis

  • tz (float) – translation in z axis

Returns:

translation matrix

Return type:

numpy.ndarray

bvhsdk.mathutils.multiInterp(x, xp, arr)[source]

Performs a linear interpolation like numpy.interp() but for multidimensional arrays. Interpolation is performed independently for each dimension.

Parameters:
  • x (numpy.ndarray) – The x-coordinates at which to evaluate the interpolated values (same for all dimensions)

  • xp (numpy.ndarray) – The x-coordinates of the data points (same for all dimensions)

  • arr (numpy.ndarray) – Multi-dimensional array of data with the same length as xp along the interpolation axis.

Returns:

interpolated array

Return type:

numpy.ndarray

bvhsdk.mathutils.printLog()[source]
bvhsdk.mathutils.projectedBarycentricCoord(p, p1, p2, p3)[source]

Compute the baricentric coordinates of a point p projected onto a triangle defined by p1, p2 and p3. Algorithm from “Computing the barycentric coordinates of a projected point.” by Heidrich, Wolfgang, Journal of Graphics Tools 10, no. 3 (2005): 9-12.

Parameters:
  • p (numpy.ndarray) – point to be projected

  • p1 (numpy.ndarray) – first point of the triangle

  • p2 (numpy.ndarray) – second point of the triangle

  • p3 (numpy.ndarray) – third point of the triangle

Returns:

normal vector, baricentric coordinates, displacement vector, baricentric coordinates in cartesian space and a boolean indicating if the point is inside the triangle

Return type:

numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, bool

bvhsdk.mathutils.projection(a, b)[source]

Compute the projection of a onto b. Exemple: https://math.boisestate.edu/~jaimos/notes/275/vector-proj.html

Parameters:
  • a (numpy.ndarray) – Vector to be projected onto the other vector

  • b (numpy.ndarray) – Projection target vector

bvhsdk.mathutils.shape3ToShape4(matrix, T=None)[source]

Expand 3x3 matrix to 4x4

matrix: 3x3 matrix T: translation vector

bvhsdk.mathutils.shape4ToShape3(matrix)[source]

Get the rotation matrix from the transform matrix

matrix: 4x4 transform matrix

bvhsdk.mathutils.transformMatrix(R, T, order='ZXY')[source]

Creates transform matrix.

R: Size 3 vector containing the rotation over the x-, y- and z-axis T: Size 3 vector containing x, y and z translation

bvhsdk.mathutils.unitVector(vec)[source]
bvhsdk.mathutils.xaxis()[source]
Returns:

Return a numpy array representing the x axis

Return type:

numpy.ndarray

bvhsdk.mathutils.yaxis()[source]
Returns:

Return a numpy array representing the y axis

Return type:

numpy.ndarray

bvhsdk.mathutils.zaxis()[source]
Returns:

Return a numpy array representing the z axis

Return type:

numpy.ndarray

plotanimation

bvhsdk.plotanimation.AnimPlot(data)[source]
bvhsdk.plotanimation.AnimPlotBones2D(data, plotax='xy')[source]
bvhsdk.plotanimation.AnimationSurface(animation, data, listofpoints)[source]

Plot animation with surface information

bvhsdk.plotanimation.AnimationSurface2(data, listofpoints)[source]

OLD (bones with 6 float array) Plot animation with surface information

bvhsdk.plotanimation.AnimationSurfaceAndVectors(data, listofpoints, dispvectors)[source]

Plot animation with surface information and displacement vectors

bvhsdk.plotanimation.AnimationSurfaceAndVectors2(data, listofpoints, dispvectors)[source]

OLD (bones with 6 float array) Plot animation with surface information and displacement vectors

bvhsdk.plotanimation.CheckTargets(animation, joint, joint1, ego)[source]
bvhsdk.plotanimation.DebugEgoCoord(animation, frame, proj='3d')[source]
bvhsdk.plotanimation.JointVelocity(data, box=0)[source]
bvhsdk.plotanimation.MSc_PlotCos(step)[source]
bvhsdk.plotanimation.MSc_PlotImportance(animation, ego, joint=None)[source]
bvhsdk.plotanimation.MSc_PlotOrtho(which, step=0.01, epsilon=0.0001, start=-3.141592653589793, stop=3.141592653589793)[source]
bvhsdk.plotanimation.MSc_PlotTrajectory(animation, animation2=None, animation3=None, joint=None)[source]
bvhsdk.plotanimation.MSc_PlotTrajectoryIK(animation, animation2=None, animation3=None, joint=None)[source]
bvhsdk.plotanimation.MSc_printSurfaceAndCapsule(animation, surface, frame=0, plotcapsule=True)[source]

Imprime surperficies em diferentes posições Parameters ———- anim : TYPE

DESCRIPTION.

surfTYPE

DESCRIPTION.

Returns

None.

bvhsdk.plotanimation.MSc_printSurfaces(animation, surface, step=45, frame=0)[source]

Imprime surperficies em diferentes posições Parameters ———- anim : TYPE

DESCRIPTION.

surfTYPE

DESCRIPTION.

Returns

None.

bvhsdk.plotanimation.MSc_printSurfacesAndPoses(animation, surface, step=45, frame=0, figs=6)[source]

Imprime surperficies em diferentes posições Parameters ———- anim : TYPE

DESCRIPTION.

surfTYPE

DESCRIPTION.

Returns

None.

bvhsdk.plotanimation.PlotBVHSurface(animation, surface)[source]
bvhsdk.plotanimation.PlotDispvectorsFrames(srcAnim, srcSurface, tgtAnim, tgtSurface, egoCoord, f1, f2, f3)[source]
bvhsdk.plotanimation.PlotDispvectorsFrames3D(animation, surface, egoCoord, frame, target=True, skipHead=False, skipBody=False)[source]
bvhsdk.plotanimation.PlotPoseAndSurface(animation, surface, axes=False, frame=0)[source]
bvhsdk.plotanimation.PosePlot(data, label=[])[source]
bvhsdk.plotanimation.PosePlotBones(joints, bones)[source]

Plot a pose (just one frame) with joints and bones

bvhsdk.plotanimation.PosePlotBonesSurface(joints, bones, surface)[source]

Plot a pose (just one frame) with joints, bones and surface data

bvhsdk.plotanimation.plot3DBones(animation, fig, ax, precomp_positions, frameDelay, color, skiproot, marker, linestyle, markersize)[source]
bvhsdk.plotanimation.plot3DJoints(animation, fig, ax, precomp_positions, frameDelay, color, marker, markersize)[source]
bvhsdk.plotanimation.plot3d(animation, mode='bones', frameDelay=0, viewPlane=0, floorPlane=True, skiproot=0, dist=7, figsize=(12, 8), color='black', marker='o', linestyle='-', markersize=2)[source]

Plot BVH animation joints. Currently assumes Y-up character. Supports 3D scatter plot and bones plot (‘scatter’ and ‘bones’ modes, respectively).

Ipython Jupyter Notebook-friendly function. Make sure to include the following line in your notebook: %matplotlib notebook import matplotlib matplotlib.rc(‘animation’, html=’html5’) These lines may also be necessary: from ipywidgets import interact, interactive, widgets from IPython.display import display

Parameters:
  • animation (anim.Animation) – Animation object to be draw

  • mode (str) – Choose between ‘bones’ or ‘scatter’ modes. ‘bones’ will draw the bones of the skeleton, ‘scatter’ will draw the joints as points.

  • frameDelay (int) – Interval or delay between frames of matplotlib’s FuncAnimation function in miliseconds. If 0, use animation’s frametime to match intended fps from BVH file.

  • viewPlane (int) – Primary view plane option (choose between 1 and )

  • floorPlane (bool) – If True, draw a XZ plane with Y = 0 as reference.

  • skiproot (int) – Skip the first skiproot joints in the hierarchy. Useful when the skeleton has a body world reference or an origin joint.

  • dist (float) – Distance from the camera to the plot. Matplotlib default is 10.

  • figsize (tuple) – Figure size in inches.

  • color (str) – Color of the plot elements.

  • marker (str) – Marker style for scatter plot.

  • linestyle (str) – Line style for bones plot.

  • markersize (int) – Marker size for scatter plot.

Returns:

Return a matplotlib.animation object containing the animation.

Return type:

matplotlib.animation

bvhsdk.plotanimation.plotAxesFromMatrix(matrix)[source]
bvhsdk.plotanimation.plotAxesVectors(x, y, z=False)[source]
bvhsdk.plotanimation.plotVector(vec)[source]

retarget

Created on Tue Sep 4 15:12:57 2018

@author: Rodolfo Luis Tonoli

bvhsdk.retarget.MotionRetargeting(sourceAnimationPath, sourceSurfacePath, targetSkeletonPath, targetSurfacePath, customSkeletomMap=None, computeEgo=True, computeIK=True, adjustOrientation=True, saveFile=True, saveInitAndFull=True, out_path=None)[source]
bvhsdk.retarget.PostureInitialization(tgtMap, srcMap, heightRatio, frame, getpositions=False, headAlign=True, spineAlign=False, handAlign=True)[source]

Copy the rotation from the mocap joints to the corresponding avatar joint.

ani_ava: Avatar animation ani_mocap: Mocap animation

bvhsdk.retarget.SimpleMotionRetargeting(srcAnimationPath, tgtAnimationPath, outputPath, srcSkeletonMap=None, tgtSkeletonMap=None, frameStop=False, trackProgress=False, forceFaceZ=False)[source]

Perform a simple motion retargeting. The bones of the target skeleton is aligned with the bones of the source animation

Parameters

tgtAnimationPathstring, optional

Path to the source animation (.bvh). The animation file may have one or several frames, but only the first take will be used.

Returns

tgtAnimationAnimation object

Retargeted animation.

bvhsdk.retarget.checkName(name, currentpath=None)[source]

Return True if the file in the path/name provided exists inside current path

Parameters:

name (string) – Local path/name of the back file

skeletonmap

Created on Mon Sep 24 23:49:43 2018

@author: Rodolfo Luis Tonoli

class bvhsdk.skeletonmap.SkeletonMap(animation, mapfile=None)[source]

Bases: object

checkJoints()[source]
getJointsLimbsHead()[source]
getJointsNoRoot()[source]
getJointsNoRootHips()[source]
vecLArm(frame)[source]
vecLClavicle(frame)[source]
vecLFemur(frame)[source]
vecLForearm(frame)[source]
vecLLowleg(frame)[source]
vecLUpleg(frame)[source]
vecNeck(frame)[source]
vecRArm(frame)[source]
vecRClavicle(frame)[source]
vecRFemur(frame)[source]
vecRForearm(frame)[source]
vecRLowleg(frame)[source]
vecRUpleg(frame)[source]
vecSpine(frame)[source]
bvhsdk.skeletonmap.getIntermediateSkeleton(animation)[source]
bvhsdk.skeletonmap.getmatchingjoint(jointname, animation, returnnear=True)[source]

Get the list of names that contains jointname and search for a joint in the animation using the names on the list

Parameters:
  • jointname (str) – Name of the joint

  • animation (pyanimation.Animation) – Animation to look for a mapped joint

bvhsdk.skeletonmap.isamatch(jointname1, jointname2, validNames=[['root', 'Hips'], ['spine05', 'Hips'], ['spine04', 'Spine'], ['spine03', 'Spine1'], ['spine02', 'Spine2'], ['spine01', 'Spine3'], ['neck01', 'Neck'], ['neck02', 'Neck1'], ['head', 'Head'], ['shoulder01.R', 'RightShoulder'], ['upperarm01.R', 'RightArm'], ['lowerarm01.R', 'RightForeArm'], ['wrist.R', 'RightHand'], [], ['finger3-1.R', 'RightHandMiddle1'], ['shoulder01.L', 'LeftShoulder'], ['upperarm01.L', 'LeftArm'], ['lowerarm01.L', 'LeftForeArm'], ['wrist.L', 'LeftHand'], [], ['finger3-1.L', 'LeftHandMiddle1'], ['upperleg01.R', 'RightUpLeg'], ['lowerleg01.R', 'RightLeg'], ['foot.R', 'RightForeFoot'], [], ['toe3-1.R', 'RightToeBase'], ['upperleg01.L', 'LeftUpLeg'], ['lowerleg01.L', 'LeftLeg'], ['foot.L', 'LeftForeFoot'], [], ['toe3-1.L', 'LeftToeBase']])[source]
bvhsdk.skeletonmap.isany(jointname, alljoints=['root', 'Hips', 'spine05', 'Hips', 'spine04', 'Spine', 'spine03', 'Spine1', 'spine02', 'Spine2', 'spine01', 'Spine3', 'neck01', 'Neck', 'neck02', 'Neck1', 'head', 'Head', 'shoulder01.R', 'RightShoulder', 'upperarm01.R', 'RightArm', 'lowerarm01.R', 'RightForeArm', 'wrist.R', 'RightHand', 'finger3-1.R', 'RightHandMiddle1', 'shoulder01.L', 'LeftShoulder', 'upperarm01.L', 'LeftArm', 'lowerarm01.L', 'LeftForeArm', 'wrist.L', 'LeftHand', 'finger3-1.L', 'LeftHandMiddle1', 'upperleg01.R', 'RightUpLeg', 'lowerleg01.R', 'RightLeg', 'foot.R', 'RightForeFoot', 'toe3-1.R', 'RightToeBase', 'upperleg01.L', 'LeftUpLeg', 'lowerleg01.L', 'LeftLeg', 'foot.L', 'LeftForeFoot', 'toe3-1.L', 'LeftToeBase'])[source]
bvhsdk.skeletonmap.ishand(jointname)[source]
bvhsdk.skeletonmap.ishead(jointname, head=['head', 'Head'])[source]
bvhsdk.skeletonmap.iships(jointname, hips=['spine05', 'Hips'])[source]
bvhsdk.skeletonmap.isleftarm(jointname, lArm=['upperarm01.L', 'LeftArm'])[source]
bvhsdk.skeletonmap.isleftfoot(jointname, lFoot=['foot.L', 'LeftForeFoot'])[source]
bvhsdk.skeletonmap.isleftforearm(jointname, lForeArm=['lowerarm01.L', 'LeftForeArm'])[source]
bvhsdk.skeletonmap.isleftforefoot(jointname, lForeFoot=[])[source]
bvhsdk.skeletonmap.islefthand(jointname, lHand=['wrist.L', 'LeftHand'])[source]
bvhsdk.skeletonmap.islefthandmiddle1(jointname, lHandMiddle1=['finger3-1.L', 'LeftHandMiddle1'])[source]
bvhsdk.skeletonmap.islefthandthumb1(jointname, lHandThumb1=[])[source]
bvhsdk.skeletonmap.isleftleg(jointname, lLeg=['lowerleg01.L', 'LeftLeg'])[source]
bvhsdk.skeletonmap.isleftshoulder(jointname, lShoulder=['shoulder01.L', 'LeftShoulder'])[source]
bvhsdk.skeletonmap.islefttoebase(jointname, lToeBase=['toe3-1.L', 'LeftToeBase'])[source]
bvhsdk.skeletonmap.isleftupleg(jointname, lUpLeg=['upperleg01.L', 'LeftUpLeg'])[source]
bvhsdk.skeletonmap.isneck(jointname, neck=['neck01', 'Neck'])[source]
bvhsdk.skeletonmap.isneck1(jointname, neck1=['neck02', 'Neck1'])[source]
bvhsdk.skeletonmap.isneckup(jointname, neckup=['neck03'])[source]
bvhsdk.skeletonmap.isrightarm(jointname, rArm=['upperarm01.R', 'RightArm'])[source]
bvhsdk.skeletonmap.isrightfoot(jointname, rFoot=['foot.R', 'RightForeFoot'])[source]
bvhsdk.skeletonmap.isrightforearm(jointname, rForeArm=['lowerarm01.R', 'RightForeArm'])[source]
bvhsdk.skeletonmap.isrightforefoot(jointname, rForeFoot=[])[source]
bvhsdk.skeletonmap.isrighthand(jointname, rHand=['wrist.R', 'RightHand'])[source]
bvhsdk.skeletonmap.isrighthandmiddle1(jointname, rHandMiddle1=['finger3-1.R', 'RightHandMiddle1'])[source]
bvhsdk.skeletonmap.isrighthandthumb1(jointname, rHandThumb1=[])[source]
bvhsdk.skeletonmap.isrightleg(jointname, rLeg=['lowerleg01.R', 'RightLeg'])[source]
bvhsdk.skeletonmap.isrightshoulder(jointname, rShoulder=['shoulder01.R', 'RightShoulder'])[source]
bvhsdk.skeletonmap.isrighttoebase(jointname, rToeBase=['toe3-1.R', 'RightToeBase'])[source]
bvhsdk.skeletonmap.isrightupleg(jointname, rUpLeg=['upperleg01.R', 'RightUpLeg'])[source]
bvhsdk.skeletonmap.isroot(jointname, root=['root', 'Hips'])[source]
bvhsdk.skeletonmap.isspine(jointname, spine=['spine04', 'Spine'])[source]
bvhsdk.skeletonmap.isspine1(jointname, spine1=['spine03', 'Spine1'])[source]
bvhsdk.skeletonmap.isspine2(jointname, spine2=['spine02', 'Spine2'])[source]
bvhsdk.skeletonmap.isspine3(jointname, spine3=['spine01', 'Spine3'])[source]
bvhsdk.skeletonmap.whichis(jointname)[source]

Returns the method that the joint passed

Parameters:

jointname (str) – Name of the mapped joint

ik

Created on Mon Sep 24 20:06:32 2018

@author: Rodolfo Luis Tonoli

class bvhsdk.ik.SimpleJacobian(animation, end_effector, depth=-1)[source]

Bases: object

Jacobian transpose method with only one end effector 1 End effector N Joints 3 DOF joints No orientation

computeJacobian(referenceframe)[source]

Create the jacobian VECTOR (one end effector)

jacobianTranspose(frame, target, rotnextframe=False, epsilon=1, maxiter=10)[source]

Perform the Inverse Kinematics Jacobian Transpose.

Calculate the Jacobian vector (only one end effector), calculate the rotations step, update the angles values and repeat it until the distance between the target and end effector is less than epsilon

#Ignore :type lastframeref: bool :param lastframeref: if True, uses the previous frame as initial pose

updateValues(rotnextframe=False)[source]

Update the rotation values of the joints in the path from root to end effector. Construct a matrix with theta values and rotate (old) local matrix with it; Extract euler angles from this new rotation (local) matrix; Repeat for the other joints down the hierarchy.

egocentric

Created on Thu Feb 21 21:44:27 2019

@author: Rodolfo L. Tonoli

bvhsdk.egocentriccoord.AdjustExtremityOrientation(animation, surface, ego, sourceanim, frame)[source]
bvhsdk.egocentriccoord.AdjustExtremityOrientation2(animation, sourceanim)[source]
bvhsdk.egocentriccoord.DenormEgoLimb(joint, animation, surface, frame, vectors, jointpositions, egocoord, index)[source]

Denormalize egocentric coordinates for the Limbs

class bvhsdk.egocentriccoord.EgocentricCoordinate(joint, frame)[source]

Bases: object

Egocentric coordinates for the right and left hand (may be also extended to support feet) Objects of this class holds the egocentric coordinates of a joint. The objects contain the respective joint, its name, and a list of reference (length = frame) for the coordinates data of that joint for every frame.

classmethod clean()[source]
egolist = []
getTarget(frame)[source]
bvhsdk.egocentriccoord.GetEgocentricCoordinatesTargets(srcAnim, surfacesrcAnim, tgtAnim, surfacetgtAnim, frame, checkLimbDistanceFlag=True)[source]
bvhsdk.egocentriccoord.extremityNormal(animation, joint, frame)[source]

Returns the surface normal

Estimate the direction of a surface normal for the extrimity joints (hands and feet). Based on the TPose in frame = 0, the initial surface normal is computed through: Get the direction of the bone in the first frame (not the joint’s orientation!) Set a rotation axis equal to the cross product of this direction and the Y-axis [0,1,0] The initial surface normal is the result of a 90 degrees rotation around this axis.

With the initial surface normal computed, apply the same transforms of the joint in the initial surface normal, resulting in the current surface normal.

bvhsdk.egocentriccoord.getJointsPositions(animation, frame)[source]
bvhsdk.egocentriccoord.getMeshPositions(animation, surface, frame)[source]
bvhsdk.egocentriccoord.getVectors(animation, frame)[source]

Get vectors to calculate the kinematic path

Parameters:

animation (pyanimation.Animation) – Animation (skeleton) to get the distance between mapped joints

bvhsdk.egocentriccoord.importanceCalc(dispvector, normal, handthick=3.5)[source]

Calcula a importância da contribuição desse triangulo para a posição da junta

bvhsdk.egocentriccoord.importanceCalcLimb(vectors, limbname, dispvector, normal)[source]

Compute the importance for the limbs (without the surface normal vector)

bvhsdk.egocentriccoord.pathnormCalc(joint, animation, mesh, frame, refpoint, vectors, jointpositions)[source]

Calcula a normalização do caminho cinemático. Recebe a junta e sobe na hierarquia. Caminho cinemático utilizado: Mão - Cotovelo - Ombro - Espinha - Cabeça ou Quadris. Retorna o vetor de deslocamento normalizado e o vetor de cossenos

bvhsdk.egocentriccoord.pathnormCalcLimb(joint, animation, mesh, frame, vectors, jointpositions, surface)[source]

surface

Created on Tue Aug 28 17:13:53 2018

@author: Rodolfo Luis Tonoli

bvhsdk.surface.AvatarSurfacePositionEstimation(avatar, avatarSurface)[source]

Estimates the position of the surface points based on the local transform based on GetAvatarSurfaceLocalTransform()

bvhsdk.surface.FindHandsZeroSpeedGaps(animation, threshold=None, plot=False, minrangewide=20, minpeakwide=40)[source]

Get the animation and find the

bvhsdk.surface.GetAvatarSurfaceFromCSV(path, highpolymesh=True)[source]
bvhsdk.surface.GetAvatarSurfaceLocalTransform(avatar, avatarSurface)[source]

Pega a local baseado na animação com um frame da TPose

bvhsdk.surface.GetCalibrationFromBVHS(frontAnimName, headAnimName, backAnimName, savefile=True, debugmode=False, minrangewide=20, minpeakwide=40, handthreshold=0.5)[source]

Opens the calibration animations (bvh files) and get the calibration positions of the points.

If savefile = True, saves a .txt file containing the calibration local transform of each point

Parameters:
  • frontAnimName (string) – Local path/name of the front calibration animation

  • headAnimName (string) – Local path/name of the head calibration animation

  • backAnimName (string) – Local path/name of the back calibration animation

bvhsdk.surface.GetMoCapSurfaceFromTXT(path=None, highpolymesh=True, minradius=True)[source]
class bvhsdk.surface.Surface(name, highpolymesh=True)[source]

Bases: object

NormalizeSurfaceData(hipsjoint)[source]

Re-scale the avatar surface data to match the joint scale. It uses the global Y position of the hips to re-scale.

hipsjoint: Class Joint object of the avatar hip (or the base of the spine)

getCentroid(animation, meshtype, index, frame)[source]
getPoint(name)[source]
getSurfaceMesh(highpoly=True)[source]
class bvhsdk.surface.SurfacePoint(pointname, pointtype, jointlock)[source]

Bases: object

getPosition(animation, frame=0)[source]

Estima a posição da superfície baseado na transformada local calculada em GetAvatarSurfaceLocalTransform()

bvhsdk.surface.checkName(name)[source]

Return True if the file in the path/name provided exists inside current path

Parameters:

name (string) – Local path/name of the back file

bvhsdk.surface.isNumber(s)[source]

Return True if the string is a number

Parameters:

s (string) – String to be tested as a number

bvhsdk.gui