Discuss Scratch

Laddie12
Scratcher
100+ posts

Triangle Fill

Hello! I have been trying to port an algorithm I found online in Java to Scratch so I can make triangle-based 3D and whatnot. Anyways, I have been having trouble with the algorithm. It might be because I inputted incorrect variables or how Scratch processes infinity versus how Java does. Here is the link. If you can help out, that would be great. Thanks

Last edited by Laddie12 (Nov. 6, 2015 01:00:06)

danzinho
Scratcher
84 posts

Triangle Fill

ask [it work can help you.] and wait
if <(answer) = [yes ]> then

say [thanks] for (2) secs
end
say [sorry i can help you.]
stupid harder with blocks
dreamy678
Scratcher
49 posts

Triangle Fill

It may not be possible. When looking through both of the codes, I only see one difference. This:
for (int scanlineY = v1.y; scanlineY <= v2.y; scanlineY++)
{
Says scanlineY <= v2.y; But yours says scanlineY > v2.y. However, If you switch the scanlineY to <=, the program breaks.
MegaApuTurkUltra
Scratcher
1000+ posts

Triangle Fill

Laddie12 wrote:

Hello! I have been trying to port an algorithm I found online in Java to Scratch so I can make triangle-based 3D and whatnot. Anyways, I have been having trouble with the algorithm. It might be because I inputted incorrect variables or how Scratch processes infinity versus how Java does. Here is the link. If you can help out, that would be great. Thanks
There's already a super fast triangle filler that optimizes for Scratch's idiosyncrasies and stuff.
Link

I actually have no idea how it works. I've written several of my own fillers but they're like 10-50x slower :(
DadOfMrLog
Scratcher
1000+ posts

Triangle Fill

MegaApuTurkUltra wrote:

There's already a super fast triangle filler that optimizes for Scratch's idiosyncrasies and stuff.
Link
I actually have no idea how it works. I've written several of my own fillers but they're like 10-50x slower :(
I've made a method that's slightly quicker than that for larger tris (but not for smaller). So I created a hybrid filler here.

They both work by starting from the in-circle and filling outwards to the corners with pen size decreasing. The original method draws three lines at each ‘layer’, whereas the faster method (for larger tris) does each corner independently.


I noticed the one you (@Laddie2) made fills using horizontal scan-lines. That's not going to be as quick as the methods used in the hybrid filler above, but there is a particular occasion you would need to do it that way in Scratch - that's if you want to have translucent triangles (i.e. so you can see some of what's behind).

If that's the case, here's a raster-based tri-filler made for that purpose: https://scratch.mit.edu/projects/61122192/

Laddie12
Scratcher
100+ posts

Triangle Fill

DadOfMrLog wrote:

MegaApuTurkUltra wrote:

There's already a super fast triangle filler that optimizes for Scratch's idiosyncrasies and stuff.
Link
I actually have no idea how it works. I've written several of my own fillers but they're like 10-50x slower :(
I've made a method that's slightly quicker than that for larger tris (but not for smaller). So I created a hybrid filler here.

They both work by starting from the in-circle and filling outwards to the corners with pen size decreasing. The original method draws three lines at each ‘layer’, whereas the faster method (for larger tris) does each corner independently.


I noticed the one you (@Laddie2) made fills using horizontal scan-lines. That's not going to be as quick as the methods used in the hybrid filler above, but there is a particular occasion you would need to do it that way in Scratch - that's if you want to have translucent triangles (i.e. so you can see some of what's behind).

If that's the case, here's a raster-based tri-filler made for that purpose: https://scratch.mit.edu/projects/61122192/


Would that filler work for 3D polygons? I would prefer a filler that can delete lines going off of the screen so that I could make a 3D cube that can move along the axes rather than just rotate.
DadOfMrLog
Scratcher
1000+ posts

Triangle Fill

Laddie12 wrote:

Would that filler work for 3D polygons? I would prefer a filler that can delete lines going off of the screen so that I could make a 3D cube that can move along the axes rather than just rotate.
Do you really mean 3d? -If you really want to show a 3d polygon, then you'd normally just transform each vertex to 2d, so you still end up with a 2d polygon…


Which filler do you want for this, the very fast opaque tri, or the (fast, but somewhat slower) translucent tri?

If you mean extending the opaque tri-filler, then I've not found a way, at least so far, to make a polygon fill that's faster than just splitting into tris and filling each of those. (Well, OK, actually, I've not tried to do it for anything beyond a quad - maybe it becomes more worthwhile after a certain number of sides?)

But if you mean extending the translucent raster-based tri-filler to polygons, then, yes.


Oh, and rendering partly off-screen is no problem. The trick is to draw with it set to a very large costume. That way it can go a long way off the edges of the screen before its position is restricted by Scratch.

If you do need to render lines that go even further off-screen than a few thousand pixels, but are also partly on-screen, then I have a couple of custom blocks you can use for that in the first project of my 3d framework studio

Last edited by DadOfMrLog (Nov. 7, 2015 15:56:10)

Laddie12
Scratcher
100+ posts

Triangle Fill

DadOfMrLog wrote:

Laddie12 wrote:

Would that filler work for 3D polygons? I would prefer a filler that can delete lines going off of the screen so that I could make a 3D cube that can move along the axes rather than just rotate.
Do you really mean 3d? -If you really want to show a 3d polygon, then you'd normally just transform each vertex to 2d, so you still end up with a 2d polygon…


Which filler do you want for this, the very fast opaque tri, or the (fast, but somewhat slower) translucent tri?

If you mean extending the opaque tri-filler, then I've not found a way, at least so far, to make a polygon fill that's faster than just splitting into tris and filling each of those. (Well, OK, actually, I've not tried to do it for anything beyond a quad - maybe it becomes more worthwhile after a certain number of sides?)

But if you mean extending the translucent tri-filler to polygons, then, yes.


Oh, and rendering partly off-screen is no problem. The trick is to draw with it set to a very large costume. That way it can go a long way off the edges of the screen before its position is restricted by Scratch.

If you do need to render lines that go even further off-screen than a few thousand pixels, but are also partly on-screen, then I have a couple of custom blocks you can use for that in the first project of my 3d framework studio


I just want to hook the triangle up to a previous 3D rig I built up. And thanks for the large costume trick! That should work fine then thanks!
Laddie12
Scratcher
100+ posts

Triangle Fill

Thanks everyone! It turned out great

https://scratch.mit.edu/projects/86608230/

Powered by DjangoBB