game engine material conversion: don't use the material to convert vertex colors, then extract back out (pre face).

This commit is contained in:
Campbell Barton 2012-11-11 00:39:08 +00:00
parent f8af8100d2
commit dfc55421df
7 changed files with 20 additions and 48 deletions

@ -487,15 +487,14 @@ static bool ConvertMaterial(
MTFace* tface,
const char *tfaceName,
MFace* mface,
MCol* mmcol,
MCol* mmcol, /* only for text, use first mcol, weak */
MTF_localLayer *layers,
bool glslmat)
const bool glslmat)
{
material->Initialize();
int numchan = -1, texalpha = 0;
bool validmat = (mat!=0);
bool validface = (tface!=0);
bool use_mcol = true;
material->IdMode = DEFAULT_BLENDER;
material->glslmat = (validmat)? glslmat: false;
@ -503,7 +502,6 @@ static bool ConvertMaterial(
// --------------------------------
if (validmat) {
use_mcol = (mat->mode & MA_VERTEXCOLP || glslmat) ? true: false;
// use lighting?
material->ras_mode |= ( mat->mode & MA_SHLESS )?0:USE_LIGHT;
material->ras_mode |= ( mat->game.flag & GEMAT_BACKCULL )?0:TWOSIDED;
@ -852,19 +850,9 @@ static bool ConvertMaterial(
}
}
unsigned int rgb[4];
GetRGB(use_mcol, mface, mmcol, mat, rgb[0], rgb[1], rgb[2], rgb[3]);
// swap the material color, so MCol on bitmap font works
if (validmat && use_mcol == false && (mat->game.flag & GEMAT_TEXT))
{
rgb[0] = KX_rgbaint2uint_new(rgb[0]);
rgb[1] = KX_rgbaint2uint_new(rgb[1]);
rgb[2] = KX_rgbaint2uint_new(rgb[2]);
rgb[3] = KX_rgbaint2uint_new(rgb[3]);
if (validmat && mmcol) { /* color is only for text */
material->m_mcol = *(unsigned int *)mmcol;
}
material->SetConversionRGB(rgb);
material->SetConversionUV(uvName, uv);
material->SetConversionUV2(uv2Name, uv2);
@ -1009,20 +997,19 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene,
bool twoside = false;
if (converter->GetMaterials()) {
const bool glslmat = converter->GetGLSLMaterials();
const bool use_mcol = ma ? (ma->mode & MA_VERTEXCOLP || glslmat) : true;
/* do Blender Multitexture and Blender GLSL materials */
unsigned int rgb[4];
MT_Point2 uv[4];
/* first is the BL_Material */
if (!bl_mat)
bl_mat = new BL_Material();
ConvertMaterial(bl_mat, ma, tface, tfaceName, mface, mcol,
layers, converter->GetGLSLMaterials());
layers, glslmat);
/* vertex colors and uv's were stored in bl_mat temporarily */
bl_mat->GetConversionRGB(rgb);
rgb0 = rgb[0]; rgb1 = rgb[1];
rgb2 = rgb[2]; rgb3 = rgb[3];
GetRGB(use_mcol, mface, mcol, ma, rgb0, rgb1, rgb2, rgb3);
bl_mat->GetConversionUV(uv);
uv0 = uv[0]; uv1 = uv[1];

@ -36,10 +36,7 @@ BL_Material::BL_Material()
void BL_Material::Initialize()
{
rgb[0] = 0;
rgb[1] = 0;
rgb[2] = 0;
rgb[3] = 0;
m_mcol = 0xFFFFFFFFL;
IdMode = 0;
ras_mode = 0;
glslmat = 0;
@ -98,22 +95,6 @@ void BL_Material::Initialize()
}
}
void BL_Material::SetConversionRGB(unsigned int *nrgb)
{
rgb[0]=*nrgb++;
rgb[1]=*nrgb++;
rgb[2]=*nrgb++;
rgb[3]=*nrgb;
}
void BL_Material::GetConversionRGB(unsigned int *nrgb)
{
*nrgb++ = rgb[0];
*nrgb++ = rgb[1];
*nrgb++ = rgb[2];
*nrgb = rgb[3];
}
void BL_Material::SetConversionUV(const STR_String& name, MT_Point2 *nuv)
{
uvName = name;

@ -87,17 +87,14 @@ public:
MTFace tface; /* copy of the derived meshes tface */
Image* img[MAXTEX];
EnvMap* cubemap[MAXTEX];
unsigned int m_mcol; /* for text color (only) */
unsigned int rgb[4];
MT_Point2 uv[4];
MT_Point2 uv2[4];
STR_String uvName;
STR_String uv2Name;
void SetConversionRGB(unsigned int *rgb);
void GetConversionRGB(unsigned int *rgb);
void SetConversionUV(const STR_String& name, MT_Point2 *uv);
void GetConversionUV(MT_Point2 *uv);

@ -124,7 +124,7 @@ MTFace* KX_BlenderMaterial::GetMTFace(void) const
unsigned int* KX_BlenderMaterial::GetMCol(void) const
{
// fonts on polys
return mMaterial->rgb;
return &mMaterial->m_mcol;
}
void KX_BlenderMaterial::GetMaterialRGBAColor(unsigned char *rgba) const
@ -138,6 +138,11 @@ void KX_BlenderMaterial::GetMaterialRGBAColor(unsigned char *rgba) const
RAS_IPolyMaterial::GetMaterialRGBAColor(rgba);
}
bool KX_BlenderMaterial::IsMaterial(BL_Material *bl_mat) const
{
return (mMaterial == bl_mat);
}
Material *KX_BlenderMaterial::GetBlenderMaterial() const
{
return mMaterial->material;

@ -76,6 +76,8 @@ public:
TCachingInfo& cachingInfo
)const;
/* mMaterial is private, but need this for conversion */
bool IsMaterial(BL_Material *bl_mat) const;
Material* GetBlenderMaterial() const;
MTFace* GetMTFace(void) const;
unsigned int* GetMCol(void) const;

@ -109,7 +109,7 @@ void KX_PolygonMaterial::Initialize(
m_mcol = *mcol;
}
else {
memset(&m_mcol, 0, sizeof(m_mcol));
m_mcol = 0;
}
m_material = ma;

@ -60,7 +60,7 @@ class KX_PolygonMaterial : public PyObjectPlus, public RAS_IPolyMaterial
private:
/** Blender texture face structure. */
mutable MTFace m_tface;
mutable unsigned int m_mcol;
mutable unsigned int m_mcol; /* for text color (only) */
Material* m_material;
#ifdef WITH_PYTHON