Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2007-06-18 11:41:21 +0400
committerJoshua Leung <aligorith@gmail.com>2007-06-18 11:41:21 +0400
commit01e8789f3f950a15aea9947ebadb1dcdcccf6a7e (patch)
tree6c9d3fa3b93d427728c1a0ce619f765227c9e677 /source/blender/blenkernel
parent770291b9ea1ec03d98b6bae4fd2a2d3f0091be41 (diff)
== PyConstraints ==
At last! The ability to code constraints in Python. This opens up many interesting rigging possibilities, as well as making prototyping constraints easier. * A PyConstraint script must begin with the line #BPYCONSTRAINT * It must also define a doConstraint function, which performs the core actions of the constraint. * PyConstraints use IDProperties to store custom properties for each PyConstraint instance. The scripter can choose which of these ID-Properties to expose to a user to control the behaviour of the constraint. This must be done using the Draw.PupBlock method. Credits to Joe Eager (joeedh) for coding the original patch on which this is based. I've made heavy revisions to large parts of the patch. For more detailed information, and some demo scripts, see the following page: http://aligorith.googlepages.com/pyconstraints2
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/bad_level_call_stubs/stubs.c11
-rw-r--r--source/blender/blenkernel/intern/constraint.c88
-rw-r--r--source/blender/blenkernel/intern/idprop.c1
3 files changed, 99 insertions, 1 deletions
diff --git a/source/blender/blenkernel/bad_level_call_stubs/stubs.c b/source/blender/blenkernel/bad_level_call_stubs/stubs.c
index 344f763608c..e76c53fc72c 100644
--- a/source/blender/blenkernel/bad_level_call_stubs/stubs.c
+++ b/source/blender/blenkernel/bad_level_call_stubs/stubs.c
@@ -54,6 +54,7 @@ struct IpoCurve;
struct FluidsimSettings;
struct Render;
struct RenderResult;
+struct bPythonConstraint;
char *getIpoCurveName( struct IpoCurve * icu );
void insert_vert_ipo(struct IpoCurve *icu, float x, float y);
@@ -124,6 +125,16 @@ int BPY_button_eval(char *expr, double *value)
return 0;
}
+/* constraint.c */
+void BPY_pyconstraint_eval(struct bPythonConstraint *con, float obmat[][4], short ownertype, void *ownerdata, float targetmat[][4])
+{
+}
+int BPY_pyconstraint_targets(struct bPythonConstraint *con, float targetmat[][4])
+{
+ return 0;
+}
+
+
/* writefile.c */
/* struct Oops; */
void free_oops(struct Oops *oops){}
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 97f5ed18cbe..9c03db824af 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -58,6 +58,9 @@
#include "BKE_ipo.h"
#include "BKE_global.h"
#include "BKE_library.h"
+#include "BKE_idprop.h"
+
+#include "BPY_extern.h"
#include "blendef.h"
@@ -80,6 +83,15 @@ void free_constraint_data (bConstraint *con)
{
if (con->data) {
/* any constraint-type specific stuff here */
+ switch (con->type) {
+ case CONSTRAINT_TYPE_PYTHON:
+ {
+ bPythonConstraint *data= con->data;
+ IDP_FreeProperty(data->prop);
+ MEM_freeN(data->prop);
+ }
+ break;
+ }
MEM_freeN(con->data);
}
@@ -117,6 +129,14 @@ void relink_constraints (struct ListBase *list)
for (con = list->first; con; con=con->next) {
switch (con->type) {
+ case CONSTRAINT_TYPE_PYTHON:
+ {
+ bPythonConstraint *data;
+ data = con->data;
+
+ ID_NEW(data->tar);
+ }
+ break;
case CONSTRAINT_TYPE_KINEMATIC:
{
bKinematicConstraint *data;
@@ -260,6 +280,13 @@ void copy_constraints (ListBase *dst, ListBase *src)
char constraint_has_target (bConstraint *con)
{
switch (con->type) {
+ case CONSTRAINT_TYPE_PYTHON:
+ {
+ bPythonConstraint *data = con->data;
+ if (data->tar)
+ return 1;
+ }
+ break;
case CONSTRAINT_TYPE_TRACKTO:
{
bTrackToConstraint *data = con->data;
@@ -354,6 +381,13 @@ Object *get_constraint_target(bConstraint *con, char **subtarget)
* to the name for this constraints subtarget ... NULL otherwise
*/
switch (con->type) {
+ case CONSTRAINT_TYPE_PYTHON:
+ {
+ bPythonConstraint *data=con->data;
+ *subtarget = data->subtarget;
+ return data->tar;
+ }
+ break;
case CONSTRAINT_TYPE_ACTION:
{
bActionConstraint *data = con->data;
@@ -450,6 +484,14 @@ void set_constraint_target(bConstraint *con, Object *ob, char *subtarget)
{
/* Set the target for this constraint */
switch (con->type) {
+
+ case CONSTRAINT_TYPE_PYTHON:
+ {
+ bPythonConstraint *data = con->data;
+ data->tar= ob;
+ if(subtarget) BLI_strncpy(data->subtarget, subtarget, 32);
+ }
+ break;
case CONSTRAINT_TYPE_ACTION:
{
bActionConstraint *data = con->data;
@@ -590,6 +632,18 @@ void *new_constraint_data (short type)
void *result;
switch (type) {
+ case CONSTRAINT_TYPE_PYTHON:
+ {
+ bPythonConstraint *data;
+ data = MEM_callocN(sizeof(bPythonConstraint), "pythonConstraint");
+
+ /* everything should be set correctly by calloc, except for the prop->type constant.*/
+ data->prop = MEM_callocN(sizeof(IDProperty), "PyConstraintProps");
+ data->prop->type = IDP_GROUP;
+
+ result = data;
+ }
+ break;
case CONSTRAINT_TYPE_KINEMATIC:
{
bKinematicConstraint *data;
@@ -1272,6 +1326,31 @@ short get_constraint_target_matrix (bConstraint *con, short ownertype, void* own
Mat4One (mat);
}
break;
+ case CONSTRAINT_TYPE_PYTHON:
+ {
+ bPythonConstraint *data;
+ data = (bPythonConstraint*)con->data;
+
+ /* special exception for curves - depsgraph issues */
+ if (data->tar && data->tar->type == OB_CURVE) {
+ Curve *cu= data->tar->data;
+
+ /* this check is to make sure curve objects get updated on file load correctly.*/
+ if(cu->path==NULL || cu->path->data==NULL) /* only happens on reload file, but violates depsgraph still... fix! */
+ makeDispListCurveTypes(data->tar, 0);
+ }
+
+ /* if the script doesn't set the target matrix for any reason, fall back to standard methods */
+ if (BPY_pyconstraint_targets(data, mat) < 1) {
+ if (data->tar) {
+ constraint_target_to_mat4(data->tar, data->subtarget, mat, size);
+ valid = 1;
+ }
+ else
+ Mat4One (mat);
+ }
+ }
+ break;
case CONSTRAINT_TYPE_CLAMPTO:
{
bClampToConstraint *data;
@@ -1316,7 +1395,14 @@ void evaluate_constraint (bConstraint *constraint, Object *ob, short ownertype,
case CONSTRAINT_TYPE_NULL:
case CONSTRAINT_TYPE_KINEMATIC: /* removed */
break;
-
+ case CONSTRAINT_TYPE_PYTHON:
+ {
+ bPythonConstraint *data;
+
+ data= constraint->data;
+ BPY_pyconstraint_eval(data, ob->obmat, ownertype, ownerdata, targetmat);
+ }
+ break;
case CONSTRAINT_TYPE_ACTION:
{
bActionConstraint *data;
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index 4ff4073fdbe..bb4c66da0b1 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -274,6 +274,7 @@ void IDP_FreeGroup(IDProperty *prop)
for (loop=prop->data.group.first; loop; loop=next)
{
next = loop->next;
+ BLI_remlink(&prop->data.group, loop);
IDP_FreeProperty(loop);
MEM_freeN(loop);
}