Esempio n. 1
0
        private void ReadPolygons(DataReader r)
        {
            Console.WriteLine(r.Position.ToString("x"));
            r.Skip(4);
            uint next = r.Position + r.ReadUInt32() - 4;

            int count = r.ReadInt32();

            var faceoffset = 0;

            //List<int> DesOfRoot = DecendentsOf(Root);
            for (int i = 0; i < count; i++)
            {
                G1MPolygon p  = new G1MPolygon();
                var        un = r.ReadInt32();
                p.UnknownIndex     = r.ReadInt32();
                p.BoneTableIndex   = r.ReadInt32();
                p.relatedToBones   = r.ReadInt32();
                p.TextureCount     = r.ReadInt32();
                p.MaterialIndex    = r.ReadInt32();
                p.TextureBankIndex = r.ReadInt32();// Materials[];
                p.Buffer           = r.ReadInt32();
                r.Skip(0x4);
                r.Skip(0x4); // format 1 = triangle 4 = strips
                r.Skip(0x8); // vertex offset and count
                p.FaceOffset = r.ReadInt32();
                p.FaceCount  = r.ReadInt32();
                faceoffset  += p.FaceCount;
                p.Name       = "Polygon_" + i;
                Polygons.Add(p);
            }
            r.Seek(next);
        }
Esempio n. 2
0
        public List <uint> GetIndices(G1MPolygon poly)
        {
            var indices = IndexBuffers[poly.Buffer];

            List <uint> vertices = new List <uint>();

            for (int i = poly.FaceOffset; i < poly.FaceOffset + poly.FaceCount; i++)
            {
                vertices.Add(indices[i]);
            }

            return(vertices);
        }
Esempio n. 3
0
        public List <GenericVertex> GetVertices(G1MPolygon poly, out List <uint> indices, bool getWeights)
        {
            indices = new List <uint>();

            var buff = GetVertex(poly.Buffer);

            var indBuff = GetIndices(poly);

            Dictionary <ushort, uint> indexToIndex = new Dictionary <ushort, uint>();
            List <GenericVertex>      vertices     = new List <GenericVertex>();

            foreach (ushort i in indBuff)
            {
                if (indexToIndex.ContainsKey(i))
                {
                    indices.Add(indexToIndex[i]);
                    continue;
                }

                var vert = buff[i];
                if (vert.Weights == Vector4.Zero)
                {
                    vert.Bones   = new Vector4(BindMatches[poly.BoneTableIndex][0], 0, 0, 0);
                    vert.Weights = new Vector4(1, 0, 0, 0);
                }
                else if (getWeights)
                {
                    //Console.WriteLine(BindMatches[poly.BoneTableIndex].Length + " " + vert.Bones.ToString() + " " + vert.Weights.ToString());
                    vert.Bones = new Vector4(BindMatches[poly.BoneTableIndex][(int)vert.Bones.X / 3],
                                             BindMatches[poly.BoneTableIndex][(int)vert.Bones.Y / 3],
                                             BindMatches[poly.BoneTableIndex][(int)vert.Bones.Z / 3],
                                             BindMatches[poly.BoneTableIndex][(int)vert.Bones.W / 3]);
                }

                /*if (vert.Bones.X >= myStart - 1 && myStart != 0)
                 * {
                 *  //Console.WriteLine(myStart + " " + p.vBuffer[ib[j]].node.ToString());
                 *  p.vBuffer[ib[j]].pos = Vector3.Transform(p.vBuffer[ib[j]].pos,
                 *      Root.transform);
                 * }*/

                indexToIndex.Add(i, (uint)vertices.Count);
                indices.Add((uint)vertices.Count);
                vertices.Add(vert);
            }

            return(vertices);

            //return vertices;
        }