- Home /
How to export FBX at runtime with animation(s), rig and the mesh to Maya, blender etc.. ?
Hello everyone !
What I want to do is basically to export FBX at runtime with animation, rig and mesh to maya (or similar tools) and view the export in 3D app with all the features exported..
Looking forward for your answers and suggestions !
Comment
Answer by TekuConcept · Feb 24 at 04:26 AM
Here's a working code snippet that should at least be a good starting point:
private static void ExportFbxScene(string filename) {
var manager = FbxManager.Create();
manager.SetIOSettings(FbxIOSettings.Create(manager, Globals.IOSROOT));
var exporter = FbxExporter.Create(manager, "exporter");
exporter.Initialize(filename, /*FileFormat=*/-1, manager.GetIOSettings());
var scene = FbxScene.Create(manager, "scene");
AddSkeletonTo(ref scene);
exporter.Export(scene);
}
private static void AddSkeletonTo(ref FbxScene scene) {
var rootObj = FbxNode.Create(scene, "root-obj");
var bones = new List<FbxNode>();
var boneNames = new[] { "root-bone", "child-bone" };
scene.GetRootNode().AddChild(rootObj);
for (var i = 0; i < boneNames.Length; i++) {
// create the bone object
var skeletonAttribute = FbxSkeleton.Create(scene, boneNames[i]);
skeletonAttribute.SetSkeletonType(i == 0 ?
FbxSkeleton.EType.eRoot : FbxSkeleton.EType.eLimbNode);
var bone = FbxNode.Create(scene, boneNames[i]);
bone.SetNodeAttribute(skeletonAttribute);
// set the bone's transform
bone.LclTranslation.Set(new FbxDouble3(0, -5, 0)); // x, -y, z
bone.LclRotation.Set(new FbxDouble3(0, -0, -0)); // x, -y, -z
bone.LclScaling.Set(new FbxDouble3(1, 1, 1)); // x, y, z
// add to parent bone
if (i > 0) bones[i - 1].AddChild(bone); // link: A -> B -> C -> ...
// add to local bone list for next iteration
bones.Add(bone);
}
var pose = FbxPose.Create(scene, boneNames[0]);
pose.SetIsBindPose(true); // default is rest pose
foreach (var bone in boneNodes) {
var bindMatrix = bone.EvaluateGlobalTransform();
pose.Add(bone, new FbxMatrix(bindMatrix));
}
scene.AddPose(pose);
}
Sources I used: