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

rna_groom.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 67c0b3a02dd82b4fd56863d5ecdc575fdba03b0f (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
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * 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.
 *
 * The Original Code is Copyright (C) Blender Foundation
 * All rights reserved.
 *
 * The Original Code is: all of this file.
 *
 * Contributor(s): Lukas Toenne
 *
 * ***** END GPL LICENSE BLOCK *****
 */

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

#include <stdlib.h>

#include "DNA_groom_types.h"
#include "DNA_scene_types.h"

#include "MEM_guardedalloc.h"

#include "BLI_string_utils.h"
#include "BLI_utildefines.h"

#include "BLT_translation.h"

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

#include "rna_internal.h"

#include "WM_types.h"
#include "DNA_object_types.h"


#ifdef RNA_RUNTIME

#include "BLI_listbase.h"
#include "BLI_math.h"

#include "WM_api.h"

#include "BKE_groom.h"
#include "BKE_object_facemap.h"

#include "DEG_depsgraph.h"

static void UNUSED_FUNCTION(rna_Groom_update)(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
{
	WM_main_add_notifier(NC_GROOM | NA_EDITED, NULL);
}

static void rna_Groom_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	DEG_id_tag_update(ptr->id.data, 0);
	WM_main_add_notifier(NC_GROOM | ND_DATA, ptr->id.data);
}

static int rna_GroomBundle_is_bound_get(PointerRNA *ptr)
{
	GroomBundle *bundle = (GroomBundle *)ptr->data;
	return (bundle->scalp_region != NULL);
}

static void rna_GroomBundle_scalp_facemap_name_set(PointerRNA *ptr, const char *value)
{
	Groom *groom = (Groom *)ptr->id.data;
	GroomBundle *bundle = (GroomBundle *)ptr->data;
	
	if (groom->scalp_object)
	{
		bFaceMap *fm = BKE_object_facemap_find_name(groom->scalp_object, value);
		if (fm) {
			/* no need for BLI_strncpy_utf8, since this matches an existing facemap */
			BLI_strncpy(bundle->scalp_facemap_name, value, sizeof(bundle->scalp_facemap_name));
			return;
		}
	}
	
	bundle->scalp_facemap_name[0] = '\0';
}

static PointerRNA rna_Groom_active_bundle_get(PointerRNA *ptr)
{
	Groom *groom = (Groom *)ptr->id.data;
	PointerRNA r_ptr;
	RNA_pointer_create(&groom->id, &RNA_GroomBundle, BLI_findlink(&groom->bundles, groom->active_bundle), &r_ptr);
	return r_ptr;
}

static int rna_Groom_active_bundle_index_get(PointerRNA *ptr)
{
	Groom *groom = (Groom *)ptr->id.data;
	return groom->active_bundle;
}

static void rna_Groom_active_bundle_index_set(PointerRNA *ptr, int value)
{
	Groom *groom = (Groom *)ptr->id.data;
	groom->active_bundle = value;
}

static void rna_Groom_active_bundle_index_range(
        PointerRNA *ptr,
        int *min,
        int *max,
        int *UNUSED(softmin),
        int *UNUSED(softmax))
{
	Groom *groom = (Groom *)ptr->id.data;
	*min = 0;
	*max = max_ii(0, BLI_listbase_count(&groom->bundles) - 1);
}

#else

static void rna_def_groom_bundle(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "GroomBundle", NULL);
	RNA_def_struct_sdna(srna, "GroomBundle");
	RNA_def_struct_ui_text(srna, "Groom Bundle", "Bundle of hair originating from a scalp region");
	
	prop = RNA_def_property(srna, "is_bound", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_funcs(prop, "rna_GroomBundle_is_bound_get", NULL);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Bound", "Bundle was successfully bound to a scalp region");
	RNA_def_property_update(prop, NC_GROOM | ND_DRAW, NULL);
	
	prop = RNA_def_property(srna, "scalp_facemap", PROP_STRING, PROP_NONE);
	RNA_def_property_string_sdna(prop, NULL, "scalp_facemap_name");
	RNA_def_property_ui_text(prop, "Scalp Vertex Group", "Face map name of the scalp region");
	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_GroomBundle_scalp_facemap_name_set");
	RNA_def_property_update(prop, 0, "rna_Groom_update_data");
}

/* groom.bundles */
static void rna_def_groom_bundles(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	RNA_def_property_srna(cprop, "GroomBundles");
	srna = RNA_def_struct(brna, "GroomBundles", NULL);
	RNA_def_struct_sdna(srna, "Groom");
	RNA_def_struct_ui_text(srna, "Groom Bundles", "Collection of groom bundles");
	
	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "GroomBundle");
	RNA_def_property_pointer_funcs(prop, "rna_Groom_active_bundle_get", NULL, NULL, NULL);
	RNA_def_property_ui_text(prop, "Active Groom Bundle", "Active groom bundle being displayed");
	RNA_def_property_update(prop, NC_GROOM | ND_DRAW, NULL);
	
	prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_funcs(prop, "rna_Groom_active_bundle_index_get",
	                           "rna_Groom_active_bundle_index_set",
	                           "rna_Groom_active_bundle_index_range");
	RNA_def_property_ui_text(prop, "Active Groom Bundle Index", "Index of active groom bundle");
	RNA_def_property_update(prop, NC_GROOM | ND_DRAW, NULL);
}

static void rna_def_groom(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "Groom", "ID");
	RNA_def_struct_sdna(srna, "Groom");
	RNA_def_struct_ui_text(srna, "Groom", "Guide curve geometry for hair");
	RNA_def_struct_ui_icon(srna, ICON_NONE);
	
	/* Animation Data */
	rna_def_animdata_common(srna);
	
	prop = RNA_def_property(srna, "bundles", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "bundles", NULL);
	RNA_def_property_struct_type(prop, "GroomBundle");
	RNA_def_property_ui_text(prop, "Bundles", "Bundles of hair");
	rna_def_groom_bundles(brna, prop);
	
	prop = RNA_def_property(srna, "curve_resolution", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "curve_res");
	RNA_def_property_range(prop, 1, 1024);
	RNA_def_property_ui_range(prop, 1, 64, 1, -1);
	RNA_def_property_ui_text(prop, "Curve Resolution", "Curve subdivisions per segment");
	RNA_def_property_update(prop, 0, "rna_Groom_update_data");
	
	prop = RNA_def_property(srna, "hair_system", PROP_POINTER, PROP_NONE);
	RNA_def_property_ui_text(prop, "Hair", "Hair data");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	
	prop = RNA_def_property(srna, "hair_draw_settings", PROP_POINTER, PROP_NONE);
	RNA_def_property_ui_text(prop, "Hair Draw Settings", "Hair draw settings");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	
	prop = RNA_def_property(srna, "scalp_object", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "scalp_object");
	RNA_def_property_ui_text(prop, "Scalp Object", "Surface for attaching hairs");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_update(prop, 0, "rna_Groom_update_data");
	
	UNUSED_VARS(prop);
}

void RNA_def_groom(BlenderRNA *brna)
{
	rna_def_groom(brna);
	rna_def_groom_bundle(brna);
}

#endif