Real-time drawing of incomplete planes.

radiotonga's icon

Hello,

I'm looking for a way to draw incomplete plane shapes with gl.sketch (or other object, if it suits). Specifically, I'm working with a grid (be it jit.matrix or matrixctrl) in order to have control of which parts can be added or removed, depending on coordinates.

It works fine, except that I can't figure the way to draw the result as a single shape, that can receive a texture in its entirety. What I mean with this is that regardless of the final plane's shape, it should receive the texture as if it was a normal plane, or rectangle (as if it had a mask). Instead, every grid space is rendered its unique texture.

Max Patch
Copy patch and select New From Clipboard in Max.

I'm also sure my method is very resource-wasteful. Please, if you could provide me any pointers in order to achieve my goal, I know this must be a complex thing...

radiotonga's icon

I'm bumping this thread because as of yet I haven't found any solution on my own. Sketch drawing functions are too low-level for me to understand completely without some free time. Of course, I'm just asking for some pointers or some exemplary messages.

I devised another solution that involves slabs and videoplane masking. It works alright, but it demands much maintenance and power. I'm thinking sketch might be more economical to me.

Thanks in advance,

seejayjames's icon

Try the tex_map and tex_plane messages. I was able to get it closer to what you wanted, but not quite. There's four variables and two planes to mess with, the third in the list never did anything. But with tex_map set to 3 you can stretch and offset the texture, and it'll be one big texture over the whole image... couldn't get it to stretch/position itself correctly though.

I like the mouse cell-draw function you have in there, for adding and removing the tiles in the 9x9 matrix. If you wanted, you could just merge that matrix with the main one, treat them both as movies/images rather than using sketch, which would give you what you were looking for... though with sketch you could get away from rectangles too.

Max Patch
Copy patch and select New From Clipboard in Max.

This one just has a mini-module added to mess with the tex_map and tex_planes, and an All Off/All On for the tiles:

radiotonga's icon

seejayjames,

Thanks for your dedicated patch. I tweaked and tweaked but couldn't get to properly set my textures. Now I'm not so sure this may be the way to go forward; I say this because I expect to have 9 tile-planes of that sort and that means +300 independent planes.

Maybe a very dedicated drawing routine for one single shape? That is out of my league, however.

I have been investigating and perhaps gl.mesh might be IT (or maybe gl.multiple). Is it possible to feed it a matrix with vertex coordinates to produce the tile/grid effect I'm looking for? If it is, could you please provide me with the basic stuff for translating my 9x9 char matrix into a float32 matrix with vertex coordinates? (I did went through the jit.expr tutorial but this seems quite a specific need)

Thanks for your time, again,

radiotonga's icon

BTW,

With working with jit.expr I'm meaning a way to procedurally position only those pixels that are at 255 in the original char matrix: some tiles on and some off, but using the texture coordinates of a complete plane.

Rob Ramirez's icon
Max Patch
Copy patch and select New From Clipboard in Max.

maybe instead of working with the tex_plane attributes directly, use this handy abstraction:

radiotonga's icon

rob,

It works like magic with my texture so thanks. Now I'll see if this same principle can be applied to a grid made up with jit.gl.multiple, which might come easier for my GPU.

Andrew Benson's icon

There are a couple of things that strike me here as possible venues for exploration. If you are looking to essentially turn on and off rectangular sections of a larger textured plane, why not just generate an alpha channel and turn on blend_enable? You can use jit.gl.slab @file cc.alphaglue.jxs to apply an arbitrary alpha texture. If you want to break up a single texture to be used on an array of textured quads, you might try using a combination of jit.expr and jit.gl.mesh to generate the geometry. For some examples, check out Jitter Recipes 36-38 https://cycling74.com/tutorials/jitter-recipes-book-3/

Let us know what you come up with.

radiotonga's icon

I did explore the slabs alternative; the problem is that I'm already pushing too many slabs already and I need to work with 9 different plane-grids.

I am now exploring for the first time the possibilities of gl.multiple and jit.expr. Below is what I have done so far: the part where I translate positions to a float32 matrix is particularly painful to see. Also, I'm aware my jit.expressions are pretty bad.

Max Patch
Copy patch and select New From Clipboard in Max.

If you think gl.mesh is better suited for this task, or if you could offer the expression I should be using for positioning the tiles in gl.multiple I would appreciate it, as my head is about to explode.

radiotonga's icon

I managed to work out something more decent than my last patch. At least I'm outputting the tiles in (mostly) the correct positions with mesh. If I manage to correct the weird vertex problem I'm having with textures and certain positions, plus realigning my quads as if they were one single plane, I'd consider myself happy.

Of course, this is way over my head for now (never really messed with expr or meshes before), so if you can lend me a hand or give me some pointers. I'm not asking for the complete homework, just some meaningful tips please.

Thanks everybody,

Max Patch
Copy patch and select New From Clipboard in Max.

Rehash of nº 36, this time readable and respectful to the viewer:

radiotonga's icon

And here is a much improved version of what I'm trying to accomplish. Now it's only fault is placement, scale (preferably 1.333, 1.) and vertex for the individual textures.

Any ideas?

Max Patch
Copy patch and select New From Clipboard in Max.

This is a composite hack from nº 36 and 38 of mesh tutorials.

Rob Ramirez's icon

can't you just scale and position the gl.mesh using attributes?