Class PerData

3DS Max Plug-In SDK

Class PerData

See Also: Class Mesh.

class PerData

Description:

This class is available in release 3.0 and later only.

This class is used for per -'something' floating-point information. For example, it is used with Meshes to keep track of such per-vertex information as weighted (Affect Region or Soft) selections and vertex weights. It is used in MNMesh to store per-edge data (edge weights).

Currently there's only one "type" of data supported, floating point values, but this may be extended in the future. PerData arrays in Meshes and MNMeshes cannot be reserved for plug-ins at this time; 3ds max maintains the list in MESH.H of the reserved vertex data channels, and in MNMESH.H for the MNEdge data channels.

The methods of this class are deliberately made to look like Tab<> methods. All methods of this class are implemented by the system.

Data Members:

All data members are public.

int dnum;

The number of elements of per-vertex data.

int type;

The type of data held by this class. At present the only 3ds max defined option is:

PERDATA_TYPE_FLOAT

int alloc;

The number of elements currently allocated in the data array.

void *data;

Points to the actual data.

The following functions are not methods of this class but are available for use:

Function:

int VertexDataType(int vdID);

Remarks:

Returns the type of data supported, i.e. PERDATA_TYPE_FLOAT.

Parameters:

int vdID

This parameter is ignored.

Function:

void *VertexDataDefault(int vdID);

Remarks:

Returns a pointer to a default floating point value for the specified channel.

Parameters:

int vdID

One of the following values:

VDATA_SELECT - Soft Selection

VDATA_WEIGHT - Vertex weights (for NURMS MeshSmooth)

VDATA_ALPHA - Vertex Alpha values (R4 and later only)

VDATA_CORNER - Cornering values for subdivision use (R4 and later only)

Methods:

public:

Prototype:

PerData();

Remarks:

Constructor. The number of elements is set to 0, the type is set to 0 and the data pointer is set to NULL.

Prototype:

PerData(int n, int tp);

Remarks:

Constructor. The data members are initialized as follows:

data=NULL; dnum=0; alloc=0; type=tp;

Parameters:

int n

The number of elements to allocate.

int tp

The type to set.

Prototype:

~PerData();

Remarks:

Destructor. Any allocated data is freed and the count and type are set to 0.

Prototype:

int DataSize();

Remarks:

Returns the number of bytes used by the base data type for the vertex data. This is only implemented for a type of VDATA_TYPE_FLOAT in which case it returns sizeof(float). Other cases simply return 0.

Prototype:

void *AllocData(int num);

Remarks:

Allocates and returns a pointer to an array of floats of the specified size.

Parameters:

int num

The number of floats to allocate.

Prototype:

void FreeData(void *addr);

Remarks:

Deletes the specified array of floats.

Parameters:

void *addr

Points to the array of floats to free.

Prototype:

void *Addr(void *ptr, int at);

Remarks:

Returns the address of the specified element in the array passed.

Parameters:

void *ptr

The array whose at-th element address is returned.

int at

The zero based index of the element.

Prototype:

void *Addr(int at);

Remarks:

Returns the address of the specified element in the data array.

Parameters:

int at

The zero based index of the element.

Prototype:

void CopyData(void *to, void *from, int num=1);

Remarks:

Copies the specified number of elements between the two data arrays.

Parameters:

void *to

Points to the destination data array.

void *from

Points to the source data array.

int num=1

The number of elements to copy.

Prototype:

void CopyData(int to, int from, int num=1);

Remarks:

Copies the specified number of elements between the two specified locations in the data array.

Parameters:

int to

The zero based index into the data array of the destination.

int from

The zero based index into the data array of the source.

int num=1

The number of elements to copy.

Prototype:

void WeightedSum(void *to, void *fr1, float prop1, void *fr2, float prop2);

Remarks:

Computes the weighted sum of the arguments passed. This is effectivly c = a*prop1 + b*prop2.

This is used, for example, in splitting an edge, where we would want to interpolate the vertex weight values from the edge's endpoints to create the weight for the new vertex.

Parameters:

void *to

A pointer to the location in which the result should be stored.

void *fr1

A pointer to the first value to be summed.

float prop1

The weight given to the first value.

void *fr2

A pointer to the second value.

float prop2

The weight given to the second value.

Prototype:

void WeightedSum(int to, int fr1, float prop1, int fr2, float prop2);

Remarks:

Computes the weighted sum of the arguments passed. This is similar to the method above except to, fr1, and fr2 are indices of the values in the PerData array. That is, PerData::WeightedSum (c, a, prop1, b, prop2), where a, b, and c are ints between 0 and PerData::dnum-1, is equivalent to the call PerData::WeightedSum (PerData::Addr(c), PerData::Addr(a), prop1, PerData::Addr(b), prop2).

Parameters:

int to

The index in the PerData array of the location in which the result should be stored.

int fr1

The index of the first value to be summed in the PerData array.

float prop1

The weight given to the first value.

int fr2

The index of the second value to be summed in the PerData array.

float prop2

The weight given to the second value.

Prototype:

void setAlloc(int num, BOOL keep=TRUE);

Remarks:

Sets the number of elements allocated in the data array.

Parameters:

int num

The number of elements to allocate.

BOOL keep=TRUE

If TRUE previous values are kept (copied to the new storage); otherwise they are discarded.

Prototype:

void SetCount(int num, BOOL keep = FALSE);

Remarks:

Sets the number of elements allocated in the data array and sets the dnum member to num.

Parameters:

int num

The number of elements to allocate.

BOOL keep = FALSE

If TRUE previous values are kept (copied to the new storage); otherwise they are discarded.

Prototype:

void Shrink();

Remarks:

Reduces the size of the data array to contain dnum elelemts.

Prototype:

int Count();

Remarks:

Returns the number of elements used (dnum)

Prototype:

void Clear();

Remarks:

Clears (deletes) any allocated data and sets the count and type to 0.

Prototype:

void DeleteSet(BitArray del);

Remarks:

Removes any element whose corresponding element in the BitArray is not set.

Parameters:

BitArray del

Specifies which elements to delete. Data elelemts corresponding to bits that are on remain; for bits that are off the elements are deleted.

Prototype:

void Delete(int at, int num);

Remarks:

Deletes the specifiec number of elements from the specified location in the data array.

Parameters:

int at

The location to delete elements.

int num

The number of elements to delete.

Prototype:

void Insert(int at, int num, void *el);

Remarks:

Inserts the specified number of data elements into the specified location in the data array.

Parameters:

int at

The zero based index of the location for the insert.

int num

The number of elements to insert.

void *el

The data to insert.

Prototype:

void Append(int num, void *el);

Remarks:

Appends the specified elements to the data array.

Parameters:

int num

The number of elements to append.

void *el

The data to append.

Prototype:

void InsertCopies(int at, int num, void *el);

Remarks:

Inserts the specified number of elements into the data array at the given location.

Parameters:

int at

The zero based index of the location to insert the data.

int num

The number of elements to insert.

void *el

Prototype:

void AppendCopies(int num, void *el);

Remarks:

Appends the specified number of elements to the data array.

Parameters:

int num

The number of elements to append.

void *el

The data to append.

Prototype:

void SwapContents(PerData &from);

Remarks:

Swaps the contents of this PerData object and the specified one.

Parameters:

PerData &from

The object to swap with.

Prototype:

PerData &operator=(PerData &from);

Remarks:

Assignment operator.

Parameters:

PerData &from

The VertexData source.