2024-04-08 17:31:38 +08:00
|
|
|
#include "ConvertTileToGltf.h"
|
|
|
|
|
|
2024-12-21 01:00:09 +08:00
|
|
|
#include <Cesium3DTilesContent/GltfConverterResult.h>
|
2024-12-18 06:27:03 +08:00
|
|
|
#include <CesiumGltf/Accessor.h>
|
|
|
|
|
#include <CesiumGltf/BufferView.h>
|
2024-04-08 17:31:38 +08:00
|
|
|
#include <CesiumGltf/ExtensionCesiumRTC.h>
|
2024-12-18 06:27:03 +08:00
|
|
|
#include <CesiumGltf/Mesh.h>
|
|
|
|
|
#include <CesiumGltf/MeshPrimitive.h>
|
|
|
|
|
#include <CesiumGltf/Model.h>
|
2024-04-08 17:31:38 +08:00
|
|
|
|
2025-01-16 05:58:03 +08:00
|
|
|
#include <doctest/doctest.h>
|
2024-04-08 17:31:38 +08:00
|
|
|
|
2024-12-18 06:27:03 +08:00
|
|
|
#include <cstddef>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
2024-04-08 17:31:38 +08:00
|
|
|
using namespace Cesium3DTilesContent;
|
|
|
|
|
using namespace CesiumGltf;
|
|
|
|
|
|
|
|
|
|
TEST_CASE("B3dmToGltfConverter") {
|
2025-01-16 05:58:03 +08:00
|
|
|
SUBCASE("includes CESIUM_RTC extension in extensionsUsed") {
|
2024-04-08 17:31:38 +08:00
|
|
|
std::filesystem::path testFilePath = Cesium3DTilesSelection_TEST_DATA_DIR;
|
|
|
|
|
testFilePath = testFilePath / "BatchTables" / "batchedWithJson.b3dm";
|
|
|
|
|
|
|
|
|
|
GltfConverterResult result = ConvertTileToGltf::fromB3dm(testFilePath);
|
|
|
|
|
|
|
|
|
|
REQUIRE(result.model);
|
|
|
|
|
|
|
|
|
|
Model& gltf = *result.model;
|
|
|
|
|
REQUIRE(gltf.getExtension<ExtensionCesiumRTC>() != nullptr);
|
|
|
|
|
CHECK(gltf.isExtensionUsed(ExtensionCesiumRTC::ExtensionName));
|
2024-04-08 17:39:15 +08:00
|
|
|
CHECK(gltf.isExtensionRequired(ExtensionCesiumRTC::ExtensionName));
|
2024-04-08 17:31:38 +08:00
|
|
|
}
|
2024-04-08 19:04:53 +08:00
|
|
|
|
2025-01-16 05:58:03 +08:00
|
|
|
SUBCASE("Index bufferViews created from Draco are valid") {
|
2024-04-08 19:04:53 +08:00
|
|
|
std::filesystem::path testFilePath = Cesium3DTilesSelection_TEST_DATA_DIR;
|
|
|
|
|
testFilePath =
|
|
|
|
|
testFilePath / "BatchTables" / "batchedWithBatchTable-draco.b3dm";
|
|
|
|
|
|
|
|
|
|
GltfConverterResult result = ConvertTileToGltf::fromB3dm(testFilePath);
|
|
|
|
|
REQUIRE(result.model);
|
|
|
|
|
|
|
|
|
|
Model& gltf = *result.model;
|
|
|
|
|
CHECK(!gltf.meshes.empty());
|
|
|
|
|
|
|
|
|
|
for (const Mesh& mesh : gltf.meshes) {
|
|
|
|
|
CHECK(!mesh.primitives.empty());
|
|
|
|
|
for (const MeshPrimitive& primitive : mesh.primitives) {
|
|
|
|
|
REQUIRE(primitive.indices >= 0);
|
|
|
|
|
REQUIRE(size_t(primitive.indices) < gltf.accessors.size());
|
|
|
|
|
const Accessor& indicesAccessor =
|
|
|
|
|
gltf.accessors[size_t(primitive.indices)];
|
|
|
|
|
|
|
|
|
|
REQUIRE(indicesAccessor.bufferView >= 0);
|
|
|
|
|
REQUIRE(sizeof(indicesAccessor.bufferView) < gltf.bufferViews.size());
|
|
|
|
|
const BufferView& indicesBufferView =
|
|
|
|
|
gltf.bufferViews[size_t(indicesAccessor.bufferView)];
|
|
|
|
|
|
|
|
|
|
CHECK(!indicesBufferView.byteStride.has_value());
|
|
|
|
|
CHECK(
|
|
|
|
|
indicesBufferView.target ==
|
|
|
|
|
BufferView::Target::ELEMENT_ARRAY_BUFFER);
|
|
|
|
|
|
|
|
|
|
auto positionIt = primitive.attributes.find("POSITION");
|
|
|
|
|
REQUIRE(positionIt != primitive.attributes.end());
|
|
|
|
|
REQUIRE(positionIt->second >= 0);
|
|
|
|
|
REQUIRE(size_t(positionIt->second) < gltf.accessors.size());
|
|
|
|
|
const Accessor& positionAccessor =
|
|
|
|
|
gltf.accessors[size_t(positionIt->second)];
|
|
|
|
|
|
|
|
|
|
REQUIRE(positionAccessor.bufferView >= 0);
|
|
|
|
|
REQUIRE(sizeof(positionAccessor.bufferView) < gltf.bufferViews.size());
|
|
|
|
|
const BufferView& positionBufferView =
|
|
|
|
|
gltf.bufferViews[size_t(positionAccessor.bufferView)];
|
|
|
|
|
|
|
|
|
|
CHECK(positionBufferView.target == BufferView::Target::ARRAY_BUFFER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-08 17:31:38 +08:00
|
|
|
}
|