Blender V5.3
rna_pointcloud.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "RNA_define.hh"
12#include "RNA_enum_types.hh"
13
14#include "rna_internal.hh"
15
16#include "BKE_attribute.h"
17
18namespace blender {
19
22 "POINTS",
23 0,
24 "Points",
25 "Simple point cloud represented by points with position and radius"},
27 "GAUSSIAN_SPLAT",
28 0,
29 "3D Gaussian Splat",
30 "A point cloud that represents the original 3D Gaussian Splats technique"},
31 {0, nullptr, 0, nullptr, nullptr},
32};
33
34}
35
36#ifdef RNA_RUNTIME
37
38# include <fmt/format.h>
39
40# include "BLI_math_vector_c.hh"
41# include "BLI_virtual_array.hh"
42
43# include "BKE_customdata.hh"
44# include "BKE_pointcloud.hh"
45
46# include "DEG_depsgraph.hh"
47
48# include "WM_api.hh"
49# include "WM_types.hh"
50
51namespace blender {
52
53static PointCloud *rna_pointcloud(const PointerRNA *ptr)
54{
55 return id_cast<PointCloud *>(ptr->owner_id);
56}
57
58static float3 *get_pointcloud_positions(PointCloud *pointcloud)
59{
60 return pointcloud->positions_for_write().data();
61}
62
63static const float3 *get_pointcloud_positions_const(const PointCloud *pointcloud)
64{
65 return pointcloud->positions().data();
66}
67
68static int rna_Point_index_get_const(const PointerRNA *ptr)
69{
70 const PointCloud *pointcloud = rna_pointcloud(ptr);
71 const float3 *co = static_cast<const float3 *>(ptr->data);
72 const float3 *positions = get_pointcloud_positions_const(pointcloud);
73 return int(co - positions);
74}
75
76static int rna_Point_index_get(PointerRNA *ptr)
77{
78 return rna_Point_index_get_const(ptr);
79}
80
81static int rna_PointCloud_points_length(PointerRNA *ptr)
82{
83 const PointCloud *pointcloud = rna_pointcloud(ptr);
84 return pointcloud->totpoint;
85}
86
87static void rna_PointCloud_points_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
88{
89 PointCloud *pointcloud = rna_pointcloud(ptr);
91 ptr,
92 get_pointcloud_positions(pointcloud),
93 sizeof(float3),
94 pointcloud->totpoint,
95 false,
96 nullptr);
97}
98
99bool rna_PointCloud_points_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
100{
101 PointCloud *pointcloud = rna_pointcloud(ptr);
102 if (index < 0 || index >= pointcloud->totpoint) {
103 return false;
104 }
106 *ptr, RNA_Point, &get_pointcloud_positions(pointcloud)[index], *r_ptr);
107 return true;
108}
109
110static void rna_Point_location_get(PointerRNA *ptr, float value[3])
111{
112 copy_v3_v3(value, *static_cast<const float3 *>(ptr->data));
113}
114
115static void rna_Point_location_set(PointerRNA *ptr, const float value[3])
116{
117 *static_cast<float3 *>(ptr->data) = float3(value);
118}
119
120static float rna_Point_radius_get(PointerRNA *ptr)
121{
122 const PointCloud *pointcloud = rna_pointcloud(ptr);
123 return pointcloud->radius().get(rna_Point_index_get_const(ptr));
124}
125
126static void rna_Point_radius_set(PointerRNA *ptr, float value)
127{
128 PointCloud *pointcloud = rna_pointcloud(ptr);
129 pointcloud->radius_for_write()[rna_Point_index_get_const(ptr)] = value;
130}
131
132static std::optional<std::string> rna_Point_path(const PointerRNA *ptr)
133{
134 return fmt::format("points[{}]", rna_Point_index_get_const(ptr));
135}
136
137static void rna_PointCloud_update_data(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
138{
139 ID *id = ptr->owner_id;
140
141 /* cheating way for importers to avoid slow updates */
142 if (id->us > 0) {
143 DEG_id_tag_update(id, 0);
145 }
146}
147
148static void rna_PointCloud_resize(PointCloud *pointcloud, const int size)
149{
150 pointcloud_resize(*pointcloud, size);
151}
152
153} // namespace blender
154
155#else
156
157namespace blender {
158
159static void rna_def_point(BlenderRNA *brna)
160{
161 StructRNA *srna;
162 PropertyRNA *prop;
163
164 srna = RNA_def_struct(brna, "Point", nullptr);
165 RNA_def_struct_ui_text(srna, "Point", "Point in a point cloud");
166 RNA_def_struct_path_func(srna, "rna_Point_path");
167
168 prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
169 RNA_def_property_array(prop, 3);
170 RNA_def_property_float_funcs(prop, "rna_Point_location_get", "rna_Point_location_set", nullptr);
171 RNA_def_property_ui_text(prop, "Location", "");
172 RNA_def_property_update(prop, 0, "rna_PointCloud_update_data");
173
174 prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_DISTANCE);
175 RNA_def_property_float_funcs(prop, "rna_Point_radius_get", "rna_Point_radius_set", nullptr);
176 RNA_def_property_ui_text(prop, "Radius", "");
177 RNA_def_property_update(prop, 0, "rna_PointCloud_update_data");
178
179 prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
181 RNA_def_property_int_funcs(prop, "rna_Point_index_get", nullptr, nullptr);
182 RNA_def_property_ui_text(prop, "Index", "Index of this point");
183}
184
186{
187 StructRNA *srna;
188 PropertyRNA *prop;
189 FunctionRNA *func;
190 PropertyRNA *parm;
191
192 srna = RNA_def_struct(brna, "PointCloud", "ID");
193 RNA_def_struct_ui_text(srna, "Point Cloud", "Point cloud data-block");
194 RNA_def_struct_ui_icon(srna, ICON_POINTCLOUD_DATA);
195
196 /* geometry */
197 prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
198 RNA_def_property_struct_type(prop, "Point");
201 "rna_PointCloud_points_begin",
202 "rna_iterator_array_next",
203 "rna_iterator_array_end",
204 "rna_iterator_array_get",
205 "rna_PointCloud_points_length",
206 "rna_PointCloud_points_lookup_int",
207 nullptr,
208 nullptr);
209 RNA_def_property_ui_text(prop, "Points", "");
210 func = RNA_def_function(srna, "resize", "rna_PointCloud_resize");
211 parm = RNA_def_int(func, "size", 0, 0, INT_MAX, "Size", "New number of points", 0, INT_MAX);
213
214 /* materials */
215 prop = RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);
216 RNA_def_property_collection_sdna(prop, nullptr, "mat", "totcol");
217 RNA_def_property_struct_type(prop, "Material");
218 RNA_def_property_ui_text(prop, "Materials", "");
219 RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.cc */
221 nullptr,
222 nullptr,
223 nullptr,
224 nullptr,
225 nullptr,
226 nullptr,
227 nullptr,
228 "rna_IDMaterials_assign_int");
229
231
232 /* Type. */
233 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
235 RNA_def_property_ui_text(prop, "Type", "Representation type of the pointcloud");
236 RNA_def_property_update(prop, 0, "rna_PointCloud_update_data");
237
238 /* common */
240}
241
243{
244 rna_def_point(brna);
245 rna_def_pointcloud(brna);
246}
247
248} // namespace blender
249
250#endif
Generic geometry attributes built on CustomData.
CustomData interface, see also DNA_customdata_types.h.
General operations for point clouds.
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define INT_MAX
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
void RNA_def_pointcloud(BlenderRNA *brna)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
static void rna_def_pointcloud(BlenderRNA *brna)
void rna_pointer_create_with_ancestors(const PointerRNA &parent, StructRNA *type, void *data, PointerRNA &r_ptr)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
@ PROPOVERRIDE_IGNORE
Definition RNA_types.hh:609
void rna_def_animdata_common(StructRNA *srna)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
@ PROP_COLLECTION
Definition RNA_types.hh:216
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
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)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void DEG_id_tag_update(ID *id, unsigned int flags)
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
static void rna_def_point(BlenderRNA *brna)
const EnumPropertyItem rna_enum_pointcloud_type_items[]
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
@ PROP_EDITABLE
Definition RNA_types.hh:376
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
void pointcloud_resize(PointCloud &pointcloud, int size)
VecBase< float, 3 > float3
@ PROP_TRANSLATION
Definition RNA_types.hh:318
@ PROP_DISTANCE
Definition RNA_types.hh:313
@ PROP_UNSIGNED
Definition RNA_types.hh:306
@ PARM_REQUIRED
Definition RNA_types.hh:631
void RNA_def_property_array(PropertyRNA *prop, int length)
void rna_iterator_array_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, void *data, size_t itemsize, int64_t length, bool free_ptr, IteratorSkipFunc skip)
void rna_def_attributes_common(StructRNA *srna, const AttributeOwnerType type)