Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
geometry.h
Go to the documentation of this file.
1
#pragma once
2
//------------------------------------------------------------------------------
15
//------------------------------------------------------------------------------
16
#include "
core/types.h
"
17
#include "
util/array.h
"
18
#include "
util/stringatom.h
"
19
#include "flat/physics/material.h"
20
21
#include <functional>
22
23
namespace
Physics
24
{
25
26
enum class
IndexType
27
{
28
InvalidIndexType
= 0,
29
Index16
,
30
Index32
,
31
};
32
33
//------------------------------------------------------------------------------
37
inline
SizeT
38
IndexSize
(
Physics::IndexType
type)
39
{
40
switch
(type)
41
{
42
case
Physics::IndexType::Index16
:
return
sizeof
(uint16_t);
43
case
Physics::IndexType::Index32
:
return
sizeof
(uint32_t);
44
default
:
return
0;
45
}
46
}
47
49
struct
MeshGeometryInput
50
{
51
Util::Array<float>
positions
;
// 3 floats per vertex
52
SizeT
vertexCount
= 0;
// positions.Size() == vertexCount * 3
53
SizeT
positionStride
=
sizeof
(float) * 3;
54
55
Util::Array<byte>
indices
;
// indexCount indices of IndexSize() bytes each, triangle triplets
56
SizeT
indexCount
= 0;
57
Physics::IndexType
indexType
=
Physics::IndexType::InvalidIndexType
;
58
59
// These can be used for the ApproxSkin topology, where every bone gets its own convex hull.
60
Util::Array<float>
weights
;
// 4 floats per vertex, empty when not skinned
61
Util::Array<uint>
bones
;
// one bone per vertex, empty when not skinned
62
63
Physics::MeshTopology
topology
= Physics::MeshTopology_Triangles;
64
};
65
67
struct
HeightFieldInput
68
{
69
SizeT
width
= 0;
70
SizeT
height
= 0;
71
Util::Array<ushort>
samples
;
// width * height samples
72
};
73
75
struct
GeometryLoader
76
{
77
std::function<bool(
Util::StringAtom
resource,
IndexT
primGroup,
MeshGeometryInput
& out)>
LoadMesh
=
nullptr
;
78
std::function<bool(
Util::StringAtom
resource,
HeightFieldInput
& out)>
LoadHeightField
=
nullptr
;
79
};
80
82
void
SetGeometryLoader
(
const
GeometryLoader
& loader);
84
const
GeometryLoader
&
GetGeometryLoader
();
85
86
}
// namespace Physics
87
//------------------------------------------------------------------------------
array.h
Util::Array
Nebula's dynamic array class.
Definition
array.h:61
Util::StringAtom
A StringAtom.
Definition
stringatom.h:22
Physics
Diverse functions for manipulating physics actors.
Definition
actorcontext.cc:22
Physics::SetGeometryLoader
void SetGeometryLoader(const GeometryLoader &loader)
register the geometry loader to use
Definition
geometry.cc:17
Physics::IndexSize
SizeT IndexSize(Physics::IndexType type)
Byte size of an index type.
Definition
geometry.h:38
Physics::GetGeometryLoader
const GeometryLoader & GetGeometryLoader()
get the currently registered geometry loader
Definition
geometry.cc:26
Physics::IndexType
IndexType
Definition
geometry.h:27
Physics::IndexType::Index32
@ Index32
Definition
geometry.h:30
Physics::IndexType::InvalidIndexType
@ InvalidIndexType
Definition
geometry.h:28
Physics::IndexType::Index16
@ Index16
Definition
geometry.h:29
stringatom.h
Physics::GeometryLoader
Holds function pointers for reading meshes and heightfields from resources.
Definition
geometry.h:76
Physics::GeometryLoader::LoadHeightField
std::function< bool(Util::StringAtom resource, HeightFieldInput &out)> LoadHeightField
Definition
geometry.h:78
Physics::GeometryLoader::LoadMesh
std::function< bool(Util::StringAtom resource, IndexT primGroup, MeshGeometryInput &out)> LoadMesh
Definition
geometry.h:77
Physics::HeightFieldInput
Height field samples for the cooking layer.
Definition
geometry.h:68
Physics::HeightFieldInput::width
SizeT width
Definition
geometry.h:69
Physics::HeightFieldInput::samples
Util::Array< ushort > samples
Definition
geometry.h:71
Physics::HeightFieldInput::height
SizeT height
Definition
geometry.h:70
Physics::MeshGeometryInput
Triangle geometry for the cooking layer.
Definition
geometry.h:50
Physics::MeshGeometryInput::weights
Util::Array< float > weights
Definition
geometry.h:60
Physics::MeshGeometryInput::vertexCount
SizeT vertexCount
Definition
geometry.h:52
Physics::MeshGeometryInput::positions
Util::Array< float > positions
Definition
geometry.h:51
Physics::MeshGeometryInput::indexCount
SizeT indexCount
Definition
geometry.h:56
Physics::MeshGeometryInput::bones
Util::Array< uint > bones
Definition
geometry.h:61
Physics::MeshGeometryInput::indices
Util::Array< byte > indices
Definition
geometry.h:55
Physics::MeshGeometryInput::topology
Physics::MeshTopology topology
Definition
geometry.h:63
Physics::MeshGeometryInput::indexType
Physics::IndexType indexType
Definition
geometry.h:57
Physics::MeshGeometryInput::positionStride
SizeT positionStride
Definition
geometry.h:53
types.h
SizeT
int SizeT
Definition
types.h:42
IndexT
int IndexT
Definition
types.h:41
code
physics
physics
geometry.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.