Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Clone Texture Tag to Children while preserving Coordiates

    Cinema 4D SDK
    python
    2
    13
    1.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • indexofrefractionI
      indexofrefraction
      last edited by Manuel

      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

      1 Reply Last reply Reply Quote 0
      • indexofrefractionI
        indexofrefraction
        last edited by indexofrefraction

        Here a barebone example not working correctly, yet
        just use it with the attached file in the script manager

        if the code is right, the cube should get a texture tag
        but the texture still look exactly the same as before

        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
            # (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()
        

        InheritTexExample.c4d

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by

          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

          MAXON SDK Specialist

          MAXON Registered Developer

          indexofrefractionI 1 Reply Last reply Reply Quote 0
          • indexofrefractionI
            indexofrefraction @Manuel
            last edited by indexofrefraction

            @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 .)

            1 Reply Last reply Reply Quote 0
            • ManuelM
              Manuel
              last edited by

              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

              MAXON SDK Specialist

              MAXON Registered Developer

              1 Reply Last reply Reply Quote 0
              • indexofrefractionI
                indexofrefraction
                last edited by indexofrefraction

                @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) --> child

                best, index

                1 Reply Last reply Reply Quote 0
                • ManuelM
                  Manuel
                  last edited by

                  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

                  MAXON SDK Specialist

                  MAXON Registered Developer

                  1 Reply Last reply Reply Quote 0
                  • indexofrefractionI
                    indexofrefraction
                    last edited by indexofrefraction

                    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!

                    1 Reply Last reply Reply Quote 0
                    • indexofrefractionI
                      indexofrefraction
                      last edited by

                      example file :
                      InheritTex5.c4d

                      and 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()
                      
                      1 Reply Last reply Reply Quote 0
                      • ManuelM
                        Manuel
                        last edited by Manuel

                        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.

                        skew.JPG

                        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

                        MAXON SDK Specialist

                        MAXON Registered Developer

                        1 Reply Last reply Reply Quote 0
                        • indexofrefractionI
                          indexofrefraction
                          last edited by indexofrefraction

                          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 case

                          best, 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?

                          1 Reply Last reply Reply Quote 0
                          • ManuelM
                            Manuel
                            last edited by Manuel

                            @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)
                            skew2.JPG

                            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

                            MAXON SDK Specialist

                            MAXON Registered Developer

                            1 Reply Last reply Reply Quote 0
                            • indexofrefractionI
                              indexofrefraction
                              last edited by

                              ah... ok, now i understand the picture !
                              thanks, manuel

                              I marked the thread as solved

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post