Unity Cesium source code compilation


foreword

The bottom layer of Cesium is Cesium Native (C++). Officially produced packages such as unity and unreal for different platforms, but if you want to change or add some functions, you need to modify the bottom layer, which involves source code compilation. Only after the source code is modified and recompiled, and the platform is introduced can the desired functions be realized. Many people expand unreal because it is the official language of C++, and the development of unity is relatively slow. The following will introduce how to make custom modifications according to the official documents .

1. Preconditions

  1. Install Cmake v3.15 or later
  2. NET SDK V6.0 or above
  3. Install VS2022
  4. On Windows, support for long file paths must be enabled
  5. install nasm
  6. You need to visit GitHub. Here I will download the key packages. As for the compiled ones, you need to do it manually. After all, the versions of net and cmake may not be universal for the project (subject to your own project environment).
    insert image description here
    Basic command line:
    enter the D drive: cd /dd:
    clear the current content: cls

2. Download project and source code

1. Unity project

git clone --recurse-submodules https://github.com/CesiumGS/cesium-unity-samples.git

insert image description here
2. Package
Enter Packages to download. Generally speaking, there will be three extension files that fail to download.

git clone --recurse-submodules https://github.com/CesiumGS/cesium-unity.git
 com.cesium.unity

insert image description here
3. Manually download failed resources
Download the three folders under the extended resources and put them into cesium-unity-samples\Packages\com.cesium.unity\native~\extern
insert image description here

It is easy to make mistakes when downloading in China, and it is too troublesome to download manually. I will organize resources and upload them to the network disk. If you need them, you can ask me for them. But my version is definitely not the latest version, so it is best to do it yourself if you can do it yourself.

3. Source code compilation

1. The intermediate plug-in (c#-c++)
enters com.cesium.com and enters the following command to install the plug-in. There will be 3 resource download failures under extern. If there are many missed reports, it may be a network problem.

dotnet publish Reinterop~ -o .

insert image description here

2. Unity compilation
Use 2021.3.10 or above to open and compile. I am using 2021.3.16f1 here
3. Cmake
generates vs solutions (that is, projects with sln)

cmake -B build -S . -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Debug

insert image description here
Success
insert image description here
4. Modify the source code
and enter the directory D:/cesium-project/cesium-unity-samples/Packages/com.cesium.unity/native~/build Open the sln file with vs2022
insert image description here
5. Compile the solution
and select the overall project generation solution (shortcut Press ctrl+shift+b)
insert image description here
to enter the directory D:/cesium-project/cesium-unity-samples/Packages/com.cesium.unity/Editor, put the two dlls in the above picture, and finally open unity to check whether the scene is correct.

4. Simplify the process

Compile in three steps

cd D:/cesium-project/cesium-unity-samples/Packages/com.cesium.unity/native~
cmake -B build -S . -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build -j14 --target install --config RelWithDebInfo

If the sln file has been generated, then you only need to execute the following code for quick compilation, and the dll file will be directly generated and overwritten to the cesium-unity-samples\Packages\com.cesium.unity\Editor folder.

cd D:/cesium-project/cesium-unity-samples/Packages/com.cesium.unity/native~
cmake --build build -j14 --target install --config RelWithDebInfo

Summarize

This article implements the source code compilation process of Unity Cesium. Careful developers may find that there are official documents and steps for encapsulating Cesium, so I won’t do a demonstration below this post.
insert image description here

Guess you like

Origin blog.csdn.net/qq_41912124/article/details/132319402