ralpha-assets/Plugins/CesiumForUnreal/Source/CesiumRuntime/Private/EncodedMetadataConversions.h

88 lines
3.1 KiB
C++

// Copyright 2020-2024 CesiumGS, Inc. and Contributors
#pragma once
#include "CesiumCommon.h"
#include "HAL/Platform.h"
#include <span>
struct FCesiumPropertyTablePropertyDescription;
struct FCesiumPropertyTableProperty;
/**
* Any custom encoding behavior, e.g., special encoding of unsupported
* properties, can go here. Use the below methods as examples.
*/
/**
* @brief Coerces property values to the type specified by the property
* description. The following property types are supported:
* - scalars
* - vecNs
* - booleans
* - scalar and boolean arrays (up to the first four elements)
*
* Additionally, if the property contains strings or string arrays, it will
* attempt to parse numbers from each string, then coerce those numbers to the
* desired format.
*/
struct CesiumEncodedMetadataCoerce {
/**
* Whether it is possible to apply the encoding method based on the property
* description.
*
* @param description The property table property description.
*/
static bool
canEncode(const FCesiumPropertyTablePropertyDescription& description);
/**
* Encodes the data of the property table property into the given texture data
* pointer, as the type specified in the property description.
*
* @param propertyDescription The property table property description.
* @param property The property table property itself.
* @param pTextureData A pointer to the texture data, which will be filled
* during encoding.
* @param pixelSize The size of a pixel from the given texture, in bytes.
*/
static void encode(
const FCesiumPropertyTablePropertyDescription& propertyDescription,
const FCesiumPropertyTableProperty& property,
const std::span<std::byte>& pTextureData,
size_t pixelSize);
};
/**
* @brief Attempts to parse colors from string property values and encode them
* for access in Unreal materials. This supports the following formats:
* - rgb(R,G,B), where R, G, and B are values in the range [0, 255]
* - hexcode colors, e.g. #AF012B and #fff
*/
struct CesiumEncodedMetadataParseColorFromString {
/**
* Whether it is possible to apply the encoding method based on the property
* description.
*
* @param description The property table property description.
*/
static bool
canEncode(const FCesiumPropertyTablePropertyDescription& description);
/**
* Encodes the data of the property table property into the given texture data
* pointer, as the type specified in the property description.
*
* @param propertyDescription The property table property description.
* @param property The property table property itself.
* @param pTextureData A pointer to the texture data, which will be filled
* during encoding.
* @param pixelSize The size of a pixel from the given texture, in bytes.
*/
static void encode(
const FCesiumPropertyTablePropertyDescription& propertyDescription,
const FCesiumPropertyTableProperty& property,
const std::span<std::byte>& textureData,
size_t pixelSize);
};