From ca32c59a58d37c1822e185a2d5f3d0d3e8943593 Mon Sep 17 00:00:00 2001 From: Marijn Tamis Date: Thu, 3 May 2018 18:22:48 +0200 Subject: NvCloth 1.1.4 Release. (24070740) --- .../SampleBase/renderer/ClothRenderMesh.cpp | 32 +++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'NvCloth/samples/SampleBase/renderer/ClothRenderMesh.cpp') diff --git a/NvCloth/samples/SampleBase/renderer/ClothRenderMesh.cpp b/NvCloth/samples/SampleBase/renderer/ClothRenderMesh.cpp index 1183bdb..492324a 100644 --- a/NvCloth/samples/SampleBase/renderer/ClothRenderMesh.cpp +++ b/NvCloth/samples/SampleBase/renderer/ClothRenderMesh.cpp @@ -34,15 +34,21 @@ void gatherIndices(std::vector& indices, indices.push_back(static_cast(tIt.ptr()[1])); indices.push_back(static_cast(tIt.ptr()[2])); } - qIt = PxMakeIterator(reinterpret_cast(quads.data), quads.stride); - for (PxU32 i = 0; i < quads.count; ++i, ++qIt) + + //Only do quads in case there wasn't triangle data provided + // otherwise we risk to render triangles double + if(indices.size() == 0) { - indices.push_back(static_cast(qIt.ptr()[0])); - indices.push_back(static_cast(qIt.ptr()[1])); - indices.push_back(static_cast(qIt.ptr()[2])); - indices.push_back(static_cast(qIt.ptr()[0])); - indices.push_back(static_cast(qIt.ptr()[2])); - indices.push_back(static_cast(qIt.ptr()[3])); + qIt = PxMakeIterator(reinterpret_cast(quads.data), quads.stride); + for (PxU32 i = 0; i < quads.count; ++i, ++qIt) + { + indices.push_back(static_cast(qIt.ptr()[0])); + indices.push_back(static_cast(qIt.ptr()[1])); + indices.push_back(static_cast(qIt.ptr()[2])); + indices.push_back(static_cast(qIt.ptr()[0])); + indices.push_back(static_cast(qIt.ptr()[2])); + indices.push_back(static_cast(qIt.ptr()[3])); + } } } @@ -147,6 +153,9 @@ void ClothRenderMesh::initialize(const void* vertices, uint32_t numVertices, uin V(mDevice->CreateBuffer(&bufferDesc, &indexBufferData, &mIndexBuffer)); } + std::vector offsets; + offsets.push_back(0); + setSubmeshOffsets(offsets); } ClothRenderMesh::~ClothRenderMesh() @@ -197,7 +206,7 @@ void ClothRenderMesh::update(const PxVec3* positions, uint32_t numVertices) } } -void ClothRenderMesh::render(ID3D11DeviceContext& context) const +void ClothRenderMesh::render(ID3D11DeviceContext& context, int submesh) const { context.IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); @@ -207,8 +216,11 @@ void ClothRenderMesh::render(ID3D11DeviceContext& context) const context.IASetIndexBuffer(mIndexBuffer, DXGI_FORMAT_R16_UINT, 0); + int firstIndex = mSubmeshOffsets[submesh]; + int indexCount = mSubmeshOffsets[submesh+1] - firstIndex; + if (mIndexBuffer) - context.DrawIndexed(mNumFaces*3, 0, 0); + context.DrawIndexed(indexCount, firstIndex, 0); else context.Draw(mNumVertices, 0); } \ No newline at end of file -- cgit v1.2.3