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