CesiumGS / cesium-unity

Bringing the 3D geospatial ecosystem to Unity
https://cesium.com/platform/cesium-for-unity/
Apache License 2.0
348 stars 83 forks source link

cesium unity plugin on arch linux #513

Open 2tata opened 2 days ago

2tata commented 2 days ago

Hi, first of all thanks for this amasing software!

I got an issue installing cesium in unity on linux.

to my system: 6.10.10-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 12 Sep 2024 17:21:02 +0000 x86_64 GNU/Linux

unityhub version 3.9.1 --> https://aur.archlinux.org/packages/unityhub

I installed the 2022.3.48f1 editor version

### first attempt

I created a new project (3D core).

under "services" -> "gerneral settings" -> "Package Manager" I added following:

Cesium
https://unity.pkg.cesium.com
com.cesium.unity

then I installed the cesium plugin in version 1.13.0

The consol log give me some errors:

Library/PackageCache/com.cesium.unity@1.13.0/Runtime/Cesium3DTile.cs(2,7): error CS0246: The type or namespace name 'Reinterop' could not be found (are you missing a using directive or an assembly reference?)

seems that Reinterop for dotnet is not coming with that repo plugin.

### second attempt

I followd the instructions here: https://github.com/CesiumGS/cesium-unity/blob/main/Documentation~/developer-setup.md

installed: extra/dotnet-sdk 8.0.8.sdk108-1 (85.3 MiB 300.0 MiB) (Installed) extra/nasm 2.16.03-1 (341.2 KiB 2.4 MiB) (Installed)

dotnet --version 8.0.108 cmake version 3.30.4

cloned cesium-unity-samples

then cesium-unity inside it.

in cesium-unity-samples/Packages/com.cesium.unity i called:

[<user> com.cesium.unity]$ dotnet publish Reinterop~ -o .
MSBuild version 17.8.5+b5265ef37 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  Reinterop -> /home/<user>/cesium-unity-samples/Packages/com.cesium.unity/Reinterop~/bin/Debug/netstandard2.0/Reinterop.dll
  Reinterop -> /home/<user>/cesium-unity-samples/Packages/com.cesium.unity/

got the message:

DllNotFoundException: CesiumForUnityNative assembly:<unknown assembly> type:<unknown type> member:(null)
NotImplementedException: The native implementation is missing so OnValidate cannot be invoked.

did:

cd cesium-unity-samples/Packages/com.cesium.unity/native~
cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug

run into following error:

[<user> native~]$ cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
CMake Deprecation Warning at extern/tidy-html5/CMakeLists.txt:20 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

CMake Warning (dev) at extern/tidy-html5/CMakeLists.txt:26 (project):
  Policy CMP0048 is not set: project() command manages VERSION variables.
  Run "cmake --help-policy CMP0048" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The following variable(s) would be set to empty:

    PROJECT_VERSION
    PROJECT_VERSION_MAJOR
    PROJECT_VERSION_MINOR
    PROJECT_VERSION_PATCH
This warning is for project developers.  Use -Wno-dev to suppress it.

-> TIDY_SO_VERSION = 58. This is an EVEN (stable) release.
-- *** Debug Logging is NOT enabled.
-- *** Building support for runtime configuration files.
-- *** Only building static library STATIC, version 5.8.0, date 2021.07.10
-- VCPKG_TRIPLET x64-linux-unity
-- EZVCPKG v0.1 starting up
    Website: https://github.com/jherico/ezvcpkg
-- EZVCPKG_BASEDIR envrionment variable not found and basedir not set, using default /home/<user>/.ezvcpkg
-- EZVCPKG initializing
    commit:     2024.07.12
    repository: https://github.com/microsoft/vcpkg.git
    local dir:  /home/<user>/.ezvcpkg/2024.07.12
-- EZVCPKG Building/Verifying package asyncplusplus using triplet x64-linux-unity
CMake Error at extern/cesium-native/cmake/ezvcpkg/ezvcpkg.cmake:83 (message):
  EZVCPKG failed with error 1
Call Stack (most recent call first):
  extern/cesium-native/cmake/ezvcpkg/ezvcpkg.cmake:185 (EZVCPKG_CHECK_RESULTS)
  extern/cesium-native/cmake/ezvcpkg/ezvcpkg.cmake:279 (EZVCPKG_BUILD)
  extern/cesium-native/cmake/ezvcpkg/ezvcpkg.cmake:293 (EZVCPKG_FETCH_IMPL)
  extern/cesium-native/CMakeLists.txt:50 (ezvcpkg_fetch)

*** The output from the command was:
error: Invalid triplet: x64-linux-unity
Built-in Triplets:
  x64-osx
  arm-neon-android
  x64-uwp
  x64-windows
  arm64-android
  x86-windows
  arm64-osx
  x64-linux
  arm64-uwp
  x64-android
  arm64-windows
  x64-windows-static
Community Triplets:
  arm64-osx-dynamic
  mips64-linux
  x64-windows-static-release
  x64-xbox-xboxone
  x86-android
  arm64-ios
  x64-openbsd
  x64-windows-static-md
  ppc64le-linux
  arm64-linux-release
  arm-linux-release
  arm64-linux
  x86-mingw-static
  x64-mingw-static
  s390x-linux
  x64-windows-static-md-release
  x86-ios
  x64-osx-dynamic
  x64-linux-release
  x86-windows-static-md
  x86-windows-static
  loongarch32-linux-release
  arm64-ios-release
  s390x-linux-release
  arm64-ios-simulator
  arm-windows
  arm64-osx-release
  arm-mingw-static
  arm-windows-static
  riscv32-linux
  x86-windows-v120
  loongarch64-linux
  arm-mingw-dynamic
  loongarch64-linux-release
  arm-linux
  riscv64-linux-release
  arm64-mingw-dynamic
  x64-xbox-xboxone-static
  arm-android
  x64-linux-dynamic
  x64-uwp-static-md
  arm64ec-windows
  wasm32-emscripten
  x64-osx-release
  x64-ios
  ppc64le-linux-release
  x64-xbox-scarlett-static
  x64-freebsd
  armv6-android
  arm64-mingw-static
  arm-uwp-static-md
  arm-ios
  arm64-uwp-static-md
  x64-windows-release
  x86-uwp
  x64-xbox-scarlett
  arm64-windows-static
  arm64-ios-simulator-release
  x86-uwp-static-md
  x86-mingw-dynamic
  arm64-windows-static-md
  riscv32-linux-release
  riscv64-linux
  x86-freebsd
  arm64-windows-static-release
  loongarch32-linux
  arm-uwp
  x86-linux
  x64-mingw-dynamic
Overlay Triplets from "/home/<user>/cesium-unity-samples/Packages/com.cesium.unity/native~/vcpkg/triplets":
  x64-android-unity
  x64-windows-unity
  arm64-osx-unity
  arm64-ios-unity
  arm64-android-unity
  x64-osx-unity
  x64-uwp-unity
  arm64-uwp-unity
See https://learn.microsoft.com/vcpkg/users/triplets?WT.mc_id=vcpkg_inproduct_cli for more information.

CMake Error at extern/cesium-native/cmake/ezvcpkg/ezvcpkg.cmake:102 (message):
Call Stack (most recent call first):
  extern/cesium-native/cmake/ezvcpkg/ezvcpkg.cmake:185 (EZVCPKG_CHECK_RESULTS)
  extern/cesium-native/cmake/ezvcpkg/ezvcpkg.cmake:279 (EZVCPKG_BUILD)
  extern/cesium-native/cmake/ezvcpkg/ezvcpkg.cmake:293 (EZVCPKG_FETCH_IMPL)
  extern/cesium-native/CMakeLists.txt:50 (ezvcpkg_fetch)

-- Configuring incomplete, errors occurred!

(this is maybe interresint for you guys)

work around it with following:

cd /home/<user>/.ezvcpkg/2024.07.12
cp triplets/x64-linux.cmake triplets/x64-linux-unity.cmake

run the first cmake call again:

[<user> native~]$ cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
CMake Deprecation Warning at extern/tidy-html5/CMakeLists.txt:20 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

CMake Warning (dev) at extern/tidy-html5/CMakeLists.txt:26 (project):
  Policy CMP0048 is not set: project() command manages VERSION variables.
  Run "cmake --help-policy CMP0048" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The following variable(s) would be set to empty:

    PROJECT_VERSION
    PROJECT_VERSION_MAJOR
    PROJECT_VERSION_MINOR
    PROJECT_VERSION_PATCH
This warning is for project developers.  Use -Wno-dev to suppress it.

-> TIDY_SO_VERSION = 58. This is an EVEN (stable) release.
-- *** Debug Logging is NOT enabled.
-- *** Building support for runtime configuration files.
-- *** Only building static library STATIC, version 5.8.0, date 2021.07.10
-- VCPKG_TRIPLET x64-linux-unity
-- EZVCPKG v0.1 starting up
    Website: https://github.com/jherico/ezvcpkg
-- EZVCPKG_BASEDIR envrionment variable not found and basedir not set, using default /home/<user>/.ezvcpkg
-- EZVCPKG initializing
    commit:     2024.07.12
    repository: https://github.com/microsoft/vcpkg.git
    local dir:  /home/<user>/.ezvcpkg/2024.07.12
-- EZVCPKG Building/Verifying package asyncplusplus using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package expected-lite using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package fmt using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package glm using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package ms-gsl using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package rapidjson using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package spdlog using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package stb using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package uriparser using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package abseil using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package draco using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package ktx using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package modp-base64 using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package meshoptimizer using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package openssl using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package s2geometry using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package libjpeg-turbo using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package sqlite3 using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package tinyxml2 using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package libwebp using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package zlib-ng using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package picosha2 using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package earcut-hpp using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package cpp-httplib[core] using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package libmorton using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package zstd using triplet x64-linux-unity
-- EZVCPKG Building/Verifying package catch2 using triplet x64-linux-unity
-- EZVCPKG done
-- CMAKE_TOOLCHAIN_FILE /home/<user>/.ezvcpkg/2024.07.12/scripts/buildsystems/vcpkg.cmake
-- PACKAGE_BASE_DIR /home/<user>/.ezvcpkg/2024.07.12/packages
-- PACKAGE_BUILD_DIR /home/<user>/.ezvcpkg/2024.07.12/installed/x64-linux-unity
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
-- Configuring done (7.4s)
-- Generating done (0.4s)
-- Build files have been written to: /home/<user>/cesium-unity-samples/Packages/com.cesium.unity/native~/build

then the second one:

[<user> native~]$ cmake --build build -j14 --target install --config Debug
[  5%] Built target tidy-static
[  7%] Built target CesiumUtility
[  8%] Built target CesiumJsonWriter
[  8%] Built target Cesium3DTiles
[ 11%] Built target CesiumGeometry
[ 14%] Built target CesiumJsonReader
[ 16%] Built target CesiumAsync
[ 20%] Built target CesiumGltf
[ 21%] Built target Cesium3DTilesReader
[ 22%] Built target Cesium3DTilesWriter
[ 22%] Built target CesiumIonClient
[ 25%] Built target CesiumGeospatial
[ 27%] Built target CesiumGltfWriter
[ 29%] Built target CesiumGltfReader
[ 29%] Built target CesiumGltfContent
[ 45%] Built target CesiumForUnityNative-Editor
[ 47%] Built target CesiumQuantizedMeshTerrain
[ 49%] Built target Cesium3DTilesContent
[ 52%] Built target CesiumRasterOverlays
[ 57%] Built target Cesium3DTilesSelection
[100%] Built target CesiumForUnityNative-Runtime
Install the project...
-- Install configuration: "Debug"
-- Up-to-date: /home/<user>/cesium-unity-samples/Packages/com.cesium.unity/native~/../Editor/./libCesiumForUnityNative-Runtime.so
-- Up-to-date: /home/<user>/cesium-unity-samples/Packages/com.cesium.unity/native~/../Editor/./libCesiumForUnityNative-Editor.so

now in unity i added the cesium-unity-samples project but with 2022.3.48f1 editor version (the 2021 one seems not work on arch anymore). logedin into cesium ion. Then added a Blank 3D Tiles Tileset on the gameobject Cesium3DTileset I switch to url and use my maps api url https://tile.googleapis.com/v1/3dtiles/root.json?key=<my key>

then I get following error:

[2024-10-01 23:49:28.695] [error] [TilesetJsonLoader.cpp:697] Error when parsing tileset JSON, error code Invalid value. at byte offset 0

UnityEngine.Debug:Log (object)
Reinterop.ReinteropInitializer:UnityEngine_Debug_CallLog_FA05wu8x__otZNsgdHTnU9A (intptr) (at ./Reinterop/Reinterop.RoslynSourceGenerator/ReinteropInitializer.cs:13570)
Reinterop.ReinteropInitializer/ActionNativeFunction:Invoke () (at ./Reinterop/Reinterop.RoslynSourceGenerator/ReinteropInitializer.cs:10186)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()

in /home/<user>/cesium-unity-samples/Packages/com.cesium.unity/native~/extern/cesium-native/Cesium3DTilesSelection/src/TilesetJsonLoader.cpp in line 697

...
  rapidjson::Document tilesetJson;
  tilesetJson.Parse(
      reinterpret_cast<const char*>(responseData.data()),
      responseData.size());
  if (tilesetJson.HasParseError()) {
    SPDLOG_LOGGER_ERROR(
        pLogger,
        "Error when parsing tileset JSON, error code {} at byte offset {}",
        tilesetJson.GetParseError(),
        tilesetJson.GetErrorOffset());
    return TileLoadResult::createFailedResult(std::move(pCompletedRequest));
  }

  // Save the parsed external tileset into custom data.
  // We will propagate it back to tile later in the main
  // thread
  TilesetContentLoaderResult<TilesetJsonLoader> externalTilesetLoader =
      parseTilesetJson(
          pLogger,
          tileUrl,
          tilesetJson,
          tileTransform,
...

i change the error message parameter to tileUrl wich gave me the uri provided by the maps google api

https://tile.googleapis.com/v1/3dtiles/datasets/CgA/files/UlRPVEYubm9kZWRhdGEucGxhbmV0b2lkPWVhc<some removal>PTYsaW1hZ2VyeV9lcG9jaD0xMDA5LGFsaWdubWVudF92ZXJzaW9uPVJPQ0tUUkVFXzk4OF9HT09HTEVfREFUVU1fMjAyNDA3MDRUMDc1M1pfZ2VuZXJhdGVkX2F0XzIwMjQwOTE3VDEyMDha.glb

this is a valid glb compressed Json file wich I checked with https://github.khronos.org/glTF-Validator/

the google maps API sayes somethng from:

  "extensionsUsed": [
    "3DTILES_content_gltf"
  ],
  "extensionsRequired": [
    "3DTILES_content_gltf"
  ]
}

which I didnt investigated further.

It seems that the cesium plugin have an Issue decompressin glb files.

Does you have any idea how i can fix it?

kring commented 2 days ago

@2tata GLB files are key to what Cesium for Unity does, so it's definitely able to decode them on other platforms. Now that you have the plugin building on Linux (nice job working that out!) I suggest you try opening the Cesium for Unity Samples project and see if it works for you. That will be more reliable a test than creating your own project, particularly one with your own Google key. Google keys sometimes just take awhile to become active, which trips people up.

It's also possible you're running into the same problem that this person did: https://github.com/CesiumGS/cesium-unity/issues/475#issuecomment-2203974137

I can't entirely explain why that would happen, but explicitly calling registerAllTileContentTypes could help.

2tata commented 2 days ago

@2tata GLB files are key to what Cesium for Unity does, so it's definitely able to decode them on other platforms. Now that you have the plugin building on Linux (nice job working that out!) I suggest you try opening the Cesium for Unity Samples project and see if it works for you. That will be more reliable a test than creating your own project, particularly one with your own Google key. Google keys sometimes just take awhile to become active, which trips people up.

on my second attempt I alreay use the Cesium for Unity Samples. I also tried it with the Google Photorealistic 3D Tiles which use the cesium Ion Tileset by the ID 2275207. Resulting in the same Error message. I think in the file TilesetJsonLoader.cpp the rapidjson/document.h which seems to handle the glb decompression does not properly handle the glb file maybe due to missing deb or extension?

Last Night I also tried it on an older Mac book which works out of the box.

It's also possible you're running into the same problem that this person did: #475 (comment)

I can't entirely explain why that would happen, but explicitly calling registerAllTileContentTypes could help.

Where do I need to call that in the Cesium for Unity Samples ?

2tata commented 1 day ago

I modified the TilesetJsonLoader.cpp further and check the fist bytes of the incoming data.

....
if (responseData.size() > 4 && std::string(reinterpret_cast<const char*>(responseData.data()), 4) == "glTF") {
    // Handle glTF binary data
    SPDLOG_LOGGER_ERROR(pLogger, "Received glTF binary file, not a JSON tileset.");
    // Handle .glb file logic here, e.g., load the 3D model
  } else {
    // Try parsing as JSON
    tilesetJson.Parse(
      reinterpret_cast<const char*>(responseData.data()),
      responseData.size());
    if (tilesetJson.HasParseError()) {
      SPDLOG_LOGGER_ERROR(
        pLogger,
        "Error when parsing tileset JSON, error code {} at byte offset {}",
        tilesetJson.GetParseError(),
        tilesetJson.GetErrorOffset());
      return TileLoadResult::createFailedResult(std::move(pCompletedRequest));
    }
  }
...

The error message is Received glTF binary file, not a JSON tileset. and the tilesetJson.Parse(...) method is not able to parse gltf file.

kring commented 1 day ago

Yep, the problem is definitely that registerAllTileContentTypes either isn't being called, or isn't effective. As a result, cesium-native doesn't know how to load a GLB, so it falls back to trying to load everything as JSON (which of course doesn't work for a GLB). The function is supposed to be called here: https://github.com/CesiumGS/cesium-unity/blob/v1.13.0/native~/Runtime/src/PluginMain.cpp#L16

That start function, in turn, is supposed to be called at the bottom of the initializeReinterop function in the generated initializeReinterop.cpp.

But that apparently isn't working for some reason. You'll have to investigate to figure why that call isn't happening (or isn't happening in time). The joys of trying to support a new platform, eh?