Clone Texture Tag to Children while preserving Coordiates
-
Hi,
if i have a parent with a texture tag and somewhere down the tree a child without texture tag
it gets the parents texture. i now need to clone the texture tag onto the child while preserving the same projection (coordinates / rotation / scale)Texture tag coordinates / scale / rotation always refer to its objects coordinate system.
So if i clone the the tag to a direct child (or somewhere deeper down the tree) i need to compensate the matrix differences of the parent object and the child object.lets say i have
parent (BaseObject) and parenttag (the parents BaseTag, c4d.Ttexture)
child (BaseObject) and childtag (the childs BaseTag, c4d.Ttexture)then i have
parent.GetMg()
child.GetMg()
parenttag.GetMl()and I need to calculate/set
childtag.SetMl(?)Anyone with a tip on how to get the childtag matrix
so that the texture is projected the same way
as if child would inherit the projection from ptag on the parent?I hope the problem is understandable
by the way... this is all because of a bug in the collada exporter
it simply ignores materials inherited from parents (at least for instances)
thats why i try to copy down the tags with the correct projection,
and then do the export.best, index
-
Here a barebone example not working correctly, yet
just use it with the attached file in the script managerif the code is right, the cube should get a texture tag
but the texture still look exactly the same as beforefrom c4d import gui def main(): parent = doc.SearchObject('parent') op = doc.SearchObject('child') ptag = parent.GetTag(c4d.Ttexture) tag = ptag.GetClone() op.InsertTag(tag) # handle coordinates / rotation # (not working correctly) pMg = parent.GetMg() oMg = op.GetMg() tMl = tag.GetMl() t = pMg * oMg tag.SetMl(t * tMl) c4d.EventAdd() if __name__=='__main__': main()
-
Hello,
For your next threads, please help us keeping things organised and clean.- Q&A New Functionality.
- How to Post Questions especially the tagging part.
I've added the tags and marked this thread as a question so when you considered it as solved, please change the state
About your question, something like this should work, that's what the CopyTag To child is doing.
parent = doc.SearchObject('parent') op = doc.SearchObject('child') ptag = parent.GetTag(c4d.Ttexture) tag = ptag.GetClone() op.InsertTag(tag) tMl = ptag.GetMl() mm = ~op.GetMl() * tMl tag.SetMl(mm) c4d.EventAdd()
I will have a look at the "bug" you are referring.
Cheers,
Manuel -
@m_magalhaes
Thanks Manuel,
This works for direct children,
but it fails if you add one or more nulls under the parent
with different location/rotation/scale and the child inside the last null..example:
parent (null) TextureTag null null null child
i try if i can extend your code .)
-
hello,
you can use global matrix probably (not sure if you want to copy paste on all children or skip some).
But if you want to copy paste on all child, you already have a command for that.tMl = parent.GetMg() * tag.GetMl() mm = ~op.GetMg() * tMl tag.SetMl(mm)
Cheers,
Manuel -
@m_magalhaes :
i traverse the complete tree and apply it only for the last child in every branch
(if it doesnt have a tag on its own)and thanks a lot, the code works!
only if there is a null in the tree with a scale != (1,1,1) things go off.this is normally not the case, but just out of interest...
would it be possible to handle that so easy, too?
or would you need to traverse-translate down the tree?
parent --> null (with scale) --> childbest, index
-
The scale are in fact the length of each vector of the matrix, it should work.
I'm maybe stupid but i can't reproduce your behavior, could you provide a file ?
and sorry for the bad testing of my code : /
Cheers,
Manuel -
here is the example, its just
parent null (with a scale) child
(all with different positions/rotations)
i had some experience with those translations,
but didnt use them for quite some time...
they're tricky .)so, thank you a lot for helping here!
-
example file :
InheritTex5.c4dand code :
(not working correctly, due to objects with scale)import c4d from c4d import gui def main(): parent = doc.SearchObject('parent') op = doc.SearchObject('child') ptag = parent.GetTag(c4d.Ttexture) tag = ptag.GetClone() op.InsertTag(tag) # handle coordinates / rotation tMg = parent.GetMg() * ptag.GetMl() mm = ~op.GetMg() * tMg tag.SetMl(mm) c4d.EventAdd() if __name__=='__main__': main()
-
Hello,
i was trying that with a scaling of the object. In your example, you are adding skewing to the object. If you add rotation to the tag, the projection become skewed.
I've tried to warp my head around this. The problem is that the tag doesn't store his information of position, scale and rotation with a matrix but with three vectors instead. So you can't add a negative skew to counter the first one. (i hope i'm clear)
The tag in the parent is not skewed, but if you add the tag in your object it will be skewed. (with rotation)
The only way to do that would be to "reset" the object's Global Matrix so the tag will not be deformed. But you have to compensate the points.
# Texture tag information are stored as three vectors and not as a matrix. tag = op.GetTag(c4d.Ttexture) bc = tag.GetDataInstance() print bc[c4d.TEXTURETAG_POSITION] print bc[c4d.TEXTURETAG_SIZE] print bc[c4d.TEXTURETAG_ROTATION]
By the way the command "copy tag to children" doesn't work with this kind of scenario.
Cheers,
Manuel -
hi manuel,
thanks... and just to understand...
the screenshot is not from the example above?
(in inherittex5.c4d the child is not skewed)but i guess its the same problem, right?
I've tried to warp my head around this. The problem is that the tag doesn't store his information of position, scale and rotation with a matrix but with three vectors instead. So you can't add a negative skew to counter the first one. (i hope i'm clear)
yes i understand... but as you can do tag.GetMl() / SetMl() ... is this still not a real matrix? or differently used than the normal object matrices?
i thought, that it might be impossible to fix this in an easy way
but luckily this is a rare special casebest, index
ps. the background of all this was to do an export to fbx/dae
and i found some other issues there...
where would be the proper channel to report that? -
@indexofrefraction said in Clone Texture Tag to Children while preserving Coordiates:
but as you can do tag.GetMl() / SetMl() ... is this still not a real matrix? or differently used than the normal object matrices?
that's what i looked for but it does call functions to store those informations to the three vector i showed previously.
the screenshot is coming from your file, i simply used the texture tool (on left)
ps. the background of all this was to do an export to fbx/dae
and i found some other issues there...
where would be the proper channel to report that ?If it's a programming issue you can do that here, I will check and open bug entry for them.
if it's something that is also happening "by hand" and is more a bug of the software you can use our support system.
If you say that you are creating a script they will forward you towards us so maybe the best is to open a new thread here and post your issue about exporting to specific format. (maybe one by format ?)Cheers,
Manuel -
ah... ok, now i understand the picture !
thanks, manuelI marked the thread as solved