Blender V2.61 - r43446
|
00001 00004 // ------------------------------------ 00005 #include "BL_Material.h" 00006 #include "DNA_material_types.h" 00007 #include "DNA_texture_types.h" 00008 #include "DNA_image_types.h" 00009 #include "DNA_mesh_types.h" 00010 #include "IMB_imbuf_types.h" 00011 #include "IMB_imbuf.h" 00012 00013 MTex* getImageFromMaterial(Material *mat, int index) 00014 { 00015 if(!mat) return 0; 00016 00017 if(!(index >=0 && index < MAX_MTEX) ) return 0; 00018 00019 MTex *m = mat->mtex[index]; 00020 return m?m:0; 00021 } 00022 00023 int getNumTexChannels( Material *mat ) 00024 { 00025 int count = -1; 00026 if(!mat) return -1; 00027 00028 for(count =0; (count < 10) && mat->mtex[count] != 0; count++) {} 00029 return count; 00030 } 00031 00032 BL_Material::BL_Material() 00033 { 00034 Initialize(); 00035 } 00036 00037 void BL_Material::Initialize() 00038 { 00039 rgb[0] = 0; 00040 rgb[1] = 0; 00041 rgb[2] = 0; 00042 rgb[3] = 0; 00043 IdMode = 0; 00044 ras_mode = 0; 00045 glslmat = 0; 00046 tile = 0; 00047 matname = "NoMaterial"; 00048 matcolor[0] = 0.5f; 00049 matcolor[1] = 0.5f; 00050 matcolor[2] = 0.5f; 00051 matcolor[3] = 0.5f; 00052 speccolor[0] = 1.f; 00053 speccolor[1] = 1.f; 00054 speccolor[2] = 1.f; 00055 alphablend = 0; 00056 hard = 50.f; 00057 spec_f = 0.5f; 00058 alpha = 1.f; 00059 emit = 0.f; 00060 material = 0; 00061 tface = 0; 00062 materialindex = 0; 00063 amb=0.5f; 00064 num_enabled = 0; 00065 num_users = 1; 00066 share = false; 00067 00068 int i; 00069 for(i=0; i<4; i++) 00070 { 00071 uv[i] = MT_Point2(0.f,1.f); 00072 uv2[i] = MT_Point2(0.f, 1.f); 00073 } 00074 00075 for(i=0; i<MAXTEX; i++) // :( 00076 { 00077 mapping[i].mapping = 0; 00078 mapping[i].offsets[0] = 0.f; 00079 mapping[i].offsets[1] = 0.f; 00080 mapping[i].offsets[2] = 0.f; 00081 mapping[i].scale[0] = 1.f; 00082 mapping[i].scale[1] = 1.f; 00083 mapping[i].scale[2] = 1.f; 00084 mapping[i].projplane[0] = PROJX; 00085 mapping[i].projplane[1] = PROJY; 00086 mapping[i].projplane[2] = PROJZ; 00087 mapping[i].objconame = ""; 00088 mtexname[i] = "NULL"; 00089 imageId[i]="NULL"; 00090 flag[i] = 0; 00091 texname[i] = "NULL"; 00092 tilexrep[i] = 1; 00093 tileyrep[i] = 1; 00094 color_blend[i] = 1.f; 00095 blend_mode[i] = 0; 00096 img[i] = 0; 00097 cubemap[i] = 0; 00098 } 00099 } 00100 00101 void BL_Material::SetConversionRGB(unsigned int *nrgb) 00102 { 00103 rgb[0]=*nrgb++; 00104 rgb[1]=*nrgb++; 00105 rgb[2]=*nrgb++; 00106 rgb[3]=*nrgb; 00107 } 00108 00109 void BL_Material::GetConversionRGB(unsigned int *nrgb) 00110 { 00111 *nrgb++ = rgb[0]; 00112 *nrgb++ = rgb[1]; 00113 *nrgb++ = rgb[2]; 00114 *nrgb = rgb[3]; 00115 } 00116 00117 void BL_Material::SetConversionUV(const STR_String& name, MT_Point2 *nuv) 00118 { 00119 uvName = name; 00120 uv[0] = *nuv++; 00121 uv[1] = *nuv++; 00122 uv[2] = *nuv++; 00123 uv[3] = *nuv; 00124 } 00125 00126 void BL_Material::GetConversionUV(MT_Point2 *nuv) 00127 { 00128 *nuv++ = uv[0]; 00129 *nuv++ = uv[1]; 00130 *nuv++ = uv[2]; 00131 *nuv = uv[3]; 00132 } 00133 void BL_Material::SetConversionUV2(const STR_String& name, MT_Point2 *nuv) 00134 { 00135 uv2Name = name; 00136 uv2[0] = *nuv++; 00137 uv2[1] = *nuv++; 00138 uv2[2] = *nuv++; 00139 uv2[3] = *nuv; 00140 } 00141 00142 void BL_Material::GetConversionUV2(MT_Point2 *nuv) 00143 { 00144 *nuv++ = uv2[0]; 00145 *nuv++ = uv2[1]; 00146 *nuv++ = uv2[2]; 00147 *nuv = uv2[3]; 00148 } 00149 00150 00151 void BL_Material::SetSharedMaterial(bool v) 00152 { 00153 if((v && num_users == -1) || num_users > 1 ) 00154 share = true; 00155 else 00156 share = false; 00157 } 00158 00159 bool BL_Material::IsShared() 00160 { 00161 return share; 00162 } 00163 00164 void BL_Material::SetUsers(int num) 00165 { 00166 num_users = num; 00167 } 00168