Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cesium-unity compatible with the shared asset changes in cesium-native. #518

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions native~/Runtime/src/TestGltfModelImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ TestGltfModelImpl::AddFeatureIdTexture(

// Copy feature IDs to texture.
CesiumGltf::Image& image = this->_nativeModel.images.emplace_back();
image.cesium.width = 2;
image.cesium.height = 2;
image.cesium.bytesPerChannel = 1;
image.cesium.channels = 2;
image.cesium.pixelData.resize(featureIdsLength * sizeof(std::uint16_t));
image.pCesium.emplace();
image.pCesium->width = 2;
image.pCesium->height = 2;
image.pCesium->bytesPerChannel = 1;
image.pCesium->channels = 2;
image.pCesium->pixelData.resize(featureIdsLength * sizeof(std::uint16_t));

std::uint16_t* pFeatureId =
reinterpret_cast<std::uint16_t*>(image.cesium.pixelData.data());
reinterpret_cast<std::uint16_t*>(image.pCesium->pixelData.data());
for (int32_t i = 0; i < featureIdsLength; i++) {
*pFeatureId = featureIds[i];
pFeatureId++;
Expand Down
10 changes: 5 additions & 5 deletions native~/Runtime/src/TextureLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace CesiumForUnityNative {

namespace {
UnityEngine::TextureFormat
getCompressedPixelFormat(const CesiumGltf::ImageCesium& image) {
getCompressedPixelFormat(const CesiumGltf::ImageAsset& image) {
switch (image.compressedPixelFormat) {
case GpuCompressedPixelFormat::ETC1_RGB:
return UnityEngine::TextureFormat::ETC_RGB4;
Expand Down Expand Up @@ -55,7 +55,7 @@ getCompressedPixelFormat(const CesiumGltf::ImageCesium& image) {
}

UnityEngine::TextureFormat
getUncompressedPixelFormat(const CesiumGltf::ImageCesium& image) {
getUncompressedPixelFormat(const CesiumGltf::ImageAsset& image) {
switch (image.channels) {
case 1:
return UnityEngine::TextureFormat::R8;
Expand All @@ -72,7 +72,7 @@ getUncompressedPixelFormat(const CesiumGltf::ImageCesium& image) {
} // namespace

UnityEngine::Texture
TextureLoader::loadTexture(const CesiumGltf::ImageCesium& image, bool sRGB) {
TextureLoader::loadTexture(const CesiumGltf::ImageAsset& image, bool sRGB) {
CESIUM_TRACE("TextureLoader::loadTexture");
std::int32_t mipCount =
image.mipPositions.empty() ? 1 : std::int32_t(image.mipPositions.size());
Expand Down Expand Up @@ -107,7 +107,7 @@ TextureLoader::loadTexture(const CesiumGltf::ImageCesium& image, bool sRGB) {
std::uint8_t* pWritePosition = pixels;
const std::byte* pReadBuffer = image.pixelData.data();

for (const ImageCesiumMipPosition& mip : image.mipPositions) {
for (const ImageAssetMipPosition& mip : image.mipPositions) {
size_t start = mip.byteOffset;
size_t end = mip.byteOffset + mip.byteSize;
if (start >= textureLength || end > textureLength)
Expand Down Expand Up @@ -144,7 +144,7 @@ UnityEngine::Texture TextureLoader::loadTexture(
return UnityEngine::Texture(nullptr);
}

const ImageCesium& imageCesium = pImage->cesium;
const ImageAsset& imageCesium = *pImage->pCesium;
UnityEngine::Texture unityTexture = loadTexture(imageCesium, sRGB);

const Sampler* pSampler = Model::getSafe(&model.samplers, texture.sampler);
Expand Down
4 changes: 2 additions & 2 deletions native~/Runtime/src/TextureLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace CesiumGltf {
struct Model;
struct Texture;
struct ImageCesium;
struct ImageAsset;
} // namespace CesiumGltf

namespace DotNet::UnityEngine {
Expand All @@ -17,7 +17,7 @@ namespace CesiumForUnityNative {
class TextureLoader {
public:
static ::DotNet::UnityEngine::Texture
loadTexture(const CesiumGltf::ImageCesium& image, bool sRGB);
loadTexture(const CesiumGltf::ImageAsset& image, bool sRGB);

static ::DotNet::UnityEngine::Texture loadTexture(
const CesiumGltf::Model& model,
Expand Down
6 changes: 3 additions & 3 deletions native~/Runtime/src/UnityPrepareRendererResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void generateMipMaps(
case CesiumGltf::Sampler::MinFilter::LINEAR_MIPMAP_NEAREST:
case CesiumGltf::Sampler::MinFilter::NEAREST_MIPMAP_LINEAR:
case CesiumGltf::Sampler::MinFilter::NEAREST_MIPMAP_NEAREST:
CesiumGltfReader::GltfReader::generateMipMaps(pImage->cesium);
CesiumGltfReader::GltfReader::generateMipMaps(*pImage->pCesium);
}
}
}
Expand Down Expand Up @@ -1722,7 +1722,7 @@ void UnityPrepareRendererResources::free(
}

void* UnityPrepareRendererResources::prepareRasterInLoadThread(
CesiumGltf::ImageCesium& image,
CesiumGltf::ImageAsset& image,
const std::any& rendererOptions) {
CesiumGltfReader::GltfReader::generateMipMaps(image);
return nullptr;
Expand All @@ -1732,7 +1732,7 @@ void* UnityPrepareRendererResources::prepareRasterInMainThread(
CesiumRasterOverlays::RasterOverlayTile& rasterTile,
void* pLoadThreadResult) {
auto pTexture = std::make_unique<UnityEngine::Texture>(
TextureLoader::loadTexture(rasterTile.getImage(), true));
TextureLoader::loadTexture(*rasterTile.getImage(), true));
pTexture->wrapMode(UnityEngine::TextureWrapMode::Clamp);
pTexture->filterMode(UnityEngine::FilterMode::Trilinear);
pTexture->anisoLevel(16);
Expand Down
2 changes: 1 addition & 1 deletion native~/Runtime/src/UnityPrepareRendererResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class UnityPrepareRendererResources
void* pMainThreadResult) noexcept override;

virtual void* prepareRasterInLoadThread(
CesiumGltf::ImageCesium& image,
CesiumGltf::ImageAsset& image,
const std::any& rendererOptions) override;

virtual void* prepareRasterInMainThread(
Expand Down
2 changes: 1 addition & 1 deletion native~/extern/cesium-native
Submodule cesium-native updated 164 files