Skip to content

Commit

Permalink
Add: Composer for writing glTF files
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Jan 28, 2024
1 parent 54c8f2b commit 7823455
Show file tree
Hide file tree
Showing 14 changed files with 702 additions and 17 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler_flags.cmake)
# Create the library target
add_library(fastgltf
"src/fastgltf.cpp" "src/base64.cpp"
"include/fastgltf/base64.hpp" "include/fastgltf/glm_element_traits.hpp" "include/fastgltf/parser.hpp" "include/fastgltf/tools.hpp" "include/fastgltf/types.hpp" "include/fastgltf/util.hpp")
"include/fastgltf/base64.hpp" "include/fastgltf/glm_element_traits.hpp" "include/fastgltf/core.hpp" "include/fastgltf/tools.hpp" "include/fastgltf/types.hpp" "include/fastgltf/util.hpp")
add_library(fastgltf::fastgltf ALIAS fastgltf)

fastgltf_compiler_flags(fastgltf)
Expand Down Expand Up @@ -100,7 +100,7 @@ if (ANDROID)
endif()

install(
FILES "include/fastgltf/base64.hpp" "include/fastgltf/glm_element_traits.hpp" "include/fastgltf/parser.hpp" "include/fastgltf/tools.hpp" "include/fastgltf/types.hpp" "include/fastgltf/util.hpp"
FILES "include/fastgltf/base64.hpp" "include/fastgltf/glm_element_traits.hpp" "include/fastgltf/core.hpp" "include/fastgltf/tools.hpp" "include/fastgltf/types.hpp" "include/fastgltf/util.hpp"
DESTINATION include/fastgltf
)

Expand Down
2 changes: 1 addition & 1 deletion examples/gl_viewer/gl_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

#include <fastgltf/parser.hpp>
#include <fastgltf/core.hpp>
#include <fastgltf/types.hpp>

constexpr std::string_view vertexShaderSource = R"(
Expand Down
28 changes: 28 additions & 0 deletions include/fastgltf/parser.hpp → include/fastgltf/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,34 @@ namespace fastgltf {
void setBase64DecodeCallback(Base64DecodeCallback* decodeCallback) noexcept;
void setUserPointer(void* pointer) noexcept;
};

/**
* A composer for one or more glTF files.
*/
class Composer {
Error errorCode = Error::None;
const Asset* asset = nullptr;

void writeAccessors(std::string& json);
void writeBuffers(std::string& json);
void writeBufferViews(std::string& json);
void writeCameras(std::string& json);
void writeImages(std::string& json);
void writeLights(std::string& json);
void writeMaterials(std::string& json);
void writeMeshes(std::string& json);
void writeNodes(std::string& json);
void writeSamplers(std::string& json);
void writeScenes(std::string& json);
void writeSkins(std::string& json);
void writeTextures(std::string& json);

public:
[[nodiscard]] Error getError() const;

std::string writeGLTF(const Asset* asset);
void writeBinaryGLTF(const Asset* asset);
};
} // namespace fastgltf

#ifdef _MSC_VER
Expand Down
21 changes: 19 additions & 2 deletions include/fastgltf/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,23 @@ namespace fastgltf {
return AccessorType::Invalid;
}
}

static constexpr std::array<std::string_view, 7> accessorTypeNames = {
"SCALAR",
"VEC2",
"VEC3",
"VEC4",
"MAT2",
"MAT3",
"MAT4"
};

constexpr std::string_view getAccessorTypeName(AccessorType type) noexcept {
if (type == AccessorType::Invalid)
return "";
auto idx = to_underlying(type) & 0xFF;
return accessorTypeNames[idx - 1];
}
#pragma endregion

#pragma region Containers
Expand Down Expand Up @@ -1315,9 +1332,9 @@ namespace fastgltf {
};

struct Skin {
FASTGLTF_FG_PMR_NS::MaybeSmallVector<std::size_t> joints;
Optional<std::size_t> skeleton;
Optional<std::size_t> inverseBindMatrices;
Optional<std::size_t> skeleton;
FASTGLTF_FG_PMR_NS::MaybeSmallVector<std::size_t> joints;

FASTGLTF_STD_PMR_NS::string name;
};
Expand Down
Loading

0 comments on commit 7823455

Please sign in to comment.