Blender  V2.93
rna_attribute.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 
21 #include <stdlib.h>
22 
23 #include "RNA_access.h"
24 #include "RNA_define.h"
25 #include "RNA_enum_types.h"
26 
27 #include "rna_internal.h"
28 
29 #include "DNA_customdata_types.h"
30 #include "DNA_hair_types.h"
31 #include "DNA_mesh_types.h"
32 #include "DNA_meshdata_types.h"
33 #include "DNA_pointcloud_types.h"
34 
35 #include "BKE_attribute.h"
36 #include "BKE_customdata.h"
37 
38 #include "WM_types.h"
39 
41  {CD_PROP_FLOAT, "FLOAT", 0, "Float", "Floating-point value"},
42  {CD_PROP_INT32, "INT", 0, "Integer", "32-bit integer"},
43  {CD_PROP_FLOAT3, "FLOAT_VECTOR", 0, "Vector", "3D vector with floating-point values"},
44  {CD_PROP_COLOR, "FLOAT_COLOR", 0, "Color", "RGBA color with floating-point precisions"},
45  {CD_MLOOPCOL, "BYTE_COLOR", 0, "Byte Color", "RGBA color with 8-bit precision"},
46  {CD_PROP_STRING, "STRING", 0, "String", "Text string"},
47  {CD_PROP_BOOL, "BOOLEAN", 0, "Boolean", "True or false"},
48  {CD_PROP_FLOAT2, "FLOAT2", 0, "2D Vector", "2D vector with floating-point values"},
49  {0, NULL, 0, NULL, NULL},
50 };
51 
53  /* Not implement yet */
54  // {ATTR_DOMAIN_GEOMETRY, "GEOMETRY", 0, "Geometry", "Attribute on (whole) geometry"},
55  {ATTR_DOMAIN_POINT, "POINT", 0, "Point", "Attribute on point"},
56  {ATTR_DOMAIN_EDGE, "EDGE", 0, "Edge", "Attribute on mesh edge"},
57  {ATTR_DOMAIN_FACE, "FACE", 0, "Face", "Attribute on mesh faces"},
58  {ATTR_DOMAIN_CORNER, "CORNER", 0, "Face Corner", "Attribute on mesh face corner"},
59  /* Not implement yet */
60  // {ATTR_DOMAIN_GRIDS, "GRIDS", 0, "Grids", "Attribute on mesh multires grids"},
61  {ATTR_DOMAIN_CURVE, "CURVE", 0, "Curve", "Attribute on hair curve"},
62  {0, NULL, 0, NULL, NULL},
63 };
64 
66  {ATTR_DOMAIN_AUTO, "AUTO", 0, "Auto", ""},
67  {ATTR_DOMAIN_POINT, "POINT", 0, "Point", "Attribute on point"},
68  {ATTR_DOMAIN_EDGE, "EDGE", 0, "Edge", "Attribute on mesh edge"},
69  {ATTR_DOMAIN_FACE, "FACE", 0, "Face", "Attribute on mesh faces"},
70  {ATTR_DOMAIN_CORNER, "CORNER", 0, "Face Corner", "Attribute on mesh face corner"},
71  {0, NULL, 0, NULL, NULL},
72 };
73 
74 #ifdef RNA_RUNTIME
75 
76 # include "BLI_math.h"
77 
78 # include "DEG_depsgraph.h"
79 
80 # include "BLT_translation.h"
81 
82 # include "WM_api.h"
83 
84 /* Attribute */
85 
86 static char *rna_Attribute_path(PointerRNA *ptr)
87 {
88  CustomDataLayer *layer = ptr->data;
89  return BLI_sprintfN("attributes['%s']", layer->name);
90 }
91 
92 static StructRNA *srna_by_custom_data_layer_type(const CustomDataType type)
93 {
94  switch (type) {
95  case CD_PROP_FLOAT:
96  return &RNA_FloatAttribute;
97  case CD_PROP_INT32:
98  return &RNA_IntAttribute;
99  case CD_PROP_FLOAT3:
100  return &RNA_FloatVectorAttribute;
101  case CD_PROP_COLOR:
102  return &RNA_FloatColorAttribute;
103  case CD_MLOOPCOL:
104  return &RNA_ByteColorAttribute;
105  case CD_PROP_STRING:
106  return &RNA_StringAttribute;
107  case CD_PROP_BOOL:
108  return &RNA_BoolAttribute;
109  case CD_PROP_FLOAT2:
110  return &RNA_Float2Attribute;
111  default:
112  return NULL;
113  }
114 }
115 
116 static StructRNA *rna_Attribute_refine(PointerRNA *ptr)
117 {
118  CustomDataLayer *layer = ptr->data;
119  return srna_by_custom_data_layer_type(layer->type);
120 }
121 
122 static void rna_Attribute_name_set(PointerRNA *ptr, const char *value)
123 {
125 }
126 
127 static int rna_Attribute_name_editable(PointerRNA *ptr, const char **r_info)
128 {
129  CustomDataLayer *layer = ptr->data;
130  if (BKE_id_attribute_required(ptr->owner_id, layer)) {
131  *r_info = N_("Can't modify name of required geometry attribute");
132  return false;
133  }
134 
135  return true;
136 }
137 
138 static int rna_Attribute_type_get(PointerRNA *ptr)
139 {
140  CustomDataLayer *layer = ptr->data;
141  return layer->type;
142 }
143 
144 const EnumPropertyItem *rna_enum_attribute_domain_itemf(ID *id, bool *r_free)
145 {
146  EnumPropertyItem *item = NULL;
147  const EnumPropertyItem *domain_item = NULL;
148  const ID_Type id_type = GS(id->name);
149  int totitem = 0, a;
150 
152  domain_item = &rna_enum_attribute_domain_items[a];
153 
154  if (id_type == ID_PT && !ELEM(domain_item->value, ATTR_DOMAIN_POINT)) {
155  continue;
156  }
157  if (id_type == ID_HA && !ELEM(domain_item->value, ATTR_DOMAIN_POINT, ATTR_DOMAIN_CURVE)) {
158  continue;
159  }
160  if (id_type == ID_ME && ELEM(domain_item->value, ATTR_DOMAIN_CURVE)) {
161  continue;
162  }
163 
164  RNA_enum_item_add(&item, &totitem, domain_item);
165  }
166  RNA_enum_item_end(&item, &totitem);
167 
168  *r_free = true;
169  return item;
170 }
171 
172 static const EnumPropertyItem *rna_Attribute_domain_itemf(bContext *UNUSED(C),
173  PointerRNA *ptr,
174  PropertyRNA *UNUSED(prop),
175  bool *r_free)
176 {
178 }
179 
180 static int rna_Attribute_domain_get(PointerRNA *ptr)
181 {
183 }
184 
185 static void rna_Attribute_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
186 {
187  ID *id = ptr->owner_id;
189 
190  int length = BKE_id_attribute_data_length(id, layer);
191  size_t struct_size;
192 
193  switch (layer->type) {
194  case CD_PROP_FLOAT:
195  struct_size = sizeof(MFloatProperty);
196  break;
197  case CD_PROP_INT32:
198  struct_size = sizeof(MIntProperty);
199  break;
200  case CD_PROP_FLOAT3:
201  struct_size = sizeof(float[3]);
202  break;
203  case CD_PROP_COLOR:
204  struct_size = sizeof(MPropCol);
205  break;
206  case CD_MLOOPCOL:
207  struct_size = sizeof(MLoopCol);
208  break;
209  case CD_PROP_STRING:
210  struct_size = sizeof(MStringProperty);
211  break;
212  case CD_PROP_BOOL:
213  struct_size = sizeof(MBoolProperty);
214  break;
215  case CD_PROP_FLOAT2:
216  struct_size = sizeof(float[2]);
217  break;
218  default:
219  struct_size = 0;
220  length = 0;
221  break;
222  }
223 
224  rna_iterator_array_begin(iter, layer->data, struct_size, length, 0, NULL);
225 }
226 
227 static int rna_Attribute_data_length(PointerRNA *ptr)
228 {
229  ID *id = ptr->owner_id;
231  return BKE_id_attribute_data_length(id, layer);
232 }
233 
234 static void rna_Attribute_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
235 {
236  ID *id = ptr->owner_id;
237 
238  /* cheating way for importers to avoid slow updates */
239  if (id->us > 0) {
240  DEG_id_tag_update(id, 0);
242  }
243 }
244 
245 /* Color Attribute */
246 
247 static void rna_ByteColorAttributeValue_color_get(PointerRNA *ptr, float *values)
248 {
249  MLoopCol *mlcol = (MLoopCol *)ptr->data;
250  srgb_to_linearrgb_uchar4(values, &mlcol->r);
251 }
252 
253 static void rna_ByteColorAttributeValue_color_set(PointerRNA *ptr, const float *values)
254 {
255  MLoopCol *mlcol = (MLoopCol *)ptr->data;
256  linearrgb_to_srgb_uchar4(&mlcol->r, values);
257 }
258 
259 /* Attribute Group */
260 
261 static PointerRNA rna_AttributeGroup_new(
262  ID *id, ReportList *reports, const char *name, const int type, const int domain)
263 {
264  CustomDataLayer *layer = BKE_id_attribute_new(id, name, type, domain, reports);
267 
268  PointerRNA ptr;
269  RNA_pointer_create(id, &RNA_Attribute, layer, &ptr);
270  return ptr;
271 }
272 
273 static void rna_AttributeGroup_remove(ID *id, ReportList *reports, PointerRNA *attribute_ptr)
274 {
275  CustomDataLayer *layer = (CustomDataLayer *)attribute_ptr->data;
276  BKE_id_attribute_remove(id, layer, reports);
277  RNA_POINTER_INVALIDATE(attribute_ptr);
278 
281 }
282 
283 static int rna_Attributes_layer_skip(CollectionPropertyIterator *UNUSED(iter), void *data)
284 {
286  return !(CD_TYPE_AS_MASK(layer->type) & CD_MASK_PROP_ALL);
287 }
288 
289 /* Attributes are spread over multiple domains in separate CustomData, we use repeated
290  * array iterators to loop over all. */
291 static void rna_AttributeGroup_next_domain(ID *id,
293  int(skip)(CollectionPropertyIterator *iter, void *data))
294 {
295  do {
296  CustomDataLayer *prev_layers = (CustomDataLayer *)iter->internal.array.endptr -
297  iter->internal.array.length;
298  CustomData *customdata = BKE_id_attributes_iterator_next_domain(id, prev_layers);
299  if (customdata == NULL) {
300  return;
301  }
303  iter, customdata->layers, sizeof(CustomDataLayer), customdata->totlayer, false, skip);
304  } while (!iter->valid);
305 }
306 
308 {
309  memset(&iter->internal.array, 0, sizeof(iter->internal.array));
310  rna_AttributeGroup_next_domain(ptr->owner_id, iter, rna_Attributes_layer_skip);
311 }
312 
314 {
316 
317  if (!iter->valid) {
318  ID *id = iter->parent.owner_id;
319  rna_AttributeGroup_next_domain(id, iter, rna_Attributes_layer_skip);
320  }
321 }
322 
324 {
325  /* refine to the proper type */
327  StructRNA *type = srna_by_custom_data_layer_type(layer->type);
328  if (type == NULL) {
329  return PointerRNA_NULL;
330  }
331  return rna_pointer_inherit_refine(&iter->parent, type, layer);
332 }
333 
335 {
337 }
338 
339 static int rna_AttributeGroup_active_index_get(PointerRNA *ptr)
340 {
342 }
343 
344 static PointerRNA rna_AttributeGroup_active_get(PointerRNA *ptr)
345 {
346  ID *id = ptr->owner_id;
348 
349  PointerRNA attribute_ptr;
350  RNA_pointer_create(id, &RNA_Attribute, layer, &attribute_ptr);
351  return attribute_ptr;
352 }
353 
354 static void rna_AttributeGroup_active_set(PointerRNA *ptr,
355  PointerRNA attribute_ptr,
356  ReportList *UNUSED(reports))
357 {
358  ID *id = ptr->owner_id;
359  CustomDataLayer *layer = attribute_ptr.data;
360  BKE_id_attributes_active_set(id, layer);
361 }
362 
363 static void rna_AttributeGroup_active_index_set(PointerRNA *ptr, int value)
364 {
366 }
367 
368 static void rna_AttributeGroup_active_index_range(
369  PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
370 {
371  *min = 0;
373 
374  *softmin = *min;
375  *softmax = *max;
376 }
377 
378 static void rna_AttributeGroup_update_active(Main *bmain, Scene *scene, PointerRNA *ptr)
379 {
380  rna_Attribute_update_data(bmain, scene, ptr);
381 }
382 
383 #else
384 
386 {
387  StructRNA *srna;
388  PropertyRNA *prop;
389 
390  srna = RNA_def_struct(brna, "FloatAttribute", "Attribute");
391  RNA_def_struct_sdna(srna, "CustomDataLayer");
392  RNA_def_struct_ui_text(srna, "Float Attribute", "Geometry attribute with floating-point values");
393 
394  prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
395  RNA_def_property_struct_type(prop, "FloatAttributeValue");
397  "rna_Attribute_data_begin",
398  "rna_iterator_array_next",
399  "rna_iterator_array_end",
400  "rna_iterator_array_get",
401  "rna_Attribute_data_length",
402  NULL,
403  NULL,
404  NULL);
405 
406  srna = RNA_def_struct(brna, "FloatAttributeValue", NULL);
407  RNA_def_struct_sdna(srna, "MFloatProperty");
409  srna, "Float Attribute Value", "Floating-point value in geometry attribute");
410  prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
411  RNA_def_property_float_sdna(prop, NULL, "f");
412  RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
413 }
414 
416 {
417  StructRNA *srna;
418  PropertyRNA *prop;
419 
420  /* Float Vector Attribute */
421  srna = RNA_def_struct(brna, "FloatVectorAttribute", "Attribute");
422  RNA_def_struct_sdna(srna, "CustomDataLayer");
424  srna, "Float Vector Attribute", "Vector geometry attribute, with floating-point precision");
425 
426  prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
427  RNA_def_property_struct_type(prop, "FloatVectorAttributeValue");
429  "rna_Attribute_data_begin",
430  "rna_iterator_array_next",
431  "rna_iterator_array_end",
432  "rna_iterator_array_get",
433  "rna_Attribute_data_length",
434  NULL,
435  NULL,
436  NULL);
437 
438  /* Float Vector Attribute Value */
439  srna = RNA_def_struct(brna, "FloatVectorAttributeValue", NULL);
440  RNA_def_struct_sdna(srna, "vec3f");
442  srna, "Float Vector Attribute Value", "Vector value in geometry attribute");
443 
444  prop = RNA_def_property(srna, "vector", PROP_FLOAT, PROP_DIRECTION);
445  RNA_def_property_ui_text(prop, "Vector", "3D vector");
446  RNA_def_property_float_sdna(prop, NULL, "x");
447  RNA_def_property_array(prop, 3);
448  RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
449 }
450 
452 {
453  StructRNA *srna;
454  PropertyRNA *prop;
455 
456  /* Float Color Attribute */
457  srna = RNA_def_struct(brna, "FloatColorAttribute", "Attribute");
458  RNA_def_struct_sdna(srna, "CustomDataLayer");
460  srna, "Float Color Attribute", "Color geometry attribute, with floating-point precision");
461 
462  prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
463  RNA_def_property_struct_type(prop, "FloatColorAttributeValue");
465  "rna_Attribute_data_begin",
466  "rna_iterator_array_next",
467  "rna_iterator_array_end",
468  "rna_iterator_array_get",
469  "rna_Attribute_data_length",
470  NULL,
471  NULL,
472  NULL);
473 
474  /* Float Color Attribute Value */
475  srna = RNA_def_struct(brna, "FloatColorAttributeValue", NULL);
476  RNA_def_struct_sdna(srna, "MPropCol");
477  RNA_def_struct_ui_text(srna, "Float Color Attribute Value", "Color value in geometry attribute");
478 
479  prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
480  RNA_def_property_ui_text(prop, "Color", "RGBA color in scene linear color space");
481  RNA_def_property_float_sdna(prop, NULL, "color");
482  RNA_def_property_array(prop, 4);
483  RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
484 }
485 
487 {
488  StructRNA *srna;
489  PropertyRNA *prop;
490 
491  /* Byte Color Attribute */
492  srna = RNA_def_struct(brna, "ByteColorAttribute", "Attribute");
493  RNA_def_struct_sdna(srna, "CustomDataLayer");
495  srna, "Byte Color Attribute", "Color geometry attribute, with 8-bit precision");
496 
497  prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
498  RNA_def_property_struct_type(prop, "ByteColorAttributeValue");
500  "rna_Attribute_data_begin",
501  "rna_iterator_array_next",
502  "rna_iterator_array_end",
503  "rna_iterator_array_get",
504  "rna_Attribute_data_length",
505  NULL,
506  NULL,
507  NULL);
508 
509  /* Byte Color Attribute Value */
510  srna = RNA_def_struct(brna, "ByteColorAttributeValue", NULL);
511  RNA_def_struct_sdna(srna, "MLoopCol");
512  RNA_def_struct_ui_text(srna, "Byte Color Attribute Value", "Color value in geometry attribute");
513 
514  prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
515  RNA_def_property_array(prop, 4);
516  RNA_def_property_range(prop, 0.0f, 1.0f);
518  "rna_ByteColorAttributeValue_color_get",
519  "rna_ByteColorAttributeValue_color_set",
520  NULL);
521  RNA_def_property_ui_text(prop, "Color", "RGBA color in scene linear color space");
522  RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
523 }
524 
526 {
527  StructRNA *srna;
528  PropertyRNA *prop;
529 
530  srna = RNA_def_struct(brna, "IntAttribute", "Attribute");
531  RNA_def_struct_sdna(srna, "CustomDataLayer");
532  RNA_def_struct_ui_text(srna, "Int Attribute", "Integer geometry attribute");
533 
534  prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
535  RNA_def_property_struct_type(prop, "IntAttributeValue");
537  "rna_Attribute_data_begin",
538  "rna_iterator_array_next",
539  "rna_iterator_array_end",
540  "rna_iterator_array_get",
541  "rna_Attribute_data_length",
542  NULL,
543  NULL,
544  NULL);
545 
546  srna = RNA_def_struct(brna, "IntAttributeValue", NULL);
547  RNA_def_struct_sdna(srna, "MIntProperty");
548  RNA_def_struct_ui_text(srna, "Integer Attribute Value", "Integer value in geometry attribute");
549  prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
550  RNA_def_property_int_sdna(prop, NULL, "i");
551  RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
552 }
553 
555 {
556  StructRNA *srna;
557  PropertyRNA *prop;
558 
559  srna = RNA_def_struct(brna, "StringAttribute", "Attribute");
560  RNA_def_struct_sdna(srna, "CustomDataLayer");
561  RNA_def_struct_ui_text(srna, "String Attribute", "String geometry attribute");
562 
563  prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
564  RNA_def_property_struct_type(prop, "StringAttributeValue");
566  "rna_Attribute_data_begin",
567  "rna_iterator_array_next",
568  "rna_iterator_array_end",
569  "rna_iterator_array_get",
570  "rna_Attribute_data_length",
571  NULL,
572  NULL,
573  NULL);
574 
575  srna = RNA_def_struct(brna, "StringAttributeValue", NULL);
576  RNA_def_struct_sdna(srna, "MStringProperty");
577  RNA_def_struct_ui_text(srna, "String Attribute Value", "String value in geometry attribute");
578  prop = RNA_def_property(srna, "value", PROP_STRING, PROP_NONE);
580  RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
581 }
582 
584 {
585  StructRNA *srna;
586  PropertyRNA *prop;
587 
588  srna = RNA_def_struct(brna, "BoolAttribute", "Attribute");
589  RNA_def_struct_sdna(srna, "CustomDataLayer");
590  RNA_def_struct_ui_text(srna, "Bool Attribute", "Bool geometry attribute");
591 
592  prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
593  RNA_def_property_struct_type(prop, "BoolAttributeValue");
595  "rna_Attribute_data_begin",
596  "rna_iterator_array_next",
597  "rna_iterator_array_end",
598  "rna_iterator_array_get",
599  "rna_Attribute_data_length",
600  NULL,
601  NULL,
602  NULL);
603 
604  srna = RNA_def_struct(brna, "BoolAttributeValue", NULL);
605  RNA_def_struct_sdna(srna, "MBoolProperty");
606  RNA_def_struct_ui_text(srna, "Bool Attribute Value", "Bool value in geometry attribute");
607  prop = RNA_def_property(srna, "value", PROP_BOOLEAN, PROP_NONE);
608  RNA_def_property_boolean_sdna(prop, NULL, "b", 0x01);
609 }
610 
612 {
613  StructRNA *srna;
614  PropertyRNA *prop;
615 
616  /* Float2 Attribute */
617  srna = RNA_def_struct(brna, "Float2Attribute", "Attribute");
618  RNA_def_struct_sdna(srna, "CustomDataLayer");
620  srna, "Float2 Attribute", "2D vector geometry attribute, with floating-point precision");
621 
622  prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
623  RNA_def_property_struct_type(prop, "Float2AttributeValue");
625  "rna_Attribute_data_begin",
626  "rna_iterator_array_next",
627  "rna_iterator_array_end",
628  "rna_iterator_array_get",
629  "rna_Attribute_data_length",
630  NULL,
631  NULL,
632  NULL);
633 
634  /* Float2 Attribute Value */
635  srna = RNA_def_struct(brna, "Float2AttributeValue", NULL);
636  RNA_def_struct_sdna(srna, "vec2f");
637  RNA_def_struct_ui_text(srna, "Float2 Attribute Value", "2D Vector value in geometry attribute");
638 
639  prop = RNA_def_property(srna, "vector", PROP_FLOAT, PROP_DIRECTION);
640  RNA_def_property_ui_text(prop, "Vector", "2D vector");
641  RNA_def_property_float_sdna(prop, NULL, "x");
642  RNA_def_property_array(prop, 2);
643  RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
644 }
645 
646 static void rna_def_attribute(BlenderRNA *brna)
647 {
648  PropertyRNA *prop;
649  StructRNA *srna;
650 
651  srna = RNA_def_struct(brna, "Attribute", NULL);
652  RNA_def_struct_sdna(srna, "CustomDataLayer");
653  RNA_def_struct_ui_text(srna, "Attribute", "Geometry attribute");
654  RNA_def_struct_path_func(srna, "rna_Attribute_path");
655  RNA_def_struct_refine_func(srna, "rna_Attribute_refine");
656 
657  prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
658  RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Attribute_name_set");
659  RNA_def_property_editable_func(prop, "rna_Attribute_name_editable");
660  RNA_def_property_ui_text(prop, "Name", "Name of the Attribute");
661  RNA_def_struct_name_property(srna, prop);
662 
663  prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE);
664  RNA_def_property_enum_sdna(prop, NULL, "type");
666  RNA_def_property_enum_funcs(prop, "rna_Attribute_type_get", NULL, NULL);
667  RNA_def_property_ui_text(prop, "Data Type", "Type of data stored in attribute");
669 
670  prop = RNA_def_property(srna, "domain", PROP_ENUM, PROP_NONE);
673  prop, "rna_Attribute_domain_get", NULL, "rna_Attribute_domain_itemf");
674  RNA_def_property_ui_text(prop, "Domain", "Domain of the Attribute");
676 
677  /* types */
682  rna_def_attribute_int(brna);
686 }
687 
688 /* Mesh/PointCloud/Hair.attributes */
690 {
691  StructRNA *srna;
692  PropertyRNA *prop;
693  FunctionRNA *func;
694  PropertyRNA *parm;
695 
696  srna = RNA_def_struct(brna, "AttributeGroup", NULL);
697  RNA_def_struct_ui_text(srna, "Attribute Group", "Group of geometry attributes");
698  RNA_def_struct_sdna(srna, "ID");
699 
700  /* API */
701  func = RNA_def_function(srna, "new", "rna_AttributeGroup_new");
702  RNA_def_function_ui_description(func, "Add an attribute");
704  parm = RNA_def_string(func, "name", "Attribute", 0, "", "Attribute name");
706  parm = RNA_def_enum(
707  func, "type", rna_enum_attribute_type_items, CD_PROP_FLOAT, "Type", "Attribute type");
709  parm = RNA_def_enum(func,
710  "domain",
713  "Domain",
714  "Type of element that attribute is stored on");
716  parm = RNA_def_pointer(func, "attribute", "Attribute", "", "New geometry attribute");
718  RNA_def_function_return(func, parm);
719 
720  func = RNA_def_function(srna, "remove", "rna_AttributeGroup_remove");
721  RNA_def_function_ui_description(func, "Remove an attribute");
723  parm = RNA_def_pointer(func, "attribute", "Attribute", "", "Geometry Attribute");
726 
727  /* Active */
728  prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
729  RNA_def_property_struct_type(prop, "Attribute");
731  prop, "rna_AttributeGroup_active_get", "rna_AttributeGroup_active_set", NULL, NULL);
733  RNA_def_property_ui_text(prop, "Active Attribute", "Active attribute");
734  RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active");
735 
736  prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
739  "rna_AttributeGroup_active_index_get",
740  "rna_AttributeGroup_active_index_set",
741  "rna_AttributeGroup_active_index_range");
742  RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active");
743 }
744 
746 {
747  PropertyRNA *prop;
748 
749  /* Attributes */
750  prop = RNA_def_property(srna, "attributes", PROP_COLLECTION, PROP_NONE);
752  "rna_AttributeGroup_iterator_begin",
753  "rna_AttributeGroup_iterator_next",
754  "rna_iterator_array_end",
755  "rna_AttributeGroup_iterator_get",
756  "rna_AttributeGroup_length",
757  NULL,
758  NULL,
759  NULL);
760  RNA_def_property_struct_type(prop, "Attribute");
761  RNA_def_property_ui_text(prop, "Attributes", "Geometry attributes");
762  RNA_def_property_srna(prop, "AttributeGroup");
763 }
764 
766 {
767  rna_def_attribute(brna);
769 }
770 #endif
Generic geometry attributes built on CustomData.
int BKE_id_attribute_data_length(struct ID *id, struct CustomDataLayer *layer)
Definition: attribute.c:209
bool BKE_id_attribute_remove(struct ID *id, struct CustomDataLayer *layer, struct ReportList *reports)
Definition: attribute.c:154
struct CustomDataLayer * BKE_id_attributes_active_get(struct ID *id)
Definition: attribute.c:239
int * BKE_id_attributes_active_index_p(struct ID *id)
Definition: attribute.c:293
void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer)
Definition: attribute.c:269
int BKE_id_attributes_length(struct ID *id, const CustomDataMask mask)
Definition: attribute.c:176
bool BKE_id_attribute_rename(struct ID *id, struct CustomDataLayer *layer, const char *new_name, struct ReportList *reports)
Definition: attribute.c:116
struct CustomDataLayer * BKE_id_attribute_new(struct ID *id, const char *name, const int type, const AttributeDomain domain, struct ReportList *reports)
Definition: attribute.c:137
@ ATTR_DOMAIN_CURVE
Definition: BKE_attribute.h:47
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:43
@ ATTR_DOMAIN_FACE
Definition: BKE_attribute.h:46
@ ATTR_DOMAIN_CORNER
Definition: BKE_attribute.h:45
@ ATTR_DOMAIN_AUTO
Definition: BKE_attribute.h:42
@ ATTR_DOMAIN_EDGE
Definition: BKE_attribute.h:44
CustomData * BKE_id_attributes_iterator_next_domain(struct ID *id, struct CustomDataLayer *layers)
Definition: attribute.c:310
AttributeDomain BKE_id_attribute_domain(struct ID *id, struct CustomDataLayer *layer)
Definition: attribute.c:193
bool BKE_id_attribute_required(struct ID *id, struct CustomDataLayer *layer)
Definition: attribute.c:225
CustomData interface, see also DNA_customdata_types.h.
#define CD_TYPE_AS_MASK(_type)
MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[4])
MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4])
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)
#define ELEM(...)
#define N_(msgid)
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
ID_Type
Definition: DNA_ID_enums.h:56
@ ID_HA
Definition: DNA_ID_enums.h:93
@ ID_ME
Definition: DNA_ID_enums.h:60
@ ID_PT
Definition: DNA_ID_enums.h:94
#define CD_MASK_PROP_ALL
CustomDataType
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ CD_PROP_COLOR
@ CD_PROP_INT32
@ CD_PROP_FLOAT2
@ CD_PROP_BOOL
@ CD_MLOOPCOL
@ CD_PROP_STRING
struct MBoolProperty MBoolProperty
struct MStringProperty MStringProperty
struct MIntProperty MIntProperty
struct MLoopCol MLoopCol
struct MFloatProperty MFloatProperty
struct MPropCol MPropCol
_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 type
StructRNA RNA_Attribute
StructRNA RNA_Float2Attribute
StructRNA RNA_StringAttribute
#define RNA_POINTER_INVALIDATE(ptr)
Definition: RNA_access.h:1425
StructRNA RNA_ByteColorAttribute
StructRNA RNA_FloatAttribute
StructRNA RNA_BoolAttribute
StructRNA RNA_IntAttribute
StructRNA RNA_FloatColorAttribute
const EnumPropertyItem * rna_enum_attribute_domain_itemf(struct ID *id, bool *r_free)
@ PARM_RNAPTR
Definition: RNA_types.h:339
@ PARM_REQUIRED
Definition: RNA_types.h:337
@ FUNC_USE_REPORTS
Definition: RNA_types.h:578
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_INT
Definition: RNA_types.h:74
@ PROP_STRING
Definition: RNA_types.h:76
@ PROP_POINTER
Definition: RNA_types.h:78
@ PROP_COLLECTION
Definition: RNA_types.h:79
@ PROP_THICK_WRAP
Definition: RNA_types.h:270
@ PROP_ANIMATABLE
Definition: RNA_types.h:188
@ PROP_NEVER_UNLINK
Definition: RNA_types.h:232
@ PROP_EDITABLE
Definition: RNA_types.h:175
@ PROP_NEVER_NULL
Definition: RNA_types.h:225
@ PROP_DIRECTION
Definition: RNA_types.h:141
@ PROP_COLOR
Definition: RNA_types.h:139
@ PROP_NONE
Definition: RNA_types.h:113
#define C
Definition: RandGen.cpp:39
#define NC_GEOM
Definition: WM_types.h:294
#define ND_DATA
Definition: WM_types.h:408
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
Definition: btQuaternion.h:895
Scene scene
#define GS(x)
Definition: iris.c:241
static unsigned a[3]
Definition: RandGen.cpp:92
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
const PointerRNA PointerRNA_NULL
Definition: rna_access.c:71
void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, bool free_ptr, IteratorSkipFunc skip)
Definition: rna_access.c:4875
void * rna_iterator_array_get(CollectionPropertyIterator *iter)
Definition: rna_access.c:4923
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:196
void rna_iterator_array_next(CollectionPropertyIterator *iter)
Definition: rna_access.c:4907
static void rna_def_attribute_bool(BlenderRNA *brna)
static void rna_def_attribute(BlenderRNA *brna)
const EnumPropertyItem rna_enum_attribute_domain_with_auto_items[]
Definition: rna_attribute.c:65
void rna_def_attributes_common(StructRNA *srna)
static void rna_def_attribute_float_vector(BlenderRNA *brna)
static void rna_def_attribute_float_color(BlenderRNA *brna)
static void rna_def_attribute_float(BlenderRNA *brna)
static void rna_def_attribute_group(BlenderRNA *brna)
const EnumPropertyItem rna_enum_attribute_domain_items[]
Definition: rna_attribute.c:52
static void rna_def_attribute_int(BlenderRNA *brna)
static void rna_def_attribute_byte_color(BlenderRNA *brna)
void RNA_def_attribute(BlenderRNA *brna)
static void rna_def_attribute_float2(BlenderRNA *brna)
const EnumPropertyItem rna_enum_attribute_type_items[]
Definition: rna_attribute.c:40
static void rna_def_attribute_string(BlenderRNA *brna)
void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
Definition: rna_define.c:1167
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
Definition: rna_define.c:1212
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4159
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
Definition: rna_define.c:2257
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1555
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
Definition: rna_define.c:3312
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4302
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3153
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1676
void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2717
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4262
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
Definition: rna_define.c:3462
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:3408
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1259
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1892
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1067
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1568
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
Definition: rna_define.c:1757
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1792
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4337
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2927
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
Definition: rna_define.c:3251
void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
Definition: rna_define.c:2877
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
Definition: rna_define.c:4470
void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop)
Definition: rna_define.c:1122
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4332
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1517
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:3373
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1047
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2623
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
Definition: rna_define.c:4416
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3055
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3675
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2515
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2364
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1547
void rna_AttributeGroup_iterator_next(CollectionPropertyIterator *iter)
int rna_AttributeGroup_length(PointerRNA *ptr)
void rna_AttributeGroup_iterator_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
PointerRNA rna_AttributeGroup_iterator_get(CollectionPropertyIterator *iter)
#define min(a, b)
Definition: sort.c:51
char * endptr
Definition: RNA_types.h:363
union CollectionPropertyIterator::@1099 internal
const char * identifier
Definition: RNA_types.h:446
Definition: DNA_ID.h:273
int us
Definition: DNA_ID.h:293
char name[66]
Definition: DNA_ID.h:283
unsigned char r
Definition: BKE_main.h:116
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
float max
void WM_main_add_notifier(unsigned int type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157