Blender  V2.93
rna_pointcloud.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_define.h"
24 #include "RNA_enum_types.h"
25 
26 #include "rna_internal.h"
27 
28 #include "DNA_pointcloud_types.h"
29 
30 #include "BLI_math_base.h"
31 #include "BLI_string.h"
32 
33 #ifdef RNA_RUNTIME
34 
35 # include "BLI_math_vector.h"
36 
37 # include "BKE_pointcloud.h"
38 
39 # include "DEG_depsgraph.h"
40 
41 # include "WM_api.h"
42 # include "WM_types.h"
43 
44 static PointCloud *rna_pointcloud(PointerRNA *ptr)
45 {
46  return (PointCloud *)ptr->owner_id;
47 }
48 
49 static int rna_Point_index_get(PointerRNA *ptr)
50 {
51  const PointCloud *pointcloud = rna_pointcloud(ptr);
52  const float(*co)[3] = ptr->data;
53  return (int)(co - pointcloud->co);
54 }
55 
56 static void rna_Point_location_get(PointerRNA *ptr, float value[3])
57 {
58  copy_v3_v3(value, (const float *)ptr->data);
59 }
60 
61 static void rna_Point_location_set(PointerRNA *ptr, const float value[3])
62 {
63  copy_v3_v3((float *)ptr->data, value);
64 }
65 
66 static float rna_Point_radius_get(PointerRNA *ptr)
67 {
68  const PointCloud *pointcloud = rna_pointcloud(ptr);
69  if (pointcloud->radius == NULL) {
70  return 0.0f;
71  }
72  const float(*co)[3] = ptr->data;
73  return pointcloud->radius[co - pointcloud->co];
74 }
75 
76 static void rna_Point_radius_set(PointerRNA *ptr, float value)
77 {
78  const PointCloud *pointcloud = rna_pointcloud(ptr);
79  if (pointcloud->radius == NULL) {
80  return;
81  }
82  const float(*co)[3] = ptr->data;
83  pointcloud->radius[co - pointcloud->co] = value;
84 }
85 
86 static char *rna_Point_path(PointerRNA *ptr)
87 {
88  return BLI_sprintfN("points[%d]", rna_Point_index_get(ptr));
89 }
90 
91 static void rna_PointCloud_update_data(struct Main *UNUSED(bmain),
92  struct Scene *UNUSED(scene),
93  PointerRNA *ptr)
94 {
95  ID *id = ptr->owner_id;
96 
97  /* cheating way for importers to avoid slow updates */
98  if (id->us > 0) {
99  DEG_id_tag_update(id, 0);
101  }
102 }
103 
104 #else
105 
106 static void rna_def_point(BlenderRNA *brna)
107 {
108  StructRNA *srna;
109  PropertyRNA *prop;
110 
111  srna = RNA_def_struct(brna, "Point", NULL);
112  RNA_def_struct_ui_text(srna, "Point", "Point in a point cloud");
113  RNA_def_struct_path_func(srna, "rna_Point_path");
114 
115  prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
116  RNA_def_property_array(prop, 3);
117  RNA_def_property_float_funcs(prop, "rna_Point_location_get", "rna_Point_location_set", NULL);
118  RNA_def_property_ui_text(prop, "Location", "");
119  RNA_def_property_update(prop, 0, "rna_PointCloud_update_data");
120 
121  prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_DISTANCE);
122  RNA_def_property_float_funcs(prop, "rna_Point_radius_get", "rna_Point_radius_set", NULL);
123  RNA_def_property_ui_text(prop, "Radius", "");
124  RNA_def_property_update(prop, 0, "rna_PointCloud_update_data");
125 
126  prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
128  RNA_def_property_int_funcs(prop, "rna_Point_index_get", NULL, NULL);
129  RNA_def_property_ui_text(prop, "Index", "Index of this points");
130 }
131 
132 static void rna_def_pointcloud(BlenderRNA *brna)
133 {
134  StructRNA *srna;
135  PropertyRNA *prop;
136 
137  srna = RNA_def_struct(brna, "PointCloud", "ID");
138  RNA_def_struct_ui_text(srna, "Point Cloud", "Point cloud data-block");
139  RNA_def_struct_ui_icon(srna, ICON_POINTCLOUD_DATA);
140 
141  /* geometry */
142  /* TODO: better solution for (*co)[3] parsing issue. */
144  prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
145  RNA_def_property_collection_sdna(prop, NULL, "co", "totpoint");
146  RNA_def_property_struct_type(prop, "Point");
147  RNA_def_property_ui_text(prop, "Points", "");
149 
150  /* materials */
151  prop = RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);
152  RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
153  RNA_def_property_struct_type(prop, "Material");
154  RNA_def_property_ui_text(prop, "Materials", "");
155  RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */
157  prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "rna_IDMaterials_assign_int");
158 
160 
161  /* common */
163 }
164 
166 {
167  rna_def_point(brna);
168  rna_def_pointcloud(brna);
169 }
170 
171 #endif
typedef float(TangentPoint)[2]
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)
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_INT
Definition: RNA_types.h:74
@ PROP_COLLECTION
Definition: RNA_types.h:79
@ PROP_EDITABLE
Definition: RNA_types.h:175
@ PROP_DISTANCE
Definition: RNA_types.h:135
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_TRANSLATION
Definition: RNA_types.h:140
@ PROP_UNSIGNED
Definition: RNA_types.h:129
#define NC_GEOM
Definition: WM_types.h:294
#define ND_DATA
Definition: WM_types.h:408
Scene scene
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:1212
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3153
void RNA_define_verify_sdna(bool verify)
Definition: rna_define.c:751
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1676
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_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1568
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1792
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
Definition: rna_define.c:2791
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2927
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1517
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1047
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3055
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
Definition: rna_define.c:1267
static void rna_def_point(BlenderRNA *brna)
void RNA_def_pointcloud(BlenderRNA *brna)
static void rna_def_pointcloud(BlenderRNA *brna)
Definition: DNA_ID.h:273
int us
Definition: DNA_ID.h:293
Definition: BKE_main.h:116
float(* co)[3]
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
void WM_main_add_notifier(unsigned int type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157