Skip to content

Commit

Permalink
ISSUE #675 only write un channel count if uvByteCount is bigger than 0
Browse files Browse the repository at this point in the history
  • Loading branch information
carmenfan committed Feb 14, 2024
1 parent 0ecc1ee commit 6065d84
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions bouncer/src/repo/core/model/bson/repo_bson_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,6 @@ MeshNode RepoBSONFactory::makeMeshNode(
// UV channels
if (uvChannels.size() > 0)
{
// Could be unsigned __int64 if BSON had such construct (the closest is only __int64)
builder.append(REPO_NODE_MESH_LABEL_UV_CHANNELS_COUNT, (uint32_t)(uvChannels.size()));

std::vector<repo::lib::RepoVector2D> concatenated;

for (auto it = uvChannels.begin(); it != uvChannels.end(); ++it)
Expand All @@ -471,25 +468,30 @@ MeshNode RepoBSONFactory::makeMeshNode(

uint64_t uvByteCount = concatenated.size() * sizeof(concatenated[0]);

if (uvByteCount + bytesize >= REPO_BSON_MAX_BYTE_SIZE)
{
std::string bName = uniqueID.toString() + "_uv";
//inclusion of this binary exceeds the maximum, store separately
binMapping[REPO_NODE_MESH_LABEL_UV_CHANNELS] =
std::pair<std::string, std::vector<uint8_t>>(bName, std::vector<uint8_t>());
binMapping[REPO_NODE_MESH_LABEL_UV_CHANNELS].second.resize(uvByteCount); //uint8_t will ensure it is a byte addrressing
memcpy(binMapping[REPO_NODE_MESH_LABEL_UV_CHANNELS].second.data(), &concatenated[0], uvByteCount);
if (uvByteCount > 0) {
// Could be unsigned __int64 if BSON had such construct (the closest is only __int64)
builder.append(REPO_NODE_MESH_LABEL_UV_CHANNELS_COUNT, (uint32_t)(uvChannels.size()));

bytesize += sizeof(bName);
}
else if(uvByteCount > 0)
{
builder.appendBinary(
REPO_NODE_MESH_LABEL_UV_CHANNELS,
&concatenated[0],
concatenated.size() * sizeof(concatenated[0]));
if (uvByteCount + bytesize >= REPO_BSON_MAX_BYTE_SIZE)
{
std::string bName = uniqueID.toString() + "_uv";
//inclusion of this binary exceeds the maximum, store separately
binMapping[REPO_NODE_MESH_LABEL_UV_CHANNELS] =
std::pair<std::string, std::vector<uint8_t>>(bName, std::vector<uint8_t>());
binMapping[REPO_NODE_MESH_LABEL_UV_CHANNELS].second.resize(uvByteCount); //uint8_t will ensure it is a byte addrressing
memcpy(binMapping[REPO_NODE_MESH_LABEL_UV_CHANNELS].second.data(), &concatenated[0], uvByteCount);

bytesize += sizeof(bName);
}
else
{
builder.appendBinary(
REPO_NODE_MESH_LABEL_UV_CHANNELS,
&concatenated[0],
concatenated.size() * sizeof(concatenated[0]));

bytesize += uvByteCount;
bytesize += uvByteCount;
}
}
}

Expand Down

0 comments on commit 6065d84

Please sign in to comment.