Skip to content

Commit d457f3f

Browse files
committed
pass bone info (skinned mesh, root, dict) as a struct
1 parent 689a4d1 commit d457f3f

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,7 +2228,9 @@ protected int ExportAnimationOnly(
22282228
foreach (var bone in bones) {
22292229
FbxNode node;
22302230
if (!ExportGameObjectAndParents (
2231-
bone.gameObject, unityGO, fbxScene, out node, newCenter, exportType, ref numObjectsExported, objectCount, skinnedMesh, boneDict, rootBone, true
2231+
bone.gameObject, unityGO, fbxScene, out node, newCenter,
2232+
exportType, ref numObjectsExported, objectCount,
2233+
new SkinnedMeshBoneInfo(rootBone, skinnedMesh, boneDict)
22322234
)) {
22332235
// export cancelled
22342236
return -1;
@@ -2264,6 +2266,18 @@ protected int ExportAnimationOnly(
22642266
return numObjectsExported;
22652267
}
22662268

2269+
class SkinnedMeshBoneInfo {
2270+
public Transform rootBone;
2271+
public SkinnedMeshRenderer skinnedMesh;
2272+
public Dictionary<Transform, int> boneDict;
2273+
2274+
public SkinnedMeshBoneInfo(Transform root, SkinnedMeshRenderer skinnedMesh, Dictionary<Transform, int> boneDict){
2275+
this.rootBone = root;
2276+
this.skinnedMesh = skinnedMesh;
2277+
this.boneDict = boneDict;
2278+
}
2279+
}
2280+
22672281
private bool ExportGameObjectAndParents(
22682282
GameObject unityGo,
22692283
GameObject rootObject,
@@ -2273,10 +2287,7 @@ private bool ExportGameObjectAndParents(
22732287
TransformExportType exportType,
22742288
ref int exportProgress,
22752289
int objectCount,
2276-
SkinnedMeshRenderer skinnedMesh = null,
2277-
Dictionary<Transform, int> boneDict = null,
2278-
Transform rootBone = null,
2279-
bool isBone = false)
2290+
SkinnedMeshBoneInfo boneInfo = null)
22802291
{
22812292
// node already exists
22822293
if (MapUnityObjectToFbxNode.TryGetValue (unityGo, out fbxNode)) {
@@ -2308,18 +2319,18 @@ private bool ExportGameObjectAndParents(
23082319
fbxNode.SetTransformationInheritType (FbxTransform.EInheritType.eInheritRSrs);
23092320

23102321
// TODO: check if GO is a bone and export accordingly
2311-
var exportedBoneTransform = isBone?
2312-
ExportBoneTransform (fbxNode, fbxScene, unityGo.transform, rootBone, skinnedMesh, boneDict) : false;
2322+
var exportedBoneTransform = boneInfo != null?
2323+
ExportBoneTransform (fbxNode, fbxScene, unityGo.transform, boneInfo) : false;
23132324

23142325
// export regular transform if we are not a bone or failed to export as a bone
23152326
if(!exportedBoneTransform){
23162327
ExportTransform (unityGo.transform, fbxNode, newCenter, exportType);
23172328
}
23182329

23192330
if (unityGo.transform.parent != null || unityGo.transform.parent != rootObject.transform.parent) {
2320-
var parentIsBone = false;
2321-
if (isBone && rootBone != null && unityGo.transform != rootBone) {
2322-
parentIsBone = true;
2331+
SkinnedMeshBoneInfo parentBoneInfo = null;
2332+
if (boneInfo != null && boneInfo.rootBone != null && unityGo.transform != boneInfo.rootBone) {
2333+
parentBoneInfo = boneInfo;
23232334
}
23242335

23252336
FbxNode fbxNodeParent;
@@ -2332,33 +2343,34 @@ private bool ExportGameObjectAndParents(
23322343
TransformExportType.Local,
23332344
ref exportProgress,
23342345
objectCount,
2335-
skinnedMesh,
2336-
boneDict,
2337-
rootBone,
2338-
parentIsBone
2346+
parentBoneInfo
23392347
)) {
23402348
// export cancelled
23412349
return false;
23422350
}
23432351
fbxNodeParent.AddChild (fbxNode);
23442352
}
23452353

2346-
if (unityGo == rootObject) {
2354+
if (unityGo == rootObject || unityGo.transform.parent == null) {
23472355
fbxScene.GetRootNode ().AddChild (fbxNode);
23482356
}
23492357

23502358
return true;
23512359
}
23522360

23532361
private bool ExportBoneTransform(
2354-
FbxNode fbxNode, FbxScene fbxScene, Transform unityBone, Transform rootBone,
2355-
SkinnedMeshRenderer skinnedMesh, Dictionary<Transform, int> boneDict
2362+
FbxNode fbxNode, FbxScene fbxScene, Transform unityBone, SkinnedMeshBoneInfo boneInfo
23562363
){
2357-
if (skinnedMesh == null || boneDict == null || unityBone == null) {
2364+
if (boneInfo != null || boneInfo.skinnedMesh == null || boneInfo.boneDict == null || unityBone == null) {
23582365
return false;
23592366
}
2367+
2368+
var rootBone = boneInfo.rootBone;
2369+
var skinnedMesh = boneInfo.skinnedMesh;
2370+
var boneDict = boneInfo.boneDict;
2371+
23602372
if (rootBone == null) {
2361-
rootBone = skinnedMesh.rootBone;
2373+
boneInfo.rootBone = skinnedMesh.rootBone;
23622374
}
23632375

23642376
var fbxSkeleton = fbxNode.GetSkeleton ();
@@ -2481,6 +2493,7 @@ protected void GetObjectsInAnimationClips(
24812493
GameObject animationRootObject,
24822494
ref AnimationOnlyExportData exportData
24832495
){
2496+
// TODO: find a better way to keep track of which components + properties we support
24842497
var cameraProps = new List<string>{"field of view"};
24852498
var lightProps = new List<string>{"m_Intensity", "m_SpotAngle", "m_Color.r", "m_Color.g", "m_Color.b"};
24862499

@@ -2497,7 +2510,6 @@ ref AnimationOnlyExportData exportData
24972510
if (!uniObj) {
24982511
continue;
24992512
}
2500-
//Debug.LogWarning (uniObj.name + ": " + uniCurveBinding.propertyName);
25012513

25022514
GameObject unityGo = GetGameObject (uniObj);
25032515
if (!unityGo) {

0 commit comments

Comments
 (0)