Skip to content

Commit

Permalink
tune, fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yiwenxue committed Sep 7, 2023
1 parent 97ed28c commit 26a2139
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions native/cocos/3d/assets/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void MeshUtils::dequantizeMesh(Mesh::IStruct &structInfo, Uint8Array &data) {
const auto inputOffset = readerStride * i + 2 * j;
const auto outputOffset = writerStride * i + 4 * j;
const auto val = mathutils::halfToFloat(ccstd::get<uint16_t>(reader(inputOffset)));
writer(outputOffset, reader(inputOffset));
writer(outputOffset, val);
}
}
};
Expand Down Expand Up @@ -329,11 +329,11 @@ void MeshUtils::dequantizeMesh(Mesh::IStruct &structInfo, Uint8Array &data) {
readers.push_back(reader);
}
auto netStride = std::accumulate(strides.begin(), strides.end(), 0U);
auto *buffer = ccnew ArrayBuffer(view.count * netStride);
auto vertData = Uint8Array(view.count * netStride);
for (uint32_t i = 0; i < attrs.size(); i++) {
const auto &attr = attrs[i];
const auto &reader = readers[i];
auto outputView = DataView(buffer, getOffset(attrs, i));
auto outputView = DataView(vertData.buffer(), getOffset(attrs, i));
auto writer = getWriter(outputView, attr.format);
const auto &dequantize = dequantizes[i];
const auto &formatInfo = gfx::GFX_FORMAT_INFOS[static_cast<uint32_t>(attr.format)];
Expand Down Expand Up @@ -364,7 +364,7 @@ void MeshUtils::dequantizeMesh(Mesh::IStruct &structInfo, Uint8Array &data) {
vertexView.count = view.count;
vertexView.stride = netStride;
bundle.view = vertexView;
bufferBlob.addBuffer(buffer);
bufferBlob.addBuffer(vertData.buffer());
}

for (auto &primitive : structInfo.primitives) {
Expand Down
14 changes: 11 additions & 3 deletions native/cocos/3d/misc/CreateMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,22 @@ Mesh::ICreateInfo MeshUtils::createDynamicMeshInfo(const IDynamicGeometry &geome
void MeshUtils::inflateMesh(const Mesh::IStruct &structInfo, Uint8Array &data) {
uLongf uncompressedSize = 0U;
for (const auto &prim : structInfo.primitives) {
uncompressedSize += prim.indexView->length;
if (prim.indexView.has_value()) {
uncompressedSize += prim.indexView->length + prim.indexView->stride;
}
if (prim.cluster.has_value()) {
uncompressedSize += prim.cluster->vertexView.length + prim.cluster->vertexView.stride;
uncompressedSize += prim.cluster->triangleView.length + prim.cluster->triangleView.stride;
uncompressedSize += prim.cluster->clusterView.length + prim.cluster->clusterView.stride;
uncompressedSize += prim.cluster->coneView.length + prim.cluster->coneView.stride;
}
}
for (const auto &vb : structInfo.vertexBundles) {
uncompressedSize += vb.view.length;
uncompressedSize += vb.view.length + vb.view.stride;
}
auto uncompressedData = Uint8Array(static_cast<uint32_t>(uncompressedSize));
auto res = uncompress(uncompressedData.buffer()->getData(), &uncompressedSize, data.buffer()->getData(), data.byteLength());
data = uncompressedData;
data = Uint8Array(uncompressedData.buffer(), 0, static_cast<uint32_t>(uncompressedSize));
}

void MeshUtils::decodeMesh(Mesh::IStruct &structInfo, Uint8Array &data) {
Expand Down

0 comments on commit 26a2139

Please sign in to comment.