Creating a stairstepped effect ala "bitcrushing" w. jit.gl.mesh?

Wetterberg's icon

So yeah, I'm trying to essentially downsample an XYZ coord, but make it stairstepped, which I reckon would mean making the end point of one segment the beginning of the next. This means I somehow have to copy points in the matrix? Argh, I'm running out of words to describe this, I'm hoping you can help me out!

Right now I'm testing with a jit.bfg float32 going into jit.gl.mesh. I'd like the final project roughly in that config.

So yeah, I can make the mesh "jagged" by running it through jit.dimop or whatever, but I'd really like to make it - you know - squared off, too.

Oh, and I'd be happy to hear any jit.gen methods for this - I don't know an operator useful for this yet.

cheers.

Brecht's icon

Do you have an example of what this would kind of look like? I know 'bitcrushing' in audio, but I honnestly don't have any idea of what you want to do. I have some images in my mind, but I'm not at all sure if they are even close to what you want to do,...

dtr's icon

One thing I think of is quantizing vertex positions to a fixed interval value ([jit.op @op round] or something in that vain). But then I can't really picture what you 're after right now.

Wetterberg's icon

PARDON MY SHITTY DRAWING SKILLZ:

embedded?

http://i.imgur.com/sPQMhIm.jpg
@dtr yeah that's the same dimop doesish - I've tried to explain the difference in my drawing.
What I'm looking for is to make the geometry somehow squared off, which means the algorithm has to add extra points - sort of how if you want a vertical line in [function], you have to put in a top and a bottom, if you get my meaning?

Wetterberg's icon

*and thanks a billion for helping me out - visually this would absolutely rock.

dtr's icon

It looks like to go from your first curved line to the stepped one you could cook up a sort of quantizing algo. Keep every n-th vertex intact. The ones in between quantize to y of vertex(n-1) and x of vertex(n). This is in 2d like your drawing, extrapolate for 3d. This way you keep the original vertex count, which is handy cause vertex ordering is tricky with jit.gl.mesh, in my experience. Could be done in jit.expr or jit.gen I think.

Wetterberg's icon

yeah, perhaps alternate between intact verteces and ones that are snapped to 1 or 2 of the coords of the next vertex.

Sheesh. I think my head is spinning.

Wetterberg's icon
Pedro Santos's icon

Hi, guys. To me, more than a bitcrushing effect, it looks like a typical "Sample & Hold" digitalization process. I think that your assumptions for the 2D example are correct but the implications for doing it in 3D seem somewhat tricky...

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

Can you use an alternative approach for obtaining this kind of "Minecraft look"?

Wetterberg's icon

Thanks for chiming in, Pedro!
haha, while that is really cool-looking, the stuff I'm working on is more along the lines of the pic I'm posting below, and I think redrawing it in that manner would be really odd, hehe. I like the flat banner-like element of it, still.

So yeah, I'm trying to work out how to grab x % of the verteces, and infuse them with, for instance, the x and z coord of the previous coord. Or the one coming after.

Pedro, I know the structure of the 3d equivalent of my drawing is really tricky. I'm not looking to sample pos at different places and hold them, as a sample and hold would, although the analogy is solid.

If anything I'm hoping to perhaps quantize positions to a grid, for instance?

Could that happen? Simply saying "this is a cube of positions available to you - 16*16*16 or whatever. Any coord will snap to the nearest?

Pedro Santos's icon

I thought about restricting the levels to obtain a snapping effect but that would not resolve it entirely, as you would not get rid of the diagonal lines... so quantizing alone is not the answer.

Anyway, to quantize, I'm probably missing some obscure object, but the way I would do it is:
1. Make sure that the position values are within 0. and 1.
2. Convert the float32 position values to char (255 values).
If you now convert back to float32, you end up with only 255 steps. If you want less steps, while in char mode use jit.op to divide and then multiply again (dividing by 2 gives you 128 steps and so on...).

It certainly would be useful to have an object that does this automatically like the degrade~ object in MSP land...

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

And here's an example of a possible approach to dealing with this kind of problem.
Good luck!

Wetterberg's icon

Wow! a great method of doing this! I'm pretty floored!

I'm going to bed now, and in the morning I hope to be able to construct a version that fits my 4 1000 matrix :D Reading all those @usesrcdim 1 @srcdimstart 2 2 @srcdimend 9 9 etc is making me woozy! :)

thanks!

Andro's icon

I don't know enough about python and swapping code into Max but heres a link to the remesh modifier in blender.
This can get any mesh and then turn it into blocks.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Modifiers/Generate/Remesh
This video shows what I think you're trying to do.
https://www.youtube.com/watch?v=Mh-gUnS2c0Y
Maybe checking out the source code for that mode of the modifier will help you get a bit closer to achieving it in max.

Andro's icon
Wetterberg's icon

Thanks, andro - the videos are embedded in the wiki page, but there's no visible python code, though?

But yes, that's roughly the effect I'm going for, except the result would look a bit like the old windows "pipes" screensave, if you remember that good'un.

pipes

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

To get that look, it should be easier to use jit.gl.path.
Good luck!

Wetterberg's icon

haha, that's awesome. I meant that the pattern of the pipes could be applied to the fancy ribbon stuff I'm working with, so it'd need to be verteces to use with something else.

luxi's icon

Hi PEDRO SANTOS
before pipe Patch
i've attach a max patch
i try to run it
but max console tell me this:

Jit.gl.mesch
failed to auto genere tangents

is this a my problem (max7 setup) ?
or a Patch problem ?

thank

Pedro Santos's icon

Yes, it's a patch problem. Just delete that attribute from jit.gl.mesh.

Wetterberg's icon

Getting a bit closer in jit.gen with this code:

Wetterberg's icon

Easter Sunday bump - Can you even do a simple "float->char->float" thing in jit.gen? I tried doing a hacky "*100000->/100000" but that didn't work.

Andrew Benson's icon

My solution for this kind of quantization in Gen is to make an expr object with 'floor(in1*in2)/in2' where in1 is the value to be quantized and in2 is the number of steps.

Wetterberg's icon

Ha, at first glance I was like "that expression does NOTHING". Brilliant, can't wait to try it out! Thanks, Andrew.

Wetterberg's icon

yup, it works! cheers!

lyve forms's icon

@wetterberg (APR 01 2015 | 12:31 PM)

where/how did you implement this code?