|
Blender
V2.59
|
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 transp = 0; 00056 hard = 50.f; 00057 spec_f = 0.5f; 00058 alpha = 1.f; 00059 emit = 0.f; 00060 mode = 0; 00061 material = 0; 00062 tface = 0; 00063 materialindex = 0; 00064 amb=0.5f; 00065 num_enabled = 0; 00066 num_users = 1; 00067 share = false; 00068 00069 int i; 00070 for(i=0; i<4; i++) 00071 { 00072 uv[i] = MT_Point2(0.f,1.f); 00073 uv2[i] = MT_Point2(0.f, 1.f); 00074 } 00075 00076 for(i=0; i<MAXTEX; i++) // :( 00077 { 00078 mapping[i].mapping = 0; 00079 mapping[i].offsets[0] = 0.f; 00080 mapping[i].offsets[1] = 0.f; 00081 mapping[i].offsets[2] = 0.f; 00082 mapping[i].scale[0] = 1.f; 00083 mapping[i].scale[1] = 1.f; 00084 mapping[i].scale[2] = 1.f; 00085 mapping[i].projplane[0] = PROJX; 00086 mapping[i].projplane[1] = PROJY; 00087 mapping[i].projplane[2] = PROJZ; 00088 mapping[i].objconame = ""; 00089 mtexname[i] = "NULL"; 00090 imageId[i]="NULL"; 00091 flag[i] = 0; 00092 texname[i] = "NULL"; 00093 tilexrep[i] = 1; 00094 tileyrep[i] = 1; 00095 color_blend[i] = 1.f; 00096 blend_mode[i] = 0; 00097 img[i] = 0; 00098 cubemap[i] = 0; 00099 } 00100 } 00101 00102 void BL_Material::SetConversionRGB(unsigned int *nrgb) { 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 *nrgb++ = rgb[0]; 00111 *nrgb++ = rgb[1]; 00112 *nrgb++ = rgb[2]; 00113 *nrgb = rgb[3]; 00114 } 00115 00116 void BL_Material::SetConversionUV(const STR_String& name, MT_Point2 *nuv) { 00117 uvName = name; 00118 uv[0] = *nuv++; 00119 uv[1] = *nuv++; 00120 uv[2] = *nuv++; 00121 uv[3] = *nuv; 00122 } 00123 00124 void BL_Material::GetConversionUV(MT_Point2 *nuv){ 00125 *nuv++ = uv[0]; 00126 *nuv++ = uv[1]; 00127 *nuv++ = uv[2]; 00128 *nuv = uv[3]; 00129 } 00130 void BL_Material::SetConversionUV2(const STR_String& name, MT_Point2 *nuv) { 00131 uv2Name = name; 00132 uv2[0] = *nuv++; 00133 uv2[1] = *nuv++; 00134 uv2[2] = *nuv++; 00135 uv2[3] = *nuv; 00136 } 00137 00138 void BL_Material::GetConversionUV2(MT_Point2 *nuv){ 00139 *nuv++ = uv2[0]; 00140 *nuv++ = uv2[1]; 00141 *nuv++ = uv2[2]; 00142 *nuv = uv2[3]; 00143 } 00144 00145 00146 void BL_Material::SetSharedMaterial(bool v) 00147 { 00148 if((v && num_users == -1) || num_users > 1 ) 00149 share = true; 00150 else 00151 share = false; 00152 } 00153 00154 bool BL_Material::IsShared() 00155 { 00156 return share; 00157 } 00158 00159 void BL_Material::SetUsers(int num) 00160 { 00161 num_users = num; 00162 } 00163