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

simple_deform.c « intern « blenkernel « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e78e73afadbff4330b8cceb29a79effb70c945b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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);
	}
}