internal void WriteValues(BinaryWriterEx bw, int groupIndex, int paramIndex, int valuesOffset) { bw.FillInt32($"ValuesOffset{groupIndex}:{paramIndex}", (int)bw.Position - valuesOffset); for (int i = 0; i < Values.Count; i++) { object value = Values[i]; switch (Type) { case ParamType.Unk1: bw.WriteInt32((int)value); break; case ParamType.Unk2: bw.WriteInt16((short)value); break; case ParamType.Unk3: bw.WriteInt32((int)value); break; case ParamType.Unk5: bw.WriteBoolean((bool)value); break; case ParamType.Unk7: bw.WriteInt32((int)value); break; case ParamType.Unk9: bw.WriteSingle((float)value); break; case ParamType.UnkB: bw.WriteBoolean((bool)value); break; case ParamType.UnkC: bw.WriteVector2((Vector2)value); bw.WriteInt32(0); bw.WriteInt32(0); break; case ParamType.UnkD: bw.WriteVector4((Vector4)value); break; case ParamType.UnkE: bw.WriteVector4((Vector4)value); break; case ParamType.UnkF: bw.WriteInt32((int)value); break; } } bw.Pad(4); }
public override void Write(HKX hkx, HKXSection section, BinaryWriterEx bw, uint sectionBaseOffset, HKXVariation variation) { CompressedBVH.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteVector4(BoundingBoxMin); bw.WriteVector4(BoundingBoxMax); bw.WriteVector3(SmallVertexOffset); bw.WriteVector3(SmallVertexScale); bw.WriteUInt32(SmallVerticesBase); bw.WriteUInt32(((uint)(VertexIndicesIndex) << 8) | (uint)(VertexIndicesLength)); bw.WriteUInt32(((uint)(ByteIndicesIndex) << 8) | (uint)(ByteIndicesLength)); bw.WriteUInt32(((uint)(Unk54Index) << 8) | (uint)(Unk54Length)); bw.WriteUInt32(Unk58); bw.WriteUInt32(Unk5C); }
public override void Write(HKX hkx, HKXSection section, BinaryWriterEx bw, uint sectionBaseOffset, HKXVariation variation) { nodes.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteVector4(BoundingBoxMin); bw.WriteVector4(BoundingBoxMax); bw.WriteVector3(SmallVertexOffset); bw.WriteVector3(SmallVertexScale); bw.WriteUInt32(firstPackedVertex); bw.WriteUInt32(((uint)(sharedVerticesIndex) << 8) | (uint)(sharedVerticesLength)); bw.WriteUInt32(((uint)(primitivesIndex) << 8) | (uint)(primitivesLength)); bw.WriteUInt32(((uint)(dataRunsIndex) << 8) | (uint)(dataRunsLendth)); bw.WriteUInt32(Unk58); bw.WriteUInt32(Unk5C); }
internal void WriteValues(BinaryWriterEx bw, int groupIndex, int paramIndex, int valuesOffset) { bw.FillInt32($"ValuesOffset{groupIndex}:{paramIndex}", (int)bw.Position - valuesOffset); for (int i = 0; i < Values.Count; i++) { object value = Values[i]; switch (Type) { case ParamType.Byte: bw.WriteInt32((byte)value); break; case ParamType.Short: bw.WriteInt16((short)value); break; case ParamType.IntA: bw.WriteInt32((int)value); break; case ParamType.BoolA: bw.WriteBoolean((bool)value); break; case ParamType.IntB: bw.WriteInt32((int)value); break; case ParamType.Float: bw.WriteSingle((float)value); break; case ParamType.BoolB: bw.WriteBoolean((bool)value); break; case ParamType.Float2: bw.WriteVector2((Vector2)value); bw.WriteInt32(0); bw.WriteInt32(0); break; case ParamType.Float3: bw.WriteVector3((Vector3)value); bw.WriteInt32(0); break; case ParamType.Float4: bw.WriteVector4((Vector4)value); break; case ParamType.Byte4: bw.WriteBytes((byte[])value); break; } } bw.Pad(4); }
public override void Write(HKX hkx, HKXSection section, BinaryWriterEx bw, uint sectionBaseOffset, HKXVariation variation) { SectionOffset = (uint)bw.Position - sectionBaseOffset; WriteEmptyPointer(hkx, bw); WriteEmptyPointer(hkx, bw); CompressedBVH.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteVector4(BoundingBoxMin); bw.WriteVector4(BoundingBoxMax); bw.WriteUInt32(Unk40); bw.WriteUInt32(Unk44); bw.WriteUInt32(Unk48); bw.WriteUInt32(Unk4C); Chunks.Write(hkx, section, bw, sectionBaseOffset, variation); MeshIndices.Write(hkx, section, bw, sectionBaseOffset, variation); VertexIndices.Write(hkx, section, bw, sectionBaseOffset, variation); SmallVertices.Write(hkx, section, bw, sectionBaseOffset, variation); LargeVertices.Write(hkx, section, bw, sectionBaseOffset, variation); UnkA0.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteUInt64(UnkB0); UnkB8.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteUInt64(UnkC8); DataSize = (uint)bw.Position - sectionBaseOffset - SectionOffset; CompressedBVH.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); Chunks.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); MeshIndices.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); VertexIndices.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); SmallVertices.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); LargeVertices.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); UnkA0.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); UnkB8.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); }
public override void Write(HKX hkx, HKXSection section, BinaryWriterEx bw, uint sectionBaseOffset, HKXVariation variation) { SectionOffset = (uint)bw.Position - sectionBaseOffset; WriteEmptyPointer(hkx, bw); WriteEmptyPointer(hkx, bw); meshTree.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteVector4(BoundingBoxMin); bw.WriteVector4(BoundingBoxMax); bw.WriteUInt32(numPrimitiveKeys); bw.WriteUInt32(bitsPerKey); bw.WriteUInt32(maxKeyValue); bw.WriteUInt32(Unk4C); sections.Write(hkx, section, bw, sectionBaseOffset, variation); primitives.Write(hkx, section, bw, sectionBaseOffset, variation); sharedVerticesIndex.Write(hkx, section, bw, sectionBaseOffset, variation); packedVertices.Write(hkx, section, bw, sectionBaseOffset, variation); sharedVertices.Write(hkx, section, bw, sectionBaseOffset, variation); primitiveDataRuns.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteUInt64(UnkB0); simdTree.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteUInt64(UnkC8); DataSize = (uint)bw.Position - sectionBaseOffset - SectionOffset; meshTree.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); sections.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); primitives.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); sharedVerticesIndex.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); packedVertices.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); sharedVertices.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); primitiveDataRuns.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); simdTree.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); }
internal void Write(BinaryWriterEx bw, BufferLayout layout, int vertexSize, int version) { var tangentQueue = new Queue <Vector4>(Tangents); var colorQueue = new Queue <Color>(Colors); var uvQueue = new Queue <Vector3>(UVs); float uvFactor = 1024; foreach (BufferLayout.Member member in layout) { switch (member.Semantic) { case BufferLayout.MemberSemantic.Position: if (member.Type == BufferLayout.MemberType.Float3) { bw.WriteVector3(Position); } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.BoneWeights: if (member.Type == BufferLayout.MemberType.Byte4C) { for (int i = 0; i < 4; i++) { bw.WriteSByte((sbyte)(BoneWeights[i] * sbyte.MaxValue)); } } else if (member.Type == BufferLayout.MemberType.Short4toFloat4A) { for (int i = 0; i < 4; i++) { bw.WriteInt16((short)(BoneWeights[i] * short.MaxValue)); } } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.BoneIndices: if (member.Type == BufferLayout.MemberType.Byte4B) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)BoneIndices[i]); } } else if (member.Type == BufferLayout.MemberType.ShortBoneIndices) { for (int i = 0; i < 4; i++) { bw.WriteUInt16((ushort)BoneIndices[i]); } } else if (member.Type == BufferLayout.MemberType.Byte4E) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)BoneIndices[i]); } } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.Normal: if (member.Type == BufferLayout.MemberType.Float4) { bw.WriteVector4(Normal); } else if (member.Type == BufferLayout.MemberType.Byte4A) { bw.WriteByte((byte)(Normal.X * 127 + 127)); bw.WriteByte((byte)(Normal.Y * 127 + 127)); bw.WriteByte((byte)(Normal.Z * 127 + 127)); bw.WriteByte((byte)(Normal.W * 127 + 127)); } else if (member.Type == BufferLayout.MemberType.Byte4B) { bw.WriteByte((byte)(Normal.X * 127 + 127)); bw.WriteByte((byte)(Normal.Y * 127 + 127)); bw.WriteByte((byte)(Normal.Z * 127 + 127)); bw.WriteByte((byte)(Normal.W * 127 + 127)); } else if (member.Type == BufferLayout.MemberType.Byte4C) { bw.WriteByte((byte)(Normal.X * 127 + 127)); bw.WriteByte((byte)(Normal.Y * 127 + 127)); bw.WriteByte((byte)(Normal.Z * 127 + 127)); bw.WriteByte((byte)(Normal.W * 127 + 127)); } else if (member.Type == BufferLayout.MemberType.Short4toFloat4B) { bw.WriteInt16((short)(Normal.X * 32767 + 32767)); bw.WriteInt16((short)(Normal.Y * 32767 + 32767)); bw.WriteInt16((short)(Normal.Z * 32767 + 32767)); bw.WriteInt16((short)(Normal.W * 32767 + 32767)); } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.UV: Vector3 uv = uvQueue.Dequeue() * uvFactor; if (member.Type == BufferLayout.MemberType.Float2) { bw.WriteSingle(uv.X); bw.WriteSingle(uv.Y); } else if (member.Type == BufferLayout.MemberType.Float3) { bw.WriteVector3(uv); } else if (member.Type == BufferLayout.MemberType.Byte4A) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else if (member.Type == BufferLayout.MemberType.Byte4B) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else if (member.Type == BufferLayout.MemberType.Short2toFloat2) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else if (member.Type == BufferLayout.MemberType.Byte4C) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else if (member.Type == BufferLayout.MemberType.UV) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else if (member.Type == BufferLayout.MemberType.UVPair) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); uv = uvQueue.Dequeue() * uvFactor; bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.Tangent: Vector4 tangent = tangentQueue.Dequeue(); if (member.Type == BufferLayout.MemberType.Byte4A) { bw.WriteByte((byte)(tangent.X * 127 + 127)); bw.WriteByte((byte)(tangent.Y * 127 + 127)); bw.WriteByte((byte)(tangent.Z * 127 + 127)); bw.WriteByte((byte)(tangent.W * 127 + 127)); } else if (member.Type == BufferLayout.MemberType.Byte4B) { bw.WriteByte((byte)(tangent.X * 127 + 127)); bw.WriteByte((byte)(tangent.Y * 127 + 127)); bw.WriteByte((byte)(tangent.Z * 127 + 127)); bw.WriteByte((byte)(tangent.W * 127 + 127)); } else if (member.Type == BufferLayout.MemberType.Byte4C) { bw.WriteByte((byte)(tangent.X * 127 + 127)); bw.WriteByte((byte)(tangent.Y * 127 + 127)); bw.WriteByte((byte)(tangent.Z * 127 + 127)); bw.WriteByte((byte)(tangent.W * 127 + 127)); } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.UnknownVector4A: if (member.Type == BufferLayout.MemberType.Byte4B) { bw.WriteBytes(UnknownVector4); } else if (member.Type == BufferLayout.MemberType.Byte4C) { bw.WriteBytes(UnknownVector4); } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.VertexColor: Color color = colorQueue.Dequeue(); if (member.Type == BufferLayout.MemberType.Float4) { bw.WriteSingle(color.R); bw.WriteSingle(color.G); bw.WriteSingle(color.B); bw.WriteSingle(color.A); } else if (member.Type == BufferLayout.MemberType.Byte4A) { bw.WriteByte((byte)(color.A * 255)); bw.WriteByte((byte)(color.R * 255)); bw.WriteByte((byte)(color.G * 255)); bw.WriteByte((byte)(color.B * 255)); } else if (member.Type == BufferLayout.MemberType.Byte4C) { bw.WriteByte((byte)(color.R * 255)); bw.WriteByte((byte)(color.G * 255)); bw.WriteByte((byte)(color.B * 255)); bw.WriteByte((byte)(color.A * 255)); } else { throw new NotImplementedException(); } break; default: throw new NotImplementedException(); } } }
internal void Write(BinaryWriterEx bw, List <LayoutMember> layout, float uvFactor) { foreach (LayoutMember member in layout) { if (member.Semantic == LayoutSemantic.Position) { if (member.Type == LayoutType.Float3) { bw.WriteVector3(Position); } else if (member.Type == LayoutType.Float4) { bw.WriteVector3(Position); bw.WriteSingle(0); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.BoneWeights) { if (member.Type == LayoutType.Byte4A) { for (int i = 0; i < 4; i++) { bw.WriteSByte((sbyte)Math.Round(BoneWeights[i] * 127)); } } else if (member.Type == LayoutType.Byte4C) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)Math.Round(BoneWeights[i] * 255)); } } else if (member.Type == LayoutType.UVPair) { for (int i = 0; i < 4; i++) { bw.WriteInt16((short)Math.Round(BoneWeights[i] * 32767)); } } else if (member.Type == LayoutType.Short4toFloat4A) { for (int i = 0; i < 4; i++) { bw.WriteInt16((short)Math.Round(BoneWeights[i] * 32767)); } } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.BoneIndices) { if (member.Type == LayoutType.Byte4B) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)BoneIndices[i]); } } else if (member.Type == LayoutType.ShortBoneIndices) { for (int i = 0; i < 4; i++) { bw.WriteUInt16((ushort)BoneIndices[i]); } } else if (member.Type == LayoutType.Byte4E) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)BoneIndices[i]); } } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.Normal) { if (member.Type == LayoutType.Float3) { bw.WriteVector3(Normal); } else if (member.Type == LayoutType.Float4) { bw.WriteVector3(Normal); bw.WriteSingle(NormalW); } else if (member.Type == LayoutType.Byte4A) { WriteByteNormVector3(bw, Normal); bw.WriteByte((byte)NormalW); } else if (member.Type == LayoutType.Byte4B) { WriteByteNormVector3(bw, Normal); bw.WriteByte((byte)NormalW); } else if (member.Type == LayoutType.Byte4C) { WriteByteNormVector3(bw, Normal); bw.WriteByte((byte)NormalW); } else if (member.Type == LayoutType.Short4toFloat4A) { WriteShortNormVector3(bw, Normal); bw.WriteInt16((short)NormalW); } else if (member.Type == LayoutType.Short4toFloat4B) { WriteUShortNormVector3(bw, Normal); bw.WriteInt16((short)NormalW); } else if (member.Type == LayoutType.Byte4E) { WriteByteNormVector3(bw, Normal); bw.WriteByte((byte)NormalW); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.UV) { Vector3 uv = uvQueue.Dequeue() * uvFactor; if (member.Type == LayoutType.Float2) { bw.WriteSingle(uv.X); bw.WriteSingle(uv.Y); } else if (member.Type == LayoutType.Float3) { bw.WriteVector3(uv); } else if (member.Type == LayoutType.Float4) { bw.WriteSingle(uv.X); bw.WriteSingle(uv.Y); uv = uvQueue.Dequeue() * uvFactor; bw.WriteSingle(uv.X); bw.WriteSingle(uv.Y); } else if (member.Type == LayoutType.Byte4A) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Byte4B) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Short2toFloat2) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Byte4C) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.UV) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.UVPair) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); uv = uvQueue.Dequeue() * uvFactor; bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Short4toFloat4B) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); bw.WriteInt16((short)Math.Round(uv.Z)); bw.WriteInt16(0); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.Tangent) { Vector4 tangent = tangentQueue.Dequeue(); if (member.Type == LayoutType.Float4) { bw.WriteVector4(tangent); } else if (member.Type == LayoutType.Byte4A) { WriteByteNormVector4(bw, tangent); } else if (member.Type == LayoutType.Byte4B) { WriteByteNormVector4(bw, tangent); } else if (member.Type == LayoutType.Byte4C) { WriteByteNormVector4(bw, tangent); } else if (member.Type == LayoutType.Short4toFloat4A) { WriteShortNormVector4(bw, tangent); } else if (member.Type == LayoutType.Byte4E) { WriteByteNormVector4(bw, tangent); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.Bitangent) { if (member.Type == LayoutType.Byte4A) { WriteByteNormVector4(bw, Bitangent); } else if (member.Type == LayoutType.Byte4B) { WriteByteNormVector4(bw, Bitangent); } else if (member.Type == LayoutType.Byte4C) { WriteByteNormVector4(bw, Bitangent); } else if (member.Type == LayoutType.Byte4E) { WriteByteNormVector4(bw, Bitangent); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.VertexColor) { VertexColor color = colorQueue.Dequeue(); if (member.Type == LayoutType.Float4) { color.WriteFloatRGBA(bw); } else if (member.Type == LayoutType.Byte4A) { color.WriteByteARGB(bw); } else if (member.Type == LayoutType.Byte4C) { color.WriteByteRGBA(bw); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } }
public override void Write(HKX hkx, HKXSection section, BinaryWriterEx bw, uint sectionBaseOffset, HKXVariation variation) { bw.WriteVector4(Vector); }
internal void Write(BinaryWriterEx bw, List <LayoutMember> layout, float uvFactor) { foreach (LayoutMember member in layout) { switch (member.Semantic) { case LayoutSemantic.Position: if (member.Type == LayoutType.Float3) { bw.WriteVector3(Position); } else if (member.Type == LayoutType.Float4) { bw.WriteVector3(Position); bw.WriteSingle(0); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } break; case LayoutSemantic.BoneWeights: if (member.Type == LayoutType.Byte4A) { for (int i = 0; i < 4; i++) { bw.WriteSByte((sbyte)Math.Round(BoneWeights[i] * sbyte.MaxValue)); } } else if (member.Type == LayoutType.Byte4C) { for (int i = 0; i < 4; i++) { bw.WriteSByte((sbyte)Math.Round(BoneWeights[i] * sbyte.MaxValue)); } } else if (member.Type == LayoutType.UVPair) { for (int i = 0; i < 4; i++) { bw.WriteInt16((short)Math.Round(BoneWeights[i] * short.MaxValue)); } } else if (member.Type == LayoutType.Short4toFloat4A) { for (int i = 0; i < 4; i++) { bw.WriteInt16((short)Math.Round(BoneWeights[i] * short.MaxValue)); } } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } break; case LayoutSemantic.BoneIndices: if (member.Type == LayoutType.Byte4B) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)BoneIndices[i]); } } else if (member.Type == LayoutType.ShortBoneIndices) { for (int i = 0; i < 4; i++) { bw.WriteUInt16((ushort)BoneIndices[i]); } } else if (member.Type == LayoutType.Byte4E) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)BoneIndices[i]); } } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } break; case LayoutSemantic.Normal: if (member.Type == LayoutType.Float3) { bw.WriteSingle(Normal.X); bw.WriteSingle(Normal.Y); bw.WriteSingle(Normal.Z); } else if (member.Type == LayoutType.Float4) { bw.WriteVector4(Normal); } else if (member.Type == LayoutType.Byte4A) { bw.WriteByte((byte)Math.Round(Normal.X * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.W * 127 + 127)); } else if (member.Type == LayoutType.Byte4B) { bw.WriteByte((byte)Math.Round(Normal.X * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.W * 127 + 127)); } else if (member.Type == LayoutType.Byte4C) { bw.WriteByte((byte)Math.Round(Normal.X * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.W * 127 + 127)); } else if (member.Type == LayoutType.Short4toFloat4A) { bw.WriteInt16((short)Math.Round(Normal.X * 32767)); bw.WriteInt16((short)Math.Round(Normal.Y * 32767)); bw.WriteInt16((short)Math.Round(Normal.Z * 32767)); bw.WriteInt16((short)Math.Round(Normal.W * 32767)); } else if (member.Type == LayoutType.Short4toFloat4B) { bw.WriteUInt16((ushort)Math.Round(Normal.X * 32767 + 32767)); bw.WriteUInt16((ushort)Math.Round(Normal.Y * 32767 + 32767)); bw.WriteUInt16((ushort)Math.Round(Normal.Z * 32767 + 32767)); bw.WriteUInt16((ushort)Math.Round(Normal.W * 32767 + 32767)); } else if (member.Type == LayoutType.Byte4E) { bw.WriteByte((byte)Math.Round(Normal.X * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(Normal.W * 127 + 127)); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } break; case LayoutSemantic.UV: Vector3 uv = uvQueue.Dequeue() * uvFactor; if (member.Type == LayoutType.Float2) { bw.WriteSingle(uv.X); bw.WriteSingle(uv.Y); } else if (member.Type == LayoutType.Float3) { bw.WriteVector3(uv); } else if (member.Type == LayoutType.Float4) { bw.WriteSingle(uv.X); bw.WriteSingle(uv.Y); uv = uvQueue.Dequeue() * uvFactor; bw.WriteSingle(uv.X); bw.WriteSingle(uv.Y); } else if (member.Type == LayoutType.Byte4A) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Byte4B) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Short2toFloat2) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Byte4C) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.UV) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.UVPair) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); uv = uvQueue.Dequeue() * uvFactor; bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Short4toFloat4B) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); bw.WriteInt16((short)Math.Round(uv.Z)); bw.WriteInt16(0); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } break; case LayoutSemantic.Tangent: Vector4 tangent = tangentQueue.Dequeue(); if (member.Type == LayoutType.Float4) { bw.WriteVector4(tangent); } else if (member.Type == LayoutType.Byte4A) { bw.WriteByte((byte)Math.Round(tangent.X * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.W * 127 + 127)); } else if (member.Type == LayoutType.Byte4B) { bw.WriteByte((byte)Math.Round(tangent.X * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.W * 127 + 127)); } else if (member.Type == LayoutType.Byte4C) { bw.WriteByte((byte)Math.Round(tangent.X * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.W * 127 + 127)); } else if (member.Type == LayoutType.Short4toFloat4A) { bw.WriteInt16((short)Math.Round(tangent.X * 32767)); bw.WriteInt16((short)Math.Round(tangent.Y * 32767)); bw.WriteInt16((short)Math.Round(tangent.Z * 32767)); bw.WriteInt16((short)Math.Round(tangent.W * 32767)); } else if (member.Type == LayoutType.Byte4E) { bw.WriteByte((byte)Math.Round(tangent.X * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(tangent.W * 127 + 127)); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } break; case LayoutSemantic.Bitangent: if (member.Type == LayoutType.Byte4A) { bw.WriteByte((byte)Math.Round(Bitangent.X * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.W * 127 + 127)); } else if (member.Type == LayoutType.Byte4B) { bw.WriteByte((byte)Math.Round(Bitangent.X * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.W * 127 + 127)); } else if (member.Type == LayoutType.Byte4C) { bw.WriteByte((byte)Math.Round(Bitangent.X * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.W * 127 + 127)); } else if (member.Type == LayoutType.Byte4E) { bw.WriteByte((byte)Math.Round(Bitangent.X * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.Y * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.Z * 127 + 127)); bw.WriteByte((byte)Math.Round(Bitangent.W * 127 + 127)); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } break; case LayoutSemantic.VertexColor: FLVER.VertexColor color = colorQueue.Dequeue(); if (member.Type == LayoutType.Float4) { bw.WriteSingle(color.R); bw.WriteSingle(color.G); bw.WriteSingle(color.B); bw.WriteSingle(color.A); } else if (member.Type == LayoutType.Byte4A) { bw.WriteByte((byte)Math.Round(color.A * 255)); bw.WriteByte((byte)Math.Round(color.R * 255)); bw.WriteByte((byte)Math.Round(color.G * 255)); bw.WriteByte((byte)Math.Round(color.B * 255)); } else if (member.Type == LayoutType.Byte4C) { bw.WriteByte((byte)Math.Round(color.R * 255)); bw.WriteByte((byte)Math.Round(color.G * 255)); bw.WriteByte((byte)Math.Round(color.B * 255)); bw.WriteByte((byte)Math.Round(color.A * 255)); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } break; default: throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } }