|
| 1 | +// |
| 2 | +// Copyright (c) 2020-present Caps Collective & contributors |
| 3 | +// Originally authored by Jonathan Moallem (@jonjondev) & Aryeh Zinn (@Raelr) |
| 4 | +// |
| 5 | +// This code is released under an unmodified zlib license. |
| 6 | +// For conditions of distribution and use, please see: |
| 7 | +// https://opensource.org/licenses/Zlib |
| 8 | +// |
| 9 | + |
| 10 | +#ifndef SIEGE_ENGINE_SKELETALMESHDATA_H |
| 11 | +#define SIEGE_ENGINE_SKELETALMESHDATA_H |
| 12 | + |
| 13 | +#include <utils/BinarySerialisation.h> |
| 14 | +#include <utils/Colour.h> |
| 15 | +#include <utils/math/mat/Mat4.h> |
| 16 | +#include <utils/math/vec/Hashing.h> |
| 17 | +#include <utils/math/vec/Vec2.h> |
| 18 | +#include <utils/math/vec/Vec3.h> |
| 19 | + |
| 20 | +#include "StaticMeshData.h" |
| 21 | + |
| 22 | +namespace Siege |
| 23 | +{ |
| 24 | +struct Bone |
| 25 | +{ |
| 26 | + uint32_t id = 0; |
| 27 | + Mat4 bindMatrix; |
| 28 | +}; |
| 29 | + |
| 30 | +struct SkinnedVertex |
| 31 | +{ |
| 32 | + Vec3 position; |
| 33 | + FColour color; |
| 34 | + Vec3 normal; |
| 35 | + Vec2 uv; |
| 36 | + Vec4 bones; |
| 37 | + Vec4 weights; |
| 38 | +}; |
| 39 | + |
| 40 | +inline bool operator==(const SkinnedVertex& left, const SkinnedVertex& right) |
| 41 | +{ |
| 42 | + return left.position == right.position && left.color == right.color && |
| 43 | + left.normal == right.normal && left.uv == right.uv && left.bones == right.bones && |
| 44 | + left.weights == right.weights; |
| 45 | +} |
| 46 | + |
| 47 | +inline bool operator!=(const SkinnedVertex& left, const SkinnedVertex& right) |
| 48 | +{ |
| 49 | + return !(left == right); |
| 50 | +} |
| 51 | + |
| 52 | +struct SkeletalMeshData |
| 53 | +{ |
| 54 | + std::vector<uint32_t> indices; |
| 55 | + std::vector<SkinnedVertex> vertices; |
| 56 | + std::map<String, Bone> bones; |
| 57 | +}; |
| 58 | + |
| 59 | +namespace BinarySerialisation |
| 60 | +{ |
| 61 | + |
| 62 | +inline void serialise(Buffer& buffer, Bone& value, SerialisationMode mode) |
| 63 | +{ |
| 64 | + serialise(buffer, value.id, mode); |
| 65 | + serialise(buffer, value.bindMatrix, mode); |
| 66 | +} |
| 67 | + |
| 68 | +inline void serialise(Buffer& buffer, SkinnedVertex& value, SerialisationMode mode) |
| 69 | +{ |
| 70 | + serialise(buffer, value.position, mode); |
| 71 | + serialise(buffer, value.color, mode); |
| 72 | + serialise(buffer, value.normal, mode); |
| 73 | + serialise(buffer, value.uv, mode); |
| 74 | + serialise(buffer, value.bones, mode); |
| 75 | + serialise(buffer, value.weights, mode); |
| 76 | +} |
| 77 | + |
| 78 | +inline void serialise(Buffer& buffer, SkeletalMeshData& value, SerialisationMode mode) |
| 79 | +{ |
| 80 | + serialise(buffer, value.indices, mode); |
| 81 | + serialise(buffer, value.vertices, mode); |
| 82 | + serialise(buffer, value.bones, mode); |
| 83 | +} |
| 84 | + |
| 85 | +} // namespace BinarySerialisation |
| 86 | + |
| 87 | +} // namespace Siege |
| 88 | + |
| 89 | +namespace std |
| 90 | +{ |
| 91 | + |
| 92 | +template<> |
| 93 | +struct hash<Siege::SkinnedVertex> |
| 94 | +{ |
| 95 | + size_t operator()(const Siege::SkinnedVertex& vertex) const |
| 96 | + { |
| 97 | + size_t seed; |
| 98 | + Siege::Hash::HashCombine(seed, vertex, vertex.bones, vertex.weights); |
| 99 | + return seed; |
| 100 | + }; |
| 101 | +}; |
| 102 | + |
| 103 | +} // namespace std |
| 104 | + |
| 105 | +#endif // SIEGE_ENGINE_SKELETALMESHDATA_H |
0 commit comments