MCPcopy Create free account
hub / github.com/CesiumGS/cesium-native / copyDecodedAttribute

Function copyDecodedAttribute

CesiumGltfReader/src/decodeDraco.cpp:219–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219void copyDecodedAttribute(
220 GltfReaderResult& readGltf,
221 CesiumGltf::MeshPrimitive& /* primitive */,
222 CesiumGltf::Accessor* pAccessor,
223 const draco::Mesh* pMesh,
224 const draco::PointAttribute* pAttribute) {
225 CESIUM_TRACE("CesiumGltfReader::copyDecodedAttribute");
226 CESIUM_ASSERT(readGltf.model.has_value());
227 CesiumGltf::Model& model = readGltf.model.value();
228
229 if (pAccessor->count != pMesh->num_points()) {
230 readGltf.warnings.emplace_back("Attribute accessor.count doesn't match "
231 "with number of decoded Draco vertices.");
232
233 pAccessor->count = pMesh->num_points();
234 }
235
236 pAccessor->bufferView = static_cast<int32_t>(model.bufferViews.size());
237 CesiumGltf::BufferView& bufferView = model.bufferViews.emplace_back();
238
239 bufferView.buffer = static_cast<int32_t>(model.buffers.size());
240 CesiumGltf::Buffer& buffer = model.buffers.emplace_back();
241
242 const int8_t numberOfComponents = pAccessor->computeNumberOfComponents();
243 const int64_t stride = static_cast<int64_t>(
244 numberOfComponents * pAccessor->computeByteSizeOfComponent());
245 const int64_t sizeBytes = pAccessor->count * stride;
246
247 buffer.cesium.data.resize(static_cast<size_t>(sizeBytes));
248 buffer.byteLength = sizeBytes;
249 bufferView.byteLength = sizeBytes;
250 bufferView.byteStride = stride;
251 bufferView.byteOffset = 0;
252 bufferView.target = CesiumGltf::BufferView::Target::ARRAY_BUFFER;
253 pAccessor->byteOffset = 0;
254
255 const auto doCopy = [pMesh, pAttribute, numberOfComponents](auto pOut) {
256 for (draco::PointIndex i(0); i < pMesh->num_points(); ++i) {
257 const draco::AttributeValueIndex valueIndex = pAttribute->mapped_index(i);
258 pAttribute->ConvertValue(valueIndex, numberOfComponents, pOut);
259 pOut += pAttribute->num_components();
260 }
261 };
262
263 switch (pAccessor->componentType) {
264 case CesiumGltf::Accessor::ComponentType::BYTE:
265 doCopy(reinterpret_cast<int8_t*>(buffer.cesium.data.data()));
266 break;
267 case CesiumGltf::Accessor::ComponentType::UNSIGNED_BYTE:
268 doCopy(reinterpret_cast<uint8_t*>(buffer.cesium.data.data()));
269 break;
270 case CesiumGltf::Accessor::ComponentType::SHORT:
271 doCopy(reinterpret_cast<int16_t*>(buffer.cesium.data.data()));
272 break;
273 case CesiumGltf::Accessor::ComponentType::UNSIGNED_SHORT:
274 doCopy(reinterpret_cast<uint16_t*>(buffer.cesium.data.data()));
275 break;
276 case CesiumGltf::Accessor::ComponentType::UNSIGNED_INT:

Callers 1

decodePrimitiveFunction · 0.85

Calls 4

sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected