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 Wed, 13 December 2023 at 4:44 AM

The script belowautomates the setup and rending of a real-time depth-map of a Poser scene, then reverts the changes to the scene. My question is about line 50, which opens the background color-picker for the user. There the user still needs to manually change the scene background color to white, then is expected to press 'OK'.  Is there some way to change the background color of a Poser scene automatically, by using Python code?

Result:



Code:

# Quickie depth map auto-render for Poser.
# Made December 2023.  Tested in Poser 13.

# 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.

# The user only needs to change the output directory dirPath, and to
# choose the white colour for the background, when the script prompts for this.

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!!
dirPath="C:\\Users\\YOUR_USER_NAME\\YOUR_SAVED_FILES\\"
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.

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 set to use document style, in case it doesn't for some reason.
poser.ProcessCommand(1438)
scene.Draw()

# Have the user set the scene's background colour to white.
poser.ProcessCommand(1269)

# Now we render the scene and save to a .JPG file. The filename 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 display modes and deleted lights.
poser.ProcessCommand(7)



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


bwldrd posted Thu, 14 December 2023 at 8:32 AM

scene.SetBackgroundColor (1.0,1.0,1.0) .. this is from the poser 11 Poser Python Methods Manual.pdf, but still works in 13.

--------------------------------------------------------------------------------

Consider me insane if you wish, but is your reality any better?


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.