Skip to content

Commit

Permalink
Update tests and allow gltf-buffer mimetypes (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessey-git authored Feb 14, 2021
1 parent 0f957ff commit f4f18f2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
16 changes: 13 additions & 3 deletions include/fx/gltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ namespace gltf
constexpr uint32_t GLBChunkBIN = 0x004e4942u;

constexpr char const * const MimetypeApplicationOctet = "data:application/octet-stream;base64";
constexpr char const * const MimetypeGLTFBuffer = "data:application/gltf-buffer;base64";
constexpr char const * const MimetypeImagePNG = "data:image/png;base64";
constexpr char const * const MimetypeImageJPG = "data:image/jpeg;base64";
} // namespace detail
Expand Down Expand Up @@ -491,7 +492,7 @@ namespace gltf

FX_GLTF_NODISCARD bool IsEmbeddedResource() const noexcept
{
return uri.find(detail::MimetypeApplicationOctet) == 0;
return uri.find(detail::MimetypeApplicationOctet) == 0 || uri.find(detail::MimetypeGLTFBuffer) == 0;
}

void SetEmbeddedResource()
Expand Down Expand Up @@ -1668,10 +1669,19 @@ namespace gltf

inline void MaterializeData(Buffer & buffer)
{
const std::size_t startPos = std::char_traits<char>::length(detail::MimetypeApplicationOctet) + 1;
std::size_t startPos = 0;
if (buffer.uri.find(detail::MimetypeApplicationOctet) == 0)
{
startPos = std::char_traits<char>::length(detail::MimetypeApplicationOctet) + 1;
}
else if (buffer.uri.find(detail::MimetypeGLTFBuffer) == 0)
{
startPos = std::char_traits<char>::length(detail::MimetypeGLTFBuffer) + 1;
}

const std::size_t base64Length = buffer.uri.length() - startPos;
const std::size_t decodedEstimate = base64Length / 4 * 3;
if ((decodedEstimate - 2) > buffer.byteLength) // we need to give room for padding...
if (startPos == 0 || (decodedEstimate - 2) > buffer.byteLength) // we need to give room for padding...
{
throw invalid_gltf_document("Invalid buffer.uri value", "malformed base64");
}
Expand Down
2 changes: 1 addition & 1 deletion test/data/glTF-Sample-Models
19 changes: 17 additions & 2 deletions test/src/unit-roundtrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ TEST_CASE("roundtrip")
"data/glTF-Sample-Models/2.0/BoomBox/glTF/BoomBox.gltf",
"data/glTF-Sample-Models/2.0/BoomBoxWithAxes/glTF/BoomBoxWithAxes.gltf",
"data/glTF-Sample-Models/2.0/Box/glTF/Box.gltf",
"data/glTF-Sample-Models/2.0/Box With Spaces/glTF/Box With Spaces.gltf",
"data/glTF-Sample-Models/2.0/BoxAnimated/glTF/BoxAnimated.gltf",
"data/glTF-Sample-Models/2.0/BoxInterleaved/glTF/BoxInterleaved.gltf",
"data/glTF-Sample-Models/2.0/BoxTextured/glTF/BoxTextured.gltf",
Expand All @@ -143,6 +144,7 @@ TEST_CASE("roundtrip")
"data/glTF-Sample-Models/2.0/GearboxAssy/glTF/GearboxAssy.gltf",
"data/glTF-Sample-Models/2.0/InterpolationTest/glTF/InterpolationTest.gltf",
"data/glTF-Sample-Models/2.0/Lantern/glTF/Lantern.gltf",
"data/glTF-Sample-Models/2.0/MaterialsVariantsShoe/glTF/MaterialsVariantsShoe.gltf",
"data/glTF-Sample-Models/2.0/MetalRoughSpheres/glTF/MetalRoughSpheres.gltf",
"data/glTF-Sample-Models/2.0/MetalRoughSpheresNoTextures/glTF/MetalRoughSpheresNoTextures.gltf",
"data/glTF-Sample-Models/2.0/MorphPrimitivesTest/glTF/MorphPrimitivesTest.gltf",
Expand All @@ -154,15 +156,21 @@ TEST_CASE("roundtrip")
"data/glTF-Sample-Models/2.0/RiggedFigure/glTF/RiggedFigure.gltf",
"data/glTF-Sample-Models/2.0/RiggedSimple/glTF/RiggedSimple.gltf",
"data/glTF-Sample-Models/2.0/SciFiHelmet/glTF/SciFiHelmet.gltf",
"data/glTF-Sample-Models/2.0/SheenChair/glTF/SheenChair.gltf",
"data/glTF-Sample-Models/2.0/SheenCloth/glTF/SheenCloth.gltf",
"data/glTF-Sample-Models/2.0/SimpleMeshes/glTF/SimpleMeshes.gltf",
"data/glTF-Sample-Models/2.0/SimpleMorph/glTF/SimpleMorph.gltf",
"data/glTF-Sample-Models/2.0/SimpleSkin/glTF/SimpleSkin.gltf",
"data/glTF-Sample-Models/2.0/SimpleSparseAccessor/glTF/SimpleSparseAccessor.gltf",
"data/glTF-Sample-Models/2.0/SpecGlossVsMetalRough/glTF/SpecGlossVsMetalRough.gltf",
"data/glTF-Sample-Models/2.0/Sponza/glTF/Sponza.gltf",
"data/glTF-Sample-Models/2.0/Suzanne/glTF/Suzanne.gltf",
"data/glTF-Sample-Models/2.0/TextureCoordinateTest/glTF/TextureCoordinateTest.gltf",
"data/glTF-Sample-Models/2.0/TextureSettingsTest/glTF/TextureSettingsTest.gltf",
"data/glTF-Sample-Models/2.0/TextureTransformMultiTest/glTF/TextureTransformMultiTest.gltf",
"data/glTF-Sample-Models/2.0/TextureTransformTest/glTF/TextureTransformTest.gltf",
"data/glTF-Sample-Models/2.0/ToyCar/glTF/ToyCar.gltf",
"data/glTF-Sample-Models/2.0/TransmissionTest/glTF/TransmissionTest.gltf",
"data/glTF-Sample-Models/2.0/Triangle/glTF/Triangle.gltf",
"data/glTF-Sample-Models/2.0/TriangleWithoutIndices/glTF/TriangleWithoutIndices.gltf",
"data/glTF-Sample-Models/2.0/TwoSidedPlane/glTF/TwoSidedPlane.gltf",
Expand Down Expand Up @@ -206,8 +214,9 @@ TEST_CASE("roundtrip")
"data/glTF-Sample-Models/2.0/RiggedFigure/glTF-Embedded/RiggedFigure.gltf",
"data/glTF-Sample-Models/2.0/RiggedSimple/glTF-Embedded/RiggedSimple.gltf",
"data/glTF-Sample-Models/2.0/SimpleMeshes/glTF-Embedded/SimpleMeshes.gltf",
//"data/glTF-Sample-Models/2.0/SimpleMorph/glTF-Embedded/SimpleMorph.gltf", // Invalid mimetype
//"data/glTF-Sample-Models/2.0/SimpleSparseAccessor/glTF-Embedded/SimpleSparseAccessor.gltf", // Invalid mimetype
"data/glTF-Sample-Models/2.0/SimpleMorph/glTF-Embedded/SimpleMorph.gltf",
"data/glTF-Sample-Models/2.0/SimpleSkin/glTF-Embedded/SimpleSkin.gltf",
"data/glTF-Sample-Models/2.0/SimpleSparseAccessor/glTF-Embedded/SimpleSparseAccessor.gltf",
"data/glTF-Sample-Models/2.0/TextureCoordinateTest/glTF-Embedded/TextureCoordinateTest.gltf",
"data/glTF-Sample-Models/2.0/TextureSettingsTest/glTF-Embedded/TextureSettingsTest.gltf",
"data/glTF-Sample-Models/2.0/Triangle/glTF-Embedded/Triangle.gltf",
Expand Down Expand Up @@ -236,6 +245,7 @@ TEST_CASE("roundtrip")
"data/glTF-Sample-Models/2.0/Duck/glTF-Draco/Duck.gltf",
"data/glTF-Sample-Models/2.0/GearboxAssy/glTF-Draco/GearboxAssy.gltf",
"data/glTF-Sample-Models/2.0/Lantern/glTF-Draco/Lantern.gltf",
"data/glTF-Sample-Models/2.0/MorphPrimitivesTest/glTF-Draco/MorphPrimitivesTest.gltf",
"data/glTF-Sample-Models/2.0/ReciprocatingSaw/glTF-Draco/ReciprocatingSaw.gltf",
"data/glTF-Sample-Models/2.0/RiggedFigure/glTF-Draco/RiggedFigure.gltf",
"data/glTF-Sample-Models/2.0/RiggedSimple/glTF-Draco/RiggedSimple.gltf",
Expand Down Expand Up @@ -276,6 +286,7 @@ TEST_CASE("roundtrip")
"data/glTF-Sample-Models/2.0/GearboxAssy/glTF-Binary/GearboxAssy.glb",
"data/glTF-Sample-Models/2.0/InterpolationTest/glTF-Binary/InterpolationTest.glb",
"data/glTF-Sample-Models/2.0/Lantern/glTF-Binary/Lantern.glb",
"data/glTF-Sample-Models/2.0/MaterialsVariantsShoe/glTF-Binary/MaterialsVariantsShoe.glb",
"data/glTF-Sample-Models/2.0/MetalRoughSpheres/glTF-Binary/MetalRoughSpheres.glb",
"data/glTF-Sample-Models/2.0/MetalRoughSpheresNoTextures/glTF-Binary/MetalRoughSpheresNoTextures.glb",
"data/glTF-Sample-Models/2.0/MorphPrimitivesTest/glTF-Binary/MorphPrimitivesTest.glb",
Expand All @@ -286,9 +297,13 @@ TEST_CASE("roundtrip")
"data/glTF-Sample-Models/2.0/ReciprocatingSaw/glTF-Binary/ReciprocatingSaw.glb",
"data/glTF-Sample-Models/2.0/RiggedFigure/glTF-Binary/RiggedFigure.glb",
"data/glTF-Sample-Models/2.0/RiggedSimple/glTF-Binary/RiggedSimple.glb",
"data/glTF-Sample-Models/2.0/SheenChair/glTF-Binary/SheenChair.glb",
"data/glTF-Sample-Models/2.0/SpecGlossVsMetalRough/glTF-Binary/SpecGlossVsMetalRough.glb",
"data/glTF-Sample-Models/2.0/TextureCoordinateTest/glTF-Binary/TextureCoordinateTest.glb",
"data/glTF-Sample-Models/2.0/TextureSettingsTest/glTF-Binary/TextureSettingsTest.glb",
"data/glTF-Sample-Models/2.0/TextureTransformMultiTest/glTF-Binary/TextureTransformMultiTest.glb",
"data/glTF-Sample-Models/2.0/ToyCar/glTF-Binary/ToyCar.glb",
"data/glTF-Sample-Models/2.0/TransmissionTest/glTF-Binary/TransmissionTest.glb",
"data/glTF-Sample-Models/2.0/UnlitTest/glTF-Binary/UnlitTest.glb",
"data/glTF-Sample-Models/2.0/VC/glTF-Binary/VC.glb",
"data/glTF-Sample-Models/2.0/VertexColorTest/glTF-Binary/VertexColorTest.glb",
Expand Down
12 changes: 12 additions & 0 deletions test/src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ namespace utility
(path.find("doubleSided") != std::string::npos && element["value"] == false) ||
(path.find("metallicFactor") != std::string::npos && element["value"] == 1.0f) ||
(path.find("roughnessFactor") != std::string::npos && element["value"] == 1.0f) ||
(path.find("strength") != std::string::npos && element["value"] == 1.0f) ||
(path.find("alphaMode") != std::string::npos && element["value"] == "OPAQUE") ||
(path.find("texCoord") != std::string::npos && element["value"] == 0))
{
Expand All @@ -154,6 +155,17 @@ namespace utility
}
else if (element["op"] == "replace")
{
if (path.find("nodes") != std::string::npos)
{
if (element["value"].find("rotation") != element["value"].end())
{
if (element["value"]["rotation"].get<std::vector<float>>() == std::vector<float>{ 0.0f, 0.0f, 0.0f, 1.0f })
{
continue;
}
}
}

if (element["value"].is_number_float())
{
// The text-based json diff says our numbers are mismatched but that could be
Expand Down

0 comments on commit f4f18f2

Please sign in to comment.