Blender  V2.93
transform_convert_paintcurve.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include "DNA_brush_types.h"
25 
26 #include "MEM_guardedalloc.h"
27 
28 #include "BLI_math.h"
29 
30 #include "BKE_context.h"
31 #include "BKE_paint.h"
32 
33 #include "transform.h"
34 #include "transform_convert.h"
35 
36 typedef struct TransDataPaintCurve {
37  struct PaintCurvePoint *pcp; /* initial curve point */
38  char id;
40 
41 /* -------------------------------------------------------------------- */
45 #define PC_IS_ANY_SEL(pc) (((pc)->bez.f1 | (pc)->bez.f2 | (pc)->bez.f3) & SELECT)
46 
48  PaintCurvePoint *pcp, int id, TransData2D *td2d, TransDataPaintCurve *tdpc, TransData *td)
49 {
50  BezTriple *bezt = &pcp->bez;
51  copy_v2_v2(td2d->loc, bezt->vec[id]);
52  td2d->loc[2] = 0.0f;
53  td2d->loc2d = bezt->vec[id];
54 
55  td->flag = 0;
56  td->loc = td2d->loc;
57  copy_v3_v3(td->center, bezt->vec[1]);
58  copy_v3_v3(td->iloc, td->loc);
59 
60  memset(td->axismtx, 0, sizeof(td->axismtx));
61  td->axismtx[2][2] = 1.0f;
62 
63  td->ext = NULL;
64  td->val = NULL;
65  td->flag |= TD_SELECTED;
66  td->dist = 0.0;
67 
68  unit_m3(td->mtx);
69  unit_m3(td->smtx);
70 
71  tdpc->id = id;
72  tdpc->pcp = pcp;
73 }
74 
76  TransData *td,
77  TransData2D *td2d,
78  TransDataPaintCurve *tdpc)
79 {
80  BezTriple *bezt = &pcp->bez;
81 
82  if (pcp->bez.f2 == SELECT) {
83  int i;
84  for (i = 0; i < 3; i++) {
85  copy_v2_v2(td2d->loc, bezt->vec[i]);
86  td2d->loc[2] = 0.0f;
87  td2d->loc2d = bezt->vec[i];
88 
89  td->flag = 0;
90  td->loc = td2d->loc;
91  copy_v3_v3(td->center, bezt->vec[1]);
92  copy_v3_v3(td->iloc, td->loc);
93 
94  memset(td->axismtx, 0, sizeof(td->axismtx));
95  td->axismtx[2][2] = 1.0f;
96 
97  td->ext = NULL;
98  td->val = NULL;
99  td->flag |= TD_SELECTED;
100  td->dist = 0.0;
101 
102  unit_m3(td->mtx);
103  unit_m3(td->smtx);
104 
105  tdpc->id = i;
106  tdpc->pcp = pcp;
107 
108  td++;
109  td2d++;
110  tdpc++;
111  }
112  }
113  else {
114  if (bezt->f3 & SELECT) {
115  PaintCurveConvertHandle(pcp, 2, td2d, tdpc, td);
116  td2d++;
117  tdpc++;
118  td++;
119  }
120 
121  if (bezt->f1 & SELECT) {
122  PaintCurveConvertHandle(pcp, 0, td2d, tdpc, td);
123  }
124  }
125 }
126 
128 {
130  PaintCurve *pc;
131  PaintCurvePoint *pcp;
132  Brush *br;
133  TransData *td = NULL;
134  TransData2D *td2d = NULL;
135  TransDataPaintCurve *tdpc = NULL;
136  int i;
137  int total = 0;
138 
140 
141  tc->data_len = 0;
142 
143  if (!paint || !paint->brush || !paint->brush->paint_curve) {
144  return;
145  }
146 
147  br = paint->brush;
148  pc = br->paint_curve;
149 
150  for (pcp = pc->points, i = 0; i < pc->tot_points; i++, pcp++) {
151  if (PC_IS_ANY_SEL(pcp)) {
152  if (pcp->bez.f2 & SELECT) {
153  total += 3;
154  continue;
155  }
156  if (pcp->bez.f1 & SELECT) {
157  total++;
158  }
159  if (pcp->bez.f3 & SELECT) {
160  total++;
161  }
162  }
163  }
164 
165  if (!total) {
166  return;
167  }
168 
169  tc->data_len = total;
170  td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransData2D");
171  td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData");
172  tc->custom.type.data = tdpc = MEM_callocN(tc->data_len * sizeof(TransDataPaintCurve),
173  "TransDataPaintCurve");
174  tc->custom.type.use_free = true;
175 
176  for (pcp = pc->points, i = 0; i < pc->tot_points; i++, pcp++) {
177  if (PC_IS_ANY_SEL(pcp)) {
178  PaintCurvePointToTransData(pcp, td, td2d, tdpc);
179 
180  if (pcp->bez.f2 & SELECT) {
181  td += 3;
182  td2d += 3;
183  tdpc += 3;
184  }
185  else {
186  if (pcp->bez.f1 & SELECT) {
187  td++;
188  td2d++;
189  tdpc++;
190  }
191  if (pcp->bez.f3 & SELECT) {
192  td++;
193  td2d++;
194  tdpc++;
195  }
196  }
197  }
198  }
199 }
200 
203 /* -------------------------------------------------------------------- */
208 {
209  int i;
210 
212 
213  TransData2D *td2d = tc->data_2d;
214  TransDataPaintCurve *tdpc = tc->custom.type.data;
215 
216  for (i = 0; i < tc->data_len; i++, tdpc++, td2d++) {
217  PaintCurvePoint *pcp = tdpc->pcp;
218  copy_v2_v2(pcp->bez.vec[tdpc->id], td2d->loc);
219  }
220 }
221 
struct Paint * BKE_paint_get_active_from_context(const struct bContext *C)
void unit_m3(float m[3][3])
Definition: math_matrix.c:58
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:39
#define SELECT
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
float vec[3][3]
struct PaintCurve * paint_curve
PaintCurvePoint * points
struct Brush * brush
TransCustomData type
Definition: transform.h:428
unsigned int use_free
Definition: transform.h:408
float loc[3]
TransCustomDataContainer custom
Definition: transform.h:501
TransData * data
Definition: transform.h:448
TransData2D * data_2d
Definition: transform.h:452
struct PaintCurvePoint * pcp
float smtx[3][3]
float axismtx[3][3]
float mtx[3][3]
TransDataExtension * ext
float * val
#define TRANS_DATA_CONTAINER_FIRST_SINGLE(t)
Definition: transform.h:810
conversion and adaptation of different datablocks to a common struct.
void flushTransPaintCurve(TransInfo *t)
void createTransPaintCurveVerts(bContext *C, TransInfo *t)
static void PaintCurvePointToTransData(PaintCurvePoint *pcp, TransData *td, TransData2D *td2d, TransDataPaintCurve *tdpc)
static void PaintCurveConvertHandle(PaintCurvePoint *pcp, int id, TransData2D *td2d, TransDataPaintCurve *tdpc, TransData *td)
#define PC_IS_ANY_SEL(pc)
struct TransDataPaintCurve TransDataPaintCurve
@ TD_SELECTED