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