(SDK) equivalent to mxs "modPanel"

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

REPLY TO THREAD
 
Thread Tools Display Modes
  02 February 2016
OK, Now I understand, Denis, what your question meant. And you are right: I'm looking for something simpler.
Thanks again you both for your help.
__________________
Andrés FC.
P3D_PathScripts
 
  02 February 2016
SDK.NET functions for "objects" & "getChildNodes"


        //  Recursive search for children nodes of a node
        static public void searchChildrenNodes(IINode rootNode, ref List<IINode> theNodes)
        {
            int numNodes = rootNode.NumberOfChildren;

            for (int i = 0; i < numNodes; i++)
            {
                IINode node = rootNode.GetChildNode(i);
                theNodes.Add(node);
                searchChildrenNodes(node, ref theNodes);
            }

            theNodes.Distinct();
        }

        //  All scene nodes
        static public List<IINode> Objects()
        {
            IGlobal global = GlobalInterface.Instance;
            IInterface14 ip = global.COREInterface14;
            IINode rootNode = ip.RootNode;

            List<IINode> theNodes = new List<IINode>();
            searchChildrenNodes(rootNode, ref theNodes);

            return theNodes;
        }


        //  Children nodes of a node
        static public List<IINode> childNodes(IINode rootNode)
        {
            List<IINode> theNodes = new List<IINode>();
            searchChildrenNodes(rootNode, ref theNodes);

            return theNodes;
        }

Call them throught:
- All scene nodes:
List<IINode> objects = Objects();
- Children nodes of a node 'theNode'
List<IINode> theChildNodes = childNodes(theNode);
__________________
Andrés FC.
P3D_PathScripts

Last edited by aaandres : 02 February 2016 at 06:13 PM.
 
  02 February 2016
And, finally, 'dependentNodes' function (return just nodes that have the input modifier applied or it's their base object).

        //  Get Dependents Nodes (for modifiers and baseObjects)
        static public List<IINode> dependentNodes(IBaseObject modif)
        {
            List<IINode> DepNodes = new List<IINode>();

            if (modif == null)
            {
                DepNodes = null;
                return DepNodes;
            }

            IntPtr modifHandle = modif.Handle;
            List<IINode> objects = Objects(); // Returns all scene nodes

            foreach (IINode node in objects)
            {
                var derivedObject = node.ObjectRef as IIDerivedObject;    

                if (derivedObject != null)
                {
                    //  The node has modifiers
                    int numSubAnims = derivedObject.NumSubs; 
                    for (int i = 0; i < numSubAnims; i++)
                    {
                        IAnimatable subAnim = derivedObject.SubAnim(i);
                        IntPtr subAnimHandle = subAnim.Handle;

                        if (subAnimHandle == modifHandle)
                        {
                            DepNodes.Add(node);
                        }
                    }
                }
                else
                {
                    //  The node has any modifier
                    IntPtr baseObjectHandle = node.ObjectRef.Handle;
                    if (baseObjectHandle == modifHandle)
                    {
                        DepNodes.Add(node);
                    }
                }
            }

            return DepNodes;
        }

Call it by:
List<IINode> theDepNodes = dependentNodes(modif);
where 'modif' is an IBaseObject (modifier or BaseObject)
__________________
Andrés FC.
P3D_PathScripts
 
  02 February 2016
something is definitely going wrong with
refs.dependentnodes 


check this out:

delete objects
b = box()
uv_modi = Uvwmap()
addmodifier b uv_modi
refs.dependentnodes uv_modi


yes. it depends as expected.

now:

delete b
refs.dependentnodes uv_modi


it doesn't have a dependency because the b-node was deleted.
sounds right


but...

delete objects
modiTest = attributes modiTest
(
	parameters params 
	(
		modi type:#maxobject
	)
)
c = createinstance modiTest
b = box()
b.custattributes[1] = c
refs.dependentnodes c 


all is OK. a dependentcy is here

but...
delete b
refs.dependentnodes c


and we have a dependency to the deleted node!

what is wrong? the first or the second case?

i'm absolutely sure that the system keeps 'dependency' to deleted node in both cases, but only in the second case it's notified.

so... my question is: where is the truth?
 
  02 February 2016
What can you do with a deleted node?
If the answer is "nothing", then the second behaviour has any sense.

As far as I know, really very few, with a deleted node you can just ask if the node is deleted... that's more than nothing!.

Just one question: what can be usefull for to keep a modifier as a custom attribute parameter?
__________________
Andrés FC.
P3D_PathScripts
 
  02 February 2016
I have done some tests to see how fast are these functions, comparing to calling them via maxscript inside the C# code.

As my function "get all scenes nodes" is faster than calling "objects as array" with mxs (not vey much), my function "get dependent nodes" is slower by far (x10) than calling "refs.dependentNodes (getAnimByHandle modif)".
I can't see where the bottleneck can be. Any ideas or suggestions?
__________________
Andrés FC.
P3D_PathScripts
 
  02 February 2016
Originally Posted by aaandres: Just one question: what can be usefull for to keep a modifier as a custom attribute parameter?

let's say if we want to keep some modifier in the scene but don't want to have it applied.
 
  02 February 2016
Originally Posted by aaandres: I have done some tests to see how fast are these functions, comparing to calling them via maxscript inside the C# code.

As my function "get all scenes nodes" is faster than calling "objects as array" with mxs (not vey much), my function "get dependent nodes" is slower by far (x10) than calling "refs.dependentNodes (getAnimByHandle modif)".
I can't see where the bottleneck can be. Any ideas or suggestions?


refs.dependentNodes must be faster. it needs pretty simple DependentEnumProc.
the code is in SDK:
class GetDependentNodesProc : public DependentEnumProc
{
public:
	ReferenceTarget* obj;
	Array* result;
	Value** item;
	BOOL firstOnly;
	BOOL baseObjOnly;
	bool isBaseObject;

	GetDependentNodesProc(ReferenceTarget* obj, Array* result, Value** item, BOOL firstOnly, BOOL baseObjOnly) 
	{ 
		this->obj = obj;
		this->result = result; 
		this->item = item; 
		this->firstOnly = firstOnly; 
		this->baseObjOnly = baseObjOnly; 
		isBaseObject = (GetObjectInterface(obj) != NULL);
	}
	int proc(ReferenceMaker *rmaker)
	{
		if (!isBaseObject && baseObjOnly)
			return DEP_ENUM_HALT;

		if (rmaker == (ReferenceMaker*)obj)
			return DEP_ENUM_CONTINUE;

		Class_ID cid = rmaker->ClassID();
		SClass_ID sid = rmaker->SuperClassID();
		if (sid == REF_MAKER_CLASS_ID && cid == CUSTATTRIB_CONTAINER_CLASS_ID)
		{
			Animatable *amaker = ((ICustAttribContainer*)rmaker)->GetOwner();
			if (amaker == NULL)
				return DEP_ENUM_CONTINUE;
			rmaker = (ReferenceMaker*)amaker->GetInterface(REFERENCE_MAKER_INTERFACE);
			if (rmaker == NULL)
				return DEP_ENUM_CONTINUE;
			cid = rmaker->ClassID();
			sid = rmaker->SuperClassID();
		}

		if (sid == MAKEREF_REST_CLASS_ID || sid == DELREF_REST_CLASS_ID || sid == MAXSCRIPT_WRAPPER_CLASS_ID)
			return DEP_ENUM_SKIP;

		MAXClass* cls = MAXClass::lookup_class(&cid, sid);
		if (cls == &inode_object)
		{
			Value *oldItem = *item;
			INode *node = (INode*)rmaker;
			*item = MAXNode::intern(node);
			if (firstOnly)
			{
				if (!isBaseObject && !baseObjOnly)
					return DEP_ENUM_HALT;
				Object* base_obj = node->GetObjectRef();
				if (base_obj->SuperClassID() == GEN_DERIVOB_CLASS_ID)
					base_obj = ((IDerivedObject*)base_obj)->FindBaseObject();
				if (base_obj == obj)
					return DEP_ENUM_HALT;
				else if (oldItem)
					*item = oldItem;
			}
			else
			{
				if (baseObjOnly)
				{
					Object* base_obj = node->GetObjectRef();
					if (base_obj->SuperClassID() == GEN_DERIVOB_CLASS_ID)
						base_obj = ((IDerivedObject*)base_obj)->FindBaseObject();
					if (base_obj == obj)
						result->append(*item);
				}
				else
					result->append(*item);
				*item = &undefined;
			}
			return DEP_ENUM_SKIP;
		}
		return DEP_ENUM_CONTINUE;
	}
}; 


in case where we look for modifier-dependent nodes the proc can be simple as:
class GetDependentNodesProc : public DependentEnumProc
{
public:
	ReferenceTarget* obj;
	Array* nodes;

	GetDependentNodesProc(ReferenceTarget* obj, Array* nodes) 
	{ 
		this->obj = obj;
		this->nodes = nodes; 
	}
	int proc(ReferenceMaker* rmaker)
	{
		if (rmaker == (ReferenceMaker*)obj) return DEP_ENUM_CONTINUE;

		Class_ID cid = rmaker->ClassID();
		SClass_ID sid = rmaker->SuperClassID();

		if (sid == MAKEREF_REST_CLASS_ID || sid == DELREF_REST_CLASS_ID || sid == MAXSCRIPT_WRAPPER_CLASS_ID)
			return DEP_ENUM_SKIP;

		MAXClass* cls = MAXClass::lookup_class(&cid, sid);
		if (cls == &inode_object)
		{
			INode* node = (INode*)rmaker;
			result->append(MAXNode::intern(node));
			return DEP_ENUM_SKIP;
		}
		return DEP_ENUM_CONTINUE;
	}
};


i would pass modifier in proc and check if this modifier applied to the node
 
  02 February 2016
Thanks DenisT.
I'll try to 'translate' that... but I think I woint be able to.
__________________
Andrés FC.
P3D_PathScripts
 
  03 March 2016
Hi DenisT.

You use in your code "isBaseObject = (GetObjectInterface(obj) != NULL);" that I can't find the equivalent in C#.
I suppose it's to know if the node has modifiers or not... that can speed up clearly my code.

Can you think about a workaround using other properties to know if a node has modifiers (OSM or WSM) applied? I'm not able to.
__________________
Andrés FC.
P3D_PathScripts
 
  03 March 2016
#define GetObjectInterface(anim)	((BaseObject*)(anim)->GetInterface(I_BASEOBJECT))


it's how GetObjectInterface defined. so you need to convert to c# (that should be easy):
(BaseObject*)(anim)->GetInterface(I_BASEOBJECT) 


anim is obj in our case
 
  06 June 2018
Edit: sorry!
__________________
Andrés FC.
P3D_PathScripts

Last edited by aaandres : 06 June 2018 at 08:15 AM.
 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 11:11 AM.


Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.