[SOLVED]Can't get bake function to work
-
On 15/05/2017 at 02:01, xxxxxxxx wrote:
I can't get the bake functino to work. I always got a black output. And There is no informations / exemples in the python sdk.
Moreover it would be nice to have in the sdk which option are needed in all cases(like BAKE_TEX_WIDTH, BAKE_TEX_HEIGHT).
illumBMP = c4d.bitmaps.BaseBitmap() tmp = illumBMP.Init(512, 512, 24, 0) #make sur to init a width/height 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] = True bc[c4d.BAKE_TEX_HEIGHT] = True thread = c4d.threading.GeGetCurrentThread() ibt = c4d.utils.InitBakeTexture(doc, targetTex, targetUVW, targetUVW, bc, thread) #Check if something went wrong if ibt[1] != c4d.BAKE_TEX_ERR_NONE: print ibt return #Assign the new render doc render_doc = ibt[0] bt = c4d.utils.BakeTexture(render_doc, bc, illumBMP, thread, None) #Check if something went wrong if bt != c4d.BAKE_TEX_ERR_NONE: print bt return #save our baked image to somewhere: f_path = os.path.join(tempfile.gettempdir(),"realTimeIllumBake_buffer_picture.jpg") illumBMP.Save(f_path, c4d.FILTER_JPG)
Thanks in advance (it's not very important it's just for myself, so take your time support guys ;))
-
On 16/05/2017 at 03:33, xxxxxxxx wrote:
Hi,
There's an example in the Python SDK for texture baking functions: https://github.com/PluginCafe/cinema4d_py_sdk/blob/master/plugins/Py-TextureBaker/Py-TextureBaker.pyp
You can see in the example that quite some data has to been set into the baking settings for c4d.utils.InitBakeTexture().Also you can simply pass None for the custom thread 'th' for the baking operation initialized with c4d.utils.InitBakeTexture(). Note since R18.039 the parameter is optional.
Passing None or nothing means the baking operation will run on the main thread and will block Cinema 4D's GUI. -
On 16/05/2017 at 04:07, xxxxxxxx wrote:
Thanks you unfortually I still can't get it to work.
Here is the scene.
https://www.sendspace.com/file/4t0w5eSelect light null and execute the script you saw a black result. While if you run the bake from the Bake tag it's work properly.
import c4d import tempfile import os def main() : tag = doc.GetActiveObject() targetTex = None targetUVW = None targetDisp = None try: targetTex = tag[c4d.ID_USERDATA,2] targetUVW = tag[c4d.ID_USERDATA,4] targetDisp = tag[c4d.ID_USERDATA,5] except: return illumBMP = c4d.bitmaps.MultipassBitmap(512, 512, c4d.COLORMODE_RGB) bc = c4d.BaseContainer() bc[c4d.BAKE_TEX_WIDTH] = True bc[c4d.BAKE_TEX_HEIGHT] = True 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 thread = c4d.threading.GeGetCurrentThread() ibt = c4d.utils.InitBakeTexture(doc, targetTex, targetUVW, targetUVW, bc, thread) #Check if something went wrong if ibt[1] != c4d.BAKE_TEX_ERR_NONE: print ibt return #Assign the new render doc render_doc = ibt[0] bt = c4d.utils.BakeTexture(render_doc, bc, illumBMP, thread, None) #Check if something went wrong if bt != c4d.BAKE_TEX_ERR_NONE: print bt return #save our baked image to somewhere: f_path = os.path.join(tempfile.gettempdir(),"realTimeIllumBake_buffer_picture.jpg") illumBMP.Save(f_path, c4d.FILTER_JPG) c4d.bitmaps.ShowBitmap(illumBMP) #Set layer to the bmp layer_sha = targetDisp[c4d.ID_MG_SHADER_SHADER] first_sha_layer = layer_sha.GetFirstLayer() shader = first_sha_layer.GetParameter(c4d.LAYER_S_PARAM_SHADER_LINK) shader[c4d.BITMAPSHADER_FILENAME] = f_path if __name__=='__main__': main()
-
On 16/05/2017 at 06:30, xxxxxxxx wrote:
The issue is you're passing True for BAKE_TEX_WIDTH/BAKE_TEX_HEIGHT settings whereas they should be set to 512.
-
On 16/05/2017 at 06:42, xxxxxxxx wrote:
I feel stupid.
Thanks you.