Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - aCallum

Pages: [1]
1
Support / Re: Disable overriding of material shader?
« on: August 16, 2013, 12:21:39 pm »
My mistake! I had not set the shader on the atlas' material! Simply on the material instance in the scene.

Cheers for the fast response though!

2
Support / Disable overriding of material shader?
« on: August 16, 2013, 12:17:14 pm »
Hey guys, I have created a modified version of the standard tk2dBlendVertexColor shader, but at runtime it is reset to the default tk2d version. Is there a way to avoid this?

Cheers
Alastair

3
Support / Re: tk2dsprite to texture2D/byte[]
« on: March 19, 2013, 10:22:22 pm »
Well, a couple of hours and I have a solution that works for my needs. The only problem is it will not handle sprites that have been rotated on the atlas because I get the UV's explicitly.

Code: [Select]
public static Texture2D SpriteToTexture(tk2dSprite sourceSprite) {

        Texture2D sourceTexture = (Texture2D)sourceSprite.GetCurrentSpriteDef().material.mainTexture;

        Vector2[] UVs = sourceSprite.GetCurrentSpriteDef().uvs;

        // Get the raw uv-pixel co-ordinates of the image.
        float fX = (sourceTexture.width) * UVs[0].x;
        float fY = (sourceTexture.height) * UVs[2].y;
        float fX2 = (sourceTexture.width) * UVs[1].x;;
        float fY2 = (sourceTexture.height) * UVs[0].y;

        // Calculate the width and height of the sprite.
        float fWidth = fX2 - fX;
        float fHeight = -(fY2 - fY);

        // Round the values to pixel units.
        int x = Mathf.RoundToInt(fX);
        int y = Mathf.RoundToInt(fY - fHeight);
        int width = Mathf.RoundToInt(fWidth);
        int height = Mathf.RoundToInt(fHeight);

        // Get the pixels contained within the pixel units of the atlas.
        Color[] pixelRect = sourceTexture.GetPixels(x, y, width, height);

        // Generate a new texture and populate it with the pixel data.
        Texture2D newTexture = new Texture2D(width, height);
        newTexture.SetPixels(pixelRect);
        newTexture.Apply();

        return newTexture;
    }

I'll leave this here for anyone else that may be interested.

4
Support / Re: tk2dsprite to texture2D/byte[]
« on: March 19, 2013, 09:02:50 pm »
Interesting, can you explain to me which elements of the UVs Vector2[] object equal what?

How I can calculate the width/height and x/y pixel units? I'd imagine something like (TextureWidth / 100.0f) * UVs.x ?

5
Support / tk2dsprite to texture2D/byte[]
« on: March 19, 2013, 07:59:57 pm »
Hey guys, I'm wondering if it's possible to extract the data of a tk2dsprite into a texture2D or byte[] object?

I'm wanting to send the image data over the internet. For example, we have an atlas texture containing medals (gold/silver/bronze) that are diplayed in game, when you complete a mission you can share your success via Facebook; including the medal image.

I know I can get the material and then the texture, but how can I get the texture data only for the current tk2dsprite area of that texture?

Cheers!

Pages: [1]