mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2024-12-29 18:55:06 +08:00
wip: remove vert color
This commit is contained in:
parent
d538551fad
commit
f7df59adc1
@ -88,6 +88,7 @@ namespace nadena.dev.modular_avatar.core.editor.plugin
|
||||
var maContext = ctx.Extension<ModularAvatarContext>().BuildContext;
|
||||
FixupExpressionsMenuPass.FixupExpressionsMenu(maContext);
|
||||
});
|
||||
seq.Run(RemoveVertexColorPass.Instance);
|
||||
#endif
|
||||
seq.Run(RebindHumanoidAvatarPass.Instance);
|
||||
seq.Run("Purge ModularAvatar components", ctx =>
|
||||
|
87
Editor/RemoveVertexColorPass.cs
Normal file
87
Editor/RemoveVertexColorPass.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using nadena.dev.ndmf;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace nadena.dev.modular_avatar.core.editor
|
||||
{
|
||||
internal class RemoveVertexColorPass : Pass<RemoveVertexColorPass>
|
||||
{
|
||||
protected override void Execute(ndmf.BuildContext context)
|
||||
{
|
||||
var removers = context.AvatarRootTransform.GetComponentsInChildren<ModularAvatarRemoveVertexColor>(true);
|
||||
|
||||
Dictionary<Mesh, Mesh> conversionMap = new();
|
||||
|
||||
foreach (var remover in removers)
|
||||
{
|
||||
foreach (var smr in remover.GetComponentsInChildren<SkinnedMeshRenderer>(true))
|
||||
{
|
||||
TryRemove(context, smr, conversionMap);
|
||||
}
|
||||
|
||||
foreach (var mf in remover.GetComponentsInChildren<MeshFilter>(true))
|
||||
{
|
||||
TryRemove(context, mf, conversionMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const string PROP_PATH = "m_Mesh";
|
||||
|
||||
private void TryRemove(ndmf.BuildContext context, Component c, Dictionary<Mesh, Mesh> conversionMap)
|
||||
{
|
||||
SerializedObject obj;
|
||||
SerializedProperty prop;
|
||||
|
||||
if (c is SkinnedMeshRenderer smr)
|
||||
{
|
||||
obj = new SerializedObject(smr);
|
||||
prop = obj.FindProperty(PROP_PATH);
|
||||
} else if (c is MeshFilter mf)
|
||||
{
|
||||
obj = new SerializedObject(mf);
|
||||
prop = obj.FindProperty(PROP_PATH);
|
||||
} else
|
||||
{
|
||||
//Debug.LogWarning($"Could not find a mesh to remove vertex colors from on {remover.name}");
|
||||
// TODO: warning
|
||||
return;
|
||||
}
|
||||
|
||||
var mesh = prop.objectReferenceValue as Mesh;
|
||||
Mesh originalMesh = mesh;
|
||||
if (mesh == null)
|
||||
{
|
||||
// TODO: warning;
|
||||
return;
|
||||
}
|
||||
|
||||
if (conversionMap.TryGetValue(mesh, out var converted))
|
||||
{
|
||||
prop.objectReferenceValue = converted;
|
||||
obj.ApplyModifiedPropertiesWithoutUndo();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mesh.GetVertexAttributes().All(va => va.attribute != VertexAttribute.Color))
|
||||
{
|
||||
// no-op
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.IsTemporaryAsset(mesh))
|
||||
{
|
||||
mesh = UnityEngine.Object.Instantiate(mesh);
|
||||
prop.objectReferenceValue = mesh;
|
||||
obj.ApplyModifiedPropertiesWithoutUndo();
|
||||
}
|
||||
|
||||
mesh.colors = null;
|
||||
|
||||
conversionMap[originalMesh] = mesh;
|
||||
}
|
||||
}
|
||||
}
|
3
Editor/RemoveVertexColorPass.cs.meta
Normal file
3
Editor/RemoveVertexColorPass.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a227da6f9f1548c3867b1ed113f28e9d
|
||||
timeCreated: 1733008734
|
12
Runtime/RemoveVertexColor.cs
Normal file
12
Runtime/RemoveVertexColor.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace nadena.dev.modular_avatar.core
|
||||
{
|
||||
[AddComponentMenu("Modular Avatar/MA Remove Vertex Color")]
|
||||
[DisallowMultipleComponent]
|
||||
[HelpURL("https://modular-avatar.nadena.dev/docs/reference/remove-vertex-color?lang=auto")]
|
||||
public class ModularAvatarRemoveVertexColor : AvatarTagComponent
|
||||
{
|
||||
|
||||
}
|
||||
}
|
3
Runtime/RemoveVertexColor.cs.meta
Normal file
3
Runtime/RemoveVertexColor.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc5f8bfae24244aeaedcd6c2bb7264f9
|
||||
timeCreated: 1733008656
|
Loading…
Reference in New Issue
Block a user