public void Write(System.IO.FileStream fileStream) { using (BrgBinaryWriter writer = new BrgBinaryWriter(new LittleEndianBitConverter(), fileStream)) { this.FileName = fileStream.Name; this.Header.Write(writer); if (this.Header.NumMeshes > 1) { updateAsetHeader(); writer.Write(1413829441); // magic "ASET" this.AsetHeader.Write(writer); } for (int i = 0; i <= this.Meshes[0].MeshAnimations.Count; i++) { writer.Write(1230193997); // magic "MESI" if (i > 0) { ((BrgMesh)this.Meshes[0].MeshAnimations[i - 1]).Write(writer); } else { this.Meshes[i].Write(writer); } } for (int i = 0; i < this.Materials.Count; i++) { writer.Write(1280463949); // magic "MTRL" this.Materials[i].Write(writer); } } }
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); }
public void Write(BrgBinaryWriter writer) { writer.Write(1196310850); // magic "BANG" writer.Write(this.Unknown01); writer.Write(this.NumMaterials); writer.Write(this.Unknown02); writer.Write(this.NumMeshes); writer.Write(this.Reserved); writer.Write(1999922179); }
public void Write(BrgBinaryWriter writer) { writer.Write(this.numFrames); writer.Write(this.frameStep); writer.Write(this.animTime); writer.Write(this.frequency); writer.Write(this.spf); writer.Write(this.fps); writer.Write(this.space); }
public void Write(BrgBinaryWriter writer) { writer.Write(this.Id); writer.Write((int)this.Flags); writer.Write(this.unknown01b); writer.Write(Encoding.UTF8.GetByteCount(this.DiffuseMap)); writer.WriteColor3D(this.DiffuseColor); writer.WriteColor3D(this.AmbientColor); writer.WriteColor3D(this.SpecularColor); writer.WriteColor3D(this.EmissiveColor); writer.WriteString(this.DiffuseMap, 0); if (this.Flags.HasFlag(BrgMatFlag.SpecularExponent)) { writer.Write(this.SpecularExponent); } if (this.Flags.HasFlag(BrgMatFlag.BumpMap)) { writer.WriteString(this.BumpMap, 4); } if (this.Flags.HasFlag(BrgMatFlag.Alpha)) { writer.Write(this.Opacity); } if (this.Flags.HasFlag(BrgMatFlag.REFLECTIONTEXTURE)) { writer.Write((byte)this.sfx.Count); for (int i = 0; i < this.sfx.Count; i++) { writer.Write(this.sfx[i].Id); writer.WriteString(this.sfx[i].Name, 2); } } }
public void Write(BrgBinaryWriter writer) { writer.Write(this.NumNameIndexes); writer.Write(this.NumDummies); writer.Write(this.NameLength); writer.Write(this.PointMaterial); writer.Write(this.PointRadius); writer.Write(this.NumMaterials); writer.Write(this.ShadowNameLength0); writer.Write(this.ShadowNameLength1); writer.Write(this.ShadowNameLength2); writer.Write(this.AnimationLength); writer.Write(this.MaterialLibraryTimestamp); writer.Write(this.Reserved); writer.Write(this.ExportedScaleFactor); writer.Write(this.NumNonUniformKeys); writer.Write(this.NumUniqueMaterials); }
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]); } } }
public void Write(Stream stream) { using (BrgBinaryWriter writer = new BrgBinaryWriter(new LittleEndianBitConverter(), stream)) { writer.Write(1280463949); // MTRL UInt32 nameLength = (UInt32)Encoding.UTF8.GetByteCount(this.Texture); writer.Write(nameLength); for (int i = 0; i < 5; ++i) { writer.Write(this.unk[i]); } writer.WriteColor3D(this.Diffuse); writer.WriteColor3D(this.Ambient); writer.WriteColor3D(this.Specular); writer.WriteColor3D(this.Emissive); writer.Write(this.SpecularLevel); writer.Write(this.Alpha); writer.Write(this.Id); writer.Write(this.SelfIlluminating); writer.Write(this.ClampU); writer.Write(this.ClampV); writer.Write(this.LightSpecular); writer.Write(this.AffectsAmbient); writer.Write(this.AffectsDiffuse); writer.Write(this.AffectsSpecular); writer.Write(this.Updateable); writer.Write(this.AlphaMode); // Seems to be very often 10, wave has a 2 here, phoenix has 6 writer.Write(this.AmbientIntensity); writer.Write(this.DiffuseIntensity); writer.Write(this.SpecularIntensity); writer.Write(this.EmissiveIntensity); writer.Write(this.ColorTransform); // Val of 4 seems to be PC writer.Write(this.TextureTransform); writer.Write(this.TextureFactor); // Has something to do with Cube Map writer.Write(this.MultiTextureMode); // Has something to do with Cube Map writer.Write(this.TexGenMode0); writer.Write(this.TexGenMode1); // Has something to do with Cube Map writer.Write(this.TexCoordSet0); writer.Write(this.TexCoordSet1); writer.Write(this.TexCoordSet2); writer.Write(this.TexCoordSet3); writer.Write(this.TexCoordSet4); writer.Write(this.TexCoordSet5); writer.Write(this.TexCoordSet6); writer.Write(this.TexCoordSet7); for (int i = 0; i < 3; ++i) { writer.WriteTexel(this.unk2[i]); } for (int i = 0; i < 3; ++i) { writer.WriteTexel(this.unk3[i]); } for (int i = 0; i < 4; ++i) { writer.Write(this.unk4[i]); } if (nameLength > 0) { writer.WriteString(this.Texture); } } }
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]); } } }