[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55486] trunk/blender/source/gameengine/ Converter/BL_BlenderDataConversion.cpp: code cleanup: conversion from blender to BGE was unnecessarily confusing in checking weather to use vertex colors ,
Campbell Barton
ideasman42 at gmail.com
Fri Mar 22 00:11:53 CET 2013
Revision: 55486
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55486
Author: campbellbarton
Date: 2013-03-21 23:11:52 +0000 (Thu, 21 Mar 2013)
Log Message:
-----------
code cleanup: conversion from blender to BGE was unnecessarily confusing in checking weather to use vertex colors,
move check to function.
Modified Paths:
--------------
trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp 2013-03-21 22:15:16 UTC (rev 55485)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp 2013-03-21 23:11:52 UTC (rev 55486)
@@ -426,63 +426,73 @@
}
+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 @@
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 @@
// 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,10 +908,9 @@
converter->CacheBlenderMaterial(ma, bl_mat);
}
+ const bool use_vcol = GetMaterialUseVColor(ma, bl_mat->glslmat);
+ GetRGB(use_vcol, mface, mcol, ma, rgb);
- short type = (ma) ? ((ma->mode & MA_VERTEXCOLP || bl_mat->glslmat) ? 0 : 1) : 0;
- GetRGB(type,mface,mcol,ma,rgb);
-
GetUVs(bl_mat, layers, mface, tface, uvs);
/* then the KX_BlenderMaterial */
More information about the Bf-blender-cvs
mailing list