@@ -18,40 +18,45 @@ namespace nbl::asset
18
18
core::smart_refctd_ptr<ICPUPolygonGeometry> CPolygonGeometryManipulator::createUnweldedList (const ICPUPolygonGeometry* inGeo)
19
19
{
20
20
const auto * indexing = inGeo->getIndexingCallback ();
21
- if (!indexing) return nullptr ;
22
- if (indexing-> degree () != 3 ) return nullptr ;
21
+ if (!indexing)
22
+ return nullptr ;
23
23
24
24
const auto indexView = inGeo->getIndexView ();
25
25
const auto primCount = inGeo->getPrimitiveCount ();
26
+ const uint8_t degree = indexing->degree ();
27
+ const auto outIndexCount = primCount*degree;
28
+ if (outIndexCount<primCount)
29
+ return nullptr ;
26
30
27
31
const auto outGeometry = core::move_and_static_cast<ICPUPolygonGeometry>(inGeo->clone (0u ));
28
32
29
33
auto * outGeo = outGeometry.get ();
30
- outGeo->setIndexing (IPolygonGeometryBase::TriangleList ( ));
34
+ outGeo->setIndexing (IPolygonGeometryBase::NGonList (degree ));
31
35
32
36
auto createOutView = [&](const ICPUPolygonGeometry::SDataView& inView) -> ICPUPolygonGeometry::SDataView
33
- {
34
- if (!inView) return {};
35
- auto buffer = ICPUBuffer::create ({ inGeo->getPrimitiveCount () * indexing->degree () * inView.composed .stride , inView.src .buffer ->getUsageFlags () });
37
+ {
38
+ if (!inView)
39
+ return {};
40
+ auto buffer = ICPUBuffer::create ({ outIndexCount*inView.composed .stride , inView.src .buffer ->getUsageFlags () });
36
41
return {
37
- .composed = inView.composed ,
38
- .src = {.offset = 0 , .size = buffer->getSize (), .buffer = std::move (buffer)}
42
+ .composed = inView.composed ,
43
+ .src = {.offset = 0 , .size = buffer->getSize (), .buffer = std::move (buffer)}
39
44
};
40
- };
45
+ };
41
46
42
47
const auto inIndexView = inGeo->getIndexView ();
43
48
auto outIndexView = createOutView (inIndexView);
44
49
auto indexBuffer = outIndexView.src .buffer ;
45
50
const auto indexSize = inIndexView.composed .stride ;
46
- std::byte* outIndexes = reinterpret_cast <std::byte*>(outIndexView.getPointer ());
51
+ std::byte* outIndices = reinterpret_cast <std::byte*>(outIndexView.getPointer ());
47
52
outGeo->setIndexView ({});
48
53
49
54
const auto inVertexView = inGeo->getPositionView ();
50
55
auto outVertexView = createOutView (inVertexView);
51
56
auto vertexBuffer = outVertexView.src .buffer ;
52
57
const auto vertexSize = inVertexView.composed .stride ;
53
- const std::byte* inVertexes = reinterpret_cast <const std::byte*>(inVertexView.getPointer ());
54
- std::byte* const outVertexes = reinterpret_cast <std::byte*>(vertexBuffer->getPointer ());
58
+ const std::byte* inVertices = reinterpret_cast <const std::byte*>(inVertexView.getPointer ());
59
+ std::byte* const outVertices = reinterpret_cast <std::byte*>(vertexBuffer->getPointer ());
55
60
outGeo->setPositionView (std::move (outVertexView));
56
61
57
62
const auto inNormalView = inGeo->getNormalView ();
@@ -63,68 +68,67 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CPolygonGeometryManipulator::createU
63
68
outGeometry->getJointWeightViews ()->resize (inGeo->getJointWeightViews ().size ());
64
69
for (uint64_t jointView_i = 0u ; jointView_i < inGeo->getJointWeightViews ().size (); jointView_i++)
65
70
{
66
- auto & inJointWeightView = inGeo->getJointWeightViews ()[jointView_i];
67
- auto & outJointWeightView = outGeometry->getJointWeightViews ()->operator [](jointView_i);
68
- outJointWeightView.indices = createOutView (inJointWeightView.indices );
69
- outJointWeightView.weights = createOutView (inJointWeightView.weights );
71
+ auto & inJointWeightView = inGeo->getJointWeightViews ()[jointView_i];
72
+ auto & outJointWeightView = outGeometry->getJointWeightViews ()->operator [](jointView_i);
73
+ outJointWeightView.indices = createOutView (inJointWeightView.indices );
74
+ outJointWeightView.weights = createOutView (inJointWeightView.weights );
70
75
}
71
76
72
77
outGeometry->getAuxAttributeViews ()->resize (inGeo->getAuxAttributeViews ().size ());
73
78
for (uint64_t auxView_i = 0u ; auxView_i < inGeo->getAuxAttributeViews ().size (); auxView_i++)
74
- {
75
- outGeo->getAuxAttributeViews ()->operator [](auxView_i) = createOutView (inGeo->getAuxAttributeViews ()[auxView_i]);
76
- }
79
+ outGeo->getAuxAttributeViews ()->operator [](auxView_i) = createOutView (inGeo->getAuxAttributeViews ()[auxView_i]);
77
80
81
+ std::array<uint32_t ,255 > indices;
78
82
for (uint64_t prim_i = 0u ; prim_i < primCount; prim_i++)
79
83
{
80
- hlsl::uint32_t3 indexes;
81
- IPolygonGeometryBase::IIndexingCallback::SContext<uint32_t > context{
82
- .indexBuffer = indexView.getPointer (),
83
- .indexSize = indexView.composed .stride ,
84
- .beginPrimitive = prim_i,
85
- .endPrimitive = prim_i + 1 ,
86
- .out = &indexes
87
- };
88
- indexing->operator ()(context);
89
- for (uint64_t primIndex_i = 0u ; primIndex_i < indexing->degree (); primIndex_i++)
90
- {
91
- const auto outIndex = prim_i * indexing->degree () + primIndex_i;
92
- const auto inIndex = indexes[primIndex_i];
93
- memcpy (outIndexes + outIndex * indexSize, &outIndex, indexSize);
94
- memcpy (outVertexes + outIndex * vertexSize, inVertexes + inIndex * vertexSize, vertexSize);
95
- if (inNormalView)
96
- {
97
- std::byte* const outNormals = reinterpret_cast <std::byte*>(outNormalBuffer->getPointer ());
98
- const auto normalSize = inNormalView.composed .stride ;
99
- memcpy (outNormals + outIndex * normalSize, inNormals + inIndex * normalSize, normalSize);
100
- }
101
-
102
- for (uint64_t jointView_i = 0u ; jointView_i < inGeo->getJointWeightViews ().size (); jointView_i++)
103
- {
104
- auto & inView = inGeo->getJointWeightViews ()[jointView_i];
105
- auto & outView = outGeometry->getJointWeightViews ()->operator [](jointView_i);
106
-
107
- const std::byte* const inJointIndices = reinterpret_cast <const std::byte*>(inView.indices .getPointer ());
108
- const auto jointIndexSize = inView.indices .composed .stride ;
109
- std::byte* const outJointIndices = reinterpret_cast <std::byte*>(outView.indices .getPointer ());
110
- memcpy (outJointIndices + outIndex * jointIndexSize, inJointIndices + inIndex * jointIndexSize, jointIndexSize);
111
-
112
- const std::byte* const inWeights = reinterpret_cast <const std::byte*>(inView.weights .getPointer ());
113
- const auto jointWeightSize = inView.weights .composed .stride ;
114
- std::byte* const outWeights = reinterpret_cast <std::byte*>(outView.weights .getPointer ());
115
- memcpy (outWeights + outIndex * jointWeightSize, outWeights + inIndex * jointWeightSize, jointWeightSize);
116
- }
117
-
118
- for (uint64_t auxView_i = 0u ; auxView_i < inGeo->getAuxAttributeViews ().size (); auxView_i++)
84
+ IPolygonGeometryBase::IIndexingCallback::SContext<uint32_t > context{
85
+ .indexBuffer = indexView.getPointer (),
86
+ .indexSize = indexView.composed .stride ,
87
+ .beginPrimitive = prim_i,
88
+ .endPrimitive = prim_i + 1 ,
89
+ .out = indices.data ()
90
+ };
91
+ indexing->operator ()(context);
92
+ for (uint8_t primIndex_i=0 ; primIndex_i<degree; primIndex_i++)
119
93
{
120
- auto & inView = inGeo->getAuxAttributeViews ()[auxView_i];
121
- auto & outView = outGeometry->getAuxAttributeViews ()->operator [](auxView_i);
122
- const auto attrSize = inView.composed .stride ;
123
- const std::byte* const inAuxs = reinterpret_cast <const std::byte*>(inView.getPointer ());
124
- std::byte* const outAuxs = reinterpret_cast <std::byte*>(outView.getPointer ());
125
- memcpy (outAuxs + outIndex * attrSize, inAuxs + inIndex * attrSize, attrSize);
94
+ const auto outIndex = prim_i * degree + primIndex_i;
95
+ const auto inIndex = indices[primIndex_i];
96
+ // TODO: these memcpys from view to view could really be DRY-ed and lambdified
97
+ memcpy (outIndices + outIndex * indexSize, &outIndex, indexSize);
98
+ memcpy (outVertices + outIndex * vertexSize, inVertices + inIndex * vertexSize, vertexSize);
99
+ if (inNormalView)
100
+ {
101
+ std::byte* const outNormals = reinterpret_cast <std::byte*>(outNormalBuffer->getPointer ());
102
+ const auto normalSize = inNormalView.composed .stride ;
103
+ memcpy (outNormals + outIndex * normalSize, inNormals + inIndex * normalSize, normalSize);
104
+ }
105
+
106
+ for (uint64_t jointView_i = 0u ; jointView_i < inGeo->getJointWeightViews ().size (); jointView_i++)
107
+ {
108
+ auto & inView = inGeo->getJointWeightViews ()[jointView_i];
109
+ auto & outView = outGeometry->getJointWeightViews ()->operator [](jointView_i);
110
+
111
+ const std::byte* const inJointIndices = reinterpret_cast <const std::byte*>(inView.indices .getPointer ());
112
+ const auto jointIndexSize = inView.indices .composed .stride ;
113
+ std::byte* const outJointIndices = reinterpret_cast <std::byte*>(outView.indices .getPointer ());
114
+ memcpy (outJointIndices + outIndex * jointIndexSize, inJointIndices + inIndex * jointIndexSize, jointIndexSize);
115
+
116
+ const std::byte* const inWeights = reinterpret_cast <const std::byte*>(inView.weights .getPointer ());
117
+ const auto jointWeightSize = inView.weights .composed .stride ;
118
+ std::byte* const outWeights = reinterpret_cast <std::byte*>(outView.weights .getPointer ());
119
+ memcpy (outWeights + outIndex * jointWeightSize, outWeights + inIndex * jointWeightSize, jointWeightSize);
120
+ }
121
+
122
+ for (uint64_t auxView_i = 0u ; auxView_i < inGeo->getAuxAttributeViews ().size (); auxView_i++)
123
+ {
124
+ auto & inView = inGeo->getAuxAttributeViews ()[auxView_i];
125
+ auto & outView = outGeometry->getAuxAttributeViews ()->operator [](auxView_i);
126
+ const auto attrSize = inView.composed .stride ;
127
+ const std::byte* const inAuxs = reinterpret_cast <const std::byte*>(inView.getPointer ());
128
+ std::byte* const outAuxs = reinterpret_cast <std::byte*>(outView.getPointer ());
129
+ memcpy (outAuxs + outIndex * attrSize, inAuxs + inIndex * attrSize, attrSize);
130
+ }
126
131
}
127
- }
128
132
}
129
133
130
134
recomputeContentHashes (outGeo);
0 commit comments