NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches
shadow_collision.hpp
Go to the documentation of this file.
1
13#pragma once
14
16#include "NNL/common/io.hpp"
19namespace nnl {
40struct Triangle {
41 std::array<u16, 3> indices_vertices{0};
45};
46
56 std::vector<u16> triangle_indices;
57};
58
79struct Collision {
84 glm::vec3 origin_point{0.0f};
87 std::vector<glm::vec3> vertices;
89 std::vector<Triangle> triangles;
93};
94
116Collision Convert(SModel&& smodel, bool auto_cull = true, u32 shift = 1);
117
129bool IsOfType(BufferView buffer);
130
131bool IsOfType(const std::filesystem::path& path);
132
133bool IsOfType(Reader& f);
134
149
150Collision Import(const std::filesystem::path& path);
151
162[[nodiscard]] Buffer Export(const Collision& collision);
163
164void Export(const Collision& collision, const std::filesystem::path& path);
165
166void Export(const Collision& collision, Writer& f);
168
169namespace raw {
175NNL_PACK(struct RHeader {
176 Vec4<f32> origin_point{0, 0, 0, 1.0f}; // 0x0
177 Vec3<u32> bbox_dimension{0}; // width, height, depth, shifted by shift value
178 u32 offset_coordinate_map = 0; // 0x1C
179 u32 offset_vertex_table = 0; // 0x20
180 u32 offset_triangles = 0; // 0x24
181 u32 offset_collision_tests = 0;
182 u16 shift_value = 0; //+5 is always added to it
183 u16 unknown = 0;
184});
185
186static_assert(sizeof(RHeader) == 0x30);
187
188NNL_PACK(struct RTriangle {
189 u16 index_vertex_0 = 0; // 0x0
190 u16 index_vertex_1 = 0; // 0x2
191 u16 index_vertex_2 = 0; // 0x4
192 u16 shadow_features = 0; // 0x6 unused in NSLAR, in NUC2 this can disable shadow (1) and possibly more
193 u32 calculation = 0; // 0x8
194});
195
196static_assert(sizeof(RTriangle) == 0xC);
197
198NNL_PACK(struct RCollisionTest {
199 u32 offset_triangle_indices = 0; // 0x0
200 u16 num_triangle_indices = 0; // 0x4
201 u16 padding = 0; // 0x6
202});
203
204static_assert(sizeof(RCollisionTest) == 0x8);
205
206struct RCollision {
207 RHeader header;
208 std::vector<Vec4<f32>> vertices;
209 std::vector<RTriangle> triangles;
210 std::vector<RCollisionTest> collision_tests;
211 std::vector<u16> indices_triangles; // indices to faces to test
212 std::vector<u16> coordinate_map;
213};
214
215RCollision Parse(Reader& f);
216
217Collision Convert(const RCollision& rcollision);
219} // namespace raw
220
221} // namespace shadow_collision
222
223} // namespace nnl
Defines a 3d array class with a linear storage.
Contains macros and definitions for fixed-width types.
4D vector template with packed storage
Definition fixed_type.hpp:116
3D vector template with packed storage
Definition fixed_type.hpp:163
std::uint16_t u16
16-bit unsigned integer
Definition fixed_type.hpp:62
std::uint32_t u32
32-bit unsigned integer
Definition fixed_type.hpp:60
#define NNL_PACK(...)
A structure packing directive.
Definition fixed_type.hpp:41
Reader implementation for read-only memory buffers.
Definition io.hpp:598
Abstract class for writing data.
Definition io.hpp:136
Abstract class for reading data.
Definition io.hpp:78
std::vector< u8 > Buffer
A type alias for std::vector<u8> that denotes a raw, contiguous memory region that may be interpreted...
Definition io.hpp:40
Represents a simple model.
Definition smodel.hpp:654
glm::vec3 origin_point
Definition shadow_collision.hpp:84
u16 shadow_features
Definition shadow_collision.hpp:43
utl::Array3D< CollisionTest > coordinate_map
Definition shadow_collision.hpp:90
std::vector< Triangle > triangles
List of triangles in the collision environment.
Definition shadow_collision.hpp:89
u16 shift_value
Definition shadow_collision.hpp:80
std::vector< glm::vec3 > vertices
Definition shadow_collision.hpp:87
std::array< u16, 3 > indices_vertices
Definition shadow_collision.hpp:41
Struct representing a set of triangles to be tested for shadow projection.
Definition shadow_collision.hpp:55
Struct that contains all necessary information for performing shadow projection.
Definition shadow_collision.hpp:79
Struct defining a single triangle for projecting shadows onto it.
Definition shadow_collision.hpp:40
Buffer Export(const Collision &collision)
Converts a shadow collision config to a binary file representation.
SModel Convert(const Collision &collision)
Converts collision data from the in-game format to a simplified model representation.
bool IsOfType(BufferView buffer)
Tests if the provided file is a shadow collision.
Collision Import(BufferView buffer)
Parses a binary file and converts it to a structured collision.
A 3-dimensional array template class.
Definition array3d.hpp:29
Provides classes for reading and writing binary data to and from various sources.
Contains structures and functions for working with static collisions.
Definition collision.hpp:31
Contains structures and functions for working with shadow "collisions" - geometry onto which fake pla...
Definition shadow_collision.hpp:30
Definition exception.hpp:56
Provides data structures and functions for managing essential components of a 3D model.