Notifications
Clear all

[Closed] c++ Best method for slicing?

Hi, I am looking to slice my object but without going into any subobject level (trying to avoid selecting any face/vert etc). I have try the MNMesh Slice, but I can only seem to get it to work by going into the subobject level and turning on SlicePlane, which I would like to avoid if possible. Anyone know of a good method for slicing ? Thanks

Edit*: I also want to stay within the MNMesh / Editable Poly for Slicing my object.

24 Replies

what’s wrong with MNMesh Slice method? It works very well for me.

They may not be anything wrong with MNMesh slice, just the issue I’m having is that it won’t slice unless I go into the Slice Plane first … I have had a look at your code from another thread but can’t seem to make this work. I need to be able to slice my object at different heights. This is my code so far:

	node->CenterPivot(TimeValue(0), FALSE);
   	PolyObject *newObj = PolyObjectFromNode(node, t);
   	
   	MNMesh* mm = &newObj->GetMesh();
   
   	BitArray verts(mm->numv);
   	mm->FaceSelect(verts);
   	BitArray Edges(mm->nume);
   	mm->FaceSelect(Edges);
   
   	Point3 planeNormal, planeCenter, sliceCenter;
   	sliceCenter = Point3(0.0f, 0.0f, 0.0f);
   	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);
   	ip->RedrawViews(ip->GetTime());

everything looks right (except VertexSelect and EdgeSelect should probably be)
i don’t understand you manipulations with matrix, but it doesn’t effect anyway.

the question is – how you get PolyObject?

Hi, the matrixs are all taken from the samples in the sdk. Its just want they had used, although after messing with them they do nothing … but kept them in just in case for the moment. I shall put my PolyfromNode function below, buts its basicly what you showed me the other day.

PolyObject* PolyTools::PolyObjectFromNode(INode *pNode, TimeValue t){
 	bool deleteIt = TRUE;
 	Object *pObj = pNode->EvalWorldState(t).obj;
 	if (pObj->CanConvertToType(Class_ID(POLYOBJ_CLASS_ID, 0))) {
 		PolyObject *pTri = (PolyObject *)pObj->ConvertToType(t, Class_ID(POLYOBJ_CLASS_ID, 0));
 		Object* ret = pTri->CollapseObject();
 		pTri = (PolyObject*)ret;
 		if (pObj != pTri) deleteIt = TRUE;
 		return pTri;
 	}
 	else {
 		return NULL;
 	}
 }

So apart from the Matrixs doing nothing, why isn’t my code slicing ??

you use probably wrong PolyObject. it’s a copy as i see. if you want to use it anyway you have to set new object to the node.

Object* obj = node->GetObjectRef();
if (obj->ClassID() == EPOLYOBJ_CLASS_ID) PolyObject *poly = dynamic_cast<PolyObject *>(obj);

it’s how it should be

Ok, it is just about working, but im still getting an issue. Only just found out that it may have been slicing all this time, but only at the based of the Object. I only found this out when I moved the bottom 4 verts of my box and the slice worked where the original 4 verts used to be. So where/how can I set up a Matrix transform so I can move the slices position/rotation ? As the mm->Slice only uses Point3 ?? Thank you for helping me.

looks like good stuff

the editpoly implementation showing how to compute the offset

bool EditPolyObject::EpfnSliceMesh (MNMesh & mesh, int msl, DWORD flag) {
 	if (msl == MNM_SL_CURRENT) msl = meshSelLevel[selLevel];
 	int i;
 	if (msl == MNM_SL_FACE) {	// do flagged faces only.
 		for (i=0; i<mesh.numf; i++) {
 			if (mesh.f[i].GetFlag (MN_DEAD)) continue;
 			if (mesh.f[i].GetFlag (flag)) break;
 		}
 		if (i==mesh.numf) return false;
 	}
 	Point3 planeNormal, planeCenter;
 	EpGetSlicePlane (planeNormal, planeCenter);
 	float offset = DotProd (planeNormal, planeCenter);
 	BOOL sliceSplit;
 	pblock->GetValue (ep_split, TimeValue(0), sliceSplit, FOREVER);
 	bool ret = mesh.Slice (planeNormal, offset, MNEPS,
 		sliceSplit?true:false, false, (msl==MNM_SL_FACE)?true:false, flag);
 	return ret;
 }

you have to understand that offset and normal are in the object space.

Page 1 / 3