## mesh again — possible to make a 2-d mesh of circles?

Feb 1, 2010 at 11:19pm

# mesh again — possible to make a 2-d mesh of circles?

Obviously, I’m deep in gl.mesh right now. I have gotten how to make a mesh of rectangles of varying size (thanks to Andrew’s Shatter example), but I’m assuming there is some way to make a similar grid of circles with the polygon draw mode. I have seen posted (more than once) Andrew’s snippet of making a row of circles, basically starring this expression:

[jit.expr @expr sin(snorm[0]*PI) cos(snorm[0]*PI 0.]

our rectangle maker looks like this:

[jit.expr @inputs 2
@expr (cell[0]%4.>0.)*(cell[0]%4.<3.)*in[]
(cell[0]%4>1)*in[1] “0.”]

so I see we’re using a factor to pick basically corners of a square in the example above, but is it possible to integrate the two, so that in each grid item, you’re generating a circle rather than a square?

M

#48165
Feb 1, 2010 at 11:32pm

Not as easy to accomplish, though with enough time and math, you could figure something out.

Two alternate, and IMHO simpler suggestions:

2. jit.gl.multiple

-Joshua

#173211
Feb 2, 2010 at 1:31am

I tried multiple, and I need too many of them to run quickly enough, and I have already thought about the alphamask should plan A be, as I suspected, too much of pain, which it obviously is. thanks for sparing me more head-banging.

M

#173212
Feb 2, 2010 at 8:30pm

Well, I’ve made myself a texture of dots — as many as there are bits of mesh (80×80) — and only the center and corners of the mesh actually line up with the dots as expected, so that one bit of mesh is textured with one dot. As you depart from the center, the textured area is offset towards the edges.

Fiddling with various ortho settings on the renderer changes things a bit, but none in a way that actually solves the problem, which makes me think I’m don’t really understand something about how the texcoords input to jit.gl.mesh should be working.

If I use a picture, it looks like all the parts fit together fine, but that must involve some trick or perspective, as when I use the dot texture, I can see that the pieces are not all mapping to equivalent areas of the texture. So either my math is wrong or there is some other trick I don’t know about. Below is a stripped-out version of the patch, obviously without the dot image, which I will pass privately to anyone in the mood to take a look.

Thanks,

M

– Pasted Max Patch, click to expand. –
#173213
Feb 2, 2010 at 10:12pm

Hello,
So, does this patch do something similar to what you are trying to achieve? If not, let me know what it lacks.

– Pasted Max Patch, click to expand. –
#173214
Feb 3, 2010 at 5:01am

Hi andrew — thanks for the help. It is heading in the right direction, but I need a grid, at which point I’m stymied by jit.expr. I can lay the circles out in one dimension, but making rows & columns is more than my poor brain can handle. I imagine that if I have 4 circles defined by 4 points, I need an expr which will take 2 normalized chunks of 4 points (to keep the proportions right), scaled to whatever my size is, & distribute those across my space on the x and y axes, if that makes any sense.

Below is my paltry effort, which gives me on one axis what I want on two:

– Pasted Max Patch, click to expand. –

(However, I need a _lot_ of objects, & I’m worried that the polygons are going to hurt my computer’s feelings, so if I have to stick with quads for my framerate, I’m still curious as to why the dots on’t line up.)

Millions of thanks,

M

#173215
Feb 3, 2010 at 5:22pm

The real trick is putting the modulo to good use. If you want to do this with quads, you should check out the BrightLights recipe.

AB

#173216
Feb 3, 2010 at 8:08pm

Hi Andrew,

Isn’t the last patch you posted exactly identical to the one I posted yesterday? I think you may have meant to pass on a different one, as that one does get a grid of quads — my only issue with that one was the texture mapping. Or have I missed something?

M

#173217
Feb 3, 2010 at 9:22pm

oops. I’ll need to repatch it, as I don’t think I saved it. The expr went something like @expr (cell[1]%10)*0.1 floor(cell[1]/10.)*0.1 0. for a 10×10 grid.

AB

#173218
Feb 3, 2010 at 9:38pm

save yourself the trouble, that’s exactly it:

@expr (cell[1]%10)*0.1 floor(cell[1]/10.)*0.1 0.

I’d love to know how it’s working, though.

Thanks!

M

#173219
Feb 4, 2010 at 12:02am

Briefly, here’s the idea.
- Think of cell[n] as an integer counter across the n-dim of the matrix, so cell[1] will generate numbers like 0,1,2,3, etc. This is used in both equations
- We need to create a grid with dimensions (x,y) using a sequence of numbers. To do this, we do a loop across the x-axis, and increment the y-coordinate every x cells. So for a 10×10 grid, we use a modulo (%10) to convert our 0-100 values into a sequence that looks like {0,1,2,3,4,5,6,7,8,9,0,1,2,3,….9}.
- To mimic the incrementing y-values, we just divide the 0-100 sequence by x and discard the decimal values (floor) so the sequence looks like {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,….9}

IMO, learning to use norm[n],snorm[n],cell[n], and working with things like modulos are the keys to doing interesting stuff with jit.expr.

Hope that helps.

AB

#173220
Feb 4, 2010 at 8:57pm

After lengthy staring, I’m starting to get the hang of it, I think. Thanks for the explanation. I even managed to get texture mapping working!

M

#173221

You must be logged in to reply to this topic.