Skip to content

Commit

Permalink
Merge pull request #2183 from ousttrue/fix/firstperson_split
Browse files Browse the repository at this point in the history
[vrm1.0] impl mesh split by blendshape existence
  • Loading branch information
ousttrue authored Nov 13, 2023
2 parents c4fbd48 + 225d58c commit 3f7a1fa
Show file tree
Hide file tree
Showing 14 changed files with 554 additions and 193 deletions.
2 changes: 1 addition & 1 deletion Assets/UniGLTF/Editor/MeshUtility/TabMeshIntegrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static bool Execute(GameObject src, bool onlyBlendShapeRenderers)
// write mesh asset.
foreach (var result in results)
{
var mesh = result.MeshMap.Integrated;
var mesh = result.Integrated.Mesh;
var assetPath = GetMeshWritePath(mesh);
Debug.LogFormat("CreateAsset: {0}", assetPath);
AssetDatabase.CreateAsset(mesh, assetPath);
Expand Down
10 changes: 5 additions & 5 deletions Assets/UniGLTF/Runtime/MeshUtility/BoneMeshEraser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ static int ExcludeTriangles(int[] triangles, BoneWeight[] bws, int[] exclude)

{
var bw = bws[a];
var eb = AreBoneContains(ref exclude, bw.boneIndex0, bw.boneIndex1, bw.boneIndex2, bw.boneIndex3);
var eb = AreBoneContains(exclude, bw.boneIndex0, bw.boneIndex1, bw.boneIndex2, bw.boneIndex3);
if (bw.weight0 > 0 && eb.Bone0) continue;
if (bw.weight1 > 0 && eb.Bone1) continue;
if (bw.weight2 > 0 && eb.Bone2) continue;
if (bw.weight3 > 0 && eb.Bone3) continue;
}
{
var bw = bws[b];
var eb = AreBoneContains(ref exclude, bw.boneIndex0, bw.boneIndex1, bw.boneIndex2, bw.boneIndex3);
var eb = AreBoneContains(exclude, bw.boneIndex0, bw.boneIndex1, bw.boneIndex2, bw.boneIndex3);
if (bw.weight0 > 0 && eb.Bone0) continue;
if (bw.weight1 > 0 && eb.Bone1) continue;
if (bw.weight2 > 0 && eb.Bone2) continue;
if (bw.weight3 > 0 && eb.Bone3) continue;
}
{
var bw = bws[c];
var eb = AreBoneContains(ref exclude, bw.boneIndex0, bw.boneIndex1, bw.boneIndex2, bw.boneIndex3);
var eb = AreBoneContains(exclude, bw.boneIndex0, bw.boneIndex1, bw.boneIndex2, bw.boneIndex3);
if (bw.weight0 > 0 && eb.Bone0) continue;
if (bw.weight1 > 0 && eb.Bone1) continue;
if (bw.weight2 > 0 && eb.Bone2) continue;
Expand All @@ -88,7 +88,7 @@ static int ExcludeTriangles(int[] triangles, BoneWeight[] bws, int[] exclude)
return count;
}

private static ExcludeBoneIndex AreBoneContains(ref int[] exclude, int boneIndex0, int boneIndex1,
private static ExcludeBoneIndex AreBoneContains(in int[] exclude, int boneIndex0, int boneIndex1,
int boneIndex2, int boneIndex3)
{
var b0 = false;
Expand Down Expand Up @@ -131,7 +131,7 @@ private static ExcludeBoneIndex AreBoneContains(ref int[] exclude, int boneIndex
/// <param name="boneWeights"></param>
/// <param name="eraseBoneIndices"></param>
/// <returns></returns>
public static int[] GetExcludedIndices(int[] indices, BoneWeight[] boneWeights, int[] eraseBoneIndices)
static int[] GetExcludedIndices(int[] indices, BoneWeight[] boneWeights, int[] eraseBoneIndices)
{
var count = ExcludeTriangles(indices, boneWeights, eraseBoneIndices);
var dst = new int[count];
Expand Down
4 changes: 0 additions & 4 deletions Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,6 @@ private static void CopyBlendShapes(SkinnedMeshRenderer src, Mesh srcMesh, Mesh
}
}

if (report.Count > 0)
{
Debug.LogFormat("{0}", report.ToString());
}
// restore blendshape weights
for (int i = 0; i < backcup.Count; ++i)
{
Expand Down
5 changes: 1 addition & 4 deletions Assets/UniGLTF/Runtime/MeshUtility/MeshIntegrationGroup.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace UniGLTF.MeshUtility
{
public class MeshIntegrationGroup
{
/// <summary>
/// FirstPerson flag
/// TODO: enum
/// </summary>
public string Name;
public List<Renderer> Renderers = new List<Renderer>();
}
Expand Down
55 changes: 39 additions & 16 deletions Assets/UniGLTF/Runtime/MeshUtility/MeshIntegrationResult.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace UniGLTF.MeshUtility
{
[System.Serializable]
public class MeshMap
public struct DrawCount
{
public List<Mesh> Sources = new List<Mesh>();
public Mesh Integrated;
public Material[] SharedMaterials;
public Transform[] Bones;
public int Count;
public Material Material;
}

public class MeshIntegrationResult
[Serializable]
public class MeshInfo
{
public List<SkinnedMeshRenderer> SourceSkinnedMeshRenderers = new List<SkinnedMeshRenderer>();
public List<MeshRenderer> SourceMeshRenderers = new List<MeshRenderer>();
public MeshMap MeshMap = new MeshMap();
public Mesh Mesh;
public List<DrawCount> SubMeshes = new List<DrawCount>();

public SkinnedMeshRenderer IntegratedRenderer;

public void AddIntegratedRendererTo(GameObject parent)
public void AddIntegratedRendererTo(GameObject parent, Transform[] bones)
{
var go = new GameObject(MeshMap.Integrated.name);
var go = new GameObject(Mesh.name);
go.transform.SetParent(parent.transform, false);
var smr = go.AddComponent<SkinnedMeshRenderer>();
smr.sharedMesh = MeshMap.Integrated;
smr.sharedMaterials = MeshMap.SharedMaterials;
smr.bones = MeshMap.Bones;

smr.sharedMesh = Mesh;
smr.sharedMaterials = SubMeshes.Where(x => x.Count > 0).Select(x => x.Material).ToArray();
smr.bones = bones;
IntegratedRenderer = smr;
}
}

public class MeshIntegrationResult
{
public List<SkinnedMeshRenderer> SourceSkinnedMeshRenderers = new List<SkinnedMeshRenderer>();
public List<MeshRenderer> SourceMeshRenderers = new List<MeshRenderer>();

public List<Mesh> Sources = new List<Mesh>();
public MeshInfo Integrated;
public MeshInfo IntegratedNoBlendShape;
public Transform[] Bones;

public void DestroySourceRenderer()
{
throw new NotImplementedException();
}

public IEnumerable<GameObject> AddIntegratedRendererTo(GameObject parent)
{
if (Integrated != null)
{
Integrated.AddIntegratedRendererTo(parent, Bones);
yield return Integrated.IntegratedRenderer.gameObject;
}
if (IntegratedNoBlendShape != null)
{
IntegratedNoBlendShape.AddIntegratedRendererTo(parent, Bones);
yield return IntegratedNoBlendShape.IntegratedRenderer.gameObject;
}
}
}
}
Loading

0 comments on commit 3f7a1fa

Please sign in to comment.