Blender  V3.3
rna_curves.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <stdlib.h>
8 
9 #include "RNA_define.h"
10 #include "RNA_enum_types.h"
11 
12 #include "rna_internal.h"
13 
14 #include "DNA_curves_types.h"
15 
16 #include "BLI_math_base.h"
17 #include "BLI_string.h"
18 
19 #include "WM_types.h"
20 
22  {CURVE_TYPE_CATMULL_ROM, "CATMULL_ROM", 0, "Catmull Rom", ""},
23  {CURVE_TYPE_POLY, "POLY", 0, "Poly", ""},
24  {CURVE_TYPE_BEZIER, "BEZIER", 0, "Bezier", ""},
25  {CURVE_TYPE_NURBS, "NURBS", 0, "NURBS", ""},
26  {0, NULL, 0, NULL, NULL},
27 };
28 
29 #ifdef RNA_RUNTIME
30 
31 # include "BLI_math_vector.h"
32 
33 # include "BKE_attribute.h"
34 # include "BKE_curves.h"
35 
36 # include "DEG_depsgraph.h"
37 
38 # include "WM_api.h"
39 # include "WM_types.h"
40 
41 static Curves *rna_curves(const PointerRNA *ptr)
42 {
43  return (Curves *)ptr->owner_id;
44 }
45 
46 static int rna_Curves_curve_offset_data_length(PointerRNA *ptr)
47 {
48  const Curves *curves = rna_curves(ptr);
49  return curves->geometry.curve_num + 1;
50 }
51 
52 static void rna_Curves_curve_offset_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
53 {
54  const Curves *curves = rna_curves(ptr);
56  (void *)curves->geometry.curve_offsets,
57  sizeof(int),
58  curves->geometry.curve_num + 1,
59  false,
60  NULL);
61 }
62 
63 static int rna_CurvePoint_index_get_const(const PointerRNA *ptr)
64 {
65  const Curves *curves = rna_curves(ptr);
66  const float(*co)[3] = ptr->data;
67  const float(*positions)[3] = (const float(*)[3])CustomData_get_layer_named(
68  &curves->geometry.point_data, CD_PROP_FLOAT3, "position");
69  return (int)(co - positions);
70 }
71 
72 static int rna_Curves_position_data_length(PointerRNA *ptr)
73 {
74  const Curves *curves = rna_curves(ptr);
75  return curves->geometry.point_num;
76 }
77 
78 static void rna_Curves_position_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
79 {
80  const Curves *curves = rna_curves(ptr);
81  const float(*positions)[3] = (const float(*)[3])CustomData_get_layer_named(
82  &curves->geometry.point_data, CD_PROP_FLOAT3, "position");
84  iter, (void *)positions, sizeof(float[3]), curves->geometry.point_num, false, NULL);
85 }
86 
87 static int rna_CurvePoint_index_get(PointerRNA *ptr)
88 {
89  return rna_CurvePoint_index_get_const(ptr);
90 }
91 
92 static void rna_CurvePoint_location_get(PointerRNA *ptr, float value[3])
93 {
94  copy_v3_v3(value, (const float *)ptr->data);
95 }
96 
97 static void rna_CurvePoint_location_set(PointerRNA *ptr, const float value[3])
98 {
99  copy_v3_v3((float *)ptr->data, value);
100 }
101 
102 static float rna_CurvePoint_radius_get(PointerRNA *ptr)
103 {
104  const Curves *curves = rna_curves(ptr);
105  const float *radii = (const float *)CustomData_get_layer_named(
106  &curves->geometry.point_data, CD_PROP_FLOAT, "radius");
107  if (radii == NULL) {
108  return 0.0f;
109  }
110  return radii[rna_CurvePoint_index_get_const(ptr)];
111 }
112 
113 static void rna_CurvePoint_radius_set(PointerRNA *ptr, float value)
114 {
115  const Curves *curves = rna_curves(ptr);
116  float *radii = (float *)CustomData_get_layer_named(
117  &curves->geometry.point_data, CD_PROP_FLOAT, "radius");
118  if (radii == NULL) {
119  return;
120  }
121  radii[rna_CurvePoint_index_get_const(ptr)] = value;
122 }
123 
124 static char *rna_CurvePoint_path(const PointerRNA *ptr)
125 {
126  return BLI_sprintfN("points[%d]", rna_CurvePoint_index_get_const(ptr));
127 }
128 
129 static int rna_CurveSlice_index_get_const(const PointerRNA *ptr)
130 {
131  Curves *curves = rna_curves(ptr);
132  return (int)((int *)ptr->data - curves->geometry.curve_offsets);
133 }
134 
135 static int rna_CurveSlice_index_get(PointerRNA *ptr)
136 {
137  return rna_CurveSlice_index_get_const(ptr);
138 }
139 
140 static char *rna_CurveSlice_path(const PointerRNA *ptr)
141 {
142  return BLI_sprintfN("curves[%d]", rna_CurveSlice_index_get_const(ptr));
143 }
144 
145 static int rna_CurveSlice_first_point_index_get(PointerRNA *ptr)
146 {
147  const int *offset_ptr = (int *)ptr->data;
148  return *offset_ptr;
149 }
150 
151 static int rna_CurveSlice_points_length_get(PointerRNA *ptr)
152 {
153  const int *offset_ptr = (int *)ptr->data;
154  const int offset = *offset_ptr;
155  return *(offset_ptr + 1) - offset;
156 }
157 
158 static void rna_CurveSlice_points_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
159 {
160  Curves *curves = rna_curves(ptr);
161  const int offset = rna_CurveSlice_first_point_index_get(ptr);
162  const int size = rna_CurveSlice_points_length_get(ptr);
164  &curves->geometry.point_data, CD_PROP_FLOAT3, "position");
165  float(*co)[3] = positions + offset;
166  rna_iterator_array_begin(iter, co, sizeof(float[3]), size, 0, NULL);
167 }
168 
169 static void rna_Curves_update_data(struct Main *UNUSED(bmain),
170  struct Scene *UNUSED(scene),
171  PointerRNA *ptr)
172 {
173  ID *id = ptr->owner_id;
174  /* Avoid updates for importers creating curves. */
175  if (id->us > 0) {
176  DEG_id_tag_update(id, 0);
178  }
179 }
180 
181 void rna_Curves_update_draw(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
182 {
183  ID *id = ptr->owner_id;
184  /* Avoid updates for importers creating curves. */
185  if (id->us > 0) {
187  }
188 }
189 
190 #else
191 
193 {
194  StructRNA *srna;
195  PropertyRNA *prop;
196 
197  srna = RNA_def_struct(brna, "CurvePoint", NULL);
198  RNA_def_struct_ui_text(srna, "Curve Point", "Curve curve control point");
199  RNA_def_struct_path_func(srna, "rna_CurvePoint_path");
200 
201  prop = RNA_def_property(srna, "position", PROP_FLOAT, PROP_TRANSLATION);
202  RNA_def_property_array(prop, 3);
204  prop, "rna_CurvePoint_location_get", "rna_CurvePoint_location_set", NULL);
205  RNA_def_property_ui_text(prop, "Position", "");
206  RNA_def_property_update(prop, 0, "rna_Curves_update_data");
207 
208  prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_DISTANCE);
210  prop, "rna_CurvePoint_radius_get", "rna_CurvePoint_radius_set", NULL);
211  RNA_def_property_ui_text(prop, "Radius", "");
212  RNA_def_property_update(prop, 0, "rna_Curves_update_data");
213 
214  prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
216  RNA_def_property_int_funcs(prop, "rna_CurvePoint_index_get", NULL, NULL);
217  RNA_def_property_ui_text(prop, "Index", "Index of this points");
218 }
219 
221 {
222  StructRNA *srna;
223  PropertyRNA *prop;
224 
225  srna = RNA_def_struct(brna, "CurveSlice", NULL);
226  RNA_def_struct_ui_text(srna, "Curve Slice", "A single curve from a curves data-block");
227  RNA_def_struct_path_func(srna, "rna_CurveSlice_path");
228 
229  prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
230  RNA_def_property_struct_type(prop, "CurvePoint");
231  RNA_def_property_ui_text(prop, "Points", "Control points of the curve");
233  "rna_CurveSlice_points_begin",
234  "rna_iterator_array_next",
235  "rna_iterator_array_end",
236  "rna_iterator_array_get",
237  "rna_CurveSlice_points_length_get",
238  NULL,
239  NULL,
240  NULL);
241 
242  prop = RNA_def_property(srna, "first_point_index", PROP_INT, PROP_UNSIGNED);
244  RNA_def_property_int_funcs(prop, "rna_CurveSlice_first_point_index_get", NULL, NULL);
246  prop, "First Point Index", "The index of this curve's first control point");
247 
248  prop = RNA_def_property(srna, "points_length", PROP_INT, PROP_UNSIGNED);
250  RNA_def_property_int_funcs(prop, "rna_CurveSlice_points_length_get", NULL, NULL);
251  RNA_def_property_ui_text(prop, "Number of Points", "Number of control points in the curve");
252 
253  prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
255  RNA_def_property_int_funcs(prop, "rna_CurveSlice_index_get", NULL, NULL);
256  RNA_def_property_ui_text(prop, "Index", "Index of this curve");
257 }
258 
259 static void rna_def_curves(BlenderRNA *brna)
260 {
261  StructRNA *srna;
262  PropertyRNA *prop;
263 
264  srna = RNA_def_struct(brna, "Curves", "ID");
265  RNA_def_struct_ui_text(srna, "Hair Curves", "Hair data-block for hair curves");
266  RNA_def_struct_ui_icon(srna, ICON_CURVES_DATA);
267 
268  /* Point and Curve RNA API helpers. */
269 
270  prop = RNA_def_property(srna, "curves", PROP_COLLECTION, PROP_NONE);
271  RNA_def_property_collection_sdna(prop, NULL, "geometry.curve_offsets", "geometry.curve_num");
272  RNA_def_property_struct_type(prop, "CurveSlice");
273  RNA_def_property_ui_text(prop, "Curves", "All curves in the data-block");
274 
275  prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
276  RNA_def_property_struct_type(prop, "CurvePoint");
278  "rna_Curves_position_data_begin",
279  "rna_iterator_array_next",
280  "rna_iterator_array_end",
281  "rna_iterator_array_get",
282  "rna_Curves_position_data_length",
283  NULL,
284  NULL,
285  NULL);
286  RNA_def_property_ui_text(prop, "Points", "Control points of all curves");
287 
288  /* Direct access to built-in attributes. */
289 
291  prop = RNA_def_property(srna, "position_data", PROP_COLLECTION, PROP_NONE);
293  "rna_Curves_position_data_begin",
294  "rna_iterator_array_next",
295  "rna_iterator_array_end",
296  "rna_iterator_array_get",
297  "rna_Curves_position_data_length",
298  NULL,
299  NULL,
300  NULL);
301  RNA_def_property_struct_type(prop, "FloatVectorAttributeValue");
302  RNA_def_property_update(prop, 0, "rna_Curves_update_data");
304 
305  prop = RNA_def_property(srna, "curve_offset_data", PROP_COLLECTION, PROP_NONE);
306  RNA_def_property_collection_sdna(prop, NULL, "geometry.curve_offsets", NULL);
307  RNA_def_property_struct_type(prop, "IntAttributeValue");
309  "rna_Curves_curve_offset_data_begin",
310  "rna_iterator_array_next",
311  "rna_iterator_array_end",
312  "rna_iterator_array_get",
313  "rna_Curves_curve_offset_data_length",
314  NULL,
315  NULL,
316  NULL);
317  RNA_def_property_update(prop, 0, "rna_Curves_update_data");
318 
319  /* materials */
320  prop = RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);
321  RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
322  RNA_def_property_struct_type(prop, "Material");
323  RNA_def_property_ui_text(prop, "Materials", "");
324  RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */
326  prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "rna_IDMaterials_assign_int");
327 
328  prop = RNA_def_property(srna, "surface", PROP_POINTER, PROP_NONE);
329  RNA_def_property_struct_type(prop, "Object");
331  RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Mesh_object_poll");
332  RNA_def_property_ui_text(prop, "Surface", "Mesh object that the curves can be attached to");
334 
335  prop = RNA_def_property(srna, "surface_uv_map", PROP_STRING, PROP_NONE);
336  RNA_def_property_string_sdna(prop, NULL, "surface_uv_map");
338  "Surface UV Map",
339  "The name of the attribute on the surface mesh used to define the "
340  "attachment of each curve");
341  RNA_def_property_update(prop, 0, "rna_Curves_update_draw");
342 
343  /* Symmetry. */
344  prop = RNA_def_property(srna, "use_mirror_x", PROP_BOOLEAN, PROP_NONE);
346  RNA_def_property_ui_text(prop, "X", "Enable symmetry in the X axis");
347  RNA_def_property_update(prop, 0, "rna_Curves_update_draw");
348 
349  prop = RNA_def_property(srna, "use_mirror_y", PROP_BOOLEAN, PROP_NONE);
351  RNA_def_property_ui_text(prop, "Y", "Enable symmetry in the Y axis");
352  RNA_def_property_update(prop, 0, "rna_Curves_update_draw");
353 
354  prop = RNA_def_property(srna, "use_mirror_z", PROP_BOOLEAN, PROP_NONE);
356  RNA_def_property_ui_text(prop, "Z", "Enable symmetry in the Z axis");
357  RNA_def_property_update(prop, 0, "rna_Curves_update_draw");
358 
359  prop = RNA_def_property(srna, "selection_domain", PROP_ENUM, PROP_NONE);
361  RNA_def_property_ui_text(prop, "Selection Domain", "");
363  RNA_def_property_update(prop, 0, "rna_Curves_update_data");
364 
365  prop = RNA_def_property(srna, "use_sculpt_selection", PROP_BOOLEAN, PROP_NONE);
367  RNA_def_property_ui_text(prop, "Use Sculpt Selection", "");
369  RNA_def_property_update(prop, 0, "rna_Curves_update_draw");
370 
371  /* attributes */
373 
374  /* common */
376 }
377 
379 {
380  rna_def_curves_point(brna);
381  rna_def_curves_curve(brna);
382  rna_def_curves(brna);
383 }
384 
385 #endif
typedef float(TangentPoint)[2]
Generic geometry attributes built on CustomData.
Low-level operations for curves that cannot be defined in the C++ header yet.
void * CustomData_get_layer_named(const struct CustomData *data, int type, const char *name)
MINLINE void copy_v3_v3(float r[3], const float a[3])
size_t size_t char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
#define UNUSED(x)
void DEG_id_tag_update(struct ID *id, int flag)
@ CURVE_TYPE_BEZIER
@ CURVE_TYPE_NURBS
@ CURVE_TYPE_POLY
@ CURVE_TYPE_CATMULL_ROM
@ CURVES_SYMMETRY_Y
@ CURVES_SYMMETRY_Z
@ CURVES_SYMMETRY_X
@ CV_SCULPT_SELECTION_ENABLED
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
@ PROP_FLOAT
Definition: RNA_types.h:61
@ PROP_BOOLEAN
Definition: RNA_types.h:59
@ PROP_ENUM
Definition: RNA_types.h:63
@ PROP_INT
Definition: RNA_types.h:60
@ PROP_STRING
Definition: RNA_types.h:62
@ PROP_POINTER
Definition: RNA_types.h:64
@ PROP_COLLECTION
Definition: RNA_types.h:65
@ PROP_ANIMATABLE
Definition: RNA_types.h:202
@ PROP_EDITABLE
Definition: RNA_types.h:189
@ PROP_DISTANCE
Definition: RNA_types.h:149
@ PROP_NONE
Definition: RNA_types.h:126
@ PROP_TRANSLATION
Definition: RNA_types.h:154
@ PROP_UNSIGNED
Definition: RNA_types.h:142
#define NC_GEOM
Definition: WM_types.h:343
#define ND_DRAW
Definition: WM_types.h:410
#define ND_DATA
Definition: WM_types.h:456
#define NC_OBJECT
Definition: WM_types.h:329
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
Scene scene
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
MutableSpan< float3 > positions
MutableSpan< float > radii
void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, bool free_ptr, IteratorSkipFunc skip)
Definition: rna_access.c:4781
void rna_def_animdata_common(StructRNA *srna)
const EnumPropertyItem rna_enum_attribute_curves_domain_items[]
void rna_def_attributes_common(StructRNA *srna)
static void rna_def_curves_point(BlenderRNA *brna)
Definition: rna_curves.c:192
void RNA_def_curves(BlenderRNA *brna)
Definition: rna_curves.c:378
static void rna_def_curves(BlenderRNA *brna)
Definition: rna_curves.c:259
const EnumPropertyItem rna_enum_curves_types[]
Definition: rna_curves.c:21
static void rna_def_curves_curve(BlenderRNA *brna)
Definition: rna_curves.c:220
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
Definition: rna_define.c:1193
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
Definition: rna_define.c:2236
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3126
void RNA_define_verify_sdna(bool verify)
Definition: rna_define.c:737
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1645
void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2695
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
Definition: rna_define.c:3474
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *assignint)
Definition: rna_define.c:3420
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1237
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1872
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1539
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1772
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
Definition: rna_define.c:2769
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2900
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1257
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1495
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
Definition: rna_define.c:3385
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1028
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3028
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
Definition: rna_define.c:1245
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
Definition: DNA_ID.h:368
int us
Definition: DNA_ID.h:388
Definition: BKE_main.h:121
void * data
Definition: RNA_types.h:38
struct ID * owner_id
Definition: RNA_types.h:36
void WM_main_add_notifier(unsigned int type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3480