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

rna_hair.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 079ce5c6a078c9aeb0296ea518194c6f14ceba71 (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.
 *
 * Contributor(s): Blender Foundation.
 *
 * ***** END GPL LICENSE BLOCK *****
 */

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

#include <stdlib.h>

#include "RNA_define.h"
#include "RNA_enum_types.h"

#include "rna_internal.h"

#include "DNA_hair_types.h"

#include "WM_types.h"

#ifdef RNA_RUNTIME

#include "MEM_guardedalloc.h"

#include "BLI_listbase.h"

#include "DNA_object_types.h"

#include "BKE_context.h"
#include "BKE_DerivedMesh.h"
#include "BKE_hair.h"
#include "BKE_main.h"
#include "BKE_material.h"

#include "DEG_depsgraph.h"

#include "RNA_access.h"

#include "WM_api.h"
#include "WM_types.h"

static void rna_HairSystem_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
}

static void rna_HairSystem_generate_follicles(
        HairSystem *hsys,
        struct bContext *C,
        Object *scalp,
        int seed,
        int count)
{
	if (!scalp)
	{
		return;
	}
	
	struct Scene *scene = CTX_data_scene(C);
	EvaluationContext eval_ctx;
	CTX_data_eval_ctx(C, &eval_ctx);
	
	CustomDataMask datamask = CD_MASK_BAREMESH;
	DerivedMesh *dm = mesh_get_derived_final(&eval_ctx, scene, scalp, datamask);
	
	BKE_hair_generate_follicles(hsys, dm, (unsigned int)seed, count);
}

static const EnumPropertyItem *rna_HairSystem_material_slot_itemf(
        bContext *C,
        PointerRNA *UNUSED(ptr),
        PropertyRNA *UNUSED(prop),
        bool *r_free)
{
	Object *ob = CTX_data_pointer_get(C, "object").data;
	Material *ma;
	EnumPropertyItem *item = NULL;
	EnumPropertyItem tmp = {0, "", 0, "", ""};
	int totitem = 0;
	int i;

	if (ob && ob->totcol > 0) {
		for (i = 1; i <= ob->totcol; i++) {
			ma = give_current_material(ob, i);
			tmp.value = i;
			tmp.icon = ICON_MATERIAL_DATA;
			if (ma) {
				tmp.name = ma->id.name + 2;
				tmp.identifier = tmp.name;
			}
			else {
				tmp.name = "Default Material";
				tmp.identifier = tmp.name;
			}
			RNA_enum_item_add(&item, &totitem, &tmp);
		}
	}
	else {
		tmp.value = 1;
		tmp.icon = ICON_MATERIAL_DATA;
		tmp.name = "Default Material";
		tmp.identifier = tmp.name;
		RNA_enum_item_add(&item, &totitem, &tmp);
	}

	RNA_enum_item_end(&item, &totitem);
	*r_free = true;

	return item;
}

#else

static void rna_def_hair_follicle(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "HairFollicle", NULL);
	RNA_def_struct_ui_text(srna, "Hair Follicle", "Single follicle on a surface");
	RNA_def_struct_sdna(srna, "HairFollicle");
	
	prop = RNA_def_property(srna, "mesh_sample", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MeshSample");
}

static void rna_def_hair_pattern(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "HairPattern", NULL);
	RNA_def_struct_ui_text(srna, "Hair Pattern", "Set of hair follicles distributed on a surface");
	RNA_def_struct_sdna(srna, "HairPattern");
	RNA_def_struct_ui_icon(srna, ICON_STRANDS);
	
	prop = RNA_def_property(srna, "follicles", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "follicles", "num_follicles");
	RNA_def_property_struct_type(prop, "HairFollicle");
	RNA_def_property_ui_text(prop, "Follicles", "Hair fiber follicles");
}

static void rna_def_hair_system(BlenderRNA *brna)
{
	StructRNA *srna;
	FunctionRNA *func;
	PropertyRNA *prop, *parm;
	
	static const EnumPropertyItem material_slot_items[] = {
		{0, "DUMMY", 0, "Dummy", ""},
		{0, NULL, 0, NULL, NULL}
	};
	
	srna = RNA_def_struct(brna, "HairSystem", NULL);
	RNA_def_struct_ui_text(srna, "Hair System", "Hair rendering and deformation data");
	RNA_def_struct_sdna(srna, "HairSystem");
	RNA_def_struct_ui_icon(srna, ICON_STRANDS);
	
	prop = RNA_def_property(srna, "pattern", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "HairPattern");
	RNA_def_property_ui_text(prop, "Pattern", "Hair pattern");
	
	prop = RNA_def_property(srna, "material_index", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "material_index");
	RNA_def_property_range(prop, 1, 32767);
	RNA_def_property_ui_text(prop, "Material Index", "Index of material slot used for rendering hair fibers");
	RNA_def_property_update(prop, 0, "rna_HairSystem_update");

	prop = RNA_def_property(srna, "material_slot", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "material_index");
	RNA_def_property_enum_items(prop, material_slot_items);
	RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_HairSystem_material_slot_itemf");
	RNA_def_property_ui_text(prop, "Material Slot", "Material slot used for rendering particles");
	RNA_def_property_update(prop, 0, "rna_HairSystem_update");
	
	func = RNA_def_function(srna, "generate_follicles", "rna_HairSystem_generate_follicles");
	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
	parm = RNA_def_pointer(func, "scalp", "Object", "Scalp", "Scalp object on which to place hair follicles");
	RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
	parm = RNA_def_int(func, "seed", 0, 0, INT_MAX, "Seed", "Seed value for random numbers", 0, INT_MAX);
	parm = RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Maximum number of follicles to generate", 1, 1e5);
	RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
}

static void rna_def_hair_draw_settings(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	static const EnumPropertyItem follicle_mode_items[] = {
	    {HAIR_DRAW_FOLLICLE_NONE, "NONE", 0, "None", ""},
	    {HAIR_DRAW_FOLLICLE_POINTS, "POINTS", 0, "Points", "Draw a point for each follicle"},
	    {HAIR_DRAW_FOLLICLE_AXES, "AXES", 0, "Axes", "Draw direction of hair for each follicle"},
		{0, NULL, 0, NULL, NULL}
	};
	
	srna = RNA_def_struct(brna, "HairDrawSettings", NULL);
	RNA_def_struct_ui_text(srna, "Hair Draw Settings", "Settings for drawing hair systems");
	RNA_def_struct_sdna(srna, "HairDrawSettings");
	
	prop = RNA_def_property(srna, "follicle_mode", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_items(prop, follicle_mode_items);
	RNA_def_property_ui_text(prop, "Follicle Mode", "Draw follicles on the scalp surface");
}

void RNA_def_hair(BlenderRNA *brna)
{
	rna_def_hair_follicle(brna);
	rna_def_hair_pattern(brna);
	rna_def_hair_system(brna);
	rna_def_hair_draw_settings(brna);
}

#endif