Correct . However it is expensive(for a dev) to do it that way when you know
you can just use one unsigned int that get assigned in every call of
setdepdirty() , and it goes also with the fact that you only have to worry
about one attribute change at a time , and it is not necessary to store every
indices like that , the use of MArrayDataHandle::jumpToArrayElement() with
MArrayDataHandle::elementIndex() is a recommended combo to iterate over the
array of compounds/element even in the documentation , and you will need to
call MDataBlock::inputArrayValue() once you are in compute anyway so … this
m_element_index thing is just here so I know what element is tingling so that I
don’t have to do expensive complete calculations, it’s lazy evaluation if you
want
Sent from Mail for Windows 10
From: Rob Engle
Sent: Saturday, March 17, 2018 7:40 PM
To: Python Programming for Autodesk Maya
Subject: Re: [Maya-Python] Why most people use boolean flags insteadofcatching
the MPlug ?
My question is slightly off topic to this thread but motivated by the posted
code sample...
I was under the impression that setDependentsDirty can be called any number of
times with different arguments before compute is called (if ever). This would
mean that storage of m_element_index (or caching of any information from
setDependentsDirty) would need to store more than just the one call. This
could be solved by making m_element_index an array of cached values and compute
handling all of them. Is this right?
Rob
On Saturday, March 17, 2018 at 7:03:16 AM UTC-7, justin hidair wrote:
/*in the boolean flag case :
lets say aDistance and aAmount are both child of a compound in an array of
compound*/
MStatus myclass::setDependentsDirty(const MPlug &plug, MPlugArray &affect)
{
mayastream << "dirtying. .." << "\n";
if(plug.isChild() && plug.attribute() == aDistance )
{
e_distance_change= true ;
/*get index to target this attribute specifically will be
useful with MArrayDataHandle*/
m_element_idx = plug.parent().logicalIndex();
}
else
if(plug.isChild() && plug.attribute() == aAmount )
{
e_amount_change= true ;
/*get index to target this attribute specifically will be
useful with MArrayDataHandle*/
m_element_idx = plug.parent().logicalIndex();
}
return MPxNode::setDependentsDirty(plug , affect );
}
MStatus myclass::compute(...)
{
//typical moves:
cmp_array = datablock.inputArrayValue(aArray);
if( e_distance_change == true )
{
/* perform targeted calculations
use cmp_array.jumpToElement(m_element_idx)*/
}
else
if(e_amount_change == true )
{
/*perform targeted calculations
use cmp_array.jumpToElement(m_element_idx)*/
}
//...
}
/*in the use Plug case :
lets say aDistance and aAmount are both child of a compound in an array of
compound*/
MStatus myclass::setDependentsDirty(const MPlug &plug, MPlugArray &affect)
{
mayastream << "dirtying. .." << "\n";
m_dirty_plug = plug;
/*just one line and we can use the plug however we want
the benefit is we also have all the methods of MPlug
like .isConnected and so on , aslong as the method stay ) const
we can use it in compute without a problem...
we can use this to get index in array :
m_dirty_plug.parent().logicalIndex();
now to compute() ... */
return MPxNode::setDependentsDirty(plug , affect );
}
MStatus myclass::compute(...)
{
//things I never saw:
cmp_array = datablock.inputArrayValue(aArray);
if(m_dirty_plug.isChild() && m_dirty_plug.attribute() == aDistance )
{
/*perform targeted calculations
use all the cool const methods of MPlug
use cmp_array.jumpToElement(m_dirty_plug.parent().logicalIndex())*/
}
else
if(m_dirty_plug.isChild() && m_dirty_plug.attribute() == aAmount)
{
/*perform targeted calculations
use all the cool const methods of MPlug
use cmp_array.jumpToElement(m_dirty_plug.parent().logicalIndex())*/
}
/*...
optionnaly at the end you can if you want reset m_dirty_plug with
m_dirty_plug.setMObject(MObject::kNullObj) but it's not really required
because it
will be reassigned ... it allow to use .isNull() in particular cases tho
lot of things you can do with just a plug instead of 4 boolean flags, it's
also
way easier to maintain*/
}
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/07e1f6bd-6c6e-4225-8d2f-6c85e758676a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/5aad739d.04191c0a.a6f51.09e0%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.