コード例 #1
0
ファイル: SpriteHelper.cs プロジェクト: Perfare/AssetStudio
        private static Vector2[][] GetTriangles(SpriteRenderData m_RD)
        {
            if (m_RD.vertices != null) //5.6 down
            {
                var vertices      = m_RD.vertices.Select(x => (Vector2)x.pos).ToArray();
                var triangleCount = m_RD.indices.Length / 3;
                var triangles     = new Vector2[triangleCount][];
                for (int i = 0; i < triangleCount; i++)
                {
                    var first    = m_RD.indices[i * 3];
                    var second   = m_RD.indices[i * 3 + 1];
                    var third    = m_RD.indices[i * 3 + 2];
                    var triangle = new[] { vertices[first], vertices[second], vertices[third] };
                    triangles[i] = triangle;
                }
                return(triangles);
            }
            else //5.6 and up
            {
                var triangles    = new List <Vector2[]>();
                var m_VertexData = m_RD.m_VertexData;
                var m_Channel    = m_VertexData.m_Channels[0]; //kShaderChannelVertex
                var m_Stream     = m_VertexData.m_Streams[m_Channel.stream];
                using (var vertexReader = new BinaryReader(new MemoryStream(m_VertexData.m_DataSize)))
                {
                    using (var indexReader = new BinaryReader(new MemoryStream(m_RD.m_IndexBuffer)))
                    {
                        foreach (var subMesh in m_RD.m_SubMeshes)
                        {
                            vertexReader.BaseStream.Position = m_Stream.offset + subMesh.firstVertex * m_Stream.stride + m_Channel.offset;

                            var vertices = new Vector2[subMesh.vertexCount];
                            for (int v = 0; v < subMesh.vertexCount; v++)
                            {
                                vertices[v] = vertexReader.ReadVector3();
                                vertexReader.BaseStream.Position += m_Stream.stride - 12;
                            }

                            indexReader.BaseStream.Position = subMesh.firstByte;

                            var triangleCount = subMesh.indexCount / 3u;
                            for (int i = 0; i < triangleCount; i++)
                            {
                                var first    = indexReader.ReadUInt16() - subMesh.firstVertex;
                                var second   = indexReader.ReadUInt16() - subMesh.firstVertex;
                                var third    = indexReader.ReadUInt16() - subMesh.firstVertex;
                                var triangle = new[] { vertices[first], vertices[second], vertices[third] };
                                triangles.Add(triangle);
                            }
                        }
                    }
                }
                return(triangles.ToArray());
            }
        }
コード例 #2
0
        public Sprite(ObjectReader reader) : base(reader)
        {
            m_Rect   = reader.ReadRectangleF();
            m_Offset = reader.ReadVector2();
            if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
            {
                m_Border = reader.ReadVector4();
            }

            m_PixelsToUnits = reader.ReadSingle();
            if (version[0] > 5 ||
                (version[0] == 5 && version[1] > 4) ||
                (version[0] == 5 && version[1] == 4 && version[2] >= 2))    //5.4.2 and up
            {
                m_Pivot = reader.ReadVector2();
            }

            m_Extrude = reader.ReadUInt32();
            if (version[0] > 5 || (version[0] == 5 && version[1] >= 3)) //5.3 and up
            {
                m_IsPolygon = reader.ReadBoolean();
                reader.AlignStream(4);
            }

            if (version[0] >= 2017) //2017 and up
            {
                var first  = new Guid(reader.ReadBytes(16));
                var second = reader.ReadInt64();
                m_RenderDataKey = new KeyValuePair <Guid, long>(first, second);

                var m_AtlasTagsSize = reader.ReadInt32();
                m_AtlasTags = new string[m_AtlasTagsSize];
                for (int i = 0; i < m_AtlasTagsSize; i++)
                {
                    m_AtlasTags[i] = reader.ReadAlignedString();
                }

                m_SpriteAtlas = new PPtr <SpriteAtlas>(reader);
            }

            m_RD = new SpriteRenderData(reader);

            if (version[0] >= 2017) //2017 and up
            {
                var m_PhysicsShapeSize = reader.ReadInt32();
                m_PhysicsShape = new Vector2[m_PhysicsShapeSize][];
                for (int i = 0; i < m_PhysicsShapeSize; i++)
                {
                    m_PhysicsShape[i] = reader.ReadVector2Array(reader.ReadInt32());
                }
            }

            //vector m_Bones 2018 and up
        }
コード例 #3
0
        private static Vector2[][] GetPolygon(SpriteRenderData m_RD)
        {
            if (m_RD.vertices != null) //5.6 down
            {
                var vertices = m_RD.vertices;
                var polygon  = new Vector2[1][];
                polygon[0] = new Vector2[vertices.Length];
                for (int i = 0; i < vertices.Length; i++)
                {
                    polygon[0][i] = (Vector2)vertices[i].pos;
                }
                return(polygon);
            }

            return(GetTriangles(m_RD)); //5.6 and up
        }
コード例 #4
0
        private static Vector2[][] GetTriangles(SpriteRenderData m_RD)
        {
            if (m_RD.vertices != null) //5.6 down
            {
                var vertices      = m_RD.vertices.Select(x => (Vector2)x.pos).ToArray();
                var triangleCount = m_RD.indices.Length / 3;
                var triangles     = new Vector2[triangleCount][];
                for (int i = 0; i < triangleCount; i++)
                {
                    var first    = m_RD.indices[i * 3];
                    var second   = m_RD.indices[i * 3 + 1];
                    var third    = m_RD.indices[i * 3 + 2];
                    var triangle = new[] { vertices[first], vertices[second], vertices[third] };
                    triangles[i] = triangle;
                }
                return(triangles);
            }

            return(GetTriangles(m_RD.m_VertexData, m_RD.m_SubMeshes, m_RD.m_IndexBuffer)); //5.6 and up
        }
コード例 #5
0
        private static Vector2[][] GetTriangles(SpriteRenderData m_RD)
        {
            var triangles    = new List <Vector2[]>();
            var m_VertexData = m_RD.m_VertexData;

            GetStreams(m_VertexData);
            var m_Channel = m_VertexData.m_Channels[0]; //kShaderChannelVertex
            var m_Stream  = m_VertexData.m_Streams[m_Channel.stream];

            using (BinaryReader vertexReader = new BinaryReader(new MemoryStream(m_VertexData.m_DataSize)),
                   indexReader = new BinaryReader(new MemoryStream(m_RD.m_IndexBuffer)))
            {
                foreach (var subMesh in m_RD.m_SubMeshes)
                {
                    var vertices = new Vector2[subMesh.vertexCount];

                    vertexReader.BaseStream.Position = m_Stream.offset + subMesh.firstVertex * m_Stream.stride + m_Channel.offset;
                    for (int v = 0; v < subMesh.vertexCount; v++)
                    {
                        vertices[v] = (Vector2)vertexReader.ReadVector3();
                        vertexReader.BaseStream.Position += m_Stream.stride - 12;
                    }

                    var triangleCount = subMesh.indexCount / 3u;
                    indexReader.BaseStream.Position = subMesh.firstByte;
                    for (int i = 0; i < triangleCount; i++)
                    {
                        var first    = indexReader.ReadUInt16() - subMesh.firstVertex;
                        var second   = indexReader.ReadUInt16() - subMesh.firstVertex;
                        var third    = indexReader.ReadUInt16() - subMesh.firstVertex;
                        var triangle = new[] { vertices[first], vertices[second], vertices[third] };
                        triangles.Add(triangle);
                    }
                }
            }
            return(triangles.ToArray());
        }