Beispiel #1
0
        public static List <Bone> GetBoneHierarchy(FBXTreeNode node, FBXFile fbx)
        {
            var bones      = new List <Bone>();
            var modelNodes = node.Children.Where(a => a.Node.Name == "Model");

            foreach (var child in modelNodes)
            {
                var model = new Model(child.Node, fbx);

                if (model.ModelType == Model.FBXModelType.LimbNode || (model.ModelType == Model.FBXModelType.None && !model.HasGeometry))
                {
                    var children = GetBoneHierarchy(child, fbx);

                    var t = model.LclTranslation;
                    var r = model.LclRotation.ToRadians().QuaternionFromEuler(EulerOrder.XYZ);
                    var s = model.LclScaling;

                    var deformerId = fbx.Connections.Where(a => a.Src == model.Id && fbx.FindChild(a.Dst).Name == "Deformer").FirstOrDefault();
                    var globalInverseMatrix = new float[] { }.IdentityMatrix();

                    if (deformerId != null)
                    {
                        var deformer = new Deformer(fbx.FindChild(deformerId.Dst));
                    }

                    var bone = new Bone()
                    {
                        Id          = model.Id.ToString(),
                        Parent      = (node.Node != null) ? node.Node.Id.ToString() : "",
                        Children    = children.Select(a => a.Id).ToList(),
                        JointMatrix = new float[] { }.MatrixCompose(t, r, s),
                        Name        = model.Name
                    };

                    bone.Keyframes = GetBoneKeyFrames(bone, fbx);

                    bones.Add(bone);

                    bones.AddRange(children);
                }
            }

            return(bones);
        }
Beispiel #2
0
        public static List <Bone> GetBoneHierarchy(FBXFile file, FBXTreeNode current = null)
        {
            var bones = new List <Bone>();

            if (current == null)
            {
                current = file.RootNode;
            }

            var children = current.Children
                           .Where(a => a.Node.Name == "Model")
                           .Select(a => new Model(a.Node, file))
                           .Where(a => a.ModelType == Model.FBXModelType.LimbNode || (a.ModelType == Model.FBXModelType.None && !a.HasGeometry));

            foreach (var node in children)
            {
                var t = node.LclTranslation;
                var r = node.LclRotation.ToRadians().QuaternionFromEuler(EulerOrder.XYZ);
                var s = node.LclScaling;

                var bone = new Bone()
                {
                    Parent      = current.Node == null ? "" : current.Node.Id.ToString(),
                    JointMatrix = new float[] { }.MatrixCompose(t, r, s),
                    Id          = node.Id.ToString(),
                    Name        = node.Name
                };

                bone.Keyframes = GetBoneKeyFrames(bone, file);

                var childrenHier = GetBoneHierarchy(file, current.Children.Where(a => a.Node.Id == node.Id).FirstOrDefault());

                bone.Children = childrenHier.Where(a => a.Parent == bone.Id).Select(a => a.Id).ToList();

                bones.Add(bone);

                bones.AddRange(childrenHier);
            }

            return(bones);
        }