Exemple #1
0
        public GenericMesh DisplayListToGenericMesh(N64DisplayList DL)
        {
            GenericMesh mesh = new GenericMesh();

            mesh.Name = "Mesh" + DL.faces.Count;

            foreach (int f in DL.faces)
            {
                mesh.Triangles.Add((uint)f);
            }

            foreach (N64Vertex_Normal nv in DL.verts)
            {
                mesh.Vertices.Add(new GenericVertex()
                {
                    Pos     = nv.pos,
                    Nrm     = nv.color.Xyz,
                    UV0     = nv.uv,
                    Bones   = new Vector4(nv.bone, 0, 0, 0),
                    Weights = new Vector4(1, 0, 0, 0)
                });
            }

            return(mesh);
        }
Exemple #2
0
        public static N64DisplayList ReadDisplayList(DataReader reader, int BoneIndex, Matrix4 Transform)
        {
            int            vbidindex = 0;
            int            vertIndex = 0;
            int            size = 0;
            bool           done = false;
            N64DisplayList list = new N64DisplayList();
            int            f1 = 0, f2 = 0, f3 = 0;

            while (!done)
            {
                //Console.WriteLine(reader.pos().ToString("x"));
                int key = reader.ReadByte();

                switch (key)
                {
                case 0x01:     // G_VTX
                    // just to offset
                    vertIndex = list.verts.Count;
                    size      = reader.ReadInt16() >> 4;
                    vbidindex = (reader.ReadByte() >> 1) - size;
                    int offset = reader.ReadInt32() & 0x1FFFF;

                    uint temp = reader.Position;
                    reader.Seek((uint)offset);
                    for (int v = 0; v < size; v++)
                    {
                        vertBuffer[vbidindex + v] = new N64Vertex_Normal()
                        {
                            pos   = new Vector3(reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16()),  // Vector3.Transform(, b == null ? Matrix4.CreateTranslation(0,0,0) : b.transform),
                            bone  = reader.ReadInt16(),
                            uv    = new Vector2((float)S10p5(reader.ReadInt16()), (float)S10p5(reader.ReadInt16())) / 32f,
                            color = new Vector4((sbyte)reader.ReadByte(), (sbyte)reader.ReadByte(), (sbyte)reader.ReadByte(), reader.ReadByte()) / sbyte.MaxValue
                        };
                        if (Transform != null)
                        {
                            vertBuffer[vbidindex + v].pos = Vector3.TransformPosition(vertBuffer[vbidindex + v].pos, Transform);
                            //if (!Transform.Inverted().Equals(Transform))
                            vertBuffer[vbidindex + v].color.Xyz = Vector3.TransformNormal(vertBuffer[vbidindex + v].color.Xyz, Transform);
                        }
                        vertBuffer[vbidindex + v].bone = BoneIndex;
                    }
                    reader.Seek(temp);

                    break;

                case 0x05:     // G_TRI1
                    f1 = reader.ReadByte() / 2;
                    f2 = reader.ReadByte() / 2;
                    f3 = reader.ReadByte() / 2;
                    reader.Skip(4);

                    //vertBuffer[f1].bone = BoneIndex;
                    //vertBuffer[f2].bone = BoneIndex;
                    //vertBuffer[f3].bone = BoneIndex;

                    if (!list.verts.Contains(vertBuffer[f1]))
                    {
                        list.verts.Add(vertBuffer[f1]);
                    }
                    if (!list.verts.Contains(vertBuffer[f2]))
                    {
                        list.verts.Add(vertBuffer[f2]);
                    }
                    if (!list.verts.Contains(vertBuffer[f3]))
                    {
                        list.verts.Add(vertBuffer[f3]);
                    }
                    list.faces.Add(list.verts.IndexOf(vertBuffer[f1]));
                    list.faces.Add(list.verts.IndexOf(vertBuffer[f2]));
                    list.faces.Add(list.verts.IndexOf(vertBuffer[f3]));
                    break;

                case 0x06:     // G_TRI2
                    f1 = reader.ReadByte() / 2;
                    f2 = reader.ReadByte() / 2;
                    f3 = reader.ReadByte() / 2;
                    //vertBuffer[f1].bone = BoneIndex;
                    //vertBuffer[f2].bone = BoneIndex;
                    //vertBuffer[f3].bone = BoneIndex;
                    if (!list.verts.Contains(vertBuffer[f1]))
                    {
                        list.verts.Add(vertBuffer[f1]);
                    }
                    if (!list.verts.Contains(vertBuffer[f2]))
                    {
                        list.verts.Add(vertBuffer[f2]);
                    }
                    if (!list.verts.Contains(vertBuffer[f3]))
                    {
                        list.verts.Add(vertBuffer[f3]);
                    }
                    list.faces.Add(list.verts.IndexOf(vertBuffer[f1]));
                    list.faces.Add(list.verts.IndexOf(vertBuffer[f2]));
                    list.faces.Add(list.verts.IndexOf(vertBuffer[f3]));
                    reader.Skip(1);
                    f1 = reader.ReadByte() / 2;
                    f2 = reader.ReadByte() / 2;
                    f3 = reader.ReadByte() / 2;
                    //vertBuffer[f1].bone = BoneIndex;
                    //vertBuffer[f2].bone = BoneIndex;
                    //vertBuffer[f3].bone = BoneIndex;
                    if (!list.verts.Contains(vertBuffer[f1]))
                    {
                        list.verts.Add(vertBuffer[f1]);
                    }
                    if (!list.verts.Contains(vertBuffer[f2]))
                    {
                        list.verts.Add(vertBuffer[f2]);
                    }
                    if (!list.verts.Contains(vertBuffer[f3]))
                    {
                        list.verts.Add(vertBuffer[f3]);
                    }
                    list.faces.Add(list.verts.IndexOf(vertBuffer[f1]));
                    list.faces.Add(list.verts.IndexOf(vertBuffer[f2]));
                    list.faces.Add(list.verts.IndexOf(vertBuffer[f3]));
                    break;

                case 0xD9:     // G_GEOMETRYMODE
                    reader.Skip(7);
                    break;

                case 0xDF:     // G_ENDDL
                    reader.Skip(7);
                    done = true;
                    break;

                default:
                    throw new Exception("Unknown Command " + key.ToString("x"));
                }
            }
            return(list);
        }