WriteVector3D() public method

public WriteVector3D ( Vector3D v, bool isAom = true, bool isHalf = false ) : void
v Vector3D
isAom bool
isHalf bool
return void
コード例 #1
0
 public void Write(BrgBinaryWriter writer)
 {
     writer.Write(this.Version);
     writer.Write((UInt16)this.Format);
     writer.Write(this.NumVertices);
     writer.Write(this.NumFaces);
     writer.Write((Byte)this.InterpolationType);
     writer.Write((Byte)this.AnimationType);
     writer.Write(this.UserDataEntryCount);
     writer.WriteVector3D(this.CenterPosition, true);
     writer.Write(this.CenterRadius);//unknown03
     writer.WriteVector3D(this.MassPosition, true);
     writer.WriteVector3D(this.HotspotPosition, true);
     writer.Write(this.ExtendedHeaderSize);
     writer.Write((UInt16)this.Flags);
     writer.WriteVector3D(this.MinimumExtent, true);
     writer.WriteVector3D(this.MaximumExtent, true);
 }
コード例 #2
0
ファイル: BrgMesh.cs プロジェクト: Ryder25/Age-of-Mythology
        public void Write(BrgBinaryWriter writer)
        {
            this.Header.Version = 22;
            if (this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLEPOINTS))
            {
                this.Header.NumVertices = (Int16)(this.particleData.Length / 4);
            }
            else
            {
                this.Header.NumVertices = (Int16)this.Vertices.Count;
            }
            this.Header.NumFaces = (Int16)this.Faces.Count;
            this.Header.UserDataEntryCount = (Int16)this.UserDataEntries.Length;
            this.Header.CenterRadius = this.Header.MaximumExtent.LongestAxisLength();
            this.Header.ExtendedHeaderSize = 40;
            this.Header.Write(writer);

            if (!this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLEPOINTS))
            {
                for (int i = 0; i < this.Vertices.Count; i++)
                {
                    writer.WriteVector3D(this.Vertices[i], true, true);
                }
                for (int i = 0; i < this.Vertices.Count; i++)
                {
                    writer.WriteVector3D(this.Normals[i], true, true);
                }

                if ((!this.Header.Flags.HasFlag(BrgMeshFlag.SECONDARYMESH) ||
                    this.Header.Flags.HasFlag(BrgMeshFlag.ANIMTEXCOORDS) ||
                    this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLESYSTEM)) &&
                    this.Header.Flags.HasFlag(BrgMeshFlag.TEXCOORDSA))
                {
                    for (int i = 0; i < this.TextureCoordinates.Count; i++)
                    {
                        writer.WriteHalf(this.TextureCoordinates[i].X);
                        writer.WriteHalf(this.TextureCoordinates[i].Y);
                    }
                }

                if (!this.Header.Flags.HasFlag(BrgMeshFlag.SECONDARYMESH) ||
                    this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLESYSTEM))
                {
                    if (this.Header.Flags.HasFlag(BrgMeshFlag.MATERIAL))
                    {
                        for (int i = 0; i < this.Faces.Count; i++)
                        {
                            writer.Write(this.Faces[i].MaterialIndex);
                        }
                    }

                    for (int i = 0; i < this.Faces.Count; i++)
                    {
                        writer.Write((Int16)this.Faces[i].Indices[0]);
                        writer.Write((Int16)this.Faces[i].Indices[1]);
                        writer.Write((Int16)this.Faces[i].Indices[2]);
                    }

                    if (this.Header.Flags.HasFlag(BrgMeshFlag.MATERIAL))
                    {
                        for (int i = 0; i < this.VertexMaterials.Count; i++)
                        {
                            writer.Write(this.VertexMaterials[i]);
                        }
                    }
                }
            }

            if (!this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLEPOINTS))
            {
                for (int i = 0; i < this.UserDataEntries.Length; i++)
                {
                    writer.WriteUserDataEntry(ref this.UserDataEntries[i], false);
                }
            }

            this.ExtendedHeader.NumNonUniformKeys = NonUniformKeys.Length;
            this.ExtendedHeader.Write(writer);

            if (this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLEPOINTS))
            {
                for (int i = 0; i < this.particleData.Length; i++)
                {
                    writer.Write(this.particleData[i]);
                }
                for (int i = 0; i < this.UserDataEntries.Length; i++)
                {
                    writer.WriteUserDataEntry(ref this.UserDataEntries[i], true);
                }
            }

            if (this.Header.Flags.HasFlag(BrgMeshFlag.ATTACHPOINTS))
            {
                writer.Write((Int16)this.Attachpoints.Count);

                List<int> nameId = new List<int>();
                int maxNameId = -1;
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    nameId.Add(att.NameId);
                    if (att.NameId > maxNameId)
                    {
                        maxNameId = att.NameId;
                    }
                }
                Int16 numIndex = (Int16)(maxNameId + 1);//(Int16)(55 - maxNameId);
                writer.Write((Int16)numIndex);
                writer.Write((Int16)1);

                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.XVector, true, true);
                }
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.YVector, true, true);
                }
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.ZVector, true, true);
                }
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.Position, true, true);
                }
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.BoundingBoxMin, true, true);
                }
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.BoundingBoxMax, 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 < this.Attachpoints.Count; i++)
                {
                    for (int j = 0; j < this.Attachpoints.Count; j++)
                    {
                        if (nameId[i] == nameId2[j])
                        {
                            nameId2[j] = -1;
                            writer.Write((byte)j);
                            break;
                        }
                    }
                }
            }

            if (((this.Header.Flags.HasFlag(BrgMeshFlag.COLORALPHACHANNEL) ||
                this.Header.Flags.HasFlag(BrgMeshFlag.COLORCHANNEL)) &&
                !this.Header.Flags.HasFlag(BrgMeshFlag.SECONDARYMESH)) ||
                this.Header.Flags.HasFlag(BrgMeshFlag.ANIMVERTCOLORALPHA))
            {
                for (int i = 0; i < this.Colors.Count; i++)
                {
                    writer.WriteTexel(this.Colors[i]);
                }
            }

            if (this.Header.AnimationType.HasFlag(BrgMeshAnimType.NonUniform))
            {
                for (int i = 0; i < this.NonUniformKeys.Length; i++)
                {
                    writer.Write(this.NonUniformKeys[i]);
                }
            }
        }
コード例 #3
0
 public void Write(BrgBinaryWriter writer)
 {
     writer.Write(this.Version);
     writer.Write((UInt16)this.Format);
     writer.Write(this.NumVertices);
     writer.Write(this.NumFaces);
     writer.Write((Byte)this.InterpolationType);
     writer.Write((Byte)this.AnimationType);
     writer.Write(this.UserDataEntryCount);
     writer.WriteVector3D(this.CenterPosition, true);
     writer.Write(this.CenterRadius);//unknown03
     writer.WriteVector3D(this.MassPosition, true);
     writer.WriteVector3D(this.HotspotPosition, true);
     writer.Write(this.ExtendedHeaderSize);
     writer.Write((UInt16)this.Flags);
     writer.WriteVector3D(this.MinimumExtent, true);
     writer.WriteVector3D(this.MaximumExtent, true);
 }
コード例 #4
0
ファイル: BrgMesh.cs プロジェクト: heinezen/Age-of-Mythology
        public void Write(BrgBinaryWriter writer)
        {
            this.Header.Version = 22;
            if (this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLEPOINTS))
            {
                this.Header.NumVertices = (Int16)(this.particleData.Length / 4);
            }
            else
            {
                this.Header.NumVertices = (Int16)this.Vertices.Count;
            }
            this.Header.NumFaces           = (Int16)this.Faces.Count;
            this.Header.UserDataEntryCount = (Int16)this.UserDataEntries.Length;
            this.Header.CenterRadius       = Math.Max(Math.Max(this.Header.MaximumExtent.X, this.Header.MaximumExtent.Y), this.Header.MaximumExtent.Z);
            this.Header.ExtendedHeaderSize = 40;
            this.Header.Write(writer);

            if (!this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLEPOINTS))
            {
                for (int i = 0; i < this.Vertices.Count; i++)
                {
                    writer.WriteVector3D(this.Vertices[i], true, true);
                }
                for (int i = 0; i < this.Vertices.Count; i++)
                {
                    writer.WriteVector3D(this.Normals[i], true, true);
                }

                if ((!this.Header.Flags.HasFlag(BrgMeshFlag.SECONDARYMESH) ||
                     this.Header.Flags.HasFlag(BrgMeshFlag.ANIMTEXCOORDS) ||
                     this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLESYSTEM)) &&
                    this.Header.Flags.HasFlag(BrgMeshFlag.TEXCOORDSA))
                {
                    for (int i = 0; i < this.TextureCoordinates.Count; i++)
                    {
                        writer.WriteHalf(this.TextureCoordinates[i].X);
                        writer.WriteHalf(this.TextureCoordinates[i].Y);
                    }
                }

                if (!this.Header.Flags.HasFlag(BrgMeshFlag.SECONDARYMESH) ||
                    this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLESYSTEM))
                {
                    if (this.Header.Flags.HasFlag(BrgMeshFlag.MATERIAL))
                    {
                        for (int i = 0; i < this.Faces.Count; i++)
                        {
                            writer.Write(this.Faces[i].MaterialIndex);
                        }
                    }

                    for (int i = 0; i < this.Faces.Count; i++)
                    {
                        writer.Write((Int16)this.Faces[i].Indices[0]);
                        writer.Write((Int16)this.Faces[i].Indices[1]);
                        writer.Write((Int16)this.Faces[i].Indices[2]);
                    }

                    if (this.Header.Flags.HasFlag(BrgMeshFlag.MATERIAL))
                    {
                        for (int i = 0; i < this.VertexMaterials.Count; i++)
                        {
                            writer.Write(this.VertexMaterials[i]);
                        }
                    }
                }
            }

            if (!this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLEPOINTS))
            {
                for (int i = 0; i < this.UserDataEntries.Length; i++)
                {
                    writer.WriteUserDataEntry(ref this.UserDataEntries[i], false);
                }
            }

            this.ExtendedHeader.NumNonUniformKeys = NonUniformKeys.Count;
            this.ExtendedHeader.Write(writer);

            if (this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLEPOINTS))
            {
                for (int i = 0; i < this.particleData.Length; i++)
                {
                    writer.Write(this.particleData[i]);
                }
                for (int i = 0; i < this.UserDataEntries.Length; i++)
                {
                    writer.WriteUserDataEntry(ref this.UserDataEntries[i], true);
                }
            }

            if (this.Header.Flags.HasFlag(BrgMeshFlag.ATTACHPOINTS))
            {
                writer.Write((Int16)this.Attachpoints.Count);

                List <int> nameId    = new List <int>();
                int        maxNameId = -1;
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    nameId.Add(att.NameId);
                    if (att.NameId > maxNameId)
                    {
                        maxNameId = att.NameId;
                    }
                }
                Int16 numIndex = (Int16)(maxNameId + 1);//(Int16)(55 - maxNameId);
                writer.Write((Int16)numIndex);
                writer.Write((Int16)1);

                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.XVector, true, true);
                }
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.YVector, true, true);
                }
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.ZVector, true, true);
                }
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.Position, true, true);
                }
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.BoundingBoxMin, true, true);
                }
                foreach (BrgAttachpoint att in this.Attachpoints)
                {
                    writer.WriteVector3D(att.BoundingBoxMax, 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 < this.Attachpoints.Count; i++)
                {
                    for (int j = 0; j < this.Attachpoints.Count; j++)
                    {
                        if (nameId[i] == nameId2[j])
                        {
                            nameId2[j] = -1;
                            writer.Write((byte)j);
                            break;
                        }
                    }
                }
            }

            if (((this.Header.Flags.HasFlag(BrgMeshFlag.COLORALPHACHANNEL) ||
                  this.Header.Flags.HasFlag(BrgMeshFlag.COLORCHANNEL)) &&
                 !this.Header.Flags.HasFlag(BrgMeshFlag.SECONDARYMESH)) ||
                this.Header.Flags.HasFlag(BrgMeshFlag.ANIMVERTCOLORALPHA))
            {
                for (int i = 0; i < this.Colors.Count; i++)
                {
                    writer.WriteTexel(this.Colors[i]);
                }
            }

            if (this.Header.AnimationType.HasFlag(BrgMeshAnimType.NonUniform))
            {
                for (int i = 0; i < this.NonUniformKeys.Count; i++)
                {
                    writer.Write(this.NonUniformKeys[i]);
                }
            }
        }