Exemple #1
0
        public void Save(string Path)
        {
            if (Materials.Count == 0)
            {
                return;
            }

            using (BEBinaryWriter bw = new BEBinaryWriter(new FileStream(Path, FileMode.Create)))
            {
                bw.WriteInt32(18);
                bw.WriteInt32(8);
                bw.WriteInt32(5);
                bw.WriteInt32(2);

                foreach (MATMaterial M in Materials)
                {
                    bw.Write(new byte[] { 0, 0, 0, 60 });
                    bw.WriteInt32(68 + M.Name.Length);

                    bw.Write(M.DiffuseColour);
                    bw.WriteSingle(M.AmbientLighting);
                    bw.WriteSingle(M.DirectionalLighting);
                    bw.WriteSingle(M.SpecularLighting);
                    bw.WriteSingle(M.SpecularPower);

                    bw.WriteInt32(M.Flags);

                    bw.WriteSingle(M.UVMatrix.M11);
                    bw.WriteSingle(M.UVMatrix.M12);
                    bw.WriteSingle(M.UVMatrix.M21);
                    bw.WriteSingle(M.UVMatrix.M22);
                    bw.WriteSingle(M.UVMatrix.M31);
                    bw.WriteSingle(M.UVMatrix.M32);

                    bw.Write(new byte[] { 10, 31, 0, 0 });                          //Unknown, seems to be a constant
                    bw.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); //13 bytes of nothing please!

                    bw.Write(M.Name.ToCharArray());
                    bw.WriteByte(0);

                    if (M.HasTexture)
                    {
                        bw.Write(new byte[] { 0, 0, 0, 28 });
                        bw.WriteInt32(M.Texture.Length + 1);
                        bw.Write(M.Texture.ToCharArray());
                        bw.WriteByte(0);
                    }

                    bw.Write(0);
                    bw.Write(0);
                }
            }
        }
Exemple #2
0
        public void Save(string path)
        {
            using (FileStream fs = new FileStream(path, FileMode.Create))
                using (BEBinaryWriter bw = new BEBinaryWriter(fs, Encoding.Default))
                {
                    int length;

                    bw.WriteInt32(0x12); // Magic Number
                    bw.WriteInt32(0x8);  //
                    bw.WriteInt32(0x1);  //
                    bw.WriteInt32(0x2);  //

                    foreach (ACTNode A in Sections)
                    {
                        bw.WriteInt32((int)A.Section);

                        switch (A.Section)
                        {
                        case Section.Name:
                            length = A.Identifier.Length + 3;

                            bw.WriteInt32(length);
                            bw.WriteByte((byte)A.ActorType);
                            bw.WriteByte((byte)A.RenderStyle);
                            bw.Write(A.Identifier.ToCharArray());
                            bw.WriteByte(0);
                            break;

                        case Section.Matrix:
                            bw.WriteInt32(48);
                            bw.WriteSingle(A.Transform.M11);
                            bw.WriteSingle(A.Transform.M12);
                            bw.WriteSingle(A.Transform.M13);
                            bw.WriteSingle(A.Transform.M21);
                            bw.WriteSingle(A.Transform.M22);
                            bw.WriteSingle(A.Transform.M23);
                            bw.WriteSingle(A.Transform.M31);
                            bw.WriteSingle(A.Transform.M32);
                            bw.WriteSingle(A.Transform.M33);
                            bw.WriteSingle(A.Transform.M41);
                            bw.WriteSingle(A.Transform.M42);
                            bw.WriteSingle(A.Transform.M43);
                            break;

                        case Section.Section37:
                        case Section.SubLevelBegin:
                        case Section.SubLevelEnd:
                            bw.WriteInt32(0);
                            break;

                        case Section.Model:
                            bw.WriteInt32(A.Model.Length + 1);
                            bw.Write(A.Model.ToCharArray());
                            bw.WriteByte(0);
                            break;
                        }
                    }

                    bw.WriteInt32(0);
                    bw.WriteInt32(0);
                }
        }
Exemple #3
0
        public void Save(string path)
        {
            using (FileStream fs = new FileStream(path, FileMode.Create))
                using (BEBinaryWriter bw = new BEBinaryWriter(fs))
                {
                    int    matListLength;
                    string name;

                    //output header
                    bw.WriteInt32(0x12);
                    bw.WriteInt32(0x8);
                    bw.WriteInt32(0xface);
                    bw.WriteInt32(0x2);

                    for (int i = 0; i < DatMeshes.Count; i++)
                    {
                        DatMesh dm = DatMeshes[i];
                        matListLength = 0;

                        for (int j = 0; j < dm.Mesh.Materials.Count; j++)
                        {
                            matListLength += dm.Mesh.Materials[j].Length + 1;
                        }

                        name = dm.Name;
                        //Console.WriteLine(name + " : " + dm.Mesh.Verts.Count);

                        //begin name section
                        bw.WriteInt32(54);
                        bw.WriteInt32(name.Length + 3);
                        bw.WriteByte(0);
                        bw.WriteByte(0);
                        bw.Write(name.ToCharArray());
                        bw.WriteByte(0);
                        //end name section

                        //begin vertex data
                        bw.WriteInt32(23);
                        bw.WriteInt32((dm.Mesh.Verts.Count * 12) + 4);
                        bw.WriteInt32(dm.Mesh.Verts.Count);

                        for (int j = 0; j < dm.Mesh.Verts.Count; j++)
                        {
                            bw.WriteSingle(dm.Mesh.Verts[j].X);
                            bw.WriteSingle(dm.Mesh.Verts[j].Y);
                            bw.WriteSingle(dm.Mesh.Verts[j].Z);
                        }
                        //end vertex data

                        //begin uv data (00 00 00 18)
                        bw.WriteInt32(24);
                        bw.WriteInt32((dm.Mesh.UVs.Count * 8) + 4);
                        bw.WriteInt32(dm.Mesh.UVs.Count);

                        for (int j = 0; j < dm.Mesh.UVs.Count; j++)
                        {
                            bw.WriteSingle(dm.Mesh.UVs[j].X);
                            bw.WriteSingle(dm.Mesh.UVs[j].Y);
                        }
                        //end uv data

                        //begin face data (00 00 00 35)
                        bw.WriteInt32(53);
                        bw.WriteInt32((dm.Mesh.Faces.Count * 9) + 4);
                        bw.WriteInt32(dm.Mesh.Faces.Count);

                        for (int j = 0; j < dm.Mesh.Faces.Count; j++)
                        {
                            bw.WriteInt16(dm.Mesh.Faces[j].V1);
                            bw.WriteInt16(dm.Mesh.Faces[j].V2);
                            bw.WriteInt16(dm.Mesh.Faces[j].V3);
                            bw.WriteByte(0); // smoothing groups 9 - 16
                            bw.WriteByte(1); // smoothing groups 1 - 8
                            bw.WriteByte(0); // number of edges, 0 and 3 = tri.  4 = quad.
                        }
                        //end face data

                        //begin material list
                        bw.WriteInt32(22);
                        bw.WriteInt32(matListLength + 4);
                        bw.WriteInt32(dm.Mesh.Materials.Count);

                        for (int j = 0; j < dm.Mesh.Materials.Count; j++)
                        {
                            bw.Write(dm.Mesh.Materials[j].ToCharArray());
                            bw.WriteByte(0);
                        }
                        //end material list

                        //begin face textures
                        bw.WriteInt32(26);
                        bw.WriteInt32((dm.Mesh.Faces.Count * 2) + 4);
                        bw.WriteInt32(dm.Mesh.Faces.Count);
                        bw.WriteInt32(2);

                        for (int j = 0; j < dm.Mesh.Faces.Count; j++)
                        {
                            bw.WriteInt16(dm.Mesh.Faces[j].MaterialID + 1);
                        }
                        //end face textures

                        bw.WriteInt32(0);
                        bw.WriteInt32(0);
                    }
                }
        }