Animating Skeleton

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
ochensati
Posts: 0
Joined: Sat Jan 27, 2007 1:14 am

Animating Skeleton

Post by ochensati »

Hello,
I need to animate a skeleton with a script, advancing the keyframe each time. I have tried many scripts here on the forum, as well as the example scripts in the documentation and cannot get anything to run without bugs, or the script just does not move anything. Can someone help me. i am running out of time to get this presentation done.

Code: Select all

import Blender
from Blender import *
from Blender.Mathutils import *
from Blender.Window import *
from Blender import Scene
Vector= Blender.Mathutils.Vector


def create_armature(FILE_NAME, arm_ob):
  temptext = file(FILE_NAME,"r")
  lines = temptext.readlines()
  BoneN = 0
  print arm_ob.getName()

  arm_data= arm_ob.data
  arm_data.makeEditable()
	# Get the bones
  bones= []
 
  for eb in arm_data.bones.values():
	bones.append(eb)
 
	# Store the numder of bones we have modified for a message
  tot_editbones= len(bones)
  tot_editbones_modified= 0

  
  for line in lines: #add the bones
    BoneN = BoneN + 1
    data = line.rstrip("\n").split(",")
    bone = bones[BoneN]
    bone.roll = float(data[1])
    bone.head = Vector(data[2], data[3], data[4])
    bone.tail = Vector(data[5], data[6], data[7])
  

def main():
	'''
	User interface function that gets the options and calls armature_symetry()
	'''
	
	scn= Scene.GetCurrent()
	arm_ob= scn.getActiveObject()
	
	if not arm_ob or arm_ob.getType()!='Armature':
		Blender.Draw.PupMenu('No Armature object selected.')
		return
	
	# Cant be in editmode for armature.makeEditable()
	is_editmode= Blender.Window.EditMode()
	if is_editmode: Blender.Window.EditMode(0)
	

	create_armature('C:\\test.csv',arm_ob)
	Draw= Blender.Draw

main()



here is the datafile

Code: Select all

1,1,0,0,0,1,0.499167083,4.975020826
2,2,1,0.499167083,4.975020826,2,0.993346654,4.900332889
3,3,2,0.993346654,4.900332889,3,1.477601033,4.776682446
4,4,3,1.477601033,4.776682446,4,1.947091712,4.60530497
5,5,4,1.947091712,4.60530497,5,2.397127693,4.387912809
6,6,5,2.397127693,4.387912809,6,2.823212367,4.126678075
7,7,6,2.823212367,4.126678075,7,3.221088436,3.824210936
8,8,7,3.221088436,3.824210936,8,3.586780454,3.483533547
9,9,8,3.586780454,3.483533547,9,3.916634548,3.108049841
10,10,9,3.916634548,3.108049841,10,4.207354924,2.701511529
11,11,10,4.207354924,2.701511529,11,4.4560368,2.267980607
12,12,11,4.4560368,2.267980607,12,4.66019543,1.811788772
13,13,12,4.66019543,1.811788772,13,4.817790927,1.337494143
14,14,13,4.817790927,1.337494143,14,4.92724865,0.849835715
15,15,14,4.92724865,0.849835715,15,4.987474933,0.353686008
and here is the mesh i am animating


Image[/img][/code]

ascotan
Posts: 0
Joined: Thu May 29, 2003 10:32 pm
Location: Maryland, U.S.

Post by ascotan »

The armature model is used to set the rest pose. The pose and action modules are used to keyframe.

You need to create an action and bind it to the object. They you need to use the Pose module to set the position of each bone, advancing the scene's framenumber as you go. Then when you're satisfied you need to insert a posekey at that frame number.

ochensati
Posts: 0
Joined: Sat Jan 27, 2007 1:14 am

Post by ochensati »

Thank for your reply, I did try to do the pose and action codes included in the latest documentation, got tired of all the errors and built the program with Ogre. Doesnt look as nice but saved me the frustration of never ending errors.

Post Reply