Beispiel #1
0
void gkBlenderMeshConverter::convertMaterial(Blender::Material* bma, gkMaterialProperties& gma, gkMeshHashKey& hk)
{
	convertTextureFace(gma, hk, 0);

	gma.m_name          = GKB_IDNAME(bma);
	gma.m_hardness      = bma->har / 4.f;
	gma.m_refraction    = bma->ref;
	gma.m_emissive      = bma->emit;
	gma.m_ambient       = bma->amb;
	gma.m_spec          = bma->spec;
	gma.m_alpha         = bma->alpha;
	gma.m_diffuse       = gkColor(bma->r, bma->g, bma->b);
	gma.m_specular      = gkColor(bma->specr, bma->specg, bma->specb);
	gma.m_rblend        = getRampBlendType(bma->rampblend_col);

	if (bma->mode & MA_ZTRA)        		gma.m_mode |= gkMaterialProperties::MA_DEPTHWRITE;
	if (bma->mode & MA_SHADOW)      		gma.m_mode |= gkMaterialProperties::MA_RECEIVESHADOWS;
	if (bma->mode & MA_WIRE)        		gma.m_mode |= gkMaterialProperties::MA_WIREFRAME;
	if (!(bma->mode & MA_SHLESS))   		gma.m_mode |= gkMaterialProperties::MA_LIGHTINGENABLED;
	// TODO: this need to be checked, as there are cases where material-alpha is set to zero to give the texture-alpha full control
	if (bma->alpha <= 0.f)          		gma.m_mode |= gkMaterialProperties::MA_INVISIBLE;
	if (bma->mode & MA_RAMP_COL)			gma.m_mode |= gkMaterialProperties::MA_HASRAMPBLEND;
	if (!(bma->game.flag & GEMAT_BACKCULL)) gma.m_mode |= gkMaterialProperties::MA_TWOSIDE;
	if (bma->game.flag & GEMAT_INVISIBLE)   gma.m_mode |= gkMaterialProperties::MA_INVISIBLE;

	if (bma->game.alpha_blend & GEMAT_ALPHA)
		gma.m_mode |= gkMaterialProperties::MA_ALPHABLEND;

	if (bma->game.alpha_blend & GEMAT_CLIP)
		gma.m_mode |= gkMaterialProperties::MA_ALPHACLIP;

	// textures
	if (bma->mtex != 0)
	{
		gma.m_totaltex = 0;

		for (int i = 0; i < MAX_MTEX; i++)
		{
			if (!bma->mtex[i] || !bma->mtex[i]->tex)
				continue;

			if (bma->mtex[i]->tex->type == TEX_IMAGE)
			{
				Blender::MTex* mtex = bma->mtex[i];

				Blender::Image* ima = mtex->tex->ima;
				if (!ima)
					continue;

				gkTextureProperties& gte = gma.m_textures[gma.m_totaltex++];
				gte.m_image = gte.m_name = GKB_IDNAME(ima);

				if (mtex->texflag & MTEX_STENCIL)
				{
					gte.m_mode |= gkTextureProperties::TM_SPLAT;
					gte.m_texmode |= gkTextureProperties::TX_STENCIL;
				}
				if (mtex->texflag & MTEX_NEGATIVE)
					gte.m_texmode |= gkTextureProperties::TX_NEGATIVE;
				if (mtex->texflag &  MTEX_RGBTOINT)
					gte.m_texmode |= gkTextureProperties::TX_RGBTOINTEN;

				if (mtex->mapto & MAP_ALPHA)
				{
					gte.m_mode |= gkTextureProperties::TM_ALPHA;
					gma.m_mode |= gkMaterialProperties::MA_ALPHABLEND;
				}
				if ((mtex->mapto & MAP_NORM) || (mtex->maptoneg & MAP_NORM))
				{
					gte.m_mode |= gkTextureProperties::TM_NORMAL;
					gma.m_tangentLayer = i;
				}
				if ((mtex->mapto & MAP_SPEC) || (mtex->maptoneg & MAP_SPEC))
					gte.m_mode |= gkTextureProperties::TM_SPECULAR;
				if ((mtex->mapto & MAP_REF)  || (mtex->maptoneg & MAP_REF))
					gte.m_mode |= gkTextureProperties::TM_REFRACTION;
				if ((mtex->mapto & MAP_EMIT) || (mtex->maptoneg & MAP_EMIT))
					gte.m_mode |= gkTextureProperties::TM_EMMISIVE;

				if (mtex->normapspace == MTEX_NSPACE_OBJECT) //else set to tagent space.
					gte.m_texmode |= gkTextureProperties::TX_OBJ_SPACE;

				gte.m_blend = getTexBlendType(mtex->blendtype);				

				gte.m_layer = findTextureLayer(mtex);
				gte.m_mix   = mtex->colfac;				

				gte.m_normalFactor = mtex->norfac;
				gte.m_diffuseColorFactor = mtex->colfac;
				gte.m_diffuseAlpahFactor = mtex->alphafac;
				gte.m_speculaColorFactor = mtex->colspecfac;
				gte.m_speculaHardFactor = mtex->hardfac;

				gte.m_scale.x = 1/mtex->size[0];
				gte.m_scale.y = 1/mtex->size[1];
				gte.m_scale.z = 1/mtex->size[2];
			}
		}
	}
}
void akMeshLoader::convertMaterial(Blender::Material* bma, akSubMeshPair* subpair)
{
    akMaterial& ma = subpair->item->getMaterial();
    akSubMeshHashKey& hk = subpair->test;

    ma.m_mode = hk.m_mode;

//	ma.m_name          = GKB_IDNAME(bma);
    ma.m_hardness      = bma->har / 4.f;
    ma.m_refraction    = bma->ref;
    ma.m_emissive      = bma->emit;
    ma.m_ambient       = bma->amb;
    ma.m_spec          = bma->spec;
    ma.m_alpha         = bma->alpha;
    ma.m_diffuse       = akColor(bma->r, bma->g, bma->b);
    ma.m_specular      = akColor(bma->specr, bma->specg, bma->specb);
    ma.m_blend		= akMeshLoaderUtils_getRampBlendType(bma->rampblend_col);

    if (bma->mode & MA_ZTRA)        ma.m_mode |= akMaterial::MA_DEPTHWRITE;
    if (bma->mode & MA_SHADOW)      ma.m_mode |= akMaterial::MA_RECEIVESHADOWS;
    if (bma->mode & MA_WIRE)        ma.m_mode |= akMaterial::MA_WIREFRAME;
    if (!(bma->mode & MA_SHLESS))   ma.m_mode |= akMaterial::MA_LIGHTINGENABLED;
    if (bma->alpha <= 0.f)          ma.m_mode |= akMaterial::MA_INVISIBLE;
    if (bma->mode & MA_RAMP_COL)	ma.m_mode |= akMaterial::MA_HASRAMPBLEND;


    // textures
    if (bma->mtex != 0)
    {
        ma.m_totaltex = 0;

        for (int i = 0; i < MAX_MTEX; i++)
        {
            if (!bma->mtex[i] || !bma->mtex[i]->tex)
                continue;

            if (bma->mtex[i]->tex->type == TEX_IMAGE)
            {
                Blender::MTex* mtex = bma->mtex[i];

                Blender::Image* ima = mtex->tex->ima;
                if (!ima)
                    continue;

                akTexture tex;
//				tex.m_name = AKB_IDNAME(ima);
                tex.m_image = AKB_IDNAME(ima);

                if (mtex->texflag & MTEX_STENCIL)
                {
                    tex.m_mode |= akTexture::TM_SPLAT;
                    tex.m_texmode |= akTexture::TX_STENCIL;
                }
                if (mtex->texflag & MTEX_NEGATIVE)
                    tex.m_texmode |= akTexture::TX_NEGATIVE;
                if (mtex->texflag &  MTEX_RGBTOINT)
                    tex.m_texmode |= akTexture::TX_RGBTOINTEN;

                if (mtex->mapto & MAP_ALPHA)
                {
                    tex.m_mode |= akTexture::TM_ALPHA;
                    ma.m_mode |= akMaterial::MA_ALPHABLEND;
                }
                if ((mtex->mapto & MAP_NORM) || (mtex->maptoneg & MAP_NORM))
                    tex.m_mode |= akTexture::TM_NORMAL;
                if ((mtex->mapto & MAP_SPEC) || (mtex->maptoneg & MAP_SPEC))
                    tex.m_mode |= akTexture::TM_SPECULAR;
                if ((mtex->mapto & MAP_REF)  || (mtex->maptoneg & MAP_REF))
                    tex.m_mode |= akTexture::TM_REFRACTION;
                if ((mtex->mapto & MAP_EMIT) || (mtex->maptoneg & MAP_EMIT))
                    tex.m_mode |= akTexture::TM_EMMISIVE;

                if (mtex->normapspace == MTEX_NSPACE_OBJECT) //else set to tagent space.
                    tex.m_texmode |= akTexture::TX_OBJ_SPACE;

                tex.m_blend = akMeshLoaderUtils_getTexBlendType(mtex->blendtype);

                tex.m_layer = findTextureLayer(mtex);
                tex.m_mix   = mtex->colfac;

                tex.m_normalFactor = mtex->norfac;
                tex.m_diffuseColorFactor = mtex->colfac;
                tex.m_diffuseAlphaFactor = mtex->alphafac;
                tex.m_specularColorFactor = mtex->colspecfac;
                tex.m_specularHardFactor = mtex->hardfac;

                ma.m_textures.push_back(tex);
                ma.m_totaltex++;
            }
        }
    }
}