This runs about 18 times faster (yes, this is still c# code
)
//define this somewhere in your class
struct Point3
{
public float X;
public float Y;
public float Z;
}
Point3* mapP = (Point3*)(mapVerts[0] as Autodesk.Max.Wrappers.Point3).INativeObject__Handle;
Point3* meshP = (Point3*)(mesh.GetVert(0) as Autodesk.Max.Wrappers.Point3).INativeObject__Handle;
for (int i = 0; i < numMapVerts; i++)
{
mapP->X = 1;
if (meshP->Z > HeightThreshold)
{
mapP->Y = Math.Max(0, mapP->Y - FadeInValue);
}
else
{
mapP->Y = Math.Min(1, mapP->Y + FadeInValue);
}
mapP->Z = mapP->Y;
mapP++;
meshP++;
}
for 1000 iterations:
previous fastest version: ~1800ms
this version: ~100ms
It requires you to reference Autodesk.Max.Wrappers in your project, and compile with unsafe code flag.
I wouldn’t recommend doing this in production code, I don’t know what issues could occur.