Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
I don't know if you had this question answered anywhere else, but it seemed like a nice little programming exercise, so I gave it a go. I chose a primitive, one sided square called 'square_1' as object 'P' and its material name is 'Preview' (P2) with an additional specification of the image_map node name 'Diffuse Map', so you could work with multiple images in that material and only change the right one. I've used 'Dolly Camera' as the gun sight cam, and 'Main Camera' as the render cam, with configurable resolutions for both of them (set as X,Y tuples).
Here's the script: (save as GunSightRender.py)
# GunSightRender.py
# (c) 2019 an0malaus (Geoff Hicks/GeoffIX/gwhicks)
#
# Requested on Renderosity by AnthonyAppleyard 2018
#
# v1.0 20190622 Initial version.
########################################################################################################################
version = '1.0'
import poser
import os
imagePath = 'Somewhere/on/your/computer/gun view.jpg'
imageType = 'jpg'
imageQuality = 80
#gunCamName = 'Dolly2'
gunCamName = 'Dolly Camera'
gunCamRes = (256,256)
renderCamName = 'Main Camera'
renderRes = (512,512)
picturePropName = 'square_1' # 'P'
pictureMatName = 'Preview' # 'P2'
imageNodeName = 'Diffuse Map'
imageNodeType = poser.kNodeTypeCodeIMAGEMAP
imageSrc = 'Image_Source'
scene = poser.Scene()
gunCam = scene.Actor(gunCamName)
assert gunCam and gunCam.IsCamera(), 'Camera "{}" not found!'.format(gunCamName)
renderCam = scene.Actor(renderCamName)
assert renderCam and renderCam.IsCamera(), 'Camera "{}" not found!'.format(renderCamName)
pictureProp = scene.Actor(picturePropName)
assert pictureProp and pictureProp.IsProp(), 'Prop "{}" not found!'.format(picturePropName)
mat = None
imageNode = None
try:
mat = pictureProp.Material(pictureMatName)
except:
pass
assert mat, 'Prop "{}" has no material "{}"!'.format(picturePropName,pictureMatName)
found = False
for layer in mat.Layers() or []:
tree = layer.ShaderTree()
for node in tree.Nodes() or []:
if node.Type() == imageNodeType and node.Name() == imageNodeName:
found = True
break
else:
continue # try next layer
break # Only get here if found
assert found, 'Prop "{}", material "{}" has no "{}" node "{}"!'.format(picturePropName,pictureMatName,imageNodeType,imageNodeName)
scene.SetCurrentCamera(gunCam)
scene.SetOutputRes(*gunCamRes) # Resolution of render output, tuple unpacked into parameters
scene.Render()
scene.SaveImage(imageType,imagePath,imageQuality)
assert os.path.exists(imagePath), 'Saved render "{}" not found!'.format(imagePath)
input = node.InputByInternalName(imageSrc)
input.SetString(imagePath)
tree.UpdatePreview()
scene.DrawAll()
scene.SetCurrentCamera(renderCam)
scene.SetOutputRes(*renderRes) # Resolution of render output, tuple unpacked into parameters
scene.Render()
print 'Done.'
### END ###
You'll need to put a real path in the imagePath string. I used a known folder on my Mac, which won't work for anyone else. Here's the material setup for the object P (square_1). Note the name set to 'Diffuse Map' which identifies which image_map node will be updated. Here's the view from the gun sight cam (Dolly Camera) before rendering
and here's the final render from the Main Camera
showing the texture automagically loaded onto the square prop.
Cheers, an0malaus
Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.
This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.
If a Poser scene has: