Delete obsolete classes, poke at Physical Material support.

Looks like I never did the required cleanup after my accidental commit back in August.
This deletes the materials classes that were obsoleted back then, and comments out the
large swathes of PhysicalMaterial code that's not currently doing anything (i.e. all the
materials properties that glTF can't currently represent.)
This commit is contained in:
Par Winzell 2019-01-16 13:52:33 -08:00
parent 1328a4b96f
commit d451aa73f3
13 changed files with 62 additions and 484 deletions

View File

@ -154,20 +154,20 @@ endif()
set(LIB_SOURCE_FILES set(LIB_SOURCE_FILES
src/FBX2glTF.h src/FBX2glTF.h
src/fbx/materials/3dsMaxPhysicalMaterial.cpp
src/fbx/materials/FbxMaterials.cpp
src/fbx/materials/FbxMaterials.hpp
src/fbx/materials/RoughnessMetallicMaterials.hpp
src/fbx/materials/StingrayPBSMaterial.cpp
src/fbx/materials/TraditionalMaterials.cpp
src/fbx/materials/TraditionalMaterials.hpp
src/fbx/Fbx2Raw.cpp src/fbx/Fbx2Raw.cpp
src/fbx/Fbx2Raw.hpp src/fbx/Fbx2Raw.hpp
src/fbx/FbxBlendShapesAccess.cpp src/fbx/FbxBlendShapesAccess.cpp
src/fbx/FbxBlendShapesAccess.hpp src/fbx/FbxBlendShapesAccess.hpp
src/fbx/FbxLayerElementAccess.hpp src/fbx/FbxLayerElementAccess.hpp
src/fbx/FbxMaterialInfo.hpp
src/fbx/FbxMaterialsAccess.cpp
src/fbx/FbxMaterialsAccess.hpp
src/fbx/FbxRoughMetMaterialInfo.cpp
src/fbx/FbxRoughMetMaterialInfo.hpp
src/fbx/FbxSkinningAccess.cpp src/fbx/FbxSkinningAccess.cpp
src/fbx/FbxSkinningAccess.hpp src/fbx/FbxSkinningAccess.hpp
src/fbx/FbxTraditionalMaterialInfo.cpp
src/fbx/FbxTraditionalMaterialInfo.hpp
src/gltf/Raw2Gltf.cpp src/gltf/Raw2Gltf.cpp
src/gltf/Raw2Gltf.hpp src/gltf/Raw2Gltf.hpp
src/gltf/GltfModel.cpp src/gltf/GltfModel.cpp

View File

@ -29,8 +29,9 @@
#include "FbxBlendShapesAccess.hpp" #include "FbxBlendShapesAccess.hpp"
#include "FbxLayerElementAccess.hpp" #include "FbxLayerElementAccess.hpp"
#include "FbxMaterialsAccess.hpp"
#include "FbxSkinningAccess.hpp" #include "FbxSkinningAccess.hpp"
#include "materials/RoughnessMetallicMaterials.hpp"
#include "materials/TraditionalMaterials.hpp"
float scaleFactor; float scaleFactor;
@ -236,7 +237,7 @@ static void ReadMesh(
FbxRoughMetMaterialInfo* fbxMatInfo = FbxRoughMetMaterialInfo* fbxMatInfo =
static_cast<FbxRoughMetMaterialInfo*>(fbxMaterial.get()); static_cast<FbxRoughMetMaterialInfo*>(fbxMaterial.get());
maybeAddTexture(fbxMatInfo->texColor, RAW_TEXTURE_USAGE_ALBEDO); maybeAddTexture(fbxMatInfo->texBaseColor, RAW_TEXTURE_USAGE_ALBEDO);
maybeAddTexture(fbxMatInfo->texNormal, RAW_TEXTURE_USAGE_NORMAL); maybeAddTexture(fbxMatInfo->texNormal, RAW_TEXTURE_USAGE_NORMAL);
maybeAddTexture(fbxMatInfo->texEmissive, RAW_TEXTURE_USAGE_EMISSIVE); maybeAddTexture(fbxMatInfo->texEmissive, RAW_TEXTURE_USAGE_EMISSIVE);
maybeAddTexture(fbxMatInfo->texRoughness, RAW_TEXTURE_USAGE_ROUGHNESS); maybeAddTexture(fbxMatInfo->texRoughness, RAW_TEXTURE_USAGE_ROUGHNESS);
@ -244,8 +245,8 @@ static void ReadMesh(
maybeAddTexture(fbxMatInfo->texAmbientOcclusion, RAW_TEXTURE_USAGE_OCCLUSION); maybeAddTexture(fbxMatInfo->texAmbientOcclusion, RAW_TEXTURE_USAGE_OCCLUSION);
rawMatProps.reset(new RawMetRoughMatProps( rawMatProps.reset(new RawMetRoughMatProps(
RAW_SHADING_MODEL_PBR_MET_ROUGH, RAW_SHADING_MODEL_PBR_MET_ROUGH,
toVec4f(fbxMatInfo->colBase), toVec4f(fbxMatInfo->baseColor),
toVec3f(fbxMatInfo->colEmissive), toVec3f(fbxMatInfo->emissive),
fbxMatInfo->emissiveIntensity, fbxMatInfo->emissiveIntensity,
fbxMatInfo->metallic, fbxMatInfo->metallic,
fbxMatInfo->roughness)); fbxMatInfo->roughness));

View File

@ -1,21 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#pragma once
#include "FBX2glTF.h"
class FbxMaterialInfo {
public:
FbxMaterialInfo(const FbxString& name, const FbxString& shadingModel)
: name(name), shadingModel(shadingModel) {}
const FbxString name;
const FbxString shadingModel;
};

View File

@ -1,104 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "FbxMaterialsAccess.hpp"
#include "Fbx2Raw.hpp"
FbxMaterialsAccess::FbxMaterialsAccess(
const FbxMesh* pMesh,
const std::map<const FbxTexture*, FbxString>& textureLocations)
: mappingMode(FbxGeometryElement::eNone), mesh(nullptr), indices(nullptr) {
if (pMesh->GetElementMaterialCount() <= 0) {
return;
}
const FbxGeometryElement::EMappingMode materialMappingMode =
pMesh->GetElementMaterial()->GetMappingMode();
if (materialMappingMode != FbxGeometryElement::eByPolygon &&
materialMappingMode != FbxGeometryElement::eAllSame) {
return;
}
const FbxGeometryElement::EReferenceMode materialReferenceMode =
pMesh->GetElementMaterial()->GetReferenceMode();
if (materialReferenceMode != FbxGeometryElement::eIndexToDirect) {
return;
}
mappingMode = materialMappingMode;
mesh = pMesh;
indices = &pMesh->GetElementMaterial()->GetIndexArray();
for (int ii = 0; ii < indices->GetCount(); ii++) {
int materialNum = indices->GetAt(ii);
if (materialNum < 0) {
continue;
}
FbxSurfaceMaterial* surfaceMaterial =
mesh->GetNode()->GetSrcObject<FbxSurfaceMaterial>(materialNum);
if (materialNum >= summaries.size()) {
summaries.resize(materialNum + 1);
}
auto summary = summaries[materialNum];
if (summary == nullptr) {
summary = summaries[materialNum] = GetMaterialInfo(surfaceMaterial, textureLocations);
}
if (materialNum >= userProperties.size()) {
userProperties.resize(materialNum + 1);
}
if (userProperties[materialNum].empty()) {
FbxProperty objectProperty = surfaceMaterial->GetFirstProperty();
while (objectProperty.IsValid()) {
if (objectProperty.GetFlag(FbxPropertyFlags::eUserDefined)) {
userProperties[materialNum].push_back(TranscribeProperty(objectProperty).dump());
}
objectProperty = surfaceMaterial->GetNextProperty(objectProperty);
}
}
}
}
const std::shared_ptr<FbxMaterialInfo> FbxMaterialsAccess::GetMaterial(
const int polygonIndex) const {
if (mappingMode != FbxGeometryElement::eNone) {
const int materialNum =
indices->GetAt((mappingMode == FbxGeometryElement::eByPolygon) ? polygonIndex : 0);
if (materialNum < 0) {
return nullptr;
}
return summaries.at((unsigned long)materialNum);
}
return nullptr;
}
const std::vector<std::string> FbxMaterialsAccess::GetUserProperties(const int polygonIndex) const {
if (mappingMode != FbxGeometryElement::eNone) {
const int materialNum =
indices->GetAt((mappingMode == FbxGeometryElement::eByPolygon) ? polygonIndex : 0);
if (materialNum < 0) {
return std::vector<std::string>();
}
return userProperties.at((unsigned long)materialNum);
}
return std::vector<std::string>();
}
std::unique_ptr<FbxMaterialInfo> FbxMaterialsAccess::GetMaterialInfo(
FbxSurfaceMaterial* material,
const std::map<const FbxTexture*, FbxString>& textureLocations) {
std::unique_ptr<FbxMaterialInfo> res;
res = FbxRoughMetMaterialInfo::From(material, textureLocations);
if (!res) {
res = FbxTraditionalMaterialInfo::From(material, textureLocations);
}
return res;
}

View File

@ -1,37 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#pragma once
#include "Fbx2Raw.hpp"
#include "FbxMaterialInfo.hpp"
#include "FbxRoughMetMaterialInfo.hpp"
#include "FbxTraditionalMaterialInfo.hpp"
class FbxMaterialsAccess {
public:
FbxMaterialsAccess(
const FbxMesh* pMesh,
const std::map<const FbxTexture*, FbxString>& textureLocations);
const std::shared_ptr<FbxMaterialInfo> GetMaterial(const int polygonIndex) const;
const std::vector<std::string> GetUserProperties(const int polygonIndex) const;
std::unique_ptr<FbxMaterialInfo> GetMaterialInfo(
FbxSurfaceMaterial* material,
const std::map<const FbxTexture*, FbxString>& textureLocations);
private:
FbxGeometryElement::EMappingMode mappingMode;
std::vector<std::shared_ptr<FbxMaterialInfo>> summaries{};
std::vector<std::vector<std::string>> userProperties;
const FbxMesh* mesh;
const FbxLayerElementArrayTemplate<int>* indices;
};

View File

@ -1,73 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "FbxRoughMetMaterialInfo.hpp"
std::unique_ptr<FbxRoughMetMaterialInfo> FbxRoughMetMaterialInfo::From(
FbxSurfaceMaterial* fbxMaterial,
const std::map<const FbxTexture*, FbxString>& textureLocations) {
std::unique_ptr<FbxRoughMetMaterialInfo> res(
new FbxRoughMetMaterialInfo(fbxMaterial->GetName(), FBX_SHADER_METROUGH));
const FbxProperty mayaProp = fbxMaterial->FindProperty("Maya");
if (mayaProp.GetPropertyDataType() != FbxCompoundDT) {
return nullptr;
}
if (!fbxMaterial->ShadingModel.Get().IsEmpty()) {
::fmt::printf(
"Warning: Material %s has surprising shading model: %s\n",
fbxMaterial->GetName(),
fbxMaterial->ShadingModel.Get());
}
auto getTex = [&](std::string propName) {
const FbxFileTexture* ptr = nullptr;
const FbxProperty useProp = mayaProp.FindHierarchical(("use_" + propName + "_map").c_str());
if (useProp.IsValid() && useProp.Get<bool>()) {
const FbxProperty texProp = mayaProp.FindHierarchical(("TEX_" + propName + "_map").c_str());
if (texProp.IsValid()) {
ptr = texProp.GetSrcObject<FbxFileTexture>();
if (ptr != nullptr && textureLocations.find(ptr) == textureLocations.end()) {
ptr = nullptr;
}
}
} else if (verboseOutput && useProp.IsValid()) {
fmt::printf(
"Note: Property '%s' of material '%s' exists, but is flagged as 'do not use'.\n",
propName,
fbxMaterial->GetName());
}
return ptr;
};
auto getVec = [&](std::string propName) -> FbxDouble3 {
const FbxProperty vecProp = mayaProp.FindHierarchical(propName.c_str());
return vecProp.IsValid() ? vecProp.Get<FbxDouble3>() : FbxDouble3(1, 1, 1);
};
auto getVal = [&](std::string propName) -> FbxDouble {
const FbxProperty vecProp = mayaProp.FindHierarchical(propName.c_str());
return vecProp.IsValid() ? vecProp.Get<FbxDouble>() : 0;
};
res->texNormal = getTex("normal");
res->texColor = getTex("color");
res->colBase = getVec("base_color");
res->texAmbientOcclusion = getTex("ao");
res->texEmissive = getTex("emissive");
res->colEmissive = getVec("emissive");
res->emissiveIntensity = getVal("emissive_intensity");
res->texMetallic = getTex("metallic");
res->metallic = getVal("metallic");
res->texRoughness = getTex("roughness");
res->roughness = getVal("roughness");
return res;
}

View File

@ -1,41 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <algorithm>
#include <fstream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "FbxMaterialInfo.hpp"
struct FbxRoughMetMaterialInfo : FbxMaterialInfo {
static constexpr const char* FBX_SHADER_METROUGH = "MetallicRoughness";
static std::unique_ptr<FbxRoughMetMaterialInfo> From(
FbxSurfaceMaterial* fbxMaterial,
const std::map<const FbxTexture*, FbxString>& textureLocations);
FbxRoughMetMaterialInfo(const FbxString& name, const FbxString& shadingModel)
: FbxMaterialInfo(name, shadingModel) {}
const FbxFileTexture* texColor{};
FbxVector4 colBase{};
const FbxFileTexture* texNormal{};
const FbxFileTexture* texMetallic{};
FbxDouble metallic{};
const FbxFileTexture* texRoughness{};
FbxDouble roughness{};
const FbxFileTexture* texEmissive{};
FbxVector4 colEmissive{};
FbxDouble emissiveIntensity{};
const FbxFileTexture* texAmbientOcclusion{};
};

View File

@ -1,137 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "FbxTraditionalMaterialInfo.hpp"
std::unique_ptr<FbxTraditionalMaterialInfo> FbxTraditionalMaterialInfo::From(
FbxSurfaceMaterial* fbxMaterial,
const std::map<const FbxTexture*, FbxString>& textureLocations) {
auto getSurfaceScalar = [&](const char* propName) -> std::tuple<FbxDouble, FbxFileTexture*> {
const FbxProperty prop = fbxMaterial->FindProperty(propName);
FbxDouble val(0);
FbxFileTexture* tex = prop.GetSrcObject<FbxFileTexture>();
if (tex != nullptr && textureLocations.find(tex) == textureLocations.end()) {
tex = nullptr;
}
if (tex == nullptr && prop.IsValid()) {
val = prop.Get<FbxDouble>();
}
return std::make_tuple(val, tex);
};
auto getSurfaceVector = [&](const char* propName) -> std::tuple<FbxDouble3, FbxFileTexture*> {
const FbxProperty prop = fbxMaterial->FindProperty(propName);
FbxDouble3 val(1, 1, 1);
FbxFileTexture* tex = prop.GetSrcObject<FbxFileTexture>();
if (tex != nullptr && textureLocations.find(tex) == textureLocations.end()) {
tex = nullptr;
}
if (tex == nullptr && prop.IsValid()) {
val = prop.Get<FbxDouble3>();
}
return std::make_tuple(val, tex);
};
auto getSurfaceValues =
[&](const char* colName,
const char* facName) -> std::tuple<FbxVector4, FbxFileTexture*, FbxFileTexture*> {
const FbxProperty colProp = fbxMaterial->FindProperty(colName);
const FbxProperty facProp = fbxMaterial->FindProperty(facName);
FbxDouble3 colorVal(1, 1, 1);
FbxDouble factorVal(1);
FbxFileTexture* colTex = colProp.GetSrcObject<FbxFileTexture>();
if (colTex != nullptr && textureLocations.find(colTex) == textureLocations.end()) {
colTex = nullptr;
}
if (colTex == nullptr && colProp.IsValid()) {
colorVal = colProp.Get<FbxDouble3>();
}
FbxFileTexture* facTex = facProp.GetSrcObject<FbxFileTexture>();
if (facTex != nullptr && textureLocations.find(facTex) == textureLocations.end()) {
facTex = nullptr;
}
if (facTex == nullptr && facProp.IsValid()) {
factorVal = facProp.Get<FbxDouble>();
}
auto val = FbxVector4(
colorVal[0] * factorVal, colorVal[1] * factorVal, colorVal[2] * factorVal, factorVal);
return std::make_tuple(val, colTex, facTex);
};
std::string name = fbxMaterial->GetName();
std::unique_ptr<FbxTraditionalMaterialInfo> res(
new FbxTraditionalMaterialInfo(name.c_str(), fbxMaterial->ShadingModel.Get()));
// four properties are on the same structure and follow the same rules
auto handleBasicProperty = [&](const char* colName,
const char* facName) -> std::tuple<FbxVector4, FbxFileTexture*> {
FbxFileTexture *colTex, *facTex;
FbxVector4 vec;
std::tie(vec, colTex, facTex) = getSurfaceValues(colName, facName);
if (colTex) {
if (facTex) {
fmt::printf(
"Warning: Mat [%s]: Can't handle both %s and %s textures; discarding %s.\n",
name,
colName,
facName,
facName);
}
return std::make_tuple(vec, colTex);
}
return std::make_tuple(vec, facTex);
};
std::tie(res->colAmbient, res->texAmbient) =
handleBasicProperty(FbxSurfaceMaterial::sAmbient, FbxSurfaceMaterial::sAmbientFactor);
std::tie(res->colSpecular, res->texSpecular) =
handleBasicProperty(FbxSurfaceMaterial::sSpecular, FbxSurfaceMaterial::sSpecularFactor);
std::tie(res->colDiffuse, res->texDiffuse) =
handleBasicProperty(FbxSurfaceMaterial::sDiffuse, FbxSurfaceMaterial::sDiffuseFactor);
std::tie(res->colEmissive, res->texEmissive) =
handleBasicProperty(FbxSurfaceMaterial::sEmissive, FbxSurfaceMaterial::sEmissiveFactor);
// the normal map can only ever be a map, ignore everything else
tie(std::ignore, res->texNormal) = getSurfaceVector(FbxSurfaceMaterial::sNormalMap);
// shininess can be a map or a factor; afaict the map is always 'ShininessExponent' and the
// value is always found in 'Shininess' but only sometimes in 'ShininessExponent'.
tie(std::ignore, res->texShininess) = getSurfaceScalar("ShininessExponent");
tie(res->shininess, std::ignore) = getSurfaceScalar("Shininess");
// for transparency we just want a constant vector value;
FbxVector4 transparency;
// extract any existing textures only so we can warn that we're throwing them away
FbxFileTexture *colTex, *facTex;
std::tie(transparency, colTex, facTex) = getSurfaceValues(
FbxSurfaceMaterial::sTransparentColor, FbxSurfaceMaterial::sTransparencyFactor);
if (colTex) {
fmt::printf(
"Warning: Mat [%s]: Can't handle texture for %s; discarding.\n",
name,
FbxSurfaceMaterial::sTransparentColor);
}
if (facTex) {
fmt::printf(
"Warning: Mat [%s]: Can't handle texture for %s; discarding.\n",
name,
FbxSurfaceMaterial::sTransparencyFactor);
}
// FBX color is RGB, so we calculate the A channel as the average of the FBX transparency color
// vector
res->colDiffuse[3] = 1.0 - (transparency[0] + transparency[1] + transparency[2]) / 3.0;
return res;
}

View File

@ -1,43 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <algorithm>
#include <fstream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "FbxMaterialInfo.hpp"
struct FbxTraditionalMaterialInfo : FbxMaterialInfo {
static constexpr const char* FBX_SHADER_LAMBERT = "Lambert";
static constexpr const char* FBX_SHADER_BLINN = "Blinn";
static constexpr const char* FBX_SHADER_PHONG = "Phong";
FbxTraditionalMaterialInfo(const FbxString& name, const FbxString& shadingModel)
: FbxMaterialInfo(name, shadingModel) {}
FbxFileTexture* texAmbient{};
FbxVector4 colAmbient{};
FbxFileTexture* texSpecular{};
FbxVector4 colSpecular{};
FbxFileTexture* texDiffuse{};
FbxVector4 colDiffuse{};
FbxFileTexture* texEmissive{};
FbxVector4 colEmissive{};
FbxFileTexture* texNormal{};
FbxFileTexture* texShininess{};
FbxDouble shininess{};
static std::unique_ptr<FbxTraditionalMaterialInfo> From(
FbxSurfaceMaterial* fbxMaterial,
const std::map<const FbxTexture*, FbxString>& textureLocations);
};

View File

@ -73,34 +73,34 @@ std::unique_ptr<FbxRoughMetMaterialInfo> Fbx3dsMaxPhysicalMaterialResolver::reso
} }
// TODO: attempt to bake transparency > 0.0f into the alpha of baseColour? // TODO: attempt to bake transparency > 0.0f into the alpha of baseColour?
double transparency = getValue(props, "transparency", 0.0); // double transparency = getValue(props, "transparency", 0.0);
const auto* transparencyMap = getTex("transparency"); // const auto* transparencyMap = getTex("transparency");
// SSS: not supported // SSS: not supported
double scattering = getValue(props, "scattering", 0.0); // double scattering = getValue(props, "scattering", 0.0);
const auto* scatteringMap = getTex("scattering"); // const auto* scatteringMap = getTex("scattering");
// reflectivity: not supported // reflectivity: not supported
double reflectivityWeight = getValue(props, "reflectivity", 1.); // double reflectivityWeight = getValue(props, "reflectivity", 1.);
const auto* reflectivityWeightMap = getTex("reflectivity"); // const auto* reflectivityWeightMap = getTex("reflectivity");
FbxDouble4 reflectivityColor = getValue(props, "refl_color", FbxDouble4(1, 1, 1, 1)); // FbxDouble4 reflectivityColor = getValue(props, "refl_color", FbxDouble4(1, 1, 1, 1));
const auto* reflectivityColorMap = getTex("refl_color"); // const auto* reflectivityColorMap = getTex("refl_color");
// coatings: not supported // coatings: not supported
double coating = getValue(props, "coating", 0.0); // double coating = getValue(props, "coating", 0.0);
// diffuse roughness: not supported // diffuse roughness: not supported
double diffuseRoughness = getValue(props, "diff_roughness", 0.); // double diffuseRoughness = getValue(props, "diff_roughness", 0.);
// explicit brdf curve control: not supported // explicit brdf curve control: not supported
bool isBrdfMode = getValue(props, "brdf_mode", false); // bool isBrdfMode = getValue(props, "brdf_mode", false);
// anisotrophy: not supported // anisotrophy: not supported
double anisotropy = getValue(props, "anisotropy", 1.0); // double anisotropy = getValue(props, "anisotropy", 1.0);
// TODO: how the heck do we combine these to generate a normal map? // TODO: how the heck do we combine these to generate a normal map?
const auto* bumpMap = getTex("bump"); const auto* bumpMap = getTex("bump");
const auto* displacementMap = getTex("displacement"); // const auto* displacementMap = getTex("displacement");
std::unique_ptr<FbxRoughMetMaterialInfo> res(new FbxRoughMetMaterialInfo( std::unique_ptr<FbxRoughMetMaterialInfo> res(new FbxRoughMetMaterialInfo(
fbxMaterial->GetName(), fbxMaterial->GetName(),

View File

@ -7,6 +7,8 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*/ */
#include "fbx/Fbx2Raw.hpp"
#include "FbxMaterials.hpp" #include "FbxMaterials.hpp"
#include "RoughnessMetallicMaterials.hpp" #include "RoughnessMetallicMaterials.hpp"
#include "TraditionalMaterials.hpp" #include "TraditionalMaterials.hpp"
@ -41,13 +43,29 @@ FbxMaterialsAccess::FbxMaterialsAccess(
if (materialNum < 0) { if (materialNum < 0) {
continue; continue;
} }
FbxSurfaceMaterial* surfaceMaterial =
mesh->GetNode()->GetSrcObject<FbxSurfaceMaterial>(materialNum);
if (materialNum >= summaries.size()) { if (materialNum >= summaries.size()) {
summaries.resize(materialNum + 1); summaries.resize(materialNum + 1);
} }
auto summary = summaries[materialNum]; auto summary = summaries[materialNum];
if (summary == nullptr) { if (summary == nullptr) {
summary = summaries[materialNum] = GetMaterialInfo( summary = summaries[materialNum] = GetMaterialInfo(surfaceMaterial, textureLocations);
mesh->GetNode()->GetSrcObject<FbxSurfaceMaterial>(materialNum), textureLocations); }
if (materialNum >= userProperties.size()) {
userProperties.resize(materialNum + 1);
}
if (userProperties[materialNum].empty()) {
FbxProperty objectProperty = surfaceMaterial->GetFirstProperty();
while (objectProperty.IsValid()) {
if (objectProperty.GetFlag(FbxPropertyFlags::eUserDefined)) {
userProperties[materialNum].push_back(TranscribeProperty(objectProperty).dump());
}
objectProperty = surfaceMaterial->GetNextProperty(objectProperty);
}
} }
} }
} }
@ -65,6 +83,18 @@ const std::shared_ptr<FbxMaterialInfo> FbxMaterialsAccess::GetMaterial(
return nullptr; return nullptr;
} }
const std::vector<std::string> FbxMaterialsAccess::GetUserProperties(const int polygonIndex) const {
if (mappingMode != FbxGeometryElement::eNone) {
const int materialNum =
indices->GetAt((mappingMode == FbxGeometryElement::eByPolygon) ? polygonIndex : 0);
if (materialNum < 0) {
return std::vector<std::string>();
}
return userProperties.at((unsigned long)materialNum);
}
return std::vector<std::string>();
}
std::unique_ptr<FbxMaterialInfo> FbxMaterialsAccess::GetMaterialInfo( std::unique_ptr<FbxMaterialInfo> FbxMaterialsAccess::GetMaterialInfo(
FbxSurfaceMaterial* material, FbxSurfaceMaterial* material,
const std::map<const FbxTexture*, FbxString>& textureLocations) { const std::map<const FbxTexture*, FbxString>& textureLocations) {

View File

@ -45,6 +45,8 @@ class FbxMaterialsAccess {
const std::shared_ptr<FbxMaterialInfo> GetMaterial(const int polygonIndex) const; const std::shared_ptr<FbxMaterialInfo> GetMaterial(const int polygonIndex) const;
const std::vector<std::string> GetUserProperties(const int polygonIndex) const;
std::unique_ptr<FbxMaterialInfo> GetMaterialInfo( std::unique_ptr<FbxMaterialInfo> GetMaterialInfo(
FbxSurfaceMaterial* material, FbxSurfaceMaterial* material,
const std::map<const FbxTexture*, FbxString>& textureLocations); const std::map<const FbxTexture*, FbxString>& textureLocations);
@ -52,6 +54,7 @@ class FbxMaterialsAccess {
private: private:
FbxGeometryElement::EMappingMode mappingMode; FbxGeometryElement::EMappingMode mappingMode;
std::vector<std::shared_ptr<FbxMaterialInfo>> summaries{}; std::vector<std::shared_ptr<FbxMaterialInfo>> summaries{};
std::vector<std::vector<std::string>> userProperties;
const FbxMesh* mesh; const FbxMesh* mesh;
const FbxLayerElementArrayTemplate<int>* indices; const FbxLayerElementArrayTemplate<int>* indices;
}; };

View File

@ -70,8 +70,8 @@ class Fbx3dsMaxPhysicalMaterialResolver : FbxMaterialResolver<FbxRoughMetMateria
private: private:
template <typename T> template <typename T>
T getValue(const FbxProperty& props, std::string propName, const T& default) const { T getValue(const FbxProperty& props, std::string propName, const T& def) const {
const FbxProperty prop = props.FindHierarchical(propName.c_str()); const FbxProperty prop = props.FindHierarchical(propName.c_str());
return prop.IsValid() ? prop.Get<T>() : default; return prop.IsValid() ? prop.Get<T>() : def;
} }
}; };