Ahh, I was changing the wrong numbers … had all the offset and stuff from that sample, but didn’t change one bit … Silly me Thanks for all your help guys
Hi, Got a new issue, sure its something simple but can’t figure out why its doing it. If I slice my Object, then that new Slice will be selected. Although, when I run it again for a second time, it will select both the new slice and the old one. I am making sure I’m deselecting everything, so can’t understand why its selecting the old slice as well. I will post my code below:
void PolyTools::SlicePlane(INode* node){
ip = GetCOREInterface();
t = GetCOREInterface()->GetTime();
srand (time(NULL));
PolyObject *newObj = PolyObjectFromNode(node, t);
newObj->SelectAll(4);
MNMesh* mm = &newObj->GetMesh();
mm->ClearAllFlags();
Box3 box = mm->getBoundingBox ();
Object *newObject = (Object*)ip->CreateInstance(HELPER_CLASS_ID, Class_ID(POINTHELP_CLASS_ID, 0));
INode *HelpNode = ip->CreateObjectNode(newObject);
float x, y, z;
for(int j = 0; j < 5; j++){
int rx = rand();
int ry = rand();
int rz = rand();
float fraction = ((float) rx / RAND_MAX) * (box.pmax.x - box.pmin.x);
x = box.pmin.x + fraction;
fraction = ((float) ry / RAND_MAX) * (box.pmax.y - box.pmin.y);
y = box.pmin.y + fraction;
fraction = ((float) rz / RAND_MAX) * (box.pmax.z - box.pmin.z);
z = box.pmin.z + fraction;
}
Point3 RandHelp(x, y, z);
Matrix3 tm;
tm.SetTranslate(RandHelp);
HelpNode->SetNodeTM(TimeValue(0), tm);
BitArray Edges;
mm->getEdgeSel(Edges);
mm->EdgeSelect(Edges);
Point3 planeNormal, planeCenter, sliceCenter;
sliceCenter = HelpNode->GetNodeTM(t).GetTrans();
Matrix3 rotMatrix;
Quat sliceRot = (0.0f, 0.0f, 0.0f,1.0f);
sliceRot.MakeMatrix (rotMatrix);
planeNormal = Point3(0.0f,0.0f,1.0f) * rotMatrix;
planeCenter = sliceCenter;
float offset = DotProd(planeCenter, planeNormal);
mm->Slice(planeNormal, offset, 0.0f, FALSE, FALSE);
node->SetObjectRef(newObj);
Edges.ClearAll();
ip->RedrawViews(ip->GetTime());
}
have to ask why are doing it like this and not as a modifier ? make your life a lot easier
I’m doing this way as I will be slicing a lot of objects at once, and don’t want to add a modifier to each object just to slice it. Also last time you said its easier by modifier, you said I should learn to do it the SDK way instead of adding modifiers, so I’m trying not to ^^ The code I’ve got works fine, I just need to deselect the old slices when creating new slices. But as I’m deselecting them, I can’t see where its getting the information from ?
you said I should learn to do it the SDK way instead of adding modifiers,
I think you misunderstood me, I was suggesting you do it as a modifier as that is the SDK way.
Ok, but from a point of speed, surely adding modifiers, collapsing them would be slower than just using MNMesh ??
Edit* : on a large scale of course ^^
eh ? but your doing that anyway
Object* ret = pTri->CollapseObject();
Edit* : on a large scale of course ^^
you do know you can add 1 modifier to every node in the scene if you want too ?
Very true xD Let me explain what I’m doing ( might put some context in place xD ) I need to be able to slice an object multiple times at different heights, which could be up to 1000 slices per object and then extract a spline from that slice. This is why I’m going through the MNMesh slice, as this way I only need to call it to slice it. The whole PolyfromNode thing will only be called once ( final version ) so that way, if its not a Editable poly, it will become one ( so the collapse should only be called once ). So do you still think it would be easier to go by modifier ? As I need this to be running fast. Hopefully this helps you understand what I’m trying to do ^^
So do you still think it would be easier to go by modifier ?
yes, sounds perfect.
Hey, I’ve just started rewriting this code so it goes by Modifer, but can’t find the Class_ID for the Slice modifier !! What is it called ?? Thanks