implement BlendShapeClipEditor

This commit is contained in:
ousttrue
2018-04-07 21:43:39 +09:00
parent 1904c96661
commit 49916176e2
3 changed files with 64 additions and 8 deletions

View File

@@ -31,9 +31,9 @@ namespace VRM
}
}
public static void DrawElement(Rect position, SerializedProperty property, string[] pathList)
public static void DrawElement(Rect position, SerializedProperty property,
PreviewSceneManager scene)
{
var y = position.y;
/*
for (var depth = property.depth;
property.NextVisible(true) && property.depth > depth;
@@ -46,16 +46,22 @@ namespace VRM
}
}
*/
var pathProp = property.FindPropertyRelative("RelativePath");
var height = 16;
var height = EditorGUI.GetPropertyHeight(property);
var y = position.y;
var rect = new Rect(position.x, y, position.width, height);
//EditorGUI.PropertyField(, pathProp, false);
var index=StringPopup(rect, property.FindPropertyRelative("RelativePath"), scene.SkinnedMeshRendererPathList);
StringPopup(rect, pathProp, pathList);
y += height;
rect = new Rect(position.x, y, position.width, height);
IntPopup(rect, property.FindPropertyRelative("Index"), scene.GetBlendShapeNames(index));
y += height;
rect = new Rect(position.x, y, position.width, height);
FloatSlider(rect, property.FindPropertyRelative("Weight"), 100);
}
static void StringPopup(Rect rect, SerializedProperty prop, string[] options)
static int StringPopup(Rect rect, SerializedProperty prop, string[] options)
{
var oldIndex = Array.IndexOf(options, prop.stringValue);
var newIndex = EditorGUI.Popup(rect, oldIndex, options);
@@ -63,6 +69,27 @@ namespace VRM
{
prop.stringValue = options[newIndex];
}
return newIndex;
}
static void IntPopup(Rect rect, SerializedProperty prop, string[] options)
{
var oldIndex = prop.intValue;
var newIndex = EditorGUI.Popup(rect, oldIndex, options);
if (newIndex != oldIndex && newIndex >= 0 && newIndex < options.Length)
{
prop.intValue = newIndex;
}
}
static void FloatSlider(Rect rect, SerializedProperty prop, float maxValue)
{
var oldValue = prop.floatValue;
var newValue = EditorGUI.Slider(rect, prop.floatValue, 0, 100f);
if (newValue != oldValue)
{
prop.floatValue = newValue;
}
}
}
}

View File

@@ -35,7 +35,7 @@ namespace VRM
rect.height -= 4;
rect.y += 2;
//EditorGUI.PropertyField(rect, element);
BlendShapeBindingPropertyDrawer.DrawElement(rect, element, m_scene.SkinnedMeshRendererPathList);
BlendShapeBindingPropertyDrawer.DrawElement(rect, element, m_scene);
};
m_MaterialValuesProp = serializedObject.FindProperty("MaterialValues");

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using System.Reflection;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
@@ -85,6 +86,16 @@ namespace VRM
.ToArray()
;
foreach(var x in m_meshes)
{
if (x.SkinnedMeshRenderer != null)
{
var mesh = x.SkinnedMeshRenderer.sharedMesh;
m_blendShapeNameMap.Add(m_blendShapeNameMap.Count,
Enumerable.Range(0, mesh.blendShapeCount).Select(y => mesh.GetBlendShapeName(y)).ToArray());
}
}
Bake();
m_rendererPathList = m_meshes.Select(x => x.Path).ToArray();
@@ -111,6 +122,12 @@ namespace VRM
private set;
}
public int BlendShapeCount
{
get;
private set;
}
public Material[] Materials
{
get;
@@ -159,6 +176,7 @@ namespace VRM
{
SkinnedMeshRenderer = skinnedMeshRenderer,
Mesh = new Mesh(), // for bake
BlendShapeCount = skinnedMeshRenderer.sharedMesh.blendShapeCount,
Materials = skinnedMeshRenderer.sharedMaterials
};
}
@@ -195,6 +213,17 @@ namespace VRM
get { return m_skinnedMeshRendererPathList; }
}
Dictionary<int, string[]> m_blendShapeNameMap = new Dictionary<int, string[]>();
public string[] GetBlendShapeNames(int skinnedMeshIndex)
{
string[] names = null;
if(m_blendShapeNameMap.TryGetValue(skinnedMeshIndex, out names))
{
return names;
}
return null;
}
Bounds m_bounds;
public void Bake()
{