Page 2 of 10

Re: Animations - Creating a Curve2IPO wizard

Posted: Sat Jun 28, 2008 4:30 pm
by Grogyan
Well at least I only have one error popping up with this

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
myCurveData = Blender.Object.Get(myCurve)   # Get data of curve
myCurveName = Blender.Curve.Get()[0]      # Assign myCurveName string as the name of the object
myCurvePoints = n = 0

myPathLength = myCurveName.getPathLen()
myCurvedName = myCurveName.getName()
myCurveIPO = Blender.Ipo.New('Object', 'myCurve') # Attmpting  to get the Curve name same as IPO curve set

myCurveData = myCurve.data
myCurvePoints = myCurveData.__getitem__(myCurvePoints)

handleTypes= (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)

print "\n##############################################\n"
print "Curve is: %s \n" % myCurve
print "Curve name: %s \n" % myCurveName
print "Ipo curves: %s \n" % myCurveIPO
print "Ipo length: %s \n" % myPathLength
print "##############################################\n"

H1x = myCurvePoints
H1y = myCurvePoints
H1z = myCurvePoints
Px = myCurvePoints
Py = myCurvePoints
Pz = myCurvePoints
H2x = myCurvePoints
H2y = myCurvePoints
H2z = myCurvePoints

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 \n" % nCurvePoints
   print"H1x: %s \n" % H1x
   print"H1y: %s \n" % H1y
   print"H1z: %s \n" % H1z
   print"\n"
   print"Px: %s \n" % Px
   print"Py: %s \n" % Py
   print"Pz: %s \n" % Pz
   print"\n"
   print"H2x: %s \n" % H2x
   print"H2y: %s \n" % H2y
   print"H2z: %s \n" % H2z
   print"##############################################\n"

scn = Scene.GetCurrent()
Blender.Curve.data.getFlag(3) == true # Is "CurvePath" flag set.
bit 3 is the flag that I assume looks at the button in the editing buttons "F9", "Curve and Surface" -> "CurvePath"
Shouldn't show the exception
Blender.Draw.PupMenu("Curve is not a Path")

But my biggest problem is that I can't figure out how to allocate each number in the matrix of BezTriple into a seperate variable, which I can print out on screen

Re: Animations - Creating a Curve2IPO wizard

Posted: Sat Jun 28, 2008 7:32 pm
by Grogyan
I have figured it out, and yes it was rather easy to do when you knew what the heck was going wrong\
BezTriple has an instance variable called "vec" which all documentation I have read has eg somevariablename.vec[0][0] <- points to the first number in the matrix

Also I am going to post code updates to the first post rather than paste the whole code out each time
Ooh, another idea, i'm gonna ask Kato something

Re: Animations - Creating a Curve2IPO wizard

Posted: Sat Jun 28, 2008 7:46 pm
by Grogyan
Success, I now have it printing out in the console window the point number in the entire curve

Re: Animations - Creating a Curve2IPO wizard

Posted: Mon Jun 30, 2008 2:18 am
by Grogyan
Next problem I am having a hard time finding an example of how to use the function append() in the class IpoCurve

Can someone please give me an example of how to use the append function in the IpoCurve class

Thanks

Re: Animations - Creating a Curve2IPO wizard

Posted: Mon Jun 30, 2008 12:10 pm
by Lontahv
This looks helpful: http://wiki.blender.org/index.php/BlenderDev/Ipo

it says that append can take either a bez-triple or a tuple of floats.

The tuple of floats would look like:

Code: Select all

something = (10.0,10.0,10.0)
<IpoCurve stuff>.append(something)


Not sure what it's expecting though. You'd have to play around with it a bit. :)

~Lontahv

Re: Animations - Creating a Curve2IPO wizard

Posted: Tue Jul 01, 2008 4:05 am
by Grogyan
Its not working, it complains that it can't find module,
nor are there any reasonable to be found anywhere to use that function

Other problems i'm working on:

Assigning the name of the IPO curves the name of the bezier curve -> getting the string passed properly
myIPOCurve = Blender.Ipo.New('Object', myCurve) -> myCurve is alread found with the getSelected function yet it complains it needs 2 string parameters

Adding any data to a specific time frame, preferably a BezTriple -> finding the function to do that, already have the base number to use

Appending data -> IpoCurve.append(<BezTriple>) -> complains it cannot find in module


Information seems to be very scarce, they must be assuming everyone is a professional coder or something, they being the Blender group

Re: Animations - Creating a Curve2IPO wizard

Posted: Tue Jul 01, 2008 3:17 pm
by Lontahv
Grogyan, what about emailing some of the blender devs?

Re: Animations - Creating a Curve2IPO wizard

Posted: Tue Jul 01, 2008 10:28 pm
by Grogyan
Got one problem solved today, it was the passing of the Curve name and then create a new set of curves based on that name.

the 3 other problems still exist.


Thanks for that tip Lontahv, i'll do that.

Re: Animations - Creating a Curve2IPO wizard

Posted: Thu Jul 03, 2008 9:47 pm
by Grogyan
I've had a quite a milestone today, found at last an example of appending a beztriple to an IPO curve
http://blenderartists.org/forum/showthread.php?t=122768

still got errors but thats ok, for now.

Problems solved are
- Managed to pass the name of the bezier curve path and set it as the name of the IPO curve set

Still left to fix or do
- Pass the beztriple of the bezier path and set each knot and set each (tuple?) to its respective IPO block
- Remove the dialog box that pops up, this is a bug where it cannot resolve the logic condition properly
- Add more parameters to check for before proceeding with the script
- Change the pop up dialog box to that of an error message dialog box.
- Find the functions for getting the tilt and bank of the curve, which should be the rotation of the object centre or knot
- Some other stuff that I can't recall to do :D

I hope that the tuples of the handles will pass automatically after the knots have been resolved, otherwise i'll have another problem to solve

Re: Animations - Creating a Curve2IPO wizard

Posted: Thu Jul 03, 2008 10:26 pm
by Grogyan
I followed a link on youtube about Tay from Zapper and found this
http://www.youtube.com/watch?v=4IBT2Qm9 ... re=related

This is what I hope to achieve in game, relatively easy, sub worlds are here so all thats left to make a really cool ride, bezier curves translated to IPO curves