Notifications
Clear all

[Closed] SDK node->

you’re mistaking PolyObject (the mnmesh holder that travels up the pipeline) with EditablePolyObject/EditablePolyModifier (which has the UI)

here’s a contrived mxs extension function that will create the editable version, I’ve kept some tests in that you would use when not sure of the input …

def_visible_primitive(createPolyBox, "createPolyBox");

Value* createPolyBox_cf(Value** arg_list, int count)
{
	Object* boxobj = (Object*)GetCOREInterface()->CreateInstance(GEOMOBJECT_CLASS_ID, Class_ID(BOXOBJ_CLASS_ID,0));

	if(boxobj && boxobj->CanConvertToType(Class_ID(POLYOBJ_CLASS_ID,0)))
	{	
		TimeValue t = GetCOREInterface()->GetTime();

		boxobj->GetParamBlock()->SetValue(0,t,25.0f);
		boxobj->GetParamBlock()->SetValue(1,t,25.0f);
		boxobj->GetParamBlock()->SetValue(2,t,25.0f);

		PolyObject *pObj = (PolyObject *)boxobj->ConvertToType(t,Class_ID(POLYOBJ_CLASS_ID,0));
		if(pObj != boxobj)		// check for "this" being passed
			boxobj->DeleteMe(); // we've a new object so no longer need the old one

		if(pObj)
		{
			Object* cObj = pObj->CollapseObject();
			if(cObj != pObj)	  // check for "this" being passed	
				pObj->DeleteMe(); // another new object so no longer need the old one
			return MAXNode::intern(GetCOREInterface()->CreateObjectNode(cObj));
		}
	}
	return &undefined;
}

That works perfectly, and that is just what I was after.

Thanks again.

I got this all working for any selected objects and adding their names and Matrix3. It has been a good learning experience.

Something funny happens when I delete the original obj. If I use the “obj->DeleteMe();” from your code it crashes max. So I thought I might try and delete the node “node->Delete(t, 0);”. This is where the funny stuff happens. It deletes the node and works fine, but only on exactly half of what I have selected.


 void Poly_Attach::FN_ConvertToPoly(){
 	ip = GetCOREInterface();
 	TimeValue t = GetCOREInterface()->GetTime();
 
 	int Node_Count;
 	Node_Count = ip->GetSelNodeCount();
 
 	for (int i = 0; i < Node_Count; i++){ 
 		INode *node = ip->GetSelNode(i);
 		Object *obj = node->EvalWorldState(t).obj;
 		Matrix3 tm = node->GetNodeTM(t);
 		const WCHAR *name = node->GetName();
 		if (obj && obj->CanConvertToType(Class_ID(POLYOBJ_CLASS_ID, 0))){
 			PolyObject *pObj = (PolyObject *)obj->ConvertToType(t, Class_ID(POLYOBJ_CLASS_ID, 0));
 			if (pObj && pObj != obj){
 				//obj->DeleteMe(); // THIS WILL CRASH MAX
 				//node->Delete(t, 0); // WILL DO EXACTLY HALF MY OBJECTS
 				Object* cObj = pObj->CollapseObject();
 				INode *NewNode = ip->CreateObjectNode(cObj);
 				NewNode->SetNodeTM(t, tm);
 				NewNode->SetName(name);
 			}
 		}
 	}
 	ip->RedrawViews(ip->GetTime());
 }
 

Not pulling my hair out, still enjoying writing C++ again.

EDIT: also if the object was an editpoly it will skip that selection

Page 2 / 2