private SsbhVertexAttribute[] ReadAttributeVec4(MeshAttribute attr, int position, int count, string attributeName, BinaryReader buffer, int offset, int stride) { var format = (SsbVertexAttribFormat)attr.DataType; var attributes = new SsbhVertexAttribute[count]; for (int i = 0; i < count; i++) { buffer.BaseStream.Position = offset + attr.BufferOffset + stride * (position + i); switch (format) { case SsbVertexAttribFormat.Byte: attributes[i] = new SsbhVertexAttribute(buffer.ReadByte(), buffer.ReadByte(), buffer.ReadByte(), buffer.ReadByte()); break; case SsbVertexAttribFormat.Float: attributes[i] = new SsbhVertexAttribute(buffer.ReadSingle(), buffer.ReadSingle(), buffer.ReadSingle(), buffer.ReadSingle()); break; case SsbVertexAttribFormat.HalfFloat: attributes[i] = new SsbhVertexAttribute(ReadHalfFloat(buffer), ReadHalfFloat(buffer), ReadHalfFloat(buffer), ReadHalfFloat(buffer)); break; case SsbVertexAttribFormat.HalfFloat2: attributes[i] = new SsbhVertexAttribute(ReadHalfFloat(buffer), ReadHalfFloat(buffer), ReadHalfFloat(buffer), ReadHalfFloat(buffer)); break; } } return(attributes); }
private SsbhVertexAttribute[] ReadAttributeVec4(MeshAttribute attr, int position, int count, BinaryReader buffer, int offset, int stride) { var format = (MeshAttribute.AttributeDataType)attr.DataType; var attributes = new SsbhVertexAttribute[count]; for (int i = 0; i < count; i++) { buffer.BaseStream.Position = offset + attr.BufferOffset + stride * (position + i); switch (format) { // TODO: Add option to not convert smaller types to larger types. case MeshAttribute.AttributeDataType.Byte: attributes[i] = new SsbhVertexAttribute(buffer.ReadByte(), buffer.ReadByte(), buffer.ReadByte(), buffer.ReadByte()); break; case MeshAttribute.AttributeDataType.Float: attributes[i] = new SsbhVertexAttribute(buffer.ReadSingle(), buffer.ReadSingle(), buffer.ReadSingle(), buffer.ReadSingle()); break; case MeshAttribute.AttributeDataType.HalfFloat: attributes[i] = new SsbhVertexAttribute(ReadHalfFloat(buffer), ReadHalfFloat(buffer), ReadHalfFloat(buffer), ReadHalfFloat(buffer)); break; case MeshAttribute.AttributeDataType.HalfFloat2: attributes[i] = new SsbhVertexAttribute(ReadHalfFloat(buffer), ReadHalfFloat(buffer), ReadHalfFloat(buffer), ReadHalfFloat(buffer)); break; } } return(attributes); }
/// <summary> /// Sets the axis aligned bounding box for the current Mesh /// </summary> /// <param name="min"></param> /// <param name="max"></param> public void SetAaBoundingBox(SsbhVertexAttribute min, SsbhVertexAttribute max) { if (currentMesh == null) { return; } currentMesh.BbMax = max; currentMesh.BbMin = min; }
/// <summary> /// Generates a very simple Axis Aligned Bounding Box /// </summary> /// <param name="points"></param> /// <param name="max"></param> /// <param name="min"></param> public static void GenerateAabb(IEnumerable <SsbhVertexAttribute> points, out SsbhVertexAttribute max, out SsbhVertexAttribute min) { max = new SsbhVertexAttribute(-float.MaxValue, -float.MaxValue, -float.MaxValue); min = new SsbhVertexAttribute(float.MaxValue, float.MaxValue, float.MaxValue); foreach (SsbhVertexAttribute p in points) { max.X = Math.Max(max.X, p.X); max.Y = Math.Max(max.Y, p.Y); max.Z = Math.Max(max.Z, p.Z); min.X = Math.Min(min.X, p.X); min.Y = Math.Min(min.Y, p.Y); min.Z = Math.Min(min.Z, p.Z); } }
private SsbhVertexAttribute[] ReadAttribute(MeshAttribute attr, int count, BinaryReader buffer, int offset, int stride, int attributeLength) { var format = attr.DataType; var attributes = new SsbhVertexAttribute[count]; for (int i = 0; i < count; i++) { buffer.BaseStream.Position = offset + attr.BufferOffset + stride * i; attributes[i] = new SsbhVertexAttribute(); switch (format) { // TODO: Add option to not convert smaller types to larger types. case MeshAttribute.AttributeDataType.Byte: for (int j = 0; j < attributeLength; j++) { attributes[i][j] = buffer.ReadByte(); } break; case MeshAttribute.AttributeDataType.Float: for (int j = 0; j < attributeLength; j++) { attributes[i][j] = buffer.ReadSingle(); } break; case MeshAttribute.AttributeDataType.HalfFloat: for (int j = 0; j < attributeLength; j++) { attributes[i][j] = ReadHalfFloat(buffer); } break; case MeshAttribute.AttributeDataType.HalfFloat2: for (int j = 0; j < attributeLength; j++) { attributes[i][j] = ReadHalfFloat(buffer); } break; } } return(attributes); }
/// <summary> /// Sets the oriented bounding box for the current Mesh /// </summary> /// <param name="center"></param> /// <param name="size"></param> /// <param name="matrix3X3"></param> public void SetOrientedBoundingBox(SsbhVertexAttribute center, SsbhVertexAttribute size, float[] matrix3X3) { if (currentMesh == null) { return; } if (matrix3X3 == null) { return; } if (matrix3X3.Length != 9) { throw new IndexOutOfRangeException("Matrix must contain 9 entries in row major order"); } currentMesh.ObbCenter = center; currentMesh.ObbSize = size; currentMesh.ObbMatrix3X3 = matrix3X3; }