Skip to content

Commit 4b20c54

Browse files
committed
Merge branch 'master' into blendshape_support
2 parents ed773fb + a69c98f commit 4b20c54

14 files changed

+9353
-122
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,8 +1118,17 @@ private bool ExportSkin (SkinnedMeshRenderer skinnedMesh,
11181118
/// </summary>
11191119
private void SetVertexWeights (MeshInfo meshInfo, Dictionary<int, FbxCluster> boneCluster)
11201120
{
1121+
HashSet<int> visitedVertices = new HashSet<int> ();
1122+
11211123
// set the vertex weights for each bone
11221124
for (int i = 0; i < meshInfo.BoneWeights.Length; i++) {
1125+
var actualIndex = ControlPointToIndex [meshInfo.Vertices [i]];
1126+
1127+
if (visitedVertices.Contains (actualIndex)) {
1128+
continue;
1129+
}
1130+
visitedVertices.Add (actualIndex);
1131+
11231132
var boneWeights = meshInfo.BoneWeights;
11241133
int[] indices = {
11251134
boneWeights [i].boneIndex0,
@@ -1141,7 +1150,8 @@ boneWeights [i].weight3
11411150
if (!boneCluster.ContainsKey (indices [j])) {
11421151
continue;
11431152
}
1144-
boneCluster [indices [j]].AddControlPointIndex (ControlPointToIndex[meshInfo.Vertices[i]], weights [j]);
1153+
// add vertex and weighting on vertex to this bone's cluster
1154+
boneCluster [indices [j]].AddControlPointIndex (actualIndex, weights [j]);
11451155
}
11461156
}
11471157
}
@@ -1220,6 +1230,30 @@ public static FbxVector4 ConvertQuaternionToXYZEuler (FbxQuaternion quat)
12201230
return new FbxVector4 (vector4.X, -vector4.Y, -vector4.Z, vector4.W);
12211231
}
12221232

1233+
/// <summary>
1234+
/// Euler to quaternion without axis conversion.
1235+
/// </summary>
1236+
/// <returns>a quaternion.</returns>
1237+
/// <param name="euler">Euler.</param>
1238+
public static FbxQuaternion EulerToQuaternion(FbxVector4 euler)
1239+
{
1240+
FbxAMatrix m = new FbxAMatrix ();
1241+
m.SetR (euler);
1242+
return m.GetQ ();
1243+
}
1244+
1245+
/// <summary>
1246+
/// Quaternion to euler without axis conversion.
1247+
/// </summary>
1248+
/// <returns>a euler.</returns>
1249+
/// <param name="quat">Quaternion.</param>
1250+
public static FbxVector4 QuaternionToEuler(FbxQuaternion quat)
1251+
{
1252+
FbxAMatrix m = new FbxAMatrix ();
1253+
m.SetQ (quat);
1254+
return m.GetR ();
1255+
}
1256+
12231257
// get a fbxNode's global default position.
12241258
protected bool ExportTransform (UnityEngine.Transform unityTransform, FbxNode fbxNode, Vector3 newCenter, TransformExportType exportType)
12251259
{
@@ -1620,6 +1654,12 @@ public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPai
16201654
return true;
16211655
}
16221656

1657+
if (uniPropertyName.StartsWith("field of view", ct))
1658+
{
1659+
prop = new FbxPropertyChannelPair("FieldOfView", null);
1660+
return true;
1661+
}
1662+
16231663
prop = new FbxPropertyChannelPair ();
16241664
return false;
16251665
}
@@ -1679,8 +1719,9 @@ Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
16791719
var fbxPreRotationEuler = node.GetRotationActive()
16801720
? node.GetPreRotation(FbxNode.EPivotSet.eSourcePivot)
16811721
: new FbxVector4();
1682-
var fbxPreRotationInverse = new FbxQuaternion();
1683-
fbxPreRotationInverse.ComposeSphericalXYZ(fbxPreRotationEuler);
1722+
1723+
// Get the inverse of the prerotation
1724+
var fbxPreRotationInverse = ModelExporter.EulerToQuaternion (fbxPreRotationEuler);
16841725
fbxPreRotationInverse.Inverse();
16851726

16861727
// If we're only animating along certain coords for some
@@ -1709,17 +1750,23 @@ Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
17091750
(z == null) ? lclQuaternion[2] : z.Evaluate(seconds),
17101751
(w == null) ? lclQuaternion[3] : w.Evaluate(seconds));
17111752

1753+
// convert the final animation to righthanded coords
1754+
var finalEuler = ModelExporter.ConvertQuaternionToXYZEuler(fbxFinalAnimation);
1755+
1756+
// convert it back to a quaternion for multiplication
1757+
fbxFinalAnimation = ModelExporter.EulerToQuaternion (finalEuler);
1758+
17121759
// Cancel out the pre-rotation. Order matters. FBX reads left-to-right.
17131760
// When we run animation we will apply:
17141761
// pre-rotation
17151762
// then pre-rotation inverse
17161763
// then animation.
1717-
var fbxQuat = fbxPreRotationInverse * fbxFinalAnimation;
1764+
var fbxFinalQuat = fbxPreRotationInverse * fbxFinalAnimation;
17181765

17191766
// Store the key so we can sort them later.
17201767
Key key;
17211768
key.time = FbxTime.FromSecondDouble(seconds);
1722-
key.euler = ModelExporter.ConvertQuaternionToXYZEuler(fbxQuat);
1769+
key.euler = ModelExporter.QuaternionToEuler (fbxFinalQuat);;
17231770
keys[i++] = key;
17241771
}
17251772

0 commit comments

Comments
 (0)