Example #1
0
        public Connection(FBXFileNode node)
        {
            Relation = (string)node.Properties[0].Data;
            Src      = (long)node.Properties[1].Data;
            Dst      = (long)node.Properties[2].Data;

            if (node.Properties.Count > 3)
            {
                ConnectionType = (string)node.Properties[3].Data;
            }
        }
Example #2
0
        // Gets a single timestamp component
        static int GetTimestampVar(FBXFileNode timestamp, string element)
        {
            var elementNode = timestamp.Nodes.Where(a => a.Name == element).FirstOrDefault();

            if (elementNode != null && elementNode.Properties.Count > 0)
            {
                var prop = elementNode.Properties[0];

                if (prop.Data is int || prop.Data is long)
                {
                    return((int)prop.Data);
                }
            }
            throw new Exception("Timestamp has no " + element);
        }
Example #3
0
        public FBXFile(Stream stream)
        {
            // The first 27 bytes contain the header
            var valid = ReadHeader(stream);

            if (!valid)
            {
                throw new Exception("Invalid header string.");
            }

            //read the version
            var uintBuffer = new byte[4];

            stream.Read(uintBuffer, 0, 4);
            Version = BitConverter.ToUInt32(uintBuffer, 0);

            // Read nodes
            while (stream.Position < stream.Length)
            {
                var node = new FBXFileNode(stream);

                if (node.IsNull)
                {
                    break;
                }

                Nodes.Add(node);
            }

            // read the footer code
            var footerCode = new byte[footerCodeSize];

            stream.Read(footerCode, 0, footerCode.Length);

            var validCode = GenerateFooterCode();

            if (!CheckEqual(footerCode, validCode))
            {
                throw new Exception("Incorrect footer code");
            }

            // Read footer extension
            var validFooterExtension = CheckFooter(stream);

            /*if (!validFooterExtension)
             *  throw new Exception("Invalid footer");*/
        }
Example #4
0
        public Deformer(FBXFileNode node)
        {
            Id   = (long)node.Properties[0].Data;
            Name = ((string)node.Properties[1].Data);

            switch ((string)node.Properties[2].Data)
            {
            case "Skin":
                DeformerType = FBXDeformerType.Skin;
                break;

            case "Cluster":
                DeformerType = FBXDeformerType.Cluster;
                break;
            }

            if (DeformerType == FBXDeformerType.Cluster)
            {
                var indexesNode = node.Nodes.Where(a => a.Name == "Indexes").FirstOrDefault();

                if (indexesNode != null)
                {
                    Indexes = (int[])indexesNode.Properties[0].Data;
                }

                var weightsNode = node.Nodes.Where(a => a.Name == "Weights").FirstOrDefault();

                if (weightsNode != null)
                {
                    Weights = ((double[])weightsNode.Properties[0].Data).Select(a => (float)a).ToArray();
                }

                var transformNode = node.Nodes.Where(a => a.Name == "Transform").FirstOrDefault();

                if (transformNode != null)
                {
                    Transform = ((double[])transformNode.Properties[0].Data).Select(a => (float)a).ToArray();
                }

                var transformLinkNode = node.Nodes.Where(a => a.Name == "TransformLink").FirstOrDefault();

                if (transformLinkNode != null)
                {
                    TransformLink = ((double[])transformLinkNode.Properties[0].Data).Select(a => (float)a).ToArray();
                }
            }
        }
Example #5
0
        public FBXFileNode(Stream stream)
        {
            var uintBuffer = new byte[4];

            stream.Read(uintBuffer, 0, 4);
            EndOffset = BitConverter.ToUInt32(uintBuffer, 0);

            stream.Read(uintBuffer, 0, 4);
            NumProperties = BitConverter.ToUInt32(uintBuffer, 0);

            stream.Read(uintBuffer, 0, 4);
            PropertyListLen = BitConverter.ToUInt32(uintBuffer, 0);

            NameLen = (byte)stream.ReadByte();

            var stringBuffer = new byte[NameLen];

            stream.Read(stringBuffer, 0, NameLen);
            Name = System.Text.ASCIIEncoding.ASCII.GetString(stringBuffer);

            //if the endoffset is 0 the node is null
            if (EndOffset == 0)
            {
                IsNull = true;
                return;
            }

            //read properties
            for (var i = 0; i < NumProperties; i++)
            {
                Properties.Add(new Property(stream));
            }

            // read nested nodes
            while (stream.Position < EndOffset)
            {
                var node = new FBXFileNode(stream);

                // the null node marks the end of nested nodes
                if (node.IsNull)
                {
                    return;
                }

                Nodes.Add(node);
            }
        }
Example #6
0
        public List <Animation.FBXAnimCurveNode> GetAnimationCurveNodes(FBXFileNode root = null)
        {
            var result = new List <Animation.FBXAnimCurveNode>();
            var nodes  = (root == null) ? Nodes : root.Nodes;

            foreach (var node in nodes)
            {
                if (node.Name == "AnimationCurveNode")
                {
                    result.Add(new Animation.FBXAnimCurveNode(node));
                }

                result.AddRange(GetAnimationCurveNodes(node));
            }

            return(result);
        }
Example #7
0
        public FBXTreeNode(FBXFileNode node, FBXFile file, FBXTreeNode parent = null)
        {
            Node = node;

            var nodeId = (Node != null) ? Node.Id : 0;

            var nodeConns = file.Connections.Where(a => a.Dst == nodeId);

            foreach (var con in nodeConns)
            {
                var childNode = file.FindChild(con.Src);

                if (childNode != null)
                {
                    Children.Add((new FBXTreeNode(childNode, file, this)));
                }
            }
        }
Example #8
0
        public Model(FBXFileNode node, FBXFile fbx)
        {
            Id   = node.Id;
            Name = ((string)node.Properties[1].Data);

            HasGeometry = node.Nodes.Where(a => a.Name == "Geometry").Count() > 0;

            switch ((string)node.Properties[2].Data)
            {
            case "Mesh":
                ModelType = FBXModelType.Mesh;
                break;

            case "LimbNode":
                ModelType = FBXModelType.LimbNode;
                break;
            }

            var propNode       = node.Nodes.Where(a => a.Name == "Properties70").FirstOrDefault();
            var rotationActive = true;

            // if(fbx.GlobalSettings != null && fbx.GlobalSettings.UnitScaleFactor != 0)
            //     Scaling = Scaling.SetScalingPart((float)fbx.GlobalSettings.UnitScaleFactor, (float)fbx.GlobalSettings.UnitScaleFactor, (float)fbx.GlobalSettings.UnitScaleFactor);

            if (propNode != null)
            {
                foreach (var child in propNode.Nodes)
                {
                    if (child.Name == "P")
                    {
                        var property = (string)child.Properties[0].Data;

                        switch (property)
                        {
                        case "PreRotation":
                            PreRotation = new float[]
                            {
                                (float)(double)child.Properties[4].Data,
                                (float)(double)child.Properties[5].Data,
                                (float)(double)child.Properties[6].Data
                            };
                            break;

                        case "Lcl Rotation":
                            LclRotation = new float[]
                            {
                                (float)(double)child.Properties[4].Data,
                                (float)(double)child.Properties[5].Data,
                                (float)(double)child.Properties[6].Data
                            };
                            break;

                        case "RotationActive":
                            rotationActive = (int)child.Properties[4].Data == 1;
                            break;

                        case "Lcl Translation":
                            LclTranslation = new float[]
                            {
                                (float)(double)child.Properties[4].Data,
                                (float)(double)child.Properties[5].Data,
                                (float)(double)child.Properties[6].Data
                            };
                            break;

                        case "Lcl Scaling":
                            LclScaling = new float[]
                            {
                                (float)(double)child.Properties[4].Data,
                                (float)(double)child.Properties[5].Data,
                                (float)(double)child.Properties[6].Data
                            };
                            break;

                        case "PostRotation":
                            PostRotation = new float[]
                            {
                                (float)(double)child.Properties[4].Data,
                                (float)(double)child.Properties[5].Data,
                                (float)(double)child.Properties[6].Data
                            };
                            break;

                        case "GeometricTranslation":
                            GeometricTranslation = new float[]
                            {
                                (float)(double)child.Properties[4].Data,
                                (float)(double)child.Properties[5].Data,
                                (float)(double)child.Properties[6].Data
                            };
                            break;

                        case "GeometricScaling":
                            GeometricScaling = new float[]
                            {
                                (float)(double)child.Properties[4].Data,
                                (float)(double)child.Properties[5].Data,
                                (float)(double)child.Properties[6].Data
                            };
                            break;

                        case "GeometricRotation ":
                            GeometricRotation = new float[]
                            {
                                (float)(double)child.Properties[4].Data,
                                (float)(double)child.Properties[5].Data,
                                (float)(double)child.Properties[6].Data
                            };
                            break;

                        case "InheritType":
                            InheritType = (InheritTypeOption)child.Properties[4].Data;
                            break;
                        }
                    }
                }
            }
        }
Example #9
0
 public PoseNode(FBXFileNode node, FBXFileNode parent)
 {
     Id         = (long)node.Nodes.Where(a => a.Name == "Node").FirstOrDefault()?.Properties[0].Data;
     Matrix     = ((double[])node.Nodes.Where(a => a.Name == "Matrix").FirstOrDefault()?.Properties[0].Data).Select(a => (float)a).ToArray().TransposeMatrix();
     IsBindPose = (parent.Properties.Count >= 3 && parent.Properties[2].Data is string) ? ((string)parent.Properties[2].Data) == "BindPose" : false;
 }