Foundation
Loading...
Searching...
No Matches
Mesh.hpp
Go to the documentation of this file.
1#pragma once
3#include <RHICore/Common.hpp>
4#include <Core/Core.hpp>
5#include <Math/Math.hpp>
6
7namespace ModelViewer
8{
9 using namespace Foundation;
10 using namespace Math;
11 using namespace Core;
12 using MeshIndex = uint32_t; // 32-bit index
27#pragma pack(push, 1)
29 uint16_t px, py, pz; // quantized fp16
30 uint16_t tp; // tangent [octa 8+8]
31 uint32_t np; // normal packed [snorm octa 15+15, bitangent sign 2]
32 uint16_t u, v; // UV coords fp16
36 static MeshVertexCompact Pack(vec3 pos, vec3 normal, vec3 tangent, vec3 bitangent, vec2 uv);
38 {
39 return Pack(data.pos, data.normal, data.tangent, data.bitangent, data.uv);
40 }
41 };
42 static_assert(sizeof(MeshVertexCompact) == 16);
47 struct MeshMeshlet // same layout as meshopt_Meshlet
48 {
49 /* offsets within meshlet_vertices and meshlet_triangles arrays with meshlet data */
50 uint32_t vertexOffset; // in vertices
51 uint32_t triangleOffset; // in indices (3*triangles)
52 /* number of vertices and triangles used in the meshlet; data is stored in consecutive range defined by offset and count */
55 /* bounds */
57 float4 coneAxisAngle; // (x,y,z,cos(half solid angle))
59 };
60 static_assert(sizeof(MeshMeshlet) == 60);
61#pragma pack(pop)
62 using MeshMicroIndex = uint8_t; // 8-bit index into meshlet vertex array
63 constexpr uint32_t kMeshletMaxVertices = 64; // max vertices per meshlet
64 constexpr uint32_t kMeshletMaxTriangles = 96; // max triangles per meshlet (indices=3*triangles)
90}
std::unique_ptr< T, StlDeleter< T > > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:161
vec3 float3
Definition Math.hpp:24
vec4 float4
Definition Math.hpp:23
std::filesystem::path Path
OS specific filesystem path. Alias of std::filesystem::path.
Definition Filesystem.hpp:10
Definition Future.hpp:8
ModelViewer implementation.
Definition App.cpp:17
uint32_t MeshIndex
Definition Mesh.hpp:12
void meshLoadObjFile(Vector< MeshVertex > &vertices, Vector< MeshIndex > &indices, const Path &path)
Load a mesh from an OBJ file.
Definition Mesh.cpp:120
void meshBuildMeshlets(Vector< MeshMeshlet > &outMeshlet, Vector< MeshIndex > &outMeshletVertices, Vector< MeshMicroIndex > &outMeshletTriangles, Span< const MeshVertex > vertices, Span< const MeshIndex > indices)
Build meshlets from a mesh.
Definition Mesh.cpp:71
uint8_t MeshMicroIndex
Definition Mesh.hpp:62
constexpr uint32_t kMeshletMaxTriangles
Definition Mesh.hpp:64
float meshGenerateLod(Vector< MeshIndex > &outIndices, Span< const MeshVertex > vertices, Span< const MeshIndex > indices, const float lodScale)
Generate a simplified LOD mesh index buffer from the input mesh.
Definition Mesh.cpp:52
constexpr uint32_t kMeshletMaxVertices
Definition Mesh.hpp:63
Meshlet structure containing offsets and counts to access meshlet data.
Definition Mesh.hpp:48
uint32_t triangleCount
Definition Mesh.hpp:54
uint32_t vertexCount
Definition Mesh.hpp:53
float3 coneApex
Definition Mesh.hpp:58
uint32_t vertexOffset
Definition Mesh.hpp:50
float4 sphereCenterRadius
Definition Mesh.hpp:56
float4 coneAxisAngle
Definition Mesh.hpp:57
uint32_t triangleOffset
Definition Mesh.hpp:51
Compact 4-byte aligned vertex structure for static meshes.
Definition Mesh.hpp:28
uint16_t u
Definition Mesh.hpp:32
uint16_t px
Definition Mesh.hpp:29
uint16_t pz
Definition Mesh.hpp:29
uint16_t tp
Definition Mesh.hpp:30
static MeshVertexCompact Pack(MeshVertex data)
Definition Mesh.hpp:37
uint32_t np
Definition Mesh.hpp:31
uint16_t v
Definition Mesh.hpp:32
static MeshVertexCompact Pack(vec3 pos, vec3 normal, vec3 tangent, vec3 bitangent, vec2 uv)
Pack vertex attributes into compact MeshVertex.
Definition Mesh.cpp:14
uint16_t py
Definition Mesh.hpp:29
Full-size vertex structure for static meshes.
Definition Mesh.hpp:17
vec3 bitangent
Definition Mesh.hpp:21
vec3 normal
Definition Mesh.hpp:19
vec3 pos
Definition Mesh.hpp:18
vec3 tangent
Definition Mesh.hpp:20
vec2 uv
Definition Mesh.hpp:22