LEFT | RIGHT |
| 1 /* |
| 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
| 3 * |
| 4 * This program is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU General Public License |
| 6 * as published by the Free Software Foundation; either version 2 |
| 7 * of the License, or (at your option) any later version. |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software Foundation, |
| 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 * |
| 18 * ***** END GPL LICENSE BLOCK ***** |
| 19 */ |
| 20 |
1 /** \file gameengine/Ketsji/BL_Material.cpp | 21 /** \file gameengine/Ketsji/BL_Material.cpp |
2 * \ingroup ketsji | 22 * \ingroup ketsji |
3 */ | 23 */ |
4 // ------------------------------------ | 24 |
5 #include "BL_Material.h" | 25 #include "BL_Material.h" |
6 #include "DNA_material_types.h" | 26 #include "DNA_material_types.h" |
7 #include "DNA_texture_types.h" | 27 #include "DNA_texture_types.h" |
8 #include "DNA_image_types.h" | 28 #include "DNA_image_types.h" |
9 #include "DNA_mesh_types.h" | 29 #include "DNA_mesh_types.h" |
10 #include "IMB_imbuf_types.h" | 30 #include "IMB_imbuf_types.h" |
11 #include "IMB_imbuf.h" | 31 #include "IMB_imbuf.h" |
12 | 32 |
13 MTex* getImageFromMaterial(Material *mat, int index) | 33 MTex* getMTexFromMaterial(Material *mat, int index) |
14 { | 34 { |
15 » if(!mat) return 0; | 35 » if (mat && (index >= 0) && (index < MAX_MTEX)) { |
16 »······· | 36 » » return mat->mtex[index]; |
17 » if(!(index >=0 && index < MAX_MTEX) ) return 0; | 37 » } |
18 »······· | 38 » else { |
19 » MTex *m = mat->mtex[index]; | 39 » » return NULL; |
20 » return m?m:0; | 40 » } |
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 } | 41 } |
31 | 42 |
32 BL_Material::BL_Material() | 43 BL_Material::BL_Material() |
33 { | 44 { |
34 Initialize(); | 45 Initialize(); |
35 } | 46 } |
36 | 47 |
37 void BL_Material::Initialize() | 48 void BL_Material::Initialize() |
38 { | 49 { |
39 rgb[0] = 0; | 50 rgb[0] = 0; |
40 rgb[1] = 0; | 51 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; | 52 speccolor[0] = 1.f; |
53 speccolor[1] = 1.f; | 53 speccolor[1] = 1.f; |
54 speccolor[2] = 1.f; | 54 speccolor[2] = 1.f; |
55 » alphablend = 0; | 55 » transp = 0; |
56 hard = 50.f; | 56 hard = 50.f; |
57 spec_f = 0.5f; | 57 spec_f = 0.5f; |
58 alpha = 1.f; | 58 alpha = 1.f; |
59 emit = 0.f; | 59 emit = 0.f; |
| 60 mode = 0; |
60 material = 0; | 61 material = 0; |
61 tface = 0; | 62 tface = 0; |
62 materialindex = 0; | 63 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 | |
LEFT | RIGHT |