Esempio n. 1
0
        // Create linked list of all bones in skeleton
        private List <DAE_Bone> load(DAE_Bone parent_bone, Grendgine_Collada_Node[] bone_children)
        {
            if (bone_children != null)
            {
                List <DAE_Bone> children = new List <DAE_Bone>();

                foreach (Grendgine_Collada_Node child in bone_children)
                {
                    Matrix4 joint_matrix = EngineHelper.createMatrix(child.Matrix[0].Value());

                    // Add parent's joint matrix
                    joint_matrix = joint_matrix * parent_bone.JM;

                    DAE_Bone temp_bone = createBone(child.ID, parent_bone, joint_matrix);

                    if (child.node != null)
                    {
                        temp_bone.children = load(temp_bone, child.node);
                    }
                    children.Add(temp_bone);
                }

                return(children);
            }
            else
            {
                return(null);
            }
        }
        public DAE_Bone createBone(string name, DAE_Bone parent, Matrix4 joint_matrix)
        {
            DAE_Bone temp_bone = new DAE_Bone(_bone_id_incrementer, name, parent, joint_matrix);

            _bone_id_incrementer++;
            return(temp_bone);
        }
Esempio n. 3
0
 public DAE_Bone(int id, string name, DAE_Bone parent, Matrix4 joint_matrix)
 {
     _id     = id;
     _name   = name;
     _parent = parent;
     _JM     = joint_matrix;
     _IBM    = Matrix4.Identity;
 }
Esempio n. 4
0
        // Create new bone and add it to dictionaries
        private DAE_Bone createBone(string name, DAE_Bone parent, Matrix4 joint_matrix)
        {
            DAE_Bone temp_bone = new DAE_Bone(_bone_id_incrementer, name, parent, joint_matrix);

            _bones.Add(temp_bone.id, temp_bone);
            _bone_ids.Add(temp_bone.name, temp_bone.id);

            _bone_id_incrementer++;
            return(temp_bone);
        }
Esempio n. 5
0
        public DAE_Skeleton(string id, Matrix4 root_matrix, Grendgine_Collada_Node[] bone_nodes)
        {
            _id                  = id;
            _animated            = false;
            _bone_id_incrementer = 0;
            _bones               = new Dictionary <int, DAE_Bone>();
            _bone_ids            = new Dictionary <string, int>();
            _vertex_weights      = new Dictionary <int, VertexWeight[]>();

            // Setup root bone and load the rest
            _root          = createBone("root", null, root_matrix);
            _root.children = load(_root, bone_nodes);

            // Print Bone Structure
            //Console.WriteLine(getBoneStructure(_root, 0));
        }
Esempio n. 6
0
        public void updateBones(DAE_Bone parent, Dictionary <string, Matrix4> boneMatrices)
        {
            if (parent.children == null)
            {
                return;
            }
            else
            {
                foreach (DAE_Bone child in parent.children)
                {
                    Matrix4 temp_mat = child.JM;
                    boneMatrices.TryGetValue(child.name, out temp_mat);
                    child.JM = temp_mat * parent.JM;

                    updateBones(child, boneMatrices);
                }
                return;
            }
        }
Esempio n. 7
0
        // Traverse Skeleton and print bone hierarchy
        private string getBoneStructure(DAE_Bone bone, int level)
        {
            string output = "";
            string indent = "|";

            for (int i = 0; i < level; i++)
            {
                indent += '_';
            }
            output += indent + " [" + bone.id + "] " + bone.name;

            if (bone.children == null)
            {
                return(output);
            }
            else
            {
                foreach (DAE_Bone child in bone.children)
                {
                    output += "\n" + getBoneStructure(child, level + 1);
                }
                return(output);
            }
        }