TexFace to Material Settings big patch
[blender.git] / source / gameengine / Ketsji / BL_Material.cpp
1 /** \file gameengine/Ketsji/BL_Material.cpp
2  *  \ingroup ketsji
3  */
4 // ------------------------------------
5 #include "BL_Material.h"
6 #include "DNA_material_types.h"
7 #include "DNA_texture_types.h"
8 #include "DNA_image_types.h"
9 #include "DNA_mesh_types.h"
10 #include "IMB_imbuf_types.h"
11 #include "IMB_imbuf.h"
12
13 MTex* getImageFromMaterial(Material *mat, int index)
14 {
15         if(!mat) return 0;
16         
17         if(!(index >=0 && index < MAX_MTEX) ) return 0;
18         
19         MTex *m = mat->mtex[index];
20         return m?m:0;
21 }
22
23 int getNumTexChannels( Material *mat )
24 {
25         int count = -1;
26         if(!mat) return -1;
27
28         for(count =0; (count < 10) && mat->mtex[count] != 0; count++) {}
29         return count;
30 }
31
32 BL_Material::BL_Material()
33 {
34         Initialize();
35 }
36
37 void BL_Material::Initialize()
38 {
39         rgb[0] = 0;
40         rgb[1] = 0;
41         rgb[2] = 0;
42         rgb[3] = 0;
43         IdMode = 0;
44         ras_mode = 0;
45         glslmat = 0;
46         tile = 0;
47         matname = "NoMaterial";
48         matcolor[0] = 0.5f;
49         matcolor[1] = 0.5f;
50         matcolor[2] = 0.5f;
51         matcolor[3] = 0.5f;
52         speccolor[0] = 1.f;
53         speccolor[1] = 1.f;
54         speccolor[2] = 1.f;
55         alphablend = 0;
56         hard = 50.f;
57         spec_f = 0.5f;
58         alpha = 1.f;
59         emit = 0.f;
60         material = 0;
61         tface = 0;
62         materialindex = 0;
63         amb=0.5f;
64         num_enabled = 0;
65         num_users = 1;
66         share = false;
67
68         int i;
69         for(i=0; i<4; i++)
70         {
71                 uv[i] = MT_Point2(0.f,1.f);
72                 uv2[i] = MT_Point2(0.f, 1.f);
73         }
74
75         for(i=0; i<MAXTEX; i++) // :(
76         {
77                 mapping[i].mapping = 0;
78                 mapping[i].offsets[0] = 0.f;
79                 mapping[i].offsets[1] = 0.f;
80                 mapping[i].offsets[2] = 0.f;
81                 mapping[i].scale[0]   = 1.f;
82                 mapping[i].scale[1]   = 1.f;
83                 mapping[i].scale[2]   = 1.f;
84                 mapping[i].projplane[0] = PROJX;
85                 mapping[i].projplane[1] = PROJY;
86                 mapping[i].projplane[2] = PROJZ;
87                 mapping[i].objconame = "";
88                 mtexname[i] = "NULL";
89                 imageId[i]="NULL";
90                 flag[i] = 0;
91                 texname[i] = "NULL";
92                 tilexrep[i] = 1;
93                 tileyrep[i] = 1;
94                 color_blend[i] = 1.f;
95                 blend_mode[i]   = 0;
96                 img[i] = 0;
97                 cubemap[i] = 0;
98         }
99 }
100
101 void BL_Material::SetConversionRGB(unsigned int *nrgb) {
102         rgb[0]=*nrgb++;
103         rgb[1]=*nrgb++;
104         rgb[2]=*nrgb++;
105         rgb[3]=*nrgb;
106 }
107
108 void BL_Material::GetConversionRGB(unsigned int *nrgb) {
109         *nrgb++ = rgb[0];
110         *nrgb++ = rgb[1];
111         *nrgb++ = rgb[2];
112         *nrgb   = rgb[3];
113 }
114
115 void BL_Material::SetConversionUV(const STR_String& name, MT_Point2 *nuv) {
116         uvName = name;
117         uv[0] = *nuv++;
118         uv[1] = *nuv++;
119         uv[2] = *nuv++;
120         uv[3] = *nuv;
121 }
122
123 void BL_Material::GetConversionUV(MT_Point2 *nuv){
124         *nuv++ = uv[0];
125         *nuv++ = uv[1];
126         *nuv++ = uv[2];
127         *nuv   = uv[3];
128 }
129 void BL_Material::SetConversionUV2(const STR_String& name, MT_Point2 *nuv) {
130         uv2Name = name;
131         uv2[0] = *nuv++;
132         uv2[1] = *nuv++;
133         uv2[2] = *nuv++;
134         uv2[3] = *nuv;
135 }
136
137 void BL_Material::GetConversionUV2(MT_Point2 *nuv){
138         *nuv++ = uv2[0];
139         *nuv++ = uv2[1];
140         *nuv++ = uv2[2];
141         *nuv   = uv2[3];
142 }
143
144
145 void BL_Material::SetSharedMaterial(bool v)
146 {
147         if((v && num_users == -1) || num_users > 1 )
148                 share = true;
149         else 
150                 share = false;
151 }
152
153 bool BL_Material::IsShared()
154 {
155         return share;
156 }
157
158 void BL_Material::SetUsers(int num)
159 {
160         num_users = num;
161 }
162