Hello, perhaps it is pretty self explanatory from the title what I am seeking to do.
I am avoiding making a plugin at all costs due to the added complexity (both from a developmental standpoint as well as having to ask IT to install a plugin across a massive farm for a single job).
So, I am trying to do everything from a Python Tag which I know carries caveats in terms of what is possible. But in a nutshell, I am trying to render a material channel on one object and then apply the result in an xbitmap shader in another material.
So far I have tried a few things, but with no success because I can't find examples of other people doing this so far.
I have tried:
- creating a bake texture tag and using CallButton on the bake button, using a frame checker to make sure it runs only once when the frame is changed. This should work, but then the file that is generated and written to disk tries to overwrite itself which displays a dialog asking "Yes or No" and I have yet to figure out how to "click" one of these buttons to get through this dialog.
- creating a new bitmap and using c4d.utils.BakeTexture, but I am running into issues getting this set up as there are no examples running it from a Python Tag (nor do I know if it's even feasible)
Thanks for any and all help / recommendations!
Follow up postings (edited by @ferdinand):
Hello again, checking back in. I have made some progress using an example I found:
https://developers.maxon.net/forum/topic/461
My code so far is as follows:
import c4d
import tempfile
import os
#Welcome to the world of Python
def main():
# Set some variables
obj = op.GetObject()
texTags = [obj.GetTag(c4d.Ttexture)]
texUVWs = [obj.GetTag(c4d.Tuvw)]
destUVWs = [obj.GetTag(c4d.Tuvw)]
# Bake texture setup
bc = c4d.BaseContainer()
bc[c4d.BAKE_TEX_WIDTH] = 512
bc[c4d.BAKE_TEX_HEIGHT] = 512
bc[c4d.BAKE_TEX_CONTINUE_UV] = False
bc[c4d.BAKE_TEX_SUPERSAMPLING] = 0
bc[c4d.BAKE_TEX_FILL_COLOR] = c4d.Vector(1)
bc[c4d.BAKE_TEX_USE_BUMP] = False
bc[c4d.BAKE_TEX_USE_CAMERA_VECTOR] = False
bc[c4d.BAKE_TEX_AUTO_SIZE] = False
bc[c4d.BAKE_TEX_NO_GI] = False
bc[c4d.BAKE_TEX_GENERATE_UNDO] = False
bc[c4d.BAKE_TEX_PREVIEW] = False
bc[c4d.BAKE_TEX_SURFACECOLOR] = True
bc[c4d.BAKE_TEX_UV_LEFT] = 0.0
bc[c4d.BAKE_TEX_UV_RIGHT] = 1.0
bc[c4d.BAKE_TEX_UV_TOP] = 0.0
bc[c4d.BAKE_TEX_UV_BOTTOM] = 1.0
bc[c4d.BAKE_TEX_NORMAL_METHOD] = c4d.BAKE_TEX_NORMAL_METHOD_OBJECT
# Initialize bake texture
bakeInfo = c4d.utils.InitBakeTexture(doc, texTags, texUVWs, destUVWs, bc, None)
# Create new bitmap and bake texture
newBitmap = c4d.bitmaps.MultipassBitmap(512, 512, c4d.COLORMODE_RGB)
bakeTextureInfo = c4d.utils.BakeTexture(bakeInfo[0], bc, newBitmap, None, None)
# Store bitmap to file
tempFilePath = os.path.join(tempfile.gettempdir(), "tempBitmap.png")
newBitmap.Save(tempFilePath, c4d.FILTER_PNG)
print(tempFilePath)
return None
if __name__=='__main__':
main()
However I am getting crashes immediately after running the InitBakeTexture command. Any idea what I'm doing wrong?
Also for some reason the tag script will run over 300 times upon file save even if the tag is disabled when InitBakeTexture exists in the script. Assuming this has something to do with thread = None and running on the main thread?
R25.010
I tried print(texTags, texUVWs) in the Set some variables section and then got the following error after doing 334 logs for the above issue:
RecursionError: maximum recursion depth exceeded while getting the repr of an object
Seems like when I do InitBakeTexture and save the file, it's opening another thread recursively and running the script again. Not sure why this is happening, but I'm pretty sure this is why I am getting crashes when I actually enable the tag.
EDIT: looks like InitBakeTexture is causing a stack overflow, but I have no idea why.
EDIT2: just realized it's creating a new doc. Ah ha
EDIT3: okay not sure if it's a new doc or what, but it's definitely looking like a stack overflow. Any ideas why this is happening?
Simplified test code (applied to Python Tag):
import c4d
#Welcome to the world of Python
def main():
# Set some variables
obj = op.GetObject()
texTags = [obj.GetTag(c4d.Ttexture)]
texUVWs = [obj.GetTag(c4d.Tuvw)]
destUVWs = [obj.GetTag(c4d.Tuvw)]
print(texTags, texUVWs)
# Bake texture setup
bc = c4d.BaseContainer()
bc[c4d.BAKE_TEX_COLOR] = True
bc[c4d.BAKE_TEX_COLOR_ILLUM] = True
bc[c4d.BAKE_TEX_NO_INIT_BITMAP] = True
bc[c4d.BAKE_TEX_WIDTH] = 512
bc[c4d.BAKE_TEX_HEIGHT] = 512
bakeInfo = c4d.utils.InitBakeTexture(doc, texTags, texUVWs, destUVWs, bc, None)
return None
if __name__=='__main__':
main()
I believe InitBakeTexture causing a stack overflow
I should mention this only happens when making a change to the Python Tag script and then saving the file.