mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-06-02 22:14:30 -05:00
MeshIntegrator use MeshIntegrationGroup
This commit is contained in:
parent
000662aeb0
commit
cd3d0573d6
|
|
@ -1,14 +1,18 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace UniGLTF.MeshUtility
|
namespace UniGLTF.MeshUtility
|
||||||
{
|
{
|
||||||
public class MeshIntegrator
|
public class MeshIntegrator
|
||||||
{
|
{
|
||||||
public const string INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME = "Integrated(WithoutBlendShape)";
|
private MeshIntegrator()
|
||||||
public const string INTEGRATED_MESH_WITH_BLENDSHAPE_NAME = "Integrated(WithBlendShape)";
|
{
|
||||||
public const string INTEGRATED_MESH_ALL_NAME = "Integrated(All)";
|
|
||||||
|
}
|
||||||
|
|
||||||
struct SubMesh
|
struct SubMesh
|
||||||
{
|
{
|
||||||
|
|
@ -81,7 +85,7 @@ namespace UniGLTF.MeshUtility
|
||||||
return bw;
|
return bw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Push(MeshRenderer renderer)
|
void Push(MeshRenderer renderer)
|
||||||
{
|
{
|
||||||
var meshFilter = renderer.GetComponent<MeshFilter>();
|
var meshFilter = renderer.GetComponent<MeshFilter>();
|
||||||
if (meshFilter == null)
|
if (meshFilter == null)
|
||||||
|
|
@ -232,7 +236,24 @@ namespace UniGLTF.MeshUtility
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MeshIntegrationResult Integrate(MeshEnumerateOption onlyBlendShapeRenderers)
|
public static MeshIntegrationResult Integrate(MeshIntegrationGroup group, bool useBlendShape)
|
||||||
|
{
|
||||||
|
var integrator = new MeshUtility.MeshIntegrator();
|
||||||
|
foreach (var x in group.Renderers)
|
||||||
|
{
|
||||||
|
if (x is SkinnedMeshRenderer smr)
|
||||||
|
{
|
||||||
|
integrator.Push(smr);
|
||||||
|
}
|
||||||
|
else if (x is MeshRenderer mr)
|
||||||
|
{
|
||||||
|
integrator.Push(mr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return integrator.Integrate(group.Name, useBlendShape);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MeshIntegrationResult Integrate(string name, bool useBlendShape)
|
||||||
{
|
{
|
||||||
var mesh = new Mesh();
|
var mesh = new Mesh();
|
||||||
|
|
||||||
|
|
@ -253,51 +274,15 @@ namespace UniGLTF.MeshUtility
|
||||||
mesh.SetIndices(SubMeshes[i].Indices.ToArray(), MeshTopology.Triangles, i);
|
mesh.SetIndices(SubMeshes[i].Indices.ToArray(), MeshTopology.Triangles, i);
|
||||||
}
|
}
|
||||||
mesh.bindposes = BindPoses.ToArray();
|
mesh.bindposes = BindPoses.ToArray();
|
||||||
|
if (useBlendShape)
|
||||||
// blendshape
|
|
||||||
switch (onlyBlendShapeRenderers)
|
|
||||||
{
|
{
|
||||||
case MeshEnumerateOption.OnlyWithBlendShape:
|
AddBlendShapesToMesh(mesh);
|
||||||
{
|
|
||||||
AddBlendShapesToMesh(mesh);
|
|
||||||
mesh.name = INTEGRATED_MESH_WITH_BLENDSHAPE_NAME;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case MeshEnumerateOption.All:
|
|
||||||
{
|
|
||||||
AddBlendShapesToMesh(mesh);
|
|
||||||
mesh.name = INTEGRATED_MESH_ALL_NAME;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case MeshEnumerateOption.OnlyWithoutBlendShape:
|
|
||||||
{
|
|
||||||
mesh.name = INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
mesh.name = name;
|
||||||
|
|
||||||
// meshName
|
// meshName
|
||||||
var meshNode = new GameObject();
|
var meshNode = new GameObject();
|
||||||
switch (onlyBlendShapeRenderers)
|
meshNode.name = name;
|
||||||
{
|
|
||||||
case MeshEnumerateOption.OnlyWithBlendShape:
|
|
||||||
{
|
|
||||||
meshNode.name = INTEGRATED_MESH_WITH_BLENDSHAPE_NAME;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MeshEnumerateOption.OnlyWithoutBlendShape:
|
|
||||||
{
|
|
||||||
meshNode.name = INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MeshEnumerateOption.All:
|
|
||||||
{
|
|
||||||
meshNode.name = INTEGRATED_MESH_ALL_NAME;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var integrated = meshNode.AddComponent<SkinnedMeshRenderer>();
|
var integrated = meshNode.AddComponent<SkinnedMeshRenderer>();
|
||||||
integrated.sharedMesh = mesh;
|
integrated.sharedMesh = mesh;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace UniGLTF.MeshUtility
|
namespace UniGLTF.MeshUtility
|
||||||
{
|
{
|
||||||
public static class MeshIntegratorUtility
|
public static class MeshIntegratorUtility
|
||||||
{
|
{
|
||||||
|
public const string INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME = "Integrated(WithoutBlendShape)";
|
||||||
|
public const string INTEGRATED_MESH_WITH_BLENDSHAPE_NAME = "Integrated(WithBlendShape)";
|
||||||
|
public const string INTEGRATED_MESH_ALL_NAME = "Integrated(All)";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// go を root としたヒエラルキーから Renderer を集めて、統合された Mesh 作成する
|
/// go を root としたヒエラルキーから Renderer を集めて、統合された Mesh 作成する
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -22,32 +25,39 @@ namespace UniGLTF.MeshUtility
|
||||||
{
|
{
|
||||||
var exclude = new MeshExclude(excludes);
|
var exclude = new MeshExclude(excludes);
|
||||||
|
|
||||||
var integrator = new MeshUtility.MeshIntegrator();
|
var group = new MeshIntegrationGroup();
|
||||||
|
bool useBlendShape = false;
|
||||||
|
|
||||||
switch (onlyBlendShapeRenderers)
|
switch (onlyBlendShapeRenderers)
|
||||||
{
|
{
|
||||||
case MeshEnumerateOption.OnlyWithBlendShape:
|
case MeshEnumerateOption.OnlyWithBlendShape:
|
||||||
{
|
{
|
||||||
|
group.Name = INTEGRATED_MESH_WITH_BLENDSHAPE_NAME;
|
||||||
|
useBlendShape = true;
|
||||||
|
|
||||||
foreach (var x in EnumerateSkinnedMeshRenderer(go.transform, onlyBlendShapeRenderers))
|
foreach (var x in EnumerateSkinnedMeshRenderer(go.transform, onlyBlendShapeRenderers))
|
||||||
{
|
{
|
||||||
if (exclude.IsExcluded(x))
|
if (exclude.IsExcluded(x))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
integrator.Push(x);
|
group.Renderers.Add(x);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MeshEnumerateOption.OnlyWithoutBlendShape:
|
case MeshEnumerateOption.OnlyWithoutBlendShape:
|
||||||
{
|
{
|
||||||
|
group.Name = INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME;
|
||||||
|
useBlendShape = false;
|
||||||
|
|
||||||
foreach (var x in EnumerateSkinnedMeshRenderer(go.transform, onlyBlendShapeRenderers))
|
foreach (var x in EnumerateSkinnedMeshRenderer(go.transform, onlyBlendShapeRenderers))
|
||||||
{
|
{
|
||||||
if (exclude.IsExcluded(x))
|
if (exclude.IsExcluded(x))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
integrator.Push(x);
|
group.Renderers.Add(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var x in EnumerateMeshRenderer(go.transform))
|
foreach (var x in EnumerateMeshRenderer(go.transform))
|
||||||
|
|
@ -56,7 +66,7 @@ namespace UniGLTF.MeshUtility
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
integrator.Push(x);
|
group.Renderers.Add(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -64,13 +74,16 @@ namespace UniGLTF.MeshUtility
|
||||||
|
|
||||||
case MeshEnumerateOption.All:
|
case MeshEnumerateOption.All:
|
||||||
{
|
{
|
||||||
|
group.Name = INTEGRATED_MESH_ALL_NAME;
|
||||||
|
useBlendShape = true;
|
||||||
|
|
||||||
foreach (var x in EnumerateSkinnedMeshRenderer(go.transform, onlyBlendShapeRenderers))
|
foreach (var x in EnumerateSkinnedMeshRenderer(go.transform, onlyBlendShapeRenderers))
|
||||||
{
|
{
|
||||||
if (exclude.IsExcluded(x))
|
if (exclude.IsExcluded(x))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
integrator.Push(x);
|
group.Renderers.Add(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var x in EnumerateMeshRenderer(go.transform))
|
foreach (var x in EnumerateMeshRenderer(go.transform))
|
||||||
|
|
@ -79,14 +92,14 @@ namespace UniGLTF.MeshUtility
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
integrator.Push(x);
|
group.Renderers.Add(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return integrator.Integrate(onlyBlendShapeRenderers);
|
return MeshIntegrator.Integrate(group, useBlendShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<SkinnedMeshRenderer> EnumerateSkinnedMeshRenderer(Transform root, MeshEnumerateOption hasBlendShape)
|
public static IEnumerable<SkinnedMeshRenderer> EnumerateSkinnedMeshRenderer(Transform root, MeshEnumerateOption hasBlendShape)
|
||||||
|
|
|
||||||
|
|
@ -145,13 +145,22 @@ namespace UniVRM10
|
||||||
// TODO: integration
|
// TODO: integration
|
||||||
foreach (var group in MeshIntegrationGroups)
|
foreach (var group in MeshIntegrationGroups)
|
||||||
{
|
{
|
||||||
foreach (var renderer in group.Renderers)
|
var newMesh = MeshIntegrator.Integrate(group, true);
|
||||||
{
|
// TODO: firstperson
|
||||||
|
|
||||||
|
// TODO: split
|
||||||
|
if (SplitByBlendShape)
|
||||||
|
{
|
||||||
|
// var withBlendShape, withoutBlendShape
|
||||||
|
// TODO: remove old renderer
|
||||||
|
// TODO: add new renderer to root
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO: remove old renderer
|
||||||
|
// TODO: add new renderer to root
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: split
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user