svn merge -r 15392:15551 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[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         rgb[0] = 0;
32         rgb[1] = 0;
33         rgb[2] = 0;
34         rgb[3] = 0;
35         IdMode = 0;
36         ras_mode = 0;
37         glslmat = 0;
38         tile = 0;
39         matname = "NoMaterial";
40         matcolor[0] = 0.5f;
41         matcolor[1] = 0.5f;
42         matcolor[2] = 0.5f;
43         matcolor[3] = 0.5f;
44         speccolor[0] = 1.f;
45         speccolor[1] = 1.f;
46         speccolor[2] = 1.f;
47         transp = 0;
48         hard = 50.f;
49         spec_f = 0.5f;
50         alpha = 1.f;
51         emit = 0.f;
52         mode = 0;
53         material = 0;
54         tface = 0;
55         material_index = 0;
56         amb=0.5f;
57         num_enabled = 0;
58         num_users = 1;
59         share = false;
60
61         int i;
62         for(i=0; i<4; i++)
63         {
64                 uv[i] = MT_Point2(0.f,1.f);
65                 uv2[i] = MT_Point2(0.f, 1.f);
66         }
67
68         for(i=0; i<MAXTEX; i++) // :(
69         {
70                 mapping[i].mapping = 0;
71                 mapping[i].offsets[0] = 0.f;
72                 mapping[i].offsets[1] = 0.f;
73                 mapping[i].offsets[2] = 0.f;
74                 mapping[i].scale[0]   = 1.f;
75                 mapping[i].scale[1]   = 1.f;
76                 mapping[i].scale[2]   = 1.f;
77                 mapping[i].projplane[0] = PROJX;
78                 mapping[i].projplane[1] = PROJY;
79                 mapping[i].projplane[2] = PROJZ;
80                 mapping[i].objconame = "";
81                 mtexname[i] = "NULL";
82                 imageId[i]="NULL";
83                 flag[i] = 0;
84                 texname[i] = "NULL";
85                 tilexrep[i] = 1;
86                 tileyrep[i] = 1;
87                 color_blend[i] = 1.f;
88                 blend_mode[i]   = 0;
89                 img[i] = 0;
90                 cubemap[i] = 0;
91         }
92 }
93
94 void BL_Material::SetConversionRGB(unsigned int *nrgb) {
95         rgb[0]=*nrgb++;
96         rgb[1]=*nrgb++;
97         rgb[2]=*nrgb++;
98         rgb[3]=*nrgb;
99 }
100
101 void BL_Material::GetConversionRGB(unsigned int *nrgb) {
102         *nrgb++ = rgb[0];
103         *nrgb++ = rgb[1];
104         *nrgb++ = rgb[2];
105         *nrgb   = rgb[3];
106 }
107
108 void BL_Material::SetConversionUV(const STR_String& name, MT_Point2 *nuv) {
109         uvName = name;
110         uv[0] = *nuv++;
111         uv[1] = *nuv++;
112         uv[2] = *nuv++;
113         uv[3] = *nuv;
114 }
115
116 void BL_Material::GetConversionUV(MT_Point2 *nuv){
117         *nuv++ = uv[0];
118         *nuv++ = uv[1];
119         *nuv++ = uv[2];
120         *nuv   = uv[3];
121 }
122 void BL_Material::SetConversionUV2(const STR_String& name, MT_Point2 *nuv) {
123         uv2Name = name;
124         uv2[0] = *nuv++;
125         uv2[1] = *nuv++;
126         uv2[2] = *nuv++;
127         uv2[3] = *nuv;
128 }
129
130 void BL_Material::GetConversionUV2(MT_Point2 *nuv){
131         *nuv++ = uv2[0];
132         *nuv++ = uv2[1];
133         *nuv++ = uv2[2];
134         *nuv   = uv2[3];
135 }
136
137
138 void BL_Material::SetSharedMaterial(bool v)
139 {
140         if((v && num_users == -1) || num_users > 1 )
141                 share = true;
142         else 
143                 share = false;
144 }
145
146 bool BL_Material::IsShared()
147 {
148         return share;
149 }
150
151 void BL_Material::SetUsers(int num)
152 {
153         num_users = num;
154 }
155