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:
authorAndre Susano Pinto <andresusanopinto@gmail.com>2008-06-24 16:04:27 +0400
committerAndre Susano Pinto <andresusanopinto@gmail.com>2008-06-24 16:04:27 +0400
commit9629f7ca119fe1ea0c9549be126466e4c6880bb1 (patch)
treefedb3ce848a996737ecfe775b7bfa51b4bdca9af /source/blender/blenkernel
parentac898d39caedf1dc4ff49432f320e7e99afe40ca (diff)
Adding initial SimpleModifier (bend,taper,twist)
(I might only touch this code again late on the week :S, so here is a tmp commit)
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_simple_deform.h40
-rw-r--r--source/blender/blenkernel/intern/modifier.c57
-rw-r--r--source/blender/blenkernel/intern/simple_deform.c118
3 files changed, 215 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_simple_deform.h b/source/blender/blenkernel/BKE_simple_deform.h
new file mode 100644
index 00000000000..b2737a2708f
--- /dev/null
+++ b/source/blender/blenkernel/BKE_simple_deform.h
@@ -0,0 +1,40 @@
+/**
+ * BKE_shrinkwrap.h
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef BKE_SIMPLE_DEFORM_H
+#define BKE_SIMPLE_DEFORM_H
+
+struct Object;
+struct DerivedMesh;
+struct SimpleDeformModifierData;
+
+/* struct DerivedMesh *simpledeformModifier_do(struct SimpleDeformModifierData *smd, struct Object *ob, struct DerivedMesh *dm, int useRenderParams, int isFinalCalc); */
+void SimpleDeformModifier_do(SimpleDeformModifierData *smd, float (*vertexCos)[3], int numVerts);
+
+#endif
+
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index c5d98dd9655..4266b559030 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -7279,6 +7279,50 @@ static void shrinkwrapModifier_updateDepgraph(ModifierData *md, DagForest *fores
dag_add_relation(forest, dag_get_node(forest, smd->cutPlane), obNode, DAG_RL_OB_DATA | DAG_RL_DATA_DATA, "Shrinkwrap Modifier");
}
+/* SimpleDeform */
+static void simpledeformModifier_initData(ModifierData *md)
+{
+ SimpleDeformModifierData *smd = (SimpleDeformModifierData*) md;
+
+ smd->mode = 0;
+ smd->origin = 0;
+ smd->factor[0] = 1.0;
+}
+
+static void simpledeformModifier_copyData(ModifierData *md, ModifierData *target)
+{
+ SimpleDeformModifierData *smd = (SimpleDeformModifierData*)md;
+ SimpleDeformModifierData *tsmd = (SimpleDeformModifierData*)target;
+
+ tsmd->mode = smd->mode;
+ tsmd->origin= smd->origin;
+ memcpy(tsmd->factor, smd->factor, sizeof(tsmd->factor));
+}
+
+static void simpledeformModifier_deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
+{
+ SimpleDeformModifier_do((SimpleDeformModifierData*)md, vertexCos, numVerts);
+}
+
+static void simpledeformModifier_deformVertsEM(ModifierData *md, Object *ob, EditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
+{
+ SimpleDeformModifier_do((SimpleDeformModifierData*)md, vertexCos, numVerts);
+}
+
+static void simpledeformModifier_foreachObjectLink(ModifierData *md, Object *ob, void (*walk)(void *userData, Object *ob, Object **obpoin), void *userData)
+{
+ SimpleDeformModifierData *smd = (SimpleDeformModifierData*)md;
+ walk(userData, ob, &smd->origin);
+}
+
+static void simpledeformModifier_updateDepgraph(ModifierData *md, DagForest *forest, Object *ob, DagNode *obNode)
+{
+ SimpleDeformModifierData *smd = (SimpleDeformModifierData*)md;
+
+ if (smd->origin)
+ dag_add_relation(forest, dag_get_node(forest, smd->origin), obNode, DAG_RL_OB_DATA, "SimpleDeform Modifier");
+}
+
/***/
@@ -7615,6 +7659,19 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type)
mti->applyModifierEM = shrinkwrapModifier_applyModifierEM;
mti->updateDepgraph = shrinkwrapModifier_updateDepgraph;
+ mti = INIT_TYPE(SimpleDeform);
+ mti->type = eModifierTypeType_OnlyDeform;
+ mti->flags = eModifierTypeFlag_AcceptsMesh
+ | eModifierTypeFlag_SupportsEditmode
+ | eModifierTypeFlag_EnableInEditmode;
+ mti->initData = simpledeformModifier_initData;
+ mti->copyData = simpledeformModifier_copyData;
+ mti->deformVerts = simpledeformModifier_deformVerts;
+ mti->deformVertsEM = simpledeformModifier_deformVertsEM;
+ mti->foreachObjectLink = simpledeformModifier_foreachObjectLink;
+ mti->updateDepgraph = simpledeformModifier_updateDepgraph;
+
+
typeArrInit = 0;
#undef INIT_TYPE
}
diff --git a/source/blender/blenkernel/intern/simple_deform.c b/source/blender/blenkernel/intern/simple_deform.c
new file mode 100644
index 00000000000..e78e73afadb
--- /dev/null
+++ b/source/blender/blenkernel/intern/simple_deform.c
@@ -0,0 +1,118 @@
+/**
+ * deform_simple.c
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): André Pinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#include "DNA_object_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BKE_simple_deform.h"
+#include "BKE_DerivedMesh.h"
+#include "BLI_arithb.h"
+
+#include <string.h>
+#include <math.h>
+
+
+static void simpleDeform_tapper(const float factor, float *co)
+{
+ float x = co[0], y = co[1], z = co[2];
+
+ co[0] = x*(1.0f + z*factor);
+ co[1] = y;
+ co[2] = z;
+}
+
+
+static void simpleDeform_twist(const float factor, float *co)
+{
+ float x = co[0], y = co[1], z = co[2];
+
+ float theta = z*factor;
+ float sint = sin(theta);
+ float cost = cos(theta);
+
+ co[0] = x*cost - y*sint;
+ co[1] = x*sint + y*cost;
+ co[2] = z;
+}
+
+static void simpleDeform_bend(const float factor, float *co)
+{
+ float x = co[0], y = co[1], z = co[2];
+
+ float x0 = 0.0f;
+ float theta = (x - x0)*factor;
+ float sint = sin(theta);
+ float cost = cos(theta);
+
+ co[0] = -sint*(y-1.0f/factor) + x0;
+ co[1] = cost*(y-1.0f/factor) + 1.0f/factor;
+ co[2] = z;
+}
+
+static void simpleDeform_shear(const float factor, float *co)
+{
+ float x = co[0], y = co[1], z = co[2];
+
+ co[0] = x + factor;
+ co[1] = y;
+ co[2] = z;
+}
+
+/* simple deform modifier */
+void SimpleDeformModifier_do(SimpleDeformModifierData *smd, float (*vertexCos)[3], int numVerts)
+{
+ float (*ob2mod)[4] = NULL, (*mod2ob)[4] = NULL;
+ if(smd->origin)
+ {
+ Mat4Invert(smd->origin->imat, smd->origin->obmat); //inverse is outdated
+
+ ob2mod = smd->origin->imat;
+ mod2ob = smd->origin->obmat;
+ }
+
+
+ for(; numVerts; numVerts--, vertexCos++)
+ {
+ if(ob2mod)
+ Mat4MulVecfl(ob2mod, *vertexCos);
+
+ switch(smd->mode)
+ {
+ case 0: simpleDeform_tapper (smd->factor[0], *vertexCos); break;
+ case 1: simpleDeform_twist (smd->factor[0], *vertexCos); break;
+ case 2: simpleDeform_bend (smd->factor[0], *vertexCos); break;
+ case 3: simpleDeform_shear (smd->factor[0], *vertexCos); break;
+ }
+
+ if(mod2ob)
+ Mat4MulVecfl(mod2ob, *vertexCos);
+ }
+}
+
+