Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation graphics.drawTriangles(_vertex, _indexes, _uv);
 #119

Open
zaidite opened this issue Jul 31, 2014 · 9 comments
Open

Implementation graphics.drawTriangles(_vertex, _indexes, _uv);
 #119

zaidite opened this issue Jul 31, 2014 · 9 comments

Comments

@zaidite
Copy link

zaidite commented Jul 31, 2014

Could you please add implementation for this :
graphics.clear();
graphics.beginBitmapFill(_image.bitmapData, null, false, true);
graphics.drawTriangles(_vertex, _indexes, _uv);


???

@IonSwitz
Copy link
Member

Hello. Thank you for reporting this

The beginBitmapFill method has been deprecated and will not be implemented again. The reasons are that adding a bitmap requires a new instance of a texture to be created, and applied, and that is wasteful. Use beginTextureFill instad.

drawTriangles is part of the "It would be nice" set of features that we currently have not implemented. We will see if we find the time, at some point.

@JeremyJonas
Copy link

👍 👍 Any progress on 'drawTriangles'? This would be an awesome feature.

I am trying to port http://en.nicoptere.net/?p=476 into Starling, for animating bitmaps along a distorted path... great effect for game.
Way to complex for me to figure out, but will have to find another solution if this isn't coming soon...

Super awesome extension by the way! Keep it up! You Rock!!!

@IonSwitz
Copy link
Member

I'm finding myself more and more swamped, unfortunately, and there is no time for me to be updating this project at this time. I'm sorry.

However, as far as I can tell, the "drawTriangles" needed for that effect on that site can be replicated using the TriangleStrip class, I think?

Create a TriangleStrip, addChild it to your Sprite (or whatever) and call "addVertex" for each vertex in the triangle list you get from the code in the nicoptere examples?

@JeremyJonas
Copy link

Cool I will give that a try! Thanks for taking the time to look into it, much appreciate!

On Sep 23, 2014, at 11:12 AM, IonSwitz [email protected] wrote:

I'm finding myself more and more swamped, unfortunately, and there is no time for me to be updating this project at this time. I'm sorry.

However, as far as I can tell, the "drawTriangles" needed for that effect on that site can be replicated using the TriangleStrip class, I think?

Create a TriangleStrip, addChild it to your Sprite (or whatever) and call "addVertex" for each vertex in the triangle list you get from the code in the nicoptere examples?


Reply to this email directly or view it on GitHub.

@IonSwitz
Copy link
Member

To transfer this into Starling:

public function draw( graphics:Graphics, smooth:Boolean = false ):void
{

        graphics.beginBitmapFill( bd, null, false, smooth );
        graphics.drawTriangles( vertices, indices, uvs );
        graphics.endFill(); 
    }

From his example, you create a Texture from the BitmapData, assign it to the TriangleStrip, and instead of drawTriangles, you do addVertex on the TriangleStrip for every vertex, index and UV pair in the lists.

If I were to do something like this, that's the route I would go, at least.

@JeremyJonas
Copy link

Cool it worked! You Rock!

Mostly working at least, a bit of an issue with my implementation... My geometry skills are very lacking these days... getting misshapen result.
I am not sure how to include the indices in the addVertex

public function draw():void
{
    _triangleStrip.clear();
    for(var i:int=0; i<vertices.length; i+=2){
        _triangleStrip.addVertex(vertices[i], vertices[i+1], uvs[i], uvs[i+1]);
    }

    // graphics.drawTriangles( vertices, indices, uvs );
}

image

Thanks again for your help! This feature is a life saver... cheers!

@JeremyJonas
Copy link

Never mind, I got it working!

Wasn't taking into account that the example from nicoptere was using quads, duh.

public function draw():void
        {
            _triangleStrip.clear();

            for(var i:int=0; i<vertices.length; i+=8){
                //_triangleStrip.addVertex(vertices[i], vertices[i+1], uvs[i], uvs[i+1], indices[indice+1], indices[indice+2], indices[indice+3], indices[indice+4]);
                // triangle 1: 0 (0,1) ,1 (2,3) ,3 (6,7)
                _triangleStrip.addVertex(vertices[i], vertices[i+1], uvs[i], uvs[i+1]);
                _triangleStrip.addVertex(vertices[i+2], vertices[i+3], uvs[i+2], uvs[i+3]);
                _triangleStrip.addVertex(vertices[i+6], vertices[i+7], uvs[i+6], uvs[i+7]);
                // triangle 1: 1 (2,3) ,2 (4,5) ,3 (6,7)
                _triangleStrip.addVertex(vertices[i+2], vertices[i+3], uvs[i+2], uvs[i+3]);
                _triangleStrip.addVertex(vertices[i+4], vertices[i+5], uvs[i+4], uvs[i+5]);
                _triangleStrip.addVertex(vertices[i+6], vertices[i+7], uvs[i+6], uvs[i+7]);
            }
            /*
            graphics.drawTriangles( vertices, indices, uvs );
            */
        }

image

@IonSwitz
Copy link
Member

Very nice, glad you got that to work. One of the problems, from what I have understood about drawTriangles, is that it has a number of combined functionalities ( you can omit indices, etc) that might be hard to figure out.

It might turn out to be easy, for sure, but It's one of those things that take a while to work out and get it to be compatible in a reasonable way with the "original" drawTriangles

@jonathanrpace
Copy link
Member

As you've noticed, the triangle strip primitive doesn't work the same way as Flash's 'drawTriangles' - You don't get to supply your own array of indices alongside the vertex data.

The triangle strip shares some vertices for efficiency. Full details here http://en.wikipedia.org/wiki/Triangle_strip

This may be 'a good thing' in your particular case, however it's not as flexible as supplying your own indices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants