Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MeshIntegrator と MeshNormalizer を MeshUtility に移動 #523

Merged
merged 13 commits into from
Aug 26, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using UnityEngine;


namespace VRM
namespace MeshUtility
{
[CustomPropertyDrawer(typeof(BoneMeshEraser.EraseBone))]
public class EraseBoneDrawer : PropertyDrawer
Expand Down Expand Up @@ -51,7 +51,7 @@ public class BoneMeshEraserWizard : ScriptableWizard
[SerializeField]
BoneMeshEraser.EraseBone[] m_eraseBones;

[MenuItem(SkinnedMeshUtility.MENU_KEY + "BoneMeshEraser Wizard", priority = SkinnedMeshUtility.MENU_PRIORITY)]
[MenuItem(MeshUtility.MENU_PARENT + "BoneMeshEraser Wizard", priority = MeshUtility.MENU_PRIORITY)]
static void CreateWizard()
{
ScriptableWizard.DisplayWizard<BoneMeshEraserWizard>("BoneMeshEraser", "Erase triangles by bone", "Erase");
Expand Down Expand Up @@ -143,7 +143,7 @@ SkinnedMeshRenderer _Erase(GameObject go)
var bones = m_skinnedMesh.bones;
var eraseBones = m_eraseBones
.Where(x => x.Erase)
.Select(x => bones.IndexOf(x.Bone))
.Select(x => Array.IndexOf(bones, x.Bone))
.ToArray();

var meshNode = new GameObject("BoneMeshEraser");
Expand All @@ -168,7 +168,7 @@ void Erase()

// save mesh to Assets
var assetPath = string.Format("{0}{1}", go.name, ASSET_SUFFIX);
var prefab = SkinnedMeshUtility.GetPrefab(go);
var prefab = MeshUtility.GetPrefab(go);
if (prefab != null)
{
var prefabPath = AssetDatabase.GetAssetPath(prefab);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "MeshUtility",
"references": [],
"name": "MeshUtility.Editor",
"references": [
"MeshUtility"
],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
Expand Down
20 changes: 16 additions & 4 deletions Assets/MeshUtility/Editor/MeshUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@

namespace MeshUtility
{
public class MeshUtility : MonoBehaviour
public class MeshUtility
{
public const string MENU_PARENT = "Mesh Utility/";
public const int MENU_PRIORITY = 11;

private const string ASSET_SUFFIX = ".mesh.asset";
private const string MENU_NAME = "Mesh Utility/Separate Skinned Meshes Contained BlendShape";
private const string MENU_NAME = MENU_PARENT + "Separate Skinned Meshes Contained BlendShape";
private static readonly Vector3 ZERO_MOVEMENT = Vector3.zero;

public static Object GetPrefab(GameObject instance)
{
#if UNITY_2018_2_OR_NEWER
return PrefabUtility.GetCorrespondingObjectFromSource(instance);
#else
return PrefabUtility.GetPrefabParent(go);
#endif
}

private enum BlendShapeLogic
{
WithBlendShape,
Expand Down Expand Up @@ -51,7 +63,7 @@ public static void LinkToMeshSeparatorDocs()

private static void SeparationProcessing(GameObject go)
{
var outputObject = Instantiate(go);
var outputObject = GameObject.Instantiate(go);
var skinnedMeshRenderers = outputObject.GetComponentsInChildren<SkinnedMeshRenderer>();
foreach (var skinnedMeshRenderer in skinnedMeshRenderers)
{
Expand Down Expand Up @@ -127,7 +139,7 @@ private static void SeparatePolyWithBlendShape(SkinnedMeshRenderer skinnedMeshRe
// put the mesh without BlendShape in a new SkinnedMeshRenderer
var srcGameObject = skinnedMeshRendererInput.gameObject;
var srcTransform = skinnedMeshRendererInput.transform.parent;
var targetObjectForMeshWithoutBS = Instantiate(srcGameObject);
var targetObjectForMeshWithoutBS = GameObject.Instantiate(srcGameObject);
targetObjectForMeshWithoutBS.name = srcGameObject.name + "_WithoutBlendShape";
targetObjectForMeshWithoutBS.transform.SetParent(srcTransform);
var skinnedMeshRendererWithoutBS = targetObjectForMeshWithoutBS.GetComponent<SkinnedMeshRenderer>();
Expand Down
13 changes: 12 additions & 1 deletion Assets/MeshUtility/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@

Mesh processing tool in Unity platform.

## MeshSeparator
## Utilities

### MeshSeparator

Separate the target mesh into different categories based on given conditions.

Currently support BlendShape mesh separation. See [documentation](Documentation/notes/MeshSeparator.md) for more details.

<img src="Documentation/images/blendshape_separator.jpg" width="300">

### MeshIntegrator

Integrate all mesh in hierarchy.

### MeshNormalizer

Bake hierarchy. This is VRM normalize backend.
MeshNormalizer can do blendShape bake.

## Import MeshUtility

There are two ways to import MeshUtility into a Unity project.
Expand Down
8 changes: 8 additions & 0 deletions Assets/MeshUtility/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UniGLTF;
// using UniGLTF;
#if UNITY_EDITOR
using UnityEditor;
#endif


namespace VRM
namespace MeshUtility
{
[DisallowMultipleComponent]
public class VRMBindposeGizmo : MonoBehaviour
public class BindposeGizmo : MonoBehaviour
{
[SerializeField]
Mesh m_target;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;


namespace VRM
namespace MeshUtility
{
public static class BoneMeshEraser
{
Expand Down Expand Up @@ -151,18 +150,6 @@ public static Mesh CreateErasedMesh(Mesh src, int[] eraseBoneIndices)
return mesh;
}

public static int IndexOf(this Transform[] list, Transform target)
{
for (int i = 0; i < list.Length; ++i)
{
if (list[i] == target)
{
return i;
}
}
return -1;
}

public static IEnumerable<Transform> Ancestor(this Transform t)
{
yield return t;
Expand Down
Loading