コード例 #1
0
        public void Write(BrgBinaryWriter writer)
        {
            writer.Write(magic);
            writer.Write(id);
            writer.Write((int)flags);

            writer.Write(unknown01b);
            writer.Write(nameLength);

            writer.WriteVector3(ref color);
            writer.WriteVector3(ref specular);
            writer.WriteVector3(ref reflection);
            writer.WriteVector3(ref ambient);

            writer.WriteString(name, false);
            writer.Write(alpha);

            if (flags.HasFlag(BrgMatFlag.SOLIDCOLOR))
            {
                writer.Write(unknown05);
            }

            if (flags.HasFlag(BrgMatFlag.SFX))
            {
                writer.Write((byte)sfx.Count);
                for (int i = 0; i < sfx.Count; i++)
                {
                    writer.Write(sfx[i].Id);
                    writer.Write(sfx[i].Name);
                }
            }
        }
コード例 #2
0
        public void WriteBr3(System.IO.Stream fileStream)
        {
            using (BrgBinaryWriter writer = new BrgBinaryWriter(new LittleEndianBitConverter(), fileStream))
            {
                writer.Write(860312130); // BRG3
                writer.Write(Header.numMeshes);
                writer.Write(Header.numMaterials);

                if (Header.numMeshes > 1)
                {
                    writer.Write(AsetHeader.animTime);
                }

                foreach (BrgMesh mesh in Mesh)
                {
                    writer.Write(mesh.numVertices);
                    writer.Write(mesh.numFaces);
                    writer.Write((Int16)mesh.flags);

                    foreach (Vector3 <float> v in mesh.vertices)
                    {
                        writer.Write(-v.X);
                        writer.Write(-v.Z);
                        writer.Write(v.Y);
                    }
                    foreach (Vector3 <float> v in mesh.normals)
                    {
                        writer.Write(-v.X);
                        writer.Write(-v.Z);
                        writer.Write(v.Y);
                    }

                    if (!mesh.flags.HasFlag(BrgMeshFlag.NOTFIRSTMESH) || mesh.flags.HasFlag(BrgMeshFlag.MOVINGTEX))
                    {
                        if (mesh.flags.HasFlag(BrgMeshFlag.TEXTURE))
                        {
                            foreach (Vector2 <float> v in mesh.texVertices)
                            {
                                writer.Write(v.X);
                                writer.Write(v.Y);
                            }
                        }
                    }

                    if (!mesh.flags.HasFlag(BrgMeshFlag.NOTFIRSTMESH))
                    {
                        if (mesh.flags.HasFlag(BrgMeshFlag.MATERIALS))
                        {
                            foreach (Int16 id in mesh.faceMaterials)
                            {
                                writer.Write((int)id);
                            }
                        }

                        foreach (Vector3 <Int16> v in mesh.faceVertices)
                        {
                            writer.Write((Int16)(v.Y + 1));
                            writer.Write((Int16)(v.X + 1));
                            writer.Write((Int16)(v.Z + 1));
                        }
                    }

                    if (mesh.flags.HasFlag(BrgMeshFlag.ATTACHPOINTS))
                    {
                        writer.Write((int)mesh.attachpoints.Count);

                        foreach (BrgAttachpoint att in mesh.attachpoints)
                        {
                            writer.WriteString(att.Name);

                            writer.Write(att.z.X);
                            writer.Write(att.y.X);
                            writer.Write(att.x.X);

                            writer.Write(att.z.Z);
                            writer.Write(att.y.Z);
                            writer.Write(att.x.Z);

                            writer.Write(att.z.Y);
                            writer.Write(att.y.Y);
                            writer.Write(att.x.Y);

                            writer.Write(-att.position.X);
                            writer.Write(-att.position.Z);
                            writer.Write(att.position.Y);
                        }
                    }
                }

                foreach (BrgMaterial mat in Material)
                {
                    writer.Write(mat.id);
                    writer.Write((int)mat.flags);
                }
            }
        }
コード例 #3
0
        public void Write(BrgBinaryWriter writer)
        {
            writer.Write(magic);

            writer.Write(meshFormat);
            writer.Write(unknown01b);
            writer.Write(numVertices);
            writer.Write(numFaces);
            writer.Write(unknown02);

            for (int i = 0; i < 9; i++)
            {
                writer.Write(unknown03[i]);
            }

            writer.Write(unknown04);

            writer.Write((Int16)flags);
            for (int i = 0; i < 3; i++)
            {
                writer.Write(unknown07[i]);
            }
            writer.Write(meshX);
            writer.Write(meshY);
            writer.Write(meshZ);

            for (int i = 0; i < numVertices; i++)
            {
                writer.WriteVector3(ref vertices[i], true, true);
            }
            for (int i = 0; i < numVertices; i++)
            {
                writer.WriteVector3(ref normals[i], true, true);
            }

            if (!flags.HasFlag(BrgMeshFlag.NOTFIRSTMESH) || flags.HasFlag(BrgMeshFlag.MOVINGTEX))
            {
                if (flags.HasFlag(BrgMeshFlag.TEXTURE))
                {
                    for (int i = 0; i < numVertices; i++)
                    {
                        writer.WriteVector2(ref texVertices[i], true);
                    }
                }
            }

            if (!flags.HasFlag(BrgMeshFlag.NOTFIRSTMESH))
            {
                if (flags.HasFlag(BrgMeshFlag.MATERIALS))
                {
                    for (int i = 0; i < numFaces; i++)
                    {
                        writer.Write(faceMaterials[i]);
                    }
                }

                for (int i = 0; i < numFaces; i++)
                {
                    writer.WriteVector3(ref faceVertices[i]);
                }

                if (flags.HasFlag(BrgMeshFlag.MATERIALS))
                {
                    for (int i = 0; i < numVertices; i++)
                    {
                        writer.Write(vertMaterials[i]);
                    }
                }
            }

            for (int i = 0; i < 12; i++)
            {
                writer.WriteHalf(unknown09[i]);
            }
            writer.Write(checkSpace);
            writer.Write(unknown09e);

            if (checkSpace == 0)
            {
                writer.Write(unknown09b);
                writer.Write(lenSpace);
                writer.Write(unknown09d);
            }

            // Implement this later
            //if (unknown05 == 97 || unknown06 == 200 || unknown06 == 204 || unknown06 == 72 || (unknown06 == 76 && unknown05 != 98)) {
            //    byte unknown0a[4 * numVertices];
            //}

            if (flags.HasFlag(BrgMeshFlag.ATTACHPOINTS))
            {
                numMatrix = (Int16)attachpoints.Count;
                writer.Write(numMatrix);

                List <int> nameId    = new List <int>();
                int        maxNameId = 0;
                for (int i = 0; i < numMatrix; i++)
                {
                    nameId.Add(attachpoints[i].NameId);
                    if (attachpoints[i].NameId > maxNameId)
                    {
                        maxNameId = attachpoints[i].NameId;
                    }
                }
                numIndex = (Int16)(55 - maxNameId);
                writer.Write(numIndex);
                writer.Write(unknown10);


                for (int i = 0; i < numMatrix; i++)
                {
                    writer.WriteVector3(ref attachpoints[i].x, true, true);
                }
                for (int i = 0; i < numMatrix; i++)
                {
                    writer.WriteVector3(ref attachpoints[i].y, true, true);
                }
                for (int i = 0; i < numMatrix; i++)
                {
                    writer.WriteVector3(ref attachpoints[i].z, true, true);
                }
                for (int i = 0; i < numMatrix; i++)
                {
                    writer.WriteVector3(ref attachpoints[i].position, true, true);
                }
                for (int i = 0; i < numMatrix; i++)
                {
                    writer.WriteVector3(ref attachpoints[i].unknown11a, true, true);
                }
                for (int i = 0; i < numMatrix; i++)
                {
                    writer.WriteVector3(ref attachpoints[i].unknown11b, true, true);
                }

                int[] dup = new int[numIndex];
                for (int i = 0; i < nameId.Count; i++)
                {
                    dup[nameId[i]] += 1;
                }
                int countId = 0;
                for (int i = 0; i < numIndex; i++)
                {
                    writer.Write(dup[i]);
                    if (dup[i] == 0)
                    {
                        writer.Write(0);
                    }
                    else
                    {
                        writer.Write(countId);
                    }
                    countId += dup[i];
                }

                List <int> nameId2 = new List <int>(nameId);
                nameId.Sort();
                for (int i = 0; i < numMatrix; i++)
                {
                    for (int j = 0; j < numMatrix; j++)
                    {
                        if (nameId[i] == nameId2[j])
                        {
                            nameId2[j] = -1;
                            writer.Write((byte)j);
                            break;
                        }
                    }
                }

                if (checkSpace == 0 && lenSpace > 0)
                {
                    for (int i = 0; i < lenSpace; i++)
                    {
                        writer.Write(unknown14[i]);
                    }
                }
            }
        }
コード例 #4
0
        public void WriteBr3(System.IO.Stream fileStream)
        {
            using (BrgBinaryWriter writer = new BrgBinaryWriter(new LittleEndianBitConverter(), fileStream))
            {
                writer.Write(860312130); // BRG3
                writer.Write(Header.numMeshes);

                if (Header.numMeshes > 1)
                {
                    writer.Write(AsetHeader.animTime);
                }

                foreach (BrgMesh mesh in Mesh)
                {
                    writer.Write(mesh.numVertices);
                    writer.Write(mesh.numFaces);
                    writer.Write((Int16)mesh.flags);

                    foreach (Vector3 <Half> v in mesh.vertices)
                    {
                        writer.Write(-(float)v.X);
                        writer.Write(-(float)v.Z);
                        writer.Write((float)v.Y);
                        //writer.Write(-(float)v.X);
                        //writer.Write((float)v.Z);
                        //writer.Write(-(float)v.Y);
                    }
                    foreach (Vector3 <Half> v in mesh.normals)
                    {
                        writer.Write(-(float)v.X);
                        writer.Write(-(float)v.Z);
                        writer.Write((float)v.Y);
                        //writer.Write(-(float)v.X);
                        //writer.Write((float)v.Z);
                        //writer.Write(-(float)v.Y);
                    }

                    if (!mesh.flags.HasFlag(BrgMeshFlag.NOTFIRSTMESH) || mesh.flags.HasFlag(BrgMeshFlag.MOVINGTEX))
                    {
                        if (mesh.flags.HasFlag(BrgMeshFlag.TEXTURE))
                        {
                            foreach (Vector2 <Half> v in mesh.texVertices)
                            {
                                writer.Write((float)v.X);
                                writer.Write((float)v.Y);
                            }
                        }
                    }

                    if (!mesh.flags.HasFlag(BrgMeshFlag.NOTFIRSTMESH))
                    {
                        foreach (Vector3 <Int16> v in mesh.faceVertices)
                        {
                            writer.Write((int)v.Y + 1);
                            writer.Write((int)v.X + 1);
                            writer.Write((int)v.Z + 1);
                        }
                    }
                }
            }
        }