GenerateTexture2DArray in ModelBaker

This commit is contained in:
max 2021-01-18 13:42:45 +01:00
parent efc5c179e4
commit e31ddd5631
7 changed files with 20 additions and 34 deletions

View File

@ -4,7 +4,7 @@ using UnityEditor;
namespace TAO.VertexAnimation.Editor
{
[CreateAssetMenu(fileName = "new ModelBaker", menuName = "VA_ModelBaker/ModelBaker", order = 400)]
[CreateAssetMenu(fileName = "new ModelBaker", menuName = "TAO/VertexAnimation/ModelBaker", order = 400)]
public class VA_ModelBaker : ScriptableObject
{
#if UNITY_EDITOR
@ -23,6 +23,7 @@ namespace TAO.VertexAnimation.Editor
// Output.
public GameObject prefab = null;
public Texture2DArray positionMap = null;
public Material material = null;
public Mesh[] meshes = null;
public VA_AnimationBook book = null;
@ -89,6 +90,8 @@ namespace TAO.VertexAnimation.Editor
target.ConbineAndConvertGameObject();
bakedData = target.Bake(animationClips, fps, textureWidth);
positionMap = VA_Texture2DArrayUtils.CreateTextureArray(bakedData.positionMaps.ToArray(), false, true, TextureWrapMode.Repeat, FilterMode.Point, 1, string.Format("{0}-PositionMap", name), true);
if (lodSettings.generate)
{
meshes = bakedData.mesh.GenerateLOD(lodSettings.LODCount(), lodSettings.GetQualitySettings());
@ -105,16 +108,16 @@ namespace TAO.VertexAnimation.Editor
{
AssetDatabaseUtils.RemoveChildAssets(this, new Object[2] { book, material });
// TODO: LODs
foreach (var m in meshes)
{
AssetDatabase.AddObjectToAsset(m, this);
}
foreach (var pm in bakedData.positionMaps)
{
AssetDatabase.AddObjectToAsset(pm, this);
}
AssetDatabase.AddObjectToAsset(positionMap, this);
//foreach (var pm in bakedData.positionMaps)
//{
// AssetDatabase.AddObjectToAsset(pm, this);
//}
AssetDatabase.SaveAssets();
@ -176,6 +179,9 @@ namespace TAO.VertexAnimation.Editor
material.shader = materialShader;
}
material.SetTexture("_PositionMap", positionMap);
material.SetInt("_MaxFrames", bakedData.maxFrames);
// Generate Prefab
prefab = AnimationPrefab.Create(path, name, meshes, material, lodSettings.GetTransitionSettings());
}

View File

@ -1,12 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TAO.VertexAnimation.Editor
{
[CreateAssetMenu(fileName = "new AssetConverter", menuName = "VA_Animation/AssetConverter", order = 400)]
public class VA_AssetConverter : ScriptableObject
{
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 55b196764521c964c84e8f2edd5c8da5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,6 +10,7 @@ namespace TAO.VertexAnimation
{
public Mesh mesh;
public List<Texture2D> positionMaps;
public int maxFrames;
// Returns main position map.
public Texture2D GetPositionMap
@ -84,6 +85,7 @@ namespace TAO.VertexAnimation
BakedData bd = Bake(model, ac, animationInfo);
bakedData.mesh = bd.mesh;
bakedData.positionMaps.AddRange(bd.positionMaps);
bakedData.maxFrames = maxFrames;
}
return bakedData;
@ -106,7 +108,8 @@ namespace TAO.VertexAnimation
BakedData bakedData = new BakedData()
{
mesh = mesh,
positionMaps = new List<Texture2D>() { BakePositionMap(model, animationClip, animationInfo) }
positionMaps = new List<Texture2D>() { BakePositionMap(model, animationClip, animationInfo) },
maxFrames = animationInfo.maxFrames
};
return bakedData;

View File

@ -3,7 +3,7 @@ using UnityEngine;
namespace TAO.VertexAnimation
{
[CreateAssetMenu(fileName = "new AnimationBook", menuName = "VA_Animation/AnimationBook", order = 400)]
[CreateAssetMenu(fileName = "new AnimationBook", menuName = "TAO/VertexAnimation/AnimationBook", order = 400)]
public class VA_AnimationBook : ScriptableObject
{
public PlayData playData = null;

View File

@ -3,7 +3,7 @@ using UnityEngine;
namespace TAO.VertexAnimation
{
[CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "VA_Animation/AnimationLibrary", order = 400)]
[CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "TAO/VertexAnimation/AnimationLibrary", order = 400)]
public class VA_AnimationLibrary : ScriptableObject
{
[SerializeField]

View File

@ -5,7 +5,7 @@ namespace TAO.VertexAnimation
public static class VA_Texture2DArrayUtils
{
public static Texture2DArray CreateTextureArray(Texture2D[] a_textures, bool a_useMipChain, bool a_isLinear,
TextureWrapMode a_wrapMode = TextureWrapMode.Repeat, FilterMode a_filterMode = FilterMode.Bilinear, int a_anisoLevel = 1, string a_name = "")
TextureWrapMode a_wrapMode = TextureWrapMode.Repeat, FilterMode a_filterMode = FilterMode.Bilinear, int a_anisoLevel = 1, string a_name = "", bool a_makeNoLongerReadable = true)
{
if(!IsValidForTextureArray(a_textures) || !IsValidCopyTexturePlatform())
{
@ -27,7 +27,7 @@ namespace TAO.VertexAnimation
textureArray.anisoLevel = a_anisoLevel;
textureArray.name = a_name;
textureArray.Apply(false, false);
textureArray.Apply(false, a_makeNoLongerReadable);
return textureArray;
}