Skip to content

Commit

Permalink
Merge pull request CesiumGS#822 from CesiumGS/refactor-feature-metada…
Browse files Browse the repository at this point in the history
…ta-textures

Let feature + metadata textures make copies
  • Loading branch information
j9liu authored Feb 29, 2024
2 parents e443a65 + f17e484 commit 356afb4
Show file tree
Hide file tree
Showing 11 changed files with 1,877 additions and 697 deletions.
7 changes: 5 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

##### Additions :tada:

- Added `TextureViewOptions`, which includes the following flags:
- `applyKhrTextureTransformExtension` . When true, the view will automatically transform texture coordinates before sampling the texture.
- `makeImageCopy`. When true, the view will make its own CPU copy of the image data.
- Added `TextureView`, which views an arbitrary glTF texture and can be affected by `TextureViewOptions`. `FeatureIdTextureView` and `PropertyTexturePropertyView` now inherit this class.
- Added `options` parameter to `PropertyTextureView::getPropertyView` and `PropertyTextureView::forEachProperty`, which allow views to be constructed with property-specific options.
- Added `KhrTextureTransform`, a utility class that parses the `KHR_texture_transform` glTF extension and reports whether it is valid. UVs may be transformed on the CPU using `applyTransform`.
- Added `applyKhrTextureTransformExtension` to the constructors of `FeatureIdTextureView` and `PropertyTexturePropertyView`. When true, the views will automatically transform texture coordinates before retrieving features and metadata. This is false by default to avoid breaking existing implementations.
- Added `getTextureTransform` methods to `FeatureIdTextureView` and `PropertyTexturePropertyView`.
- Added `contains` method to `BoundingSphere`.
- Added `GlobeRectangle::MAXIMUM` static field.
- Added `ReferenceCountedThreadSafe` type alias.
Expand Down
68 changes: 6 additions & 62 deletions CesiumGltf/include/CesiumGltf/FeatureIdTextureView.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "CesiumGltf/Image.h"
#include "CesiumGltf/ImageCesium.h"
#include "CesiumGltf/KhrTextureTransform.h"
#include "CesiumGltf/Model.h"
#include "CesiumGltf/Texture.h"
#include "CesiumGltf/TextureView.h"

#include <algorithm>
#include <cmath>
Expand All @@ -14,6 +14,9 @@
#include <optional>

namespace CesiumGltf {

struct Model;

/**
* @brief The status of a feature ID texture view.
*
Expand Down Expand Up @@ -76,7 +79,7 @@ enum class FeatureIdTextureViewStatus {
* It provides the ability to sample the feature IDs from the
* {@link FeatureIdTexture} using texture coordinates.
*/
class FeatureIdTextureView {
class FeatureIdTextureView : public TextureView {
public:
/**
* @brief Constructs an uninitialized and invalid view.
Expand Down Expand Up @@ -108,7 +111,7 @@ class FeatureIdTextureView {
FeatureIdTextureView(
const Model& model,
const FeatureIdTexture& featureIdTexture,
bool applyKhrTextureTransformExtension = false) noexcept;
const TextureViewOptions& options = TextureViewOptions()) noexcept;

/**
* @brief Get the feature ID from the texture at the given texture
Expand All @@ -129,73 +132,14 @@ class FeatureIdTextureView {
*/
FeatureIdTextureViewStatus status() const noexcept { return this->_status; }

/**
* @brief Get the actual feature ID texture.
*
* This will be nullptr if the feature ID texture view runs into problems
* during construction.
*/
const ImageCesium* getImage() const noexcept { return this->_pImage; }

/**
* @brief Get the sampler describing how to sample the data from the
* feature ID texture.
*
* This will be nullptr if the feature ID texture view runs into
* problems during construction.
*/
const Sampler* getSampler() const noexcept { return this->_pSampler; }

/**
* @brief Get the channels of this feature ID texture. The channels represent
* the bytes of the actual feature ID, in little-endian order.
*/
std::vector<int64_t> getChannels() const noexcept { return this->_channels; }

/**
* @brief Get the texture coordinate set index for this feature ID
* texture.
*
* If applyKhrTextureTransformExtension is true, and if the feature ID texture
* contains the `KHR_texture_transform` extension, this will return the value
* from the extension, as it is meant to override the original index. However,
* if the extension does not specify a TEXCOORD set index, then the original
* index of the feature ID texture is returned.
*/
int64_t getTexCoordSetIndex() const noexcept {
if (this->_applyTextureTransform && this->_textureTransform) {
return this->_textureTransform->getTexCoordSetIndex().value_or(
this->_texCoordSetIndex);
}
return this->_texCoordSetIndex;
}

/**
* @brief Get the KHR_texture_transform for this feature ID texture, if it
* exists.
*
* Even if this view was constructed with applyKhrTextureTransformExtension
* set to false, it will save the extension's values, and they may be
* retrieved through this function.
*
* If this view was constructed with applyKhrTextureTransformExtension set to
* true, any texture coordinates passed into `getFeatureID` will be
* automatically transformed, so there's no need to re-apply the transform
* here.
*/
std::optional<KhrTextureTransform> getTextureTransform() const noexcept {
return this->_textureTransform;
}

private:
FeatureIdTextureViewStatus _status;
int64_t _texCoordSetIndex;
std::vector<int64_t> _channels;

const ImageCesium* _pImage;
const Sampler* _pSampler;

bool _applyTextureTransform;
std::optional<KhrTextureTransform> _textureTransform;
};
} // namespace CesiumGltf
Loading

0 comments on commit 356afb4

Please sign in to comment.