mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-24 20:07:34 -05:00
Merge pull request #2263 from Santarh/basisuRuntimeImport
[WIP] Can import basisu texture at runtime import
This commit is contained in:
commit
4fe77f63cf
|
|
@ -1,6 +1,10 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
#if USE_COM_UNITY_CLOUD_KTX
|
||||
using KtxUnity;
|
||||
#endif
|
||||
|
||||
namespace VRMShaders
|
||||
{
|
||||
|
|
@ -11,12 +15,37 @@ namespace VRMShaders
|
|||
{
|
||||
public async Task<Texture2D> LoadTextureAsync(DeserializingTextureInfo textureInfo, IAwaitCaller awaitCaller)
|
||||
{
|
||||
Texture2D texture = null;
|
||||
switch (textureInfo.DataMimeType)
|
||||
{
|
||||
case "image/png":
|
||||
break;
|
||||
case "image/jpeg":
|
||||
texture = new Texture2D(2, 2, TextureFormat.ARGB32, textureInfo.UseMipmap, textureInfo.ColorSpace == ColorSpace.Linear);
|
||||
if (textureInfo.ImageData != null)
|
||||
{
|
||||
texture.LoadImage(textureInfo.ImageData);
|
||||
await awaitCaller.NextFrame();
|
||||
}
|
||||
break;
|
||||
#if USE_COM_UNITY_CLOUD_KTX
|
||||
case "image/ktx":
|
||||
var ktxTexture = new KtxTexture();
|
||||
var nativeBytes = new NativeArray<byte>(textureInfo.ImageData, Allocator.Temp);
|
||||
try
|
||||
{
|
||||
var nativeSlice = new NativeSlice<byte>(nativeBytes);
|
||||
var result = await ktxTexture.LoadFromBytes(nativeSlice, textureInfo.ColorSpace == ColorSpace.Linear);
|
||||
if (result != null && result.errorCode == ErrorCode.Success)
|
||||
{
|
||||
texture = result.texture;
|
||||
}
|
||||
break;
|
||||
}
|
||||
finally
|
||||
{
|
||||
nativeBytes.Dispose();
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
if (string.IsNullOrEmpty(textureInfo.DataMimeType))
|
||||
{
|
||||
|
|
@ -29,16 +58,12 @@ namespace VRMShaders
|
|||
break;
|
||||
}
|
||||
|
||||
var texture = new Texture2D(2, 2, TextureFormat.ARGB32, textureInfo.UseMipmap, textureInfo.ColorSpace == ColorSpace.Linear);
|
||||
if (textureInfo.ImageData != null)
|
||||
if (texture != null)
|
||||
{
|
||||
texture.LoadImage(textureInfo.ImageData);
|
||||
texture.wrapModeU = textureInfo.WrapModeU;
|
||||
texture.wrapModeV = textureInfo.WrapModeV;
|
||||
texture.filterMode = textureInfo.FilterMode;
|
||||
await awaitCaller.NextFrame();
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
{
|
||||
"name": "VRMShaders.GLTF.IO.Runtime",
|
||||
"references": [],
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:3d354272d3f2f4c3387dbccbaebd0f60"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
|
|
@ -8,6 +11,12 @@
|
|||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.cloud.ktx",
|
||||
"expression": "3.0.0",
|
||||
"define": "USE_COM_UNITY_CLOUD_KTX"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"com.unity.burst": "1.6.6",
|
||||
"com.unity.ide.rider": "3.0.21",
|
||||
"com.unity.cloud.ktx": "3.3.0",
|
||||
"com.unity.cloud.ktx.webgl-2021": "1.0.1",
|
||||
"com.unity.ide.rider": "3.0.24",
|
||||
"com.unity.ide.visualstudio": "2.0.22",
|
||||
"com.unity.ide.vscode": "1.2.5",
|
||||
"com.unity.postprocessing": "3.2.2",
|
||||
"com.unity.render-pipelines.universal": "12.1.12",
|
||||
"com.unity.test-framework": "1.1.33",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,22 @@
|
|||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.cloud.ktx": {
|
||||
"version": "3.3.0",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.modules.unitywebrequest": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.cloud.ktx.webgl-2021": {
|
||||
"version": "1.0.1",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ext.nunit": {
|
||||
"version": "1.0.6",
|
||||
"depth": 1,
|
||||
|
|
@ -17,7 +33,7 @@
|
|||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.rider": {
|
||||
"version": "3.0.21",
|
||||
"version": "3.0.24",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
|
|
@ -34,6 +50,13 @@
|
|||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.vscode": {
|
||||
"version": "1.2.5",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.mathematics": {
|
||||
"version": "1.2.6",
|
||||
"depth": 1,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user