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