How can i get the related polyobject through INode?

How can i get the related polyobject through INode?

Anonymous
Not applicable
978 Views
6 Replies
Message 1 of 7

How can i get the related polyobject through INode?

Anonymous
Not applicable

As I know, we can find the object through INode and turn them to triobject then get it's mesh.

But what the relationship between INode and poly?

How can i get the polyobject?

0 Likes
Accepted solutions (1)
979 Views
6 Replies
Replies (6)
Message 2 of 7

michaelsonbritt
Advocate
Advocate

See example below.

  • INode::GetObjectRef() returns either the base object (if there are no modifiers) or a DerivedObjects (which represents a modifier stack).  Both of these are type Object.
  • The value of type Object is either a PolyObject (like an Editable Poly base object, or the result flowing up the stack from an Edit Poly modifier), or it might be something convertable to a PolyObject (like a Teapot base object)
  • So the process is to (1) get the base object or DerivedObject flowing up the stack, and then (2) get the Poly from it directly if it's already PolyObject, or convert to PolyObject, or fail if it's not convertable.

There are various exceptions and special cases, so try some searches through maxsdk\samples and see how other areas of the code handle this task.  You can just search for "GetObjectRef" and "IsSubClassOf".

Regards,

Michaelson Britt

 

	// First get the object
	BOOL del = FALSE;
	PolyObject *obj = NULL;
	ObjectState os = node->GetObjectRef()->Eval(t);
	if (os.obj->IsSubClassOf(polyObjectClassID))
	{
		obj = (PolyObject *) os.obj;
		// obj->mm hold the Poly mesh
	}
	else {
		if (!os.obj->CanConvertToType(polyObjectClassID)) return;
		obj = (PolyObject*)os.obj->ConvertToType (t, polyObjectClassID);
		if (obj!=os.obj) del = TRUE; // Make sure to delete this object later!
	}

 

Message 3 of 7

Anonymous
Not applicable

Thank you very much for replying!!

And I also want to ask a question:

I know the modifier will change the mesh information about the object. If I get a IDerivedObject,  then I can get the base object in it through the function FindBaseObject(), but I will lost the modifier's change and the mesh will be the original mesh without the modifier. How can I get the mesh Information after using the modifier?

0 Likes
Message 4 of 7

michaelsonbritt
Advocate
Advocate
Accepted solution

The code is the same.  The call

ObjectState os = node->GetObjectRef()->Eval(t);

will evaluate the modifiers and return the top-of-stack object.  That's what the Eval() method is doing.

 

Michaelson Britt

Message 5 of 7

Anonymous
Not applicable

Thank you!! It is a great answer which helps me a lot.

But there is still a problem, that the object in 3dmax is smoothed nice and beautiful, but the mesh which I exported and drew is not very smooth,why?

And how can I export and drew it smoother?11.png12.png13.png14.png

0 Likes
Message 6 of 7

michaelsonbritt
Advocate
Advocate

How did you perform the export, and what other software are you importing to?

Maybe you need to switch from "flat shaded" to "phong shaded" in that other software.  But you haven't provided enough information to answer this.

 

Regards,

Michaelson Britt

0 Likes
Message 7 of 7

Anonymous
Not applicable

Thank you very much for your help!

I want to export it to sketchup, but there is a problem in soften and smooth the mesh

0 Likes