From 429b94a0eee79520526bb219d73e611c1169bf1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9B=BE?= <442739441@qq.com> Date: Thu, 7 Feb 2019 10:58:24 +0800 Subject: [PATCH] Update Raw2Gltf.cpp draco compress bug --- src/gltf/Raw2Gltf.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/gltf/Raw2Gltf.cpp b/src/gltf/Raw2Gltf.cpp index eac53e4..ab295bf 100644 --- a/src/gltf/Raw2Gltf.cpp +++ b/src/gltf/Raw2Gltf.cpp @@ -439,10 +439,15 @@ ModelData* Raw2Gltf( for (uint32_t ii = 0; ii < triangleCount; ii++) { draco::Mesh::Face face; - face[0] = surfaceModel.GetTriangle(ii).verts[0]; - face[1] = surfaceModel.GetTriangle(ii).verts[1]; - face[2] = surfaceModel.GetTriangle(ii).verts[2]; - dracoMesh->SetFace(draco::FaceIndex(ii), face); + //face[0] = surfaceModel.GetTriangle(ii).verts[0]; + //face[1] = surfaceModel.GetTriangle(ii).verts[1]; + // face[2] = surfaceModel.GetTriangle(ii).verts[2]; + //dracoMesh->SetFace(draco::FaceIndex(ii), face); + draco::Mesh::Face face; + face[0] = ii * 3; + face[1] = ii * 3 + 1; + face[2] = ii * 3 + 2; + dracoMesh->SetFace(draco::FaceIndex(ii), face); } AccessorData& indexes = @@ -611,7 +616,24 @@ ModelData* Raw2Gltf( encoder.SetAttributeQuantization( draco::GeometryAttribute::GENERIC, options.draco.quantBitsGeneric); } - + // MapPointToVertexIndices + std::map::iterator itB = primitive->dracoAttributes.begin(); + auto dracoMesh = primitive->dracoMesh; + int triangleCount = surfaceModel.GetTriangleCount(); + for (; itB != primitive->dracoAttributes.end(); itB++) { + draco::PointAttribute* attPtr = dracoMesh->attribute(itB->second); + for (uint32_t ii = 0; ii < triangleCount; ii++) { + int index1 = surfaceModel.GetTriangle(ii).verts[0]; + int index2 = surfaceModel.GetTriangle(ii).verts[1]; + int index3 = surfaceModel.GetTriangle(ii).verts[2]; + attPtr->SetPointMapEntry( + draco::PointIndex(ii * 3), draco::AttributeValueIndex(index1)); + attPtr->SetPointMapEntry( + draco::PointIndex(ii * 3 + 1), draco::AttributeValueIndex(index2)); + attPtr->SetPointMapEntry( + draco::PointIndex(ii * 3 + 2), draco::AttributeValueIndex(index3)); + } + } draco::EncoderBuffer dracoBuffer; draco::Status status = encoder.EncodeMeshToBuffer(*primitive->dracoMesh, &dracoBuffer); assert(status.code() == draco::Status::OK);