Thanks Klvnk
I did the following test before I saw you replay and it seems to be working but I’m not sure if its the right way to do it.
One thing is that when I tried by writing mesh = mesh + tmesh; like you have it, I lost the uv’s of the original plane.
I used CombineMeshes which I saw used on particalmesher.cpp, collapse.cpp and Parray.cpp and it seems to work fine, Why should I use mesh = mesh +tmesh ?
I have a few questions on the code below.
- On creating the plane: How do you find out what the id’s for setting the parameters for the plane? I used the code you posted here. Creating plane with 3dsMax SDK and guessed about the uv’s but the realscale does not seems to be doing anything.
- On the loop where I create 6 copies how do I delete the copyMesh ? if I delete it max crashes.
- Also it seems I need to delete the tempMesh too but it also crashes max.
Interface *ip = GetCOREInterface();
int planeWsegs = 1;
int planeLsegs = 1;
bool planeUV = true;
bool planeWorldScale = false;
float planeSize = 5.0f;
SimpleObject2* planeObj = (SimpleObject2*)GetCOREInterface()->CreateInstance(GEOMOBJECT_CLASS_ID, PLANE_CLASS_ID);
IParamBlock2* pb = (IParamBlock2*)planeObj->GetReference(0);
if (pb)
{
pb->SetValue(1, 0, planeSize*2.0f);
pb->SetValue(0, 0, planeSize);
pb->SetValue(2, 0, planeWsegs);
pb->SetValue(3, 0, planeLsegs);
pb->SetValue(6, 0, planeUV);
pb->SetValue(7, 0, planeWorldScale);
}
Object *obj = planeObj->CollapseObject();
int t = 0;
TriObject *tri = NULL;
if (obj->CanConvertToType(Class_ID(POLYOBJ_CLASS_ID, 0)))
{
PolyObject *pTri = (PolyObject *)obj->ConvertToType(t, Class_ID(POLYOBJ_CLASS_ID, 0));
if (pTri->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0))) {
tri = (TriObject *)pTri->ConvertToType(t, Class_ID(TRIOBJ_CLASS_ID, 0));
}
}
Mesh& planeMesh = tri->GetMesh();
Mesh tempMesh;
tempMesh.DeepCopy(&tri->GetMesh(), GEOM_CHANNEL | TOPO_CHANNEL | TEXMAP_CHANNEL | MTL_CHANNEL | DISP_ATTRIB_CHANNEL | TM_CHANNEL);
for (int m = 0; m < 5; m++)
{
Matrix3 tm(1.0);
Matrix3 rotate;
Mesh copyMesh = tri->GetMesh();
tm.Translate(Point3((planeSize*2) + m, 0.0f, 0.0f));
// Move the new plane around
for (int v = 0; v < copyMesh.numVerts; v++)
{
copyMesh.verts[v] = copyMesh.verts[v] * tm;
}
CombineMeshes(planeMesh, tempMesh, copyMesh);
}
planeMesh.InvalidateGeomCache();
INode* planeNode = GetCOREInterface()->CreateObjectNode(tri);
TSTR name(T("superPlane"));
ip->MakeNameUnique(name);
planeNode->SetName(name);
Point3 pt(5.0, 5.0, 0.0);
Matrix3 tm;
tm.SetTranslate(pt);
planeNode->SetNodeTM(TimeValue(0), tm);
Guillermo