Merge branch 'master' into feat-stingray-pbs
This commit is contained in:
commit
9df6a5d8b5
|
@ -26,7 +26,6 @@ endif()
|
||||||
|
|
||||||
# DRACO
|
# DRACO
|
||||||
ExternalProject_Add(Draco
|
ExternalProject_Add(Draco
|
||||||
UPDATE_DISCONNECTED TRUE
|
|
||||||
GIT_REPOSITORY https://github.com/google/draco
|
GIT_REPOSITORY https://github.com/google/draco
|
||||||
PREFIX draco
|
PREFIX draco
|
||||||
INSTALL_DIR
|
INSTALL_DIR
|
||||||
|
@ -44,9 +43,9 @@ endif()
|
||||||
set(mathfu_build_benchmarks OFF CACHE BOOL "")
|
set(mathfu_build_benchmarks OFF CACHE BOOL "")
|
||||||
set(mathfu_build_tests OFF CACHE BOOL "")
|
set(mathfu_build_tests OFF CACHE BOOL "")
|
||||||
ExternalProject_Add(MathFu
|
ExternalProject_Add(MathFu
|
||||||
UPDATE_DISCONNECTED TRUE
|
|
||||||
GIT_REPOSITORY https://github.com/google/mathfu
|
|
||||||
PREFIX mathfu
|
PREFIX mathfu
|
||||||
|
GIT_REPOSITORY https://github.com/google/mathfu
|
||||||
|
GIT_TAG v1.1.0
|
||||||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "Skipping MathFu configure step."
|
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "Skipping MathFu configure step."
|
||||||
BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Skipping MathFu build step."
|
BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Skipping MathFu build step."
|
||||||
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping MathFu install step."
|
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping MathFu install step."
|
||||||
|
@ -57,9 +56,9 @@ set(MATHFU_INCLUDE_DIRS
|
||||||
|
|
||||||
# JSON
|
# JSON
|
||||||
ExternalProject_Add(Json
|
ExternalProject_Add(Json
|
||||||
UPDATE_DISCONNECTED TRUE
|
|
||||||
GIT_REPOSITORY https://github.com/nlohmann/json
|
|
||||||
PREFIX json
|
PREFIX json
|
||||||
|
GIT_REPOSITORY https://github.com/nlohmann/json
|
||||||
|
GIT_TAG v2.1.1
|
||||||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "Skipping JSON configure step."
|
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "Skipping JSON configure step."
|
||||||
BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Skipping JSON build step."
|
BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Skipping JSON build step."
|
||||||
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping JSON install step."
|
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping JSON install step."
|
||||||
|
@ -68,9 +67,8 @@ set(JSON_INCLUDE_DIR "${CMAKE_BINARY_DIR}/json/src/Json/src")
|
||||||
|
|
||||||
# cppcodec
|
# cppcodec
|
||||||
ExternalProject_Add(CPPCodec
|
ExternalProject_Add(CPPCodec
|
||||||
UPDATE_DISCONNECTED TRUE
|
|
||||||
GIT_REPOSITORY https://github.com/tplgy/cppcodec
|
|
||||||
PREFIX cppcodec
|
PREFIX cppcodec
|
||||||
|
GIT_REPOSITORY https://github.com/tplgy/cppcodec
|
||||||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "Skipping CPPCodec configure step."
|
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "Skipping CPPCodec configure step."
|
||||||
BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Skipping CPPCodec build step."
|
BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Skipping CPPCodec build step."
|
||||||
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping CPPCodec install step."
|
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping CPPCodec install step."
|
||||||
|
@ -79,8 +77,8 @@ set(CPPCODEC_INCLUDE_DIR "${CMAKE_BINARY_DIR}/cppcodec/src/CPPCodec")
|
||||||
|
|
||||||
# CXXOPTS
|
# CXXOPTS
|
||||||
ExternalProject_Add(CxxOpts
|
ExternalProject_Add(CxxOpts
|
||||||
UPDATE_DISCONNECTED TRUE
|
|
||||||
GIT_REPOSITORY https://github.com/jarro2783/cxxopts
|
GIT_REPOSITORY https://github.com/jarro2783/cxxopts
|
||||||
|
GIT_TAG v1.4.4
|
||||||
PREFIX cxxopts
|
PREFIX cxxopts
|
||||||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "Skipping cxxopts configure step."
|
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "Skipping cxxopts configure step."
|
||||||
BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Skipping cxxopts build step."
|
BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Skipping cxxopts build step."
|
||||||
|
@ -90,12 +88,12 @@ set(CXXOPTS_INCLUDE_DIR "${CMAKE_BINARY_DIR}/cxxopts/src/CxxOpts/include")
|
||||||
|
|
||||||
# FMT
|
# FMT
|
||||||
ExternalProject_Add(Fmt
|
ExternalProject_Add(Fmt
|
||||||
UPDATE_DISCONNECTED TRUE
|
PREFIX fmt
|
||||||
GIT_REPOSITORY https://github.com/fmtlib/fmt
|
GIT_REPOSITORY https://github.com/fmtlib/fmt
|
||||||
|
GIT_TAG 4.0.0
|
||||||
CMAKE_CACHE_ARGS "-DFMT_DOC:BOOL=OFF" "-DFMT_INSTALL:BOOL=ON" "-DFMT_TEST:BOOL=OFF"
|
CMAKE_CACHE_ARGS "-DFMT_DOC:BOOL=OFF" "-DFMT_INSTALL:BOOL=ON" "-DFMT_TEST:BOOL=OFF"
|
||||||
CMAKE_ARGS
|
CMAKE_ARGS
|
||||||
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
|
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
|
||||||
PREFIX fmt
|
|
||||||
)
|
)
|
||||||
set(FMT_INCLUDE_DIR "${CMAKE_BINARY_DIR}/fmt/include")
|
set(FMT_INCLUDE_DIR "${CMAKE_BINARY_DIR}/fmt/include")
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|
19
README.md
19
README.md
|
@ -48,6 +48,10 @@ Usage:
|
||||||
--pbr-specular-glossiness
|
--pbr-specular-glossiness
|
||||||
(WIP) Experimentally fill in the
|
(WIP) Experimentally fill in the
|
||||||
KHR_materials_pbrSpecularGlossiness extension.
|
KHR_materials_pbrSpecularGlossiness extension.
|
||||||
|
--blend-shape-normals Include blend shape normals, if reported
|
||||||
|
present by the FBX SDK.
|
||||||
|
--blend-shape-tangents Include blend shape tangents, if reported
|
||||||
|
present by the FBX SDK.
|
||||||
-k, --keep-attribute arg Used repeatedly to build a limiting set of
|
-k, --keep-attribute arg Used repeatedly to build a limiting set of
|
||||||
vertex attributes to keep.
|
vertex attributes to keep.
|
||||||
-v, --verbose Enable verbose output.
|
-v, --verbose Enable verbose output.
|
||||||
|
@ -81,6 +85,13 @@ Some of these switches are not obvious:
|
||||||
the conversion process. This is a way to trim the size of the resulting glTF
|
the conversion process. This is a way to trim the size of the resulting glTF
|
||||||
if you know the FBX contains superfluous attributes. The supported arguments
|
if you know the FBX contains superfluous attributes. The supported arguments
|
||||||
are `position`, `normal`, `tangent`, `color`, `uv0`, and `uv1`.
|
are `position`, `normal`, `tangent`, `color`, `uv0`, and `uv1`.
|
||||||
|
- When **blend shapes** are present, you may use `--blend-shape-normals` and
|
||||||
|
`--blend-shape-tangents` to include normal and tangent attributes in the glTF
|
||||||
|
morph targets. They are not included by default because they rarely or never
|
||||||
|
seem to be correctly present in the actual FBX source, which means the SDK
|
||||||
|
must be computing them from geometry, unasked? In any case, they are beyond
|
||||||
|
the control of the artist, and can yield strange crinkly behaviour. Since
|
||||||
|
they also take up significant space in the output file, we made them opt-in.
|
||||||
|
|
||||||
## Building it on your own
|
## Building it on your own
|
||||||
|
|
||||||
|
@ -124,7 +135,8 @@ As part of this process, you will be asked to choose which generator
|
||||||
to use. **At present, only Visual Studio 2017 is supported.** Older
|
to use. **At present, only Visual Studio 2017 is supported.** Older
|
||||||
versions of the IDE are unlikely to successfully build the tool.
|
versions of the IDE are unlikely to successfully build the tool.
|
||||||
|
|
||||||
*(MinGW support is plausible. Contributions welcome.)*
|
*(MinGW support is plausible. The difficulty is linking statically against the
|
||||||
|
FBX SDK .lib file. Contributions welcome.)*
|
||||||
|
|
||||||
Note that the `CMAKE_BUILD_TYPE` variable from the Unix Makefile system is
|
Note that the `CMAKE_BUILD_TYPE` variable from the Unix Makefile system is
|
||||||
entirely ignored here; it is when you open the generated solution that
|
entirely ignored here; it is when you open the generated solution that
|
||||||
|
@ -150,7 +162,7 @@ node, and whenever we find any node that's rotated, translated or scaled, we
|
||||||
record that fact in the output.
|
record that fact in the output.
|
||||||
|
|
||||||
Beyond skeleton-based animation, *Blend Shapes* are also supported; they are
|
Beyond skeleton-based animation, *Blend Shapes* are also supported; they are
|
||||||
read from the FBX file on a per-mesh basis, and animations can them by varying
|
read from the FBX file on a per-mesh basis, and clips can use them by varying
|
||||||
the weights associated with each one.
|
the weights associated with each one.
|
||||||
|
|
||||||
The baking method has the benefit of being simple and precise. It has the
|
The baking method has the benefit of being simple and precise. It has the
|
||||||
|
@ -165,7 +177,8 @@ There are three future enhancements we hope to see for animations:
|
||||||
it into a long sequence of linear approximations.
|
it into a long sequence of linear approximations.
|
||||||
- We do not yet ever generate
|
- We do not yet ever generate
|
||||||
[sparse accessors](https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#sparse-accessors),
|
[sparse accessors](https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#sparse-accessors),
|
||||||
but many animations would benefit from this storage optimisation.
|
but many animations (especially morph targets) would benefit from this
|
||||||
|
storage optimisation.
|
||||||
- Perhaps most useful in practice is the idea of compressing animation curves
|
- Perhaps most useful in practice is the idea of compressing animation curves
|
||||||
the same way we use Draco to compress meshes (see below). Like geometry,
|
the same way we use Draco to compress meshes (see below). Like geometry,
|
||||||
animations are highly redundant — each new value is highly predictable from
|
animations are highly redundant — each new value is highly predictable from
|
||||||
|
|
|
@ -837,7 +837,7 @@ static void ReadMesh(RawModel &raw, FbxScene *pScene, FbxNode *pNode, const std:
|
||||||
vertex.polarityUv0 = false;
|
vertex.polarityUv0 = false;
|
||||||
|
|
||||||
// flag this triangle as transparent if any of its corner vertices substantially deviates from fully opaque
|
// flag this triangle as transparent if any of its corner vertices substantially deviates from fully opaque
|
||||||
vertexTransparency |= (fabs(fbxColor.mAlpha - 1.0) > 1e-3);
|
vertexTransparency |= colorLayer.LayerPresent() && (fabs(fbxColor.mAlpha - 1.0) > 1e-3);
|
||||||
|
|
||||||
rawSurface.bounds.AddPoint(vertex.position);
|
rawSurface.bounds.AddPoint(vertex.position);
|
||||||
|
|
||||||
|
|
|
@ -477,18 +477,11 @@ ModelData *Raw2Gltf(
|
||||||
|
|
||||||
for (size_t surfaceIndex = 0; surfaceIndex < materialModels.size(); surfaceIndex++) {
|
for (size_t surfaceIndex = 0; surfaceIndex < materialModels.size(); surfaceIndex++) {
|
||||||
const RawModel &surfaceModel = materialModels[surfaceIndex];
|
const RawModel &surfaceModel = materialModels[surfaceIndex];
|
||||||
assert(surfaceModel.GetSurfaceCount() == 1);
|
|
||||||
|
|
||||||
|
assert(surfaceModel.GetSurfaceCount() == 1);
|
||||||
const RawSurface &rawSurface = surfaceModel.GetSurface(0);
|
const RawSurface &rawSurface = surfaceModel.GetSurface(0);
|
||||||
const std::string surfaceName = std::to_string(surfaceIndex) + "_" + rawSurface.name;
|
|
||||||
|
|
||||||
const RawMaterial &rawMaterial = surfaceModel.GetMaterial(surfaceModel.GetTriangle(0).materialIndex);
|
const RawMaterial &rawMaterial = surfaceModel.GetMaterial(surfaceModel.GetTriangle(0).materialIndex);
|
||||||
if (rawMaterial.textures[RAW_TEXTURE_USAGE_DIFFUSE] < 0 &&
|
|
||||||
(surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_COLOR) == 0) {
|
|
||||||
if (verboseOutput) {
|
|
||||||
fmt::printf("Warning: surface %s has neither texture nor vertex colors.\n", surfaceName.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const MaterialData &mData = require(materialsByName, materialHash(rawMaterial));
|
const MaterialData &mData = require(materialsByName, materialHash(rawMaterial));
|
||||||
|
|
||||||
std::string nodeName = rawSurface.nodeName;
|
std::string nodeName = rawSurface.nodeName;
|
||||||
|
@ -622,10 +615,10 @@ ModelData *Raw2Gltf(
|
||||||
auto blendVertex = surfaceModel.GetVertex(jj).blends[channelIx];
|
auto blendVertex = surfaceModel.GetVertex(jj).blends[channelIx];
|
||||||
shapeBounds.AddPoint(blendVertex.position);
|
shapeBounds.AddPoint(blendVertex.position);
|
||||||
positions.push_back(blendVertex.position);
|
positions.push_back(blendVertex.position);
|
||||||
if (channel.hasNormals) {
|
if (options.useBlendShapeTangents && channel.hasNormals) {
|
||||||
normals.push_back(blendVertex.normal);
|
normals.push_back(blendVertex.normal);
|
||||||
}
|
}
|
||||||
if (channel.hasTangents) {
|
if (options.useBlendShapeTangents && channel.hasTangents) {
|
||||||
tangents.push_back(blendVertex.tangent);
|
tangents.push_back(blendVertex.tangent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -636,14 +629,14 @@ ModelData *Raw2Gltf(
|
||||||
pAcc->max = toStdVec(shapeBounds.max);
|
pAcc->max = toStdVec(shapeBounds.max);
|
||||||
|
|
||||||
std::shared_ptr<AccessorData> nAcc;
|
std::shared_ptr<AccessorData> nAcc;
|
||||||
if (channel.hasNormals) {
|
if (!normals.empty()) {
|
||||||
nAcc = gltf->AddAccessorWithView(
|
nAcc = gltf->AddAccessorWithView(
|
||||||
*gltf->GetAlignedBufferView(buffer, BufferViewData::GL_ARRAY_BUFFER),
|
*gltf->GetAlignedBufferView(buffer, BufferViewData::GL_ARRAY_BUFFER),
|
||||||
GLT_VEC3F, normals);
|
GLT_VEC3F, normals);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<AccessorData> tAcc;
|
std::shared_ptr<AccessorData> tAcc;
|
||||||
if (channel.hasTangents) {
|
if (!tangents.empty()) {
|
||||||
nAcc = gltf->AddAccessorWithView(
|
nAcc = gltf->AddAccessorWithView(
|
||||||
*gltf->GetAlignedBufferView(buffer, BufferViewData::GL_ARRAY_BUFFER),
|
*gltf->GetAlignedBufferView(buffer, BufferViewData::GL_ARRAY_BUFFER),
|
||||||
GLT_VEC4F, tangents);
|
GLT_VEC4F, tangents);
|
||||||
|
|
|
@ -53,6 +53,10 @@ struct GltfOptions
|
||||||
bool usePBRMetRough;
|
bool usePBRMetRough;
|
||||||
/** Whether to use KHR_materials_pbrSpecularGlossiness to extend material definitions. */
|
/** Whether to use KHR_materials_pbrSpecularGlossiness to extend material definitions. */
|
||||||
bool usePBRSpecGloss;
|
bool usePBRSpecGloss;
|
||||||
|
/** Whether to include blend shape normals, if present according to the SDK. */
|
||||||
|
bool useBlendShapeNormals;
|
||||||
|
/** Whether to include blend shape tangents, if present according to the SDK. */
|
||||||
|
bool useBlendShapeTangents;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ComponentType {
|
struct ComponentType {
|
||||||
|
|
20
src/main.cpp
20
src/main.cpp
|
@ -44,12 +44,14 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
GltfOptions gltfOptions{
|
GltfOptions gltfOptions{
|
||||||
-1, // keepAttribs
|
-1, // keepAttribs
|
||||||
false, // outputBinary
|
false, // outputBinary
|
||||||
false, // embedResources
|
false, // embedResources
|
||||||
false, // useDraco
|
false, // useDraco
|
||||||
false, // useKHRMatCom
|
false, // useKHRMatCom
|
||||||
false, // usePBRMetRough
|
false, // usePBRMetRough
|
||||||
false // usePBRSpecGloss
|
false, // usePBRSpecGloss
|
||||||
|
false, // useBlendShapeNormals
|
||||||
|
false, // useBlendShapeTangents
|
||||||
};
|
};
|
||||||
|
|
||||||
options.positional_help("[<FBX File>]");
|
options.positional_help("[<FBX File>]");
|
||||||
|
@ -81,6 +83,12 @@ int main(int argc, char *argv[])
|
||||||
(
|
(
|
||||||
"pbr-specular-glossiness", "(WIP) Experimentally fill in the KHR_materials_pbrSpecularGlossiness extension.",
|
"pbr-specular-glossiness", "(WIP) Experimentally fill in the KHR_materials_pbrSpecularGlossiness extension.",
|
||||||
cxxopts::value<bool>(gltfOptions.usePBRSpecGloss))
|
cxxopts::value<bool>(gltfOptions.usePBRSpecGloss))
|
||||||
|
(
|
||||||
|
"blend-shape-normals", "Include blend shape normals, if reported present by the FBX SDK.",
|
||||||
|
cxxopts::value<bool>(gltfOptions.useBlendShapeNormals))
|
||||||
|
(
|
||||||
|
"blend-shape-tangents", "Include blend shape tangents, if reported present by the FBX SDK.",
|
||||||
|
cxxopts::value<bool>(gltfOptions.useBlendShapeTangents))
|
||||||
(
|
(
|
||||||
"k,keep-attribute", "Used repeatedly to build a limiting set of vertex attributes to keep.",
|
"k,keep-attribute", "Used repeatedly to build a limiting set of vertex attributes to keep.",
|
||||||
cxxopts::value<std::vector<std::string>>())
|
cxxopts::value<std::vector<std::string>>())
|
||||||
|
|
Loading…
Reference in New Issue