Skip to content

Commit 4057c44

Browse files
committed
fix: Default samper state for models + serialization for getters/setters
1 parent 564d228 commit 4057c44

8 files changed

Lines changed: 441 additions & 139 deletions

File tree

3DRadSpace/3DRadSpace_Editor_WindowsDX11/Frontend/Windows/AboutWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void AboutWindow::_createControls()
7575
_label = CreateWindowExA(
7676
0,
7777
"Static",
78-
"3DRadSpace Editor\nVersion 0.1.0Alpha\n\nhttps:\\3dradspace.github.io\n\n\n\nThis software is licensed under MIT.",
78+
"3DRadSpace Editor\nVersion 0.1.0Alpha\n\nhttps://3dradspace.github.io\n\n\n\nThis software is licensed under MIT.",
7979
WS_VISIBLE | WS_CHILD | SS_CENTER,
8080
220, 10, 200, 200,
8181
window,

3DRadSpace/Engine3DRadSpace/Content/AssetID.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,32 @@ namespace Engine3DRadSpace::Content
1010
template<AssetType T>
1111
struct AssetID
1212
{
13+
/// <summary>
14+
/// Constructs an AssetID with an null identifier.
15+
/// </summary>
1316
AssetID() : ID(0) {};
17+
/// <summary>
18+
/// Constructs an AssetID with the specified identifier.
19+
/// </summary>
20+
/// <param name="id">Identifier of the asset.</param>
1421
AssetID(unsigned id) : ID(id) {};
22+
23+
/// <summary>
24+
/// Underlying unsigned identifier of the asset.
25+
/// </summary>
1526
unsigned ID;
1627

28+
/// <summary>
29+
/// Gets the underlying unsigned identifier of the asset.
30+
/// </summary>
1731
operator unsigned() const noexcept
1832
{
1933
return ID;
2034
}
2135

36+
/// <summary>
37+
/// Type of the asset associated with this AssetID.
38+
/// </summary>
2239
using Type = T;
2340
};
2441
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
#pragma once
22
#include "../ContentManager.hpp"
33

4+
/*
5+
This header is not supposed to be included by the user as it is used internally when initializing content related services.
6+
*/
7+
48
namespace Engine3DRadSpace::Internal
59
{
10+
/// <summary>
11+
/// Registers the default asset types with the content manager.
12+
/// </summary>
13+
/// <param name="manager">Pointer to the content manager.</param>
614
void E3DRSP_CONTENT_ASSETS_EXPORT RegisterDefaultTypes(Content::ContentManager* manager);
715
}

3DRadSpace/Engine3DRadSpace/Content/ContentManager.hpp

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Engine3DRadSpace::Content
77
{
88
/// <summary>
9-
///
9+
/// Manages the lifetimes of all loaded assets.
1010
/// </summary>
1111
class E3DRSP_CONTENT_EXPORT ContentManager : public IService
1212
{
@@ -123,6 +123,10 @@ namespace Engine3DRadSpace::Content
123123
std::vector<AssetEntry> _assets;
124124
IGame* _owner;
125125
public:
126+
/// <summary>
127+
/// Constructs an instance of ContentManager.
128+
/// </summary>
129+
/// <param name="owner">Owner of this ContentManager.</param>
126130
ContentManager(IGame* owner);
127131

128132
ContentManager(const ContentManager &) = delete;
@@ -131,33 +135,102 @@ namespace Engine3DRadSpace::Content
131135
ContentManager &operator =(const ContentManager &) = delete;
132136
ContentManager &operator =(ContentManager &&) noexcept = default;
133137

138+
/// <summary>
139+
/// Registers an type T into this ContentManager.
140+
/// </summary>
141+
/// <typeparam name="T">Type that must satisfy the AssetType concept</typeparam>
142+
/// <param name="dummy">Type dummy used for operator overloading</param>
134143
template<AssetType T>
135144
void RegisterType(Tag<T> dummy);
136145

146+
/// <summary>
147+
/// Loads an asset of type T from the specified path.
148+
/// </summary>
149+
/// <typeparam name="T">Asset type.</typeparam>
150+
/// <param name="path">Path on disk to the asset.</param>
151+
/// <param name="refID">Optional reference ID to store the asset's ID.</param>
152+
/// <returns>Pointer to the loaded asset.</returns>
137153
template<AssetType T>
138154
T* Load(const std::filesystem::path& path, AssetID<T>* refID = nullptr);
139155

156+
/// <summary>
157+
/// Loads an asset of type T with additional constructor parameters.
158+
/// </summary>
159+
/// <typeparam name="...Args">Extra type arguments</typeparam>
160+
/// <typeparam name="T">Asset type</typeparam>
161+
/// <param name="path">Path on disk to the asset.</param>
162+
/// <param name="refID">Optional reference ID to store the asset's ID.</param>
163+
/// <param name="...params">Additional constructor parameters.</param>
164+
/// <returns>Pointer to the loaded asset.</returns>
140165
template<AssetType T, typename ...Args>
141166
T* Load(const std::filesystem::path& path, AssetID<T>* refID, Args&& ...params);
142167

168+
/// <summary>
169+
/// Type erased asset loading function.
170+
/// </summary>
171+
/// <param name="uuid">UUID of the asset type.</param>
172+
/// <param name="path">Path on disk to the asset.</param>
173+
/// <param name="refID">Optional reference ID to store the asset's ID.</param>
174+
/// <returns>Pointer to the loaded asset.</returns>
143175
IAsset* Load(const Reflection::UUID &uuid, const std::filesystem::path& path, unsigned* refID = nullptr);
144176

177+
/// <summary>
178+
/// Reloads an asset by its reference ID.
179+
/// </summary>
180+
/// <param name="ref">Asset reference ID</param>
145181
void Reload(unsigned ref);
146182

183+
/// <summary>
184+
/// Returns an pointer to the asset of type T associated with the given reference ID.
185+
/// </summary>
186+
/// <typeparam name="T">Asset type</typeparam>
187+
/// <param name="ref">Asset reference ID</param>
188+
/// <returns>Pointer to the asset of type T</returns>
147189
template<AssetType T>
148190
T *operator[](AssetID<T> ref);
149191

192+
/// <summary>
193+
/// Returns the path an asset with the specified ID was loaded from.
194+
/// </summary>
195+
/// <param name="id">Asset ID</param>
196+
/// <returns>Path to the asset</returns>
150197
std::filesystem::path GetAssetPath(unsigned id) const noexcept;
198+
/// <summary>
199+
/// Returns the type UUID of the specified asset ID.
200+
/// </summary>
201+
/// <param name="id">Asset ID</param>
202+
/// <returns>Type UUID of the asset</returns>
151203
Reflection::UUID GetAssetType(unsigned id) const noexcept;
204+
205+
/// <summary>
206+
/// Returns the name of the specified asset ID.
207+
/// </summary>
208+
/// <param name="id">Asset ID</param>
209+
/// <returns>Name of the asset</returns>
152210
std::string GetAssetName(unsigned id) const noexcept;
153211

154212
std::vector<AssetEntry>::iterator begin();
155213
std::vector<AssetEntry>::iterator end();
156214

215+
/// <summary>
216+
/// Frees an asset from the ContentManager by its ID.
217+
/// </summary>
218+
/// <param name="id">Asset ID</param>
157219
void RemoveAsset(unsigned id);
220+
/// <summary>
221+
/// Removes all assets from the ContentManager.
222+
/// </summary>
158223
void Clear();
159224

225+
/// <summary>
226+
/// Returns the graphics device associated with this ContentManager.
227+
/// </summary>
228+
/// <returns>Pointer to the graphics device</returns>
160229
Graphics::IGraphicsDevice* GetDevice() const noexcept;
230+
/// <summary>
231+
/// Returns the number of loaded assets in the ContentManager.
232+
/// </summary>
233+
/// <returns>Number of loaded assets</returns>
161234
size_t Count() const noexcept;
162235

163236
~ContentManager() override = default;

3DRadSpace/Engine3DRadSpace/Graphics/Model3D.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ Model3D::Model3D(IGraphicsDevice* Device, const std::filesystem::path& path) :
213213
}
214214

215215
mesh->Textures.push_back(std::move(diffuseTexture));
216-
mesh->TextureSamplers.push_back(Device->CreateSamplerState());
216+
mesh->TextureSamplers.push_back(Device->CreateSamplerState_AnisotropicWrap());
217+
mesh->GetShaders()->operator[](0)->SetSampler(0, mesh->TextureSamplers[0].get());
217218
meshParts.push_back(std::move(mesh));
218219
}
219220

3DRadSpace/Engine3DRadSpace/Math/Math.hpp

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,81 @@
33

44
namespace Engine3DRadSpace::Math
55
{
6+
/// <summary>
7+
/// Converts degrees to radians.
8+
/// </summary>
9+
/// <typeparam name="T">Floating type</typeparam>
10+
/// <param name="degrees">Angle in degrees</param>
11+
/// <returns>Angle in radians</returns>
612
template<typename T>
713
constexpr T ToRadians(T degrees)
814
{
915
return static_cast<T>(std::numbers::pi * degrees / 180);
1016
}
1117

18+
/// <summary>
19+
/// Converts radians to degrees.
20+
/// </summary>
21+
/// <typeparam name="T">Floating type</typeparam>
22+
/// <param name="radians">Angle in radians</param>
23+
/// <returns>Angle in degrees</returns>
1224
template<typename T>
1325
constexpr T ToDegrees(T radians)
1426
{
1527
return static_cast<T>(radians * 180 / std::numbers::pi);
1628
}
1729

30+
/// <summary>
31+
/// Performs a Catmull-Rom interpolation.
32+
/// </summary>
33+
/// <param name="value1">The first value.</param>
34+
/// <param name="value2">The second value.</param>
35+
/// <param name="value3">The third value.</param>
36+
/// <param name="value4">The fourth value.</param>
37+
/// <param name="amount">The interpolation amount.</param>
38+
/// <returns>The interpolated value.</returns>
1839
constexpr double E3DRSP_MATH_EXPORT CatmullRom(double value1, double value2, double value3, double value4, double amount);
40+
/// <summary>
41+
/// Performs a Hermite spline interpolation between two values with specified tangents.
42+
/// </summary>
43+
/// <param name="value1">The first value.</param>
44+
/// <param name="tangent1">The tangent of the first value.</param>
45+
/// <param name="value2">The second value.</param>
46+
/// <param name="tangent2">The tangent of the second value.</param>
47+
/// <param name="amount">The interpolation amount.</param>
48+
/// <returns>The interpolated value.</returns>
1949
constexpr double E3DRSP_MATH_EXPORT Hermite(double value1, double tangent1, double value2, double tangent2, double amount);
2050

21-
//Axis aligned check for one single axis.
51+
/// <summary>
52+
/// Axis aligned bounding box check for one single axis.
53+
/// </summary>
54+
/// <param name="p1">The position of the first box.</param>
55+
/// <param name="w1">The width of the first box.</param>
56+
/// <param name="p2">The position of the second box.</param>
57+
/// <param name="w2">The width of the second box.</param>
58+
/// <returns>True if the boxes overlap, false otherwise.</returns>
2259
constexpr bool E3DRSP_MATH_EXPORT AABB(float p1, float w1, float p2, float w2);
23-
//Axis aligned check for one single axis.
60+
61+
/// <summary>
62+
/// Axis aligned bounding box check for one single axis.
63+
/// </summary>
64+
/// <param name="p1">The position of the first box.</param>
65+
/// <param name="w1">The width of the first box.</param>
66+
/// <param name="p2">The position of the second box.</param>
67+
/// <param name="w2">The width of the second box.</param>
68+
/// <returns>True if the boxes overlap, false otherwise.</returns>
2469
constexpr bool E3DRSP_MATH_EXPORT AABB(double p1, double w1, double p2, double w2);
2570

71+
/// <summary>
72+
/// Performs a smooth step interpolation between two values.
73+
/// </summary>
74+
/// <remarks>
75+
/// Same as Hermite(value1, 0, value2, 0, result).
76+
/// </remarks>
77+
/// <param name="value1">The first value.</param>
78+
/// <param name="value2">The second value.</param>
79+
/// <param name="amount">The interpolation amount.</param>
80+
/// <returns>The interpolated value.</returns>
2681
constexpr double E3DRSP_MATH_EXPORT SmoothStep(double value1, double value2, double amount);
2782

2883
/// <summary>

3DRadSpace/Engine3DRadSpace/Objects/Impl/Box.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ Graphics::Primitives::Box* Box::GetPrimitive() const noexcept
7474
return _box.get();
7575
}
7676

77-
REFL_BEGIN(Box, "Box", "3D Primitives", "3D box")
78-
REFL_FIELD(Box, std::string, Name, "Name", "Skinmesh", "Object's name")
77+
REFL_BEGIN(Box, "Box (AABB)", "3D Primitives", "3D box")
78+
REFL_FIELD(Box, std::string, Name, "Name", "Box", "Object's name")
7979
REFL_FIELD(Box, bool, Visible, "Visible", true, "Is the object visible?")
8080
REFL_FIELD(Box, Vector3, Position, "Position", Vector3::Zero(), "Object's position in world space")
8181
REFL_FIELD(Box, Vector3, Scale, "Scale", Vector3::One(), "Scale")

0 commit comments

Comments
 (0)