Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

How to pass objects from the scene/viewport as parameters? C++

How to pass objects from the scene/viewport as parameters? C++

martim.grosner
Enthusiast Enthusiast
964 Views
8 Replies
Message 1 of 9

How to pass objects from the scene/viewport as parameters? C++

martim.grosner
Enthusiast
Enthusiast

I want to pass an object from the viewport as a parameter in a C++ function. It could be something like the classic teapot. I pass in the teapot and in my function I can access it's transform, rotation, scale and whatnot.

0 Likes
Accepted solutions (2)
965 Views
8 Replies
Replies (8)
Message 2 of 9

denisT.MaxDoctor
Advisor
Advisor

what do you mean by "passing" from the viewport? What does the process of "passing" look like according to your vision?

0 Likes
Message 3 of 9

istan
Advisor
Advisor

From my side I have two questions:

a) What do you mean with an "object"? A Node?

a) To which C++ function you want to pass such an "object"? To a MXS function? If we talk about nodes, there exist also node-handles, which can be shared between MXS and C++.

0 Likes
Message 4 of 9

martim.grosner
Enthusiast
Enthusiast
Accepted solution

I mean passing an object as a parameter.

 

Example, you have Class A, and you have Function F. F looks something like this: F(A obj, int i){//body}

 

Now the class A in this example would probably be INode and 'obj' would be the object from the viewport.

 

While working on this I couldn't pass an 'obj' of class INode, but I could pass a pointer 'obj' that points to an INode.

0 Likes
Message 5 of 9

martim.grosner
Enthusiast
Enthusiast

3ds Max has many classes, and according to the documentation, an object(scene element) and a node are virtually the same here.

 

There's the Object class and there are scene elements/objects which are instances of classes that inherit from Object.

 

Answer to a), I mean the scene element/object, but acording to the link it is also the node.

 

Answer to b) I want to pass in a function like the one given as an example in my reply above. It is supposed to be an exposed function in the end. But would this affect anything?

0 Likes
Message 6 of 9

klvnk
Collaborator
Collaborator
Accepted solution

the general procedure is...

 

your are going be passed (how ever that's done) a Node (class INode)

the node is going to  reference an object (the actual box, spline, editable mesh, poly etc), you look at the class of that object and decide if it's what you want

 

usually something like....

 

 

 

 

void myfunc(INode* node)
{
    if(!node) return;

    Object* obj = node->GetObjectRef(); 
    if(obj && obj.ClassID() == MY_CLASS_ID)
    {
          ......

 

 

 

 

 

should be plenty of examples in the sdk, though things get a bit more complicated when modifiers an being used on the incoming node.

 

also worth noting that if you are storing this node in a parameter block the validation of the type is handled by the parameter block code using a PBValidator object (maxsdk\samples\controllers\Path_cnstrnt.cpp is a good example of this)

 

ChannelInfo project in samples is a good place to start on how to handle scene nodes

0 Likes
Message 7 of 9

martim.grosner
Enthusiast
Enthusiast

For a starting point I just want to access it's transform. I don't need to be defensive and make sure the passed object is the exact one I'm looking for. The INode should let me do it right? 

0 Likes
Message 8 of 9

klvnk
Collaborator
Collaborator

virtual Matrix3 INode::GetObjectTM ( TimeValue time, Interval * valid = NULL ) 

 

does for most things

Message 9 of 9

istan
Advisor
Advisor
MaxSDK uses old C/C++ coding style - most "objects" will not be passed by reference, but by pointers.
0 Likes