From f254ba77fd8b820b892298009634c5cc8ca32a76 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 21 Mar 2013 23:11:52 +0000 Subject: code cleanup: conversion from blender to BGE was unnecessarily confusing in checking weather to use vertex colors, move check to function. --- .../Converter/BL_BlenderDataConversion.cpp | 125 +++++++++++---------- 1 file changed, 64 insertions(+), 61 deletions(-) (limited to 'source/gameengine/Converter') diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index d90708602d5..6481983e8bc 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -426,63 +426,73 @@ static void SetDefaultLightMode(Scene* scene) } +static bool GetMaterialUseVColor(Material *ma, const bool glslmat) +{ + if (ma) { + /* glsl uses vertex colors, otherwise use material setting */ + return (glslmat || (ma->mode & MA_VERTEXCOLP) != 0); + } + else { + /* no material, use vertex colors */ + return true; + } +} + // -- -static void GetRGB(short type, - MFace* mface, - MCol* mmcol, - Material *mat, - unsigned int c[4]) +static void GetRGB( + const bool use_vcol, + MFace* mface, + MCol* mmcol, + Material *mat, + unsigned int c[4]) { unsigned int color = 0xFFFFFFFFL; - switch (type) { - case 0: // vertex colors - { - if (mmcol) { - c[0] = KX_Mcol2uint_new(mmcol[0]); - c[1] = KX_Mcol2uint_new(mmcol[1]); - c[2] = KX_Mcol2uint_new(mmcol[2]); - if (mface->v4) - c[3] = KX_Mcol2uint_new(mmcol[3]); - } - else { // backup white - c[0] = KX_rgbaint2uint_new(color); - c[1] = KX_rgbaint2uint_new(color); - c[2] = KX_rgbaint2uint_new(color); - if (mface->v4) - c[3] = KX_rgbaint2uint_new( color ); - } - } break; - - - case 1: // material rgba - { - if (mat) { - union { - unsigned char cp[4]; - unsigned int integer; - } col_converter; - col_converter.cp[3] = (unsigned char) (mat->r * 255.0f); - col_converter.cp[2] = (unsigned char) (mat->g * 255.0f); - col_converter.cp[1] = (unsigned char) (mat->b * 255.0f); - col_converter.cp[0] = (unsigned char) (mat->alpha * 255.0f); - color = col_converter.integer; - } - c[0] = KX_rgbaint2uint_new(color); - c[1] = KX_rgbaint2uint_new(color); - c[2] = KX_rgbaint2uint_new(color); + if (use_vcol == true) { + if (mmcol) { + c[0] = KX_Mcol2uint_new(mmcol[0]); + c[1] = KX_Mcol2uint_new(mmcol[1]); + c[2] = KX_Mcol2uint_new(mmcol[2]); if (mface->v4) - c[3] = KX_rgbaint2uint_new(color); - } break; - - default: // white - { + c[3] = KX_Mcol2uint_new(mmcol[3]); + } + else { // backup white c[0] = KX_rgbaint2uint_new(color); c[1] = KX_rgbaint2uint_new(color); c[2] = KX_rgbaint2uint_new(color); if (mface->v4) - c[3] = KX_rgbaint2uint_new(color); - } break; + c[3] = KX_rgbaint2uint_new( color ); + } } + else { + /* material rgba */ + if (mat) { + union { + unsigned char cp[4]; + unsigned int integer; + } col_converter; + col_converter.cp[3] = (unsigned char) (mat->r * 255.0f); + col_converter.cp[2] = (unsigned char) (mat->g * 255.0f); + col_converter.cp[1] = (unsigned char) (mat->b * 255.0f); + col_converter.cp[0] = (unsigned char) (mat->alpha * 255.0f); + color = col_converter.integer; + } + c[0] = KX_rgbaint2uint_new(color); + c[1] = KX_rgbaint2uint_new(color); + c[2] = KX_rgbaint2uint_new(color); + if (mface->v4) { + c[3] = KX_rgbaint2uint_new(color); + } + } + +#if 0 /* white, unused */ + { + c[0] = KX_rgbaint2uint_new(color); + c[1] = KX_rgbaint2uint_new(color); + c[2] = KX_rgbaint2uint_new(color); + if (mface->v4) + c[3] = KX_rgbaint2uint_new(color); + } +#endif } typedef struct MTF_localLayer { @@ -573,21 +583,15 @@ static bool ConvertMaterial( bool validmat = (mat!=0); bool validface = (tface!=0); - short type = 0; - if ( validmat ) - type = 1; // material color + const bool use_vcol = GetMaterialUseVColor(mat, glslmat); material->IdMode = DEFAULT_BLENDER; - material->glslmat = (validmat)? glslmat: false; + material->glslmat = (validmat) ? glslmat: false; material->materialindex = mface->mat_nr; // -------------------------------- if (validmat) { - // use vertex colors by explicitly setting - if (mat->mode &MA_VERTEXCOLP || glslmat) - type = 0; - // use lighting? material->ras_mode |= ( mat->mode & MA_SHLESS )?0:USE_LIGHT; material->ras_mode |= ( mat->game.flag & GEMAT_BACKCULL )?0:TWOSIDED; @@ -859,10 +863,10 @@ static bool ConvertMaterial( // XXX The RGB values here were meant to be temporary storage for the conversion process, // but fonts now make use of them too, so we leave them in for now. unsigned int rgb[4]; - GetRGB(type,mface,mmcol,mat,rgb); + GetRGB(use_vcol, mface, mmcol, mat, rgb); // swap the material color, so MCol on bitmap font works - if (validmat && type==1 && (mat->game.flag & GEMAT_TEXT)) + if (validmat && (use_vcol == false) && (mat->game.flag & GEMAT_TEXT)) { rgb[0] = KX_rgbaint2uint_new(rgb[0]); rgb[1] = KX_rgbaint2uint_new(rgb[1]); @@ -904,9 +908,8 @@ static RAS_MaterialBucket *material_from_mesh(Material *ma, MFace *mface, MTFace converter->CacheBlenderMaterial(ma, bl_mat); } - - short type = (ma) ? ((ma->mode & MA_VERTEXCOLP || bl_mat->glslmat) ? 0 : 1) : 0; - GetRGB(type,mface,mcol,ma,rgb); + const bool use_vcol = GetMaterialUseVColor(ma, bl_mat->glslmat); + GetRGB(use_vcol, mface, mcol, ma, rgb); GetUVs(bl_mat, layers, mface, tface, uvs); -- cgit v1.2.3