Exemplo n.º 1
0
            public Geometry(Collada document, string geometryname, List <Triangle> triangles)
                : base(ns + "geometry", geometryname)
            {
                this.Symbol = geometryname;
                Dictionary <string, List <Triangle> > trilists = new Dictionary <string, List <Triangle> >();

                this.VertexList = new List <Vertex>();
                this.Materials  = new List <Material>();
                Dictionary <object, int> vtxrevindex = new Dictionary <object, int>();

                foreach (Triangle triangle in triangles)
                {
                    if (!trilists.ContainsKey(triangle.Texture.Name))
                    {
                        trilists[triangle.Texture.Name] = new List <Triangle>();
                        Material material = document.GetOrCreateMaterial(triangle.Texture);
                        Materials.Add(material);
                    }
                    trilists[triangle.Texture.Name].Add(triangle);
                    foreach (Vertex vertex in new Vertex[] { triangle.A, triangle.B, triangle.C })
                    {
                        if (!vtxrevindex.ContainsKey(vertex))
                        {
                            vtxrevindex[vertex] = VertexList.Count;
                            VertexList.Add(vertex);
                        }
                    }
                }

                PositionSource = new Source(geometryname + "_pos", "POSITION", VertexList.Select(v => v.Position), VertexList.Count);
                TexcoordSource = new TexCoordSource(geometryname + "_tex", "TEXCOORD", VertexList.Select(v => v.TexCoord), VertexList.Count, Materials);
                NormalSource   = VertexList[0].Normal != Vector4.Zero ? new Source(geometryname + "_normal", "NORMAL", VertexList.Select(v => v.Normal), VertexList.Count) : null;
                TangentSource  = VertexList[0].Tangent != Vector4.Zero ? new Source(geometryname + "_tangent", "TANGENT", VertexList.Select(v => v.Tangent), VertexList.Count) : null;
                BinormalSource = VertexList[0].Binormal != Vector4.Zero ? new Source(geometryname + "_binormal", "BINORMAL", VertexList.Select(v => v.Binormal), VertexList.Count) : null;
                VertexSource   = new VerticesSource(geometryname + "_vtx", "VERTEX", PositionSource, NormalSource, TangentSource, BinormalSource);

                this.Add(
                    new XElement(ns + "mesh",
                                 PositionSource,
                                 TexcoordSource,
                                 NormalSource,
                                 TangentSource,
                                 BinormalSource,
                                 VertexSource,
                                 Materials.Select(m =>
                                                  new XElement(ns + "triangles",
                                                               new XAttribute("count", trilists[m.Effect.Image.Texture.Name].Count),
                                                               new XAttribute("material", m.ID),
                                                               VertexSource.GetInput(0),
                                                               TexcoordSource.GetInput(1, m),
                                                               new XElement(ns + "p",
                                                                            "\n",
                                                                            String.Join("\n", trilists[m.Effect.Image.Texture.Name].Select(t => String.Join("  ", new Vertex[] { t.A, t.B, t.C }.Select(v => String.Format("{0} {0}", vtxrevindex[v]))))),
                                                                            "\n"
                                                                            )
                                                               )
                                                  )
                                 )
                    );
            }
Exemplo n.º 2
0
 public void Save(Action onsave, Action oncomplete)
 {
     if (IsValidFactory() && (overwrite || !File.Exists(Filename)))
     {
         onsave();
         Collada.Save(Filename, MeshFactory(), SkeletonFactory(), ExtraDataFactory(), CreateTime, ModTime);
         oncomplete();
     }
 }
Exemplo n.º 3
0
        public static void Save(string filename, IEnumerable <List <Triangle> > meshes, Joint rootjoint, IEnumerable <XElement> extradata, DateTime creattime, DateTime modtime)
        {
            string dir = Path.GetDirectoryName(filename);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            string path = Path.Combine(".", Path.Combine(Path.GetDirectoryName(filename).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Where(d => d != "." && d != "..").Select(d => "..").ToArray()));

            XDocument doc = new Collada(meshes, rootjoint, extradata, path, creattime, modtime);

            doc.Save(filename);
            File.SetLastWriteTimeUtc(filename, modtime);
        }
Exemplo n.º 4
0
            public Geometry(Collada document, string geometryname, List<Triangle> triangles)
                : base(ns + "geometry", geometryname)
            {
                this.Symbol = geometryname;
                Dictionary<string, List<Triangle>> trilists = new Dictionary<string,List<Triangle>>();
                this.VertexList = new List<Vertex>();
                this.Materials = new List<Material>();
                Dictionary<object, int> vtxrevindex = new Dictionary<object, int>();

                foreach (Triangle triangle in triangles)
                {
                    if (!trilists.ContainsKey(triangle.Texture.Name))
                    {
                        trilists[triangle.Texture.Name] = new List<Triangle>();
                        Material material = document.GetOrCreateMaterial(triangle.Texture);
                        Materials.Add(material);
                    }
                    trilists[triangle.Texture.Name].Add(triangle);
                    foreach (Vertex vertex in new Vertex[] { triangle.A, triangle.B, triangle.C })
                    {
                        if (!vtxrevindex.ContainsKey(vertex))
                        {
                            vtxrevindex[vertex] = VertexList.Count;
                            VertexList.Add(vertex);
                        }
                    }
                }

                PositionSource = new Source(geometryname + "_pos", "POSITION", VertexList.Select(v => v.Position), VertexList.Count);
                TexcoordSource = new TexCoordSource(geometryname + "_tex", "TEXCOORD", VertexList.Select(v => v.TexCoord), VertexList.Count, Materials);
                NormalSource = VertexList[0].Normal != Vector4.Zero ? new Source(geometryname + "_normal", "NORMAL", VertexList.Select(v => v.Normal), VertexList.Count) : null;
                TangentSource = VertexList[0].Tangent != Vector4.Zero ? new Source(geometryname + "_tangent", "TANGENT", VertexList.Select(v => v.Tangent), VertexList.Count) : null;
                BinormalSource = VertexList[0].Binormal != Vector4.Zero ? new Source(geometryname + "_binormal", "BINORMAL", VertexList.Select(v => v.Binormal), VertexList.Count) : null;
                VertexSource = new VerticesSource(geometryname + "_vtx", "VERTEX", PositionSource, NormalSource, TangentSource, BinormalSource);

                this.Add(
                    new XElement(ns + "mesh",
                        PositionSource,
                        TexcoordSource,
                        NormalSource,
                        TangentSource,
                        BinormalSource,
                        VertexSource,
                        Materials.Select(m =>
                            new XElement(ns + "triangles",
                                new XAttribute("count", trilists[m.Effect.Image.Texture.Name].Count),
                                new XAttribute("material", m.ID),
                                VertexSource.GetInput(0),
                                TexcoordSource.GetInput(1, m),
                                new XElement(ns + "p",
                                    "\n",
                                    String.Join("\n", trilists[m.Effect.Image.Texture.Name].Select(t => String.Join("  ", new Vertex[] { t.A, t.B, t.C }.Select(v => String.Format("{0} {0}", vtxrevindex[v]))))),
                                    "\n"
                                )
                            )
                        )
                    )
                );
            }
Exemplo n.º 5
0
        public static void Save(string filename, IEnumerable<List<Triangle>> meshes, Joint rootjoint, IEnumerable<XElement> extradata, DateTime creattime, DateTime modtime)
        {
            string dir = Path.GetDirectoryName(filename);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            string path = Path.Combine(".", Path.Combine(Path.GetDirectoryName(filename).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Where(d => d != "." && d != "..").Select(d => "..").ToArray()));

            XDocument doc = new Collada(meshes, rootjoint, extradata, path, creattime, modtime);
            doc.Save(filename);
            File.SetLastWriteTimeUtc(filename, modtime);
        }