Cesium for Unreal 2.13.2
Loading...
Searching...
No Matches
CesiumFeatureIdTexture.h
Go to the documentation of this file.
1// Copyright 2020-2024 CesiumGS, Inc. and Contributors
2
3#pragma once
4
5#include "Containers/UnrealString.h"
6#include "Kismet/BlueprintFunctionLibrary.h"
7
8#include <CesiumGltf/AccessorUtility.h>
9#include <CesiumGltf/FeatureIdTextureView.h>
10
11#include "CesiumFeatureIdTexture.generated.h"
12
13namespace CesiumGltf {
14struct Model;
15struct FeatureIdTexture;
16} // namespace CesiumGltf
17
18/**
19 * @brief Reports the status of a FCesiumFeatureIdTexture. If the feature ID
20 * texture cannot be accessed, this briefly indicates why.
21 */
22UENUM(BlueprintType)
24 /* The feature ID texture is valid. */
25 Valid = 0,
26 /* The feature ID texture cannot be found in the glTF, or the texture itself
27 has errors. */
29 /* The feature ID texture is being read in an invalid way -- for example,
30 trying to read nonexistent image channels. */
32};
33
34/**
35 * @brief A blueprint-accessible wrapper for a feature ID texture from a glTF
36 * primitive. Provides access to per-pixel feature IDs, which can be used with
37 * the corresponding {@link FCesiumPropertyTable} to access per-pixel metadata.
38 */
39USTRUCT(BlueprintType)
40struct CESIUMRUNTIME_API FCesiumFeatureIdTexture {
41 GENERATED_USTRUCT_BODY()
42
43public:
44 /**
45 * @brief Constructs an empty feature ID texture instance. Empty feature ID
46 * textures can be constructed while trying to convert a FCesiumFeatureIdSet
47 * that is not an texture. In this case, the status reports it is an invalid
48 * texture.
49 */
52
53 /**
54 * @brief Constructs a feature ID texture instance.
55 *
56 * @param Model The model.
57 * @param Primitive The mesh primitive containing the feature ID texture.
58 * @param FeatureIdTexture The texture specified by the FeatureId.
59 * @param PropertyTableName The name of the property table this texture
60 * corresponds to, if one exists, for backwards compatibility.
61 */
63 const CesiumGltf::Model& Model,
64 const CesiumGltf::MeshPrimitive& Primitive,
65 const CesiumGltf::FeatureIdTexture& FeatureIdTexture,
66 const FString& PropertyTableName);
67
68 /**
69 * @brief Gets the underlying view of this feature ID texture.
70 */
73 return this->_featureIdTextureView;
74 }
75
76private:
78 CesiumGltf::FeatureIdTextureView _featureIdTextureView;
79 CesiumGltf::TexCoordAccessorType _texCoordAccessor;
80 int64 _textureCoordinateSetIndex;
81
82 // For backwards compatibility.
83 FString _propertyTableName;
84
86};
87
88UCLASS()
90 : public UBlueprintFunctionLibrary {
91 GENERATED_BODY()
92
93public:
94 PRAGMA_DISABLE_DEPRECATION_WARNINGS
95 /**
96 * Gets the name of the feature table corresponding to this feature ID
97 * texture. The name can be used to fetch the appropriate
98 * {@link FCesiumPropertyTable} from the FCesiumMetadataModel.
99 */
100 UFUNCTION(
101 BlueprintCallable,
102 BlueprintPure,
103 Category = "Cesium|Metadata|FeatureIdTexture",
104 Meta =
105 (DeprecatedFunction,
106 DeprecationMessage =
107 "Use GetPropertyTableIndex on a CesiumFeatureIdSet instead."))
108 static const FString&
110 const FCesiumFeatureIdTexture& FeatureIDTexture);
111 PRAGMA_ENABLE_DEPRECATION_WARNINGS
112
113 /**
114 * Gets the status of the feature ID texture. If this texture is
115 * invalid in any way, this will briefly indicate why.
116 */
117 UFUNCTION(
118 BlueprintCallable,
119 BlueprintPure,
120 Category = "Cesium|Features|FeatureIDTexture")
122 UPARAM(ref) const FCesiumFeatureIdTexture& FeatureIDTexture);
123
124 /**
125 * Gets the glTF texture coordinate set index used by the feature ID texture.
126 * This is the index N corresponding to the "TEXCOORD_N" attribute on the glTF
127 * primitive that samples this texture.
128 *
129 * If the texture contains the `KHR_texture_transform` extension, the original
130 * texture coordinate set index can be overridden by the one provided by the
131 * extension.
132 *
133 * If the feature ID texture is invalid, this returns -1.
134 */
135 UFUNCTION(
136 BlueprintCallable,
137 BlueprintPure,
138 Category = "Cesium|Features|FeatureIDTexture")
140 UPARAM(ref) const FCesiumFeatureIdTexture& FeatureIDTexture);
141
142 /**
143 * Gets the UV channel containing the texture coordinate set that is used by
144 * the feature ID texture on the given component. This refers to the UV
145 * channel it uses on the primitive's static mesh, which is not necessarily
146 * equal to value of GetGltfTextureCoordinateSetIndex.
147 *
148 * This function may be used with FindCollisionUV to get the feature ID from a
149 * line trace hit. However, in order for this function to work, the feature ID
150 * texture should be listed under the CesiumFeaturesMetadataComponent of the
151 * owner Cesium3DTileset. Otherwise, its texture coordinate set may not be
152 * included in the Unreal mesh data. To avoid using
153 * CesiumFeaturesMetadataComponent, use GetFeatureIDFromHit instead.
154 *
155 * This returns -1 if the feature ID texture is invalid, or if the specified
156 * texture coordinate set is not present in the component's mesh data.
157 */
158 UFUNCTION(
159 BlueprintCallable,
160 BlueprintPure,
161 Category = "Cesium|Features|FeatureIDTexture")
162 static int64 GetUnrealUVChannel(
163 const UPrimitiveComponent* Component,
164 UPARAM(ref) const FCesiumFeatureIdTexture& FeatureIDTexture);
165
166 PRAGMA_DISABLE_DEPRECATION_WARNINGS
167 /**
168 * Gets the feature ID corresponding to the pixel specified by the texture
169 * coordinates. The feature ID can be used with a FCesiumPropertyTable to
170 * retrieve the per-pixel metadata.
171 *
172 * This assumes the given texture coordinates are from the appropriate
173 * texture coordinate set as indicated by GetTextureCoordinateSetIndex. If the
174 * feature ID texture is invalid, this returns -1.
175 */
176 UFUNCTION(
177 BlueprintCallable,
178 BlueprintPure,
179 Category = "Cesium|Features|FeatureIDTexture")
181 UPARAM(ref) const FCesiumFeatureIdTexture& FeatureIDTexture,
182 float U,
183 float V);
184 PRAGMA_ENABLE_DEPRECATION_WARNINGS
185
186 /**
187 * Gets the feature ID corresponding to the pixel specified by the UV texture
188 * coordinates. The feature ID can be used with a FCesiumPropertyTable to
189 * retrieve the per-pixel metadata.
190 *
191 * If the feature ID texture is invalid, this returns -1.
192 */
193 UFUNCTION(
194 BlueprintCallable,
195 BlueprintPure,
196 Category = "Cesium|Features|FeatureIDTexture")
197 static int64 GetFeatureIDForUV(
198 UPARAM(ref) const FCesiumFeatureIdTexture& FeatureIDTexture,
199 const FVector2D& UV);
200
201 /**
202 * Gets the feature ID associated with the given vertex. The
203 * feature ID can be used with a FCesiumPropertyTable to retrieve the
204 * per-vertex metadata.
205 *
206 * This works if the vertex contains texture coordinates for the relevant
207 * texture coordinate set as indicated by GetGltfTextureCoordinateSetIndex. If
208 * the vertex has no such coordinates, or if the feature ID texture itself is
209 * invalid, this returns -1.
210 */
211 UFUNCTION(
212 BlueprintCallable,
213 BlueprintPure,
214 Category = "Cesium|Features|FeatureIDTexture")
216 UPARAM(ref) const FCesiumFeatureIdTexture& FeatureIDTexture,
217 int64 VertexIndex);
218
219 /**
220 * Gets the feature ID from a given line trace hit on the primitive containing
221 * this feature ID texture. The feature ID can be used with a
222 * FCesiumPropertyTable to retrieve the corresponding metadata.
223 *
224 * If the feature ID texture is invalid, this returns -1.
225 */
226 UFUNCTION(
227 BlueprintCallable,
228 BlueprintPure,
229 Category = "Cesium|Features|FeatureIDTexture")
231 UPARAM(ref) const FCesiumFeatureIdTexture& FeatureIDTexture,
232 const FHitResult& Hit);
233};
ECesiumFeatureIdTextureStatus
Reports the status of a FCesiumFeatureIdTexture.
@ ErrorInvalidTexture
@ ErrorInvalidTextureAccess
static PRAGMA_ENABLE_DEPRECATION_WARNINGS int64 GetFeatureIDForUV(UPARAM(ref) const FCesiumFeatureIdTexture &FeatureIDTexture, const FVector2D &UV)
Gets the feature ID corresponding to the pixel specified by the UV texture coordinates.
static int64 GetGltfTextureCoordinateSetIndex(UPARAM(ref) const FCesiumFeatureIdTexture &FeatureIDTexture)
Gets the glTF texture coordinate set index used by the feature ID texture.
static PRAGMA_DISABLE_DEPRECATION_WARNINGS const FString & GetFeatureTableName(UPARAM(ref) const FCesiumFeatureIdTexture &FeatureIDTexture)
Gets the name of the feature table corresponding to this feature ID texture.
static int64 GetUnrealUVChannel(const UPrimitiveComponent *Component, UPARAM(ref) const FCesiumFeatureIdTexture &FeatureIDTexture)
Gets the UV channel containing the texture coordinate set that is used by the feature ID texture on t...
static PRAGMA_DISABLE_DEPRECATION_WARNINGS int64 GetFeatureIDForTextureCoordinates(UPARAM(ref) const FCesiumFeatureIdTexture &FeatureIDTexture, float U, float V)
Gets the feature ID corresponding to the pixel specified by the texture coordinates.
static int64 GetFeatureIDFromHit(UPARAM(ref) const FCesiumFeatureIdTexture &FeatureIDTexture, const FHitResult &Hit)
Gets the feature ID from a given line trace hit on the primitive containing this feature ID texture.
static int64 GetFeatureIDForVertex(UPARAM(ref) const FCesiumFeatureIdTexture &FeatureIDTexture, int64 VertexIndex)
Gets the feature ID associated with the given vertex.
static PRAGMA_ENABLE_DEPRECATION_WARNINGS ECesiumFeatureIdTextureStatus GetFeatureIDTextureStatus(UPARAM(ref) const FCesiumFeatureIdTexture &FeatureIDTexture)
Gets the status of the feature ID texture.
std::variant< AccessorView< AccessorTypes::VEC2< uint8_t > >, AccessorView< AccessorTypes::VEC2< uint16_t > >, AccessorView< AccessorTypes::VEC2< float > > > TexCoordAccessorType
A blueprint-accessible wrapper for a feature ID texture from a glTF primitive.
constexpr const CesiumGltf::FeatureIdTextureView & getFeatureIdTextureView() const
Gets the underlying view of this feature ID texture.
FCesiumFeatureIdTexture(const CesiumGltf::Model &Model, const CesiumGltf::MeshPrimitive &Primitive, const CesiumGltf::FeatureIdTexture &FeatureIdTexture, const FString &PropertyTableName)
Constructs a feature ID texture instance.
FCesiumFeatureIdTexture()
Constructs an empty feature ID texture instance.