From 26a2139b9b259a90e91ff035d7c7aa175f4bde4f Mon Sep 17 00:00:00 2001 From: yiwenxue <15225434259xue@gmail.com> Date: Thu, 7 Sep 2023 18:44:39 +0800 Subject: [PATCH] tune, fix bug --- native/cocos/3d/assets/Mesh.cpp | 8 ++++---- native/cocos/3d/misc/CreateMesh.cpp | 14 +++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/native/cocos/3d/assets/Mesh.cpp b/native/cocos/3d/assets/Mesh.cpp index db2fe919c5f..8446ec0f51e 100644 --- a/native/cocos/3d/assets/Mesh.cpp +++ b/native/cocos/3d/assets/Mesh.cpp @@ -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(reader(inputOffset))); - writer(outputOffset, reader(inputOffset)); + writer(outputOffset, val); } } }; @@ -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(attr.format)]; @@ -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) { diff --git a/native/cocos/3d/misc/CreateMesh.cpp b/native/cocos/3d/misc/CreateMesh.cpp index e479a23d33d..ffed86a849d 100644 --- a/native/cocos/3d/misc/CreateMesh.cpp +++ b/native/cocos/3d/misc/CreateMesh.cpp @@ -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(uncompressedSize)); auto res = uncompress(uncompressedData.buffer()->getData(), &uncompressedSize, data.buffer()->getData(), data.byteLength()); - data = uncompressedData; + data = Uint8Array(uncompressedData.buffer(), 0, static_cast(uncompressedSize)); } void MeshUtils::decodeMesh(Mesh::IStruct &structInfo, Uint8Array &data) {