Exemplo n.º 1
0
        public static void ParseGeometryFromNode(Collada_Node geom_node, Matrix4 transform, ref Dictionary <string, Color> colorNodes, ref List <ColladaGeometry> geometries, ref Dictionary <string, Collada_Geometry> geometryNodes, ref Dictionary <string, Collada_Node> nodeNodes)
        {
            //if there is no matrix...
            if (geom_node.Matrix == null)
            {
                transform = new Matrix4(
                    1, 0, 0, 0, //x_x, x_y, x_z, t
                    0, 1, 0, 0, //y_x, y_y, y_z, t
                    0, 0, 1, 0, //z_x, z_y, z_z, t
                    0, 0, 0, 1
                    );
            }
            else
            {
                //get the matrix
                float[] matrix = geom_node.Matrix[0].Value();
                //map to the transform
                //      [axis]_x                  [axis]_y                   [axis]_z                [axis]_transform
                transform.M11 = matrix[0]; transform.M12 = matrix[1]; transform.M13 = matrix[2]; transform.M14 = matrix[3];   //X axis
                transform.M21 = matrix[4]; transform.M22 = matrix[5]; transform.M23 = matrix[6]; transform.M24 = matrix[7];   //Y axis
                transform.M31 = matrix[8]; transform.M32 = matrix[9]; transform.M33 = matrix[10]; transform.M34 = matrix[11]; //Z axis
                transform.M41 = 0; transform.M42 = matrix[9]; transform.M43 = matrix[10]; transform.M44 = matrix[11];         //W axis
            }
            //and now process the geometry
            if (geom_node.Instance_Geometry != null)
            {
                foreach (Collada_Instance_Geometry geometry in geom_node.Instance_Geometry)
                {
                    //build a dictionary of materials
                    Dictionary <string, Color> Materials = new Dictionary <string, Color>();
                    foreach (Collada_Instance_Material_Geometry materialName in
                             geometry.Bind_Material[0].Technique_Common.Instance_Material)
                    {
                        Materials.Add(materialName.Symbol, colorNodes[materialName.Target]);
                    }
                    //and get the actual geometry
                    geometries.Add(parseGeometry(transform, geometryNodes[geometry.URL], Materials));
                }
            }
            //and now process the sub nodes
            if (geom_node.Instance_Node != null)
            {
                foreach (Collada_Instance_Node node in geom_node.Instance_Node)
                {
                    nodeNodes[node.URL].Matrix = geom_node.Matrix;

                    ParseGeometryFromNode(nodeNodes[node.URL], transform, ref colorNodes, ref geometries, ref geometryNodes, ref nodeNodes);
                }
            }
            else
            {
                //DEBUG LOGGING
                DebugTools.Log("[Model Loader]: Geometry missing in node with ID " + geom_node.ID);
            }
        }
Exemplo n.º 2
0
 public static void recursiveAddNodes(Collada_Node node, ref Dictionary <string, Collada_Node> nodeNodes)
 {
     if (node.ID != null)
     {
         nodeNodes.Add("#" + node.ID, node);
     }
     else
     {
         nodeNodes.Add("#" + node.Name, node);
     }
     if (node.node != null)
     {
         foreach (Collada_Node node_sub in node.node)
         {
             recursiveAddNodes(node_sub, ref nodeNodes);
         }
     }
 }