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); }
/// <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; }
public SSBHVertexAttribute[] ReadAttribute(string AttributeName, int Position, int Count, MeshObject MeshObject) { MeshAttribute attr = GetAttribute(AttributeName, MeshObject); if (attr == null) { return(new SSBHVertexAttribute[0]); } BinaryReader SelectedBuffer = buffers[attr.BufferIndex]; int Offset = MeshObject.VertexOffset; int Stride = MeshObject.Stride; if (attr.BufferIndex == 1) { Offset = MeshObject.VertexOffset2; Stride = MeshObject.Stride2; } int Size = 3; if (AttributeName.Contains("colorSet")) { Size = 4; } if (AttributeName.Equals("map1") || AttributeName.Equals("bake1") || AttributeName.Contains("uvSet")) { Size = 2; } SSBHVertexAttribute[] a = new SSBHVertexAttribute[Count]; for (int i = 0; i < Count; i++) { SelectedBuffer.BaseStream.Position = Offset + attr.BufferOffset + Stride * (Position + i); a[i] = new SSBHVertexAttribute(); if (Size > 0) { a[i].X = ReadAttribute(SelectedBuffer, (SSBVertexAttribFormat)attr.DataType); } if (Size > 1) { a[i].Y = ReadAttribute(SelectedBuffer, (SSBVertexAttribFormat)attr.DataType); } if (Size > 2) { a[i].Z = ReadAttribute(SelectedBuffer, (SSBVertexAttribFormat)attr.DataType); } if (Size > 3) { a[i].W = ReadAttribute(SelectedBuffer, (SSBVertexAttribFormat)attr.DataType); } } return(a); }
/// <summary> /// Generates a very simple Axis Aligned Bounding Box /// </summary> /// <param name="points"></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); } }
/// <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; }