C++ Interface

The BonesPro Modifier implements a set of user-define properties that provide access to bones and vertex data, as well to several important operations.

To access the BonesPro data plug-in developers should use the Modifier::SetProperty() method. The IDs for the available properties and all necessary data structures used for data exchange are defined in the BonesPro.h file.

The class ID of the BonesPro modifier is also defined in the BonesPro.h file. This class ID can be used to locate BonesPro in the modifier stack.

The list of available properties is given below. The sample code is given with assumption that the Modifier* bonespro variable is defined and stores the pointer to a valid instance of BonesPro with assigned bones. The bone and vertex indices are zero-based.

User-defined Properties of the BonesPro Modifier

BP_PROPID_GET_N_BONES

Returns the number of assigned bones.

int nb = bonespro->SetProperty ( BP_PROPID_GET_N_BONES, NULL );

BP_PROPID_GET_N_VERTS

Returns the number of vertices in the attached mesh.

int nv = bonespro->SetProperty ( BP_PROPID_GET_N_VERTS, NULL );

BP_PROPID_REFRESH

Refreshes the mesh:

bonespro->SetProperty ( BP_PROPID_REFRESH, NULL );

Result:

The weights are recalculated and the mesh is updated. In some cases, the result will not immediately appear in the MAX Viewports, unless you enforce the viewport redraw.

BP_PROPID_GET_WEIGHTS

Returns the weight influences for all bone/vertex pairs

float* weights = (float*)malloc(numBones * numVertices * sizeof(float));
bonespro->SetProperty(BP_PROPID_GET_WEIGHTS, weights);
free(weights);

Result: the storage gets filled with the full set of weights:

weights[v * wa->num_bones + b] = weight of influence imposed by the bone #b onto the vertex #v (0 <= b < nun_bones; 0 <= v < num_vertices).

BP_PROPID_GET_BONE

Fills the BonesPro_Bone structure for bone #b at time = t:

BonesPro_Bone bone;
bone.t = t;
bone.index = b;
bonespro->SetProperty ( BP_PROPID_GET_BONE, &bone );

Result:

bone.node = bone’s INode*
bone.name = bone node name. This name is UTF-8 encoded for unicode compatible versions of 3ds Max.
bone.matrix[4][3] = unscaled transform matrix of the bone (does not necessarily coincide with the node matrix
bone.scale[3] = bone’s bounding box dimensions
bone.falloff = bone’s falloff
bone.strength = bone’s strength
bone.marked = bone’s selected status

To obtain bone’s data at the time of mesh attachment, set the bone.t to BP_TIME_ATTACHED

BP_PROPID_GET_BONE_BY_NAME

Finds the bone index for the given bone name:

BonesPro_Bone bone;
strcpy (bone.name,bone_name);
bonespro->SetProperty ( BP_PROPID_GET_BONE_BY_NAME, &bone );

Result:

bone.index = index of the bone, or -1 if there is no bone with the given name

BP_PROPID_SET_BONE_FALLOFF

Sets the falloff value for bone #b

BonesPro_Bone bone;
bone.index = b;
bone.falloff = f;
bonespro->SetProperty ( BP_PROPID_SET_BONE_FALLOFF, &bone );

Result:

bone’s falloff is set to f.

This operation will not yield an immediate update of the mesh object. To refresh the mesh, use the BP_PROPID_REFRESH property and then redraw the MAX views.

BP_PROPID_SET_BONE_STRENGTH

Sets the strength value for bone #b

BonesPro_Bone bone;
bone.index = b;
bone.strength = s;
bonespro->SetProperty ( BP_PROPID_SET_BONE_STRENGTH, &bone );

Result:

bone’s strength is set to s.

This operation will not yield an immediate update of the mesh object. To refresh the mesh, use the BP_PROPID_REFRESH property and then redraw the MAX views.

BP_PROPID_SET_BONE_MARK

Selects/deselects bone #b

BonesPro_Bone bone;
bone.index = b;
bone.marked = TRUE // or FALSE to deselect;
bonespro->SetProperty ( BP_PROPID_SET_BONE_MARK, &bone );

Result:

The Bone gets selected or deselected. In some cases, the result will not immediately appear in the MAX Viewports, unless you enforce the viewport redraw.

BP_PROPID_GET_VERT_SEL

Retrieves the selection status of vertex #v

BonesPro_Vertex vert;
vert.index = v;
bonespro->SetProperty ( BP_PROPID_GET_VERT_SEL, &vert );

Result:

vert.selected = TRUE if selected, FALSE if not

BP_PROPID_SET_VERT_SEL

Selects/deselects vertex #v

BonesPro_Vertex vert;
vert.index = v;
vert.selected = TRUE; // or FALSE to deselect;
bonespro->SetProperty ( BP_PROPID_SET_VERT_SEL, &vert );

Result:

The vertex gets selected or deselected. In some cases, the result will not immediately appear in the MAX Viewports, unless you enforce the viewport redraw.

BP_PROPID_GET_VERT_DQ

Retrieves the dual quaternion influence for vertex #v

BonesPro_Vertex vert;
vert.index = v;
bonespro->SetProperty ( BP_PROPID_GET_VERT_DQ, &vert );

Result:

vert.dqInfluence = Dual Quaternion influence percentage for the vertex. A value of 0 means that the deformation is fully linear. A value of 100 means it’s fully based on quaternions. Values inbetween blend accordingly between those modes.

BP_PROPID_SET_VERT_DQ

Sets the dual quaternion influence i for vertex #v

BonesPro_Vertex vert;
vert.index = v;
vert.dqInfluence = i;
bonespro->SetProperty ( BP_PROPID_SET_VERT_DQ, &vert );

Result:

Dual Quaternion influence for the vertex is set to w. A value of 0 means that the deformation is fully linear. A value of 100 means it’s fully based on quaternions. Values inbetween blend accordingly between those modes.

BP_PROPID_SET_VERT_SEL_ANI

Performs Select All / Deselect All / Invert Selection operation on vertices

int i = 0; // 0 = select all
           // 1 = deselect all
           // 2 = invert selection
bonespro->SetProperty ( BP_PROPID_SET_VERT_SEL_ANI, &i );

Result:

In some cases, the result will not immediately appear in the MAX Viewports, unless you enforce the viewport redraw.

BP_PROPID_SET_BONE_SEL_ANI

Performs Select All / Deselect All / Invert Selection operation on bones.

int i = 0; // 0 = select all
           // 1 = deselect all
           // 2 = invert selection
bonespro->SetProperty ( BP_PROPID_SET_BONE_SEL_ANI, &i );

Result:

In some cases, the result will not immediately appear in the MAX Viewports, unless you enforce the viewport redraw.

BP_PROPID_GET_BV

Retrieves the information about the influence of bone #b upon the vertex #v.

BonesPro_BoneVertex bv;
bv.bindex = b
bv.vindex = v;
bonespro->SetProperty ( BP_PROPID_GET_BV, &bv );

Result:

bv.included = FALSE if the vertex is excluded from the bone, otherwise TRUE
bv.forced = forced weight of the bone-vertex influence in percent.

BP_PROPID_SET_BV

Sets the include/exclude status and/or the forced weight to bone #b and vertex #v.

BonesPro_BoneVertex bv;
bv.bindex = b
bv.vindex = v;
bv.included = 0; //  0 = make excluded
                 //  1 = make included
                 // -1 = ignore
bv.forced = fw;  // Set to negative value to ignore
bonespro->SetProperty ( BP_PROPID_SET_BV, &bv );

Result:

If bv.included == 0, the vertex gets excluded from the bone
If bv.included == 1, the vertex gets included into the bone
If bv.included == -1, this parameter is ignored
If bv.forced >= 0, the forced weight is set to the percentage bv.forced
If bv.forced <= 0, this parameter is ignored

Setting a forced weight percentage will cause the vertex to be included. If both, a weight and an inclusion state are specified the weight setting takes precedence.

BonesPro.h file

// Begin BonesPro.h file
#ifndef _bonespro_h_
#define _bonespro_h_

#include "max.h"

#define BP_CLASS_ID                  Class_ID(0x37e26e45, 0x543b6b2a)
#define BP_TIME_ATTACHED             TimeValue(0x80000000)
#define BP_PROPID                    (PROPID_USER+0xFF)

#define BP_PROPID_GET_N_BONES        (BP_PROPID + 0)
#define BP_PROPID_GET_N_VERTS        (BP_PROPID + 1)
#define BP_PROPID_GET_WEIGHTS        (BP_PROPID + 2)
#define BP_PROPID_GET_BONE           (BP_PROPID + 3)
#define BP_PROPID_GET_BONE_BY_NAME   (BP_PROPID + 5)
#define BP_PROPID_SET_BONE_FALLOFF   (BP_PROPID + 6)
#define BP_PROPID_SET_BONE_STRENGTH  (BP_PROPID + 7)
#define BP_PROPID_REFRESH            (BP_PROPID + 8)
#define BP_PROPID_SET_BONE_MARK      (BP_PROPID + 9)
#define BP_PROPID_GET_VERT_SEL       (BP_PROPID + 10)
#define BP_PROPID_SET_VERT_SEL       (BP_PROPID + 11)
#define BP_PROPID_SET_VERT_SEL_ANI   (BP_PROPID + 12)
#define BP_PROPID_SET_BONE_SEL_ANI   (BP_PROPID + 13)
#define BP_PROPID_GET_BV             (BP_PROPID + 14)
#define BP_PROPID_SET_BV             (BP_PROPID + 15)
#define BP_PROPID_GET_VERT_DQ        (BP_PROPID + 16)
#define BP_PROPID_SET_VERT_DQ        (BP_PROPID + 17)

#define BP_PROPID_END                (BP_PROPID + 50)


typedef struct
{
  TimeValue t;
  int       index;
  char      name[256];
  INode*    node;
  float     matrix[4][3];
  float     scale[3];
  float     falloff;
  float     strength;
  int       marked;
} BonesPro_Bone;

typedef struct
{
  int   index;
  int   selected;
  float dqInfluence;
} BonesPro_Vertex;

typedef struct
{
  int   bindex;
  int   vindex;
  int   included;
  float forced;
} BonesPro_BoneVertex;

#endif
// End BonesPro.h file