Class HitMesh

3DS Max Plug-In SDK

Class HitMesh

See Also: Class Osnap, The Advanced Topics section on Snapping..

class HitMesh

Description:

This class is available in release 2.0 and later only.

This is a class to hold a list of object space points for highlighting the geometry associated with a hit. One oddity of this class is that you need to allocate one point more than the number of points you actually need. This additional storage is used for clipping against the viewport at display time. For example the "endpoint" snap would alocate a three-point hitmesh to highlight the edge which was hit (See the example below) .

The class has data members for the number of points and a pointer to the actual Point3 list.

In practice, developers need only use the first two methods shown below.

Methods:

Prototype:

HitMesh(int n);

Remarks:

Constructor. The number of vertices is set to the value n passed and the points array is allocated with that size. This is the constructor that plugin developers will typically use in conjunction with the setVert() method described below.

Parameters:

int n

The number of points to allocate.

Prototype:

void setVert(int i, const Point3 &xyz);

Remarks:

Sets the 'i-th' vertex to the specified value.

Parameters:

int i

The vertex to set.

const Point3 &xyz

The value to set.

In practice, developers need only use the two previous methods. The following code segment from the mesh snap exemplifies their use.

//add the hit points based on the active subsnaps

if(GetActive(EDGE_SUB)

)// The edge snapping is active and we have a hit on the edge defined by from and to.

 HitMesh *hitmesh = new HitMesh(3); //Allocate one more than we need.

 hitmesh->setVert(0, from);

 hitmesh->setVert(1, to);

 

 float dap = Length(cursor - sf2);

 assert(Length(st2 - sf2)>=0.0f);

 float pct = (float)sqrt(fabs(dap*dap - distance*distance)) / Length(st2 - sf2);

 Point3 cand;

 float pctout = gw->interpWorld(&xyz[0],&xyz[1],pct,&cand);

 theman->RecordHit(new EdgeHit(cand, this, EDGE_SUB, hitmesh, ifrom, ito, pct));

}

Prototype:

HitMesh();

Remarks:

Constructor. The number of points is set to zero and the point list is set to NULL.

Prototype:

HitMesh(const HitMesh& h);

Remarks:

Constructor. The number of points and the points are initialized from the HitMesh passed.

Parameters:

const HitMesh& h

The HitMesh to init from.

Prototype:

~HitMesh();

Remarks:

Destructor. If point list is allocated it is freed.

Prototype:

int getNumVerts();

Remarks:

Returns the number of points in this HitMesh.

Prototype:

void setNumVerts(int n);

Remarks:

Sets the number of vertices. This frees any existing verts and allocates new ones.

Parameters:

int n

The number of points to allocate.

Prototype:

Point3& getVert(int i);

Remarks:

Returns the 'i-th' vertex.

Prototype:

Point3* getVertPtr();

Remarks:

Returns a pointer to the array of points.

Operators:

Prototype:

Point3 operator[](int i);

Remarks:

Access operator. Return the 'i-th' point.

Parameters:

int i

Specifies the point to return.