**THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED**

*On 08/10/2009 at 06:35, ***xxxxxxxx** wrote:

OK, I found it's easier to write my own crumple function than to find my way through undocumented tool functions... I'll share the code here.

Please note that this code was written very hasty It works, but it could be cleaner.

> <code>void CrumpleGeometry(PolygonObject *op, Real Strength, Random &Rnd;)

> {

> if (!op) return;

>

> LONG PointCount = op->GetPointCount();

> LONG p = 0;

>

> Vector Norm = Vector();

> Vector *parr = op->GetPointW();

>

> Neighbor nb;

> if (!nb.Init(PointCount, op->GetPolygonW(), op->GetPolygonCount(), NULL)) return;

>

> for (p = 0; p < PointCount; p++) {

> Norm = GetVertexNormal(p, op, &nb;);

> parr

>

> += Norm * Strength * Rnd.Get11();

> }

> }

> </code>

And here's the used GetVertexNormal() function, which I wrote earlier from tipps here in the Café...

> <code>Vector GetVertexNormal(LONG PointIndex, PolygonObject *op, Neighbor *neighbor)

> // Gets the normal vector for a vertex of a polygon object.

> // Needs an initialized Neighbor class

> {

> // Variables

> CPolygon *pNeighborPoly;

> LONG j, faceCnt, *pFaces = NULL;

> Vector v1, v2, vNorm = Vector();

> CPolygon *m_pPolys = op->GetPolygonW();

> Vector *m_pPoints = op->GetPointW();

>

> // Get polygons attached to point

> neighbor->GetPointPolys(PointIndex, &pFaces;, &faceCnt;);

> if(!faceCnt) return vNorm;

>

> for(j=0; j<faceCnt; j++)

> {

> pNeighborPoly = &m;_pPolys[pFaces[j]];

>

> // Compute face normal

> v1 = m_pPoints[pNeighborPoly->b] - m_pPoints[pNeighborPoly->a];

> v2 = m_pPoints[pNeighborPoly->c] - m_pPoints[pNeighborPoly->a];

> vNorm += v1 % v2; // get cross-product

> }

> vNorm /= faceCnt;

>

> // Return resuling normal vector

> return !vNorm;

> }

> </code>

Cheers,

Jack