Forum: Poser Python Scripting


Subject: About select body part of object file by python

Tekitoumen opened this issue on Aug 26, 2022 ยท 7 posts


Tekitoumen posted Fri, 26 August 2022 at 3:00 AM

Hello.


https://www.renderosity.com/forums/threads/2972020/reduce-the-number-of-meshes#msg4441239


I was taught how to output an obj file with body part names etc. at this URL.


I don't know how to select this body part from python after importing this obj file. .

Could you tell me how to realize it from python? (For example, which method should be used, etc.)


Thank you.




FVerbaas posted Sun, 28 August 2022 at 9:11 AM Forum Coordinator

So, you load a prop from file and you want to do something with that prop via Python?

If you know the name of the prop you can use scene.Actor()

The prop usually will be selected after the loading so you can also use scene. CurrentActor()



adp001 posted Mon, 29 August 2022 at 2:31 PM

After the above procedure, there are no more individual body parts. The geometry is baked together and is a single, solid object (a "Prop").

Unlike most other programs, a figure in Poser is not one continuous mesh but is made up of various body parts that are handled so that the whole thing looks like one solid figure.

So if you want to use what you've produced as a Poser figure again, you first have to disassemble it and tell Poser which parts of the prop belong to which "body part".




Tekitoumen posted Tue, 30 August 2022 at 2:18 AM

Thank you for your reply.

I was able to understand.


If I import the model expoted obj model again, the model will be treated as props.


I noticed that this prop contains a body part in a group.


#test_model.obj imported

actor = scene.Actor("test_model")

actGeom = actor.Geometry()

print(actGeom.Groups())


----result----

['hip', 'abdomen', 'chest', 'lThigh', 'lShin', 'lFoot', 'neck', 'head', 'lCollar', 'lShldr', 'lForeArm', 'lHand', ' rThigh', 'rShin', 'rFoot', 'rCollar', 'rShldr', 'rForeArm', 'rHand']


What I want to do now is get the coordinates of just the "hip" part, for example. (act Geom.Vertices())


Is it possible to select only one part in the group and get the vertex coordinates limited to that part?

Which method will be used?


Thank you all for your kindness.



adp001 posted Wed, 31 August 2022 at 10:13 AM

What you see there are polygon groups. These groups were created when you exported your figure. That's why they have the same name as the body parts. From these polygon groups you can actually restore the figure (at least vertices and polygons in the right order).

To get the vertices you are interested in, you have to analyze the polygons and extract the data you need from them. Poser Python has a few commands for this:

Example:

geom = poser.Scene().CurrentActor().Geometry()
polys = geom.Polygons()
bodypart_name = "chest"

for poly in polys: # type: poser.PolygonType
if poly.InGroup(bodypart_name):
for vert in poly.Vertices(): # type: poser.VertexType
print(vert.X(), vert.Y(), vert.Z())


"poly.InGroup(<str>)" tells you if the queried polygon belongs to the group you are looking for.

"poly.Vertices()" returns a list of Poser's vertex objects (poser.VertexType). A Poser vertex knows X(), Y() and Z() to query as well as the corresponding "set" functions (SetX(), SetY(), SetZ()).

Another example:

sets = geom.Sets()
vertices = list()
for poly in geom.Polygons(): # type: poser.PolygonType
if poly.InGroup(bodypart_name):
index_start = poly.Start()
index_end = poly.Start() + poly.NumVertices()
vertices.append(sets[index_start:index_end])


Here the indices are queried into the geometry's vertex array and stored in the "vertices" list. This can only be done using the "sets" (geom.Sets()), which provide pointers into the vertex array.





adp001 posted Wed, 31 August 2022 at 11:20 AM

In the last example it is better to use "extend" instead of "append" to avoid a list within a list (last line).




Tekitoumen posted Wed, 14 September 2022 at 8:11 PM

Sorry about the late reply.

I was able to solve it thanks to you.

I was able to choose from pythons for each body part.


Thank you very much. Thank you for your kindness.