Last active
March 26, 2018 17:35
-
-
Save bonsak/7ed3514746de1bd7ce81 to your computer and use it in GitHub Desktop.
Mimic UDIM in Cinema4D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re, c4d | |
| from c4d import documents as docs | |
| # Python tag that Mimics UDIM for texture tags in Cimena4D. | |
| # Name your texture tags 1001, 1002, 1021 etc | |
| # Doesn't check the number of tag on each row | |
| # Iterates through all tags on the object that this script is attached to | |
| # Find all texture tags with with name that starts with 10 (UDIM style) | |
| # Check if they are of type texture (5616) | |
| class TagIterator: | |
| def __init__(self, obj): | |
| currentTag = None | |
| if obj : | |
| self.currentTag = obj.GetFirstTag() | |
| def __iter__(self): | |
| return self | |
| def next(self): | |
| tag = self.currentTag | |
| if tag == None : | |
| raise StopIteration | |
| self.currentTag = tag.GetNext() | |
| return tag | |
| def main(): | |
| obj = op.GetObject() | |
| tags = TagIterator(obj) | |
| for tag in tags: | |
| # Check first if tag type is Texture | |
| if tag.GetType() == 5616: | |
| # Then check if Tag name starts with 10 | |
| if tag[c4d.ID_BASELIST_NAME][:2] == "10": | |
| # Take the 4th character and subtract 1 to get U | |
| offsetU = float(tag[c4d.ID_BASELIST_NAME][3]) - 1.0 | |
| # Take the 3rd character and multiply with -1 to get V | |
| offsetV = float(tag[c4d.ID_BASELIST_NAME][2]) * -1 | |
| # print "Offset U %s" % tag[c4d.TEXTURETAG_OFFSETX] | |
| # print "Offset V %s" % tag[c4d.TEXTURETAG_OFFSETY] | |
| # Set U and V | |
| tag[c4d.TEXTURETAG_OFFSETX] = offsetU | |
| tag[c4d.TEXTURETAG_OFFSETY] = offsetV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment