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
path: root/source
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2008-01-14 14:23:03 +0300
committerJoshua Leung <aligorith@gmail.com>2008-01-14 14:23:03 +0300
commit65c4a2f9ffbdfe0071d4d3f0475b9f3b1e808658 (patch)
tree27b96a2a86b34b4ade008e592c62a4515952b7b7 /source
parent7bd8871e14fee5e59463f21307144d1d88c016cf (diff)
== Limit Scale Constraint - Affects Transform ==
Now, the Limit Scale Constraint can be made to work on the Transform values like the Limit Location constraint. Use the "For Transform" button to activate. For clarity, this means that when scaling with a Limit Scale Constraint with this option on, the relevant values in the Transform Properties will stop changing once the Limit defined in the Limit Constraint is reached.
Diffstat (limited to 'source')
-rw-r--r--source/blender/src/buttons_object.c7
-rw-r--r--source/blender/src/transform.c185
2 files changed, 179 insertions, 13 deletions
diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c
index 968bba6b88b..1815fdd06f2 100644
--- a/source/blender/src/buttons_object.c
+++ b/source/blender/src/buttons_object.c
@@ -1378,7 +1378,7 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
int togButWidth = 50;
int textButWidth = ((width/2)-togButWidth);
- height = 106;
+ height = 136;
uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, "");
@@ -1415,8 +1415,11 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-72, (textButWidth-5), 18, &(data->zmax), 0.0001, 1000, 0.1,0.5,"Highest z value to allow");
uiBlockEndAlign(block);
+ /* special option(s) */
+ uiDefButBitS(block, TOG, LIMIT_TRANSFORM, B_CONSTRAINT_TEST, "For Transform", *xco+(width/4), *yco-100, (width/2), 18, &data->flag2, 0, 24, 0, 0, "Transforms are affected by this constraint as well");
+
/* constraint space settings */
- draw_constraint_spaceselect(block, con, *xco, *yco-100, is_armature_owner(ob), -1);
+ draw_constraint_spaceselect(block, con, *xco, *yco-130, is_armature_owner(ob), -1);
}
break;
case CONSTRAINT_TYPE_RIGIDBODYJOINT:
diff --git a/source/blender/src/transform.c b/source/blender/src/transform.c
index 5950eef6703..32c152488d1 100644
--- a/source/blender/src/transform.c
+++ b/source/blender/src/transform.c
@@ -1644,9 +1644,155 @@ static void constraintTransLim(TransInfo *t, TransData *td)
/* Evaluate valid constraints */
for (con= td->con; con; con= con->next) {
- /* we're only interested in Limit-Location constraints */
+ float tmat[4][4];
+
+ /* only use it if it's tagged for this purpose (and the right type) */
if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
bLocLimitConstraint *data= con->data;
+ if ((data->flag2 & LIMIT_TRANSFORM)==0)
+ continue;
+ }
+ else if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
+ bRotLimitConstraint *data= con->data;
+ if ((data->flag2 & LIMIT_TRANSFORM)==0)
+ continue;
+ }
+ else if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
+ bSizeLimitConstraint *data= con->data;
+ if ((data->flag2 & LIMIT_TRANSFORM)==0)
+ continue;
+ }
+ else {
+ /* not supported */
+ continue;
+ }
+
+ /* do space conversions */
+ if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
+ /* just multiply by td->mtx (this should be ok) */
+ Mat4CpyMat4(tmat, cob.matrix);
+ Mat4MulMat34(cob.matrix, td->mtx, tmat);
+ }
+ else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
+ /* skip... incompatable spacetype */
+ continue;
+ }
+
+ /* do constraint */
+ cti->evaluate_constraint(con, &cob, NULL);
+
+ /* convert spaces again */
+ if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
+ /* just multiply by td->mtx (this should be ok) */
+ Mat4CpyMat4(tmat, cob.matrix);
+ Mat4MulMat34(cob.matrix, td->smtx, tmat);
+ }
+ }
+
+ /* copy results from cob->matrix */
+ if (td->tdi) {
+ TransDataIpokey *tdi= td->tdi;
+ tdi->locx[0]= cob.matrix[3][0];
+ tdi->locy[0]= cob.matrix[3][1];
+ tdi->locz[0]= cob.matrix[3][2];
+ }
+ else {
+ VECCOPY(td->loc, cob.matrix[3]);
+ }
+ }
+}
+
+static void constraintRotLim(TransInfo *t, TransData *td)
+{
+ if (td->con && td->ext) {
+ bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
+ bConstraintOb cob;
+ bConstraint *con;
+
+ /* Make a temporary bConstraintOb for using these limit constraints
+ * - they only care that cob->matrix is correctly set ;-)
+ * - current space should be local
+ */
+ memset(&cob, 0, sizeof(bConstraintOb));
+ // FIXME: todo
+
+ /* Evaluate valid constraints */
+ for (con= td->con; con; con= con->next) {
+ /* we're only interested in Limit-Scale constraints */
+ if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
+ bSizeLimitConstraint *data= con->data;
+ float tmat[4][4];
+
+ /* only use it if it's tagged for this purpose */
+ if ((data->flag2 & LIMIT_TRANSFORM)==0)
+ continue;
+
+ /* do space conversions */
+ if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
+ /* just multiply by td->mtx (this should be ok) */
+ Mat4CpyMat4(tmat, cob.matrix);
+ Mat4MulMat34(cob.matrix, td->mtx, tmat);
+ }
+ else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
+ /* skip... incompatable spacetype */
+ continue;
+ }
+
+ /* do constraint */
+ cti->evaluate_constraint(con, &cob, NULL);
+
+ /* convert spaces again */
+ if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
+ /* just multiply by td->mtx (this should be ok) */
+ Mat4CpyMat4(tmat, cob.matrix);
+ Mat4MulMat34(cob.matrix, td->smtx, tmat);
+ }
+ }
+ }
+
+ /* copy results from cob->matrix */
+ // fixme: todo
+ }
+}
+
+static void constraintSizeLim(TransInfo *t, TransData *td)
+{
+ if (td->con && td->ext) {
+ bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
+ bConstraintOb cob;
+ bConstraint *con;
+
+ /* Make a temporary bConstraintOb for using these limit constraints
+ * - they only care that cob->matrix is correctly set ;-)
+ * - current space should be local
+ */
+ memset(&cob, 0, sizeof(bConstraintOb));
+ if (td->tdi) {
+ TransDataIpokey *tdi= td->tdi;
+ float size[3];
+
+ size[0]= tdi->sizex[0];
+ size[1]= tdi->sizey[0];
+ size[2]= tdi->sizez[0];
+ SizeToMat4(size, cob.matrix);
+ }
+ else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
+ /* scale val and reset size */
+ return; // TODO: fix this case
+ }
+ else {
+ /* Reset val if SINGLESIZE but using a constraint */
+ if (td->flag & TD_SINGLESIZE)
+ return;
+
+ SizeToMat4(td->ext->size, cob.matrix);
+ }
+
+ /* Evaluate valid constraints */
+ for (con= td->con; con; con= con->next) {
+ /* we're only interested in Limit-Scale constraints */
+ if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
+ bSizeLimitConstraint *data= con->data;
float tmat[4][4];
/* only use it if it's tagged for this purpose */
@@ -1657,7 +1803,7 @@ static void constraintTransLim(TransInfo *t, TransData *td)
if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
/* just multiply by td->mtx (this should be ok) */
Mat4CpyMat4(tmat, cob.matrix);
- Mat4MulMat34(cob.matrix, td->mtx, tmat); // checkme
+ Mat4MulMat34(cob.matrix, td->mtx, tmat);
}
else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
/* skip... incompatable spacetype */
@@ -1671,7 +1817,7 @@ static void constraintTransLim(TransInfo *t, TransData *td)
if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
/* just multiply by td->mtx (this should be ok) */
Mat4CpyMat4(tmat, cob.matrix);
- Mat4MulMat34(cob.matrix, td->smtx, tmat); // checkme
+ Mat4MulMat34(cob.matrix, td->smtx, tmat);
}
}
}
@@ -1679,12 +1825,24 @@ static void constraintTransLim(TransInfo *t, TransData *td)
/* copy results from cob->matrix */
if (td->tdi) {
TransDataIpokey *tdi= td->tdi;
- tdi->locx[0]= cob.matrix[3][0];
- tdi->locy[0]= cob.matrix[3][1];
- tdi->locz[0]= cob.matrix[3][2];
+ float size[3];
+
+ Mat4ToSize(cob.matrix, size);
+
+ tdi->sizex[0]= size[0];
+ tdi->sizey[0]= size[1];
+ tdi->sizez[0]= size[2];
+ }
+ else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
+ /* scale val and reset size */
+ return; // TODO: fix this case
}
else {
- VECCOPY(td->loc, cob.matrix[3]);
+ /* Reset val if SINGLESIZE but using a constraint */
+ if (td->flag & TD_SINGLESIZE)
+ return;
+
+ Mat4ToSize(cob.matrix, td->ext->size);
}
}
}
@@ -2098,7 +2256,7 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
if (td->ext) {
float fsize[3];
-
+
if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
float obsizemat[3][3];
// Reorient the size mat to fit the oriented object.
@@ -2127,11 +2285,11 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
add_tdi_poin(tdi->sizey, tdi->oldsize+1, vec[1]);
add_tdi_poin(tdi->sizez, tdi->oldsize+2, vec[2]);
- }
+ }
else if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
/* scale val and reset size */
*td->val = td->ival * fsize[0] * td->factor;
-
+
td->ext->size[0] = td->ext->isize[0];
td->ext->size[1] = td->ext->isize[1];
td->ext->size[2] = td->ext->isize[2];
@@ -2140,13 +2298,16 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
/* Reset val if SINGLESIZE but using a constraint */
if (td->flag & TD_SINGLESIZE)
*td->val = td->ival;
-
+
td->ext->size[0] = td->ext->isize[0] * (fsize[0]) * td->factor;
td->ext->size[1] = td->ext->isize[1] * (fsize[1]) * td->factor;
td->ext->size[2] = td->ext->isize[2] * (fsize[2]) * td->factor;
}
}
+
+ constraintSizeLim(t, td);
}
+
/* For individual element center, Editmode need to use iloc */
if (t->flag & T_POINTS)
VecSubf(vec, td->iloc, center);
@@ -2176,6 +2337,8 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
}
else VecAddf(td->loc, td->iloc, vec);
+
+ constraintTransLim(t, td);
}
int Resize(TransInfo *t, short mval[2])