Skip to content

Commit 9e2c925

Browse files
committed
gltfpack: Assorted gltfpack correctness fixes
- Fix getBaseTransform layout for morph targets; we allocate Attr per weight and put the weight in [0] instead of... whatever we were doing before - Fix texture mask argument comparisons; they were off by one and did not respect the segment length properly - Fix max joint index determination; we were previously ignoring [1-3] so it was possible for a mesh with >256 joints to be accidentally encoded using 8-bit indices - Fix clearcoatRoughnessFactor serialization which had a typo in the redundancy check
1 parent 9a3fc40 commit 9e2c925

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

gltf/animation.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static float getDeltaTolerance(cgltf_animation_path_type type)
4646
return 0.001f; // 0.1% linear
4747

4848
default:
49-
assert(!"Uknown animation path");
49+
assert(!"Unknown animation path");
5050
return 0;
5151
}
5252
}
@@ -246,12 +246,14 @@ static void getBaseTransform(Attr* result, size_t components, cgltf_animation_pa
246246
if (node->weights_count)
247247
{
248248
assert(node->weights_count == components);
249-
memcpy(result->f, node->weights, components * sizeof(float));
249+
for (size_t k = 0; k < components; ++k)
250+
result[k].f[0] = node->weights[k];
250251
}
251252
else if (node->mesh && node->mesh->weights_count)
252253
{
253254
assert(node->mesh->weights_count == components);
254-
memcpy(result->f, node->mesh->weights, components * sizeof(float));
255+
for (size_t k = 0; k < components; ++k)
256+
result[k].f[0] = node->mesh->weights[k];
255257
}
256258
break;
257259

gltf/gltfpack.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,13 +1258,13 @@ unsigned int textureMask(const char* arg)
12581258
while (arg)
12591259
{
12601260
const char* comma = strchr(arg, ',');
1261-
size_t seg = comma ? comma - arg - 1 : strlen(arg);
1261+
size_t seg = comma ? comma - arg : strlen(arg);
12621262

1263-
if (strncmp(arg, "color", seg) == 0)
1263+
if (seg == 5 && strncmp(arg, "color", seg) == 0)
12641264
result |= 1 << TextureKind_Color;
1265-
else if (strncmp(arg, "normal", seg) == 0)
1265+
else if (seg == 6 && strncmp(arg, "normal", seg) == 0)
12661266
result |= 1 << TextureKind_Normal;
1267-
else if (strncmp(arg, "attrib", seg) == 0)
1267+
else if (seg == 6 && strncmp(arg, "attrib", seg) == 0)
12681268
result |= 1 << TextureKind_Attrib;
12691269
else
12701270
fprintf(stderr, "Warning: unrecognized texture class %.*s\n", int(seg), arg);

gltf/stream.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,8 @@ StreamFormat writeVertexStream(std::string& bin, const Stream& stream, const Qua
683683
unsigned int maxj = 0;
684684

685685
for (size_t i = 0; i < stream.data.size(); ++i)
686-
maxj = std::max(maxj, unsigned(stream.data[i].f[0]));
686+
for (int k = 0; k < 4; ++k)
687+
maxj = std::max(maxj, unsigned(int(stream.data[i].f[k])));
687688

688689
assert(maxj <= 65535);
689690

@@ -731,7 +732,7 @@ StreamFormat writeVertexStream(std::string& bin, const Stream& stream, const Qua
731732
unsigned int maxv = 0;
732733

733734
for (size_t i = 0; i < stream.data.size(); ++i)
734-
maxv = std::max(maxv, unsigned(stream.data[i].f[0]));
735+
maxv = std::max(maxv, unsigned(int(stream.data[i].f[0])));
735736

736737
// exp encoding uses a signed mantissa with only 23 significant bits; input glTF encoding may encode indices losslessly up to 2^24
737738
if (maxv >= (1 << 23))

gltf/write.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static void writeMaterialComponent(std::string& json, const cgltf_data* data, co
338338
append(json, "\"clearcoatFactor\":");
339339
append(json, cc.clearcoat_factor);
340340
}
341-
if (cc.clearcoat_factor != 0)
341+
if (cc.clearcoat_roughness_factor != 0)
342342
{
343343
comma(json);
344344
append(json, "\"clearcoatRoughnessFactor\":");

0 commit comments

Comments
 (0)