Forum: Poser Python Scripting


Subject: Render a real-time depth map, but how to turn the scene background white?

HartyBart opened this issue on Dec 13, 2023 ยท 3 posts


HartyBart posted Thu, 14 December 2023 at 2:14 PM

Wonderful, many thanks Bwldrd. I had run several searches for "background" across my Poser Python folder, but didn't think to search for SetBackground.

Here is the final working fully-automated script, tested on both Poser 11 and 13.  Useful for those needing a quick depth pass render, but who not want to go to the trouble of setting up an Atmosphere, using a special .MT5, or rendering in Firefly to .PSD with z-buffers on.


# Make a quick depth-qued auto-render from Poser.
# Version 1.0 - December 2023.  Tested in Poser 11 and 13.
# With thanks to bwldrd for the 'SetBackgroundColor' tip.

# From a saved Poser scene, auto render a quick real-time depth-map
# as a .JPG on white, then revert the scene to the last saved scene file.

NOTE: The user will needs to change the output directory 'dirPath=' to their chosen path.

import poser
import datetime

# Set up the saving and timestamp parameters. Change the save directory to suit your needs.
# Remember that the \\ double slashes are vital!! This is for Windows. Mac paths may be different?
dirPath="C:\\Users\\WINDOWS_USER_NAME\\FOLDER_NAME\\"
ext="JPG"
current_date = datetime.datetime.now().strftime ("%a-%d-%b-%Y-%H-%M-%S")

# Are we dealing with a Poser scene?
scene = poser.Scene()

# First, we make the Ground invisible. Thus, no ground shadows or grid.
# Comment out these two lines with #'s if you dont want this to happen.
scene.SelectActor(scene.Actor("GROUND"))
scene.Actor("GROUND").SetVisible(0)

# Now we make sure the render is set to use a DPI of 300.
# And switch the render engine to real-time PREVIEW mode.
# This assumes the user has already set their preferred render size.
scene.SetResolution(3000)
scene.SetCurrentRenderEngine(poser.kRenderEngineCodePREVIEW)

# Now delete all lights in the scene. Then redraw the Poser scene.
lights = scene.Lights()
for light in lights:
    light.Delete()
scene.Draw()

# Now turn on the 'Smooth Shaded' display mode.
poser.ProcessCommand(1083)
scene.Draw()

# Now Toggle 'Depth Cue' display mode on.
poser.ProcessCommand(1044)
scene.Draw()

# Figure style is now set to use document style, in case it wasn't for some reason.
poser.ProcessCommand(1438)
scene.Draw()

# Set the scene's background color to white.
scene.SetBackgroundColor (1.0,1.0,1.0)
scene.Draw()

# Now we render the scene in Preview at 300dpi and save to a .JPG file.
# It must be .JPG otherwise we get a .PNG cutout with alpha and fringing.
# The file is timestamped and saved into the user's preferred directory.
scene.Render()
scene.SaveImage(ext, dirPath + current_date)

# Done. Now we revert the entire scene, to its last saved state. This means
# that it doesn't matter that we changed the display modes and deleted lights.
poser.ProcessCommand(7)



Learn the Secrets of Poser 11 and Line-art Filters.