Forum: Poser Python Scripting


Subject: How to edit a model by selecting a frame in a script

Tekitoumen opened this issue on Jul 20, 2022 · 7 posts


Tekitoumen posted Wed, 20 July 2022 at 11:26 PM

Hi.

I want to select a frame of a moving model (animation) and edit the model.

(For example, I want to give the model a walking animation and do something that makes the breathing rougher every frame)

It takes time to manually edit the model frame by frame.

Therefore, I want to automate it with a Python script.


1. Select the first frame

2. Select a chest

3. Edit the shape of the chest

4. Select the second frame

5. Select a chest

6. Select the shape of the chest

・・・repert


I want to know if the script can recognize the model frame by frame and edit the image.



scene.SetFrame(frame_num)

actors = scene.Actors()

actor = scene.Actor("Chest")

・・・


I repeated the following script and edited the model frame by frame but it didn't work.

The edited content given in the first frame was reflected in all frames.

If you know the right way, please let me know.


Thank you.


Y-Phil posted Thu, 21 July 2022 at 4:39 AM

Did you add key frames to your character?

𝒫𝒽𝓎𝓁


(っ◔◡◔)っ

👿 Win11 on i9-13900K@5GHz, 64GB, RoG Strix B760F Gamng, Asus Tuf Gaming RTX 4070 OC Edition, 1 TB SSD, 6+4+8TB HD
👿 Mac Mini M2, Sequoia 15.2, 16GB, 500GB SSD
👿 Nas 10TB
👿 Poser 13 and soon 14 ❤️


adp001 posted Thu, 21 July 2022 at 8:23 AM

Y-Phil posted at 4:39 AM Thu, 21 July 2022 - #4441630

Did you add key frames to your character?

I tried it with a fresh started P12 (Trial). Opened a Python Terminal and typed in:

poser.Scene().SetFrame(10)

Poser updated the framecounter as expected.

@Tekitoumen:

How do you try to change the current figure?

FYI:

fig = poser.Scene().CurrentFigure()

actor = fig.Actor("Chest")

geom = actor.Geometry()

geom.Vertices() (the base mesh) stays the same in every frame. It doesn't change. What changes is geom.WorldVertices(). It reflects what morphs, weightmaps etc did to modify the base mesh. But it makes no sense to change these values frame by frame. Better use morphs and activate/deactivate or set value to these morphs the way you need them at certain frames.




adp001 posted Thu, 21 July 2022 at 8:46 AM

Example:

Assumed you have a figure with a morph called "Breath". To get a handle to that morph, do this:

figure = poser.Scene().CurrentFigure()
breath_morph = figure.Parameter("Breath")

Say you want to start with Breath == 0 at frame == 0 and a full breath (value=1) every 10 seconds. We further assume your scene goes with 25 frames per second. So, we have a full breath at 10 Seconds * 25 Frames == Frame 250, 500, 750, 1000, etc. 

full = True

for frame in range(0, poser.Scene().NumFrames(), 125):
    breath_morph.SetValue(int(full))
    full = not full

That's all it needs. Poser does the rest, interpolating all the steps in between.

To set a scene length that makes sense with those values, do something like:

poser.Scene().SetNumFrames(1000)




adp001 posted Thu, 21 July 2022 at 7:37 PM

ups! Forgot to set the frame:

for frame in range(0, poser.Scene().NumFrames(), 125):
    poser.Scene().SetFrame(frame)
    breath_morph.SetValue(int(full))
    full = not full




Tekitoumen posted Thu, 21 July 2022 at 10:29 PM

Thank you for your response!

Thank you for your kindness.


I'm setting a keyframe.

Then select body parts (eg chest) for each frame and

I'm trying to select that vertex coordinate and edit the chest area as I like.

First I tried it with a simple script.(The chest is greatly deformed for easy understanding)

However, even if I edit only the 6th frame as shown below, all the frames will be edited in the same way when I look at Poser.

In this case, I want to edit only a specific frame (6th).

I haven't been able to edit frame by frame.


Is this a failed frame selection?

Or is it not possible to select and edit vertices for each frame?

Sorry for the lack of understanding of Poser.






---------------------------------------------------------------------------------------------------------------------------------------------------

import poser

import time

import os


x_axis = 0

y_axis = 1

z_axis = 2


scene = poser.Scene()


for test_num in range( 0, 6):

    actors = scene.CurrentFigure()

    scene.SetFrame(test_num)

    

    actor = scene.Actor("Chest")

    actGeom = actor.Geometry()

    #verts = actGeom.Vertices()

    verts = actGeom.WorldVertices()

    vert_num = actGeom.NumVertices()

    vert_list = [[0 for k in range(3) ] for j in range(vert_num)]


    #x,y,z vertices 

    list_num = 0

    while list_num < vert_num:

        vert = actGeom.Vertices()[list_num]

        Vx = vert.X()

        Vy = vert.Y()

        Vz = vert.Z()


        vert_list[list_num][x_axis] = Vx

        vert_list[list_num][y_axis] = Vy

        vert_list[list_num][z_axis] = Vz


        list_num = list_num + 1


    j = 0


    while j < vert_num:

        if test_num == 5:

            set_z.SetZ(vert_list[j][z_axis] - 0.5)

---------------------------------------------------------------------------------------------------------------------------------------------------

Thank you.


Tekitoumen posted Tue, 26 July 2022 at 10:14 PM

I'm sorry. My understanding was not enough.


Thanks to you guys, I found the following.

・ The coordinates of the model cannot be changed for each frame.

・ If you create a morph first, you can set it for each frame.


Thank you.