public Sprite (Stream stream, TextureSettings settings, Vector4 rect, bool relativeRect, Vector4 color, bool flipV = true) { var tex = new Texture(stream, settings); _material = new SpriteMaterial(new SpriteShader(), tex); if (rect == Vector4.Zero) rect = new Vector4(0, 0, tex.Size.Width, tex.Size.Height); else if (relativeRect) { rect.X *= tex.Size.Width; rect.Y *= tex.Size.Height; rect.Z *= tex.Size.Width; rect.W *= tex.Size.Height; } _size = new Vector2(rect.Z - rect.X, rect.W - rect.Y); _vbuffer = new VertexBuffer(VertexFormat.PositionColorUV); _vbuffer.Data = new [] { rect.X, rect.Y, 0f, color.X, color.Y, color.Z, color.W, 0f, flipV ? 1f : 0f, rect.Z, rect.Y, 0f, color.X, color.Y, color.Z, color.W, 1f, flipV ? 1f : 0f, rect.Z, rect.W, 0f, color.X, color.Y, color.Z, color.W, 1f, flipV ? 0f : 1f, rect.X, rect.W, 0f, color.X, color.Y, color.Z, color.W, 0f, flipV ? 0f : 1f }; _vbuffer.Commit (); _ibuffer = new IndexBuffer(); _ibuffer.Data = new [] { 0, 1, 2, 2, 3, 0 }; _ibuffer.Commit (); _ioffset = 0; _icount = 6; _ownResources = true; }
public Mesh (string name, Material mat, VertexFormat format, float[] vertices, int[] indices, Bone[] bones) { _name = name; _material = mat; _vbuffer = new VertexBuffer(format, vertices); _ibuffer = new IndexBuffer(indices, BeginMode.Triangles); _bones = bones; if(_bones != null) _boneTransforms = new Matrix4[_bones.Length]; }
public Sprite (Material material, Vector2 size, VertexBuffer vbuffer = null, IndexBuffer ibuffer = null, int ioffset = 0, int icount = 0, bool ownMaterial = false) { _material = material; _size = size; _vbuffer = vbuffer; _ibuffer = ibuffer; _ioffset = ioffset; _icount = icount; _ownResources = ownMaterial; }
public Quad (Material material, Vector4 rect, Vector4 color, bool flipV = false) { _material = material; _color = color; _vbuffer = new VertexBuffer (VertexFormat.PositionColorUV); _ibuffer = new IndexBuffer (); if (rect == Vector4.Zero) rect = new Vector4(-0.5f, -0.5f, 0.5f, 0.5f); _vbuffer.Data = new [] { rect.X, rect.Y, 0f, _color.X, _color.Y, _color.Z, _color.W, 0f, flipV ? 1f : 0f, rect.Z, rect.Y, 0f, _color.X, _color.Y, _color.Z, _color.W, 1f, flipV ? 1f : 0f, rect.Z, rect.W, 0f, _color.X, _color.Y, _color.Z, _color.W, 1f, flipV ? 0f : 1f, rect.X, rect.W, 0f, _color.X, _color.Y, _color.Z, _color.W, 0f, flipV ? 0f : 1f }; _vbuffer.Commit (); _ibuffer.Data = new [] { 0, 1, 2, 2, 3, 0 }; _ibuffer.Commit (); }
unsafe Mesh[] ReadMeshes (BinaryReader reader, Material[] materials) { var meshCount = reader.ReadInt32(); var meshes = new Mesh[meshCount]; for (var i = 0; i < meshCount; i++) { var name = reader.ReadString(); var format = GetVertexFormat((VertexFlags)reader.ReadInt32(), reader.ReadInt32()); var matIdx = reader.ReadInt32(); if (matIdx < 0 || matIdx >= materials.Length) throw new ContentException("Invalid material index " + matIdx); var count = reader.ReadInt32(); var vertices = new float[count]; byte[] buf = new byte[count * sizeof(float)]; reader.Read(buf, 0, buf.Length); fixed(byte *bp = &buf[0]) { fixed(float *fp = &vertices[0]) { float* src = (float*)bp; float* dst = fp; for (var j = 0; j < count; j++) { *(dst++) = *(src++); } } } count = reader.ReadInt32(); var indices = new int[count]; buf = new byte[count * sizeof(int)]; reader.Read(buf, 0, buf.Length); fixed(byte *bp = &buf[0]) { fixed(int *ip = &indices[0]) { int* src = (int*)bp; int* dst = ip; for (var j = 0; j < count; j++) { *(dst++) = *(src++); } } } count = reader.ReadInt32(); Bone[] bones = null; if (count > 0) { bones = new Bone[count]; for (var j = 0; j < count; j++) { var boneName = reader.ReadString(); Matrix4 offset; reader.ReadMatrix4(out offset); var weightCount = reader.ReadInt32(); var weights = new VertexWeight[weightCount]; var sz = weightCount * sizeof(VertexWeight); if (buf.Length < sz) buf = new byte[sz]; reader.Read(buf, 0, sz); fixed(byte *src = &buf[0]) { var p = (VertexWeight*)src; fixed(VertexWeight *dst = &weights[0]) { for (var k = 0; k < weightCount; k++) { *(dst + k) = *(p + k); } } } bones[j] = new Bone(j, boneName, ref offset, weights); } } meshes[i] = new Mesh(name, materials[matIdx], format, vertices, indices, bones); } return meshes; }
private SlicedSprite (Material material, Vector2 size) : base(material, size) { _vbuffer = new VertexBuffer(VertexFormat.PositionColorUV); _ibuffer = new IndexBuffer(); }