Skip to content

Commit

Permalink
Rename ModelLoadFlags to GLTFLoadFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
edunad committed Oct 23, 2024
1 parent 99d5caf commit f4f3415
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions rawrbox.gltf/include/rawrbox/gltf/importer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace rawrbox {
// NOLINTBEGIN(unused-const-variable)
namespace ModelLoadFlags {
namespace GLTFLoadFlags {
const uint32_t NONE = 0;
const uint32_t IMPORT_LIGHT = 1 << 1;
const uint32_t IMPORT_TEXTURES = 1 << 2;
Expand All @@ -41,7 +41,7 @@ namespace rawrbox {
const uint32_t SKELETON_ANIMATIONS = 1 << 21;
} // namespace Optimizer

}; // namespace ModelLoadFlags
}; // namespace GLTFLoadFlags
// NOLINTEND(unused-const-variable)

enum class GLTFImageType : uint32_t {
Expand Down Expand Up @@ -269,7 +269,7 @@ namespace rawrbox {
std::vector<std::unique_ptr<rawrbox::GLTFMesh>> meshes = {};
// ---------------

explicit GLTFImporter(uint32_t loadFlags = ModelLoadFlags::NONE);
explicit GLTFImporter(uint32_t loadFlags = GLTFLoadFlags::NONE);
GLTFImporter(const GLTFImporter&) = delete;
GLTFImporter(GLTFImporter&&) = delete;
GLTFImporter& operator=(const GLTFImporter&) = delete;
Expand Down
32 changes: 16 additions & 16 deletions rawrbox.gltf/src/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ namespace rawrbox {
fastgltf::Options::DecomposeNodeMatrices |
fastgltf::Options::LoadExternalBuffers;

if ((this->loadFlags & rawrbox::ModelLoadFlags::IMPORT_TEXTURES) > 0) {
if ((this->loadFlags & rawrbox::GLTFLoadFlags::IMPORT_TEXTURES) > 0) {
extensions |= fastgltf::Extensions::KHR_materials_unlit |
fastgltf::Extensions::KHR_materials_specular | fastgltf::Extensions::KHR_texture_basisu |
fastgltf::Extensions::EXT_texture_webp | fastgltf::Extensions::KHR_materials_emissive_strength;

gltfOptions |= fastgltf::Options::LoadExternalImages; // Handle loading for us
}

if ((this->loadFlags & rawrbox::ModelLoadFlags::IMPORT_LIGHT) > 0) {
if ((this->loadFlags & rawrbox::GLTFLoadFlags::IMPORT_LIGHT) > 0) {
extensions |= fastgltf::Extensions::KHR_lights_punctual;
}

Expand All @@ -60,7 +60,7 @@ namespace rawrbox {
if (importer == nullptr) return;

if (objectType == fastgltf::Category::Meshes) {
if ((importer->loadFlags & rawrbox::ModelLoadFlags::IMPORT_BLEND_SHAPES) > 0) {
if ((importer->loadFlags & rawrbox::GLTFLoadFlags::IMPORT_BLEND_SHAPES) > 0) {
auto arr = extras->at_key("targetNames").get_array();
if (arr.error() != simdjson::error_code::SUCCESS) return;

Expand Down Expand Up @@ -88,7 +88,7 @@ namespace rawrbox {
// ---------------

// LOAD MATERIALS ---
if ((this->loadFlags & rawrbox::ModelLoadFlags::IMPORT_TEXTURES) > 0) {
if ((this->loadFlags & rawrbox::GLTFLoadFlags::IMPORT_TEXTURES) > 0) {
this->loadTextures(scene);
this->loadMaterials(scene);
}
Expand All @@ -99,7 +99,7 @@ namespace rawrbox {
// ---------------

// LOAD SKELETONS & ANIMATIONS ---
if ((this->loadFlags & rawrbox::ModelLoadFlags::IMPORT_ANIMATIONS) > 0) {
if ((this->loadFlags & rawrbox::GLTFLoadFlags::IMPORT_ANIMATIONS) > 0) {
this->loadSkeletons(scene);
this->loadAnimations(scene);
}
Expand All @@ -108,9 +108,9 @@ namespace rawrbox {

// POST-LOAD ---
void GLTFImporter::postLoadFixSceneNames(fastgltf::Asset& scene) {
const bool importAnims = (this->loadFlags & rawrbox::ModelLoadFlags::IMPORT_ANIMATIONS) > 0;
const bool importTextures = (this->loadFlags & rawrbox::ModelLoadFlags::IMPORT_TEXTURES) > 0;
const bool importLights = (this->loadFlags & rawrbox::ModelLoadFlags::IMPORT_LIGHT) > 0;
const bool importAnims = (this->loadFlags & rawrbox::GLTFLoadFlags::IMPORT_ANIMATIONS) > 0;
const bool importTextures = (this->loadFlags & rawrbox::GLTFLoadFlags::IMPORT_TEXTURES) > 0;
const bool importLights = (this->loadFlags & rawrbox::GLTFLoadFlags::IMPORT_LIGHT) > 0;

// Fix scenes ---
for (size_t i = 0; i < scene.scenes.size(); i++) {
Expand Down Expand Up @@ -356,7 +356,7 @@ namespace rawrbox {

// DEBUG ----
std::function<void(const ozz::animation::offline::RawSkeleton::Joint&, int, bool)> printBone;
if ((this->loadFlags & rawrbox::ModelLoadFlags::Debug::PRINT_BONE_STRUCTURE) > 0) {
if ((this->loadFlags & rawrbox::GLTFLoadFlags::Debug::PRINT_BONE_STRUCTURE) > 0) {
printBone = [this, &printBone](const ozz::animation::offline::RawSkeleton::Joint& bn, int depth, bool isLast) -> void {
std::string indent(depth * 4, ' ');
std::string branch = isLast ? "└── " : "├── ";
Expand Down Expand Up @@ -481,7 +481,7 @@ namespace rawrbox {
gltfAnim.name = std::string(anim.name.begin(), anim.name.end());
gltfAnim.duration = 0.001F;

if ((this->loadFlags & rawrbox::ModelLoadFlags::Debug::PRINT_ANIMATIONS) > 0) {
if ((this->loadFlags & rawrbox::GLTFLoadFlags::Debug::PRINT_ANIMATIONS) > 0) {
this->_logger->debug("Found animation '{}'", fmt::styled(gltfAnim.name, fmt::fg(fmt::color::green_yellow)));
}

Expand Down Expand Up @@ -607,7 +607,7 @@ namespace rawrbox {
}

// Optimize skeleton
if ((this->loadFlags & rawrbox::ModelLoadFlags::Optimizer::SKELETON_ANIMATIONS) > 0 && anim.skeleton != nullptr) {
if ((this->loadFlags & rawrbox::GLTFLoadFlags::Optimizer::SKELETON_ANIMATIONS) > 0 && anim.skeleton != nullptr) {
ozz::animation::offline::AnimationOptimizer optimizer;
ozz::animation::offline::RawAnimation input = rawrAnim;

Expand Down Expand Up @@ -661,7 +661,7 @@ namespace rawrbox {
size_t meshIndex = node.meshIndex.value();
const auto& mesh = scene.meshes[meshIndex];

const bool importBlendShapes = (this->loadFlags & rawrbox::ModelLoadFlags::IMPORT_BLEND_SHAPES) > 0;
const bool importBlendShapes = (this->loadFlags & rawrbox::GLTFLoadFlags::IMPORT_BLEND_SHAPES) > 0;

// SUB-MESHES ----
gltfMesh->primitives.resize(mesh.primitives.size());
Expand Down Expand Up @@ -722,15 +722,15 @@ namespace rawrbox {
// -----------

// OPTIMIZATION ---
if ((this->loadFlags & rawrbox::ModelLoadFlags::Optimizer::MESH) > 0) {
if ((this->loadFlags & rawrbox::GLTFLoadFlags::Optimizer::MESH) > 0) {
if (rawrPrimitive.blendShapes.empty()) {
auto startVert = rawrPrimitive.vertices.size();
auto startInd = rawrPrimitive.indices.size();

rawrbox::MeshOptimization::optimize(rawrPrimitive.vertices, rawrPrimitive.indices);
rawrbox::MeshOptimization::simplify(rawrPrimitive.vertices, rawrPrimitive.indices);

if ((this->loadFlags & rawrbox::ModelLoadFlags::Debug::PRINT_OPTIMIZATION_STATS) > 0) {
if ((this->loadFlags & rawrbox::GLTFLoadFlags::Debug::PRINT_OPTIMIZATION_STATS) > 0) {
if (startVert != rawrPrimitive.vertices.size() || startInd != rawrPrimitive.indices.size()) {
this->_logger->debug("Optimized mesh '{}'\n\tVertices -> {} to {}\n\tIndices -> {} to {}", fmt::styled(gltfMesh->name, fmt::fg(fmt::color::cyan)), startVert, rawrPrimitive.vertices.size(), startInd, rawrPrimitive.indices.size());
}
Expand All @@ -742,7 +742,7 @@ namespace rawrbox {
// ----------------

// BBOX CALCULATION --
if ((this->loadFlags & rawrbox::ModelLoadFlags::CALCULATE_BBOX) > 0) {
if ((this->loadFlags & rawrbox::GLTFLoadFlags::CALCULATE_BBOX) > 0) {
gltfMesh->bbox.min = rawrbox::Vector3f(std::numeric_limits<float>::max());
gltfMesh->bbox.max = rawrbox::Vector3f(std::numeric_limits<float>::min());

Expand Down Expand Up @@ -811,7 +811,7 @@ namespace rawrbox {
// -------------

// BONES -----
if ((this->loadFlags & rawrbox::ModelLoadFlags::IMPORT_ANIMATIONS) > 0) {
if ((this->loadFlags & rawrbox::GLTFLoadFlags::IMPORT_ANIMATIONS) > 0) {
const auto* jointIt = primitive.findAttribute("JOINTS_0");
const auto* weightIt = primitive.findAttribute("WEIGHTS_0");

Expand Down
10 changes: 5 additions & 5 deletions samples/009-gltf/src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ namespace gltf {

void Game::loadContent() {
std::vector<std::pair<std::string, uint32_t>> initialContentFiles = {
{"./assets/models/ps1_phasmophobia/scene.glb", rawrbox::ModelLoadFlags::IMPORT_TEXTURES | rawrbox::ModelLoadFlags::IMPORT_LIGHT | rawrbox::ModelLoadFlags::Optimizer::MESH},
{"./assets/models/shape_keys/shape_keys.glb", rawrbox::ModelLoadFlags::CALCULATE_BBOX | rawrbox::ModelLoadFlags::IMPORT_TEXTURES | rawrbox::ModelLoadFlags::IMPORT_BLEND_SHAPES | rawrbox::ModelLoadFlags::Debug::PRINT_BLENDSHAPES},
{"./assets/models/wolf/wolf.glb", rawrbox::ModelLoadFlags::IMPORT_TEXTURES | rawrbox::ModelLoadFlags::IMPORT_ANIMATIONS | rawrbox::ModelLoadFlags::Optimizer::SKELETON_ANIMATIONS | rawrbox::ModelLoadFlags::Debug::PRINT_ANIMATIONS},
{"./assets/models/anim_test.glb", rawrbox::ModelLoadFlags::IMPORT_ANIMATIONS},
{"./assets/models/grandma_tv/scene.gltf", rawrbox::ModelLoadFlags::IMPORT_TEXTURES | rawrbox::ModelLoadFlags::IMPORT_ANIMATIONS | rawrbox::ModelLoadFlags::Debug::PRINT_MATERIALS}};
{"./assets/models/ps1_phasmophobia/scene.glb", rawrbox::GLTFLoadFlags::IMPORT_TEXTURES | rawrbox::GLTFLoadFlags::IMPORT_LIGHT | rawrbox::GLTFLoadFlags::Optimizer::MESH},
{"./assets/models/shape_keys/shape_keys.glb", rawrbox::GLTFLoadFlags::CALCULATE_BBOX | rawrbox::GLTFLoadFlags::IMPORT_TEXTURES | rawrbox::GLTFLoadFlags::IMPORT_BLEND_SHAPES | rawrbox::GLTFLoadFlags::Debug::PRINT_BLENDSHAPES},
{"./assets/models/wolf/wolf.glb", rawrbox::GLTFLoadFlags::IMPORT_TEXTURES | rawrbox::GLTFLoadFlags::IMPORT_ANIMATIONS | rawrbox::GLTFLoadFlags::Optimizer::SKELETON_ANIMATIONS | rawrbox::GLTFLoadFlags::Debug::PRINT_ANIMATIONS},
{"./assets/models/anim_test.glb", rawrbox::GLTFLoadFlags::IMPORT_ANIMATIONS},
{"./assets/models/grandma_tv/scene.gltf", rawrbox::GLTFLoadFlags::IMPORT_TEXTURES | rawrbox::GLTFLoadFlags::IMPORT_ANIMATIONS | rawrbox::GLTFLoadFlags::Debug::PRINT_MATERIALS}};

rawrbox::RESOURCES::loadListAsync(initialContentFiles, [this]() {
rawrbox::runOnRenderThread([this]() {
Expand Down

0 comments on commit f4f3415

Please sign in to comment.