From 1e17e175949f1143007e25faf486c2dfbc9161d5 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Sat, 25 Feb 2023 23:32:51 +0800 Subject: [PATCH] Working commit, do byte based copy --- src/AssetMacros.h | 18 ++++++++++++++++++ src/Libraries/MeshCompiler.h | 4 +++- src/Libraries/MeshCompiler.hpp | 23 ++++++++++++++++++++--- src/main.cpp | 2 ++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/AssetMacros.h b/src/AssetMacros.h index 64154b6..8a5f081 100644 --- a/src/AssetMacros.h +++ b/src/AssetMacros.h @@ -30,6 +30,24 @@ enum class ACCESSOR_DATA_TYPE : int FLOAT = 5126 }; +constexpr size_t SizeOfType(ACCESSOR_DATA_TYPE type) +{ + switch(type) + { + case ACCESSOR_DATA_TYPE::BYTE: + case ACCESSOR_DATA_TYPE::U_BYTE: + return sizeof(char); + case ACCESSOR_DATA_TYPE::SHORT: + case ACCESSOR_DATA_TYPE::U_SHORT: + return sizeof(short); + case ACCESSOR_DATA_TYPE::U_INT: + case ACCESSOR_DATA_TYPE::FLOAT: + return sizeof(float); + default: + return 0; + } +} + enum class ACCESSOR_COMPONENT_TYPE : int { SCALAR = 64 + 1, diff --git a/src/Libraries/MeshCompiler.h b/src/Libraries/MeshCompiler.h index 49fd876..64d27f6 100644 --- a/src/Libraries/MeshCompiler.h +++ b/src/Libraries/MeshCompiler.h @@ -44,7 +44,7 @@ namespace SH_COMP static BufferViewReference bufferViews; static BufferData buffer; - static void LoadFromFile(AssetPath path, ModelRef asset) noexcept; + static inline void LoadFromFile(AssetPath path, ModelRef asset) noexcept; static inline void ProcessModel(ModelData const&, ModelRef asset) noexcept; static inline void BuildHeaders(ModelRef asset) noexcept; @@ -54,3 +54,5 @@ namespace SH_COMP static void LoadAndCompile(AssetPath path) noexcept; }; } + +#include "MeshCompiler.hpp" diff --git a/src/Libraries/MeshCompiler.hpp b/src/Libraries/MeshCompiler.hpp index d659d1a..9bceb96 100644 --- a/src/Libraries/MeshCompiler.hpp +++ b/src/Libraries/MeshCompiler.hpp @@ -118,13 +118,30 @@ namespace SH_COMP { auto const& accessor = (*accessors)[accessorID]; auto const& view = (*bufferViews)[accessor.bufferView]; - dst.resize(3484); - std::cout << "buffer line\n"; + auto const typeIdentifier{ static_cast(accessor.componentType) }; + auto const sizeIdentifier{ SizeOfType(typeIdentifier) }; + if (sizeof(T) == sizeIdentifier) + { + dst.resize(accessor.count); + std::memcpy( + dst.data(), + buffer + view.byteOffset, + view.byteLength + ); + return; + } + + std::vector tempData(view.byteLength); std::memcpy( - dst.data(), + tempData.data(), buffer + view.byteOffset, view.byteLength ); + + for (auto i{0}; i < accessor.count; i += sizeIdentifier) + { + + } } inline void MeshCompiler::BuildHeaders(ModelRef asset) noexcept diff --git a/src/main.cpp b/src/main.cpp index 62a9c00..ff6c6d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,6 +57,8 @@ int main(int argc, char* argv[]) } #else + (void)argc; + (void)argv; SH_COMP::MeshCompiler::LoadAndCompile("racoon_tiny.gltf"); #endif