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(uuid, "1e923d52-3494-49e8-8698-b001405000da")
45
46 struct
47 {
48 PositionControl position;
49 RotationControl rotation;
50 ScaleControl scale;
51 struct : halp::spinbox_i32<"H divs.", halp::range{2, 200, 16}>, Update {} hdivs;
52 struct : halp::spinbox_i32<"V divs.", halp::range{2, 200, 16}>, Update {} vdivs;
53 } inputs;
54
55 struct
56 {
57 struct
58 {
59 halp_meta(name, "Geometry");
60 halp::position_normals_texcoords_geometry_plane mesh;
61 float transform[16]{};
62 bool dirty_mesh = false;
63 bool dirty_transform = false;
64 } geometry;
65 } outputs;
66
67 void prepare(halp::setup) { update(); }
68 void update();
69 void operator()()
70 {
71 outputs.geometry.dirty_transform
72 = computeTRSMatrix(inputs, outputs.geometry.transform, m_cachedTRS);
73 }
74
75 std::vector<float> complete;
76 CachedTRS m_cachedTRS{};
77};
78
80{
81public:
82 halp_meta(name, "Cube")
83 halp_meta(c_name, "3d_cube")
84 halp_meta(uuid, "cf8a328a-1ba6-47f8-929f-2168bdec90b0")
85
86 struct
87 {
88 PositionControl position;
89 RotationControl rotation;
90 ScaleControl scale;
91 } inputs;
92
93 void prepare(halp::setup) { update(); }
94 void update();
95 void operator()() { apply_transform(inputs, outputs.geometry); }
96};
97
99{
100public:
101 halp_meta(name, "Sphere")
102 halp_meta(c_name, "3d_sphere")
103 halp_meta(uuid, "fc0df335-d0e9-4ebf-b438-6ba334741c1a")
104
105 struct
106 {
107 PositionControl position;
108 RotationControl rotation;
109 ScaleControl scale;
110 struct
111 : halp::hslider_i32<"Subdivisions", halp::range{1, 5, 2}>
112 , Update
113 {
114 } subdiv;
115 } inputs;
116
117 void prepare(halp::setup) { update(); }
118 void update();
119 void operator()() { apply_transform(inputs, outputs.geometry); }
120};
121
123{
124 halp_meta(name, "Icosahedron")
125 halp_meta(c_name, "3d_ico")
126 halp_meta(uuid, "3ea9f69f-1a0e-49c2-ad16-a88e9ca628a7")
127
128 struct
129 {
130 PositionControl position;
131 RotationControl rotation;
132 ScaleControl scale;
133 } inputs;
134
135 void prepare(halp::setup) { update(); }
136 void update();
137 void operator()() { apply_transform(inputs, outputs.geometry); }
138};
139
141{
142 halp_meta(name, "Cone")
143 halp_meta(c_name, "3d_cone")
144 halp_meta(uuid, "8a5718c4-07f0-476b-b720-1c99e5a379a5")
145
146 struct
147 {
148 PositionControl position;
149 RotationControl rotation;
150 ScaleControl scale;
151 struct
152 : halp::hslider_i32<"Subdivisions", halp::range{1, 500, 36}>
153 , Update
154 {
155 } subdiv;
156 struct
157 : halp::hslider_f32<"R1", halp::range{0, 1000, 1}>
158 , Update
159 {
160 } r1;
161 struct
162 : halp::hslider_f32<"R2", halp::range{0, 1000, 10}>
163 , Update
164 {
165 } r2;
166 struct
167 : halp::hslider_f32<"Height", halp::range{0, 1000, 5}>
168 , Update
169 {
170 } h;
171 } inputs;
172
173 void prepare(halp::setup) { update(); }
174 void update();
175 void operator()() { apply_transform(inputs, outputs.geometry); }
176};
177
179{
180 halp_meta(name, "Cylinder")
181 halp_meta(c_name, "3d_cylinder")
182 halp_meta(uuid, "5992830e-80fe-4461-b357-2c9b5c5e48ae")
183
184 struct
185 {
186 PositionControl position;
187 RotationControl rotation;
188 ScaleControl scale;
189 struct
190 : halp::hslider_i32<"Slices", halp::range{1, 64, 16}>
191 , Update
192 {
193 } slices;
194 struct
195 : halp::hslider_i32<"Stacks", halp::range{1, 64, 16}>
196 , Update
197 {
198 } stacks;
199 } inputs;
200
201 void prepare(halp::setup) { update(); }
202 void update();
203 void operator()() { apply_transform(inputs, outputs.geometry); }
204};
205
207{
208 halp_meta(name, "Torus")
209 halp_meta(c_name, "3d_torus")
210 halp_meta(uuid, "85c5983c-3f4f-4bfe-b8cf-fccdf6ec5faf")
211
212 struct
213 {
214 PositionControl position;
215 RotationControl rotation;
216 ScaleControl scale;
217 struct
218 : halp::hslider_f32<"R1", halp::range{0, 100, 10}>
219 , Update
220 {
221 } r1;
222 struct
223 : halp::hslider_f32<"R2", halp::range{0, 100, 1}>
224 , Update
225 {
226 } r2;
227 struct
228 : halp::hslider_i32<"H Divisions", halp::range{1, 50, 24}>
229 , Update
230 {
231 } hdiv;
232 struct
233 : halp::hslider_i32<"V Divisions", halp::range{1, 50, 12}>
234 , Update
235 {
236 } vdiv;
237 } inputs;
238
239 void prepare(halp::setup) { update(); }
240 void update();
241 void operator()() { apply_transform(inputs, outputs.geometry); }
242};
243
244}
Definition TransformHelper.hpp:26
Definition Primitive.hpp:141
Definition Primitive.hpp:80
Definition Primitive.hpp:179
Definition Primitive.hpp:123
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:99
Definition Primitive.hpp:207
Definition TinyObj.hpp:112
Definition TinyObj.hpp:27