vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
mesh_asset.h
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <type_traits>
6#include <vector>
7
8#include <glm/glm.hpp>
9
10#include "core/math/bounds.h"
11
12#include "resource/resource.h"
13#include "resource/resource_handle.h"
14
15namespace Vkm::Engine {
16
17struct SkeletonAsset;
18
24struct Vertex {
25 glm::vec3 position;
26 glm::vec3 normal;
27 glm::vec2 uv;
28 glm::vec4 tangent;
29};
30
38struct SkinVertex {
39 uint16_t bones[4];
40 uint8_t weights[4];
41};
42static_assert(sizeof(SkinVertex) == 12, "SkinVertex layout changed - bump COOKER_VERSION");
43static_assert(
44 std::is_trivially_copyable_v<SkinVertex>,
45 "SkinVertex must be trivially copyable to bulk-write"
46);
47
51struct MeshAsset : public Resource {
52 std::vector<Vertex> vertices = {};
53 std::vector<uint32_t> indices = {};
54
60 std::vector<SkinVertex> skin = {};
61
68 std::string skeleton = "";
69
75 float skinRadius = 0.0f;
76
77 glm::vec3 boundsMin{0};
78 glm::vec3 boundsMax{0};
79
85 Math::AABB bounds() const noexcept { return {boundsMin, boundsMax}; }
86
92 bool loading = false;
93
101
112};
113
114using MeshHandle = Handle<MeshAsset>;
115
116} // namespace Vkm::Engine
Opaque, type-safe handle for resources, distinguished by ResourceType.
Definition resource_handle.h:16
An axis-aligned box.
Definition bounds.h:14
CPU-side geometry: indexed triangle mesh plus a cached local-space AABB.
Definition mesh_asset.h:51
bool loading
True while an async decode is in flight.
Definition mesh_asset.h:92
glm::vec3 boundsMin
Local space.
Definition mesh_asset.h:77
void computeAndSetSkinRadius(const SkeletonAsset &rig)
Compute how far a vertex sits from the bones that drive it and store it in skinRadius.
float skinRadius
Largest distance from a vertex to any bone that influences it.
Definition mesh_asset.h:75
Math::AABB bounds() const noexcept
The local-space bounds as one box.
Definition mesh_asset.h:85
std::string skeleton
Name of the rig skin's indices address; empty when unskinned.
Definition mesh_asset.h:68
void computeAndSetBounds()
Compute the local-space AABB from vertex positions and store it in boundsMin / boundsMax.
glm::vec3 boundsMax
Local space.
Definition mesh_asset.h:78
std::vector< SkinVertex > skin
Per-vertex rig binding: empty, or exactly vertices.size() long.
Definition mesh_asset.h:60
A rig: a flat, parent-before-child bone array plus its bind pose.
Definition skeleton_asset.h:33
One vertex's binding to the rig, in a stream parallel to vertices.
Definition mesh_asset.h:38
uint8_t weights[4]
unorm8 influences, summing to exactly 255.
Definition mesh_asset.h:40
uint16_t bones[4]
Indices into the skeleton named by MeshAsset::skeleton.
Definition mesh_asset.h:39
One vertex: position, normal, texture coordinates and tangent frame.
Definition mesh_asset.h:24
glm::vec4 tangent
Along +U; w is the handedness, +1 or -1.
Definition mesh_asset.h:28
glm::vec2 uv
Texture coordinates.
Definition mesh_asset.h:27
glm::vec3 position
Model-space position.
Definition mesh_asset.h:25
glm::vec3 normal
Surface normal, model space.
Definition mesh_asset.h:26