private FBXVector GetEulerXYZ(CSGGroup group, float time) { CSGMatrix transformLH = new CSGMatrix(); group.GetTransform(group.Parent, time, ref transformLH); var transformRH = ConvertTransformToRightHanded_ThisLittleBitTookFourDaysToFigureOut(transformLH); FBXMatrix matrix = new FBXMatrix( transformRH.m11, transformRH.m12, transformRH.m13, transformRH.m14, transformRH.m21, transformRH.m22, transformRH.m23, transformRH.m24, transformRH.m31, transformRH.m32, transformRH.m33, transformRH.m34, transformRH.m41, transformRH.m42, transformRH.m43, transformRH.m44); FBXQuaternion fbxQuaternionRH = matrix.GetQuaternion(); var eulerXYZRH = fbxQuaternionRH.DecomposeSphericalXYZ(); return(eulerXYZRH); }
public void Import( string importFileName, CSGGroup importGroup, CSG sceneGraph, CSGApplicationState applicationState, ref float[] userDataFloats, ref int[] userDataInts, ref string userDataString) { // if importing, set SupportImport to return true and add your import code }
public void Export( string filename, CSGGroup group, CSG sceneGraph, CSGApplicationState applicationState, ref float[] userDataFloats, ref int[] userDataInts, ref string userDataString) { Exporter exporter = new Exporter(); exporter.Export(filename, sceneGraph, group); }
private void SetTransform(CSGGroup group, FBXNode node) { CSGVector position = new CSGVector(); group.GetPosition(group.Parent, -1, ref position); position.Z *= -1; node.LclTranslationSet(new FBXVector(position.X, position.Y, position.Z)); FBXVector eulerXYZRH = this.GetEulerXYZ(group, -1); node.LclRotationSet(new FBXVector(eulerXYZRH.x, eulerXYZRH.y, eulerXYZRH.z)); }
internal static void CreaseGroupRecursively(CSGGroup group, ref int shapesCreasedCount) { CSGShapeArray childShapeList = group.GetShapes(); for (int shapeIndex = 0; shapeIndex < childShapeList.GetSize(); shapeIndex++) { CreaseShape(childShapeList.GetElement(shapeIndex), ref shapesCreasedCount); } CSGGroupArray childGroupList = group.GetChildren(); for (int groupIndex = 0; groupIndex < childGroupList.GetSize(); groupIndex++) { CreaseGroupRecursively(childGroupList.GetElement(groupIndex), ref shapesCreasedCount); } }
private void ExportGroupShapes(CSGGroup group, FBXScene fbxScene, FBXNode sceneNode, string groupName, FBXNode node) { CSGShapeArray childShapeList = group.GetShapes(); for (int shapeIndex = 0; shapeIndex < childShapeList.GetSize(); shapeIndex++) { // this little bit of weirdness is due to View3D and Paint3D not being able to have multiple shapes on the same node // there may need to be an export option for this at some point var subnode = node; if (shapeIndex > 0) { string subGroupName = this.GetUniqueName(groupName + "_" + shapeIndex.ToString(), "group"); subnode = FBXNode.Create(sceneNode, subGroupName); node.AddChild(subnode); } this.ExportShape(fbxScene, subnode, childShapeList.GetElement(shapeIndex)); subnode.SetShadingMode(ArcManagedFBX.Types.EShadingMode.eTextureShading); } }
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); } }
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(); } }