Animations - Creating a Curve2IPO wizard

Re: Animations - Creating a Curve2IPO wizard

Postby Grogyan » Thu Jul 03, 2008 11:01 pm

I just did a quick couple of fixes and have a version on the first post of this topic.

Caution that this is only an Alpha version, its still buggy


A few things I found out when I ran this script

- The IPO curves don't appear automatically even though thy are done, just use the IPO selection menu
- I was afraid of this, the bezier handles didn't get copied over
- An interesting but buggy, is that the curve follows itself

If some people can try it out and let me know what you think, or if it works for you in game,that'd be great
Just extract the python script to your belder scripts directory
To execute the script switch one window to scripts and select the "Wizards sub menu" its named as "Curve2IPO"
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 Grogyan » Fri Jul 04, 2008 6:00 pm

Small change
- Curve no longer animates itself
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 Grogyan » Sat Jul 05, 2008 8:33 pm

I still havn't yet figured out how to append along with the knots the handles of each bezier curve to the Ipo Curve set.

I've nearly exhausted all routes to do this, but I have seen some scripts the seem to indicate that it is indeed possible to append the handles to the Ipo curve set

Anyone got any ideas of how to do this?

I know I must have to apply more data somehow to myIPOCurveSet_X.append((myCurrentPathLen, nCurvePoints.vec[1][0])) as an example

Code: Select all
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
myCurrentPathLen = 1
for nCurvePoints in myCurvePoints:
   
   #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"
   
   # 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]))
   
   # Must be done last in the for loop
   myBezPointNumber = myBezPointNumber + 1
   myCurrentPathLen = myPathIter * myBezPointNumber
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 Grogyan » Mon Jul 07, 2008 12:38 am

well I have experimented a bit more with Blender, and indeed you can, at least in theory, have something as complex as the harvester in E'rCana, especially when the banking feature gets implemented.

Still right now, still havn't found a way to pass the bezier handles
The only method I have found so far that doesn't raise an error is this as an example

Code: Select all
myIPOCurveSet_X.append((myCurrentPathLen, nCurvePoints.vec[0][0], nCurvePoints.vec[1][0], nCurvePoints.vec[2][0]))


Not only does this not work, its also very obvious that it cannot work
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 Christian Walther » Mon Jul 07, 2008 1:22 pm

Mind you, I haven't closely followed what you're trying to achieve, and I've put my hands on an IpoCurve for the first time 15 minutes ago, but could it be that you're looking for something like this:
Code: Select all
myIpoCurve.append(BezTriple.New((handleInX, handleInY, handleInZ, knotX, knotY, knotZ, handleOutX, handleOutY, handleOutZ)))

This seems to constrain the handles and knot onto a straight line, a way to suppress this seems to be
Code: Select all
p = BezTriple.New((handleInX, handleInY, handleInZ, knotX, knotY, knotZ, handleOutX, handleOutY, handleOutZ))
p.handleTypes = (BezTriple.HandleTypes.FREE, BezTriple.HandleTypes.FREE)
myIpoCurve.append(p)

That's at least what I found out by skimming over the documentation (IpoCurve, BezTriple) and experimenting in Blender's interactive Python console.
Christian Walther
 
Posts: 443
Joined: Sun Jun 08, 2008 3:10 am
Location: Switzerland

Re: Animations - Creating a Curve2IPO wizard

Postby Grogyan » Mon Jul 07, 2008 11:22 pm

The typical way to do animations, including those that loop, is to keyframe them with the "I" key.

But if you want to do something like Mag-Lev rides to get around your Age like Riven, its going to be a lot easier to do it when this tool is done.

Eg I already have a very simple bird flapping and following the curve, though not very well, thats due to the BezTriple problem.
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 Grogyan » Tue Jul 08, 2008 12:28 am

I tried your suggestion Christian, but it doesn't compile.

Even harder still is that it doesn't iterate to the next key frame value, eg the animation is 120 frames long, frame 30 would be the next iteration.

Edit:
Nope that is the way to do it, and is shown in the Curve module

Its also shown here in X3DImporter-alpha.py

And last point of reference is our very own prp_MatClasses.py which shows how to append the frame number to the iteration.


I have a feeling I have bitten off more than I can eat, as I havn't even thought of how to apply a rotation set of vectors to this script, and for that there is only one place to look for it, the Blender subversion repository, with their curve follow path function.
The reason why im not using this is quite simple, it applies only the speed of the curve in the Ipo window
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 » Tue Jul 08, 2008 6:17 am

I tried your suggestion Christian, but it doesn't compile.


Compile? :shock:

Ok, I know what you mean but I just thought I'd say that... for some reason.

Don't feel too bad about dealing with all the vectors (and stuff). I'm going to soon be writing most of the export-geometry and matrix stuff (I hope that's the same for blender and plasma) again when I start work on the blender-settings>plasma part of the cluster-group class.

So, when I get around to that code, we can share our blender-api miseries. ;)

Blender api is still really hard for people who know python pretty well. I'm amazed how much python you've picked up and how well you're coping with the crazy blender-api. Keep on learning and trying and asking. :)
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 Christian Walther » Tue Jul 08, 2008 10:38 am

Grogyan wrote:But if you want to do something like Mag-Lev rides to get around your Age like Riven, its going to be a lot easier to do it when this tool is done.

Eg I already have a very simple bird flapping and following the curve, though not very well, thats due to the BezTriple problem.

I gathered that much, and I agree it seems like an interesting exercise. I faintly remember having done something similar in POV-Ray years ago. What I meant was that I hadn't (and still haven't) tried or examined your script, so I don't know what your variables like nCurvePoints.vec[1][0] mean. That's why I used generic variable names in my examples.

Grogyan wrote:I tried your suggestion Christian, but it doesn't compile.

What's the error message?

Even harder still is that it doesn't iterate to the next key frame value, eg the animation is 120 frames long, frame 30 would be the next iteration.

You lost me here :| (which is probably due to my lack of experience with Blender).

Nope that is the way to do it, and is shown in the Curve module

Its also shown here in X3DImporter-alpha.py

And last point of reference is our very own prp_MatClasses.py which shows how to append the frame number to the iteration.

You seem to have a similar approach to Python scripting as Gehn had to age writing :). (Nothing wrong with that, of course.)

I have a feeling I have bitten off more than I can eat

I might be able to help you digest that bite, if you're interested. There would be something to learn in it for me too.
Christian Walther
 
Posts: 443
Joined: Sun Jun 08, 2008 3:10 am
Location: Switzerland

Re: Animations - Creating a Curve2IPO wizard

Postby Grogyan » Tue Jul 08, 2008 11:19 am

Christian Walther wrote:
Grogyan wrote:
Grogyan wrote:I tried your suggestion Christian, but it doesn't compile.

What's the error message?

Even harder still is that it doesn't iterate to the next key frame value, eg the animation is 120 frames long, frame 30 would be the next iteration.

You lost me here :| (which is probably due to my lack of experience with Blender).

Nope that is the way to do it, and is shown in the Curve module

Its also shown here in X3DImporter-alpha.py

And last point of reference is our very own prp_MatClasses.py which shows how to append the frame number to the iteration.

You seem to have a similar approach to Python scripting as Gehn had to age writing :). (Nothing wrong with that, of course.)



The error message after cleaning up as much as I can, but it doesn't iterate to the next key frame
Traceback (most recent call last):
File "C:\Program Files\Blender3d\.blender\scripts\Curve2IPO2.py", line 92, in
<module>
#myIPOCurveSet_X.append((myCurrentPathLen, p))
NameError: name 'myIpoCurve' is not defined


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

myCurve = Blender.Object.GetSelected()[0]    # Assign what is the currently selected curve
myCurveData = Blender.Curve.Get()[0]
myCurveFlag1 = myCurveData.getFlag()

# Standard bit mask for bit 3
if myCurveFlag1 and 0x08: #  Is "CurvePath" flag set
   print"-> Curve flag bit 3 at 0x00001000 is set, value is: %x " % (myCurveFlag1 and 0x08)
else:
   Blender.Draw.PupMenu("Curve is not a Path")
   #print"-> Curve flag bit 3 at 0x00001000 is NOT set, value is: %x " % (myCurveFlag1 and 0x08)

myCurveName = myCurve.getName()
myCurveBez = Blender.Object.Get(myCurve)   # Get data of curve
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
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
myCurrentPathLen = 1
for nCurvePoints in 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"
   
   H1_X = nCurvePoints.vec[0][0]
   H1_Y = nCurvePoints.vec[0][0]
   H1_Z = nCurvePoints.vec[0][2]
   P_X = nCurvePoints.vec[1][0]
   P_Y = nCurvePoints.vec[1][1]
   P_Z = nCurvePoints.vec[1][2]
   H2_X = nCurvePoints.vec[2][0]
   H2_Y = nCurvePoints.vec[2][1]
   H2_Z = nCurvePoints.vec[2][2]
   
   p = Blender.BezTriple.New(H1_X, H1_Y, H1_Z, P_X, P_Y, P_Z, H2_X, H2_Y, H2_Z)
   p.handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
   myIpoCurve.append(p)
   #myIPOCurveSet_X.append((myCurrentPathLen, p))
   #myIPOCurveSet_Y.append((myCurrentPathLen, p))
   #myIPOCurveSet_Z.append((myCurrentPathLen, p))
   #myIPO = Blender.BezTriple.New((H1_X, H1_Y, H1_Z, P_X, P_Y, P_Z, H2_X, H2_Y, H2_Z))
   #myIPO.HandleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
   #myIPOCurve.apend(myIPO)
   # 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((nCurvePoints.vec[0][0], nCurvePoints.vec[0][1], nCurvePoints.vec[0][2]))   
   # Similar to above
   # myIPOCurveSet_Y.append((nCurvePoints.vec[1][0], nCurvePoints.vec[1][1], nCurvePoints.vec[1][2]))
   # myIPOCurveSet_Z.append((nCurvePoints.vec[2][0], nCurvePoints.vec[2][1], nCurvePoints.vec[2][2]))
   
   #myIPOCurveSet_X.append((myCurrentPathLen, nCurvePoints.vec[1][0]))
   #myIPOCurveSet_Y.append((myCurrentPathLen, nCurvePoints.vec[1][1]))
   #myIPOCurveSet_Z.append((myCurrentPathLen, nCurvePoints.vec[1][2]))
   # Set the frame to iterate
   # KeyList.append(myCurrentPathLen)
   # Must be done last in the for loop
   myBezPointNumber = myBezPointNumber + 1
   myCurrentPathLen = myPathIter * myBezPointNumber
   
       
#myIPOCurveSet_X.recalc()
#myIPOCurveSet_Y.recalc()
#myIPOCurveSet_Z.recalc()


nCurvePoints now becomes a BezTriple
Using the .vec suffix gets the number in the array of BezTriples
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

PreviousNext

Return to Grogyan's Journal

Who is online

Users browsing this forum: No registered users and 1 guest