Beispiel #1
0
		void FbxLoader::FbxLoader::ProcessMaterialTexture2D(FbxSurfaceMaterial* mat, FMaterial& material)
		{
			int Texture2DIndex = 0;
			FbxProperty prop;

			FBXSDK_FOR_EACH_TEXTURE(Texture2DIndex)
			{
				prop = mat->FindProperty(FbxLayerElement::sTextureChannelNames[Texture2DIndex]);
				if(prop.IsValid()) {
					const int Texture2DCount = prop.GetSrcObjectCount<FbxTexture>();
					for(int i = 0; i < Texture2DCount; i++) {
						FbxTexture* texture = prop.GetSrcObject<FbxTexture>(i);
						if(texture) {
							std::string textureType = prop.GetNameAsCStr();
							FbxFileTexture* fileTexture = FbxCast<FbxFileTexture>(texture);
							if(fileTexture) {
								if(textureType == "DiffuseColor")
									material.diffuseMapName = fileTexture->GetRelativeFileName();
								else if(textureType == "SpecularColor")
									material.specularMapName = fileTexture->GetRelativeFileName();
								else if(textureType == "NormalMap") {
									material.normalMapName = fileTexture->GetRelativeFileName();
									useNormalMap = true;
								}
							}
						}
					}

					const int layeredTextureCount = prop.GetSrcObjectCount<FbxLayeredTexture>();
					for(int i = 0; i < layeredTextureCount; i++) {
						auto layeredTexture = prop.GetSrcObject<FbxLayeredTexture>(i);
						const int fileCount = layeredTexture->GetSrcObjectCount<FbxFileTexture>();
						for(int j = 0; j < fileCount; j++) {
							auto fileTexture = layeredTexture->GetSrcObject<FbxFileTexture>(j);
							std::string Texture2DType = prop.GetNameAsCStr();
							if(fileTexture) {
								if(Texture2DType == "DiffuseColor")
									material.diffuseMapName = fileTexture->GetRelativeFileName();
								else if(Texture2DType == "SpecularColor")
									material.specularMapName = fileTexture->GetRelativeFileName();
								else if(Texture2DType == "NormalMap") {
									material.normalMapName = fileTexture->GetRelativeFileName();
									useNormalMap = true;
								}
							}
						}
					}
				}
			}

			if(material.diffuseMapName != "") {
				std::string n = FbxPathUtils::GetFileName(material.diffuseMapName.c_str(), false).Buffer();
				material.name = n;
				mat->SetName(n.c_str());
			}
		}
Beispiel #2
0
void Converter::getDiffuseTextures(FbxSurfaceMaterial *material, std::vector<std::string> &textures)
{
	FbxProperty property = material->FindProperty(FbxLayerElement::sTextureChannelNames[0]);
	if (property.IsValid()) {
		for (int j = 0; j < property.GetSrcObjectCount<FbxTexture>(); ++j) {
			if (!property.GetSrcObject<FbxLayeredTexture>(j)) {
				FbxTexture* texture = property.GetSrcObject<FbxTexture>(j);
				if (texture) {
					std::string textureType = property.GetNameAsCStr();
					FbxFileTexture* fileTexture = FbxCast<FbxFileTexture>(texture);
					if (fileTexture) {
						if (textureType == "DiffuseColor") {
							//std::cout << fileTexture->GetRelativeFileName() << "\n";
							textures.push_back(fileTexture->GetRelativeFileName());
						}
					}
				}
			}
		}
	}
}
Beispiel #3
0
//===============================================================================================================================
void FBXLoader::LoadMaterialTexture(FbxSurfaceMaterial* inMaterial, ZShadeSandboxLighting::ShaderMaterial*& ioMaterial)
{
	uint32 textureIndex = 0;
	FbxProperty property;
	
	FBXSDK_FOR_EACH_TEXTURE(textureIndex)
	{
		property = inMaterial->FindProperty(FbxLayerElement::sTextureChannelNames[textureIndex]);
		if (property.IsValid())
		{
			uint32 textureCount = property.GetSrcObjectCount<FbxTexture>();
			for (uint32 i = 0; i < textureCount; ++i)
			{
				FbxLayeredTexture* layeredTexture = property.GetSrcObject<FbxLayeredTexture>(i);
				if(layeredTexture)
				{
					throw std::exception("Layered Texture is currently unsupported\n");
				}
				else
				{
					FbxTexture* texture = property.GetSrcObject<FbxTexture>(i);
					if (texture)
					{
						std::string textureType = property.GetNameAsCStr();
						FbxFileTexture* fileTexture = FbxCast<FbxFileTexture>(texture);

						if (fileTexture)
						{
							string str_filename(fileTexture->GetFileName());
							std::size_t index = str_filename.find_last_of('/\\');
							if (index != string::npos)
							{
								BetterString str(fileTexture->GetFileName());
								int dot_index = str.get_index('.');
								BetterString pathName = str.substring(index + 1, dot_index);
								BetterString ext = str.substring(dot_index + 1);
								BetterString filename = pathName + "." + ext;
								str_filename = filename.toString();
							}

							if (textureType == "DiffuseColor")
							{
								ioMaterial->sDiffuseTextureName = str_filename;
								ioMaterial->bHasDiffuseTexture = true;
							}
							else if (textureType == "SpecularColor")
							{
								ioMaterial->sSpecularTextureName = str_filename;
								ioMaterial->bHasSpecularTexture = true;
							}
							else if (textureType == "Bump")
							{
								ioMaterial->sNormalMapTextureName = str_filename;
								ioMaterial->bHasNormalMapTexture = true;
							}
						}
					}
				}
			}
		}
	}
	
	ioMaterial->SetD3D(m_pD3DSystem);
	
	bool addToMM = false;
	
	if (ioMaterial->bHasDiffuseTexture)
	{
		ZShadeSandboxLighting::ShaderMaterial* material;
		if (material = MaterialManager::Instance()->GetMaterial(ioMaterial->sMaterialName))
		{
			// The texture has already been loaded
			ioMaterial->SetMaterialDiffuseTexture(material->DiffuseTexture());
		}
		else
		{
			// Need to load new texture
			ioMaterial->AddDiffuseTexture(m_pGD3D->m_textures_path, ioMaterial->sDiffuseTextureName);
			
			addToMM = true;
		}
	}
	
	if (ioMaterial->bHasSpecularTexture)
	{
		ZShadeSandboxLighting::ShaderMaterial* material;
		if (material = MaterialManager::Instance()->GetMaterial(ioMaterial->sMaterialName))
		{
			// The texture has already been loaded
			ioMaterial->SetMaterialSpecularTexture(material->SpecularTexture());
		}
		else
		{
			// Need to load new texture
			ioMaterial->AddDiffuseTexture(m_pGD3D->m_textures_path, ioMaterial->sSpecularTextureName);
			
			addToMM = true;
		}
	}
	
	if (ioMaterial->bHasNormalMapTexture)
	{
		ZShadeSandboxLighting::ShaderMaterial* material;
		if (material = MaterialManager::Instance()->GetMaterial(ioMaterial->sMaterialName))
		{
			// The texture has already been loaded
			ioMaterial->SetMaterialNormalMapTexture(material->NormalMapTexture());
		}
		else
		{
			// Need to load new texture
			ioMaterial->AddDiffuseTexture(m_pGD3D->m_textures_path, ioMaterial->sNormalMapTextureName);
			
			addToMM = true;
		}
	}
	
	if (addToMM)
	{
		MaterialManager::Instance()->Add(ioMaterial);
	}
}
Beispiel #4
0
void FbxMaterial::AddProperty(const FbxProperty &property,
                           const FbxProperty &factor_property)
{




    /**
    *If we are dealing with an invalid properties, abort
    */
    if (!property.IsValid() || !factor_property.IsValid())
        return;




    /**
     *Get the name of the property
     */
    QString property_name = property.GetNameAsCStr();


    /**
    *Based on the property's name, load required stuff
    */
    if (property_name == FbxSurfaceMaterial::sDiffuse)
    {



        /**
         *Get the diffuse color and intensity
         */
        FbxDouble3 diffuse_color = property.Get<FbxDouble3>();
        FbxDouble diffuse_intensity = factor_property.Get<FbxDouble>();



        /**
         *Set diffuse color and intensity
         */
        SetDiffuseColor(aae::mesh_util::QVector3DFromFbxVector3D(diffuse_color));
        SetDiffuseIntensity(diffuse_intensity);




        /**
        *If there are no textures attached to the property, return
        */
        if(!property.GetSrcObjectCount<FbxFileTexture>() > 0)
            return;



        /**
         *Get the texture handler
         */
        FbxFileTexture * texture = property.GetSrcObject<FbxFileTexture>();
        if (!texture)
            return;



        /**
        *Add the diffuse texture name of the material
        */
        AddTexture(diffuse, texture->GetFileName());


    }
    else if (property_name == FbxSurfaceMaterial::sNormalMap)
    {


        /**
        *If there are no textures attached to the property, return
        */
        if(!property.GetSrcObjectCount<FbxFileTexture>() > 0)
            return;


        /**
         *Get the texture handler
         */
        FbxFileTexture * texture = property.GetSrcObject<FbxFileTexture>();
        if (!texture)
            return;


        /**
        *Set normal map texture of the material
        */
        AddTexture(normal, texture->GetFileName());


    }
    else if (property_name == FbxSurfaceMaterial::sSpecular)
    {


        /**
         *Get the specular color and intensity
         */
        FbxDouble3 specular_color = property.Get<FbxDouble3>();
        FbxDouble specular_intensity = factor_property.Get<FbxDouble>();



        /**
        *Set the specular color and intensity
        */
        SetSpecularColor(aae::mesh_util::QVector3DFromFbxVector3D(specular_color));
        SetSpecularIntensity(specular_intensity);



    }
    else if (property_name == FbxSurfaceMaterial::sShininess)
    {


        /**
         *Get and set specular hardness
         */
        FbxDouble specular_hardness = property.Get<FbxDouble>();
        SetSpecularHardness(specular_hardness);


    }





}