From 5a27d76313dbdbc98503a8ede446495e1daf81e4 Mon Sep 17 00:00:00 2001 From: Matias Lavik Date: Tue, 13 Dec 2022 12:25:54 +0100 Subject: [PATCH 1/4] Unity 2022.0 --- .github/workflows/package.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 427eb86..f6147b6 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -76,3 +76,37 @@ jobs: with: name: UnityAsyncTextureImport-Unity-2021.unitypackage path: UnityAsyncTextureImport.unitypackage + package-unity-2022-3: + needs: build-freeimage-android + runs-on: ubuntu-latest + container: + image: unityci/editor:ubuntu-2022.2.0f1-base-1.0.1 + steps: + - uses: actions/checkout@v1 + with: + submodules: true + - uses: actions/download-artifact@master + with: + name: arm64-v8a + path: binaries/arm64-v8a + - uses: actions/download-artifact@master + with: + name: armeabi-v7a + path: binaries/armeabi-v7a + - uses: actions/download-artifact@master + with: + name: ubuntu-16.04 + path: binaries/linux + - name: Package + run: | + chmod a+x scripts/ci/activate-license.sh + ./scripts/ci/activate-license.sh + echo "Packaging..." + python scripts/export-unity-package.py /opt/unity/Editor/Unity -nodisplay + shell: bash + env: + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE_BASE64 }} + - uses: actions/upload-artifact@v3 + with: + name: UnityAsyncTextureImport-Unity-2022.unitypackage + path: UnityAsyncTextureImport.unitypackage From e560312a5762202a20b9b4b52376b81cbee16a3e Mon Sep 17 00:00:00 2001 From: Matias Lavik Date: Tue, 13 Dec 2022 12:54:59 +0100 Subject: [PATCH 2/4] Update package.yml --- .github/workflows/package.yml | 42 +++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index f6147b6..f86480b 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -3,7 +3,7 @@ name: Package on: [push, pull_request] jobs: - build-freeimage-android: + build-freeimage-android-unity-2021: runs-on: ubuntu-latest container: image: unityci/editor:ubuntu-2021.3.14f1-android-1.0.1 @@ -21,11 +21,35 @@ jobs: shell: bash - uses: actions/upload-artifact@v3 with: - name: "arm64-v8a" + name: "arm64-v8a-unity-2021" path: build-arm64-v8a/libFreeImage.so - uses: actions/upload-artifact@v3 with: - name: "armeabi-v7a" + name: "armeabi-v7a-unity-2021" + path: build-armeabi-v7a/libFreeImage.so + build-freeimage-android-unity-2022: + runs-on: ubuntu-latest + container: + image: unityci/editor:ubuntu-2022.2.0f1-base-1.0.1 + steps: + - uses: actions/checkout@v1 + with: + submodules: true + - name: Build FreeImage + run: | + apt update -y + apt install cmake -y + apt install build-essential -y + chmod a+x scripts/build-android.py + python scripts/build-android.py /opt/unity/Editor + shell: bash + - uses: actions/upload-artifact@v3 + with: + name: "arm64-v8a-unity-2022" + path: build-arm64-v8a/libFreeImage.so + - uses: actions/upload-artifact@v3 + with: + name: "armeabi-v7a-unity-2022" path: build-armeabi-v7a/libFreeImage.so build-freeimage-ubuntu: runs-on: ubuntu-18.04 @@ -43,7 +67,7 @@ jobs: name: "ubuntu-16.04" path: build/libFreeImage.so package-unity-2021-3: - needs: build-freeimage-android + needs: build-freeimage-android-unity-2021 runs-on: ubuntu-latest container: image: unityci/editor:ubuntu-2021.3.9f1-base-1.0.1 @@ -53,11 +77,11 @@ jobs: submodules: true - uses: actions/download-artifact@master with: - name: arm64-v8a + name: arm64-v8a-unity-2021 path: binaries/arm64-v8a - uses: actions/download-artifact@master with: - name: armeabi-v7a + name: armeabi-v7a-unity-2021 path: binaries/armeabi-v7a - uses: actions/download-artifact@master with: @@ -77,7 +101,7 @@ jobs: name: UnityAsyncTextureImport-Unity-2021.unitypackage path: UnityAsyncTextureImport.unitypackage package-unity-2022-3: - needs: build-freeimage-android + needs: build-freeimage-android-unity-2022 runs-on: ubuntu-latest container: image: unityci/editor:ubuntu-2022.2.0f1-base-1.0.1 @@ -87,11 +111,11 @@ jobs: submodules: true - uses: actions/download-artifact@master with: - name: arm64-v8a + name: arm64-v8a-unity-2022 path: binaries/arm64-v8a - uses: actions/download-artifact@master with: - name: armeabi-v7a + name: armeabi-v7a-unity-2022 path: binaries/armeabi-v7a - uses: actions/download-artifact@master with: From 1519192d2a0af294e80efbddd46626891d25385d Mon Sep 17 00:00:00 2001 From: Matias Lavik Date: Tue, 13 Dec 2022 13:02:31 +0100 Subject: [PATCH 3/4] Update package.yml --- .github/workflows/package.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index f86480b..64e840a 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -30,7 +30,7 @@ jobs: build-freeimage-android-unity-2022: runs-on: ubuntu-latest container: - image: unityci/editor:ubuntu-2022.2.0f1-base-1.0.1 + image: unityci/editor:ubuntu-2022.2.0f1-android-1.0.1 steps: - uses: actions/checkout@v1 with: @@ -98,9 +98,9 @@ jobs: UNITY_LICENSE: ${{ secrets.UNITY_LICENSE_BASE64 }} - uses: actions/upload-artifact@v3 with: - name: UnityAsyncTextureImport-Unity-2021.unitypackage + name: UnityAsyncTextureImport-Unity-2021.3.unitypackage path: UnityAsyncTextureImport.unitypackage - package-unity-2022-3: + package-unity-2022-2: needs: build-freeimage-android-unity-2022 runs-on: ubuntu-latest container: @@ -132,5 +132,5 @@ jobs: UNITY_LICENSE: ${{ secrets.UNITY_LICENSE_BASE64 }} - uses: actions/upload-artifact@v3 with: - name: UnityAsyncTextureImport-Unity-2022.unitypackage + name: UnityAsyncTextureImport-Unity-2022.2.unitypackage path: UnityAsyncTextureImport.unitypackage From 062d56e4fd07f17eee3658996a369a518307efac Mon Sep 17 00:00:00 2001 From: Matias Lavik Date: Wed, 14 Dec 2022 23:39:36 +0100 Subject: [PATCH 4/4] Create README.md --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..7efdfe1 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Unity Async Texture Importer (automatic builds) + +This repository is simply a set of build scripts and actions for building and packaging unity-async-textureimport for Unity. +See main repo here: https://codeberg.org/matiaslavik/unity-async-textureimport + +This is a faster alternative to [Texture2D.LoadImage](https://docs.unity3d.com/530/Documentation/ScriptReference/Texture2D.LoadImage.html) and , which can only be used on the main thread - and which will block the thread until it's done. + +# How to use +Create a [coroutine](https://docs.unity3d.com/Manual/Coroutines.html), and from there do this: +```csharp +TextureImporter importer = new TextureImporter(); +yield return importer.ImportTexture(texPath, FREE_IMAGE_FORMAT.FIF_JPEG); +Texture2D tex = importer.texture; +``` +See the sample scene for an example. + +# What it does +The TextureImporter class has a public IEnumerator ("ImportTexture") that you can call/yield from a coroutine. It runs a task in a separate thread that loads the texture file, converts it to raw data and generates mipmaps. When the task is done, the IEnumerator will finally upload the raw data by calling [Texture2D.LoadRawTextureData](https://docs.unity3d.com/ScriptReference/Texture2D.LoadRawTextureData.html). +Since the file reading, decompressing and mipmap generation is done in a separate thread, you will be able to load large textures without causing FPS lags/hiccups. +I used [FreeImage](https://freeimage.sourceforge.io/) for the texture loading/conversion. + +# License + MIT License + (See the "LICENSE" file) + + Note: This project uses the FreeImage library. To use this project, you should include a copy of the FreeImage license (GPL or FIPL). See more info here: https://freeimage.sourceforge.io/license.html