StarlingGraphics / Starling-Extension-Graphics

flash.display.Graphics style extension for the Starling Flash GPU rendering framework
https://github.com/StarlingGraphics/Starling-Extension-Graphics/wiki
MIT License
282 stars 89 forks source link

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

Open zaidite opened 10 years ago

zaidite commented 10 years ago

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


???

IonSwitz commented 10 years ago

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 commented 9 years ago

:+1: :+1: 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 commented 9 years ago

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 commented 9 years ago

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 notifications@github.com 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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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.