static vertex thing

This commit is contained in:
Joshua Ashton 2022-08-12 12:03:00 +00:00
parent ee4bf54bf3
commit 29f8deb608
1 changed files with 38 additions and 4 deletions

View File

@ -28,21 +28,54 @@ struct AABB
}
};
enum class MeshVertexType
{
Static,
Skinned,
};
struct Vertex
{
vec3 pos;
vec2 uv;
vec3 normal;
vec3 tangent;
bool operator == (const Vertex& other) const
{
return pos == other.pos && uv == other.uv && normal == other.normal;
return pos == other.pos &&
uv == other.uv &&
normal == other.normal &&
tangent == other.tangent;
}
};
struct SkinnedVertex : public Vertex
{
static constexpr uint32_t MaxVertexWeights = 4;
bool operator == (const SkinnedVertex& other) const
{
return pos == other.pos &&
uv == other.uv &&
normal == other.normal &&
tangent == other.tangent &&
boneIndices == other.boneIndices &&
boneWeights == other.boneWeights;
}
Array<uint8_t, MaxVertexWeights> boneIndices;
Array<uint8_t, MaxVertexWeights> boneWeights;
}
struct MeshData
{
Vector<Vertex> vertices;
MeshVertexType vertexType;
union
{
Vector<Vertex> staticVertices;
Vector<SkinnedVertex> skinnedVertices;
};
Vector<uint16_t> indices;
AABB bounds;
};
@ -50,6 +83,7 @@ struct MeshData
Result<MeshData> ParseOBJ(StringView buffer)
{
MeshData data;
data.vertexType = MeshVertexType::Static;
Vector<vec3> positions;
Vector<vec2> uvs;
@ -121,11 +155,11 @@ Result<MeshData> ParseOBJ(StringView buffer)
.normal = indices[i][2] != -1 ? normals [indices[i][2]] : vec3{},
};
size_t vertexIdx = data.vertices.FindIdx(vertex);
size_t vertexIdx = data.staticVertices.FindIdx(vertex);
if (vertexIdx == Vector<Vertex>::InvalidIdx)
{
data.bounds.Extend(vertex.pos);
vertexIdx = data.vertices.PushBack(vertex);
vertexIdx = data.staticVertices.PushBack(vertex);
}
Assert(vertexIdx < UINT16_MAX);