Merge pull request #997 from ousttrue/fix/meshutility_namespace

Fix/meshutility namespace
This commit is contained in:
ousttrue 2021-06-01 19:42:36 +09:00 committed by GitHub
commit 21f35c70e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 63 additions and 996 deletions

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using UnityEditor;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
/// <summary>
/// Application.dataPath を root とするファイルパスを扱う。

View File

@ -6,7 +6,7 @@ using UnityEditor;
using UnityEngine;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
[CustomPropertyDrawer(typeof(BoneMeshEraser.EraseBone))]
public class EraseBoneDrawer : PropertyDrawer

View File

@ -7,7 +7,7 @@ using UnityEditor;
using UniGLTF;
using UniGLTF.M17N;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
[CustomEditor(typeof(MeshProcessDialog), true)]
public class BoneMeshEraserGUI : Editor

View File

@ -4,7 +4,7 @@ using System.Linq;
using UnityEngine;
using UnityEditor;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
public class MeshUtility
{

View File

@ -4,7 +4,7 @@ using UnityEngine;
using VRMShaders;
using ColorSpace = VRMShaders.ColorSpace;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
public static class EditorChangeTextureType
{

View File

@ -3,7 +3,7 @@ using System.Linq;
using UnityEditor;
using UnityEngine;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
public static class TabBar

View File

@ -7,7 +7,7 @@ using UnityEditor;
#endif
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
[DisallowMultipleComponent]
public class BindposeGizmo : MonoBehaviour

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
public static class BoneMeshEraser
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using UnityEngine;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
public static class BoneNormalizer
{

View File

@ -2,7 +2,7 @@
using System.Linq;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
public static class MeshExtensions
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using UnityEngine;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
[System.Serializable]
public class MeshIntegrationResult

View File

@ -2,7 +2,7 @@ using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
public class MeshIntegrator
{

View File

@ -2,7 +2,7 @@ using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
public static class MeshIntegratorUtility
{

View File

@ -7,7 +7,7 @@ using UnityEditor;
#endif
namespace MeshUtility
namespace UniGLTF.MeshUtility
{
public static class StaticMeshIntegrator
{

View File

@ -1,319 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MeshUtility
{
public struct PosRot
{
public Vector3 Position;
public Quaternion Rotation;
public static PosRot FromGlobalTransform(Transform t)
{
return new PosRot
{
Position = t.position,
Rotation = t.rotation,
};
}
}
public class BlendShape
{
public string Name;
public BlendShape(string name)
{
Name = name;
}
public List<Vector3> Positions = new List<Vector3>();
public List<Vector3> Normals = new List<Vector3>();
public List<Vector3> Tangents = new List<Vector3>();
}
public static class UnityExtensions
{
public static Vector4 ReverseZ(this Vector4 v)
{
return new Vector4(v.x, v.y, -v.z, v.w);
}
public static Vector3 ReverseZ(this Vector3 v)
{
return new Vector3(v.x, v.y, -v.z);
}
[Obsolete]
public static Vector2 ReverseY(this Vector2 v)
{
return new Vector2(v.x, -v.y);
}
public static Vector2 ReverseUV(this Vector2 v)
{
return new Vector2(v.x, 1.0f - v.y);
}
public static Quaternion ReverseZ(this Quaternion q)
{
float angle;
Vector3 axis;
q.ToAngleAxis(out angle, out axis);
return Quaternion.AngleAxis(-angle, ReverseZ(axis));
}
public static Matrix4x4 Matrix4x4FromColumns(Vector4 c0, Vector4 c1, Vector4 c2, Vector4 c3)
{
#if UNITY_2017_1_OR_NEWER
return new Matrix4x4(c0, c1, c2, c3);
#else
var m = default(Matrix4x4);
m.SetColumn(0, c0);
m.SetColumn(1, c1);
m.SetColumn(2, c2);
m.SetColumn(3, c3);
return m;
#endif
}
public static Matrix4x4 Matrix4x4FromRotation(Quaternion q)
{
#if UNITY_2017_1_OR_NEWER
return Matrix4x4.Rotate(q);
#else
var m = default(Matrix4x4);
m.SetTRS(Vector3.zero, q, Vector3.one);
return m;
#endif
}
public static Matrix4x4 ReverseZ(this Matrix4x4 m)
{
m.SetTRS(m.ExtractPosition().ReverseZ(), m.ExtractRotation().ReverseZ(), m.ExtractScale());
return m;
}
public static Matrix4x4 MatrixFromArray(float[] values)
{
var m = new Matrix4x4();
m.m00 = values[0];
m.m10 = values[1];
m.m20 = values[2];
m.m30 = values[3];
m.m01 = values[4];
m.m11 = values[5];
m.m21 = values[6];
m.m31 = values[7];
m.m02 = values[8];
m.m12 = values[9];
m.m22 = values[10];
m.m32 = values[11];
m.m03 = values[12];
m.m13 = values[13];
m.m23 = values[14];
m.m33 = values[15];
return m;
}
// https://forum.unity.com/threads/how-to-assign-matrix4x4-to-transform.121966/
public static Quaternion ExtractRotation(this Matrix4x4 matrix)
{
Vector3 forward;
forward.x = matrix.m02;
forward.y = matrix.m12;
forward.z = matrix.m22;
Vector3 upwards;
upwards.x = matrix.m01;
upwards.y = matrix.m11;
upwards.z = matrix.m21;
return Quaternion.LookRotation(forward, upwards);
}
public static Vector3 ExtractPosition(this Matrix4x4 matrix)
{
Vector3 position;
position.x = matrix.m03;
position.y = matrix.m13;
position.z = matrix.m23;
return position;
}
public static Vector3 ExtractScale(this Matrix4x4 matrix)
{
Vector3 scale;
scale.x = new Vector4(matrix.m00, matrix.m10, matrix.m20, matrix.m30).magnitude;
scale.y = new Vector4(matrix.m01, matrix.m11, matrix.m21, matrix.m31).magnitude;
scale.z = new Vector4(matrix.m02, matrix.m12, matrix.m22, matrix.m32).magnitude;
return scale;
}
public static string RelativePathFrom(this Transform self, Transform root)
{
var path = new List<String>();
for (var current = self; current != null; current = current.parent)
{
if (current == root)
{
return String.Join("/", path.ToArray());
}
path.Insert(0, current.name);
}
throw new Exception("no RelativePath");
}
public static Transform GetChildByName(this Transform self, string childName)
{
foreach (Transform child in self)
{
if (child.name == childName)
{
return child;
}
}
throw new KeyNotFoundException();
}
public static Transform GetFromPath(this Transform self, string path)
{
var current = self;
var split = path.Split('/');
foreach (var childName in split)
{
current = current.GetChildByName(childName);
}
return current;
}
public static IEnumerable<Transform> GetChildren(this Transform self)
{
foreach (Transform child in self)
{
yield return child;
}
}
public static IEnumerable<Transform> Traverse(this Transform t)
{
yield return t;
foreach (Transform x in t)
{
foreach (Transform y in x.Traverse())
{
yield return y;
}
}
}
[Obsolete("Use FindDescendant(name)")]
public static Transform FindDescenedant(this Transform t, string name)
{
return FindDescendant(t, name);
}
public static Transform FindDescendant(this Transform t, string name)
{
return t.Traverse().First(x => x.name == name);
}
public static IEnumerable<Transform> Ancestors(this Transform t)
{
yield return t;
if (t.parent != null)
{
foreach (Transform x in t.parent.Ancestors())
{
yield return x;
}
}
}
public static float[] ToArray(this Quaternion q)
{
return new float[] { q.x, q.y, q.z, q.w };
}
public static float[] ToArray(this Vector3 v)
{
return new float[] { v.x, v.y, v.z };
}
public static float[] ToArray(this Vector4 v)
{
return new float[] { v.x, v.y, v.z, v.w };
}
public static float[] ToArray(this Color c)
{
return new float[] { c.r, c.g, c.b, c.a };
}
public static void ReverseZRecursive(this Transform root)
{
var globalMap = root.Traverse().ToDictionary(x => x, x => PosRot.FromGlobalTransform(x));
foreach (var x in root.Traverse())
{
x.position = globalMap[x].Position.ReverseZ();
x.rotation = globalMap[x].Rotation.ReverseZ();
}
}
public static Mesh GetSharedMesh(this Transform t)
{
var meshFilter = t.GetComponent<MeshFilter>();
if (meshFilter != null)
{
return meshFilter.sharedMesh;
}
var skinnedMeshRenderer = t.GetComponent<SkinnedMeshRenderer>();
if (skinnedMeshRenderer != null)
{
return skinnedMeshRenderer.sharedMesh;
}
return null;
}
public static Material[] GetSharedMaterials(this Transform t)
{
var renderer = t.GetComponent<Renderer>();
if (renderer != null)
{
return renderer.sharedMaterials;
}
return new Material[] { };
}
public static bool Has<T>(this Transform transform, T t) where T : Component
{
return transform.GetComponent<T>() == t;
}
public static T GetOrAddComponent<T>(this GameObject go) where T : Component
{
var c = go.GetComponent<T>();
if (c != null)
{
return c;
}
return go.AddComponent<T>();
}
}
}

View File

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

View File

@ -1,435 +0,0 @@
using System;
using System.IO;
using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MeshUtility
{
/// <summary>
/// relative path from Unity project root.
/// For AssetDatabase.
/// </summary>
public struct UnityPath
{
#region UnityPath
public string Value
{
get;
private set;
}
public override string ToString()
{
return string.Format("unity://{0}", Value);
}
public bool IsNull
{
get { return Value == null; }
}
public bool IsUnderAssetsFolder
{
get
{
if (IsNull)
{
return false;
}
return Value == "Assets" || Value.StartsWith("Assets/");
}
}
public bool IsStreamingAsset
{
get
{
if (IsNull)
{
return false;
}
return FullPath.StartsWith(Application.streamingAssetsPath + "/");
}
}
public string FileName
{
get { return Path.GetFileName(Value); }
}
public string FileNameWithoutExtension
{
get { return Path.GetFileNameWithoutExtension(Value); }
}
public string Extension
{
get { return Path.GetExtension(Value); }
}
public UnityPath Parent
{
get
{
if (IsNull)
{
return default(UnityPath);
}
return new UnityPath(Path.GetDirectoryName(Value));
}
}
public bool HasParent
{
get
{
return !string.IsNullOrEmpty(Value);
}
}
static readonly char[] EscapeChars = new char[]
{
'\\',
'/',
':',
'*',
'?',
'"',
'<',
'>',
'|',
};
static string EscapeFilePath(string path)
{
foreach (var x in EscapeChars)
{
path = path.Replace(x, '+');
}
return path;
}
public UnityPath Child(string name)
{
if (IsNull)
{
throw new NotImplementedException();
}
else if (Value == "")
{
return new UnityPath(name);
}
else
{
return new UnityPath(Value + "/" + name);
}
}
public override int GetHashCode()
{
if (IsNull)
{
return 0;
}
return Value.GetHashCode();
}
public override bool Equals(object obj)
{
if(obj is UnityPath)
{
var rhs = (UnityPath)obj;
if(Value==null && rhs.Value == null)
{
return true;
}
else if (Value == null)
{
return false;
}
else if (rhs.Value == null)
{
return false;
}
else
{
return Value == rhs.Value;
}
}
else
{
return false;
}
}
/// <summary>
/// Remove extension and add suffix
/// </summary>
/// <param name="prefabPath"></param>
/// <param name="suffix"></param>
/// <returns></returns>
public UnityPath GetAssetFolder(string suffix)
{
if (!IsUnderAssetsFolder)
{
throw new NotImplementedException();
}
return new UnityPath(
string.Format("{0}/{1}{2}",
Parent.Value,
FileNameWithoutExtension,
suffix
));
}
UnityPath(string value) : this()
{
Value = value.Replace("\\", "/");
}
/// <summary>
///
/// </summary>
/// <param name="unityPath">Relative from unity current path. GetParent(Application.dataPath)</param>
/// <returns></returns>
public static UnityPath FromUnityPath(string unityPath)
{
if (String.IsNullOrEmpty(unityPath))
{
return new UnityPath
{
Value=""
};
}
return FromFullpath(Path.GetFullPath(unityPath));
}
#endregion
#region FullPath
static string s_basePath;
static string BaseFullPath
{
get
{
if (string.IsNullOrEmpty(s_basePath))
{
s_basePath = Path.GetFullPath(Application.dataPath + "/..").Replace("\\", "/");
}
return s_basePath;
}
}
static string AssetFullPath
{
get
{
return BaseFullPath + "/Assets";
}
}
public string FullPath
{
get
{
if (IsNull)
{
throw new NotImplementedException();
}
return Path.Combine(BaseFullPath, Value).Replace("\\", "/");
}
}
public bool IsFileExists
{
get { return File.Exists(FullPath); }
}
public bool IsDirectoryExists
{
get { return Directory.Exists(FullPath); }
}
/// <summary>
///
/// </summary>
/// <param name="fullPath">C:/path/to/file</param>
/// <returns></returns>
public static UnityPath FromFullpath(string fullPath)
{
if(fullPath == null)
{
fullPath = "";
}
fullPath = fullPath.Replace("\\", "/");
if (fullPath == BaseFullPath) {
return new UnityPath
{
Value=""
};
}
else if(fullPath.StartsWith(BaseFullPath + "/"))
{
return new UnityPath(fullPath.Substring(BaseFullPath.Length + 1));
}
else
{
return default(UnityPath);
}
}
public static bool IsUnderAssetFolder(string fullPath)
{
return fullPath.Replace("\\", "/").StartsWith(AssetFullPath);
}
#endregion
[Obsolete("Use TraverseDir()")]
public IEnumerable<UnityPath> TravserseDir()
{
return TraverseDir();
}
public IEnumerable<UnityPath> TraverseDir()
{
if (IsDirectoryExists)
{
yield return this;
foreach(var child in ChildDirs)
{
foreach(var x in child.TraverseDir())
{
yield return x;
}
}
}
}
public IEnumerable<UnityPath> ChildDirs
{
get
{
foreach(var x in Directory.GetDirectories(FullPath))
{
yield return UnityPath.FromFullpath(x);
}
}
}
public IEnumerable<UnityPath> ChildFiles
{
get
{
foreach (var x in Directory.GetFiles(FullPath))
{
yield return UnityPath.FromFullpath(x);
}
}
}
#if UNITY_EDITOR
public T GetImporter<T>() where T : AssetImporter
{
return AssetImporter.GetAtPath(Value) as T;
}
public static UnityPath FromAsset(UnityEngine.Object asset)
{
return new UnityPath(AssetDatabase.GetAssetPath(asset));
}
public void ImportAsset()
{
if (!IsUnderAssetsFolder)
{
throw new NotImplementedException();
}
AssetDatabase.ImportAsset(Value);
}
public void EnsureFolder()
{
if (IsNull)
{
throw new NotImplementedException();
}
if (HasParent)
{
Parent.EnsureFolder();
}
if (!IsDirectoryExists)
{
var parent = Parent;
// ensure parent
parent.ImportAsset();
// create
AssetDatabase.CreateFolder(
parent.Value,
Path.GetFileName(Value)
);
ImportAsset();
}
}
public UnityEngine.Object[] GetSubAssets()
{
if (!IsUnderAssetsFolder)
{
throw new NotImplementedException();
}
return AssetDatabase.LoadAllAssetsAtPath(Value);
}
public void CreateAsset(UnityEngine.Object o)
{
if (!IsUnderAssetsFolder)
{
throw new NotImplementedException();
}
AssetDatabase.CreateAsset(o, Value);
}
public void AddObjectToAsset(UnityEngine.Object o)
{
if (!IsUnderAssetsFolder)
{
throw new NotImplementedException();
}
AssetDatabase.AddObjectToAsset(o, Value);
}
public T LoadAsset<T>() where T : UnityEngine.Object
{
if (!IsUnderAssetsFolder)
{
throw new NotImplementedException();
}
return AssetDatabase.LoadAssetAtPath<T>(Value);
}
public UnityPath GenerateUniqueAssetPath()
{
if (!IsUnderAssetsFolder)
{
throw new NotImplementedException();
}
return new UnityPath(AssetDatabase.GenerateUniqueAssetPath(Value));
}
#endif
}
}

View File

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 7b7af908694806c469d62ce0b5b2f06a
timeCreated: 1532326996
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -6,7 +6,7 @@ using UnityEditor;
using UnityEngine;
using System;
namespace MeshUtility
namespace UniHumanoid
{
[CustomEditor(typeof(Humanoid))]
public class HumanoidEditor : Editor

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 57cc7b16eb4146c4ab5631f538e2489f
guid: ee7ea50401b78f64a950f59564838270
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace MeshUtility
namespace UniHumanoid
{
/// <summary>
/// Bone割り当てを保持する。

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 889d98e41c0e8ff48bae50d1a729c2df
guid: 97a39af5b64ede64e86b92b5bf94a0e7
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace MeshUtility
namespace UniHumanoid
{
public static class HumanoidLoader
{
@ -37,16 +37,6 @@ namespace MeshUtility
return AvatarBuilder.BuildHumanAvatar(root.gameObject, description);
}
static SkeletonBone ToSkeletonBone(this Transform t)
{
var sb = new SkeletonBone();
sb.name = t.name;
sb.position = t.localPosition;
sb.rotation = t.localRotation;
sb.scale = t.localScale;
return sb;
}
static HumanBodyBones TraitToHumanBone(string x)
{
return (HumanBodyBones)Enum.Parse(typeof(HumanBodyBones), x.Replace(" ", ""), true);

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 12453a111483e4145852e3b057e065d9
guid: 7b88d4c3436f9894ebc69f162d804cd4
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -1,9 +1,9 @@
using NUnit.Framework;
using System.IO;
using UniGLTF;
using UniGLTF.MeshUtility;
using UniJSON;
using UnityEngine;
using MeshUtility;
using System;
using VRMShaders;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniGLTF;
using UniGLTF.MeshUtility;
using UnityEngine;
using VRMShaders;
@ -76,7 +77,7 @@ namespace VRM
.Distinct()
.ToArray();
var copyMesh = MeshUtility.MeshExtensions.Copy(mesh, copyBlendShape: false);
var copyMesh = mesh.Copy(copyBlendShape: false);
// 使われている BlendShape だけをコピーする
foreach (var i in usedBlendshapeIndexArray)
{

View File

@ -5,6 +5,7 @@ using UnityEngine;
using UniGLTF;
using UniGLTF.M17N;
using System.IO;
using UniGLTF.MeshUtility;
namespace VRM
{
@ -252,7 +253,7 @@ namespace VRM
//
// GUI
//
_tab = MeshUtility.TabBar.OnGUI(_tab);
_tab = TabBar.OnGUI(_tab);
foreach (var meshInfo in m_meshes.Meshes)
{
switch (meshInfo.VertexColor)

View File

@ -273,7 +273,7 @@ namespace VRM
break;
}
var assetPath = MeshUtility.UnityPath.FromFullpath(dst);
var assetPath = UnityPath.FromFullpath(dst);
EditorApplication.delayCall += () =>
{
assetPath.ImportAsset();

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using UniGLTF;
using UniGLTF.MeshUtility;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
@ -44,7 +45,7 @@ namespace VRM
//}
public static List<MeshUtility.MeshIntegrationResult> Integrate(GameObject prefab)
public static List<MeshIntegrationResult> Integrate(GameObject prefab)
{
Undo.RecordObject(prefab, "Mesh Integration");
var instance = SkinnedMeshUtility.InstantiatePrefab(prefab);

View File

@ -4,7 +4,7 @@ using UnityEngine;
using System.Linq;
using System;
using System.Collections.Generic;
using UniGLTF.MeshUtility;
namespace VRM
{
@ -58,7 +58,7 @@ namespace VRM
MaterialList[] m_duplicateMaterials;
[Header("Result")]
public MeshUtility.MeshIntegrationResult[] integrationResults;
public MeshIntegrationResult[] integrationResults;
[MenuItem(MENU_KEY)]
static void CreateWizard()
@ -124,7 +124,7 @@ namespace VRM
return;
}
m_uniqueMaterials = MeshUtility.MeshIntegratorUtility.EnumerateSkinnedMeshRenderer(m_root.transform, false)
m_uniqueMaterials = MeshIntegratorUtility.EnumerateSkinnedMeshRenderer(m_root.transform, false)
.SelectMany(x => x.sharedMaterials)
.Distinct()
.ToArray();

View File

@ -1,5 +1,4 @@
using System.Linq;
using MeshUtility;
using UniGLTF;
using UnityEditor;
using UnityEngine;

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using UniGLTF;
using UniGLTF.MeshUtility;
using UnityEngine;
@ -215,7 +216,7 @@ namespace VRM
setVisibility(renderer, false, true);
// 削除対象のボーンに対するウェイトを保持する三角形を除外して、一人称用のモデルを複製する
var headlessMesh = MeshUtility.BoneMeshEraser.CreateErasedMesh(renderer.sharedMesh, eraseBones);
var headlessMesh = BoneMeshEraser.CreateErasedMesh(renderer.sharedMesh, eraseBones);
if (headlessMesh.triangles.Length == 0)
{
// 一人称用のmeshには描画すべき部分が無い(全部削除された)

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UniGLTF.MeshUtility;
using UniHumanoid;
using UnityEngine;
@ -66,7 +67,7 @@ namespace VRM
//
// 正規化されたヒエラルキーを作る
//
var (normalized, bMap) = MeshUtility.BoneNormalizer.Execute(go, (_src, dst, boneMap) =>
var (normalized, bMap) = BoneNormalizer.Execute(go, (_src, dst, boneMap) =>
{
var src = _src.GetComponent<Animator>();

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using UniGLTF;
using UniGLTF.MeshUtility;
using UnityEngine;
namespace VRM
@ -38,17 +39,17 @@ namespace VRM
return true;
}
public static List<MeshUtility.MeshIntegrationResult> Integrate(GameObject root, List<BlendShapeClip> blendshapeClips)
public static List<UniGLTF.MeshUtility.MeshIntegrationResult> Integrate(GameObject root, List<BlendShapeClip> blendshapeClips)
{
var result = new List<MeshUtility.MeshIntegrationResult>();
var result = new List<UniGLTF.MeshUtility.MeshIntegrationResult>();
var withoutBlendShape = MeshUtility.MeshIntegratorUtility.Integrate(root, onlyBlendShapeRenderers: false);
var withoutBlendShape = MeshIntegratorUtility.Integrate(root, onlyBlendShapeRenderers: false);
if (withoutBlendShape.IntegratedRenderer != null)
{
result.Add(withoutBlendShape);
}
var onlyBlendShape = MeshUtility.MeshIntegratorUtility.Integrate(root, onlyBlendShapeRenderers: true);
var onlyBlendShape = MeshIntegratorUtility.Integrate(root, onlyBlendShapeRenderers: true);
if (onlyBlendShape.IntegratedRenderer != null)
{
result.Add(onlyBlendShape);
@ -58,7 +59,7 @@ namespace VRM
return result;
}
private static void FollowBlendshapeRendererChange(List<BlendShapeClip> clips, MeshUtility.MeshIntegrationResult result, GameObject root)
private static void FollowBlendshapeRendererChange(List<BlendShapeClip> clips, MeshIntegrationResult result, GameObject root)
{
if (clips == null || result == null || result.IntegratedRenderer == null || root == null) return;

View File

@ -1,5 +1,6 @@
using NUnit.Framework;
using UnityEngine;
using UniGLTF.MeshUtility;
using System.Linq;
namespace VRM
@ -55,7 +56,7 @@ namespace VRM
var src = new Mesh();
src.AddBlendShapeFrame("blendShape", 100.0f, null, null, null);
var dst = MeshUtility.MeshExtensions.Copy(src, true);
var dst = src.Copy(true);
MeshEquals(src, dst);
}

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using UniGLTF.MeshUtility;
using UnityEngine;
namespace VRM
@ -58,7 +59,7 @@ namespace VRM
map.Add(null, new GameObject("null"));
// map.Add(new GameObject("c"), null); // ありえないので Exception にしてある
var boneWeights = map.CreateBoneWeight(64).ToArray();
var newBoneWeight = MeshUtility.BoneNormalizer.MapBoneWeight(boneWeights, map.Map,
var newBoneWeight = BoneNormalizer.MapBoneWeight(boneWeights, map.Map,
map.SrcBones.ToArray(), map.DstBones.ToArray());
// 正常系
@ -74,7 +75,7 @@ namespace VRM
map.Add(null, new GameObject("null"));
// map.Add(new GameObject("c"), null); // ありえないので Exception にしてある
var boneWeights = map.CreateBoneWeight(64).ToArray();
var newBoneWeight = MeshUtility.BoneNormalizer.MapBoneWeight(boneWeights, map.Map,
var newBoneWeight = BoneNormalizer.MapBoneWeight(boneWeights, map.Map,
map.SrcBones.ToArray(), map.DstBones.ToArray());
// 4 つめが 0 になる

View File

@ -1,5 +1,4 @@
using MeshUtility;
using UnityEditor;
using UnityEditor;
using UnityEngine;
namespace UniVRM10

View File

@ -1,6 +1,6 @@
using System;
using System.IO;
using MeshUtility;
using UniGLTF;
using UnityEditor;
using UnityEngine;

View File

@ -1,139 +0,0 @@
using System;
using UnityEngine;
using System.Linq;
using MeshUtility;
using VrmLib;
namespace UniVRM10
{
public static class EditorUnityBuilder
{
// static public ModelAsset ToUnityAsset(VrmLib.Model model, string assetPath, IExternalUnityObject scriptedImporter)
// {
// var modelAsset = new ModelAsset();
// CreateTextureAsset(model, modelAsset, scriptedImporter);
// CreateMaterialAsset(model, modelAsset, scriptedImporter);
// CreateMeshAsset(model, modelAsset);
// // node
// RuntimeUnityBuilder.CreateNodes(model.Root, null, modelAsset.Map.Nodes);
// modelAsset.Root = modelAsset.Map.Nodes[model.Root];
// // renderer
// var map = modelAsset.Map;
// foreach (var (node, go) in map.Nodes)
// {
// if (node.MeshGroup is null)
// {
// continue;
// }
// if (node.MeshGroup.Meshes.Count > 1)
// {
// throw new NotImplementedException("invalid isolated vertexbuffer");
// }
// var renderer = RuntimeUnityBuilder.CreateRenderer(node, go, map);
// map.Renderers.Add(node, renderer);
// modelAsset.Renderers.Add(renderer);
// }
// if (model.Vrm != null)
// {
// // humanoid
// var humanoid = modelAsset.Root.AddComponent<MeshUtility.Humanoid>();
// humanoid.AssignBones(modelAsset.Map.Nodes.Select(x => (x.Key.HumanoidBone.GetValueOrDefault().ToUnity(), x.Value.transform)));
// modelAsset.HumanoidAvatar = humanoid.CreateAvatar();
// modelAsset.HumanoidAvatar.name = "VRM";
// var animator = modelAsset.Root.AddComponent<Animator>();
// animator.avatar = modelAsset.HumanoidAvatar;
// }
// return modelAsset;
// }
// static private void CreateTextureAsset(VrmLib.Model model, ModelAsset modelAsset, IExternalUnityObject scriptedImporter)
// {
// var externalObjects = scriptedImporter.GetExternalUnityObjects<Texture2D>();
// // textures
// for (int i = 0; i < model.Textures.Count; ++i)
// {
// if (model.Textures[i] is VrmLib.ImageTexture imageTexture)
// {
// if (string.IsNullOrEmpty(model.Textures[i].Name))
// {
// model.Textures[i].Name = string.Format("{0}_img{1}", model.Root.Name, i);
// }
// if (externalObjects.ContainsKey(model.Textures[i].Name))
// {
// modelAsset.Map.Textures.Add(imageTexture, externalObjects[model.Textures[i].Name]);
// modelAsset.Textures.Add(externalObjects[model.Textures[i].Name]);
// }
// else
// {
// var name = !string.IsNullOrEmpty(imageTexture.Name)
// ? imageTexture.Name
// : string.Format("{0}_img{1}", model.Root.Name, i);
// var texture = RuntimeUnityBuilder.CreateTexture(imageTexture);
// texture.name = name;
// modelAsset.Map.Textures.Add(imageTexture, texture);
// modelAsset.Textures.Add(texture);
// }
// }
// else
// {
// Debug.LogWarning($"{i} not ImageTexture");
// }
// }
// }
// static private void CreateMaterialAsset(VrmLib.Model model, ModelAsset modelAsset, IExternalUnityObject scriptedImporter)
// {
// var externalObjects = scriptedImporter.GetExternalUnityObjects<UnityEngine.Material>();
// foreach (var src in model.Materials)
// {
// if (externalObjects.ContainsKey(src.Name))
// {
// modelAsset.Map.Materials.Add(src, externalObjects[src.Name]);
// modelAsset.Materials.Add(externalObjects[src.Name]);
// }
// else
// {
// // TODO: material has VertexColor
// var material = RuntimeUnityMaterialBuilder.CreateMaterialAsset(src, hasVertexColor: false, modelAsset.Map.Textures);
// material.name = src.Name;
// modelAsset.Map.Materials.Add(src, material);
// modelAsset.Materials.Add(material);
// }
// }
// }
// static private void CreateMeshAsset(VrmLib.Model model, ModelAsset modelAsset)
// {
// for (int i = 0; i < model.MeshGroups.Count; ++i)
// {
// var src = model.MeshGroups[i];
// if (src.Meshes.Count == 1)
// {
// // submesh 方式
// var mesh = new UnityEngine.Mesh();
// mesh.name = src.Name;
// mesh.LoadMesh(src.Meshes[0], src.Skin);
// modelAsset.Map.Meshes.Add(src, mesh);
// modelAsset.Meshes.Add(mesh);
// }
// else
// {
// // 頂点バッファの連結が必用
// throw new NotImplementedException();
// }
// }
// }
}
}

View File

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

View File

@ -2,6 +2,7 @@
using UnityEngine;
using UniGLTF;
using System.IO;
using UniGLTF.MeshUtility;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
@ -57,7 +58,7 @@ namespace UniVRM10
EditorGUILayout.HelpBox(m_message, MessageType.Error);
}
s_currentTab = MeshUtility.TabBar.OnGUI(s_currentTab);
s_currentTab = TabBar.OnGUI(s_currentTab);
GUILayout.Space(10);
switch (s_currentTab)

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using UniGLTF;
using UniGLTF.M17N;
using UniGLTF.MeshUtility;
using UnityEditor;
using UnityEngine;
using VrmLib;
@ -235,7 +236,7 @@ namespace UniVRM10
}
// tabbar
_tab = MeshUtility.TabBar.OnGUI(_tab);
_tab = TabBar.OnGUI(_tab);
switch (_tab)
{
case Tabs.Meta:

View File

@ -1,7 +1,6 @@
using MeshUtility;
using UniGLTF;
using UnityEngine;
namespace UniVRM10
{
[CreateAssetMenu(menuName = "VRM10/Expression")]

View File

@ -3,7 +3,7 @@ using System.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using MeshUtility;
using UniGLTF;
#if UNITY_EDITOR
using UnityEditor;
#endif

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using MeshUtility;
using UniGLTF;
using UnityEngine;
using VRMShaders;

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MeshUtility;
using UniGLTF.MeshUtility;
using UnityEngine;
namespace UniVRM10

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MeshUtility;
using UnityEngine;
using VrmLib;
@ -31,10 +30,10 @@ namespace UniVRM10
// humanoid
{
var humanoid = root.GetComponent<MeshUtility.Humanoid>();
var humanoid = root.GetComponent<UniHumanoid.Humanoid>();
if (humanoid is null)
{
humanoid = root.AddComponent<MeshUtility.Humanoid>();
humanoid = root.AddComponent<UniHumanoid.Humanoid>();
humanoid.AssignBonesFromAnimator();
}

View File

@ -215,7 +215,7 @@ namespace UniVRM10
Root.name = "VRM1";
// humanoid
var humanoid = Root.AddComponent<MeshUtility.Humanoid>();
var humanoid = Root.AddComponent<UniHumanoid.Humanoid>();
humanoid.AssignBones(m_map.Nodes.Select(x => (ToUnity(x.Key.HumanoidBone.GetValueOrDefault()), x.Value.transform)));
m_humanoid = humanoid.CreateAvatar();
m_humanoid.name = "humanoid";

View File

@ -5,15 +5,15 @@
"MToon",
"UniGLTF",
"VRMShaders.GLTF.IO.Runtime",
"VRMShaders.VRM10.Format.Runtime"
"VRMShaders.VRM10.Format.Runtime",
"UniHumanoid"
],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
"defineConstraints": []
}