public void Read(XmlNode root)
            {
                source = (string)root.Attributes["source"].Value;

                foreach (XmlNode node in root.ChildNodes)
                {
                    if (node.Name.Equals("bind_shape_matrix"))
                    {
                        string[] data = node.InnerText.Trim().Replace("\n", " ").Split(' ');
                        mat.M11 = float.Parse(data[0]); mat.M12 = float.Parse(data[1]); mat.M13 = float.Parse(data[2]); mat.M14 = float.Parse(data[3]);
                        mat.M21 = float.Parse(data[4]); mat.M22 = float.Parse(data[5]); mat.M23 = float.Parse(data[6]); mat.M24 = float.Parse(data[7]);
                        mat.M31 = float.Parse(data[8]); mat.M32 = float.Parse(data[9]); mat.M33 = float.Parse(data[10]); mat.M34 = float.Parse(data[11]);
                        mat.M41 = float.Parse(data[12]); mat.M42 = float.Parse(data[13]); mat.M43 = float.Parse(data[14]); mat.M44 = float.Parse(data[15]);
                    }
                    if (node.Name.Equals("source"))
                    {
                        ColladaSource source = new ColladaSource();
                        source.Read(node);
                        sources.Add(source);
                    }
                    if (node.Name.Equals("joints"))
                    {
                        joints.Read(node);
                    }
                    if (node.Name.Equals("vertex_weights"))
                    {
                        weights.Read(node);
                    }
                }
            }
 public void Read(XmlNode root)
 {
     foreach (XmlNode node in root.ChildNodes)
     {
         if (node.Name.Equals("source"))
         {
             ColladaSource source = new ColladaSource();
             source.Read(node);
             sources.Add(source);
         }
         if (node.Name.Equals("vertices"))
         {
             vertices.Read(node);
         }
         if (node.Name.Equals("triangles"))
         {
             ColladaPolygons source = new ColladaPolygons();
             source.type = ColladaPrimitiveType.triangles;
             source.Read(node);
             polygons.Add(source);
         }
         if (node.Name.Equals("polylist"))
         {
             ColladaPolygons source = new ColladaPolygons();
             source.type = ColladaPrimitiveType.polylist;
             source.Read(node);
             polygons.Add(source);
         }
     }
 }
Esempio n. 3
0
            public ColladaVertices(ColladaRoot collada, XElement node) : base(collada, node, "")
            {
                XElement xElement = node.Element(ColladaRoot.Namespace + "input");

                Semantic = xElement.Attribute("semantic").Value;
                Source   = (ColladaSource)collada.ObjectsById[xElement.Attribute("source").Value.Substring(1)];
            }
Esempio n. 4
0
 private void ImportSources()
 {
     Sources = new Dictionary <String, ColladaSource>();
     foreach (var item in Animation.Items)
     {
         if (item is source)
         {
             var src = ColladaSource.FromCollada(item as source);
             Sources.Add(src.id, src);
         }
     }
 }
Esempio n. 5
0
            public ColladaInput(ColladaRoot collada, XElement node)
            {
                Offset   = int.Parse(node.Attribute("offset").Value, CultureInfo.InvariantCulture);
                Semantic = node.Attribute("semantic").Value;
                XAttribute xAttribute = node.Attribute("set");

                if (xAttribute != null)
                {
                    Set = int.Parse(xAttribute.Value, CultureInfo.InvariantCulture);
                }
                ColladaNameId colladaNameId = collada.ObjectsById[node.Attribute("source").Value.Substring(1)];

                if (colladaNameId is ColladaVertices)
                {
                    ColladaVertices colladaVertices = (ColladaVertices)colladaNameId;
                    Source   = colladaVertices.Source;
                    Semantic = colladaVertices.Semantic;
                    return;
                }
                Source = (ColladaSource)colladaNameId;
            }
Esempio n. 6
0
        private void ImportSampler()
        {
            sampler sampler = null;

            foreach (var item in Animation.Items)
            {
                if (item is sampler)
                {
                    sampler = item as sampler;
                    break;
                }
            }

            if (sampler == null)
            {
                throw new ParsingException("Animation " + Animation.id + " has no sampler!");
            }

            ColladaSource inputSource = null, outputSource = null, interpolationSource = null;

            foreach (var input in sampler.input)
            {
                if (input.source[0] != '#')
                {
                    throw new ParsingException("Only ID references are supported for animation input sources");
                }

                ColladaSource source;
                if (!Sources.TryGetValue(input.source.Substring(1), out source))
                {
                    throw new ParsingException("Animation sampler " + input.semantic + " references nonexistent source: " + input.source);
                }

                switch (input.semantic)
                {
                case "INPUT":
                    inputSource = source;
                    break;

                case "OUTPUT":
                    outputSource = source;
                    break;

                case "INTERPOLATION":
                    interpolationSource = source;
                    break;

                default:
                    break;
                }
            }

            if (inputSource == null || outputSource == null || interpolationSource == null)
            {
                throw new ParsingException("Animation " + Animation.id + " must have an INPUT, OUTPUT and INTERPOLATION sampler input!");
            }

            if (!inputSource.FloatParams.TryGetValue("TIME", out Times))
            {
                Times = inputSource.FloatParams.Values.SingleOrDefault();
            }

            if (Times == null)
            {
                throw new ParsingException("Animation " + Animation.id + " INPUT must have a TIME parameter!");
            }

            if (!outputSource.MatrixParams.TryGetValue("TRANSFORM", out Transforms))
            {
                Transforms = outputSource.MatrixParams.Values.SingleOrDefault();
            }

            if (Transforms == null)
            {
                throw new ParsingException("Animation " + Animation.id + " OUTPUT must have a TRANSFORM parameter!");
            }

            if (Transforms.Count != Times.Count)
            {
                throw new ParsingException("Animation " + Animation.id + " has different time and transform counts!");
            }

            for (var i = 0; i < Transforms.Count; i++)
            {
                var m = Transforms[i];
                m.Transpose();
                Transforms[i] = m;
            }
        }
Esempio n. 7
0
            private void genericAttributes(ref XmlTextReader reader)
            {
                if (reader.Name == "source" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaSource(ref reader, this, scene);
                }

                if (reader.Name == "vertices" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaVerts(ref reader, this, scene);
                }

                if (reader.Name == "library_animations" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaLibraryAnimation(ref reader, this, scene);
                }

                if (reader.Name == "animation" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaAnimation(ref reader, this, scene);
                }

                if (reader.Name == "controller" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaControler(ref reader, this, scene);
                }

                if (reader.Name == "polylist" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaPolys(ref reader, this, scene);
                }
                /*
                if (reader.Name == "visual_scene")
                {
                    ColladaObject newObj = new ColladaVScene(ref reader, this, scene);
                    scene.colladaObjects.Add(newObj);
                }
                */
                if (reader.Name == "vertex_weights" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaVertWeights(ref reader, this, scene);
                }

                if (reader.Name == "node" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaNode(ref reader, this, scene);
                }

                if (reader.Name == "input")
                    inputs.Add(new ColladaInput(ref reader, this, scene));
            }