Hi,
I managed to simulate a parenting behavior in the xpresso node editor.
You can see it in this illustration video below:
https://www.dropbox.com/s/isw8bibg6r8u3ot/c4d270_parenting_in_script_form.mp4?dl=0
It works well. As you can see, the child
follows the parent
even though it is not parented in the hierarchy.
My problem is I want it to be in a script form (executes only once) rather than on a Xpresso editor (executes every time or live)
Here is my code so far. It is the same logic I used in the node editor.
import c4d
from c4d import gui
# Main function
def main():
parent = doc.SearchObject("parent")
child = doc.SearchObject("child")
child_parent_wrd_mat = child.GetUpMg() # Since there are no direct parent. This will be the default world matrix
parent_wrd_mat = parent.GetMg()
child_offset_mat = ~parent.GetMg() * child.GetMg()
overall_mat = child_parent_wrd_mat * parent_wrd_mat * child_offset_mat
# Rotating the Parent
parent[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Y] += 0.5
# This should also move the child based on the parent's rotation but it does not
# Same thing happens if I move the rotating parent before retreiving the matrices.
# Again, I'm not sure how to implement it on a script. Only on a node.
child.SetMg(overall_mat)
c4d.EventAdd()
# Execute main()
if __name__=='__main__':
main()
You can also check the C4D File with the Xpresso Parent Behavior here:
https://www.dropbox.com/s/isw8bibg6r8u3ot/c4d270_parenting_in_script_form.mp4?dl=0
Regards,
Ben