generating gl.mesh points, ignoring empty cells

bferns's icon

How can I make jit.gl.mesh ignore 'empty' (zeroed) cells when manually sending vertex matrices to it, or otherwise remove them? At the moment my nice clean mesh is spoiled by a bunch of triangles reaching out to 0. 0. 0.

I'm sure theres probably an easy solution, but I've spent so long on it I can no longer see woods or trees.

My instinct was to use jit.iter to route all the non-zero cells into a new single-row matrix, but that requires you to know the number of cells needed in advance (unless you can add cells dynamically? - its been a while since I was in matrix-land).

I've taken that idea to the point I'm jit.glue ing extra columns onto the matrix, but it all seems hopelessly inefficient to be run multiple times per frame (plus that solution currently reports 'invalid glue output').

Is it possible to send jit.gl.mesh individual messages for the vertices? That would solve my pre-made matrix issues.

Wesley Smith's icon

Hi bferns,
You'll need to use an index matrix to tell jit.gl.mesh which cells are actually relevant to the geometry you want to draw. There are a number of ways to generate the indices, but they're highly dependent on how the data is arranged in your vertex matrix.

bferns's icon

Thanks Wesley - that sounds exactly what I need (and the 'the index array is an array of indexes' reference description is a little tautological!). I can see its a one plane integer matrix - is it simply 0/1 or do the values modify the order of rendering?

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

I've gone with the assumption that its a simple on/off state for the index matrix cells (as feeding in incrementing integers for each cell drew nothing). I have this so far, but it appears to be only rendering a partial row whether I feed it 0s and 1s or 0s and 255s in char or long types:

If you disconnect the index matrix on the rightmost mesh input and re-initialise the mesh object (delete then undo) you'll see the mesh I'm trying to trim the circle from. Looking at the expr I stole to generate the vertex matrix, to me it seems that the dims (640x480) from the original video matrix should still apply when it comes to masking the circle.

Rob Ramirez's icon

hi bferns. maybe this wikipedia article will help clarify:
http://en.wikipedia.org/wiki/Triangle_mesh

also look at the link, Face-Vertex Meshes.
eg, if you wanted to draw the first three faces of the image in that article, your index array would contain the values 0, 4, 5, 0, 5, 1, 1, 5, 6

LSka's icon

I have a similar issue, so I'm posting here.
I have a point cloud generated with Kinect and jit.openni
For some reason, there is just a "blind spot", a single matrix cell with Z value 0 (the red dot in the attached image). I can make it disappear by changing its color or altering its position when I'm in draw_mode points, but I can't use any other draw_mode, because it causes odd faces to be generated.

I'm struggling with edgeflag and index arrays to try to tell jit.gl.mesh to simply ignore that point, but it seems I can't understand how they work.
Any practical example would be very appreciated.

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

I'm attaching an example patch and a matrix file to show the issue.

PointCloud.jxf_.jit_.zip
zip
Screen-shot-2013-10-23-at-1.21.10-.png
png
LSka's icon

Edit:
I now understand that the "single point" actually are all the "black" cells in the jit.matrix...

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

I almost found a solution, using Wesley Smith's xray.jit.cellminmax object

I used the [p CalcGLHeight] and [p Pixel2GL] found in xray.jit cellminmax helpfile to relocate the "zero" points. Since Wesley's example was using a 2d mesh, I'm now missing the correct method to calculate the Z values of the points...
(see image attached)

Screen-shot-2013-10-23-at-12.26.24-.png
png