Skip to content

Commit

Permalink
Merge branch 'main' of github.com:CesiumGS/cesium-unity into update-n…
Browse files Browse the repository at this point in the history
…ative
  • Loading branch information
azrogers committed Oct 31, 2024
2 parents 784a967 + a023792 commit 1c5eee4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## v1.?.? - 2024-11-01

##### Fixes :wrench:

- Added restrictions to `CesiumRuntime.asmdef` to prevent the plugin from attempting to load on platforms not supported by Cesium Native.

## v1.13.0 - 2024-10-01

##### Additions :tada:
Expand Down
10 changes: 9 additions & 1 deletion Runtime/CesiumRuntime.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
"Unity.Mathematics",
"Unity.Splines"
],
"includePlatforms": [],
"includePlatforms": [
"Android",
"Editor",
"iOS",
"macOSStandalone",
"WSA",
"WindowsStandalone32",
"WindowsStandalone64"
],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": false,
Expand Down
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

0 comments on commit 1c5eee4

Please sign in to comment.