-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
ComponentInfos.VRM0.cs
154 lines (133 loc) · 6.12 KB
/
ComponentInfos.VRM0.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#if AAO_VRM0
using System.Linq;
using Anatawa12.AvatarOptimizer.API;
using UnityEngine;
using VRM;
namespace Anatawa12.AvatarOptimizer.APIInternal
{
// NOTE: VRM0 bones are not animated, therefore no need to configure ComponentDependencyInfo
[ComponentInformation(typeof(VRMMeta))]
internal class VRMMetaInformation : ComponentInformation<VRMMeta>
{
protected override void CollectDependency(VRMMeta component, ComponentDependencyCollector collector)
{
collector.MarkEntrypoint();
if (component.TryGetComponent<Animator>(out var animator)) collector.AddDependency(animator);
}
}
[ComponentInformation(typeof(VRMSpringBone))]
internal class VRMSpringBoneInformation : ComponentInformation<VRMSpringBone>
{
protected override void CollectDependency(VRMSpringBone component, ComponentDependencyCollector collector)
{
collector.MarkHeavyBehaviour();
foreach (var rootBone in component.RootBones)
{
foreach (var transform in rootBone.GetComponentsInChildren<Transform>())
{
collector.AddDependency(transform, component);
collector.AddDependency(transform);
}
}
foreach (var collider in component.ColliderGroups) collector.AddDependency(collider);
}
protected override void CollectMutations(VRMSpringBone component, ComponentMutationsCollector collector)
{
foreach (var transform in component.GetComponentsInChildren<Transform>())
collector.TransformPositionAndRotation(transform);
}
}
[ComponentInformation(typeof(VRMSpringBoneColliderGroup))]
internal class VRMSpringBoneColliderGroupInformation : ComponentInformation<VRMSpringBoneColliderGroup>
{
protected override void CollectDependency(VRMSpringBoneColliderGroup component,
ComponentDependencyCollector collector)
{
}
}
[ComponentInformation(typeof(VRMBlendShapeProxy))]
internal class VRMBlendShapeProxyInformation : ComponentInformation<VRMBlendShapeProxy>
{
protected override void CollectDependency(VRMBlendShapeProxy component, ComponentDependencyCollector collector)
{
if (component.BlendShapeAvatar) collector.MarkEntrypoint();
}
// BlendShape / Material mutations are collected through AnimatorParser, once we start tracking material changes
}
[ComponentInformation(typeof(VRMLookAtHead))]
internal class VRMLookAtHeadInformation : ComponentInformation<VRMLookAtHead>
{
protected override void CollectDependency(VRMLookAtHead component, ComponentDependencyCollector collector)
{
collector.MarkHeavyBehaviour();
collector.AddDependency(component.Head, component);
collector.AddDependency(component.Head);
}
}
[ComponentInformation(typeof(VRMLookAtBoneApplyer))]
internal class VRMLookAtBoneApplyerInformation : ComponentInformation<VRMLookAtBoneApplyer>
{
protected override void CollectDependency(VRMLookAtBoneApplyer component, ComponentDependencyCollector collector)
{
collector.MarkHeavyBehaviour();
collector.AddDependency(component.GetComponent<VRMLookAtHead>());
collector.AddDependency(component.LeftEye.Transform);
collector.AddDependency(component.RightEye.Transform);
}
protected override void CollectMutations(VRMLookAtBoneApplyer component, ComponentMutationsCollector collector)
{
collector.TransformRotation(component.LeftEye.Transform);
collector.TransformRotation(component.RightEye.Transform);
}
}
[ComponentInformation(typeof(VRMLookAtBlendShapeApplyer))]
internal class VRMLookAtBlendShapeApplyerInformation : ComponentInformation<VRMLookAtBlendShapeApplyer>
{
protected override void CollectDependency(VRMLookAtBlendShapeApplyer component, ComponentDependencyCollector collector)
{
collector.MarkHeavyBehaviour();
collector.AddDependency(component.GetComponent<VRMLookAtHead>());
}
}
[ComponentInformation(typeof(VRMFirstPerson))]
internal class VRMFirstPersonInformation : ComponentInformation<VRMFirstPerson>
{
protected override void CollectDependency(VRMFirstPerson component, ComponentDependencyCollector collector)
{
collector.MarkHeavyBehaviour();
collector.AddDependency(component.FirstPersonBone, component);
collector.AddDependency(component.FirstPersonBone);
}
protected override void ApplySpecialMapping(VRMFirstPerson component, MappingSource mappingSource)
{
component.Renderers = component.Renderers
.Select(r => new VRMFirstPerson.RendererFirstPersonFlags
{
Renderer = mappingSource.GetMappedComponent(r.Renderer).MappedComponent,
FirstPersonFlag = r.FirstPersonFlag
})
.Where(r => r.Renderer)
.GroupBy(r => r.Renderer, r => r.FirstPersonFlag)
.Select(grouping =>
{
FirstPersonFlag mergedFirstPersonFlag;
var firstPersonFlags = grouping.Distinct().ToArray();
if (firstPersonFlags.Length == 1)
{
mergedFirstPersonFlag = firstPersonFlags[0];
}
else
{
mergedFirstPersonFlag = firstPersonFlags.Contains(FirstPersonFlag.Both) ? FirstPersonFlag.Both : FirstPersonFlag.Auto;
BuildLog.LogWarning("MergeSkinnedMesh:warning:VRM:FirstPersonFlagsMismatch", mergedFirstPersonFlag.ToString());
}
return new VRMFirstPerson.RendererFirstPersonFlags
{
Renderer = grouping.Key,
FirstPersonFlag = mergedFirstPersonFlag
};
}).ToList();
}
}
}
#endif