remove out string textureName

This commit is contained in:
ousttrue
2021-02-25 16:39:29 +09:00
parent 3f64a93457
commit 6d690d0892
6 changed files with 24 additions and 48 deletions

View File

@@ -325,7 +325,8 @@ namespace UniGLTF
var bufferCount = vertexAccessor.count * vertexAccessor.TypeCount;
float[] result = null;
if(vertexAccessor.bufferView != -1){
if (vertexAccessor.bufferView != -1)
{
var attrib = new float[vertexAccessor.count * vertexAccessor.TypeCount];
var view = self.bufferViews[vertexAccessor.bufferView];
var segment = self.buffers[view.buffer].GetBytes();
@@ -333,8 +334,9 @@ namespace UniGLTF
bytes.MarshalCopyTo(attrib);
result = attrib;
}
else{
result = new float[bufferCount];
else
{
result = new float[bufferCount];
}
var sparse = vertexAccessor.sparse;
@@ -354,28 +356,15 @@ namespace UniGLTF
return result;
}
public static ArraySegment<Byte> GetImageBytes(this glTF self, IStorage storage, int imageIndex, out string textureName)
public static ArraySegment<Byte> GetImageBytes(this glTF self, IStorage storage, int imageIndex)
{
var image = self.images[imageIndex];
if (string.IsNullOrEmpty(image.uri))
{
//
// use buffer view (GLB)
//
//m_imageBytes = ToArray(byteSegment);
textureName = !string.IsNullOrEmpty(image.name) ? image.name : string.Format("{0:00}#GLB", imageIndex);
return self.GetViewBytes(image.bufferView);
}
else
{
if (image.uri.FastStartsWith("data:"))
{
textureName = !string.IsNullOrEmpty(image.name) ? image.name : string.Format("{0:00}#Base64Embedded", imageIndex);
}
else
{
textureName = !string.IsNullOrEmpty(image.name) ? image.name : Path.GetFileNameWithoutExtension(image.uri);
}
return storage.Get(image.uri);
}
}
@@ -441,7 +430,7 @@ namespace UniGLTF
// remove unused extenions
var json = f.ToString().ParseAsJson().ToString(" ");
self.RemoveUnusedExtensions(json);
return Glb.Create(json, self.buffers[0].GetBytes()).ToBytes();
}

View File

@@ -67,16 +67,6 @@ namespace UniGLTF
[JsonSchema(MinItems = 1, ExplicitIgnorableItemLength = 0)]
public List<glTFImage> images = new List<glTFImage>();
public int GetImageIndexFromTextureIndex(int textureIndex)
{
return textures[textureIndex].source;
}
public glTFImage GetImageFromTextureIndex(int textureIndex)
{
return images[GetImageIndexFromTextureIndex(textureIndex)];
}
public glTFTextureSampler GetSamplerFromTextureIndex(int textureIndex)
{
var samplerIndex = textures[textureIndex].sampler;

View File

@@ -391,30 +391,29 @@ namespace UniGLTF
// https://answers.unity.com/questions/647615/how-to-update-import-settings-for-newly-created-as.html
//
int created = 0;
//for (int i = 0; i < GLTF.textures.Count; ++i)
for (int i = 0; i < GLTF.images.Count; ++i)
for (int i = 0; i < GLTF.textures.Count; ++i)
{
folder.EnsureFolder();
//var x = GLTF.textures[i];
var image = GLTF.images[i];
var src = Storage.GetPath(image.uri);
var gltfTexture = GLTF.textures[i];
var gltfImage = GLTF.images[gltfTexture.source];
var src = Storage.GetPath(gltfImage.uri);
if (UnityPath.FromFullpath(src).IsUnderAssetsFolder)
{
// asset is exists.
}
else
{
string textureName;
var byteSegment = GLTF.GetImageBytes(Storage, i, out textureName);
var byteSegment = GLTF.GetImageBytes(Storage, gltfTexture.source);
var textureName = gltfTexture.name;
// path
var dst = folder.Child(textureName + image.GetExt());
var dst = folder.Child(textureName + gltfImage.GetExt());
File.WriteAllBytes(dst.FullPath, byteSegment.ToArray());
dst.ImportAsset();
// make relative path from PrefabParentDir
image.uri = dst.Value.Substring(prefabParentDir.Value.Length + 1);
gltfImage.uri = dst.Value.Substring(prefabParentDir.Value.Length + 1);
++created;
}
}

View File

@@ -24,23 +24,23 @@ namespace UniGLTF
}
}
public static async Awaitable<Texture2D> LoadTextureAsync(glTF gltf, IStorage storage, int index)
public static async Awaitable<Texture2D> LoadTextureAsync(glTF gltf, IStorage storage, int textureIndex)
{
string textureName = default;
var imageBytes = await Awaitable.Run(() =>
{
var imageIndex = gltf.GetImageIndexFromTextureIndex(index);
var segments = gltf.GetImageBytes(storage, imageIndex, out textureName);
var imageIndex = gltf.textures[textureIndex].source;
var segments = gltf.GetImageBytes(storage, imageIndex);
return ToArray(segments);
});
//
// texture from image(png etc) bytes
//
var textureType = TextureIO.GetglTFTextureType(gltf, index);
var textureType = TextureIO.GetglTFTextureType(gltf, textureIndex);
var colorSpace = TextureIO.GetColorSpace(textureType);
var isLinear = colorSpace == RenderTextureReadWrite.Linear;
var sampler = gltf.GetSamplerFromTextureIndex(index);
var sampler = gltf.GetSamplerFromTextureIndex(textureIndex);
var texture = new Texture2D(2, 2, TextureFormat.ARGB32, false, isLinear);
texture.name = textureName;

View File

@@ -51,11 +51,9 @@ namespace UniGLTF
if (param.Index0.HasValue && m_externalMap != null)
{
var gltfTexture = m_gltf.textures[param.Index0.Value];
m_gltf.GetImageBytes(m_storage, gltfTexture.source, out string textureName);
if (m_externalMap.TryGetValue(textureName, out external))
if (m_externalMap.TryGetValue(gltfTexture.name, out external))
{
Debug.Log($"use external: {textureName}");
Debug.Log($"use external: {gltfTexture.name}");
m_textureCache.Add(param, new TextureLoadInfo(external, used, true));
return external;
}

View File

@@ -55,8 +55,8 @@ namespace UniGLTF
public IEnumerator ProcessOnMainThread(glTF gltf, IStorage storage, bool isLinear, glTFTextureSampler sampler)
{
var imageIndex = gltf.GetImageIndexFromTextureIndex(m_textureIndex);
var bytes = gltf.GetImageBytes(storage, imageIndex, out m_textureName);
var gltfTexture = gltf.textures[m_textureIndex];
var bytes = gltf.GetImageBytes(storage, gltfTexture.source);
// tmp file
var tmp = Path.GetTempFileName();