Blender  V3.3
rna_pointcloud.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_pointcloud_types.h"
15 
16 #include "BLI_math_base.h"
17 #include "BLI_string.h"
18 
19 #ifdef RNA_RUNTIME
20 
21 # include "BLI_math_vector.h"
22 
23 # include "BKE_customdata.h"
24 # include "BKE_pointcloud.h"
25 
26 # include "DEG_depsgraph.h"
27 
28 # include "WM_api.h"
29 # include "WM_types.h"
30 
31 static PointCloud *rna_pointcloud(const PointerRNA *ptr)
32 {
33  return (PointCloud *)ptr->owner_id;
34 }
35 
36 static int rna_Point_index_get_const(const PointerRNA *ptr)
37 {
38  const PointCloud *pointcloud = rna_pointcloud(ptr);
39  const float(*co)[3] = ptr->data;
40  const float(*positions)[3] = (const float(*)[3])CustomData_get_layer_named(
41  &pointcloud->pdata, CD_PROP_FLOAT3, "position");
42  return (int)(co - positions);
43 }
44 
45 static int rna_Point_index_get(PointerRNA *ptr)
46 {
47  return rna_Point_index_get_const(ptr);
48 }
49 
50 static int rna_PointCloud_points_length(PointerRNA *ptr)
51 {
52  const PointCloud *pointcloud = rna_pointcloud(ptr);
53  return pointcloud->totpoint;
54 }
55 
56 static void rna_PointCloud_points_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
57 {
58  const PointCloud *pointcloud = rna_pointcloud(ptr);
59  const float(*positions)[3] = (const float(*)[3])CustomData_get_layer_named(
60  &pointcloud->pdata, CD_PROP_FLOAT3, "position");
62  iter, (void *)positions, sizeof(float[3]), pointcloud->totpoint, false, NULL);
63 }
64 
65 static void rna_Point_location_get(PointerRNA *ptr, float value[3])
66 {
67  copy_v3_v3(value, (const float *)ptr->data);
68 }
69 
70 static void rna_Point_location_set(PointerRNA *ptr, const float value[3])
71 {
72  copy_v3_v3((float *)ptr->data, value);
73 }
74 
75 static float rna_Point_radius_get(PointerRNA *ptr)
76 {
77  const PointCloud *pointcloud = rna_pointcloud(ptr);
78  const float *radii = (const float *)CustomData_get_layer_named(
79  &pointcloud->pdata, CD_PROP_FLOAT, "radius");
80  if (radii == NULL) {
81  return 0.0f;
82  }
83  return radii[rna_Point_index_get_const(ptr)];
84 }
85 
86 static void rna_Point_radius_set(PointerRNA *ptr, float value)
87 {
88  PointCloud *pointcloud = rna_pointcloud(ptr);
89  float *radii = (float *)CustomData_get_layer_named(&pointcloud->pdata, CD_PROP_FLOAT, "radius");
90  if (radii == NULL) {
91  return;
92  }
93  radii[rna_Point_index_get_const(ptr)] = value;
94 }
95 
96 static char *rna_Point_path(const PointerRNA *ptr)
97 {
98  return BLI_sprintfN("points[%d]", rna_Point_index_get_const(ptr));
99 }
100 
101 static void rna_PointCloud_update_data(struct Main *UNUSED(bmain),
102  struct Scene *UNUSED(scene),
103  PointerRNA *ptr)
104 {
105  ID *id = ptr->owner_id;
106 
107  /* cheating way for importers to avoid slow updates */
108  if (id->us > 0) {
109  DEG_id_tag_update(id, 0);
111  }
112 }
113 
114 #else
115 
116 static void rna_def_point(BlenderRNA *brna)
117 {
118  StructRNA *srna;
119  PropertyRNA *prop;
120 
121  srna = RNA_def_struct(brna, "Point", NULL);
122  RNA_def_struct_ui_text(srna, "Point", "Point in a point cloud");
123  RNA_def_struct_path_func(srna, "rna_Point_path");
124 
125  prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
126  RNA_def_property_array(prop, 3);
127  RNA_def_property_float_funcs(prop, "rna_Point_location_get", "rna_Point_location_set", NULL);
128  RNA_def_property_ui_text(prop, "Location", "");
129  RNA_def_property_update(prop, 0, "rna_PointCloud_update_data");
130 
131  prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_DISTANCE);
132  RNA_def_property_float_funcs(prop, "rna_Point_radius_get", "rna_Point_radius_set", NULL);
133  RNA_def_property_ui_text(prop, "Radius", "");
134  RNA_def_property_update(prop, 0, "rna_PointCloud_update_data");
135 
136  prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
138  RNA_def_property_int_funcs(prop, "rna_Point_index_get", NULL, NULL);
139  RNA_def_property_ui_text(prop, "Index", "Index of this points");
140 }
141 
142 static void rna_def_pointcloud(BlenderRNA *brna)
143 {
144  StructRNA *srna;
145  PropertyRNA *prop;
146 
147  srna = RNA_def_struct(brna, "PointCloud", "ID");
148  RNA_def_struct_ui_text(srna, "Point Cloud", "Point cloud data-block");
149  RNA_def_struct_ui_icon(srna, ICON_POINTCLOUD_DATA);
150 
151  /* geometry */
152  prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
153  RNA_def_property_struct_type(prop, "Point");
155  "rna_PointCloud_points_begin",
156  "rna_iterator_array_next",
157  "rna_iterator_array_end",
158  "rna_iterator_array_get",
159  "rna_PointCloud_points_length",
160  NULL,
161  NULL,
162  NULL);
163  RNA_def_property_ui_text(prop, "Points", "");
164 
165  /* materials */
166  prop = RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);
167  RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
168  RNA_def_property_struct_type(prop, "Material");
169  RNA_def_property_ui_text(prop, "Materials", "");
170  RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */
172  prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "rna_IDMaterials_assign_int");
173 
175 
176  /* common */
178 }
179 
181 {
182  rna_def_point(brna);
183  rna_def_pointcloud(brna);
184 }
185 
186 #endif
typedef float(TangentPoint)[2]
CustomData interface, see also DNA_customdata_types.h.
void * CustomData_get_layer_named(const struct CustomData *data, int type, const char *name)
General operations for point clouds.
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)
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ PROP_FLOAT
Definition: RNA_types.h:61
@ PROP_INT
Definition: RNA_types.h:60
@ PROP_COLLECTION
Definition: RNA_types.h:65
@ 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_DATA
Definition: WM_types.h:456
Scene scene
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)
void rna_def_attributes_common(StructRNA *srna)
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
Definition: rna_define.c:1193
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3126
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1645
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_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
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
static void rna_def_point(BlenderRNA *brna)
void RNA_def_pointcloud(BlenderRNA *brna)
static void rna_def_pointcloud(BlenderRNA *brna)
Definition: DNA_ID.h:368
int us
Definition: DNA_ID.h:388
Definition: BKE_main.h:121
struct CustomData pdata
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