예제 #1
0
        static FbxProperty GetDefinitionsProperty(FbxObjectManager ObjectManager)
        {
            var Defs = new FbxProperty("Definitions");

            Defs.AddProperty("Version", 100);

            Defs.AddProperty("Count", ObjectManager.Objects.Count);

            //	get types
            var TypeCounts = new Dictionary <string, int>();

            foreach (var Object in ObjectManager.Objects)
            {
                var TypeName = Object.TypeName;
                if (!TypeCounts.ContainsKey(TypeName))
                {
                    TypeCounts.Add(TypeName, 1);
                }
                else
                {
                    TypeCounts[TypeName]++;
                }
            }

            foreach (var TypeCount in TypeCounts)
            {
                var ot = Defs.AddProperty("ObjectType", TypeCount.Key);
                ot.AddProperty("Count", TypeCount.Value);
            }
            return(Defs);
        }
예제 #2
0
        static void Export(System.Action <string> WriteLine, FbxObjectManager ObjectManager)
        {
            var ObjectPropertys = new FbxProperty("Objects");

            foreach (var Object in ObjectManager.Objects)
            {
                ObjectPropertys.AddProperty(Object.Definition);
            }
            Export(WriteLine, ObjectPropertys);
        }
예제 #3
0
        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);
        }
예제 #4
0
        static FbxObject CreateAnimStackObject(AnimStack Anim, FbxObjectManager ObjectManager)
        {
            var Name   = "AnimStack::" + Anim.Name;
            var Object = ObjectManager.CreateObject("AnimationStack", Name);
            var Def    = Object.Definition;

            Def.AddValue(Object.Ident);
            Def.AddValue(Name);
            Def.AddValue("");
            var Properties = Def.AddProperty("Properties70");

            var LocalStart = Properties.AddProperty("P");

            LocalStart.AddValue("LocalStart");
            LocalStart.AddValue("KTime");
            LocalStart.AddValue("Time");
            LocalStart.AddValue("");
            LocalStart.AddValue(FbxHelper.GetFbxSeconds(Anim.LocalStartTime));

            var LocalStop = Properties.AddProperty("P");

            LocalStop.AddValue("LocalStop");
            LocalStop.AddValue("KTime");
            LocalStop.AddValue("Time");
            LocalStop.AddValue("");
            LocalStop.AddValue(FbxHelper.GetFbxSeconds(Anim.LocalEndTime));

            var ReferenceStart = Properties.AddProperty("P");

            ReferenceStart.AddValue("ReferenceStart");
            ReferenceStart.AddValue("KTime");
            ReferenceStart.AddValue("Time");
            ReferenceStart.AddValue("");
            ReferenceStart.AddValue(FbxHelper.GetFbxSeconds(Anim.ReferenceStartTime));

            var ReferenceStop = Properties.AddProperty("P");

            ReferenceStop.AddValue("ReferenceStop");
            ReferenceStop.AddValue("KTime");
            ReferenceStop.AddValue("Time");
            ReferenceStop.AddValue("");
            ReferenceStop.AddValue(FbxHelper.GetFbxSeconds(Anim.ReferenceEndTime));

            /*
             * AnimationStack: 362632224, "AnimStack::Take 001", "" {
             * Properties70:
             *      {
             *      P: "LocalStart", "KTime", "Time", "",0
             *      P: "LocalStop", "KTime", "Time", "", 46186158000
             *      P: "ReferenceStart", "KTime", "Time", "",0
             *      P: "ReferenceStop", "KTime", "Time", "", 46186158000
             * }
             */
            return(Object);
        }
예제 #5
0
        static FbxObject CreateFbxObject_Material(string MaterialName, FbxObjectManager ObjectManager)
        {
            var Name   = "Material::" + MaterialName;
            var Object = ObjectManager.CreateObject("Material", Name);

            var Model = Object.Definition;

            Model.AddValue(Object.Ident);
            Model.AddValue(Name);
            Model.AddValue("");
            return(Object);
        }
예제 #6
0
        static FbxObject CreateAnimLayerObject(FbxObjectManager ObjectManager)
        {
            var Name   = "AnimLayer::BaseLayer";
            var Object = ObjectManager.CreateObject("AnimationLayer", Name);

            Object.Definition.AddValue(Object.Ident);
            Object.Definition.AddValue(Name);
            Object.Definition.AddValue("");
            //AnimationLayer: 3445458688, , "AnimLayer::BaseLayer" {
            Object.Definition.AddProperty("Dummy");
            return(Object);
        }
예제 #7
0
        static FbxObject CreateFbxObject(NodeAttribute Attrib, FbxObjectManager ObjectManager)
        {
            var Name = "NodeAttribute::" + Attrib.Name;

            FbxObject Object;

            Object = ObjectManager.CreateObject("NodeAttribute", Name);

            var Model = Object.Definition;

            Model.AddValue(Object.Ident);
            Model.AddValue(Name);
            Model.AddValue("Camera");

            Model.AddProperty("TypeFlags", "Camera");
            Model.AddProperty("GeometryVersion", 124);
            Model.AddProperty("Position", Vector3.zero);
            Model.AddProperty("Up", Vector3.up);
            Model.AddProperty("LookAt", Vector3.forward);

            return(Object);
        }
예제 #8
0
        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);
        }
예제 #9
0
        static FbxObject CreateFbxObject(Mesh mesh, Matrix4x4 transform, FbxObjectManager ObjectManager, int?ExplicitIdent = null)
        {
            //var Object = ObjectManager.CreateObject(mesh.name);
            //Object.Definition = new FbxProperty("Model");

            var Name = "Model::" + mesh.name;

            FbxObject Object;

            if (ExplicitIdent.HasValue)
            {
                Object = ObjectManager.CreateObject(ExplicitIdent.Value, "Model", Name);
            }
            else
            {
                Object = ObjectManager.CreateObject("Model", Name);
            }

            var Model = Object.Definition;

            Model.AddValue(Object.Ident);
            Model.AddValue(Name);
            Model.AddValue("Mesh");

            Model.AddProperty("Version", 232);
            Model.AddProperty("Vertices", new FbxValue_Floats(mesh.vertices, (n) => { return(transform.MultiplyPoint(n)); }));
            //	indexes start at 1, and last in poly is negative
            var FbxIndexes = GetMeshIndexes(mesh.GetIndices(0), mesh.GetTopology(0));

            Model.AddProperty("PolygonVertexIndex", new FbxValue_Ints(FbxIndexes));
            Model.AddProperty("GeometryVersion", 124);

            int LayerNumber = 0;
            var NormalLayer = Model.AddProperty("LayerElementNormal", LayerNumber);

            NormalLayer.AddProperty("Version", 101);
            NormalLayer.AddProperty("Name", "");
            //	ByPolygon	It means that there is a normal for every polygon of the model.
            //	ByPolygonVertex	It means that there is a normal for every vertex of every polygon of the model.
            //	ByVertex	It means that there is a normal for every vertex of the model.
            //	gr: ByVertex "Unsupported wedge mapping mode type.Please report this bug."
            //		even though I think that's the right one to use.. as ByPolygonVertex looks wrong
            NormalLayer.AddProperty("MappingInformationType", "ByPolygonVertex");
            NormalLayer.AddProperty("ReferenceInformationType", "Direct");
            NormalLayer.AddProperty("Normals", new FbxValue_Floats(mesh.normals, (n) => { return(transform.MultiplyVector(n)); }));

            var Layer = Model.AddProperty("Layer", LayerNumber);

            Layer.AddProperty("Version", 100);
            var len = Layer.AddProperty("LayerElement");

            len.AddProperty("Type", "LayerElementNormal");
            len.AddProperty("TypedIndex", 0);
            var les = Layer.AddProperty("LayerElement");

            les.AddProperty("Type", "LayerElementSmoothing");
            les.AddProperty("TypedIndex", 0);
            var leuv = Layer.AddProperty("LayerElement");

            leuv.AddProperty("Type", "LayerElementUV");
            leuv.AddProperty("TypedIndex", 0);
            var let = Layer.AddProperty("LayerElement");

            let.AddProperty("Type", "LayerElementTexture");
            let.AddProperty("TypedIndex", 0);
            var lem = Layer.AddProperty("LayerElement");

            lem.AddProperty("Type", "LayerElementMaterial");
            lem.AddProperty("TypedIndex", 0);

            return(Object);
        }
예제 #10
0
        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;
            }
        }
예제 #11
0
        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"));
            }
        }