Loading...
Searching...
No Matches
BufferToGeometry.hpp
1#pragma once
2#include "BufferToGeometryCommon.hpp"
3#include "TransformHelper.hpp"
4
5#include <Threedim/TinyObj.hpp>
6#include <halp/buffer.hpp>
7#include <halp/controls.hpp>
8#include <halp/geometry.hpp>
9#include <halp/layout.hpp>
10#include <halp/meta.hpp>
11
12#include <climits>
13#include <cstdint>
14namespace Threedim
15{
16
18{
19public:
20 // "(v1)", not plain "Buffers to geometry": BuffersToGeometry2 in
21 // BufferToGeometry2.hpp carries the same name, so a document holding one of
22 // each would show two identical headers. Matches the c_name pair
23 // (buffers_to_geometry / buffers_to_geometry_v2); the uuid is unchanged, so
24 // existing documents still load.
25 halp_meta(name, "Buffers to geometry (v1)")
26 halp_meta(category, "Visuals/Utilities")
27 halp_meta(c_name, "buffers_to_geometry")
28 halp_meta(manual_url, "https://ossia.io/score-docs/processes/buffers-to-geometry.html")
29 halp_meta(uuid, "d5dd3b9a-f57b-4546-9890-d5b5e351dcea")
30 halp_flag(deprecated);
31
32 struct ins
33 {
34 // Input buffers
35 halp::gpu_buffer_input<"Buffer 0"> buffer_0;
36 halp::gpu_buffer_input<"Buffer 1"> buffer_1;
37 halp::gpu_buffer_input<"Buffer 2"> buffer_2;
38 halp::gpu_buffer_input<"Buffer 3"> buffer_3;
39 halp::gpu_buffer_input<"Buffer 4"> buffer_4;
40 halp::gpu_buffer_input<"Buffer 5"> buffer_5;
41 halp::gpu_buffer_input<"Buffer 6"> buffer_6;
42 halp::gpu_buffer_input<"Buffer 7"> buffer_7;
43
44 // clang-format off
45#define ATTRIBUTE(i) \
46 halp::spinbox_i32<"Attr" #i " buffer", halp::irange{-1, 7, -1}> attribute_buffer_ ## i; \
47 halp::spinbox_i32<"Attr" #i " offset", halp::irange{0, INT32_MAX, 0}> attribute_offset_ ## i; \
48 halp::spinbox_i32<"Attr" #i " stride", halp::irange{0, 1024, 0}> attribute_stride_ ## i; \
49 halp::combobox_t<"Attr" #i " format", AttributeFormat> format_ ## i; \
50 halp::spinbox_i32<"Attr" #i " location", halp::irange{0, 15, i}> location_ ## i; \
51 halp::toggle<"Attr" #i " instanced"> instanced_ ## i;
52
53 ATTRIBUTE(0)
54 ATTRIBUTE(1)
55 ATTRIBUTE(2)
56 ATTRIBUTE(3)
57 ATTRIBUTE(4)
58 ATTRIBUTE(5)
59 ATTRIBUTE(6)
60 ATTRIBUTE(7)
61#undef ATTRIBUTE
62 // clang-format on
63
64 // Index buffer
65 halp::spinbox_i32<"Index Buffer", halp::irange{-1, 7, -1}> index_buffer;
66 halp::combobox_t<"Index Format", IndexFormat> index_format;
67 halp::spinbox_i32<"Index Offset", halp::irange{0, 1000000, 0}> index_offset;
68
69 // Geometry settings
70 halp::spinbox_i32<"Vertices", halp::irange{0, 1000000000, 0}> vertices;
71 halp::spinbox_i32<"Instances", halp::irange{1, 1000000000, 1}> instances;
72 halp::combobox_t<"Topology", PrimitiveTopology> topology;
73 halp::combobox_t<"Cull Mode", CullMode> cull_mode;
74 halp::combobox_t<"Front Face", FrontFace> front_face;
75
76 // Transform
77 PositionControl position;
78 RotationControl rotation;
79 ScaleControl scale;
80 } inputs;
81
82 struct
83 {
84 struct
85 {
86 halp_meta(name, "Geometry");
87 halp::dynamic_gpu_geometry mesh;
88 float transform[16]{};
89 bool dirty_mesh = false;
90 bool dirty_transform = false;
91 } geometry;
92 } outputs;
93
94 BuffersToGeometry();
95 void operator()();
96
97 // Cache previous state to detect changes
99 {
100 bool enabled{};
101 int32_t buffer{};
102 int32_t offset{};
103 int32_t stride{};
104 AttributeFormat format{};
105 int32_t location{};
106 bool instanced{};
107 };
108
109 std::array<AttributeState, 8> m_prevAttributes{};
110 std::array<halp::gpu_buffer, 8> m_prevBuffers;
111 int32_t m_prevUseIndexBuffer{};
112 IndexFormat m_prevIndexFormat{};
113 int32_t m_prevIndexOffset{};
114 int32_t m_prevVertices{};
115 int32_t m_prevInstances{};
116 PrimitiveTopology m_prevTopology{};
117 CullMode m_prevCullMode{};
118 FrontFace m_prevFrontFace{};
119 CachedTRS m_cachedTRS{};
120
121 struct ui
122 {
123 halp_meta(name, "Main")
124 halp_meta(layout, halp::layouts::hbox)
125 halp_meta(background, halp::colors::background_mid)
126
127 struct T
128 {
129 halp_meta(name, "Tabs")
130 halp_meta(layout, halp::layouts::tabs)
131 halp_meta(background, halp::colors::background_darker)
132 struct G
133 {
134 halp_meta(name, "Global")
135 halp_meta(layout, halp::layouts::hbox)
136 struct A
137 {
138 halp_meta(layout, halp::layouts::vbox)
139 halp::item<&ins::vertices> vertices;
140 halp::item<&ins::instances> instances;
141 halp::item<&ins::topology> topology;
142 halp::item<&ins::cull_mode> cull_mode;
143 halp::item<&ins::front_face> front_face;
144 } a;
145
146 struct B
147 {
148 halp_meta(layout, halp::layouts::vbox)
149 halp::item<&ins::position> p;
150 halp::item<&ins::rotation> r;
151 halp::item<&ins::scale> s;
152 } b;
153 } global;
154
155 struct A1
156 {
157 halp_meta(name, "0")
158 halp_meta(layout, halp::layouts::vbox)
159 halp::item<&ins::attribute_buffer_0> buffer;
160 halp::item<&ins::attribute_offset_0> offset;
161 halp::item<&ins::attribute_stride_0> stride;
162 halp::item<&ins::format_0> format;
163 halp::item<&ins::location_0> location;
164 halp::item<&ins::instanced_0> instanced;
165 } a0;
166 struct A2
167 {
168 halp_meta(name, "1")
169 halp_meta(layout, halp::layouts::vbox)
170 halp::item<&ins::attribute_buffer_1> buffer;
171 halp::item<&ins::attribute_offset_1> offset;
172 halp::item<&ins::attribute_stride_1> stride;
173 halp::item<&ins::format_1> format;
174 halp::item<&ins::location_1> location;
175 halp::item<&ins::instanced_1> instanced;
176 } a1;
177 struct
178 {
179 halp_meta(name, "2")
180 halp_meta(layout, halp::layouts::vbox)
181 halp::item<&ins::attribute_buffer_2> buffer;
182 halp::item<&ins::attribute_offset_2> offset;
183 halp::item<&ins::attribute_stride_2> stride;
184 halp::item<&ins::format_2> format;
185 halp::item<&ins::location_2> location;
186 halp::item<&ins::instanced_2> instanced;
187 } a2;
188 struct A3
189 {
190 halp_meta(name, "3")
191 halp_meta(layout, halp::layouts::vbox)
192 halp::item<&ins::attribute_buffer_3> buffer;
193 halp::item<&ins::attribute_offset_3> offset;
194 halp::item<&ins::attribute_stride_3> stride;
195 halp::item<&ins::format_3> format;
196 halp::item<&ins::location_3> location;
197 halp::item<&ins::instanced_3> instanced;
198 } a3;
199 struct A4
200 {
201 halp_meta(name, "4")
202 halp_meta(layout, halp::layouts::vbox)
203 halp::item<&ins::attribute_buffer_4> buffer;
204 halp::item<&ins::attribute_offset_4> offset;
205 halp::item<&ins::attribute_stride_4> stride;
206 halp::item<&ins::format_4> format;
207 halp::item<&ins::location_4> location;
208 halp::item<&ins::instanced_4> instanced;
209 } a4;
210 struct A5
211 {
212 halp_meta(name, "5")
213 halp_meta(layout, halp::layouts::vbox)
214 halp::item<&ins::attribute_buffer_5> buffer;
215 halp::item<&ins::attribute_offset_5> offset;
216 halp::item<&ins::attribute_stride_5> stride;
217 halp::item<&ins::format_5> format;
218 halp::item<&ins::location_5> location;
219 halp::item<&ins::instanced_5> instanced;
220 } a5;
221 struct A6
222 {
223 halp_meta(name, "6")
224 halp_meta(layout, halp::layouts::vbox)
225 halp::item<&ins::attribute_buffer_6> buffer;
226 halp::item<&ins::attribute_offset_6> offset;
227 halp::item<&ins::attribute_stride_6> stride;
228 halp::item<&ins::format_6> format;
229 halp::item<&ins::location_6> location;
230 halp::item<&ins::instanced_6> instanced;
231 } a6;
232 struct A7
233 {
234 halp_meta(name, "7")
235 halp_meta(layout, halp::layouts::vbox)
236 halp::item<&ins::attribute_buffer_7> buffer;
237 halp::item<&ins::attribute_offset_7> offset;
238 halp::item<&ins::attribute_stride_7> stride;
239 halp::item<&ins::format_7> format;
240 halp::item<&ins::location_7> location;
241 halp::item<&ins::instanced_7> instanced;
242 } a7;
243 struct
244 {
245 halp_meta(name, "Index")
246 halp_meta(layout, halp::layouts::vbox)
247 halp::item<&ins::index_buffer> buffer;
248 halp::item<&ins::index_offset> offset;
249 halp::item<&ins::index_format> format;
250 } index;
251 } tabs;
252 };
253};
254
255} // namespace Threedim
Definition BufferToGeometry.hpp:18
Definition BufferToGeometry.hpp:99
Definition BufferToGeometry.hpp:33
Definition BufferToGeometry.hpp:122
Definition TinyObj.hpp:98
Definition TinyObj.hpp:103
Definition TinyObj.hpp:107
Definition TinyObj.hpp:27