Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ public static bool UVProp(Rect rect, SerializedProperty prop)
}
}

public static bool Vec3Prop(Rect rect, SerializedProperty prop)
{
var oldValue = prop.vector3Value;
var newValue = EditorGUI.Vector3Field(rect, prop.displayName, oldValue);
if (newValue != oldValue)
{
prop.vector3Value = newValue;
return true;
}
else
{
return false;
}
}

static Rect AdvanceRect(ref float x, float y, float w, float h)
{
var rect = new Rect(x, y, w, h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public Texture Render(Rect r, GUIStyle background, PreviewSceneManager scene,
int subMeshCount = item.Mesh.subMeshCount;
for (int i = 0; i < subMeshCount; i++)
{
if (item.SkinnedMeshRenderer != null)
{
item.SkinnedMeshRenderer.BakeMesh(item.Mesh);
}
m_previewUtility.DrawMesh(item.Mesh,
item.Position, item.Rotation,
item.Materials[i], i);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;


namespace UniVRM10
{
public class ReorderableNodeTransformBindingList
{
ReorderableList m_ValuesList;
SerializedProperty m_valuesProp;
bool m_changed;

public ReorderableNodeTransformBindingList(SerializedObject serializedObject, PreviewSceneManager previewSceneManager, int height)
{
m_valuesProp = serializedObject.FindProperty(nameof(VRM10Expression.NodeTransformBindings));
m_ValuesList = new ReorderableList(serializedObject, m_valuesProp);
m_ValuesList.elementHeight = height * 4;
m_ValuesList.drawElementCallback =
(rect, index, isActive, isFocused) =>
{
var element = m_valuesProp.GetArrayElementAtIndex(index);
rect.height -= 4;
rect.y += 2;
if (DrawNodeTransformBinding(rect, element, previewSceneManager, height))
{
m_changed = true;
}
};
}

///
/// NodeTransform List のElement描画
///
static bool DrawNodeTransformBinding(Rect position, SerializedProperty property,
PreviewSceneManager scene, int height)
{
bool changed = false;
if (scene != null)
{
var y = position.y;
var rect = new Rect(position.x, y, position.width, height);
int pathIndex;
if (ExpressionEditorHelper.StringPopup(rect, property.FindPropertyRelative(nameof(NodeTransformBinding.RelativePath)), scene.NodeTransformPathList, out pathIndex))
{
changed = true;
}

// T`
y += height;
rect = new Rect(position.x, y, position.width, height);
if (ExpressionEditorHelper.Vec3Prop(rect, property.FindPropertyRelative(nameof(NodeTransformBinding.OffsetTranslation))))
{
changed = true;
}

// R
y += height;
rect = new Rect(position.x, y, position.width, height);
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(rect, property.FindPropertyRelative(nameof(NodeTransformBinding.OffsetRotation)));
if (EditorGUI.EndChangeCheck())
{
changed = true;
}

// S
y += height;
rect = new Rect(position.x, y, position.width, height);
if (ExpressionEditorHelper.Vec3Prop(rect, property.FindPropertyRelative(nameof(NodeTransformBinding.TargetScale))))
{
changed = true;
}
}
return changed;
}

public void SetValues(NodeTransformBinding[] bindings)
{
m_valuesProp.ClearArray();
m_valuesProp.arraySize = bindings.Length;
for (int i = 0; i < bindings.Length; ++i)
{
var item = m_valuesProp.GetArrayElementAtIndex(i);

var endProperty = item.GetEndProperty();
while (item.NextVisible(true))
{
if (SerializedProperty.EqualContents(item, endProperty))
{
break;
}

switch (item.name)
{
case nameof(NodeTransformBinding.RelativePath):
item.stringValue = bindings[i].RelativePath;
break;

case nameof(NodeTransformBinding.OffsetTranslation):
item.vector3Value = bindings[i].OffsetTranslation;
break;

case nameof(NodeTransformBinding.OffsetRotation):
item.quaternionValue = bindings[i].OffsetRotation;
break;

case nameof(NodeTransformBinding.TargetScale):
item.vector3Value = bindings[i].TargetScale;
break;

default:
throw new Exception();
}
}
}

}

public bool Draw(string label)
{
m_changed = false;
m_ValuesList.DoLayoutList();
if (GUILayout.Button($"Clear {label}"))
{
m_changed = true;
m_valuesProp.arraySize = 0;
}
return m_changed;
}
}
}

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,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
Expand Down Expand Up @@ -28,21 +29,24 @@ public class SerializedExpressionEditor
ReorderableMorphTargetBindingList m_morphTargetBindings;
ReorderableMaterialColorBindingList m_materialColorBindings;
ReorderableMaterialUVBindingList m_materialUVBindings;

ReorderableNodeTransformBindingList m_nodeTransformBindings;
#region Editor values

bool m_changed;

static int s_Mode;
static bool s_MorphTargetFoldout = true;
static bool s_OptionFoldout;
static bool s_ListFoldout;

static string[] MODES = new[]{
"MorphTarget",
"Material Color",
"Texture Transform"
};
enum ListMode
{
MorphTarget,
MaterialColor,
TextureTransform,
NodeTransform,
}
static ListMode s_Mode;
static string[] MODES = ((ListMode[])Enum.GetValues(typeof(ListMode))).Select(x => x.ToString()).ToArray();

PreviewMeshItem[] m_items;
#endregion
Expand Down Expand Up @@ -71,6 +75,7 @@ public SerializedExpressionEditor(SerializedObject serializedObject, VRM10Expres
m_morphTargetBindings = new ReorderableMorphTargetBindingList(serializedObject, previewSceneManager, 20);
m_materialColorBindings = new ReorderableMaterialColorBindingList(serializedObject, previewSceneManager?.MaterialNames, 20);
m_materialUVBindings = new ReorderableMaterialUVBindingList(serializedObject, previewSceneManager?.MaterialNames, 20);
m_nodeTransformBindings = new ReorderableNodeTransformBindingList(serializedObject, previewSceneManager, 20);

m_items = previewSceneManager.EnumRenderItems
.Where(x => x.SkinnedMeshRenderer != null)
Expand Down Expand Up @@ -109,33 +114,39 @@ public bool Draw(out VRM10Expression bakeValue)
if (s_ListFoldout)
{
EditorGUI.indentLevel++;
s_Mode = GUILayout.Toolbar(s_Mode, MODES);
s_Mode = (ListMode)GUILayout.Toolbar((int)s_Mode, MODES);
switch (s_Mode)
{
case 0:
// MorphTarget
case ListMode.MorphTarget:
{
if (m_morphTargetBindings.Draw(s_Mode.ToString()))
{
m_changed = true;
}
}
break;

case ListMode.MaterialColor:
{
if (m_morphTargetBindings.Draw("MorphTarget"))
if (m_materialColorBindings.Draw(s_Mode.ToString()))
{
m_changed = true;
}
}
break;

case 1:
// Material
case ListMode.TextureTransform:
{
if (m_materialColorBindings.Draw("MaterialColor"))
if (m_materialUVBindings.Draw(s_Mode.ToString()))
{
m_changed = true;
}
}
break;

case 2:
// TextureTransform
case ListMode.NodeTransform:
{
if (m_materialUVBindings.Draw("TextureTransform"))
if (m_nodeTransformBindings.Draw(s_Mode.ToString()))
{
m_changed = true;
}
Expand Down
11 changes: 10 additions & 1 deletion Packages/VRM10/Editor/Vrm10SerializerGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public GenerateInfo(string jsonSchema, string formatDir) : this(jsonSchema, form

private const string Vrm10SpecDir = "vrm-specification/specification";
private const string Vrm10FormatGeneratedDir = "Packages/VRM10/Runtime/Format";
private const string UniGltfFormatGeneratedDir = "Packages/UniGLTF/Runtime/UniGLTF/Format";

public static void Run(bool debug)
{
Expand All @@ -48,7 +49,7 @@ public static void Run(bool debug)
// VRMC_hdr_emissiveMultiplier
new GenerateInfo(
$"{Vrm10SpecDir}/VRMC_materials_hdr_emissiveMultiplier-1.0/schema/VRMC_materials_hdr_emissiveMultiplier.json",
"Assets/UniGLTF/Runtime/UniGLTF/Format/ExtensionsAndExtras/EmissiveMultiplier"
$"{UniGltfFormatGeneratedDir}/ExtensionsAndExtras/EmissiveMultiplier"
),

// VRMC_vrm
Expand Down Expand Up @@ -94,6 +95,14 @@ public static void Run(bool debug)
$"{Vrm10SpecDir}/VRMC_springBone_limit-1.0/schema/VRMC_springBone_limit.schema.json",
$"{Vrm10FormatGeneratedDir}/SpringBoneLimit"
),

// VRMC_vrm_expressions_node_transform-1.0
// (experimental)
// https://github.com/ousttrue/vrm-specification/tree/VRMC_vrm_expression_joint
new GenerateInfo(
$"{Vrm10SpecDir}/VRMC_vrm_expressions_node_transform-1.0/schema/VRMC_vrm_expressions_node_transform.schema.json",
$"{Vrm10FormatGeneratedDir}/ExpressionsNodeTransform"
),
};

foreach (var arg in args)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UniGLTF.Utils;
using UnityEngine;

namespace UniVRM10
Expand All @@ -23,9 +24,13 @@ internal sealed class ExpressionMerger : IDisposable

MorphTargetBindingMerger m_morphTargetBindingMerger;
MaterialValueBindingMerger m_materialValueBindingMerger;
NodeTransformBindingMerger m_boneTransformBindingMerger;


public ExpressionMerger(VRM10ObjectExpression expressions, Transform root, bool isPrefabInstance)
public ExpressionMerger(VRM10ObjectExpression expressions,
Transform root,
bool isPrefabInstance,
IReadOnlyDictionary<Transform, TransformState> initPose)
{
m_clipMap = expressions.Clips.ToDictionary(
x => expressions.CreateKey(x.Clip),
Expand All @@ -35,6 +40,7 @@ public ExpressionMerger(VRM10ObjectExpression expressions, Transform root, bool
m_valueMap = new Dictionary<ExpressionKey, float>(ExpressionKey.Comparer);
m_morphTargetBindingMerger = new MorphTargetBindingMerger(m_clipMap, root);
m_materialValueBindingMerger = new MaterialValueBindingMerger(m_clipMap, root, isPrefabInstance);
m_boneTransformBindingMerger = new NodeTransformBindingMerger(m_clipMap, root, initPose);
}

/// <summary>
Expand All @@ -50,6 +56,7 @@ public void SetValues(Dictionary<ExpressionKey, float> expressionWeights)

m_morphTargetBindingMerger.Apply();
m_materialValueBindingMerger.Apply();
m_boneTransformBindingMerger.Apply();
Comment thread
ousttrue marked this conversation as resolved.
}

private void AccumulateValue(ExpressionKey key, float value)
Expand All @@ -69,6 +76,7 @@ private void AccumulateValue(ExpressionKey key, float value)

m_morphTargetBindingMerger.AccumulateValue(key, value);
m_materialValueBindingMerger.AccumulateValue(clip, value);
m_boneTransformBindingMerger.AccumulateValue(key, value);
}

public void Dispose()
Expand Down
Loading