|
@@ -248,42 +248,58 @@ private:
|
|
SetShadingPropertiesCommon(out_mat,props);
|
|
SetShadingPropertiesCommon(out_mat,props);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
- void SetShadingPropertiesCommon(aiMaterial* out_mat, const PropertyTable& props)
|
|
|
|
|
|
+ aiColor3D GetColorPropertyFromMaterial(const PropertyTable& props,const std::string& baseName, bool& result)
|
|
{
|
|
{
|
|
- // set shading properties. There are various, redundant ways in which FBX materials
|
|
|
|
- // specify their shading settings (depending on shading models, prop
|
|
|
|
- // template etc.). No idea which one is right in a particular context.
|
|
|
|
- // Just try to make sense of it - there's no spec to verify this against,
|
|
|
|
- // so why should we.
|
|
|
|
|
|
+ result = true;
|
|
|
|
+
|
|
bool ok;
|
|
bool ok;
|
|
- const aiVector3D& Diffuse = PropertyGet<aiVector3D>(props,"Diffuse",ok);
|
|
|
|
|
|
+ const aiVector3D& Diffuse = PropertyGet<aiVector3D>(props,baseName,ok);
|
|
if(ok) {
|
|
if(ok) {
|
|
- out_mat->AddProperty(&Diffuse,1,AI_MATKEY_COLOR_DIFFUSE);
|
|
|
|
|
|
+ return aiColor3D(Diffuse.x,Diffuse.y,Diffuse.z);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- aiVector3D DiffuseColor = PropertyGet<aiVector3D>(props,"DiffuseColor",ok);
|
|
|
|
|
|
+ aiVector3D DiffuseColor = PropertyGet<aiVector3D>(props,baseName + "Color",ok);
|
|
if(ok) {
|
|
if(ok) {
|
|
- float DiffuseFactor = PropertyGet<float>(props,"DiffuseFactor",ok);
|
|
|
|
|
|
+ float DiffuseFactor = PropertyGet<float>(props,baseName + "Factor",ok);
|
|
if(ok) {
|
|
if(ok) {
|
|
DiffuseColor *= DiffuseFactor;
|
|
DiffuseColor *= DiffuseFactor;
|
|
}
|
|
}
|
|
|
|
|
|
- out_mat->AddProperty(&DiffuseColor,1,AI_MATKEY_COLOR_DIFFUSE);
|
|
|
|
|
|
+ return aiColor3D(DiffuseColor.x,DiffuseColor.y,DiffuseColor.z);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ result = false;
|
|
|
|
+ return aiColor3D(0.0f,0.0f,0.0f);
|
|
|
|
+ }
|
|
|
|
|
|
- const aiVector3D& Emissive = PropertyGet<aiVector3D>(props,"Emissive",ok);
|
|
|
|
|
|
+
|
|
|
|
+ // ------------------------------------------------------------------------------------------------
|
|
|
|
+ void SetShadingPropertiesCommon(aiMaterial* out_mat, const PropertyTable& props)
|
|
|
|
+ {
|
|
|
|
+ // set shading properties. There are various, redundant ways in which FBX materials
|
|
|
|
+ // specify their shading settings (depending on shading models, prop
|
|
|
|
+ // template etc.). No idea which one is right in a particular context.
|
|
|
|
+ // Just try to make sense of it - there's no spec to verify this against,
|
|
|
|
+ // so why should we.
|
|
|
|
+ bool ok;
|
|
|
|
+ const aiColor3D& Diffuse = GetColorPropertyFromMaterial(props,"Diffuse",ok);
|
|
|
|
+ if(ok) {
|
|
|
|
+ out_mat->AddProperty(&Diffuse,1,AI_MATKEY_COLOR_EMISSIVE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const aiColor3D& Emissive = GetColorPropertyFromMaterial(props,"Emissive",ok);
|
|
if(ok) {
|
|
if(ok) {
|
|
out_mat->AddProperty(&Emissive,1,AI_MATKEY_COLOR_EMISSIVE);
|
|
out_mat->AddProperty(&Emissive,1,AI_MATKEY_COLOR_EMISSIVE);
|
|
}
|
|
}
|
|
|
|
|
|
- const aiVector3D& Ambient = PropertyGet<aiVector3D>(props,"Ambient",ok);
|
|
|
|
|
|
+ const aiColor3D& Ambient = GetColorPropertyFromMaterial(props,"Ambient",ok);
|
|
if(ok) {
|
|
if(ok) {
|
|
out_mat->AddProperty(&Ambient,1,AI_MATKEY_COLOR_AMBIENT);
|
|
out_mat->AddProperty(&Ambient,1,AI_MATKEY_COLOR_AMBIENT);
|
|
}
|
|
}
|
|
|
|
|
|
- const aiVector3D& Specular = PropertyGet<aiVector3D>(props,"Specular",ok);
|
|
|
|
|
|
+ const aiColor3D& Specular = GetColorPropertyFromMaterial(props,"Specular",ok);
|
|
if(ok) {
|
|
if(ok) {
|
|
out_mat->AddProperty(&Specular,1,AI_MATKEY_COLOR_SPECULAR);
|
|
out_mat->AddProperty(&Specular,1,AI_MATKEY_COLOR_SPECULAR);
|
|
}
|
|
}
|
|
@@ -325,10 +341,12 @@ private:
|
|
std::swap_ranges(meshes.begin(),meshes.end(),out->mMeshes);
|
|
std::swap_ranges(meshes.begin(),meshes.end(),out->mMeshes);
|
|
|
|
|
|
|
|
|
|
- out->mMaterials = new aiMaterial*[meshes.size()]();
|
|
|
|
- out->mNumMaterials = static_cast<unsigned int>(materials.size());
|
|
|
|
|
|
+ if(materials.size()) {
|
|
|
|
+ out->mMaterials = new aiMaterial*[materials.size()]();
|
|
|
|
+ out->mNumMaterials = static_cast<unsigned int>(materials.size());
|
|
|
|
|
|
- std::swap_ranges(materials.begin(),materials.end(),out->mMaterials);
|
|
|
|
|
|
+ std::swap_ranges(materials.begin(),materials.end(),out->mMaterials);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|