Add support for primitive targets.

This commit is contained in:
Kevin Ring 2021-01-04 22:32:35 +11:00
parent e4a69c6559
commit a67ed6a6ca
3 changed files with 12 additions and 2 deletions

View File

@ -25,7 +25,10 @@ TEST_CASE("GltfModel") {
" \"attributes\": {"s +
" \"POSITION\": 0,"s +
" \"NORMAL\": 1"s +
" }"s +
" },"s +
" \"targets\": ["s +
" {\"POSITION\": 10, \"NORMAL\": 11}"s +
" ]"s +
" }]"s +
" }],"s +
" \"surprise\":{\"foo\":true}"s +
@ -48,6 +51,10 @@ TEST_CASE("GltfModel") {
REQUIRE(model.meshes[0].primitives.size() == 1);
CHECK(model.meshes[0].primitives[0].attributes["POSITION"] == 0);
CHECK(model.meshes[0].primitives[0].attributes["NORMAL"] == 1);
REQUIRE(model.meshes[0].primitives[0].targets.size() == 1);
CHECK(model.meshes[0].primitives[0].targets[0]["POSITION"] == 10);
CHECK(model.meshes[0].primitives[0].targets[0]["NORMAL"] == 11);
// std::vector<uint8_t> v;
// GltfModel model = GltfModel::fromMemory(v);
// GltfCollection<GltfMesh> meshes = model.meshes();

View File

@ -14,10 +14,12 @@ JsonHandler* PrimitiveJsonHandler::Key(const char* str, size_t /*length*/, bool
using namespace std::string_literals;
assert(this->_pPrimitive);
if ("attributes"s == str) return property(this->_attributes, this->_pPrimitive->attributes);
if ("indices"s == str) return property(this->_indices, this->_pPrimitive->indices);
if ("material"s == str) return property(this->_material, this->_pPrimitive->material);
if ("mode"s == str) return property(this->_mode, this->_pPrimitive->mode);
if ("targets"s == str) return property(this->_targets, this->_pPrimitive->targets);
return this->ExtensibleObjectKey(str, *this->_pPrimitive);
}

View File

@ -4,6 +4,7 @@
#include "CesiumGltf/PrimitiveMode.h"
#include "ExtensibleObjectJsonHandler.h"
#include "IntegerJsonHandler.h"
#include "ObjectArrayJsonHandler.h"
namespace CesiumGltf {
struct Primitive;
@ -20,6 +21,6 @@ namespace CesiumGltf {
IntegerJsonHandler<int32_t> _indices;
IntegerJsonHandler<int32_t> _material;
IntegerJsonHandler<PrimitiveMode> _mode;
// std::vector<std::unordered_map<std::string, size_t>> targets;
ObjectArrayJsonHandler<std::unordered_map<std::string, int32_t>, AttributeJsonHandler> _targets;
};
}