Blender  V3.3
transform_convert_paintcurve.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include "DNA_brush_types.h"
9 
10 #include "MEM_guardedalloc.h"
11 
12 #include "BLI_math.h"
13 
14 #include "BKE_context.h"
15 #include "BKE_paint.h"
16 
17 #include "transform.h"
18 #include "transform_convert.h"
19 
20 typedef struct TransDataPaintCurve {
21  struct PaintCurvePoint *pcp; /* initial curve point */
22  char id;
24 
25 /* -------------------------------------------------------------------- */
29 #define PC_IS_ANY_SEL(pc) (((pc)->bez.f1 | (pc)->bez.f2 | (pc)->bez.f3) & SELECT)
30 
32  PaintCurvePoint *pcp, int id, TransData2D *td2d, TransDataPaintCurve *tdpc, TransData *td)
33 {
34  BezTriple *bezt = &pcp->bez;
35  copy_v2_v2(td2d->loc, bezt->vec[id]);
36  td2d->loc[2] = 0.0f;
37  td2d->loc2d = bezt->vec[id];
38 
39  td->flag = 0;
40  td->loc = td2d->loc;
41  copy_v3_v3(td->center, bezt->vec[1]);
42  copy_v3_v3(td->iloc, td->loc);
43 
44  memset(td->axismtx, 0, sizeof(td->axismtx));
45  td->axismtx[2][2] = 1.0f;
46 
47  td->ext = NULL;
48  td->val = NULL;
49  td->flag |= TD_SELECTED;
50  td->dist = 0.0;
51 
52  unit_m3(td->mtx);
53  unit_m3(td->smtx);
54 
55  tdpc->id = id;
56  tdpc->pcp = pcp;
57 }
58 
60  TransData *td,
61  TransData2D *td2d,
62  TransDataPaintCurve *tdpc)
63 {
64  BezTriple *bezt = &pcp->bez;
65 
66  if (pcp->bez.f2 == SELECT) {
67  int i;
68  for (i = 0; i < 3; i++) {
69  copy_v2_v2(td2d->loc, bezt->vec[i]);
70  td2d->loc[2] = 0.0f;
71  td2d->loc2d = bezt->vec[i];
72 
73  td->flag = 0;
74  td->loc = td2d->loc;
75  copy_v3_v3(td->center, bezt->vec[1]);
76  copy_v3_v3(td->iloc, td->loc);
77 
78  memset(td->axismtx, 0, sizeof(td->axismtx));
79  td->axismtx[2][2] = 1.0f;
80 
81  td->ext = NULL;
82  td->val = NULL;
83  td->flag |= TD_SELECTED;
84  td->dist = 0.0;
85 
86  unit_m3(td->mtx);
87  unit_m3(td->smtx);
88 
89  tdpc->id = i;
90  tdpc->pcp = pcp;
91 
92  td++;
93  td2d++;
94  tdpc++;
95  }
96  }
97  else {
98  if (bezt->f3 & SELECT) {
99  PaintCurveConvertHandle(pcp, 2, td2d, tdpc, td);
100  td2d++;
101  tdpc++;
102  td++;
103  }
104 
105  if (bezt->f1 & SELECT) {
106  PaintCurveConvertHandle(pcp, 0, td2d, tdpc, td);
107  }
108  }
109 }
110 
112 {
114  PaintCurve *pc;
115  PaintCurvePoint *pcp;
116  Brush *br;
117  TransData *td = NULL;
118  TransData2D *td2d = NULL;
119  TransDataPaintCurve *tdpc = NULL;
120  int i;
121  int total = 0;
122 
124 
125  tc->data_len = 0;
126 
127  if (!paint || !paint->brush || !paint->brush->paint_curve) {
128  return;
129  }
130 
131  br = paint->brush;
132  pc = br->paint_curve;
133 
134  for (pcp = pc->points, i = 0; i < pc->tot_points; i++, pcp++) {
135  if (PC_IS_ANY_SEL(pcp)) {
136  if (pcp->bez.f2 & SELECT) {
137  total += 3;
138  continue;
139  }
140  if (pcp->bez.f1 & SELECT) {
141  total++;
142  }
143  if (pcp->bez.f3 & SELECT) {
144  total++;
145  }
146  }
147  }
148 
149  if (!total) {
150  return;
151  }
152 
153  tc->data_len = total;
154  td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransData2D");
155  td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData");
156  tc->custom.type.data = tdpc = MEM_callocN(tc->data_len * sizeof(TransDataPaintCurve),
157  "TransDataPaintCurve");
158  tc->custom.type.use_free = true;
159 
160  for (pcp = pc->points, i = 0; i < pc->tot_points; i++, pcp++) {
161  if (PC_IS_ANY_SEL(pcp)) {
162  PaintCurvePointToTransData(pcp, td, td2d, tdpc);
163 
164  if (pcp->bez.f2 & SELECT) {
165  td += 3;
166  td2d += 3;
167  tdpc += 3;
168  }
169  else {
170  if (pcp->bez.f1 & SELECT) {
171  td++;
172  td2d++;
173  tdpc++;
174  }
175  if (pcp->bez.f3 & SELECT) {
176  td++;
177  td2d++;
178  tdpc++;
179  }
180  }
181  }
182  }
183 }
184 
187 /* -------------------------------------------------------------------- */
192 {
193  int i;
194 
196 
197  TransData2D *td2d = tc->data_2d;
198  TransDataPaintCurve *tdpc = tc->custom.type.data;
199 
200  for (i = 0; i < tc->data_len; i++, tdpc++, td2d++) {
201  PaintCurvePoint *pcp = tdpc->pcp;
202  copy_v2_v2(pcp->bez.vec[tdpc->id], td2d->loc);
203  }
204 }
205 
209  /* flags */ (T_POINTS | T_2D_EDIT),
210  /* createTransData */ createTransPaintCurveVerts,
211  /* recalcData */ flushTransPaintCurve,
212  /* special_aftertrans_update */ NULL,
213 };
struct Paint * BKE_paint_get_active_from_context(const struct bContext *C)
void unit_m3(float m[3][3])
Definition: math_matrix.c:40
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:25
#define SELECT
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
#define TRANS_DATA_CONTAINER_FIRST_SINGLE(t)
uint8_t f3
float vec[3][3]
uint8_t f1
uint8_t f2
struct PaintCurve * paint_curve
PaintCurvePoint * points
struct Brush * brush
float * loc2d
float loc[3]
struct PaintCurvePoint * pcp
float smtx[3][3]
float axismtx[3][3]
float mtx[3][3]
TransDataExtension * ext
float * val
conversion and adaptation of different datablocks to a common struct.
static void flushTransPaintCurve(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)
static void createTransPaintCurveVerts(bContext *C, TransInfo *t)
TransConvertTypeInfo TransConvertType_PaintCurve
#define PC_IS_ANY_SEL(pc)
struct TransDataPaintCurve TransDataPaintCurve
@ TD_SELECTED