Skip to content

Commit

Permalink
Merge pull request #561 from JacquesLucke/v1_6
Browse files Browse the repository at this point in the history
V1.6
  • Loading branch information
JacquesLucke committed Jun 2, 2016
2 parents a85e2e1 + 2a9e051 commit f1420c1
Show file tree
Hide file tree
Showing 386 changed files with 7,464 additions and 3,629 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
*.pyc
*.pyd
*.py~
*.c
*.exp
*.lib
*.obj
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Animation Nodes

The Animation Nodes (AN) addon is a powerful extension for [Blender](http://blender.org).
The Animation Nodes addon (AN) implements a new node system for [Blender](http://blender.org).

You can find some documentation here: http://animation-nodes-manual.readthedocs.org/en/latest/
19 changes: 13 additions & 6 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright (C) 2014 Jacques Lucke
Copyright (C) 2016 Jacques Lucke
[email protected]
Created by Jacques Lucke
Expand Down Expand Up @@ -64,6 +64,15 @@
raise Exception(message)


from . preferences import getBlenderVersion
if getBlenderVersion() < (2, 76, 0):
message = ("\n\n"
"The Animation Nodes addon requires at least Blender 2.77.\n"
"Your are using an older version.\n"
"Please download the latest official release.")
raise Exception(message)



# load and reload submodules
##################################
Expand All @@ -75,13 +84,11 @@



# Public API
# Initialization
##################################

from . execution import units
subprogramsByName = units.getSubprogramUnitsByName
setup = units.setupExecutionUnits
finish = units.finishExecutionUnits
from . sockets.info import updateSocketInfo
updateSocketInfo()



Expand Down
4 changes: 1 addition & 3 deletions algorithms/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/math/Interpolation.java
'''

# using pythons functools.partial function is slower
def assignArguments(function, *arguments):
def interpolationWrapper(x):
return function(x, *arguments)
Expand Down Expand Up @@ -221,9 +222,6 @@ def sinOut(x):

# Specials

def curveMapping(x, curve):
return min(max((curve.evaluate(x) - 0.25) * 2, -0.5), 1.5)

def fCurveMapping(x, settings):
fCurve, xMove, xFactor, yMove, yDivisor = settings
x = x * xFactor + xMove
Expand Down
139 changes: 58 additions & 81 deletions algorithms/rotation.py
Original file line number Diff line number Diff line change
@@ -1,95 +1,72 @@
from mathutils import Matrix, Vector

def rotationToDirection(rotation, axis = "X"):
'''axis in ("X", "Y", "Z", "-X", "-Y", "-Z")'''
return rotation.to_matrix() * axisVectorDict[axis]

#### RotationToDirection
'''
Converts euler to vector (direction or normal) with custom length
required arguments (as strings):
input socket name: rotation (euler), length (float),
output socket name: direction (vector)
axis in ("X", "Y", "Z", "-X", "-Y", "-Z")
needs mathutils module
'''
def generateRotationMatrix(direction, guide, trackAxis = "Z", guideAxis = "X"):
'''
trackAxis in ("X", "Y", "Z", "-X", "-Y", "-Z")
guideAxis in ("X", "Y", "Z")
'''

def generateRotationToDirectionCode(rotationName, lengthName, directionOutputName, axis):
directionAxisTuple = {"X": "({}, 0, 0)", "Y": "(0, {}, 0)", "Z": "(0, 0, {})",
"-X":"(-{}, 0, 0)","-Y": "(0,-{}, 0)","-Z": "(0, 0,-{})"}
axisTuple = directionAxisTuple[axis].format(lengthName)

return "{} = {}.to_matrix() * mathutils.Vector({})".format(directionOutputName, rotationName, axisTuple)
matrix = Matrix.Identity(4)

##############################
if guideAxis[-1:] == trackAxis[-1:]:
return matrix

if direction == zero:
return matrix

#### DirectionToRotation
'''
Converts vector to rotation, with an extra guide vector
(like to_track_quat(), but can specify custom UP axis (as guide))
z = direction.normalized()
y = z.cross(guide.normalized())
if y == zero:
if guideAxis == "X":
if z.cross(xAxis) != zero: y = z.cross(xAxis)
else: y = zAxis
elif guideAxis == "Y":
if z.cross(yAxis) != zero: y = z.cross(yAxis)
else: y = zAxis
elif guideAxis == "Z":
if z.cross(zAxis) != zero: y = z.cross(zAxis)
else: y = yAxis

required arguments (as strings):
input socket name: direction (vector), guide (vector),
trackAxis in ("X", "Y", "Z", "-X", "-Y", "-Z")
guideAxis in ("X", "Y", "Z")
optional outputs / types (as strings):
output socket names : matrix (matrix), rotation (euler), quaternion (quaternion)
- will generate that output type if respective name is other than ""
if no output is specified (all to ""), code will be ""
this allows to generate that output only if needed (ex if respective socket is linked (isLinked dict))
needs mathutils module
'''
x = y.cross(z)

def generateDirectionToRotationCode(directionName, guideName, trackAxis, guideAxis, matrixOutputName = "", rotationOutputName = "", quaternionOutputName = ""):

def getAxesChange(track, guide):
if track == "X": a = "( z,-y, x)" if guide == "Z" else "( z, x, y)"
elif track == "Y": a = "( y, z, x)" if guide == "Z" else "( x, z,-y)"
elif track == "Z": a = "( x, y, z)" if guide == "X" else "(-y, x, z)"
elif track == "-X": a = "(-z, y, x)" if guide == "Z" else "(-z, x,-y)"
elif track == "-Y": a = "(-y,-z, x)" if guide == "Z" else "( x,-z, y)"
elif track == "-Z": a = "( x,-y,-z)" if guide == "X" else "( y, x,-z)"
return a

outputMatrix, outputEuler, outputQuaternion = False, False, False
if matrixOutputName != "": outputMatrix = True
if rotationOutputName != "": outputEuler = True
if quaternionOutputName != "": outputQuaternion = True

#### exception 0
if not any([outputMatrix, outputEuler, outputQuaternion]):
return ""

#### exception 1
if trackAxis[-1:] == guideAxis[-1:]:
if outputMatrix: yield "{} = mathutils.Matrix()".format(matrixOutputName)
if outputEuler: yield "{} = mathutils.Euler((0, 0, 0), 'XYZ')".format(rotationOutputName)
if outputQuaternion: yield "{} = mathutils.Quaternion((1, 0, 0, 0))".format(quaternionOutputName)
return
mx, my, mz = changeAxesDict[(trackAxis, guideAxis)](x, y, z)
matrix.col[0][:3] = mx
matrix.col[1][:3] = my
matrix.col[2][:3] = mz
return matrix

#### exception 2
yield "zero = mathutils.Vector((0, 0, 0))"

yield "if {} == zero:".format(directionName)
if outputMatrix: yield " {} = mathutils.Matrix()".format(matrixOutputName)
if outputEuler: yield " {} = mathutils.Euler((0, 0, 0), 'XYZ')".format(rotationOutputName)
if outputQuaternion: yield " {} = mathutils.Quaternion((1, 0, 0, 0))".format(quaternionOutputName)
changeAxesDict = {
( "X", "Z"): lambda x, y, z: ( z, -y, x),
( "X", "Y"): lambda x, y, z: ( z, x, y),
( "Y", "Z"): lambda x, y, z: ( y, z, x),
( "Y", "X"): lambda x, y, z: ( x, z, -y),

# always same
yield "else:"
yield " z = {}.normalized()".format(directionName)
yield " if {} != zero and z.cross({}) != zero: y = z.cross({}.normalized())".format(guideName, guideName, guideName)
if "X" == guideAxis: yield " else: y = z.cross(mathutils.Vector((1, 0, 0))) if z.cross(mathutils.Vector((1, 0, 0))) != zero else mathutils.Vector((0, 0, 1))"
if "Y" == guideAxis: yield " else: y = z.cross(mathutils.Vector((0, 1, 0))) if z.cross(mathutils.Vector((0, 1, 0))) != zero else mathutils.Vector((0, 0, 1))"
if "Z" == guideAxis: yield " else: y = z.cross(mathutils.Vector((0, 0, 1))) if z.cross(mathutils.Vector((0, 0, 1))) != zero else mathutils.Vector((0, 1, 0))"
yield " x = y.cross(z)"
( "Z", "X"): lambda x, y, z: ( x, y, z),
( "Z", "Y"): lambda x, y, z: (-y, x, z),
("-X", "Z"): lambda x, y, z: (-z, y, x),
("-X", "Y"): lambda x, y, z: (-z, x, -y),

yield " mx, my, mz = " + getAxesChange(trackAxis, guideAxis)
("-Y", "Z"): lambda x, y, z: (-y, -z, x),
("-Y", "X"): lambda x, y, z: ( x, -z, y),
("-Z", "X"): lambda x, y, z: ( x, -y, -z),
("-Z", "Y"): lambda x, y, z: ( y, x, -z),
}

yield " mat = mathutils.Matrix()"
yield " mat.col[0].xyz, mat.col[1].xyz, mat.col[2].xyz = mx, my, mz"

#### outputs
if outputMatrix: yield " {} = mat.normalized()".format(matrixOutputName)
if outputEuler: yield " {} = mat.to_euler()".format(rotationOutputName)
if outputQuaternion: yield " {} = mat.to_quaternion()".format(quaternionOutputName)
zero = Vector((0, 0, 0))
xAxis = Vector((1, 0, 0))
yAxis = Vector((0, 1, 0))
zAxis = Vector((0, 0, 1))

##############################
axisVectorDict = {
"X" : Vector(( 1, 0, 0)),
"Y" : Vector(( 0, 1, 0)),
"Z" : Vector(( 0, 0, 1)),
"-X" : Vector((-1, 0, 0)),
"-Y" : Vector(( 0, -1, 0)),
"-Z" : Vector(( 0, 0, -1)),
}
Loading

0 comments on commit f1420c1

Please sign in to comment.