public void Export(string fileName, CSG sceneGraph, CSGGroup group) { Common.InitializeSdkObjects(group.Name, out FBXManager managerInstance, out FBXScene fbxScene); FBXAnimStack myAnimStack = FBXAnimStack.Create(fbxScene, group.Name + " Animation Stack"); FBXAnimLayer myAnimBaseLayer = FBXAnimLayer.Create(fbxScene, "Layer0"); myAnimStack.AddMember(myAnimBaseLayer); var node = fbxScene.GetRootNode(); this.ExportGroupRecursively(group, fbxScene, node, myAnimBaseLayer, sceneGraph.ApplicationState.SettingAnimationKeyFramesPerSecond); int fileFormat = -1; if (string.Equals(Path.GetExtension(fileName), ".fbx", StringComparison.InvariantCultureIgnoreCase)) { fileFormat = 1; // force text export for fbx } Common.SaveScene(managerInstance, fbxScene, fileName, fileFormat); }
private void ExportGroupAnimation(CSGGroup group, FBXAnimLayer animationLayer, float keyFramesPerSecond, FBXNode node) { CSGAnimationKey[] animationKeyList = null; int keyListCount = 0; group.GetAnimationKeys(0, 999999, ref animationKeyList, ref keyListCount); int translationAnimationKeyCount = 0; int rotationAnimationKeyCount = 0; foreach (var animationKey in animationKeyList) { if (animationKey.Type == CSGAnimationKeyType.CSGAnimationPositionKey) { translationAnimationKeyCount++; } if (animationKey.Type == CSGAnimationKeyType.CSGAnimationOrientationKey) { rotationAnimationKeyCount++; } } if (translationAnimationKeyCount > 1) { FBXAnimCurveNode myTranslationAnimCurveNode = node.LclTranslationGetCurveNode(animationLayer); FBXAnimCurve myTranXCurve = node.LclTranslationGetCurve(animationLayer, "X"); FBXAnimCurve myTranYCurve = node.LclTranslationGetCurve(animationLayer, "Y"); FBXAnimCurve myTranZCurve = node.LclTranslationGetCurve(animationLayer, "Z"); myTranXCurve.KeyModifyBegin(); myTranYCurve.KeyModifyBegin(); myTranZCurve.KeyModifyBegin(); foreach (var animationKey in animationKeyList) { if (animationKey.Type == CSGAnimationKeyType.CSGAnimationPositionKey) { myTranXCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, animationKey.V.X); // , ArcManagedFBX.Types.EInterpolationType.eInterpolationConstant); myTranYCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, animationKey.V.Y); // , ArcManagedFBX.Types.EInterpolationType.eInterpolationConstant); myTranZCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, -animationKey.V.Z); // , ArcManagedFBX.Types.EInterpolationType.eInterpolationConstant); } } myTranXCurve.KeyModifyEnd(); myTranYCurve.KeyModifyEnd(); myTranZCurve.KeyModifyEnd(); } if (rotationAnimationKeyCount > 1) { FBXAnimCurveNode myRotationAnimCurveNode = node.LclRotationGetCurveNode(animationLayer); FBXAnimCurve myRotXCurve = node.LclRotationGetCurve(animationLayer, "X"); FBXAnimCurve myRotYCurve = node.LclRotationGetCurve(animationLayer, "Y"); FBXAnimCurve myRotZCurve = node.LclRotationGetCurve(animationLayer, "Z"); myRotXCurve.KeyModifyBegin(); myRotYCurve.KeyModifyBegin(); myRotZCurve.KeyModifyBegin(); foreach (var animationKey in animationKeyList) { if (animationKey.Type == CSGAnimationKeyType.CSGAnimationOrientationKey) { FBXVector eulerXYZ = this.GetEulerXYZ(group, animationKey.Time); myRotXCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, (float)eulerXYZ.x); // , ArcManagedFBX.Types.EInterpolationType.eInterpolationLinear); myRotYCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, (float)eulerXYZ.y); // , ArcManagedFBX.Types.EInterpolationType.eInterpolationLinear); myRotZCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, (float)eulerXYZ.z); // , ArcManagedFBX.Types.EInterpolationType.eInterpolationLinear); } } myRotXCurve.KeyModifyEnd(); myRotYCurve.KeyModifyEnd(); myRotZCurve.KeyModifyEnd(); } }
private void ExportGroupRecursively(CSGGroup group, FBXScene fbxScene, FBXNode parentNode, FBXAnimLayer animationLayer, float keyFramesPerSecond) { string groupName = this.GetUniqueName(group.Name, "group"); var node = FBXNode.Create(parentNode, groupName); parentNode.AddChild(node); this.SetTransform(group, node); this.ExportGroupAnimation(group, animationLayer, keyFramesPerSecond, node); this.ExportGroupShapes(group, fbxScene, parentNode, groupName, node); CSGGroupArray childGroupList = group.GetChildren(); for (int groupIndex = 0; groupIndex < childGroupList.GetSize(); groupIndex++) { this.ExportGroupRecursively(childGroupList.GetElement(groupIndex), fbxScene, node, animationLayer, keyFramesPerSecond); } }