Skip to content

Commit

Permalink
Eliminate another round of using namespace CesiumGltf.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Oct 31, 2024
1 parent a6d7b3b commit 28333a1
Show file tree
Hide file tree
Showing 15 changed files with 818 additions and 757 deletions.
318 changes: 178 additions & 140 deletions Source/CesiumRuntime/Private/CesiumGltfComponent.cpp

Large diffs are not rendered by default.

70 changes: 40 additions & 30 deletions Source/CesiumRuntime/Private/CesiumGltfTextures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
#include <CesiumGltfReader/GltfReader.h>

using namespace CesiumAsync;
using namespace CesiumGltf;

namespace {

// Determines if a glTF primitive is usable for our purposes.
bool isValidPrimitive(const Model& gltf, const MeshPrimitive& primitive);
bool isValidPrimitive(
const CesiumGltf::Model& gltf,
const CesiumGltf::MeshPrimitive& primitive);

// Determines if an Accessor's componentType is valid for an index buffer.
bool isSupportedIndexComponentType(int32_t componentType);
Expand All @@ -25,13 +26,15 @@ bool isSupportedIndexComponentType(int32_t componentType);
bool isSupportedPrimitiveMode(int32_t primitiveMode);

// Determines if the given texture uses mipmaps.
bool doesTextureUseMipmaps(const Model& gltf, const Texture& texture);
bool doesTextureUseMipmaps(
const CesiumGltf::Model& gltf,
const CesiumGltf::Texture& texture);

// Creates a single texture in the load thread.
SharedFuture<void> createTextureInLoadThread(
const AsyncSystem& asyncSystem,
Model& gltf,
TextureInfo& textureInfo,
CesiumGltf::Model& gltf,
CesiumGltf::TextureInfo& textureInfo,
bool sRGB,
const std::vector<bool>& imageNeedsMipmaps);

Expand All @@ -44,7 +47,7 @@ SharedFuture<void> createTextureInLoadThread(
// requires mipmaps. An image requires mipmaps if any of its textures have a
// sampler that will use them.
std::vector<bool> imageNeedsMipmaps(model.images.size(), false);
for (const Texture& texture : model.textures) {
for (const CesiumGltf::Texture& texture : model.textures) {
int32_t imageIndex = texture.source;
if (imageIndex < 0 || imageIndex >= model.images.size()) {
continue;
Expand All @@ -60,17 +63,17 @@ SharedFuture<void> createTextureInLoadThread(
model.forEachPrimitiveInScene(
-1,
[&imageNeedsMipmaps, &asyncSystem, &futures](
Model& gltf,
Node& node,
Mesh& mesh,
MeshPrimitive& primitive,
CesiumGltf::Model& gltf,
CesiumGltf::Node& node,
CesiumGltf::Mesh& mesh,
CesiumGltf::MeshPrimitive& primitive,
const glm::dmat4& transform) {
if (!isValidPrimitive(gltf, primitive)) {
return;
}

Material* pMaterial =
Model::getSafe(&gltf.materials, primitive.material);
CesiumGltf::Material* pMaterial =
CesiumGltf::Model::getSafe(&gltf.materials, primitive.material);
if (!pMaterial) {
// A primitive using the default material will not have any textures.
return;
Expand Down Expand Up @@ -134,7 +137,7 @@ SharedFuture<void> createTextureInLoadThread(
waterMaskTextureIdIt->second.isInt64()) {
int32_t waterMaskTextureId = static_cast<int32_t>(
waterMaskTextureIdIt->second.getInt64OrDefault(-1));
TextureInfo waterMaskInfo;
CesiumGltf::TextureInfo waterMaskInfo;
waterMaskInfo.index = waterMaskTextureId;
if (waterMaskTextureId >= 0 &&
waterMaskTextureId < gltf.textures.size()) {
Expand All @@ -156,15 +159,15 @@ SharedFuture<void> createTextureInLoadThread(
namespace {

bool isSupportedIndexComponentType(int32_t componentType) {
return componentType == Accessor::ComponentType::UNSIGNED_BYTE ||
componentType == Accessor::ComponentType::UNSIGNED_SHORT ||
componentType == Accessor::ComponentType::UNSIGNED_INT;
return componentType == CesiumGltf::Accessor::ComponentType::UNSIGNED_BYTE ||
componentType == CesiumGltf::Accessor::ComponentType::UNSIGNED_SHORT ||
componentType == CesiumGltf::Accessor::ComponentType::UNSIGNED_INT;
}

bool isSupportedPrimitiveMode(int32_t primitiveMode) {
return primitiveMode == MeshPrimitive::Mode::TRIANGLES ||
primitiveMode == MeshPrimitive::Mode::TRIANGLE_STRIP ||
primitiveMode == MeshPrimitive::Mode::POINTS;
return primitiveMode == CesiumGltf::MeshPrimitive::Mode::TRIANGLES ||
primitiveMode == CesiumGltf::MeshPrimitive::Mode::TRIANGLE_STRIP ||
primitiveMode == CesiumGltf::MeshPrimitive::Mode::POINTS;
}

// Determines if a glTF primitive is usable for our purposes.
Expand All @@ -177,21 +180,23 @@ bool isValidPrimitive(
}

auto positionAccessorIt =
primitive.attributes.find(VertexAttributeSemantics::POSITION);
primitive.attributes.find(CesiumGltf::VertexAttributeSemantics::POSITION);
if (positionAccessorIt == primitive.attributes.end()) {
// This primitive doesn't have a POSITION semantic, so it's not valid.
return false;
}

AccessorView<FVector3f> positionView(gltf, positionAccessorIt->second);
if (positionView.status() != AccessorViewStatus::Valid) {
CesiumGltf::AccessorView<FVector3f> positionView(
gltf,
positionAccessorIt->second);
if (positionView.status() != CesiumGltf::AccessorViewStatus::Valid) {
// This primitive's POSITION accessor is invalid, so the primitive is not
// valid.
return false;
}

const Accessor* pIndexAccessor =
Model::getSafe(&gltf.accessors, primitive.indices);
const CesiumGltf::Accessor* pIndexAccessor =
CesiumGltf::Model::getSafe(&gltf.accessors, primitive.indices);
if (pIndexAccessor &&
!isSupportedIndexComponentType(pIndexAccessor->componentType)) {
// This primitive's indices are not a supported type, so the primitive is
Expand All @@ -202,8 +207,11 @@ bool isValidPrimitive(
return true;
}

bool doesTextureUseMipmaps(const Model& gltf, const Texture& texture) {
const Sampler& sampler = Model::getSafe(gltf.samplers, texture.sampler);
bool doesTextureUseMipmaps(
const CesiumGltf::Model& gltf,
const CesiumGltf::Texture& texture) {
const CesiumGltf::Sampler& sampler =
CesiumGltf::Model::getSafe(gltf.samplers, texture.sampler);

switch (sampler.minFilter.value_or(
CesiumGltf::Sampler::MinFilter::LINEAR_MIPMAP_LINEAR)) {
Expand All @@ -219,15 +227,17 @@ bool doesTextureUseMipmaps(const Model& gltf, const Texture& texture) {

SharedFuture<void> createTextureInLoadThread(
const AsyncSystem& asyncSystem,
Model& gltf,
TextureInfo& textureInfo,
CesiumGltf::Model& gltf,
CesiumGltf::TextureInfo& textureInfo,
bool sRGB,
const std::vector<bool>& imageNeedsMipmaps) {
Texture* pTexture = Model::getSafe(&gltf.textures, textureInfo.index);
CesiumGltf::Texture* pTexture =
CesiumGltf::Model::getSafe(&gltf.textures, textureInfo.index);
if (pTexture == nullptr)
return asyncSystem.createResolvedFuture().share();

Image* pImage = Model::getSafe(&gltf.images, pTexture->source);
CesiumGltf::Image* pImage =
CesiumGltf::Model::getSafe(&gltf.images, pTexture->source);
if (pImage == nullptr)
return asyncSystem.createResolvedFuture().share();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@
#include "CesiumGltfSpecUtility.h"
#include "Misc/AutomationTest.h"

using namespace CesiumGltf;

BEGIN_DEFINE_SPEC(
FCesiumFeatureIdAttributeSpec,
"Cesium.Unit.FeatureIdAttribute",
EAutomationTestFlags::ApplicationContextMask |
EAutomationTestFlags::ProductFilter)
Model model;
MeshPrimitive* pPrimitive;
CesiumGltf::Model model;
CesiumGltf::MeshPrimitive* pPrimitive;
END_DEFINE_SPEC(FCesiumFeatureIdAttributeSpec)

void FCesiumFeatureIdAttributeSpec::Define() {
Describe("Constructor", [this]() {
BeforeEach([this]() {
model = Model();
Mesh& mesh = model.meshes.emplace_back();
model = CesiumGltf::Model();
CesiumGltf::Mesh& mesh = model.meshes.emplace_back();
pPrimitive = &mesh.primitives.emplace_back();
});

Expand Down Expand Up @@ -76,9 +74,10 @@ void FCesiumFeatureIdAttributeSpec::Define() {

It("constructs invalid instance for attribute with invalid accessor",
[this]() {
Accessor& accessor = model.accessors.emplace_back();
accessor.type = AccessorSpec::Type::VEC2;
accessor.componentType = AccessorSpec::ComponentType::FLOAT;
CesiumGltf::Accessor& accessor = model.accessors.emplace_back();
accessor.type = CesiumGltf::AccessorSpec::Type::VEC2;
accessor.componentType =
CesiumGltf::AccessorSpec::ComponentType::FLOAT;
const int64 attributeIndex = 0;
pPrimitive->attributes.insert({"_FEATURE_ID_0", 0});

Expand Down Expand Up @@ -127,8 +126,8 @@ void FCesiumFeatureIdAttributeSpec::Define() {

Describe("GetVertexCount", [this]() {
BeforeEach([this]() {
model = Model();
Mesh& mesh = model.meshes.emplace_back();
model = CesiumGltf::Model();
CesiumGltf::Mesh& mesh = model.meshes.emplace_back();
pPrimitive = &mesh.primitives.emplace_back();
});

Expand Down Expand Up @@ -184,8 +183,8 @@ void FCesiumFeatureIdAttributeSpec::Define() {

Describe("GetFeatureIDForVertex", [this]() {
BeforeEach([this]() {
model = Model();
Mesh& mesh = model.meshes.emplace_back();
model = CesiumGltf::Model();
CesiumGltf::Mesh& mesh = model.meshes.emplace_back();
pPrimitive = &mesh.primitives.emplace_back();
});

Expand Down
Loading

0 comments on commit 28333a1

Please sign in to comment.