Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
curve.hpp
Go to the documentation of this file.
1
7
8
#pragma once
9
#include "
core_types.hpp
"
10
11
#include <glm/glm.hpp>
12
#include <tinysplinecxx.h>
13
14
namespace
assets {
15
16
enum class
SplineType
: uint8_t {
17
linear,
18
catmull_rom
,
19
bspline
,
20
bezier
,
21
};
22
23
enum class
CurveDimension : uint8_t {
24
d1 = 1,
25
d2 = 2,
26
d3 = 3,
27
};
28
29
class
TOAST_API Curve :
public
Asset,
public
ISaveable
{
30
public
:
31
using
Points = std::vector<float>;
32
33
Curve(std::vector<Points> channels,
SplineType
type,
float
t_scale = 1.0f);
34
35
[[nodiscard]]
36
static
auto
fromToml(
const
toml::table& tbl) -> std::unique_ptr<Curve>;
37
38
[[nodiscard]]
39
auto
type()
const
-> std::string_view
override
{
40
return
"curve"
;
41
}
42
43
[[nodiscard]]
44
auto
serialize(
SaveMode
mode)
const
-> std::vector<uint8_t>
override
;
45
46
[[nodiscard]]
47
auto
eval1D(
float
t)
const
-> float;
48
49
[[nodiscard]]
50
auto
eval2D(
float
t)
const
-> glm::vec2;
51
52
[[nodiscard]]
53
auto
eval3D(
float
t)
const
-> glm::vec3;
54
55
[[nodiscard]]
56
auto
evalChannel(
size_t
channel,
float
t)
const
-> float;
57
58
[[nodiscard]]
59
auto
evalAtX(
float
x)
const
->
float
{
60
return
sampleChannel(0, x);
61
}
62
63
[[nodiscard]]
64
auto
xRange()
const
noexcept
-> glm::vec2;
65
66
[[nodiscard]]
67
auto
dimension()
const
noexcept
-> CurveDimension {
68
return
static_cast<
CurveDimension
>
(m_channels.size());
69
}
70
71
[[nodiscard]]
72
auto
splineType()
const
noexcept
->
SplineType
{
73
return
m_spline_type;
74
}
75
76
[[nodiscard]]
77
auto
tScale()
const
noexcept
->
float
{
78
return
m_t_scale;
79
}
80
81
[[nodiscard]]
82
auto
numPoints(
size_t
channel = 0)
const
noexcept
->
size_t
{
83
return
channel < m_channels.size() ? m_channels[channel].points.size() / 2 : 0;
84
}
85
86
void
setPoints(
size_t
channel, Points points);
87
89
void
reload
(
const
toml::table& tbl);
90
91
private
:
92
struct
Channel {
93
Points points;
94
tinyspline::BSpline spline;
95
};
96
98
[[nodiscard]]
99
auto
sampleChannel(
size_t
channel,
float
x)
const
-> float;
100
101
void
rebuildSpline(Channel& channel)
const
;
102
103
std::vector<Channel> m_channels;
104
SplineType
m_spline_type;
105
float
m_t_scale = 1.0f;
106
};
107
108
}
assets::Curve::reload
void reload(const toml::table &tbl)
Throws and keeps the old curve when the table is not a curve, nothing may sample it while this runs.
Definition
curve.cpp:163
assets::ISaveable
Inherit from this class to allow an asset to be saved.
Definition
core_types.hpp:33
core_types.hpp
Base types for the asset system.
assets::SaveMode
SaveMode
Definition
core_types.hpp:25
assets::SplineType
SplineType
Definition
curve.hpp:16
assets::SplineType::bspline
@ bspline
approximates central points
Definition
curve.hpp:19
assets::SplineType::bezier
@ bezier
bezier
Definition
curve.hpp:20
assets::SplineType::catmull_rom
@ catmull_rom
automatic tangents
Definition
curve.hpp:18
engine
src
toast
assets
curve.hpp
Generated by
1.17.0