Tuesday 22 May 2012

Dancing Girl


I'm not sure if this is brilliance, and just plain silly. This is a PoserPhysics ragdoll simulation, with a tiny python script which propels her upward once she gets below a certain level.

The python script (PoserPhysics2012 version)for this is follows:


import poser

import os, sys
(folder, bundle) = os.path.split(poser.AppLocation())
sys.path.insert(0, os.path.join(folder, "Runtime", "Python", "poserScripts", "PoserPhysics"))

import PhysicsWxP9
from PhysicsWxP9 import *
import PhysicsToolsP9
from PhysicsToolsP9 import PhysicsToolsError

upForce = 2 # Assumes gravity of -5 (set manually via the PoserPhysicsGUI)
goingUp = 0

# Add forces if below a certain height (checked each frame)
def callback():
    global prevHipPos, goingUp
  
    fname = poser.Scene().CurrentFigure().Name()
    if poser.Scene().CurrentFigure().ActorByInternalName("hip").ParameterByCode(poser.kParmCodeYTRAN).Value() < 0.17:
        goingUp = 1
    if poser.Scene().CurrentFigure().ActorByInternalName("hip").ParameterByCode(poser.kParmCodeYTRAN).Value() > 0.25:
        goingUp = 0
       
    if goingUp == 1:
        p.applyForce(fname + "/hip", [0, upForce * 0.5, 0], verbose = 0)
        try:
            p.applyForce(fname + "/waist", [0, upForce * 0.6, 0], verbose = 0)
        except:
            pass
        p.applyForce(fname + "/abdomen", [0, upForce * 0.7, 0], verbose = 0)
        p.applyForce(fname + "/chest", [0, upForce * 0.8, 0], verbose = 0)
        p.applyForce(fname + "/neck", [0, upForce * 0.9, 0], verbose = 0)
        p.applyForce(fname + "/head", [0, upForce, 0], verbose = 0)
        p.applyForce(fname + "/lForeArm", [0, upForce * 0.1, 0], verbose = 0)
        p.applyForce(fname + "/rForeArm", [0, upForce * 0.1, 0], verbose = 0)
        p.applyForce(fname + "/rHand", [0, upForce * 0.1, 0], verbose = 0)
        p.applyForce(fname + "/lHand", [0, upForce * 0.1, 0], verbose = 0)
        p.applyForce(fname + "/rHand", [0, upForce * 0.1, 0], verbose = 0)
    else:
        p.applyForce(fname + "/lForeArm", [0, upForce * -0.3, 0], verbose = 0)
        p.applyForce(fname + "/rForeArm", [0, upForce * -0.3, 0], verbose = 0)
    p.applyForce(fname + "/rFoot", [0, upForce * -0.3, 0], verbose = 0)
    p.applyForce(fname + "/lFoot", [0, upForce * -0.3, 0], verbose = 0)
   
print
print "Dancing Girl Sample"

# Bend the knee a little
poser.Scene().CurrentFigure().ActorByInternalName("lShin").ParameterByCode (poser.kParmCodeXROT).SetMinValue(20)
poser.Scene().CurrentFigure().ActorByInternalName("rShin").ParameterByCode (poser.kParmCodeXROT).SetMinValue(20)
poser.Scene().CurrentFigure().ActorByInternalName("lThigh").ParameterByCode (poser.kParmCodeXROT).SetMaxValue(-10)
poser.Scene().CurrentFigure().ActorByInternalName("rThigh").ParameterByCode (poser.kParmCodeXROT).SetMaxValue(-10)

p = PhysicsTools.PoserPhysicsEngine()
p.importDefaults()
p.setGroundPlane(1)
p.setPerFrameCallback (callback)
p.setupSimulation()
p.runSimulation()

print "Simluation Complete"


Make sure you select the figure you want to dance prior to running the script.

No comments:

Post a Comment