| 316 | } |
| 317 | |
| 318 | inline Ref<Accessor> ExportDataSparse(Asset &a, std::string &meshName, Ref<Buffer> &buffer, |
| 319 | size_t count, void *data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, BufferViewTarget target = BufferViewTarget_NONE, void *dataBase = nullptr) { |
| 320 | if (!count || !data) { |
| 321 | return Ref<Accessor>(); |
| 322 | } |
| 323 | |
| 324 | unsigned int numCompsIn = AttribType::GetNumComponents(typeIn); |
| 325 | unsigned int numCompsOut = AttribType::GetNumComponents(typeOut); |
| 326 | unsigned int bytesPerComp = ComponentTypeSize(compType); |
| 327 | |
| 328 | // accessor |
| 329 | Ref<Accessor> acc = a.accessors.Create(a.FindUniqueID(meshName, "accessor")); |
| 330 | |
| 331 | // if there is a basic data vector |
| 332 | if (dataBase) { |
| 333 | size_t base_offset = buffer->byteLength; |
| 334 | size_t base_padding = base_offset % bytesPerComp; |
| 335 | base_offset += base_padding; |
| 336 | size_t base_length = count * numCompsOut * bytesPerComp; |
| 337 | buffer->Grow(base_length + base_padding); |
| 338 | |
| 339 | Ref<BufferView> bv = a.bufferViews.Create(a.FindUniqueID(meshName, "view")); |
| 340 | bv->buffer = buffer; |
| 341 | bv->byteOffset = base_offset; |
| 342 | bv->byteLength = base_length; //! The target that the WebGL buffer should be bound to. |
| 343 | bv->byteStride = 0; |
| 344 | bv->target = target; |
| 345 | acc->bufferView = bv; |
| 346 | acc->WriteData(count, dataBase, numCompsIn * bytesPerComp); |
| 347 | } |
| 348 | acc->byteOffset = 0; |
| 349 | acc->componentType = compType; |
| 350 | acc->count = count; |
| 351 | acc->type = typeOut; |
| 352 | |
| 353 | if (data) { |
| 354 | void *nzDiff = nullptr, *nzIdx = nullptr; |
| 355 | size_t nzCount = NZDiff(compType, data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx); |
| 356 | acc->sparse.reset(new Accessor::Sparse); |
| 357 | acc->sparse->count = nzCount; |
| 358 | |
| 359 | // indices |
| 360 | unsigned int bytesPerIdx = sizeof(unsigned short); |
| 361 | size_t indices_offset = buffer->byteLength; |
| 362 | size_t indices_padding = indices_offset % bytesPerIdx; |
| 363 | indices_offset += indices_padding; |
| 364 | size_t indices_length = nzCount * 1 * bytesPerIdx; |
| 365 | buffer->Grow(indices_length + indices_padding); |
| 366 | |
| 367 | Ref<BufferView> indicesBV = a.bufferViews.Create(a.FindUniqueID(meshName, "view")); |
| 368 | indicesBV->buffer = buffer; |
| 369 | indicesBV->byteOffset = indices_offset; |
| 370 | indicesBV->byteLength = indices_length; |
| 371 | indicesBV->byteStride = 0; |
| 372 | acc->sparse->indices = indicesBV; |
| 373 | acc->sparse->indicesType = ComponentType_UNSIGNED_SHORT; |
| 374 | acc->sparse->indicesByteOffset = 0; |
| 375 | acc->WriteSparseIndices(nzCount, nzIdx, 1 * bytesPerIdx); |
no test coverage detected