

Trylon wrote:Oh, there's nothing more easy (well, not exactly but still) than converting localspace to worldspace.
obj = Blender.Object.Get('objectname')
X = obj.loc[0]+deltaX
Y = obj.loc[1]+deltaY
Z = obj.loc[2]+deltaZ
#!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'
"""
# ==============================================
#
# ToDo
#
# 1) Move the else statement
# to the end so that that section is skipped
# when the condition isn't true
# -> DONE
#
# 2) Put in a check object type in before the
# first if statement, the else goes at the end
# -> DONE
#
# 3) Put in a check for if its cyclic or not,
# if it is true then save copy of the first
# BezTriple and apply it after the for loop
#
# 4) Apply the BezTriple of locations to the IPO
# window
#
# 5) Add to the IPO window the folowing blocks
# dRotX, dRotY, dRotZ and Time where time is
# the slow down or speed up at certain sections
# though this is probably redundant and just
# maintain a constand speed
#
# 6) Work out an algorithm for the above
# but don't for get that rotation is divided
# by 10, eg 90 degres becomes 9 degrees
# but test it out first.
#
# 7) Set the curves' datablock name as the
# objects'
# -> DONE
#
# ==============================================
import Blender
import math
from math import *
print"\n\n\n#################################################"
print" Attempting to run script"
print"##############################################\n"
# Get the currently selected object
myCurve = Blender.Object.GetSelected()[0]
#get X,Y,Z of the curve
myCurveX = myCurve.loc[0]
myCurveY = myCurve.loc[1]
myCurveZ = myCurve.loc[2]
# Create variable and get the type of object
myObjectType = myCurve.getType()
if myObjectType == 'Curve':
print" -> Object is a %s" % myObjectType
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)
# Get the object name of the curve
myCurveName = myCurve.getName()
#myCurveBez = Blender.Object.Get(myCurve) # Get data of curve
# Initialize what will be the name of the IPO's
myIPOCurveSet = myCurve.getName()
# Get the length of the curve in frames
myPathLength = myCurveData.getPathLen()
# Create variables myPathIter, myCurrentPathLen
# and initialize them to a known value
myPathIter = myCurrentPathLen = myPathLength
#myIPOCurves = myIPOCurves.LOC[x]
myIPOCurveSet = Blender.Ipo.New('Object', myCurveName) # Attmpting to get the Curve name same as IPO curve set
#####################################
#handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
#####################################
# Get the name of the data block
myCurveData = myCurve.data
myCyclicTest = myCurveData.isCyclic()
if myCyclicTest == True:
print" -> Curve is cyclic"
else:
print" -> Curve is not cyclic"
# Set the name of the data block as the
# objects' name
myCurveData.setName(myCurveName)
# Create the variable and intialize it to 0
myCurvePoints = 0
# Old way -> myCurvePoints = myCurveData.__getitem__(myCurvePoints)
myCurvePoints = myCurveData[myCurvePoints]
# can't be bothered how to figure out how
# use get curve length function in the API
# its just as easy to write a loop to calculate it
myNumberOfPoints = 0
for iNumberOfPoints in myCurvePoints:
myNumberOfPoints = myNumberOfPoints + 1.0
myPathIter = myPathLength / myNumberOfPoints
myHandleIter = myPathIter / (myNumberOfPoints * 2.0)
myHandleIter = ceil (myHandleIter)
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
myIPOCurveLoc_X = myIPOCurveSet.addCurve('LocX')
myIPOCurveLoc_Y = myIPOCurveSet.addCurve('LocY')
myIPOCurveLoc_Z = myIPOCurveSet.addCurve('LocZ')
myIPOCurveRot_X = myIPOCurveSet.addCurve('RotX')
myIPOCurveRot_Y = myIPOCurveSet.addCurve('RotY')
myIPOCurveRot_Z = myIPOCurveSet.addCurve('RotZ')
#myIPOCurveSpeed = myIPOCurveSet.addCurve('Time')
myBezPointNumber = 1
myCurrentPathLen = 1
for nCurvePoints in myCurvePoints:
# Copy the first set of co-ordinates
# ready for a isCyclic condtion
if myBezPointNumber == 0:
myFirstCoods = nCurvePoints
# 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"
# Store all bezier points
H1_X = nCurvePoints.vec[0][0]
H1_Y = nCurvePoints.vec[0][1]
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]
# make 3 BezTriples, and mke sure their handles are FREE
# pass eacch of these 3 new BezTriples for X, Y and Z
# to their relevant IPO's
myIPOCurveX = Blender.BezTriple.New(myCurrentPathLen - myHandleIter+myCurveX, H1_X, 0, myCurrentPathLen, P_X+myCurveX, 0, myCurrentPathLen + myHandleIter, H2_X+myCurveX, 0)
myIPOCurveY = Blender.BezTriple.New(myCurrentPathLen - myHandleIter, H1_Y+myCurveY, 0, myCurrentPathLen, P_Y+myCurveY, 0, myCurrentPathLen + myHandleIter, H2_Y+myCurveY, 0)
myIPOCurveZ = Blender.BezTriple.New(myCurrentPathLen - myHandleIter, H1_Z+myCurveZ, 0, myCurrentPathLen, P_Z+myCurveZ, 0, myCurrentPathLen + myHandleIter, H2_Z+myCurveZ, 0)
myIPOCurveX.handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
myIPOCurveY.handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
myIPOCurveZ.handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
myIPOCurveLoc_X.append(myIPOCurveX)
myIPOCurveLoc_Y.append(myIPOCurveY)
myIPOCurveLoc_Z.append(myIPOCurveZ)
#myIPOCurveSpeed.append((myCurrentPathLen, 30))
# Must be done last in the for loop
myBezPointNumber = myBezPointNumber + 1
myCurrentPathLen = myPathIter * myBezPointNumber
myIPOCurveLoc_X.recalc()
myIPOCurveLoc_Y.recalc()
myIPOCurveLoc_Z.recalc()
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)
else:
Blender.Draw.PupMenu("Object is not a curve")
print" -> Object is a %s" % myObjectType
#!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'
"""
# ==============================================
#
# ToDo
#
# 1) Move the else statement
# to the end so that that section is skipped
# when the condition isn't true
# -> DONE
#
# 2) Put in a check object type in before the
# first if statement, the else goes at the end
# -> DONE
#
# 3) Put in a check for if its cyclic or not,
# if it is true then save copy of the first
# BezTriple and apply it after the for loop
#
# 4) Apply the BezTriple of locations to the IPO
# window
#
# 5) Add to the IPO window the folowing blocks
# dRotX, dRotY, dRotZ and Time where time is
# the slow down or speed up at certain sections
# though this is probably redundant and just
# maintain a constand speed
#
# 6) Work out an algorithm for the above
# but don't for get that rotation is divided
# by 10, eg 90 degres becomes 9 degrees
# but test it out first.
#
# 7) Set the curves' datablock name as the
# objects'
# -> DONE
#
# ==============================================
import Blender
import math
from math import *
print"\n\n\n#################################################"
print" Attempting to run script"
print"##############################################\n"
# Get the currently selected object
myCurve = Blender.Object.GetSelected()[0]
#get X,Y,Z of the curve
myCurveX = myCurve.loc[0]
myCurveY = myCurve.loc[1]
myCurveZ = myCurve.loc[2]
# Create variable and get the type of object
myObjectType = myCurve.getType()
if myObjectType == 'Curve':
print" -> Object is a %s" % myObjectType
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)
# Get the object name of the curve
myCurveName = myCurve.getName()
#myCurveBez = Blender.Object.Get(myCurve) # Get data of curve
# Initialize what will be the name of the IPO's
myIPOCurveSet = myCurve.getName()
# Get the length of the curve in frames
myPathLength = myCurveData.getPathLen()
# Create variables myPathIter, myCurrentPathLen
# and initialize them to a known value
myPathIter = myCurrentPathLen = myPathLength
#myIPOCurves = myIPOCurves.LOC[x]
myIPOCurveSet = Blender.Ipo.New('Object', myCurveName) # Attmpting to get the Curve name same as IPO curve set
#####################################
#handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
#####################################
# Get the name of the data block
myCurveData = myCurve.data
myCyclicTest = myCurveData.isCyclic()
if myCyclicTest == True:
print" -> Curve is cyclic"
else:
print" -> Curve is not cyclic"
# Set the name of the data block as the
# objects' name
myCurveData.setName(myCurveName)
# Create the variable and intialize it to 0
myCurvePoints = 0
# Old way -> myCurvePoints = myCurveData.__getitem__(myCurvePoints)
myCurvePoints = myCurveData[myCurvePoints]
# can't be bothered how to figure out how
# use get curve length function in the API
# its just as easy to write a loop to calculate it
myNumberOfPoints = 0
for iNumberOfPoints in myCurvePoints:
myNumberOfPoints = myNumberOfPoints + 1.0
myPathIter = myPathLength / myNumberOfPoints
myHandleIter = myPathIter / (myNumberOfPoints * 2.0)
myHandleIter = ceil (myHandleIter)
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
myIPOCurveLoc_X = myIPOCurveSet.addCurve('LocX')
myIPOCurveLoc_Y = myIPOCurveSet.addCurve('LocY')
myIPOCurveLoc_Z = myIPOCurveSet.addCurve('LocZ')
myIPOCurveRot_X = myIPOCurveSet.addCurve('RotX')
myIPOCurveRot_Y = myIPOCurveSet.addCurve('RotY')
myIPOCurveRot_Z = myIPOCurveSet.addCurve('RotZ')
#myIPOCurveSpeed = myIPOCurveSet.addCurve('Time')
myBezPointNumber = 1
myCurrentPathLen = 1
for nCurvePoints in myCurvePoints:
# Copy the first set of co-ordinates
# ready for a isCyclic condtion
if myBezPointNumber == 0:
myFirstCoods = nCurvePoints
# 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"
# Store all bezier points
H1_X = nCurvePoints.vec[0][0]
H1_Y = nCurvePoints.vec[0][1]
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]
# make 3 BezTriples, and mke sure their handles are FREE
# pass eacch of these 3 new BezTriples for X, Y and Z
# to their relevant IPO's
myIPOCurveX = Blender.BezTriple.New(myCurrentPathLen - myHandleIter+myCurveX, H1_X, 0, myCurrentPathLen, P_X+myCurveX, 0, myCurrentPathLen + myHandleIter, H2_X+myCurveX, 0)
myIPOCurveY = Blender.BezTriple.New(myCurrentPathLen - myHandleIter, H1_Y+myCurveY, 0, myCurrentPathLen, P_Y+myCurveY, 0, myCurrentPathLen + myHandleIter, H2_Y+myCurveY, 0)
myIPOCurveZ = Blender.BezTriple.New(myCurrentPathLen - myHandleIter, H1_Z+myCurveZ, 0, myCurrentPathLen, P_Z+myCurveZ, 0, myCurrentPathLen + myHandleIter, H2_Z+myCurveZ, 0)
myIPOCurveX.handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
myIPOCurveY.handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
myIPOCurveZ.handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
myIPOCurveLoc_X.append(myIPOCurveX)
myIPOCurveLoc_Y.append(myIPOCurveY)
myIPOCurveLoc_Z.append(myIPOCurveZ)
#myIPOCurveSpeed.append((myCurrentPathLen, 30))
# Must be done last in the for loop
myBezPointNumber = myBezPointNumber + 1
myCurrentPathLen = myPathIter * myBezPointNumber
myIPOCurveLoc_X.recalc()
myIPOCurveLoc_Y.recalc()
myIPOCurveLoc_Z.recalc()
lin = Blender.IpoCurve.InterpTypes.LINEAR
myIPOCurveLoc_X.interpolation = lin
myIPOCurveLoc_Y.interpolation = lin
myIPOCurveLoc_Z.interpolation = lin
myIPOCurveRot_X.interpolation = lin
myIPOCurveRot_Y.interpolation = lin
myIPOCurveRot_Z.interpolation = lin
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)
else:
Blender.Draw.PupMenu("Object is not a curve")
print" -> Object is a %s" % myObjectType
Users browsing this forum: No registered users and 0 guests