Skip to content

Commit

Permalink
cleanup bake BlendShape
Browse files Browse the repository at this point in the history
  • Loading branch information
ousttrue committed Apr 17, 2018
1 parent 162a431 commit 035811f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
8 changes: 4 additions & 4 deletions Scripts/Format/VRMVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace VRM
public static class VRMVersion
{
public const int MAJOR = 0;
public const int MINOR = 32;
public const int MINOR = 33;

public const string VERSION = "0.32";
public const string VERSION = "0.33";

public const string DecrementMenuName = "VRM/Version(0.32) Decrement";
public const string IncrementMenuName = "VRM/Version(0.32) Increment";
public const string DecrementMenuName = "VRM/Version(0.33) Decrement";
public const string IncrementMenuName = "VRM/Version(0.33) Increment";
}
}
50 changes: 35 additions & 15 deletions Scripts/SkinnedMeshUtility/Editor/BoneNormalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,61 +180,81 @@ public static GameObject Execute(GameObject go, Dictionary<Transform, Transform>

srcRenderer.SetBlendShapeWeight(i, 100.0f);
srcRenderer.BakeMesh(blendShapeMesh);
srcRenderer.SetBlendShapeWeight(i, 0);

if (blendShapeMesh.vertices.Length != mesh.vertices.Length)
{
throw new Exception("diffrent vertex count");
}
srcRenderer.SetBlendShapeWeight(i, 0);

var weight = srcMesh.GetBlendShapeFrameWeight(i, 0);
var vertices = blendShapeMesh.vertices;
var normals = blendShapeMesh.normals;
var tangents = blendShapeMesh.tangents.Select(x => (Vector3)x).ToArray();

for (int j = 0; j < vertices.Length; ++j)
Vector3[] vertices = null;
if (hasVertices)
{
vertices[j] = m.MultiplyPoint(vertices[j]) - meshVertices[j];
vertices = blendShapeMesh.vertices;
// to delta
for (int j = 0; j < vertices.Length; ++j)
{
vertices[j] = m.MultiplyPoint(vertices[j]) - meshVertices[j];
}
}
else
{
vertices = new Vector3[mesh.vertexCount];
}

Vector3[] normals = null;
if (hasNormals)
{
normals = blendShapeMesh.normals;
// to delta
for (int j = 0; j < normals.Length; ++j)
{
normals[j] = m.MultiplyVector(normals[j]) - meshNormals[j];
}
}
else
{
normals = new Vector3[mesh.vertexCount];
}

Vector3[] tangents = null;
if (hasTangents)
{
tangents = blendShapeMesh.tangents.Select(x => (Vector3)x).ToArray();
// to delta
for (int j = 0; j < tangents.Length; ++j)
{
tangents[j] = m.MultiplyVector(tangents[j]) - meshTangents[j];
}
}
else
{
tangents = new Vector3[mesh.vertexCount];
}

var name = srcMesh.GetBlendShapeName(i);
if (string.IsNullOrEmpty(name))
{
name = String.Format("{0}", i);
}

var weight = srcMesh.GetBlendShapeFrameWeight(i, 0);

try
{
mesh.AddBlendShapeFrame(name,
weight,
vertices,
hasNormals && normals.Length == mesh.vertexCount ? normals : null,
hasTangents && tangents.Length == mesh.vertexCount ? tangents : null
normals,
tangents
);
}
catch (Exception ex)
catch (Exception)
{
Debug.LogWarningFormat("fail to mesh.AddBlendShapeFrame {0}.{1}: {2}",
Debug.LogErrorFormat("fail to mesh.AddBlendShapeFrame {0}.{1}",
mesh.name,
srcMesh.GetBlendShapeName(i),
ex
srcMesh.GetBlendShapeName(i)
);
throw;
}
}

Expand Down

0 comments on commit 035811f

Please sign in to comment.