opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
polyhedron_geometry.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <cstddef>
8#include <cstdint>
9#include <span>
10#include <vector>
11
12namespace osc
13{
14 // parameters to construct `PolyhedronGeometry`
15 //
16 // defaults to a tetrahedron for demonstration purposes, callers should
17 // overwrite `vertices` and `indices` as appropriate
20
21 std::vector<Vector3> vertices = {
22 {1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f},
23 };
24 std::vector<uint32_t> indices = {
25 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1,
26 };
27 float radius = 1.0f;
28 size_t detail_level = 0;
29 };
30
31 // generates a 3D solid with flat faces by projecting triangle faces (`indices`
32 // indexes into `vertices` for each triangle) onto a sphere of `radius`, followed
33 // by dividing them up to the desired `detail_level`
35 public:
37
38 static constexpr CStringView name() { return "Polyhedron"; }
39
40 explicit PolyhedronGeometry(const Params& = Params{});
41
42 // constructs a `PolyhedronGeometry` from existing vertex + index data (rather
43 // than requiring `std::vector`s)
45 std::span<const Vector3> vertices,
46 std::span<const uint32_t> indices,
47 float radius = 1.0f,
48 size_t detail_level = 0
49 );
50
51 const Mesh& mesh() const { return mesh_; }
52 operator const Mesh& () const { return mesh_; }
53 private:
54 Mesh mesh_;
55 };
56}
Definition c_string_view.h:12
Definition mesh.h:33
Definition polyhedron_geometry.h:34
PolyhedronGeometry(const Params &=Params{})
static constexpr CStringView name()
Definition polyhedron_geometry.h:38
const Mesh & mesh() const
Definition polyhedron_geometry.h:51
PolyhedronGeometry(std::span< const Vector3 > vertices, std::span< const uint32_t > indices, float radius=1.0f, size_t detail_level=0)
Definition custom_decoration_generator.h:5
constexpr U to(T &&value)
Definition conversion.h:56
Definition polyhedron_geometry.h:18
size_t detail_level
Definition polyhedron_geometry.h:28
float radius
Definition polyhedron_geometry.h:27
friend bool operator==(const PolyhedronGeometryParams &, const PolyhedronGeometryParams &)
std::vector< Vector3 > vertices
Definition polyhedron_geometry.h:21
std::vector< uint32_t > indices
Definition polyhedron_geometry.h:24