Mon, Nov 25, 11:05 PM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: How to make a Poser texture image display what a camera sees?


Anthony Appleyard ( ) posted Tue, 13 February 2018 at 5:48 AM · edited Wed, 20 November 2024 at 3:01 PM

If a Poser scene has:

  • A main camera, which is being used for the current image.
  • An object P which has a textured surface P2 which is visible on the main camera.
  • A camera Dolly2, parented to some object such as a gun, e.g. to see what the gun's sight sees. Can I, within one Poser run (probably needing a Python script), render what Dolly2 sees, then feed the resulting rendered image into one of textured surface P2's texture nodes, then make the main render using the main camera?


an0malaus ( ) posted Sat, 22 June 2019 at 5:36 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. Screen Shot 2019-06-22 at 8.21.21 pm.png Here's the view from the gun sight cam (Dolly Camera) before rendering

Screen Shot 2019-06-22 at 8.21.51 pm.png

and here's the final render from the Main Camera Screen Shot 2019-06-22 at 8.24.59 pm.png

showing the texture automagically loaded onto the square prop.

Cheers, an0malaus



My ShareCG Stuff

Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.


Anthony Appleyard ( ) posted Sat, 22 June 2019 at 5:52 AM

Thanks.


Privacy Notice

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.