Notifications
Clear all

[Closed] C++ Detach by Elements

Hi, I am trying to Detach by Elements. I am trying to use the MeshDelta Detach to do this. I have read the SDK docs on it, and seen other bits of code, but can’t get mine to work. It just doesn’t seem to do anything! Any reason why ?

void PolyTools::PolyDetach(){
 	Object *obj = ip->GetSelNode(0)->EvalWorldState(TimeValue(0)).obj;
 	TriObject *triObj =  (TriObject *) obj;
 
 	MeshDelta meshDelta(triObj->mesh);
 
 	// meshDelta.Detach(Mesh & m, Mesh *out, BitArray fset, BOOL faces, BOOL del, BOOL elem);
 	meshDelta.Detach(triObj->mesh, NULL, triObj->mesh.faceSel, true, true, true);
 	meshDelta.Apply(triObj->mesh);
 }

I know the triObj is working, as I can delete it. I believe it may have something to do with the BitArray ? I did also have a mesh in the out, but as im doing it by elements, I’ve set it to Null.

18 Replies

there is working code for detach in the max sdk sampels: meshop.cpp and polyop.cpp

Thanks, I shall check them out

Ok, I’ve had a look at the different samples and still can’t get this to work. I have been using the meshop.cpp and triops.cpp as references. They both do pretty much the same thing, but it just doesn’t seem to work on mine. Here ‘s my new code.

Object *obj = ip->GetSelNode(0)->EvalWorldState(TimeValue(0)).obj;
 	TriObject *triObj =  (TriObject *) obj;
 
 	MeshDelta meshDelta;
 
 	int nFaces=triObj->mesh.getNumFaces();
 	BitArray Faces (nFaces);
 
 	// meshDelta.Detach(Mesh & m, Mesh *out, BitArray fset, BOOL faces, BOOL del, BOOL elem);
 	meshDelta.Detach(triObj->mesh, NULL, Faces, TRUE, TRUE, TRUE);
 	meshDelta.Apply(triObj->mesh);

how do you want to detach it? to new mesh? no new node?

look at meshop_detachFaces_cf in meshop.cpp file

I would like to detach then into a new TriObject, but just getting to detach into two new mesh would be great. I have been looking at the meshop code. But I don’t see that many differences between that code and mine. Even tried adding in the MeshDeltaUser bit and still nothing is happening.

	MeshDelta tmd;
	Mesh* newMesh = new Mesh();
	tmd.Detach(*mesh, newMesh, faces, TRUE, TRUE, FALSE);
	tmd.Apply(*mesh);

it’s what you basically have to do … newMesh will get detached faces

Ok, thank you, but even with them just as meshes, its still not detaching … I’ve checked to make sure it isn’t my Obj or triobj causing the issue. Its now like your code, but still nothing. Really strange Just in case, the new code is below:

Object *obj = ip->GetSelNode(0)->EvalWorldState(TimeValue(0)).obj;
 	TriObject *triObj =  (TriObject *) obj;
 	Mesh *oldMesh = &triObj->GetMesh();
 
 	MeshDelta meshDelta;
 
 	int nFaces=triObj->mesh.getNumFaces();
 	BitArray Faces (nFaces);
 
 	Mesh* newMesh = new Mesh();
 
 	// meshDelta.Detach(Mesh & m, Mesh *out, BitArray fset, BOOL faces, BOOL del, BOOL elem);
 	meshDelta.Detach(*oldMesh, newMesh, Faces, TRUE, TRUE, FALSE);
 	meshDelta.Apply(*oldMesh);
 
 	ip->RedrawViews(ip->GetTime());

but you don’t apply old mesh. i see your want to change owned mesh. so you have to apply this mesh to owner.

see this part:

	MeshDeltaUser *mdu = (owner) ? GetMeshDeltaUserInterface(owner) : NULL;
	MeshDelta tmd;
	Mesh* newMesh = NULL;
	if (asMesh)
		newMesh = new Mesh();
	tmd.Detach (*mesh, newMesh, faces, TRUE, del, !asMesh);
	if (mdu) 
		GetMeshDeltaUserDataInterface(owner)->ApplyMeshDelta (tmd, mdu, MAXScript_time());

where owner is the ReferenceTarget which owns the original mesh

Ok, I have used that before, but just checked it, and its coming up null. I see if I can get the Reference for my Mesh. Thanks for the help.

Page 1 / 2