@@ -626,18 +626,18 @@ fg::Expected<fg::DataSource> fg::Parser::decodeDataUri(URIView& uri) const noexc
626
626
}
627
627
628
628
// Decode the base64 data into a traditional vector
629
- std::vector<std::uint8_t > uriData;
629
+ auto padding = base64::getPadding (encodedData);
630
+ fg::StaticVector<std::uint8_t > uriData (base64::getOutputSize (encodedData.size (), padding));
630
631
if (config.decodeCallback != nullptr ) {
631
- auto padding = base64::getPadding (encodedData);
632
- uriData.resize (base64::getOutputSize (encodedData.size (), padding));
633
632
config.decodeCallback (encodedData, uriData.data (), padding, uriData.size (), config.userPointer );
634
633
} else {
635
- uriData = base64::decode (encodedData);
634
+ base64::decode_inplace (encodedData, uriData. data (), padding );
636
635
}
637
636
638
- sources::Vector source = {};
639
- source.mimeType = getMimeTypeFromString (mime);
640
- source.bytes = std::move (uriData);
637
+ sources::Array source = {
638
+ std::move (uriData),
639
+ getMimeTypeFromString (mime),
640
+ };
641
641
return Expected<DataSource> { std::move (source) };
642
642
}
643
643
@@ -669,10 +669,12 @@ fg::Expected<fg::DataSource> fg::Parser::loadFileFromUri(URIView& uri) const noe
669
669
}
670
670
}
671
671
672
- sources::Vector vectorSource = {};
673
- vectorSource.mimeType = MimeType::GltfBuffer;
674
- vectorSource.bytes .resize (length);
675
- file.read (reinterpret_cast <char *>(vectorSource.bytes .data ()), length);
672
+ StaticVector<std::uint8_t > data (length);
673
+ file.read (reinterpret_cast <char *>(data.data ()), length);
674
+ sources::Array vectorSource = {
675
+ std::move (data),
676
+ MimeType::GltfBuffer,
677
+ };
676
678
return Expected<DataSource> { std::move (vectorSource) };
677
679
}
678
680
@@ -744,10 +746,9 @@ fg::Error fg::Parser::generateMeshIndices(fastgltf::Asset& asset) const {
744
746
}
745
747
auto & positionAccessor = asset.accessors [positionAttribute->second ];
746
748
747
- sources::Vector generatedIndices;
748
- generatedIndices.bytes .resize (positionAccessor.count * getElementByteSize (positionAccessor.type , positionAccessor.componentType ));
749
- fastgltf::span<std::uint32_t > indices { reinterpret_cast <std::uint32_t *>(generatedIndices.bytes .data ()),
750
- generatedIndices.bytes .size () / sizeof (std::uint32_t ) };
749
+ StaticVector<std::uint8_t > generatedIndices (positionAccessor.count * getElementByteSize (positionAccessor.type , positionAccessor.componentType ));
750
+ fastgltf::span<std::uint32_t > indices { reinterpret_cast <std::uint32_t *>(generatedIndices.data ()),
751
+ generatedIndices.size () / sizeof (std::uint32_t ) };
751
752
for (std::size_t i = 0 ; i < positionAccessor.count ; ++i) {
752
753
indices[i] = static_cast <std::uint32_t >(i);
753
754
}
@@ -756,7 +757,7 @@ fg::Error fg::Parser::generateMeshIndices(fastgltf::Asset& asset) const {
756
757
757
758
auto bufferViewIdx = asset.bufferViews .size ();
758
759
auto & bufferView = asset.bufferViews .emplace_back ();
759
- bufferView.byteLength = generatedIndices.bytes . size ();
760
+ bufferView.byteLength = generatedIndices.size_bytes ();
760
761
bufferView.bufferIndex = bufferIdx;
761
762
bufferView.byteOffset = 0 ;
762
763
@@ -769,9 +770,12 @@ fg::Error fg::Parser::generateMeshIndices(fastgltf::Asset& asset) const {
769
770
accessor.normalized = false ;
770
771
accessor.bufferViewIndex = bufferViewIdx;
771
772
773
+ sources::Array indicesArray {
774
+ std::move (generatedIndices),
775
+ };
772
776
auto & buffer = asset.buffers .emplace_back ();
773
- buffer.byteLength = generatedIndices.bytes . size ();
774
- buffer.data = std::move (generatedIndices );
777
+ buffer.byteLength = generatedIndices.size_bytes ();
778
+ buffer.data = std::move (indicesArray );
775
779
primitive.indicesAccessor = accessorIdx;
776
780
}
777
781
}
@@ -2022,7 +2026,7 @@ fg::Error fg::Parser::parseImages(simdjson::dom::array& images, Asset& asset) {
2022
2026
using T = std::decay_t <decltype (arg)>;
2023
2027
2024
2028
// This is kinda cursed
2025
- if constexpr (is_any<T, sources::CustomBuffer, sources::BufferView, sources::URI, sources::Vector >()) {
2029
+ if constexpr (is_any<T, sources::CustomBuffer, sources::BufferView, sources::URI, sources::Array >()) {
2026
2030
arg.mimeType = getMimeTypeFromString (mimeType);
2027
2031
}
2028
2032
}, image.data );
@@ -3495,10 +3499,13 @@ fg::Expected<fg::Asset> fg::Parser::loadGltfBinary(GltfDataBuffer* buffer, fs::p
3495
3499
glbBuffer = sources::CustomBuffer { info.customId , MimeType::None };
3496
3500
}
3497
3501
} else {
3498
- sources::Vector vectorData = {};
3499
- vectorData.bytes .resize (binaryChunk.chunkLength );
3500
- read (vectorData.bytes .data (), binaryChunk.chunkLength );
3501
- vectorData.mimeType = MimeType::GltfBuffer;
3502
+ StaticVector<std::uint8_t > binaryData (binaryChunk.chunkLength );
3503
+ read (binaryData.data (), binaryChunk.chunkLength );
3504
+
3505
+ sources::Array vectorData = {
3506
+ std::move (binaryData),
3507
+ MimeType::GltfBuffer,
3508
+ };
3502
3509
glbBuffer = std::move (vectorData);
3503
3510
}
3504
3511
} else {
@@ -3699,7 +3706,7 @@ void fg::Exporter::writeBuffers(const Asset& asset, std::string& json) {
3699
3706
// Covers BufferView and CustomBuffer.
3700
3707
errorCode = Error::InvalidGltf;
3701
3708
},
3702
- [&](const sources::Vector & vector) {
3709
+ [&](const sources::Array & vector) {
3703
3710
if (bufferIdx == 0 && exportingBinary) {
3704
3711
bufferPaths.emplace_back (std::nullopt);
3705
3712
return ;
@@ -3870,7 +3877,7 @@ void fg::Exporter::writeImages(const Asset& asset, std::string& json) {
3870
3877
json += std::string (R"( "mimeType":")" ) + std::string (getMimeTypeString (bufferView.mimeType )) + ' "' ;
3871
3878
imagePaths.emplace_back (std::nullopt);
3872
3879
},
3873
- [&](const sources::Vector & vector) {
3880
+ [&](const sources::Array & vector) {
3874
3881
auto path = getImageFilePath (asset, imageIdx, vector.mimeType );
3875
3882
json += std::string (R"( "uri":")" ) + fg::escapeString (path.string ()) + ' "' ;
3876
3883
imagePaths.emplace_back (path);
@@ -4745,7 +4752,7 @@ fg::Expected<fg::ExportResult<std::vector<std::byte>>> fg::Exporter::writeGltfBi
4745
4752
// TODO: Add ExportOption enumeration for disabling this?
4746
4753
const bool withEmbeddedBuffer = !asset.buffers .empty ()
4747
4754
// We only support writing Vectors and ByteViews as embedded buffers
4748
- && (std::holds_alternative<sources::Vector >(asset.buffers .front ().data ) || std::holds_alternative<sources::ByteView>(asset.buffers .front ().data ))
4755
+ && (std::holds_alternative<sources::Array >(asset.buffers .front ().data ) || std::holds_alternative<sources::ByteView>(asset.buffers .front ().data ))
4749
4756
&& asset.buffers .front ().byteLength < std::numeric_limits<decltype (BinaryGltfChunk::chunkLength)>::max ();
4750
4757
4751
4758
std::size_t binarySize = sizeof (BinaryGltfHeader) + sizeof (BinaryGltfChunk) + json.size ();
@@ -4782,7 +4789,7 @@ fg::Expected<fg::ExportResult<std::vector<std::byte>>> fg::Exporter::writeGltfBi
4782
4789
4783
4790
std::visit (visitor {
4784
4791
[](auto arg) {},
4785
- [&](sources::Vector & vector) {
4792
+ [&](sources::Array & vector) {
4786
4793
write (vector.bytes .data (), buffer.byteLength );
4787
4794
},
4788
4795
[&](sources::ByteView& byteView) {
@@ -4798,7 +4805,7 @@ namespace fastgltf {
4798
4805
void writeFile (const DataSource& dataSource, fs::path baseFolder, fs::path filePath) {
4799
4806
std::visit (visitor {
4800
4807
[](auto & arg) {},
4801
- [&](const fastgltf::sources::Vector &vector) {
4808
+ [&](const fastgltf::sources::Array &vector) {
4802
4809
std::ofstream file (baseFolder / filePath, std::ios::out | std::ios::binary);
4803
4810
file.write (reinterpret_cast <const char *>(vector.bytes .data ()),
4804
4811
static_cast <std::streamsize>(vector.bytes .size ()));
0 commit comments