Animations - Creating a Curve2IPO wizard

Animations - Creating a Curve2IPO wizard

Postby Grogyan » Sat Jun 14, 2008 11:09 pm

Well I have done a few tests, and I know for certain that an object, light source, empty and camera can all be animated using an IPO curve, they just need an IPO curve that is originally made using an object ONLY as the first reference animation using the "I" key

I then moved onto trying to create IPO curves with armatures with objects as children of the armatures, but I found that very difficult to do and have now moved onto a different type of animation to test.

Get an object to go around a set path in a set amount of seconds/frames, again this doesn't produce an IPO curve for the plugin to recognize.

So to hopefully get around this limitation of Blender's, i'm having a go at writing a script for blender to convert a curve into an object IPO curve. I can't see why Blender hasn't even got this feature auto magically.

I have an idea of how to do this, and below is my current code

Version now at: 0.6.6
Curve2IPO.zip
(1.56 KiB) Downloaded 493 times
Scripting.blend
(183.92 KiB) Downloaded 363 times


Current code
Code: Select all
#!BPY

# A script to convert a curve to an IPO curve which can be used by an object to simulate the path it is flying

# Specifically designed to help with GoW_PyPrp plugin
"""
Name: 'Curve2IPO'
Blender: 246
Group: 'Wizards'
Tooltip: 'Make IPO curves from path'
"""
import Blender

try:
   scn = Scene.GetCurrent()
   Blender.Curve.data.getFlag(3) == true #  Is "CurvePath" flag set.
except:
   Blender.Draw.PupMenu("Curve is not a Path")

myCurve = Blender.Object.GetSelected()[0]    # Assign what is the currently selected curve
#myCurveName = myCurveName.getName()
myCurveName = myCurve.getName()
myCurveBez = Blender.Object.Get(myCurve)   # Get data of curve
myCurveData = Blender.Curve.Get()[0]
myIPOCurveSet =  myCurve.getName()
myCurvePoints = n = 0
myPathLength = myCurveData.getPathLen()
myPathIter = myCurrentPathLen = myPathLength
#myIPOCurves = myIPOCurves.LOC[x]
myIPOCurveSet = Blender.Ipo.New('Object', myCurveName) # Attmpting  to get the Curve name same as IPO curve set
#myIPOCurves = Blender.IpoCurve.New(myIPOCurveSet)
handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
myCurveData = myCurve.data
# Old way -> myCurvePoints = myCurveData.__getitem__(myCurvePoints)
myCurvePoints = myCurveData[myCurvePoints]
myNumberOfPoints = 0
for iNumberOfPoints in myCurvePoints:
   myNumberOfPoints = myNumberOfPoints + 1
myPathIter = myPathLength / myNumberOfPoints
   
print "\n##############################################"
print "Curve name: %s " % myCurveName
print "Curve data: %s " % myCurveData
print "Ipo curves: %s " % myIPOCurveSet
print "Ipo length: %s " % myPathLength
print "Path iteration constant: %s" % myPathIter
print "##############################################\n"
# Create LocX, LocY, and LocZ Ipo curves in our new Curve Object
# and store them so we can access them later
myIPOCurveSet_X = myIPOCurveSet.addCurve('dLocX')
myIPOCurveSet_Y = myIPOCurveSet.addCurve('dLocY')
myIPOCurveSet_Z = myIPOCurveSet.addCurve('dLocZ')
myBezPointNumber = 0
for nCurvePoints in myCurvePoints:
   myBezPointNumber = myBezPointNumber + 1
   myCurrentPathLen = myPathIter * myBezPointNumber
   
   #myIPOCurves = Blender.Ipo.New(Blender.Ipo.OB_LOCX, 'Ipo1a')
   # Create an new Ipo Curve of name myIpo and type Object
    #myIPOCurves = bpy.data.ipos.new(myCurveName, 'Object')
   
 

   #print"%s" %s myCurvePoints
   # Apparently  BezTriple outputs 9 floats for each handle/knot in 3D space
   # so print out each float value
   print"\n##############################################"
   print"Bezier point number: %s" % myBezPointNumber
   print"Out of a total: %s" % myNumberOfPoints
   print"Current iteration at frame: %s\n" %  myCurrentPathLen
   print"H1x: %s " % nCurvePoints.vec[0][0]
   print"H1y: %s " % nCurvePoints.vec[0][1]
   print"H1z: %s " % nCurvePoints.vec[0][2]
   print"\n"
   print"Px: %s " % nCurvePoints.vec[1][0]
   print"Py: %s " % nCurvePoints.vec[1][1]
   print"Pz: %s " % nCurvePoints.vec[1][2]
   print"\n"
   print"H2x: %s " % nCurvePoints.vec[2][0]
   print"H2y: %s " % nCurvePoints.vec[2][1]
   print"H2z: %s " % nCurvePoints.vec[2][2]
   print"##############################################\n"
   
   # Here set the current frame
   # myIpo = myCurveIPO.__setitem__ (myCurrentPathLen, nCurvePoints)
   # Here Append current frame with BezTriple nCurvePoints
   # myIPOCurves = myIPOCurveSet.IpoCurve.
   # myIPOCurves = myIPOCurveSet.__setitem__(myCurrentPathLen, nCurvePoints)
   #myIPOCurves = Blender.Ipo.addCurve([Blender.Ipo.OB_LOCX])  # retrieves an Ipo object
   #ipo.name = 'ipo1'                              # change the Ipo's name
   #icu = ipo[Blender.Ipo.OB_LOCX] # request X Location Ipo curve object
   #if icu != None and len(icu.bezierPoints) > 0: # if curve exists and has BezTriple points
   #   val = icu[2.5]              # get the curve's value at time 2.5

   # Append to the Ipo curve at location frame, with the value ipoValue_x
   # Note that we should pass the append function a tuple or a BezTriple
    myIPOCurveSet_X.append((myCurrentPathLen, nCurvePoints.vec[1][0]))
   
   # Similar to above
   myIPOCurveSet_Y.append((myCurrentPathLen, nCurvePoints.vec[1][1]))
   myIPOCurveSet_Z.append((myCurrentPathLen, nCurvePoints.vec[1][2]))


Edit: removed a statement I made about following a curve, as after reading the code for about the tenth time, the Bezier addition looks like it related to the IPO curve and not path following by bezier

Edit 1: I'll be placing here in the first post updates to the code when improvement is made

Edit 2: Removed the first block of code
Last edited by Grogyan on Fri Jul 11, 2008 10:53 pm, edited 12 times in total.
Better to have loved and lost than never to have loved at all
User avatar
Grogyan
 
Posts: 1203
Joined: Thu Oct 11, 2007 1:27 am

Re: Animations

Postby Nadnerb » Sat Jun 14, 2008 11:29 pm

I did not add any feature that would allow the camera to "follow a bezier curve". I made changes to allow the camera to be animated and other, unrelated changes to correct the behavior of the IPO curves in bezier interpolation mode.

As for creating an IPO from a 3D curve, Because you're essentially making curves out of a curve, if you have a CurNurb, of type Bezier, it should be relatively simple to split each knot vector into components and use them to make 3 component IPO curves.
Image
Live KI: 34914 MOULa KI: 23247 Gehn KI: 11588 Available Ages: TunnelDemo3, BoxAge, Odema
Nadnerb
 
Posts: 1057
Joined: Fri Sep 28, 2007 8:01 pm
Location: US (Eastern Time)

Re: Animations

Postby Grogyan » Sat Jun 14, 2008 11:46 pm

So the Bezier addition is for the actual IPO curve?

See thats how much I know of python.

I'll keep having a go at this script, though I don't hold much hope of it being actually working

When it comes to me and python, the snake named Monty usually wins


I should also really get back to writing the code for my robot, in yet another language I despise, BASIC.
It will be the last project i'll do, with any language other than C, as I still keep liking that language for some unknown reason
Better to have loved and lost than never to have loved at all
User avatar
Grogyan
 
Posts: 1203
Joined: Thu Oct 11, 2007 1:27 am

Re: Animations

Postby Chacal » Sun Jun 15, 2008 10:34 am

I loved C programming. I miss the sheer terror of knowing that a typo could crash your entire machine.
Chacal


"The weak can never forgive. Forgiveness is an attribute of the strong."
-- Mahatma Gandhi
User avatar
Chacal
 
Posts: 2508
Joined: Tue Nov 06, 2007 2:45 pm
Location: Quebec, Canada

Re: Animations

Postby Grogyan » Tue Jun 17, 2008 12:32 am

Well i'm gonna post this here
I've spent over 6 hours trying to figure out why it throws up an error
Code: Select all
Traceback (most recent call last):
  File "C:\Program Files\Blender3d\.blender\scripts\Curve2IPO.py", line 25, in <module>
    PathLength = Curve.getPathLen()
AttributeError: 'module' object has no attribute 'getPathLen'


after that i'm sure it'll throw up another error, but i'm going through this step by step
Code: Select all
#!BPY

# A script to convert a curve to an IPO curve which can be used by an object to simulate the path it is flying

# Specifically designed to help with GoW_PyPrp plugin
"""
Name: 'Curve2IPO'
Blender: 246
Group: 'Wizards'
Tooltip: 'Make IPO curves from path'
"""
 
from Blender import *
from Blender import Draw
from Blender import Curve
try:
   Curve.data.getFlag(3|8) == true #  Is "CurvePath" flag set.
except:
   Draw.PupMenu("Curve is not a Path")
   
AUTO = BezTriple.HandleTypes.AUTO
Curv = Curve.Get()
print Curv
CurvIPO = Ipo.New('Object', 'ObIPO') # Attempting  to get the Name of the curve as the name of the new IPO set of curves
PathLength = Curve.getPathLen()
Curve.CurNURB.__getitem__(CurveLen)
# for i in PathLength: using in another way of doing this script
for n in CurveLen:
   # Apparently  BezTriple outputs 9 floats for each handle/knot in 3D space
   # so print out each float value
   print"Bezier point number: ", (n), __getitem__
   print"H1x: ", type(H1x),BezTriple
   print"H1y: ", type(H1y),BezTriple
   print"H1z: ", type(H1z),BezTriple
   print""
   print"Px: ", type(Px),BezTriple
   print"Py: ", type(Py),BezTriple
   print"Pz: ", type(Pz),BezTriple
   print""
   print"H2x: ", type(H2x),BezTriple
   print"H2y: ", type(H2y),BezTriple
   print"H2z: ", type(H2z),BezTriple
   print""

   # IpoCurve.append(point
   # Ipo.New(Object,OB_LOCX)
   # OB_LOCY
   # OB_LOCZ
   # OB_ROTX
   # OB_ROTY
   # OB_ROTZ


Python isn't my forte, and this isn't anywhere near all scripted, at the moment the idea is to get the location of each handle and knot in a point on a bezier curve in 3D space, which isn't even as hard as might think, just call the function, and it returns 9 floats
A handle
A knot
Another handle
Each is 3D space aka X,Y,Z axes
Then print those out in Blender's console
Better to have loved and lost than never to have loved at all
User avatar
Grogyan
 
Posts: 1203
Joined: Thu Oct 11, 2007 1:27 am

Re: Animations

Postby Christian Walther » Tue Jun 17, 2008 10:47 am

My completely uneducated guess from the error message (I have no experience with Blender's Python APIs, and don't have time right now to test it) is that you have a typo on this line:
Code: Select all
PathLength = Curve.getPathLen()

That should read Curv, not Curve. Curve is a module that comes from the line from Blender import Curve. Curv comes from the line Curv = Curve.Get() and is, I don't know what, but perhaps something that has a getPathLen method.

Might be a good idea to choose less easily confused variable names... :)
Christian Walther
 
Posts: 443
Joined: Sun Jun 08, 2008 3:10 am
Location: Switzerland

Re: Animations

Postby Grogyan » Tue Jun 17, 2008 10:59 pm

Yeah, its a little confusing, so i've changed them to see whats mine and what belongs to an API

I did find this one and only example on the web
http://blenderartists.org/forum/showthread.php?t=32230

which works just fine as is, and even after integrating it into the code, the compiler stops complaining.
I still though can't see what the dot "." actually means, in C++ it means child of class, which was the assumption I was following, but now in python it means something else, point or part of?
Better to have loved and lost than never to have loved at all
User avatar
Grogyan
 
Posts: 1203
Joined: Thu Oct 11, 2007 1:27 am

Re: Animations - Creating a Curve2IPO wizard

Postby Lontahv » Wed Jun 18, 2008 1:17 am

If you import "from" something, you load that class or whatever the thing you're importing is. So, this class behaves just like a normal class. If you just "import <module>" then you have to have the module's name before every class that's in the module so; "<modulename>.object_in_module"

I hope I've clarified it a bit.

~Lontahv
Currently getting some ink on my hands over at the Guild Of Ink-Makers (PyPRP2).
User avatar
Lontahv
Councilor of Artistic Direction
 
Posts: 1331
Joined: Wed Oct 03, 2007 2:09 pm

Re: Animations - Creating a Curve2IPO wizard

Postby Grogyan » Wed Jun 18, 2008 2:57 am

so if I had a class like this

Class GrogyansAttempts
LearnPython
BrickWall

import GrogyansAttempts

def SomeFunction()
LearnPython.CanWin()

don't need to declare the class as a prefix?

Where as if GrogyansAttempts is a module containing a class named LearnPython for example it would be
from GrogyansAttempts import *

imports everything in that module including classes and declare anything as?
CanWin = GrogyansAttempts.LearnPython()

i'm confused :?

Edit: Sorry, my brain was asleep, I did find some documentation with some good examples or working with functions, classes and modules
Better to have loved and lost than never to have loved at all
User avatar
Grogyan
 
Posts: 1203
Joined: Thu Oct 11, 2007 1:27 am

Re: Animations - Creating a Curve2IPO wizard

Postby Lontahv » Wed Jun 18, 2008 3:20 pm

Er, sometimes you need to call the class's _init_ function first... this is also good form for most things. So;

Code: Select all
import GrogyansAttempts

def SomeFunction()
    learnPythonInstance = GrogyansAttempts.LearnPython(<initvars(usually nothing here)>)
    learnPythonInstance.CanWin()



But if you use:

Code: Select all
from GrogyansAttempts import LearnPython


Then you have no need for the module prefix.

~Lontahv
Currently getting some ink on my hands over at the Guild Of Ink-Makers (PyPRP2).
User avatar
Lontahv
Councilor of Artistic Direction
 
Posts: 1331
Joined: Wed Oct 03, 2007 2:09 pm

Next

Return to Grogyan's Journal

Who is online

Users browsing this forum: No registered users and 0 guests

cron