MeshPrimitiveUtils now contains methods for serializing triangulated and segmented indices.#2
Conversation
…and segmented indices.
|
Internal build 11299284 passed. |
| std::vector<uint32_t> GetJointWeights32(const Document& doc, const GLTFResourceReader& reader, const Accessor& accessor); | ||
| std::vector<uint32_t> GetJointWeights32_0(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive); | ||
|
|
||
| std::string SerializeTriangulatedIndices16(const uint16_t* indices, size_t indexCount, MeshMode mode, BufferBuilder& bufferBuilder); |
There was a problem hiding this comment.
These utils shouldn't use BufferBuilder at all. Return a vector of indices and let the user decide what to do with it. Currently it's making too many assumptions about how the user wants to serialize their data, i.e. in it's own BufferView, not interleaved, etc....
| const auto resultIndexCount = 2 + triangleCount; | ||
| std::vector<T> result(resultIndexCount); | ||
|
|
||
| result[0] = indices[0]; |
There was a problem hiding this comment.
Doing multiplication and then subtraction to get the index seems really weird to me. Why not do this, which is more like the opposite of the original transform code?
// indices:
// 0,1,2
// 1,3,2
// 2,3,4
result.push_back(indices[0]);
result.push_back(indices[1]);
for (size_t i = 2; i < triangleCount; i+=3)
{
if (i % 2 == 0)
{
result.push_back(indices[i]);
}
else
{
result.push_back(indices[i - 1]);
}
}
| const auto resultIndexCount = 2 + triangleCount; | ||
| std::vector<T> result(resultIndexCount); | ||
|
|
||
| result[0] = indices[0]; |
There was a problem hiding this comment.
Doing multiplication and then subtraction to get the index seems really weird to me. Why not do this, which is more like the opposite of the original transform?
// indices:
// 0,1,2
// 0,2,3
// 0,3,4
result.push_back(indices[0]);
result.push_back(indices[1]);
for (size_t i = 2; i < triangleCount; i+=3)
{
result.push_back(indices[i]);
}
| Assert::AreEqual(outputIndices[262139], 0U); | ||
| } | ||
|
|
||
| GLTFSDK_TEST_METHOD(MeshPrimitiveUtilsTests, MeshPrimitiveUtils_Test_SerializeTriangulatedIndices16_Triangles) |
There was a problem hiding this comment.
You also need to add tests which start with a fan/strip/etc, and then do a round-trip by calling both the triangulate and reverse operations and then compare input to output.
|
Internal build 11317591 passed. |
| result[0] = indices[0]; | ||
| result[1] = indices[1]; | ||
| result[2] = indices[2]; | ||
| std::vector<T> result; |
There was a problem hiding this comment.
You need to call reserve on this now that we're using push_back.
| const size_t triangleCount = indexCount / 3; | ||
| const auto resultIndexCount = 2 + triangleCount; | ||
| std::vector<T> result(resultIndexCount); | ||
| std::vector<T> result; |
There was a problem hiding this comment.
You need to call reserve on this now that we're using push_back.
| struct Accessor; | ||
| struct MeshPrimitive; | ||
| struct MorphTarget; | ||
| class BufferBuilder; |
There was a problem hiding this comment.
Can the BufferBuilder forward declaration be removed now?
There was a problem hiding this comment.
Good point. Cleaning it up now.
| throw GLTFException("Input triangulated triangle strip has fewer than 3 indices."); | ||
| } | ||
|
|
||
| std::vector<T> result; |
There was a problem hiding this comment.
Call reserve on the vector(s) to avoid reallocations?
|
Internal build 11336263 passed. |
MeshPrimitiveUtils now contains methods for serializing triangulated and segmented indices.