Loading...
Searching...
No Matches
Primitive.hpp
1#pragma once
2
3#include "TransformHelper.hpp"
4
5#include <Threedim/TinyObj.hpp>
6#include <halp/audio.hpp>
7#include <halp/geometry.hpp>
8#include <halp/meta.hpp>
9
10namespace Threedim
11{
13{
14 halp_meta(category, "Visuals/Meshes/Primitives")
15 halp_meta(author, "Jean-Michaël Celerier, vcglib")
16 halp_meta(manual_url, "https://ossia.io/score-docs/processes/meshes.html#primitive")
17
18 // Derived classes' operator() calls this with their own inputs +
19 // geometry output to propagate the position/rotation/scale controls
20 // into the transform[16] slot + dirty_transform flag. Only sets
21 // dirty_transform when the matrix actually changes vs last frame.
22 template <typename In, typename Out>
23 void apply_transform(const In& in, Out& out)
24 {
25 out.dirty_transform = computeTRSMatrix(in, out.transform, m_cachedTRS);
26 }
27
28 void operator()() { }
29 PrimitiveOutputs outputs;
30 std::vector<float> complete;
31 CachedTRS m_cachedTRS{};
32};
33
34// Plane is a special case due to needing a different geometry type
35// to disable back-face culling
36struct Plane
37{
38public:
39 halp_meta(category, "Visuals/Meshes/Primitives")
40 halp_meta(author, "Jean-Michaël Celerier, vcglib")
41 halp_meta(manual_url, "https://ossia.io/score-docs/processes/meshes.html#primitive")
42 halp_meta(name, "Plane")
43 halp_meta(c_name, "3d_plane")
44 halp_meta(description, "Generate a subdivided plane mesh with position, rotation and scale controls.")
45 halp_meta(uuid, "1e923d52-3494-49e8-8698-b001405000da")
46
47 struct
48 {
49 PositionControl position;
50 RotationControl rotation;
51 ScaleControl scale;
52 struct : halp::spinbox_i32<"H divs.", halp::range{2, 200, 16}>, Update {} hdivs;
53 struct : halp::spinbox_i32<"V divs.", halp::range{2, 200, 16}>, Update {} vdivs;
54 } inputs;
55
56 struct
57 {
58 struct
59 {
60 halp_meta(name, "Geometry");
61 halp::position_normals_texcoords_geometry_plane mesh;
62 float transform[16]{};
63 bool dirty_mesh = false;
64 bool dirty_transform = false;
65 } geometry;
66 } outputs;
67
68 void prepare(halp::setup) { update(); }
69 void update();
70 void operator()()
71 {
72 outputs.geometry.dirty_transform
73 = computeTRSMatrix(inputs, outputs.geometry.transform, m_cachedTRS);
74 }
75
76 std::vector<float> complete;
77 CachedTRS m_cachedTRS{};
78};
79
81{
82public:
83 halp_meta(name, "Cube")
84 halp_meta(c_name, "3d_cube")
85 halp_meta(description, "Generate a cube mesh with position, rotation and scale controls.")
86 halp_meta(uuid, "cf8a328a-1ba6-47f8-929f-2168bdec90b0")
87
88 struct
89 {
90 PositionControl position;
91 RotationControl rotation;
92 ScaleControl scale;
93 } inputs;
94
95 void prepare(halp::setup) { update(); }
96 void update();
97 void operator()() { apply_transform(inputs, outputs.geometry); }
98};
99
101{
102public:
103 halp_meta(name, "Sphere")
104 halp_meta(c_name, "3d_sphere")
105 halp_meta(description, "Generate a sphere mesh with position, rotation and scale controls.")
106 halp_meta(uuid, "fc0df335-d0e9-4ebf-b438-6ba334741c1a")
107
108 struct
109 {
110 PositionControl position;
111 RotationControl rotation;
112 ScaleControl scale;
113 struct
114 : halp::hslider_i32<"Subdivisions", halp::range{1, 5, 2}>
115 , Update
116 {
117 } subdiv;
118 } inputs;
119
120 void prepare(halp::setup) { update(); }
121 void update();
122 void operator()() { apply_transform(inputs, outputs.geometry); }
123};
124
126{
127 halp_meta(name, "Icosahedron")
128 halp_meta(c_name, "3d_ico")
129 halp_meta(description, "Generate an icosahedron mesh with position, rotation and scale controls.")
130 halp_meta(uuid, "3ea9f69f-1a0e-49c2-ad16-a88e9ca628a7")
131
132 struct
133 {
134 PositionControl position;
135 RotationControl rotation;
136 ScaleControl scale;
137 } inputs;
138
139 void prepare(halp::setup) { update(); }
140 void update();
141 void operator()() { apply_transform(inputs, outputs.geometry); }
142};
143
145{
146 halp_meta(name, "Cone")
147 halp_meta(c_name, "3d_cone")
148 halp_meta(description, "Generate a cone mesh with position, rotation and scale controls.")
149 halp_meta(uuid, "8a5718c4-07f0-476b-b720-1c99e5a379a5")
150
151 struct
152 {
153 PositionControl position;
154 RotationControl rotation;
155 ScaleControl scale;
156 struct
157 : halp::hslider_i32<"Subdivisions", halp::range{1, 500, 36}>
158 , Update
159 {
160 } subdiv;
161 struct
162 : halp::hslider_f32<"R1", halp::range{0, 1000, 1}>
163 , Update
164 {
165 } r1;
166 struct
167 : halp::hslider_f32<"R2", halp::range{0, 1000, 10}>
168 , Update
169 {
170 } r2;
171 struct
172 : halp::hslider_f32<"Height", halp::range{0, 1000, 5}>
173 , Update
174 {
175 } h;
176 } inputs;
177
178 void prepare(halp::setup) { update(); }
179 void update();
180 void operator()() { apply_transform(inputs, outputs.geometry); }
181};
182
184{
185 halp_meta(name, "Cylinder")
186 halp_meta(c_name, "3d_cylinder")
187 halp_meta(description, "Generate a cylinder mesh with position, rotation and scale controls.")
188 halp_meta(uuid, "5992830e-80fe-4461-b357-2c9b5c5e48ae")
189
190 struct
191 {
192 PositionControl position;
193 RotationControl rotation;
194 ScaleControl scale;
195 struct
196 : halp::hslider_i32<"Slices", halp::range{1, 64, 16}>
197 , Update
198 {
199 } slices;
200 struct
201 : halp::hslider_i32<"Stacks", halp::range{1, 64, 16}>
202 , Update
203 {
204 } stacks;
205 } inputs;
206
207 void prepare(halp::setup) { update(); }
208 void update();
209 void operator()() { apply_transform(inputs, outputs.geometry); }
210};
211
213{
214 halp_meta(name, "Torus")
215 halp_meta(c_name, "3d_torus")
216 halp_meta(description, "Generate a torus mesh with position, rotation and scale controls.")
217 halp_meta(uuid, "85c5983c-3f4f-4bfe-b8cf-fccdf6ec5faf")
218
219 struct
220 {
221 PositionControl position;
222 RotationControl rotation;
223 ScaleControl scale;
224 struct
225 : halp::hslider_f32<"R1", halp::range{0, 100, 10}>
226 , Update
227 {
228 } r1;
229 struct
230 : halp::hslider_f32<"R2", halp::range{0, 100, 1}>
231 , Update
232 {
233 } r2;
234 struct
235 : halp::hslider_i32<"H Divisions", halp::range{1, 50, 24}>
236 , Update
237 {
238 } hdiv;
239 struct
240 : halp::hslider_i32<"V Divisions", halp::range{1, 50, 12}>
241 , Update
242 {
243 } vdiv;
244 } inputs;
245
246 void prepare(halp::setup) { update(); }
247 void update();
248 void operator()() { apply_transform(inputs, outputs.geometry); }
249};
250
251}
Definition TransformHelper.hpp:26
Definition Primitive.hpp:145
Definition Primitive.hpp:81
Definition Primitive.hpp:184
Definition Primitive.hpp:126
Definition Primitive.hpp:37
Definition TinyObj.hpp:98
Definition Primitive.hpp:13
Definition TinyObj.hpp:117
Definition TinyObj.hpp:103
Definition TinyObj.hpp:107
Definition Primitive.hpp:101
Definition Primitive.hpp:213
Definition TinyObj.hpp:112
Definition TinyObj.hpp:27