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" ) ) ) ) ); }
public TexCoordGen(EndianBinaryReader er) { Unknown1 = er.ReadByte(); Source = (TexCoordSource)er.ReadByte(); Unknown2 = er.ReadUInt16(); }
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" ) ) ) ) ); }