static FbxObject CreateFbxObject(FbxCamera mesh, Matrix4x4 transform, FbxObjectManager ObjectManager, FbxConnectionManager ConnectionManager) { var Name = "Model::" + mesh.Name; FbxObject Object; Object = ObjectManager.CreateObject("Model", Name); var Model = Object.Definition; Model.AddValue(Object.Ident); Model.AddValue(Name); Model.AddValue("Camera"); Model.AddProperty("Version", 232); var Properties = Model.AddProperty("Properties70"); var DefaultAttributeIndex = Properties.AddProperty("P"); DefaultAttributeIndex.AddValue("DefaultAttributeIndex"); DefaultAttributeIndex.AddValue("int"); DefaultAttributeIndex.AddValue("Integer"); DefaultAttributeIndex.AddValue(""); DefaultAttributeIndex.AddValue(0); var LclTranslation = Properties.AddProperty("P"); LclTranslation.AddValue("Lcl Translation"); LclTranslation.AddValue(""); LclTranslation.AddValue("A+"); LclTranslation.AddValue(Vector3.zero); var LclRotation = Properties.AddProperty("P"); LclRotation.AddValue("Lcl Rotation"); LclRotation.AddValue(""); LclRotation.AddValue("A+"); LclRotation.AddValue(Vector3.zero); var LclScaling = Properties.AddProperty("P"); LclScaling.AddValue("Lcl Scaling"); LclScaling.AddValue(""); LclScaling.AddValue("A+"); LclScaling.AddValue(Vector3.one); // need a camera attrib and need it connected var CameraAttrib = new NodeAttribute(mesh.Name); var AttribObject = CreateFbxObject(CameraAttrib, ObjectManager); ConnectionManager.Add(new FbxConnection(AttribObject, Object, FbxRelationType.OO)); return(Object); }
static void MakeAnimationNode(AnimObject Anim, FbxObject AnimatedObject, FbxObject AnimLayer, FbxObjectManager ObjectManager, FbxConnectionManager ConnectionManager) { // make the animation nodes FbxObject AnimNodePosition, AnimNodeRotation, AnimNodeScale; MakeAnimationNode(Anim, AnimLayer, ObjectManager, ConnectionManager, out AnimNodePosition, out AnimNodeRotation, out AnimNodeScale); // object connection if (AnimNodePosition != null) { ConnectionManager.Add(new FbxConnection("AnimCurveNode", "T", AnimNodePosition, "Model", AnimatedObject.TypeName, AnimatedObject, FbxRelationType.OP, "Lcl Translation")); } if (AnimNodeRotation != null) { ConnectionManager.Add(new FbxConnection("AnimCurveNode", "R", AnimNodeRotation, "Model", AnimatedObject.TypeName, AnimatedObject, FbxRelationType.OP, "Lcl Rotation")); } if (AnimNodeScale != null) { ConnectionManager.Add(new FbxConnection("AnimCurveNode", "S", AnimNodeScale, "Model", AnimatedObject.TypeName, AnimatedObject, FbxRelationType.OP, "Lcl Scaling")); } }
public static void Export(System.Action <string> WriteLine, Mesh mesh, Matrix4x4 transform, List <string> Comments = null) { // temp objects var MeshAnim = new AnimObject(); MeshAnim.AddFrame(new Vector3(0, 0, 0), Quaternion.identity, 0); MeshAnim.AddFrame(new Vector3(0, 1000, 0), Quaternion.Euler(0, 90, 0), 1); MeshAnim.AddFrame(new Vector3(0, 0, 0), Quaternion.Euler(0, 180, 0), 2); MeshAnim.AddFrame(new Vector3(0, 1000, 0), Quaternion.Euler(0, 270, 0), 3); MeshAnim.AddFrame(new Vector3(0, 0, 0), Quaternion.Euler(0, 359, 0), 4); var AnimStack = new AnimStack("Take001", MeshAnim.GetStartTime(), MeshAnim.GetEndTime()); var Cam = new FbxCamera("Camera1"); Pop.AllocIfNull(ref Comments); Comments.Add("Using WIP PopX.FbxAscii exporter from @soylentgraham"); var Header = GetHeaderProperty(); Header.AddComment(Comments); Export(WriteLine, Header); var ConnectionManager = new FbxConnectionManager(); var ObjectManager = new FbxObjectManager(); //var MeshObject = CreateFbxObject(mesh, transform, ObjectManager); var CameraObject = CreateFbxObject(Cam, transform, ObjectManager, ConnectionManager); var AnimLayerObject = CreateAnimLayerObject(ObjectManager); var AnimStackObject = CreateAnimStackObject(AnimStack, ObjectManager); MakeAnimationNode(MeshAnim, CameraObject, AnimLayerObject, ObjectManager, ConnectionManager); ConnectionManager.Add(new FbxConnection(AnimLayerObject.TypeName, AnimLayerObject.ObjectName, AnimLayerObject, AnimStackObject.TypeName, AnimStackObject.ObjectName, AnimStackObject, FbxRelationType.OO)); var Definitions = GetDefinitionsProperty(ObjectManager); Export(WriteLine, Definitions); Export(WriteLine, ObjectManager); // fake connections after we've exported ObjectManager var SceneMesh = new Mesh(); SceneMesh.name = "Root"; var SceneMeshObject = CreateFbxObject(SceneMesh, Matrix4x4.identity, ObjectManager, FbxObjectManager.RootNodeIdent); //var MeshMaterialObject = CreateFbxObject_Material("DummyMaterial", ObjectManager); //ConnectionManager.Add(new FbxConnection( MeshObject, SceneMeshObject, FbxRelationType.OO)); ConnectionManager.Add(new FbxConnection(CameraObject, SceneMeshObject, FbxRelationType.OO)); //ConnectionManager.Add(new FbxConnection( MeshMaterialObject.TypeName, MeshMaterialObject.ObjectName, MeshMaterialObject, MeshObject.TypeName, MeshObject.ObjectName, MeshObject, FbxRelationType.OO)); Export(WriteLine, ConnectionManager); }
static void MakeAnimationNode(AnimObject Anim, FbxObject AnimLayer, FbxObjectManager ObjectManager, FbxConnectionManager ConnectionManager, out FbxObject AnimNodePosition, out FbxObject AnimNodeRotation, out FbxObject AnimNodeScale) { // add anim nodes var ao = Anim; float[] TimeData; ao.GetCurveTimes(out TimeData); bool MakeTranslation = true; bool MakeRotation = false; bool MakeScale = false; if (MakeTranslation) { var NodeT = ObjectManager.AddAnimationCurveNode(FbxAnimationCurveNodeType.Translation, ao.Frames[0].Position); AnimNodePosition = NodeT; // get data float[] TXData; float[] TYData; float[] TZData; ao.GetPositionCurveData(out TXData, out TYData, out TZData); var CurveTX = ObjectManager.AddAnimationCurve(TXData, TimeData); var CurveTY = ObjectManager.AddAnimationCurve(TYData, TimeData); var CurveTZ = ObjectManager.AddAnimationCurve(TZData, TimeData); ConnectionManager.Add(new FbxConnection("AnimCurveNode", "T", NodeT, "AnimLayer", "BaseLayer", AnimLayer, FbxRelationType.OO)); ConnectionManager.Add(new FbxConnection("AnimCurve", "", CurveTX, "AnimCurveNode", "T", NodeT, FbxRelationType.OP, "d|X")); ConnectionManager.Add(new FbxConnection("AnimCurve", "", CurveTY, "AnimCurveNode", "T", NodeT, FbxRelationType.OP, "d|Y")); ConnectionManager.Add(new FbxConnection("AnimCurve", "", CurveTZ, "AnimCurveNode", "T", NodeT, FbxRelationType.OP, "d|Z")); } else { AnimNodePosition = null; } if (MakeRotation) { var NodeR = ObjectManager.AddAnimationCurveNode(FbxAnimationCurveNodeType.Rotation, ao.Frames[0].RotationEular); AnimNodeRotation = NodeR; float[] RXData; float[] RYData; float[] RZData; ao.GetRotationCurveData(out RXData, out RYData, out RZData); var CurveRX = ObjectManager.AddAnimationCurve(RXData, TimeData); var CurveRY = ObjectManager.AddAnimationCurve(RYData, TimeData); var CurveRZ = ObjectManager.AddAnimationCurve(RZData, TimeData); ConnectionManager.Add(new FbxConnection("AnimCurveNode", "R", NodeR, "AnimLayer", "BaseLayer", AnimLayer, FbxRelationType.OO)); ConnectionManager.Add(new FbxConnection("AnimCurve", "", CurveRX, "AnimCurveNode", "R", NodeR, FbxRelationType.OP, "d|X")); ConnectionManager.Add(new FbxConnection("AnimCurve", "", CurveRY, "AnimCurveNode", "R", NodeR, FbxRelationType.OP, "d|Y")); ConnectionManager.Add(new FbxConnection("AnimCurve", "", CurveRZ, "AnimCurveNode", "R", NodeR, FbxRelationType.OP, "d|Z")); } else { AnimNodeRotation = null; } if (MakeScale) { var NodeS = ObjectManager.AddAnimationCurveNode(FbxAnimationCurveNodeType.Scale, ao.Frames[0].Scale); AnimNodeScale = NodeS; float[] SXData; float[] SYData; float[] SZData; ao.GetScaleCurveData(out SXData, out SYData, out SZData); var CurveSX = ObjectManager.AddAnimationCurve(SXData, TimeData); var CurveSY = ObjectManager.AddAnimationCurve(SYData, TimeData); var CurveSZ = ObjectManager.AddAnimationCurve(SZData, TimeData); ConnectionManager.Add(new FbxConnection("AnimCurveNode", "S", NodeS, "AnimLayer", "BaseLayer", AnimLayer, FbxRelationType.OO)); ConnectionManager.Add(new FbxConnection("AnimCurve", "", CurveSX, "AnimCurveNode", "S", NodeS, FbxRelationType.OP, "d|X")); ConnectionManager.Add(new FbxConnection("AnimCurve", "", CurveSY, "AnimCurveNode", "S", NodeS, FbxRelationType.OP, "d|Y")); ConnectionManager.Add(new FbxConnection("AnimCurve", "", CurveSZ, "AnimCurveNode", "S", NodeS, FbxRelationType.OP, "d|Z")); } else { AnimNodeScale = null; } }