Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rna_strands.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f6154fd1e010c5d9e9a399517e729f12e759d8a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
 * Copyright 2015, Blender Foundation.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

/** \file blender/makesrna/intern/rna_strands.c
 *  \ingroup RNA
 */

#include <stdlib.h>

#include "BLI_utildefines.h"

#include "RNA_define.h"
#include "RNA_access.h"

#include "rna_internal.h"

#include "WM_types.h"

#ifdef RNA_RUNTIME

#include "BLI_math.h"

#include "BKE_strands.h"
#include "BKE_report.h"

static int rna_Strands_has_motion_state_get(PointerRNA *ptr)
{
	Strands *strands = ptr->data;
	return (bool)(strands->state != NULL);
}

static int rna_StrandsChildCurve_render_size_get(PointerRNA *ptr)
{
	StrandsChildCurve *curve = ptr->data;
	return curve->cutoff < 0.0f ? curve->numverts : min_ii(curve->numverts, (int)ceilf(curve->cutoff) + 1);
}

static void rna_StrandsChildren_curve_uvs_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	StrandsChildren *strands = ptr->data;
	rna_iterator_array_begin(iter, strands->curve_uvs, sizeof(StrandsChildCurveUV), strands->totcurves * strands->numuv, false, NULL);
}

static int rna_StrandsChildren_curve_uvs_length(PointerRNA *ptr)
{
	StrandsChildren *strands = ptr->data;
	return strands->totcurves * strands->numuv;
}

static int rna_StrandsChildren_curve_uvs_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
{
	StrandsChildren *strands = ptr->data;
	if (index >= 0 && index < strands->totcurves * strands->numuv) {
		RNA_pointer_create(ptr->id.data, &RNA_StrandsChildCurveUV, strands->curve_uvs + index, r_ptr);
		return true;
	}
	else {
		RNA_pointer_create(ptr->id.data, &RNA_StrandsChildCurveUV, NULL, r_ptr);
		return false;
	}
}

static void rna_StrandsChildren_curve_vcols_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	StrandsChildren *strands = ptr->data;
	rna_iterator_array_begin(iter, strands->curve_vcols, sizeof(StrandsChildCurveVCol), strands->totcurves * strands->numvcol, false, NULL);
}

static int rna_StrandsChildren_curve_vcols_length(PointerRNA *ptr)
{
	StrandsChildren *strands = ptr->data;
	return strands->totcurves * strands->numvcol;
}

static int rna_StrandsChildren_curve_vcols_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
{
	StrandsChildren *strands = ptr->data;
	if (index >= 0 && index < strands->totcurves * strands->numvcol) {
		RNA_pointer_create(ptr->id.data, &RNA_StrandsChildCurveVCol, strands->curve_vcols + index, r_ptr);
		return true;
	}
	else {
		RNA_pointer_create(ptr->id.data, &RNA_StrandsChildCurveVCol, NULL, r_ptr);
		return false;
	}
}

#else

static void rna_def_strands_curve(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "StrandsCurve", NULL);
	RNA_def_struct_sdna(srna, "StrandsCurve");
	RNA_def_struct_ui_text(srna, "Strand Curve", "Strand curve");
	
	prop = RNA_def_property(srna, "size", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "numverts");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Size", "Number of vertices of the curve");
	
	/* same as "size", defined for consistency */
	prop = RNA_def_property(srna, "render_size", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "numverts");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Render Size", "Number of vertices of the curve for rendering based on cutoff length");
}

static void rna_def_strands_vertex(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "StrandsVertex", NULL);
	RNA_def_struct_sdna(srna, "StrandsVertex");
	RNA_def_struct_ui_text(srna, "Strand Vertex", "Strand vertex");
	
	prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_float_sdna(prop, NULL, "co");
	RNA_def_property_array(prop, 3);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Location", "");
}

static void rna_def_strands_motion_state(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "StrandsMotionState", NULL);
	RNA_def_struct_sdna(srna, "StrandsMotionState");
	RNA_def_struct_ui_text(srna, "Strand Vertex Motion State", "Physical motion state of a vertex");
	
	prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_float_sdna(prop, NULL, "co");
	RNA_def_property_array(prop, 3);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Location", "");
}

static void rna_def_strands(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "Strands", NULL);
	RNA_def_struct_sdna(srna, "Strands");
	RNA_def_struct_ui_text(srna, "Strands", "Strand geometry to represent hair and similar linear structures");
	
	prop = RNA_def_property(srna, "curves", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "curves", "totcurves");
	RNA_def_property_struct_type(prop, "StrandsCurve");
	RNA_def_property_ui_text(prop, "Strand Curves", "");
	
	prop = RNA_def_property(srna, "vertices", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "verts", "totverts");
	RNA_def_property_struct_type(prop, "StrandsVertex");
	RNA_def_property_ui_text(prop, "Strand Vertex", "");
	
	prop = RNA_def_property(srna, "has_motion_state", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_funcs(prop, "rna_Strands_has_motion_state_get", NULL);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Has Motion State", "Strands have physical motion data associated with vertices");
	
	prop = RNA_def_property(srna, "motion_state", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "state", "totverts");
	RNA_def_property_struct_type(prop, "StrandsMotionState");
	RNA_def_property_ui_text(prop, "Strand Motion State", "");
}

static void rna_def_strands_child_curve(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "StrandsChildCurve", NULL);
	RNA_def_struct_sdna(srna, "StrandsChildCurve");
	RNA_def_struct_ui_text(srna, "Strand Child Curve", "Strand child curve");
	
	prop = RNA_def_property(srna, "size", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "numverts");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Size", "Number of vertices of the curve");
	
	prop = RNA_def_property(srna, "render_size", PROP_INT, PROP_NONE);
	RNA_def_property_int_funcs(prop, "rna_StrandsChildCurve_render_size_get", NULL, NULL);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Render Size", "Number of vertices of the curve for rendering based on cutoff length");
	
	prop = RNA_def_property(srna, "cutoff", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "cutoff");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Cutoff", "Curve parameter at which the curve is cut short for rendering");
}

static void rna_def_strands_child_curve_uv(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "StrandsChildCurveUV", NULL);
	RNA_def_struct_sdna(srna, "StrandsChildCurveUV");
	RNA_def_struct_ui_text(srna, "Strand Child Curve UV", "UV data for child strand curves");
	
	prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_NONE);
	RNA_def_property_array(prop, 2);
	RNA_def_property_ui_text(prop, "UV", "");
}

static void rna_def_strands_child_curve_vcol(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "StrandsChildCurveVCol", NULL);
	RNA_def_struct_sdna(srna, "StrandsChildCurveVCol");
	RNA_def_struct_ui_text(srna, "Strand Child Curve Vertex Color", "Vertex color data for child strand curves");
	
	prop = RNA_def_property(srna, "vcol", PROP_FLOAT, PROP_NONE);
	RNA_def_property_array(prop, 3);
	RNA_def_property_ui_text(prop, "Vertex Color", "");
}

static void rna_def_strands_child_vertex(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "StrandsChildVertex", NULL);
	RNA_def_struct_sdna(srna, "StrandsChildVertex");
	RNA_def_struct_ui_text(srna, "Strand Child Vertex", "Strand child vertex");
	
	prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_float_sdna(prop, NULL, "co");
	RNA_def_property_array(prop, 3);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Location", "");
}

static void rna_def_strands_children(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "StrandsChildren", NULL);
	RNA_def_struct_sdna(srna, "StrandsChildren");
	RNA_def_struct_ui_text(srna, "Child Strands", "Strand geometry to represent hair and similar linear structures");
	
	prop = RNA_def_property(srna, "curves", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "curves", "totcurves");
	RNA_def_property_struct_type(prop, "StrandsChildCurve");
	RNA_def_property_ui_text(prop, "Strand Child Curves", "");
	
	prop = RNA_def_property(srna, "curve_uvs", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_funcs(prop, "rna_StrandsChildren_curve_uvs_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get",
	                                  "rna_StrandsChildren_curve_uvs_length", "rna_StrandsChildren_curve_uvs_lookup_int", NULL, NULL);
	RNA_def_property_struct_type(prop, "StrandsChildCurveUV");
	RNA_def_property_ui_text(prop, "Strand Child Curves UV", "");
	
	prop = RNA_def_property(srna, "num_curve_uv_layers", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "numuv");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "UV Layers", "Number of UV layers");
	
	prop = RNA_def_property(srna, "curve_vcols", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_funcs(prop, "rna_StrandsChildren_curve_vcols_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get",
	                                  "rna_StrandsChildren_curve_vcols_length", "rna_StrandsChildren_curve_vcols_lookup_int", NULL, NULL);
	RNA_def_property_struct_type(prop, "StrandsChildCurveVCol");
	RNA_def_property_ui_text(prop, "Strand Child Curves Vertex Colors", "");
	
	prop = RNA_def_property(srna, "num_curve_vcol_layers", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "numvcol");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Vertex Color Layers", "Number of Vertex Color layers");
	
	prop = RNA_def_property(srna, "vertices", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "verts", "totverts");
	RNA_def_property_struct_type(prop, "StrandsChildVertex");
	RNA_def_property_ui_text(prop, "Strand Child Vertex", "");
}

void RNA_def_strands(BlenderRNA *brna)
{
	rna_def_strands_curve(brna);
	rna_def_strands_vertex(brna);
	rna_def_strands_motion_state(brna);
	rna_def_strands(brna);
	rna_def_strands_child_curve(brna);
	rna_def_strands_child_curve_uv(brna);
	rna_def_strands_child_curve_vcol(brna);
	rna_def_strands_child_vertex(brna);
	rna_def_strands_children(brna);
}

#endif