mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 06:19:47 -05:00
2tabに変更
This commit is contained in:
parent
c4fbd485ed
commit
18dccde65e
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
|
@ -6,9 +7,14 @@ namespace UniGLTF.MeshUtility
|
|||
{
|
||||
public class MeshIntegrator
|
||||
{
|
||||
private MeshIntegrator()
|
||||
public enum BlendShapeOperation
|
||||
{
|
||||
|
||||
// No BlendShape(drop if mesh has blendshape)
|
||||
None,
|
||||
// Use blendShape(keep blendshape)
|
||||
Use,
|
||||
// Integrate to two mesh that is with blendShape and is without blendshape
|
||||
Split,
|
||||
}
|
||||
|
||||
struct SubMesh
|
||||
|
|
@ -233,7 +239,7 @@ namespace UniGLTF.MeshUtility
|
|||
}
|
||||
}
|
||||
|
||||
public static MeshIntegrationResult Integrate(MeshIntegrationGroup group, bool useBlendShape)
|
||||
public static MeshIntegrationResult Integrate(MeshIntegrationGroup group, BlendShapeOperation op)
|
||||
{
|
||||
var integrator = new MeshUtility.MeshIntegrator();
|
||||
foreach (var x in group.Renderers)
|
||||
|
|
@ -247,11 +253,16 @@ namespace UniGLTF.MeshUtility
|
|||
integrator.Push(mr);
|
||||
}
|
||||
}
|
||||
return integrator.Integrate(group.Name, useBlendShape);
|
||||
return integrator.Integrate(group.Name, op);
|
||||
}
|
||||
|
||||
public MeshIntegrationResult Integrate(string name, bool useBlendShape)
|
||||
public MeshIntegrationResult Integrate(string name, BlendShapeOperation op)
|
||||
{
|
||||
if (op == BlendShapeOperation.Split)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
var mesh = new Mesh();
|
||||
|
||||
if (Positions.Count > ushort.MaxValue)
|
||||
|
|
@ -271,7 +282,7 @@ namespace UniGLTF.MeshUtility
|
|||
mesh.SetIndices(SubMeshes[i].Indices.ToArray(), MeshTopology.Triangles, i);
|
||||
}
|
||||
mesh.bindposes = BindPoses.ToArray();
|
||||
if (useBlendShape)
|
||||
if (op == BlendShapeOperation.Use)
|
||||
{
|
||||
AddBlendShapesToMesh(mesh);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,9 @@ namespace UniGLTF.MeshUtility
|
|||
}
|
||||
}
|
||||
|
||||
return MeshIntegrator.Integrate(group, useBlendShape);
|
||||
return MeshIntegrator.Integrate(group, useBlendShape
|
||||
? MeshIntegrator.BlendShapeOperation.Use
|
||||
: MeshIntegrator.BlendShapeOperation.None);
|
||||
}
|
||||
|
||||
public static IEnumerable<SkinnedMeshRenderer> EnumerateSkinnedMeshRenderer(Transform root, MeshEnumerateOption hasBlendShape)
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@ namespace UniVRM10
|
|||
const string TITLE = "Vrm10 Mesh Utility Window";
|
||||
enum Tabs
|
||||
{
|
||||
MeshFreeze,
|
||||
MeshIntegration,
|
||||
MeshSplitter,
|
||||
Freeze,
|
||||
IntegrateSplit,
|
||||
}
|
||||
Tabs _tab;
|
||||
|
||||
|
|
@ -78,7 +77,7 @@ namespace UniVRM10
|
|||
|
||||
switch (_tab)
|
||||
{
|
||||
case Tabs.MeshFreeze:
|
||||
case Tabs.Freeze:
|
||||
{
|
||||
if (MeshFreezeGui())
|
||||
{
|
||||
|
|
@ -87,7 +86,7 @@ namespace UniVRM10
|
|||
break;
|
||||
}
|
||||
|
||||
case Tabs.MeshIntegration:
|
||||
case Tabs.IntegrateSplit:
|
||||
{
|
||||
if (MeshIntegrateGui())
|
||||
{
|
||||
|
|
@ -95,15 +94,6 @@ namespace UniVRM10
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Tabs.MeshSplitter:
|
||||
{
|
||||
if (MeshSplitGui())
|
||||
{
|
||||
modified = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndScrollView();
|
||||
|
||||
|
|
@ -147,6 +137,7 @@ namespace UniVRM10
|
|||
bool MeshIntegrateGui()
|
||||
{
|
||||
var firstPerson = ToggleIsModified("FirstPerson == AUTO の生成", ref _meshUtility.GenerateMeshForFirstPersonAuto);
|
||||
var split = ToggleIsModified("Separate by BlendShape", ref _meshUtility.SplitByBlendShape);
|
||||
var p = position;
|
||||
var last = GUILayoutUtility.GetLastRect();
|
||||
var y = last.y + last.height;
|
||||
|
|
@ -160,12 +151,7 @@ namespace UniVRM10
|
|||
- 30
|
||||
};
|
||||
var mod = _meshIntegration.OnGui(rect);
|
||||
return firstPerson || mod;
|
||||
}
|
||||
|
||||
bool MeshSplitGui()
|
||||
{
|
||||
return ToggleIsModified("Separate by BlendShape", ref _meshUtility.SplitByBlendShape);
|
||||
return firstPerson || split || mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniGLTF;
|
||||
using UniGLTF.MeshUtility;
|
||||
using UniHumanoid;
|
||||
using UnityEngine;
|
||||
|
|
@ -117,56 +118,98 @@ namespace UniVRM10
|
|||
}
|
||||
}
|
||||
|
||||
public void Process(GameObject go)
|
||||
void RemoveComponent<T>(T c) where T : Component
|
||||
{
|
||||
// TODO: UNDO
|
||||
|
||||
if (ForceUniqueName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// 正規化されたヒエラルキーを作る
|
||||
var (normalized, boneMap) = BoneNormalizer.NormalizeHierarchyFreezeMesh(go,
|
||||
removeScaling: FreezeScaling,
|
||||
removeRotation: FreezeRotation,
|
||||
freezeBlendShape: FreezeBlendShape);
|
||||
|
||||
// TODO: update: spring
|
||||
// TODO: update: constraint
|
||||
// TODO: update: firstPoint offset
|
||||
// write back normalized transform to boneMap
|
||||
BoneNormalizer.WriteBackResult(go, normalized, boneMap);
|
||||
var t = c.transform;
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
GameObject.Destroy(normalized);
|
||||
GameObject.Destroy(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject.DestroyImmediate(normalized);
|
||||
GameObject.DestroyImmediate(c);
|
||||
}
|
||||
|
||||
var animator = go.GetComponent<Animator>();
|
||||
var newAvatar = AvatarDescription.RecreateAvatar(animator);
|
||||
animator.avatar = newAvatar;
|
||||
|
||||
// TODO: integration
|
||||
foreach (var group in MeshIntegrationGroups)
|
||||
if (t.childCount == 0)
|
||||
{
|
||||
var result = MeshIntegrator.Integrate(group, true);
|
||||
// TODO: firstperson
|
||||
|
||||
// TODO: split
|
||||
if (SplitByBlendShape)
|
||||
var list = t.GetComponents<Component>();
|
||||
// Debug.Log($"{list[0].GetType().Name}");
|
||||
if (list.Length == 1 && list[0] == t)
|
||||
{
|
||||
// var withBlendShape, withoutBlendShape
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
GameObject.Destroy(t.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject.DestroyImmediate(t.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Process(GameObject go)
|
||||
{
|
||||
// TODO unpack prefab
|
||||
|
||||
if (ForceUniqueName)
|
||||
{
|
||||
// TODO: UNDO
|
||||
throw new NotImplementedException();
|
||||
|
||||
// 必用?
|
||||
var animator = go.GetComponent<Animator>();
|
||||
var newAvatar = AvatarDescription.RecreateAvatar(animator);
|
||||
animator.avatar = newAvatar;
|
||||
}
|
||||
|
||||
// 正規化されたヒエラルキーを作る
|
||||
if (FreezeBlendShape || FreezeRotation || FreezeScaling)
|
||||
{
|
||||
// TODO: UNDO
|
||||
var (normalized, boneMap) = BoneNormalizer.NormalizeHierarchyFreezeMesh(go,
|
||||
removeScaling: FreezeScaling,
|
||||
removeRotation: FreezeRotation,
|
||||
freezeBlendShape: FreezeBlendShape);
|
||||
|
||||
// TODO: update: spring
|
||||
// TODO: update: constraint
|
||||
// TODO: update: firstPoint offset
|
||||
// write back normalized transform to boneMap
|
||||
BoneNormalizer.WriteBackResult(go, normalized, boneMap);
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
GameObject.Destroy(normalized);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject.DestroyImmediate(normalized);
|
||||
}
|
||||
|
||||
// TODO: remove old renderer
|
||||
result.AddIntegratedRendererTo(go);
|
||||
var animator = go.GetComponent<Animator>();
|
||||
var newAvatar = AvatarDescription.RecreateAvatar(animator);
|
||||
animator.avatar = newAvatar;
|
||||
}
|
||||
|
||||
{
|
||||
// TODO: UNDO
|
||||
foreach (var group in MeshIntegrationGroups)
|
||||
{
|
||||
var result = MeshIntegrator.Integrate(group, SplitByBlendShape
|
||||
? MeshIntegrator.BlendShapeOperation.Split
|
||||
: MeshIntegrator.BlendShapeOperation.None);
|
||||
|
||||
foreach (var r in result.SourceMeshRenderers)
|
||||
{
|
||||
RemoveComponent(r);
|
||||
}
|
||||
foreach (var r in result.SourceSkinnedMeshRenderers)
|
||||
{
|
||||
RemoveComponent(r);
|
||||
}
|
||||
|
||||
result.AddIntegratedRendererTo(go);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user