mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-23 02:55:07 -05:00
implement Material Morph in/out
This commit is contained in:
@@ -19,7 +19,6 @@ namespace VRM
|
||||
|
||||
if (m_target.BlendShapeAvatar != null)
|
||||
{
|
||||
|
||||
m_sliders = m_target.BlendShapeAvatar.Clips
|
||||
.Where(x => x != null)
|
||||
.Select(x => new BlendShapeSlider(m_target, BlendShapeKey.CreateFrom(x)))
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace VRM
|
||||
if (materialValues != null && m_materialMap != null)
|
||||
{
|
||||
// clear
|
||||
Debug.LogFormat("clear material");
|
||||
//Debug.LogFormat("clear material");
|
||||
foreach (var kv in m_materialMap)
|
||||
{
|
||||
foreach (var _kv in kv.Value.PropMap)
|
||||
@@ -218,7 +218,7 @@ namespace VRM
|
||||
MaterialItem item;
|
||||
if (m_materialMap.TryGetValue(x.MaterialName, out item))
|
||||
{
|
||||
Debug.Log("set material");
|
||||
//Debug.Log("set material");
|
||||
PropItem prop;
|
||||
if (item.PropMap.TryGetValue(x.ValueName, out prop))
|
||||
{
|
||||
|
||||
@@ -318,13 +318,33 @@ namespace VRM
|
||||
var relativePath = UniGLTF.UnityExtensions.RelativePathFrom(node, context.Root.transform);
|
||||
return new BlendShapeBinding
|
||||
{
|
||||
//Name = name,
|
||||
RelativePath = relativePath,
|
||||
Index = x.index,
|
||||
Weight = x.weight,
|
||||
};
|
||||
})
|
||||
.ToArray();
|
||||
asset.MaterialValues = group.materialValues.Select(x =>
|
||||
{
|
||||
var value = new Vector4();
|
||||
for(int i=0; i<x.targetValue.Length; ++i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0: value.x = x.targetValue[0]; break;
|
||||
case 1: value.y = x.targetValue[1]; break;
|
||||
case 2: value.z = x.targetValue[2]; break;
|
||||
case 3: value.w = x.targetValue[3]; break;
|
||||
}
|
||||
}
|
||||
return new MaterialValueBinding
|
||||
{
|
||||
MaterialName = x.materialName,
|
||||
ValueName = x.propertyName,
|
||||
TargetValue = value
|
||||
};
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
return asset;
|
||||
|
||||
@@ -7,9 +7,21 @@ using UnityEngine;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
/// <summary>
|
||||
/// BlendShapeBind
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class glTF_VRM_MaterialValueBind : UniGLTF.JsonSerializableBase
|
||||
{
|
||||
public string materialName;
|
||||
public string propertyName;
|
||||
public float[] targetValue;
|
||||
|
||||
protected override void SerializeMembers(JsonFormatter f)
|
||||
{
|
||||
f.KeyValue(() => materialName);
|
||||
f.KeyValue(() => propertyName);
|
||||
f.KeyValue(() => targetValue);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class glTF_VRM_BlendShapeBind : UniGLTF.JsonSerializableBase
|
||||
{
|
||||
@@ -75,22 +87,15 @@ namespace VRM
|
||||
{
|
||||
public string name;
|
||||
public string presetName;
|
||||
[Obsolete]
|
||||
public string extendedName;
|
||||
public List<glTF_VRM_BlendShapeBind> binds = new List<glTF_VRM_BlendShapeBind>();
|
||||
public List<glTF_VRM_MaterialValueBind> materialValues = new List<glTF_VRM_MaterialValueBind>();
|
||||
|
||||
protected override void SerializeMembers(JsonFormatter f)
|
||||
{
|
||||
f.KeyValue(() => name);
|
||||
f.KeyValue(() => presetName);
|
||||
/*
|
||||
if (name == "extended")
|
||||
{
|
||||
f.KeyValue(() => extendedName);
|
||||
}
|
||||
f.Key("flags"); f.Value((int)flags);
|
||||
*/
|
||||
f.KeyValue(() => binds);
|
||||
f.KeyValue(() => materialValues);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,11 +111,24 @@ namespace VRM
|
||||
{
|
||||
list.AddRange(clip.Values.Select(y => glTF_VRM_BlendShapeBind.Cerate(transform, meshes.ToList(), y)));
|
||||
}
|
||||
|
||||
var materialList = new List<glTF_VRM_MaterialValueBind>();
|
||||
if (clip.MaterialValues != null)
|
||||
{
|
||||
materialList.AddRange(clip.MaterialValues.Select(y => new glTF_VRM_MaterialValueBind
|
||||
{
|
||||
materialName = y.MaterialName,
|
||||
propertyName = y.ValueName,
|
||||
targetValue = y.TargetValue.ToArray(),
|
||||
}));
|
||||
}
|
||||
|
||||
var group = new glTF_VRM_BlendShapeGroup
|
||||
{
|
||||
name = clip.BlendShapeName,
|
||||
presetName = clip.Preset.ToString().ToLower(),
|
||||
binds = list,
|
||||
materialValues = materialList,
|
||||
};
|
||||
blendShapeGroups.Add(group);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user