Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
The part of the material you addressed (via Python) is only the informative part. It serves for example to create an OBJ file or the corresponding ".mat" file in a simple way. This includes the texture names and some rudimentary information, which is (or should be) a summary of the used material shaders.
If you want to make a visible change to a material, you have to change the associated shader. Roughly, this requires:
* The corresponding root node (Firefly, Superfly).
* The shader tree based on it.
* The nodeset that represents the property to be changed (can also be a property of the root shader).
(A bit more complicated if the material uses material layers).
To change the base color of the preview material in the currently selected Poser Actor to red, the following is necessary:
material = poser.Scene().CurrentActor()
tree = material.ShaderTree()
# we know the first node in this shadertree is the root node, and we want to change the first entry of this node.
node = tree.Nodes()[0]
inp = node.Inputs()[0]
inp.SetColor(1.0, 0.0, 0.0) # RGB in floating point notation
or short:
material.ShaderTree().Nodes()[0].Inputs()[0].SetColor(1.0, 0.0, 0.0)
Perhaps the following script (used as lib) may be helpful when working with materials:
As usual the forum editor messed with my posted code.
And also as usual one may download the source from my server:
JimX posted at 8:26 AM Wed, 7 June 2023 - #4467373
That makes some sense. The nodes I had found probably had to do with some much earlier version of Poser, before shader tress were introduced.
Yes, I remember the old way to do it.
Shaders really do have massive advantages, though. And once you've got it right, you can do it easily and quickly with Python.
Unlike much else in Poser, where there is more chaos than structure, the structure of materials, shader trees and shader nodes is logical and effective - so they are very easy to deal with in Python.
Good luck!I'll go forward based on your suggestions.
Many thanks!
Don't be shy to ask if you get stuck somewhere. Sometimes a little external hint loosens thick knots :)
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.
I did some Python scripting for another application a few years ago. The Python knowledge is coming back just fine, but I am slowly slogging up the learning curve for the Poser classes and methods. I've studied the pydoc, and I've looked at a lot of sample scripts. I am using Poser 12 on a Mac.
My project involves changing the Texture Map (and maybe later, some other maps) on an object. I wrote a quick script to test my understanding of the process:
import poser
scene = poser.Scene()
actor = scene.CurrentActor()
mtl = actor.Material('hair')
mtl.SetDiffuseColor(0.5, 0.0, 0.0)
print ('Diffuse Color should have been set')
print ('Texture before =', mtl.TextureMapFileName() )
mtl.SetTextureMapFileName('/Users/Shared/Poser 12 Content/Downloads/Runtime/textures/KozHair/KyokoHair_Mk2/KyokoHr2TxBlondGold.jpg')
print ('Texture after =', mtl.TextureMapFileName() )
I have a basic scene with on Victoria 4 figure and one prop-style hair object parented to it. I have the hair selected, and in the Material Room I have the "hair" material selected. There is the Poser_Surface node, and three image nodes (one each for texture map, specular map, and transparency map). When I run the script, I get
Diffuse Color should have been set
Texture before = /Users/Shared/Poser 12 Content/Downloads/Runtime/textures/KozHair/KyokoHair_Mk2/KyokoHr2TxBlack.jpg
Texture after = /Users/Shared/Poser 12 Content/Downloads/Runtime/textures/KozHair/KyokoHair_Mk2/KyokoHr2TxBlondGold.jpg
So some texture map path somewhere seems to have been changed.
However, the Diffuse_Color on the Poser_Surface node has not changed at all. Nor have any of the texture maps in either of the image_map nodes changed (they are still exactly what was printed on the "Texture before = " line).
Clearly, my understanding of the process still needs some help. Does anyone have any pointers?
Many thanks for any suggestions.