[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16754] trunk/blender/source/blender: Merge of SimpleDeform modifier from soc-2008-jaguarandi branch
André Pinto
andresusanopinto at gmail.com
Fri Sep 26 23:21:21 CEST 2008
Revision: 16754
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16754
Author: jaguarandi
Date: 2008-09-26 23:21:20 +0200 (Fri, 26 Sep 2008)
Log Message:
-----------
Merge of SimpleDeform modifier from soc-2008-jaguarandi branch
http://wiki.blender.org/index.php/User:Jaguarandi/SummerOfCode2008/SimpleDeform
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/modifier.c
trunk/blender/source/blender/makesdna/DNA_modifier_types.h
trunk/blender/source/blender/src/buttons_editing.c
Added Paths:
-----------
trunk/blender/source/blender/blenkernel/BKE_simple_deform.h
trunk/blender/source/blender/blenkernel/intern/simple_deform.c
Copied: trunk/blender/source/blender/blenkernel/BKE_simple_deform.h (from rev 16749, branches/soc-2008-jaguarandi/source/blender/blenkernel/BKE_simple_deform.h)
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_simple_deform.h (rev 0)
+++ trunk/blender/source/blender/blenkernel/BKE_simple_deform.h 2008-09-26 21:21:20 UTC (rev 16754)
@@ -0,0 +1,39 @@
+/**
+ * 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;
+
+void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3], int numVerts);
+
+#endif
+
Modified: trunk/blender/source/blender/blenkernel/intern/modifier.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/modifier.c 2008-09-26 19:38:07 UTC (rev 16753)
+++ trunk/blender/source/blender/blenkernel/intern/modifier.c 2008-09-26 21:21:20 UTC (rev 16754)
@@ -105,6 +105,7 @@
#include "depsgraph_private.h"
#include "BKE_deform.h"
#include "BKE_shrinkwrap.h"
+#include "BKE_simple_deform.h"
#include "LOD_DependKludge.h"
#include "LOD_decimation.h"
@@ -7743,7 +7744,7 @@
CustomDataMask dataMask = shrinkwrapModifier_requiredDataMask(md);
/* We implement requiredDataMask but thats not really usefull since mesh_calc_modifiers pass a NULL derivedData or without the modified vertexs applied */
- if(shrinkwrapModifier_requiredDataMask(md))
+ if(dataMask)
{
if(derivedData) dm = CDDM_copy(derivedData);
else if(ob->type==OB_MESH) dm = CDDM_from_mesh(ob->data, ob);
@@ -7797,6 +7798,109 @@
dag_add_relation(forest, dag_get_node(forest, smd->auxTarget), obNode, DAG_RL_OB_DATA | DAG_RL_DATA_DATA, "Shrinkwrap Modifier");
}
+/* SimpleDeform */
+static void simpledeformModifier_initData(ModifierData *md)
+{
+ SimpleDeformModifierData *smd = (SimpleDeformModifierData*) md;
+
+ smd->mode = MOD_SIMPLEDEFORM_MODE_TWIST;
+ smd->axis = 0;
+
+ smd->origin = NULL;
+ smd->factor = 0.35f;
+ smd->limit[0] = 0.0f;
+ smd->limit[1] = 1.0f;
+}
+
+static void simpledeformModifier_copyData(ModifierData *md, ModifierData *target)
+{
+ SimpleDeformModifierData *smd = (SimpleDeformModifierData*)md;
+ SimpleDeformModifierData *tsmd = (SimpleDeformModifierData*)target;
+
+ tsmd->mode = smd->mode;
+ tsmd->axis = smd->axis;
+ tsmd->origin= smd->origin;
+ tsmd->factor= smd->factor;
+ memcpy(tsmd->limit, smd->limit, sizeof(tsmd->limit));
+}
+
+static CustomDataMask simpledeformModifier_requiredDataMask(ModifierData *md)
+{
+ SimpleDeformModifierData *smd = (SimpleDeformModifierData *)md;
+ CustomDataMask dataMask = 0;
+
+ /* ask for vertexgroups if we need them */
+ if(smd->vgroup_name[0])
+ dataMask |= (1 << CD_MDEFORMVERT);
+
+ return dataMask;
+}
+
+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");
+}
+
+static void simpledeformModifier_deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
+{
+ DerivedMesh *dm = NULL;
+ CustomDataMask dataMask = simpledeformModifier_requiredDataMask(md);
+
+ /* We implement requiredDataMask but thats not really usefull since mesh_calc_modifiers pass a NULL derivedData or without the modified vertexs applied */
+ if(dataMask)
+ {
+ if(derivedData) dm = CDDM_copy(derivedData);
+ else if(ob->type==OB_MESH) dm = CDDM_from_mesh(ob->data, ob);
+ else return;
+
+ if(dataMask & CD_MVERT)
+ {
+ CDDM_apply_vert_coords(dm, vertexCos);
+ CDDM_calc_normals(dm);
+ }
+ }
+
+ SimpleDeformModifier_do((SimpleDeformModifierData*)md, ob, dm, vertexCos, numVerts);
+
+ if(dm)
+ dm->release(dm);
+
+}
+
+static void simpledeformModifier_deformVertsEM(ModifierData *md, Object *ob, EditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
+{
+ DerivedMesh *dm = NULL;
+ CustomDataMask dataMask = simpledeformModifier_requiredDataMask(md);
+
+ /* We implement requiredDataMask but thats not really usefull since mesh_calc_modifiers pass a NULL derivedData or without the modified vertexs applied */
+ if(dataMask)
+ {
+ if(derivedData) dm = CDDM_copy(derivedData);
+ else if(ob->type==OB_MESH) dm = CDDM_from_editmesh(editData, ob->data);
+ else return;
+
+ if(dataMask & CD_MVERT)
+ {
+ CDDM_apply_vert_coords(dm, vertexCos);
+ CDDM_calc_normals(dm);
+ }
+ }
+
+ SimpleDeformModifier_do((SimpleDeformModifierData*)md, ob, dm, vertexCos, numVerts);
+
+ if(dm)
+ dm->release(dm);
+}
+
/***/
static ModifierTypeInfo typeArr[NUM_MODIFIER_TYPES];
@@ -8154,6 +8258,20 @@
mti->deformVertsEM = shrinkwrapModifier_deformVertsEM;
mti->updateDepgraph = shrinkwrapModifier_updateDepgraph;
+ mti = INIT_TYPE(SimpleDeform);
+ mti->type = eModifierTypeType_OnlyDeform;
+ mti->flags = eModifierTypeFlag_AcceptsMesh
+ | eModifierTypeFlag_AcceptsCVs
+ | eModifierTypeFlag_SupportsEditmode
+ | eModifierTypeFlag_EnableInEditmode;
+ mti->initData = simpledeformModifier_initData;
+ mti->copyData = simpledeformModifier_copyData;
+ mti->requiredDataMask = simpledeformModifier_requiredDataMask;
+ mti->deformVerts = simpledeformModifier_deformVerts;
+ mti->deformVertsEM = simpledeformModifier_deformVertsEM;
+ mti->foreachObjectLink = simpledeformModifier_foreachObjectLink;
+ mti->updateDepgraph = simpledeformModifier_updateDepgraph;
+
typeArrInit = 0;
#undef INIT_TYPE
}
Copied: trunk/blender/source/blender/blenkernel/intern/simple_deform.c (from rev 16749, branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/simple_deform.c)
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/simple_deform.c (rev 0)
+++ trunk/blender/source/blender/blenkernel/intern/simple_deform.c 2008-09-26 21:21:20 UTC (rev 16754)
@@ -0,0 +1,248 @@
+/**
+ * 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 "BKE_deform.h"
+#include "BKE_utildefines.h"
+#include "BLI_arithb.h"
+#include "BKE_shrinkwrap.h"
+
+#include <string.h>
+#include <math.h>
+
+
+//Clamps/Limits the given coordinate to: limits[0] <= co[axis] <= limits[1]
+//The ammount of clamp is saved on dcut
+static void axis_limit(int axis, const float limits[2], float co[3], float dcut[3])
+{
+ float val = co[axis];
+ if(limits[0] > val) val = limits[0];
+ if(limits[1] < val) val = limits[1];
+
+ dcut[axis] = co[axis] - val;
+ co[axis] = val;
+}
+
+static void simpleDeform_taper(const float factor, const float dcut[3], float *co)
+{
+ float x = co[0], y = co[1], z = co[2];
+ float scale = z*factor;
+
+ co[0] = x + x*scale;
+ co[1] = y + y*scale;
+ co[2] = z;
+
+ if(dcut)
+ {
+ co[0] += dcut[0];
+ co[1] += dcut[1];
+ co[2] += dcut[2];
+ }
+}
+
+static void simpleDeform_stretch(const float factor, const float dcut[3], float *co)
+{
+ float x = co[0], y = co[1], z = co[2];
+ float scale;
+
+ scale = (z*z*factor-factor + 1.0);
+
+ co[0] = x*scale;
+ co[1] = y*scale;
+ co[2] = z*(1.0+factor);
+
+
+ if(dcut)
+ {
+ co[0] += dcut[0];
+ co[1] += dcut[1];
+ co[2] += dcut[2];
+ }
+}
+
+static void simpleDeform_twist(const float factor, const float *dcut, float *co)
+{
+ float x = co[0], y = co[1], z = co[2];
+ float theta, sint, cost;
+
+ theta = z*factor;
+ sint = sin(theta);
+ cost = cos(theta);
+
+ co[0] = x*cost - y*sint;
+ co[1] = x*sint + y*cost;
+ co[2] = z;
+
+ if(dcut)
+ {
+ co[0] += dcut[0];
+ co[1] += dcut[1];
+ co[2] += dcut[2];
+ }
+}
+
+static void simpleDeform_bend(const float factor, const float dcut[3], float *co)
+{
+ float x = co[0], y = co[1], z = co[2];
+ float theta, sint, cost;
+
+ theta = x*factor;
+ sint = sin(theta);
+ cost = cos(theta);
+
+ if(fabs(factor) > 1e-7f)
+ {
+ co[0] = -(y-1.0f/factor)*sint;
+ co[1] = (y-1.0f/factor)*cost + 1.0f/factor;
+ co[2] = z;
+ }
+
+
+ if(dcut)
+ {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list