2007-06-18 11:36:05 +00:00
|
|
|
#!BPY
|
|
|
|
"""
|
|
|
|
Name: 'Script Constraint'
|
|
|
|
Blender: 245
|
|
|
|
Group: 'ScriptTemplate'
|
2007-10-15 15:28:09 +00:00
|
|
|
Tooltip: 'Add a new script for custom constraints'
|
2007-06-18 11:36:05 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
from Blender import Window
|
|
|
|
import bpy
|
|
|
|
|
|
|
|
script_data = \
|
2007-10-15 15:28:09 +00:00
|
|
|
"""#BPYCONSTRAINT
|
|
|
|
'''
|
|
|
|
PyConstraint template, access this in the "add constraint" scripts submenu.
|
|
|
|
Add docstring here
|
|
|
|
'''
|
2007-06-18 11:36:05 +00:00
|
|
|
|
2007-10-15 15:28:09 +00:00
|
|
|
import Blender
|
|
|
|
from Blender import Draw
|
|
|
|
from Blender import Mathutils
|
|
|
|
import math
|
2007-06-18 11:36:05 +00:00
|
|
|
|
== Constraints System - Recode 2 ==
Once again, I've recoded the constraints system. This time, the goals were:
* To make it more future-proof by 'modernising' the coding style. The long functions filled with switch statements, have given way to function-pointers with smaller functions for specific purposes.
* To make it support constraints which use multiple targets more readily that it did. In the past, it was assumed that constraints could only have at most one target.
As a result, a lot of code has been shuffled around, and modified. Also, the subversion number has been bumped up.
Known issues:
* PyConstraints, which were the main motivation for supporting multiple-targets, are currently broken. There are some bimport() error that keeps causing problems. I've also temporarily removed the doDriver support, although it may return in another form soon.
* Constraints BPy-API is currently has a few features which currently don't work yet
* Outliner currently only displays the names of the constraints instead of the fancy subtarget/target/constraint-name display it used to do. What gets displayed here needs further investigation, as the old way was certainly not that great (and is not compatible with the new system too)
2007-10-21 23:00:29 +00:00
|
|
|
'''
|
|
|
|
This variable specifies the number of targets
|
|
|
|
that this constraint can use
|
|
|
|
'''
|
|
|
|
NUM_TARGETS = 1
|
2007-06-18 11:36:05 +00:00
|
|
|
|
|
|
|
|
2007-10-15 15:28:09 +00:00
|
|
|
'''
|
|
|
|
This function is called to evaluate the constraint
|
== Constraints System - Recode 2 ==
Once again, I've recoded the constraints system. This time, the goals were:
* To make it more future-proof by 'modernising' the coding style. The long functions filled with switch statements, have given way to function-pointers with smaller functions for specific purposes.
* To make it support constraints which use multiple targets more readily that it did. In the past, it was assumed that constraints could only have at most one target.
As a result, a lot of code has been shuffled around, and modified. Also, the subversion number has been bumped up.
Known issues:
* PyConstraints, which were the main motivation for supporting multiple-targets, are currently broken. There are some bimport() error that keeps causing problems. I've also temporarily removed the doDriver support, although it may return in another form soon.
* Constraints BPy-API is currently has a few features which currently don't work yet
* Outliner currently only displays the names of the constraints instead of the fancy subtarget/target/constraint-name display it used to do. What gets displayed here needs further investigation, as the old way was certainly not that great (and is not compatible with the new system too)
2007-10-21 23:00:29 +00:00
|
|
|
obmatrix: (Matrix) copy of owner's 'ownerspace' matrix
|
|
|
|
targetmatrices: (List) list of copies of the 'targetspace' matrices of the targets (where applicable)
|
2007-10-15 15:28:09 +00:00
|
|
|
idprop: (IDProperties) wrapped data referring to this
|
|
|
|
constraint instance's idproperties
|
|
|
|
'''
|
== Constraints System - Recode 2 ==
Once again, I've recoded the constraints system. This time, the goals were:
* To make it more future-proof by 'modernising' the coding style. The long functions filled with switch statements, have given way to function-pointers with smaller functions for specific purposes.
* To make it support constraints which use multiple targets more readily that it did. In the past, it was assumed that constraints could only have at most one target.
As a result, a lot of code has been shuffled around, and modified. Also, the subversion number has been bumped up.
Known issues:
* PyConstraints, which were the main motivation for supporting multiple-targets, are currently broken. There are some bimport() error that keeps causing problems. I've also temporarily removed the doDriver support, although it may return in another form soon.
* Constraints BPy-API is currently has a few features which currently don't work yet
* Outliner currently only displays the names of the constraints instead of the fancy subtarget/target/constraint-name display it used to do. What gets displayed here needs further investigation, as the old way was certainly not that great (and is not compatible with the new system too)
2007-10-21 23:00:29 +00:00
|
|
|
def doConstraint(obmatrix, targetmatrices, idprop):
|
2008-03-23 02:28:24 +00:00
|
|
|
# Separate out the transformation components for easy access.
|
2007-10-15 15:28:09 +00:00
|
|
|
obloc = obmatrix.translationPart() # Translation
|
|
|
|
obrot = obmatrix.toEuler() # Rotation
|
|
|
|
obsca = obmatrix.scalePart() # Scale
|
|
|
|
|
2008-03-23 02:28:24 +00:00
|
|
|
# Define user-settable parameters
|
|
|
|
# Must also be defined in getSettings().
|
2007-10-15 15:28:09 +00:00
|
|
|
if not idprop.has_key('user_toggle'): idprop['user_toggle'] = 1
|
|
|
|
if not idprop.has_key('user_slider'): idprop['user_slider'] = 1.0
|
|
|
|
|
|
|
|
|
|
|
|
# Do stuff here, changing obloc, obrot, and obsca.
|
2007-06-18 11:36:05 +00:00
|
|
|
|
2007-10-15 15:28:09 +00:00
|
|
|
|
|
|
|
# Convert back into a matrix for loc, scale, rotation,
|
2008-03-23 02:28:24 +00:00
|
|
|
mtxloc = Mathutils.TranslationMatrix(obloc)
|
2007-10-15 15:28:09 +00:00
|
|
|
mtxrot = obrot.toMatrix().resize4x4()
|
|
|
|
mtxsca = Mathutils.Matrix([obsca[0],0,0,0], [0,obsca[1],0,0], [0,0,obsca[2],0], [0,0,0,1])
|
|
|
|
|
|
|
|
# Recombine the separate elements into a transform matrix.
|
|
|
|
outputmatrix = mtxsca * mtxrot * mtxloc
|
2007-08-18 06:17:50 +00:00
|
|
|
|
2007-10-15 15:28:09 +00:00
|
|
|
# Return the new matrix.
|
|
|
|
return outputmatrix
|
2007-06-18 11:36:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-10-15 15:28:09 +00:00
|
|
|
'''
|
== Constraints System - Recode 2 ==
Once again, I've recoded the constraints system. This time, the goals were:
* To make it more future-proof by 'modernising' the coding style. The long functions filled with switch statements, have given way to function-pointers with smaller functions for specific purposes.
* To make it support constraints which use multiple targets more readily that it did. In the past, it was assumed that constraints could only have at most one target.
As a result, a lot of code has been shuffled around, and modified. Also, the subversion number has been bumped up.
Known issues:
* PyConstraints, which were the main motivation for supporting multiple-targets, are currently broken. There are some bimport() error that keeps causing problems. I've also temporarily removed the doDriver support, although it may return in another form soon.
* Constraints BPy-API is currently has a few features which currently don't work yet
* Outliner currently only displays the names of the constraints instead of the fancy subtarget/target/constraint-name display it used to do. What gets displayed here needs further investigation, as the old way was certainly not that great (and is not compatible with the new system too)
2007-10-21 23:00:29 +00:00
|
|
|
This function manipulates the matrix of a target prior to sending it to doConstraint()
|
2007-10-15 15:28:09 +00:00
|
|
|
target_object: wrapped data, representing the target object
|
== Constraints System - Recode 2 ==
Once again, I've recoded the constraints system. This time, the goals were:
* To make it more future-proof by 'modernising' the coding style. The long functions filled with switch statements, have given way to function-pointers with smaller functions for specific purposes.
* To make it support constraints which use multiple targets more readily that it did. In the past, it was assumed that constraints could only have at most one target.
As a result, a lot of code has been shuffled around, and modified. Also, the subversion number has been bumped up.
Known issues:
* PyConstraints, which were the main motivation for supporting multiple-targets, are currently broken. There are some bimport() error that keeps causing problems. I've also temporarily removed the doDriver support, although it may return in another form soon.
* Constraints BPy-API is currently has a few features which currently don't work yet
* Outliner currently only displays the names of the constraints instead of the fancy subtarget/target/constraint-name display it used to do. What gets displayed here needs further investigation, as the old way was certainly not that great (and is not compatible with the new system too)
2007-10-21 23:00:29 +00:00
|
|
|
subtarget_bone: wrapped data, representing the subtarget pose-bone/vertex-group (where applicable)
|
2007-10-15 15:28:09 +00:00
|
|
|
target_matrix: (Matrix) the transformation matrix of the target
|
|
|
|
id_properties_of_constraint: (IDProperties) wrapped idproperties
|
|
|
|
'''
|
|
|
|
def doTarget(target_object, subtarget_bone, target_matrix, id_properties_of_constraint):
|
|
|
|
return target_matrix
|
2007-06-18 11:36:05 +00:00
|
|
|
|
2007-08-18 06:17:50 +00:00
|
|
|
|
2007-06-18 11:36:05 +00:00
|
|
|
'''
|
2007-10-15 15:28:09 +00:00
|
|
|
This function draws a pupblock that lets the user set
|
== Constraints System - Recode 2 ==
Once again, I've recoded the constraints system. This time, the goals were:
* To make it more future-proof by 'modernising' the coding style. The long functions filled with switch statements, have given way to function-pointers with smaller functions for specific purposes.
* To make it support constraints which use multiple targets more readily that it did. In the past, it was assumed that constraints could only have at most one target.
As a result, a lot of code has been shuffled around, and modified. Also, the subversion number has been bumped up.
Known issues:
* PyConstraints, which were the main motivation for supporting multiple-targets, are currently broken. There are some bimport() error that keeps causing problems. I've also temporarily removed the doDriver support, although it may return in another form soon.
* Constraints BPy-API is currently has a few features which currently don't work yet
* Outliner currently only displays the names of the constraints instead of the fancy subtarget/target/constraint-name display it used to do. What gets displayed here needs further investigation, as the old way was certainly not that great (and is not compatible with the new system too)
2007-10-21 23:00:29 +00:00
|
|
|
the values of custom settings the constraint defines.
|
|
|
|
This function is called when the user presses the settings button.
|
2007-10-15 15:28:09 +00:00
|
|
|
idprop: (IDProperties) wrapped data referring to this
|
|
|
|
constraint instance's idproperties
|
|
|
|
'''
|
|
|
|
def getSettings(idprop):
|
|
|
|
# Define user-settable parameters.
|
|
|
|
# Must also be defined in getSettings().
|
|
|
|
if not idprop.has_key('user_toggle'): idprop['user_toggle'] = 1
|
|
|
|
if not idprop.has_key('user_slider'): idprop['user_slider'] = 1.0
|
|
|
|
|
|
|
|
# create temporary vars for interface
|
|
|
|
utoggle = Draw.Create(idprop['user_toggle'])
|
|
|
|
uslider = Draw.Create(idprop['user_slider'])
|
|
|
|
|
|
|
|
|
|
|
|
# define and draw pupblock
|
|
|
|
block = []
|
|
|
|
block.append("Buttons: ")
|
|
|
|
block.append(("Toggle", utoggle, "This is a toggle button."))
|
|
|
|
block.append("More buttons: ")
|
|
|
|
block.append(("Slider", uslider, 0.0000001, 1000.0, "This is a number field."))
|
|
|
|
|
|
|
|
retval = Draw.PupBlock("Constraint Template", block)
|
|
|
|
|
|
|
|
# update id-property values after user changes settings
|
|
|
|
if (retval):
|
|
|
|
idprop['user_toggle']= utoggle.val
|
|
|
|
idprop['user_slider']= uslider.val
|
|
|
|
|
|
|
|
"""
|
2007-06-18 11:36:05 +00:00
|
|
|
|
|
|
|
new_text = bpy.data.texts.new('pyconstraint_template.py')
|
|
|
|
new_text.write(script_data)
|
|
|
|
bpy.data.texts.active = new_text
|
2007-10-15 15:28:09 +00:00
|
|
|
Window.RedrawAll()
|