コード例 #1
0
        public Tuple <R3DSphere, R3DBox> CalculateBoundingGeometry()
        {
            R3DBox    box    = CalculateBoundingBox();
            R3DSphere sphere = CalculateSphere(box);

            return(new Tuple <R3DSphere, R3DBox>(sphere, box));
        }
コード例 #2
0
        public SimpleSkin(Stream stream)
        {
            using (BinaryReader br = new BinaryReader(stream))
            {
                uint magic = br.ReadUInt32();
                if (magic != 0x00112233)
                {
                    throw new Exception("Not a valid SKN file");
                }

                ushort major = br.ReadUInt16();
                ushort minor = br.ReadUInt16();
                if (major != 2 && major != 4 && minor != 1)
                {
                    throw new Exception("This SKN version is not supported");
                }

                uint submeshCount = br.ReadUInt32();

                for (int i = 0; i < submeshCount; i++)
                {
                    this.Submeshes.Add(new SimpleSkinSubmesh(br));
                }
                if (major == 4)
                {
                    uint unknown = br.ReadUInt32();
                }

                uint indexCount  = br.ReadUInt32();
                uint vertexCount = br.ReadUInt32();

                uint vertexSize = major == 4 ? br.ReadUInt32() : 52;
                SimpleSkinVertexType vertexType = major == 4 ? (SimpleSkinVertexType)br.ReadUInt32() : SimpleSkinVertexType.Basic;
                R3DBox    boundingBox           = major == 4 ? new R3DBox(br) : R3DBox.Infinite;
                R3DSphere boundingSphere        = major == 4 ? new R3DSphere(br) : R3DSphere.Infinite;

                List <ushort>           indices  = new List <ushort>();
                List <SimpleSkinVertex> vertices = new List <SimpleSkinVertex>();
                for (int i = 0; i < indexCount; i++)
                {
                    indices.Add(br.ReadUInt16());
                }
                for (int i = 0; i < vertexCount; i++)
                {
                    vertices.Add(new SimpleSkinVertex(br, vertexType));
                }

                foreach (SimpleSkinSubmesh submesh in this.Submeshes)
                {
                    List <ushort> submeshIndices = indices.GetRange((int)submesh._startIndex, (int)submesh._indexCount);
                    ushort        minIndex       = submeshIndices.Min();

                    submesh.Indices  = submeshIndices.Select(x => x -= minIndex).ToList();
                    submesh.Vertices = vertices.GetRange((int)submesh._startVertex, (int)submesh._vertexCount);
                }
            }
        }
コード例 #3
0
        public SKNFile(Stream stream)
        {
            using (BinaryReader br = new BinaryReader(stream))
            {
                uint magic = br.ReadUInt32();
                if (magic != 0x00112233)
                {
                    throw new Exception("SKNFile.Read: Not a valid SKN file");
                }

                ushort major = br.ReadUInt16();
                ushort minor = br.ReadUInt16();
                if (major != 2 && major != 4 && minor != 1)
                {
                    throw new Exception("SKNFile.Read: Unsupported SKN version: " + major + "." + minor);
                }

                uint submeshCount = br.ReadUInt32();
                for (int i = 0; i < submeshCount; i++)
                {
                    this.Submeshes.Add(new SKNSubmesh(br));
                }

                uint flags = 0;
                if (major == 4)
                {
                    flags = br.ReadUInt32();
                }

                uint indexCount  = br.ReadUInt32();
                uint vertexCount = br.ReadUInt32();

                uint          vertexSize = 52;
                SKNVertexType vertexType = SKNVertexType.Basic;
                if (major == 4)
                {
                    vertexSize          = br.ReadUInt32();
                    vertexType          = (SKNVertexType)br.ReadUInt32();
                    this.BoundingBox    = new R3DBox(br);
                    this.BoundingSphere = new R3DSphere(br);
                }


                for (int i = 0; i < indexCount; i++)
                {
                    this.Indices.Add(br.ReadUInt16());
                }

                for (int i = 0; i < vertexCount; i++)
                {
                    this.Vertices.Add(new SKNVertex(br, vertexType));
                }
            }
        }
コード例 #4
0
        public void CalculateBoundaries()
        {
            Vector3 min = this.Vertices[0].Position;
            Vector3 max = this.Vertices[0].Position;

            foreach (SKNVertex vertex in this.Vertices)
            {
                if (min.X > vertex.Position.X)
                {
                    min.X = vertex.Position.X;
                }
                if (min.Y > vertex.Position.Y)
                {
                    min.Y = vertex.Position.Y;
                }
                if (min.Z > vertex.Position.Z)
                {
                    min.Z = vertex.Position.Z;
                }
                if (max.X < vertex.Position.X)
                {
                    max.X = vertex.Position.X;
                }
                if (max.Y < vertex.Position.Y)
                {
                    max.Y = vertex.Position.Y;
                }
                if (max.Z < vertex.Position.Z)
                {
                    max.Z = vertex.Position.Z;
                }
            }

            this.BoundingBox = new R3DBox(min, max);
            Vector3 centralPoint = new Vector3(
                0.5f * (this.BoundingBox.Max.X + this.BoundingBox.Min.X),
                0.5f * (this.BoundingBox.Max.Y + this.BoundingBox.Min.Y),
                0.5f * (this.BoundingBox.Max.Z + this.BoundingBox.Min.Z));

            this.BoundingSphere = new R3DSphere(centralPoint, Vector3.Distance(centralPoint, this.BoundingBox.Max));
        }
コード例 #5
0
ファイル: SimpleSkin.cs プロジェクト: Jochem-W/LeagueToolkit
        public SimpleSkin(Stream stream)
        {
            using (BinaryReader br = new BinaryReader(stream))
            {
                uint magic = br.ReadUInt32();
                if (magic != 0x00112233)
                {
                    throw new InvalidFileSignatureException();
                }

                ushort major = br.ReadUInt16();
                ushort minor = br.ReadUInt16();
                if (major != 0 && major != 2 && major != 4 && minor != 1)
                {
                    throw new UnsupportedFileVersionException();
                }

                uint indexCount  = 0;
                uint vertexCount = 0;
                SimpleSkinVertexType vertexType = SimpleSkinVertexType.Basic;
                if (major == 0)
                {
                    indexCount  = br.ReadUInt32();
                    vertexCount = br.ReadUInt32();
                }
                else
                {
                    uint submeshCount = br.ReadUInt32();

                    for (int i = 0; i < submeshCount; i++)
                    {
                        this.Submeshes.Add(new SimpleSkinSubmesh(br));
                    }
                    if (major == 4)
                    {
                        uint flags = br.ReadUInt32();
                    }

                    indexCount  = br.ReadUInt32();
                    vertexCount = br.ReadUInt32();

                    uint vertexSize = major == 4 ? br.ReadUInt32() : 52;
                    vertexType = major == 4 ? (SimpleSkinVertexType)br.ReadUInt32() : SimpleSkinVertexType.Basic;
                    R3DBox    boundingBox    = major == 4 ? new R3DBox(br) : new R3DBox(Vector3.Zero, Vector3.Zero);
                    R3DSphere boundingSphere = major == 4 ? new R3DSphere(br) : R3DSphere.Infinite;
                }

                List <ushort>           indices  = new List <ushort>();
                List <SimpleSkinVertex> vertices = new List <SimpleSkinVertex>();
                for (int i = 0; i < indexCount; i++)
                {
                    indices.Add(br.ReadUInt16());
                }
                for (int i = 0; i < vertexCount; i++)
                {
                    vertices.Add(new SimpleSkinVertex(br, vertexType));
                }

                if (major == 0)
                {
                    this.Submeshes.Add(new SimpleSkinSubmesh("Base", indices, vertices));
                }
                else
                {
                    foreach (SimpleSkinSubmesh submesh in this.Submeshes)
                    {
                        List <ushort> submeshIndices = indices.GetRange((int)submesh._startIndex, (int)submesh._indexCount);
                        ushort        minIndex       = submeshIndices.Min();

                        submesh.Indices  = submeshIndices.Select(x => x -= minIndex).ToList();
                        submesh.Vertices = vertices.GetRange((int)submesh._startVertex, (int)submesh._vertexCount);
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new <see cref="SKNFile"/> from a <see cref="Stream"/>
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> to read from</param>
        public SKNFile(Stream stream)
        {
            using (BinaryReader br = new BinaryReader(stream))
            {
                uint magic = br.ReadUInt32();
                if (magic != 0x00112233)
                {
                    throw new Exception("Not a valid SKN file");
                }

                ushort major = br.ReadUInt16();
                ushort minor = br.ReadUInt16();
                if (major != 2 && major != 4 && minor != 1)
                {
                    throw new Exception("This SKN version is not supported");
                }

                uint submeshCount = br.ReadUInt32();

                for (int i = 0; i < submeshCount; i++)
                {
                    this.Submeshes.Add(new SKNSubmesh(this, br));
                }
                if (major == 4)
                {
                    uint unknown = br.ReadUInt32();
                }

                uint indexCount  = br.ReadUInt32();
                uint vertexCount = br.ReadUInt32();

                uint      vertexSize;
                bool      isTangent = false;
                R3DBox    boundingBox;
                R3DSphere boundingSphere;

                if (major == 4)
                {
                    vertexSize     = br.ReadUInt32();
                    isTangent      = br.ReadUInt32() == 1;
                    boundingBox    = new R3DBox(br);
                    boundingSphere = new R3DSphere(br);
                }

                List <ushort>    indices  = new List <ushort>();
                List <SKNVertex> vertices = new List <SKNVertex>();
                for (int i = 0; i < indexCount; i++)
                {
                    indices.Add(br.ReadUInt16());
                }
                for (int i = 0; i < vertexCount; i++)
                {
                    vertices.Add(new SKNVertex(br, isTangent));
                }

                foreach (SKNSubmesh submesh in this.Submeshes)
                {
                    submesh.Indices  = indices.GetRange((int)submesh._startIndex, (int)submesh._indexCount);
                    submesh.Vertices = vertices.GetRange((int)submesh._startVertex, (int)submesh._vertexCount);
                }
            }
        }