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

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

#include <stdlib.h>
#include <stdio.h>

#include "RNA_define.h"

#include "DNA_material_types.h"

#ifdef RNA_RUNTIME

#include "BKE_material.h"
#include "BKE_texture.h"

/*
  Adds material to the first free texture slot.
  If all slots are busy, replaces the first.
*/
static void rna_Material_add_texture(Material *ma, Tex *tex, int mapto, int texco)
{
	int i;
	MTex *mtex;
	int slot= -1;

	for (i= 0; i < MAX_MTEX; i++) {
		if (!ma->mtex[i]) {
			slot= i;
			break;
		}
	}
	
	if (slot == -1)
		slot= 0;
	
	if (ma->mtex[slot]) {
		ma->mtex[slot]->tex->id.us--;
	}
	else {
		ma->mtex[slot]= add_mtex();
	}

	mtex= ma->mtex[slot];

	mtex->tex= tex;
	if (tex)
		id_us_plus(&tex->id);
	
	mtex->texco= mapto;
	mtex->mapto= texco;
}

#else

void RNA_api_material(StructRNA *srna)
{
	FunctionRNA *func;
	PropertyRNA *parm;

	/* copied from rna_def_material_mtex (rna_material.c) */
	static EnumPropertyItem prop_texture_coordinates_items[] = {
		{TEXCO_GLOB, "GLOBAL", 0, "Global", "Uses global coordinates for the texture coordinates"},
		{TEXCO_OBJECT, "OBJECT", 0, "Object", "Uses linked object's coordinates for texture coordinates"},
		{TEXCO_UV, "UV", 0, "UV", "Uses UV coordinates for texture coordinates"},
		{TEXCO_ORCO, "ORCO", 0, "Generated", "Uses the original undeformed coordinates of the object"},
		{TEXCO_STRAND, "STRAND", 0, "Strand", "Uses normalized strand texture coordinate (1D)"},
		{TEXCO_STICKY, "STICKY", 0, "Sticky", "Uses mesh's sticky coordinates for the texture coordinates"},
		{TEXCO_WINDOW, "WINDOW", 0, "Window", "Uses screen coordinates as texture coordinates"},
		{TEXCO_NORM, "NORMAL", 0, "Normal", "Uses normal vector as texture coordinates"},
		{TEXCO_REFL, "REFLECTION", 0, "Reflection", "Uses reflection vector as texture coordinates"},
		{TEXCO_STRESS, "STRESS", 0, "Stress", "Uses the difference of edge lengths compared to original coordinates of the mesh"},
		{TEXCO_TANGENT, "TANGENT", 0, "Tangent", "Uses the optional tangent vector as texture coordinates"},

		{0, NULL, 0, NULL, NULL}};

	static EnumPropertyItem prop_texture_mapto_items[] = {
		{MAP_COL, "COLOR", 0, "Color", "Causes the texture to affect basic color of the material"},
		{MAP_NORM, "NORMAL", 0, "Normal", "Causes the texture to affect the rendered normal"},
		{MAP_COLSPEC, "SPECULAR_COLOR", 0, "Specularity Color", "Causes the texture to affect the specularity color"},
		{MAP_COLMIR, "MIRROR", 0, "Mirror", "Causes the texture to affect the mirror color"},
		{MAP_REF, "REFLECTION", 0, "Reflection", "Causes the texture to affect the value of the materials reflectivity"},
		{MAP_SPEC, "SPECULARITY", 0, "Specularity", "Causes the texture to affect the value of specularity"},
		{MAP_EMIT, "EMIT", 0, "Emit", "Causes the texture to affect the emit value"},
		{MAP_ALPHA, "ALPHA", 0, "Alpha", "Causes the texture to affect the alpha value"},
		{MAP_HAR, "HARDNESS", 0, "Hardness", "Causes the texture to affect the hardness value"},
		{MAP_RAYMIRR, "RAY_MIRROR", 0, "Ray-Mirror", "Causes the texture to affect the ray-mirror value"},
		{MAP_TRANSLU, "TRANSLUCENCY", 0, "Translucency", "Causes the texture to affect the translucency value"},
		{MAP_AMB, "AMBIENT", 0, "Ambient", "Causes the texture to affect the value of ambient"},
		{MAP_DISPLACE, "DISPLACEMENT", 0, "Displacement", "Let the texture displace the surface"},
		{MAP_WARP, "WARP", 0, "Warp", "Let the texture warp texture coordinates of next channels"},
		{0, NULL, 0, NULL, NULL}};

	func= RNA_def_function(srna, "add_texture", "rna_Material_add_texture");
	RNA_def_function_ui_description(func, "Add a texture to material's free texture slot.");
	parm= RNA_def_pointer(func, "texture", "Texture", "Texture", "Texture to add."); 
	RNA_def_property_flag(parm, PROP_REQUIRED);
	parm= RNA_def_enum(func, "texture_coordinates", prop_texture_coordinates_items, TEXCO_UV, "", "Source of texture coordinate information."); /* optional */
	parm= RNA_def_enum(func, "map_to", prop_texture_mapto_items, MAP_COL, "", "Controls which material property the texture affects."); /* optional */
}

#endif