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

[1.0] preview の MaterialUVBindings 動作を修正 #1226

Merged
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 @@ -10,7 +10,6 @@ namespace UniVRM10
///
internal sealed class MaterialValueBindingMerger
{
public const string UV_PROPERTY = "_MainTex_ST";
public const string COLOR_PROPERTY = "_Color";
public const string EMISSION_COLOR_PROPERTY = "_EmissionColor";
public const string RIM_COLOR_PROPERTY = "_RimColor";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,12 @@ public void Bake(VRM10Expression bake, float weight)
if (m_materialMap != null)
{
// clear
//Debug.LogFormat("clear material");
foreach (var kv in m_materialMap)
{
foreach (var _kv in kv.Value.PropMap)
{
// var prop = VrmLib.MaterialBindTypeExtensions.GetProperty(_kv.Key);
kv.Value.Material.SetColor(_kv.Value.Name, _kv.Value.DefaultValues);
}

// clear UV
kv.Value.Material.SetVector("_MainTex_ST", new Vector4(1, 1, 0, 0));
kv.Value.Clear();
}

// color
if (bake.MaterialColorBindings != null)
{
foreach (var x in bake.MaterialColorBindings)
Expand Down Expand Up @@ -274,24 +267,15 @@ public void Bake(VRM10Expression bake, float weight)
}
}

// uv
if (bake.MaterialUVBindings != null)
{
foreach (var x in bake.MaterialUVBindings)
{
PreviewMaterialItem item;
if (m_materialMap.TryGetValue(x.MaterialName, out item))
{
// var valueName = x.ValueName;
// if (valueName.EndsWith("_ST_S")
// || valueName.EndsWith("_ST_T"))
// {
// valueName = valueName.Substring(0, valueName.Length - 2);
// }

var value = item.Material.GetVector("_MainTex_ST");
//Debug.LogFormat("{0} => {1}", valueName, x.TargetValue);
value += ((x.ScalingOffset - new Vector4(1, 1, 0, 0)) * weight);
item.Material.SetColor("_MainTex_ST", value);
item.AddScaleOffset(x.ScalingOffset, weight);
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions Assets/VRM10/Runtime/Components/Expression/PreviewMaterialItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,33 @@ public static MaterialColorType GetBindType(string property)

throw new NotImplementedException();
}

/// <summary>
/// [Preview] 積算する前の初期値にクリアする
/// </summary>
public void Clear()
{
// clear Color
foreach (var _kv in PropMap)
{
Material.SetColor(_kv.Value.Name, _kv.Value.DefaultValues);
}

// clear UV
Material.SetVector(UV_PROPERTY, DefaultUVScaleOffset);
}

/// <summary>
/// [Preview] scaleOffset を weight で重みを付けて加える
/// </summary>
/// <param name="scaleOffset"></param>
/// <param name="weight"></param>
public void AddScaleOffset(Vector4 scaleOffset, float weight)
{
var value = Material.GetVector(UV_PROPERTY);
//Debug.LogFormat("{0} => {1}", valueName, x.TargetValue);
value += (scaleOffset - DefaultUVScaleOffset) * weight;
Material.SetColor(UV_PROPERTY, value);
}
}
}