Fix glTF exporter's texture handling

Modified the  function in  to correctly handle  and  texture attributes.
Added a new test case  to  to ensure the fix is working correctly.
As the execution environment was not available, tests could not be executed.
This commit is contained in:
google-labs-jules[bot] 2025-03-10 21:56:36 +00:00
parent 4e12ab27d0
commit e9fe201364
2 changed files with 41 additions and 1 deletions

View File

@ -1300,7 +1300,7 @@ int GltfAsset::AddDracoTexture(const Mesh &mesh, int tex_coord_index,
const PointAttribute *const att =
mesh.GetNamedAttribute(GeometryAttribute::TEX_COORD, tex_coord_index);
// TODO(b/200303080): Add support for DT_UINT8 and DT_UINT16 with TEX_COORD.
if (!CheckDracoAttribute(att, {DT_FLOAT32}, {2})) {
if (!CheckDracoAttribute(att, {DT_FLOAT32, DT_UINT8, DT_UINT16}, {2})) {
return -1;
}

View File

@ -991,6 +991,46 @@ TEST_F(GltfEncoderTest, EncodeTexCoord1) {
ASSERT_EQ(mesh_from_gltf->NumNamedAttributes(GeometryAttribute::POSITION), 1);
ASSERT_EQ(mesh_from_gltf->NumNamedAttributes(GeometryAttribute::NORMAL), 1);
ASSERT_EQ(mesh_from_gltf->NumNamedAttributes(GeometryAttribute::TANGENT), 1);
const std::string att_name_0 = "TEXCOORD_0";
const std::string att_name_1 = "TEXCOORD_1";
const auto& att_names_ = mesh->GetNamedAttribute(GeometryAttribute::TEX_COORD, 0)->name();
ASSERT_EQ(att_names_, "TEXCOORD_0");
const auto& att_names = mesh->GetNamedAttribute(GeometryAttribute::TEX_COORD, 1)->name();
ASSERT_EQ(att_names, "TEXCOORD_1");
// Test uint8_t and uint16_t support in tex coords.
// Create an mesh with UINT8 and UINT16 types.
std::unique_ptr<draco::Mesh> mesh_uint8_uint16 = draco::ReadMeshFromTestFile("test_pos_color.ply");
ASSERT_NE(mesh_uint8_uint16, nullptr);
draco::PointAttribute pa;
pa.Init(draco::GeometryAttribute::TEX_COORD, nullptr, 2,
draco::DT_UINT8, false, 8, 0);
std::unique_ptr<draco::PointAttribute> pa_1 =
std::unique_ptr<draco::PointAttribute>(new draco::PointAttribute());
pa_1->Init(draco::GeometryAttribute::TEX_COORD, nullptr, 2,
draco::DT_UINT16, false, 16, 0);
mesh_uint8_uint16->AddAttribute(pa, false, 0);
mesh_uint8_uint16->AddAttribute(*pa_1, false, 0);
// Verify.
const int count = 2;
for (int i = 0; i < mesh_uint8_uint16->num_points(); ++i) {
float v1,v2;
if(att_name_0=="TEXCOORD_0"){
mesh_uint8_uint16->attribute(0)->GetAttributeValue(AttributeValueIndex(i),&v1);
mesh_uint8_uint16->attribute(0)->GetAttributeValue(AttributeValueIndex(i),&v2);
} else {
mesh_uint8_uint16->attribute(1)->GetAttributeValue(AttributeValueIndex(i),&v1);
mesh_uint8_uint16->attribute(1)->GetAttributeValue(AttributeValueIndex(i),&v2);
}
}
// Check that we can load and then save to glTF with no issues.
EncodeMeshToGltfAndCompare(mesh_uint8_uint16.get());
}
TEST_F(GltfEncoderTest, TestEncodeFileFunctions) {