Forum: Poser Python Scripting


Subject: JointVertexWeights and TwistVertexWeights

kuroyume0161 opened this issue on Nov 13, 2004 ยท 18 posts


kuroyume0161 posted Sat, 13 November 2004 at 1:10 PM

Anybody have experience using these two Poser Python methods?

Each returns a [FloatType list] for an Actor, but not certain how many vertex weights will be returned. I'm guessing that it would equal the number of Actor vertices (?). But then children affect their parents, so this may include them, or just be a composite of the weights on the Actor including its childrens' influences. Uncertain.

Thanks for any input!

Message edited on: 11/13/2004 13:11

C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, you blow your whole leg off.

 -- Bjarne Stroustrup

Contact Me | Kuroyume's DevelopmentZone


ockham posted Sat, 13 November 2004 at 2:13 PM

You roused my curiosity. I don't know what it's for, but it's interesting! After a bit of playing: The number of entries is exactly the same as the number of verts. Seems to be a very sparse array, though; lots of zeroes. Not every part has an array, and most parts seem to have the set only for one dimension. I'm guessing that this tells how the joint moves in a vector form. The verts that have 1.0 for "x" will move (for Bend) on an arc with radius = 1.0 * current scaled length; those with 0.5 for "x" will Bend on an arc with radius = 0.5 * length. Does that make sense? Stewer will undoubtedly know the true answer.

My python page
My ShareCG freebies


ockham posted Sat, 13 November 2004 at 2:56 PM

Better guess: After more playing, it looks like the weights indicate which vertices need the most distortion when the joint bends in this direction. The facets that keep their shape under this rotation have zero entries in the list.

My python page
My ShareCG freebies


kuroyume0161 posted Sat, 13 November 2004 at 3:45 PM

Right, that's what I was expecting. Most likely, the values are between 0.0 and 1.0. Actually, you're close. They indicate the amount of influence of the joint on the vertex. 1.0 means move with the joint, 0.0 means don't move at all, inbetween (blend zone) means move with a percentage of joint movement.

But, since my Python experience is very limited, how did you go through the list. Here's my untested code for printing them out:

<br></br>
# --------------------------------------<br></br>
# VertexWeight Info<br></br>
# --------------------------------------<br></br>
def printWeights(weights):<br></br>
i = 0<br></br>
for wgt in weights:<br></br>
print " ", i, ": =", wgt<br></br>
i = i + 1<br></br><br></br><br></br>
# --------------------------------------<br></br>
# Hierarchy Info<br></br>
# --------------------------------------<br></br>
def printHier(actor, numTabs):<br></br>
if(not actor):<br></br>
return<br></br>
tab = ' ' + ' __ '*(numTabs-1) + '_'<br></br>
print tab, actor.Name()<br></br>
children = actor.Children()<br></br>
if(children):<br></br>
for child in children:<br></br>
printHier(child, numTabs+1)<br></br><br></br><br></br>
# --------------------------------------<br></br>
# Define a function to print out the vertex weights of a Poser
Actor.<br></br>
# Use some globals so the we can tally them as we go<br></br>
# --------------------------------------<br></br>
def printActorWeights(iActor):<br></br>
maxName = 20<br></br>
print " ", iActor.Name(), ' '*(maxName - len(iActor.Name())),<br></br><br></br>
# --------------------------------------<br></br>
# Returns<br></br>
# --------------------------------------<br></br>
axis = ["x", "y", "z"]<br></br>
for a in axis:<br></br>
weights = iActor.JointVertexWeights(a)<br></br>
if (weights):<br></br>
printWeights(weights)<br></br>
else:<br></br>
weights = iActor.TwistVertexWeights(a)<br></br>
if (weights):<br></br>
printWeights(weights)<br></br>
else:<br></br>
print "No Weights for axis ",a<br></br><br></br><br></br><br></br>
# --------------------------------------<br></br>
# Get the Poser scene object...<br></br>
# --------------------------------------<br></br>
scene = poser.Scene()<br></br><br></br>
# --------------------------------------<br></br>
# For every figure in the scene,<br></br>
# print out how many polygons it has (if it has geometry)<br></br>
# and keep a total as we go<br></br>
# --------------------------------------<br></br>
figs = scene.Figures()<br></br>
for fig in figs:<br></br>
print fig.Name()<br></br>
body = fig.Actor('Body')<br></br>
print " Hierarchy:"<br></br>
printHier(body, 0)<br></br>
print<br></br>
print " Actor info:"<br></br>
actors = fig.Actors()<br></br>
for actor in actors:<br></br>
printActorWeights(actor)<br></br>

C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, you blow your whole leg off.

 -- Bjarne Stroustrup

Contact Me | Kuroyume's DevelopmentZone


ockham posted Sat, 13 November 2004 at 3:54 PM

Here's how I moved them. This is obviously not a general-purpose script..... it just moves them in some direction, proportional to their vertex weight, so you can see which areas move more and which move less. You'd have to manually edit the "z" to the other dims. import poser scene=poser.Scene() TheFig=scene.CurrentFigure() OneActor=scene.CurrentActor() Geom=OneActor.Geometry() L=OneActor.JointVertexWeights("z") # Hold the list for i in range(Geom.NumVertices()): ~V=Geom.Vertex(i) ~V.SetZ(V.Z()*(1.0+L[i])) # Move in proportion scene.DrawAll()

My python page
My ShareCG freebies


kuroyume0161 posted Sat, 13 November 2004 at 4:51 PM

[Cue "Mission Impossible" theme music]

Here's your mission, if you choose to accept it. What would be really cool would be some way to actually "paint" the vertex weights onto the figure so that someone can see a visual representation of the weights (I'm thinking LightWave and Cinema4D style display).

[/Cue]

This message will self-destruct in ...
I lie. :)

My code works, but it also seems to crash unexpectedly with an unknown error code = -50. (?) Works for the most part otherwise. I'm printing out the weights to file for an entire Figure's actors, so might be blowing the stack or heap for Python scripting.

Message edited on: 11/13/2004 16:52

C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, you blow your whole leg off.

 -- Bjarne Stroustrup

Contact Me | Kuroyume's DevelopmentZone


ockham posted Sat, 13 November 2004 at 4:53 PM

Yup, sounds like a stack-blow error. I'll see if there's a way to color the points.

My python page
My ShareCG freebies


kuroyume0161 posted Sat, 13 November 2004 at 5:53 PM

Found the solution to the error - the console output was not only slowing down the file write considerably, but it was causing the blow out. I'll try the same. If you have Poser 5, shader nodes may be an interesting approach.

C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, you blow your whole leg off.

 -- Bjarne Stroustrup

Contact Me | Kuroyume's DevelopmentZone


ockham posted Sat, 13 November 2004 at 6:11 PM

Yes, the console output gets jammed up way too easily. I'm just about there on the coloring.... this raises some interesting possibilities.

My python page
My ShareCG freebies


ockham posted Sat, 13 November 2004 at 7:23 PM

Here's a first working version. The script is built to do the Z axis, but I've given you the alternate lines (remmed out) to form the other 5 possible scripts. To use, just select a body part and hit the script. It paints the vertex weights on the body. I think you'll see how to make make finer color gradations, if that's desirable.....

My python page
My ShareCG freebies


ockham posted Sat, 13 November 2004 at 7:24 PM

Here's poor Misaki after a body-painting session.

My python page
My ShareCG freebies


kuroyume0161 posted Sat, 13 November 2004 at 10:26 PM

Looks weird, but cool. I haven't had as much success. I'm trying to use red-yellow instead of grey gradiations. Instead, I'm getting blue - almost like SetDiffuseColor() in Poser 5 is (b,g,r) and not (r,g,b). Strange.

I'm going to keep playing with it to see what can be done. :I

Almost forgot: Thanks for the script!! I'd be lost otherwise.

Message edited on: 11/13/2004 22:27

C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, you blow your whole leg off.

 -- Bjarne Stroustrup

Contact Me | Kuroyume's DevelopmentZone


ockham posted Sat, 13 November 2004 at 10:36 PM

I believe P5 has a separate DiffuseValue variable, which affects the other settings.... I don't see a way to set that in Python. Try SetTextureColor?

My python page
My ShareCG freebies


kuroyume0161 posted Sun, 14 November 2004 at 1:11 AM

This is very fun!! ;I Python in Poser 5 is definitely not the same as PP, but I have finally managed to paint all of a figure's actors on any axis from red to yellow (0.0 to 1.0). I've attached the script for you to modify. Thanks for the enjoyment and challenge!!!

C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, you blow your whole leg off.

 -- Bjarne Stroustrup

Contact Me | Kuroyume's DevelopmentZone


kuroyume0161 posted Sun, 14 November 2004 at 1:12 AM

And here's an image showing the results using the Y axis.

C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, you blow your whole leg off.

 -- Bjarne Stroustrup

Contact Me | Kuroyume's DevelopmentZone


kuroyume0161 posted Sun, 14 November 2004 at 1:13 AM

Note that the eyes and hip do not get painted because they don't have JPs. In a general sense, their weights are all 1.0 by default.

C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, you blow your whole leg off.

 -- Bjarne Stroustrup

Contact Me | Kuroyume's DevelopmentZone


ockham posted Sun, 14 November 2004 at 11:19 AM

Looks good! I'm trying to think of "real" uses for the facet-by-facet painting method. It's obviously a good tool for model-building; visual indicator for various types of internal info.

My python page
My ShareCG freebies


stewer posted Sun, 14 November 2004 at 4:54 PM

Ooooohhh....this is so cool! I'm away for a couple of days and you guys do this - cheers to you! lifts glass