Clamp FBX values to glTF specifications (#80)
There seem to be few constraints on what values FBX properties can take. By contrast, glTF constrains e.g. common material factors to lie in [0, 1]. We take a simple approach and just clamp.
This commit is contained in:
parent
a8f194f793
commit
362b8bd761
|
@ -36,14 +36,24 @@ void to_json(json &j, const KHRCmnUnlitMaterial &d)
|
||||||
j = json({});
|
j = json({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline float clamp(float d, float bottom = 0, float top = 1) {
|
||||||
|
return std::max(bottom, std::min(top, d));
|
||||||
|
}
|
||||||
|
inline Vec3f clamp(const Vec3f &vec, const Vec3f &bottom = VEC3F_ZERO, const Vec3f &top = VEC3F_ONE) {
|
||||||
|
return Vec3f::Max(bottom, Vec3f::Min(top, vec));
|
||||||
|
}
|
||||||
|
inline Vec4f clamp(const Vec4f &vec, const Vec4f &bottom = VEC4F_ZERO, const Vec4f &top = VEC4F_ONE) {
|
||||||
|
return Vec4f::Max(bottom, Vec4f::Min(top, vec));
|
||||||
|
}
|
||||||
|
|
||||||
PBRMetallicRoughness::PBRMetallicRoughness(
|
PBRMetallicRoughness::PBRMetallicRoughness(
|
||||||
const TextureData *baseColorTexture, const TextureData *metRoughTexture,
|
const TextureData *baseColorTexture, const TextureData *metRoughTexture,
|
||||||
const Vec4f &baseColorFactor, float metallic, float roughness)
|
const Vec4f &baseColorFactor, float metallic, float roughness)
|
||||||
: baseColorTexture(Tex::ref(baseColorTexture)),
|
: baseColorTexture(Tex::ref(baseColorTexture)),
|
||||||
metRoughTexture(Tex::ref(metRoughTexture)),
|
metRoughTexture(Tex::ref(metRoughTexture)),
|
||||||
baseColorFactor(baseColorFactor),
|
baseColorFactor(clamp(baseColorFactor)),
|
||||||
metallic(metallic),
|
metallic(clamp(metallic)),
|
||||||
roughness(roughness)
|
roughness(clamp(roughness))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +88,7 @@ MaterialData::MaterialData(
|
||||||
isTransparent(isTransparent),
|
isTransparent(isTransparent),
|
||||||
normalTexture(Tex::ref(normalTexture)),
|
normalTexture(Tex::ref(normalTexture)),
|
||||||
emissiveTexture(Tex::ref(emissiveTexture)),
|
emissiveTexture(Tex::ref(emissiveTexture)),
|
||||||
emissiveFactor(emissiveFactor),
|
emissiveFactor(clamp(emissiveFactor)),
|
||||||
khrCmnConstantMaterial(khrCmnConstantMaterial),
|
khrCmnConstantMaterial(khrCmnConstantMaterial),
|
||||||
pbrMetallicRoughness(pbrMetallicRoughness) {}
|
pbrMetallicRoughness(pbrMetallicRoughness) {}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,11 @@ typedef mathfu::Matrix<float, 4> Mat4f;
|
||||||
typedef mathfu::Quaternion<float> Quatf;
|
typedef mathfu::Quaternion<float> Quatf;
|
||||||
typedef Bounds<float, 3> Boundsf;
|
typedef Bounds<float, 3> Boundsf;
|
||||||
|
|
||||||
|
const Vec3f VEC3F_ONE = Vec3f {1.0f};
|
||||||
|
const Vec3f VEC3F_ZERO = Vec3f {0.0f};
|
||||||
|
const Vec4f VEC4F_ONE = Vec4f {1.0f};
|
||||||
|
const Vec4f VEC4F_ZERO = Vec4f {0.0f};
|
||||||
|
|
||||||
template<class T, int d> static inline std::vector<T> toStdVec(const mathfu::Vector <T, d> &vec)
|
template<class T, int d> static inline std::vector<T> toStdVec(const mathfu::Vector <T, d> &vec)
|
||||||
{
|
{
|
||||||
std::vector<T> result(d);
|
std::vector<T> result(d);
|
||||||
|
|
Loading…
Reference in New Issue