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