Example #1
0
void ShadingManager::SetMaterialProperty(const KFbxSurfaceMaterial * pMaterial,
		const char * pPropertyName,
		const char * pFactorPropertyName,
		unsigned int pOGLProperty) const
{
	const KFbxProperty lProperty = pMaterial->FindProperty(pPropertyName);
	const KFbxProperty lFactorProperty = pMaterial->FindProperty(pFactorPropertyName);
	if (lProperty.IsValid() && lFactorProperty.IsValid())
	{
		fbxDouble3 lColor = fbxDouble3(0, 0, 0);
		lColor = lProperty.Get(&lColor);
		double lFactor = 1;
		lFactor = lFactorProperty.Get(&lFactor);
		if (lFactor != 1)
		{
			lColor[0] *= lFactor;
			lColor[1] *= lFactor;
			lColor[2] *= lFactor;
		}

		const GLfloat lMaterial[] = {(GLfloat)lColor[0], (GLfloat)lColor[1], (GLfloat)lColor[2], 1.0f};
		glMaterialfv(GL_FRONT, pOGLProperty, lMaterial);
	}
}
Example #2
0
void ShadingManager::SetMaterial(const KFbxNode * pNode, int pMaterialIndex) const
{
	const KFbxSurfaceMaterial * lSurfaceMaterial = pNode->GetMaterial(pMaterialIndex);
	if (!lSurfaceMaterial)
		return;

	if (lSurfaceMaterial == mLastMaterial)
		return;

	mLastMaterial = lSurfaceMaterial;

	SetMaterialProperty(lSurfaceMaterial, KFbxSurfaceMaterial::sEmissive, KFbxSurfaceMaterial::sEmissiveFactor, GL_EMISSION);

	SetMaterialProperty(lSurfaceMaterial, KFbxSurfaceMaterial::sAmbient, KFbxSurfaceMaterial::sAmbientFactor, GL_AMBIENT);

	const TextureObjectsForMaterialType::RecordType * lRecord = mTextureObjectsForMaterial.Find(lSurfaceMaterial);
	if (lRecord)
	{
		glBindTexture(GL_TEXTURE_2D, lRecord->GetValue());
		mLastTextureObject = lRecord->GetValue();
	}
	else
	{
		mLastTextureObject = 0;
	}

	if (!mLastTextureObject)
	{
		SetMaterialProperty(lSurfaceMaterial, KFbxSurfaceMaterial::sDiffuse, KFbxSurfaceMaterial::sDiffuseFactor, GL_DIFFUSE);
	}

	SetMaterialProperty(lSurfaceMaterial, KFbxSurfaceMaterial::sSpecular, KFbxSurfaceMaterial::sSpecularFactor, GL_SPECULAR);
	KFbxProperty lShininessProperty = lSurfaceMaterial->FindProperty(KFbxSurfaceMaterial::sShininess);
	if (lShininessProperty.IsValid())
	{
		double lShininess = 0;
		lShininess = lShininessProperty.Get(&lShininess);
		glMaterialf(GL_FRONT, GL_SHININESS, (GLfloat)lShininess);
	}
}