Previous topicNext topic

Z-Order Sort for 4 Polygons

Questions, comments, feedback, etc.
Post Reply
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Z-Order Sort for 4 Polygons

Post by artnik »

Based on the ALPHA transparency issue with sorting polygons from this thread: viewtopic.php?f=2&t=1170

Here's a solution that will automatically Z-Sort 4 Polygons arranged in a carousel. Example:



It's useful when you want to overlap 4 polygons with full ALPHA (Greenscreen video with ChromaKeyFast module used as an example). The sorting is synched with a simple Global Spin Rate variable.
Screen Shot 2017-02-14 at 2.09.28 AM.png
Screen Shot 2017-02-14 at 2.09.28 AM.png (405.02 KiB) Viewed 13722 times
4_Poly_Z-Sort_Turntable.magic
(3.01 KiB) Downloaded 436 times
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: Z-Order Sort for 4 Polygons

Post by Magic »

Haha, as I was going about my day today I absolutely KNEW in the back of my head that you were going to figure out a solution like this. (I was thinking of a similar thing but yours is much more well thought out). Very nicely done :)
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Z-Order Sort for 4 Polygons

Post by artnik »

:-D
Sadler
Posts: 1141
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: Z-Order Sort for 4 Polygons

Post by Sadler »

It took me a little while to understand what was going on here but very nicely done. This is computational problem solving pure and simple. (also, your use of annotations to explain and document is excellent)
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Z-Order Sort for 4 Polygons

Post by artnik »

Thanks Sadler. :-) I think the general technique has broad applicability. Working on it made me realize that the lack of conditionals in MMV might not be as much of a limitation as I previously thought. (Having said that, I'd love for there to be support for conditionals with Globals.)

The main problem with the solution is that it kicks the issue down the road. The Z-Sort problem is solved, but it becomes a Time-Sorting problem. It only works in one direction, if you reverse the direction of the spin you need to re-sort the order of the inputs. With conditionals you can solve the general problem, irrespective of time order.
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: Z-Order Sort for 4 Polygons

Post by Magic »

How would you need to use conditionals? The Expression modifier does support them: https://github.com/ArashPartow/exprtk/b ... readme.txt
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Z-Order Sort for 4 Polygons

Post by artnik »

To set up ranges where "if angle is within this range then this sort order. " From the comment above, it only works in one direction right now without rewiring.

Can I set up multiple "if then" statements with the Exp modifier? I don't see how I can work it.
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: Z-Order Sort for 4 Polygons

Post by blackdot »

i've used multiple consecutive exp modifiers with if statememts successfully. they either do something, or do nothing. if they do nothing and just pass through x, then the next if statement has the chance to do something, etc.
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Z-Order Sort for 4 Polygons

Post by artnik »

@Blackdot. Cool. Can you throw up a quick screenshot of what that looks like?
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Z-Order Sort for 4 Polygons

Post by artnik »

artnik wrote:The main problem with the solution is that it kicks the issue down the road. The Z-Sort problem is solved, but it becomes a Time-Sorting problem. It only works in one direction, if you reverse the direction of the spin you need to re-sort the order of the inputs. With conditionals you can solve the general problem, irrespective of time order.
DOH! User error. I found a sorting error, so now it works irrespective of order. (I guess that's what happens when you stay up to the wee hours working on stuff.) If the Spin Rate Global goes out of the range (0-1) it does mess up, though. An EXPRESSION modifier of (1-x) makes it spin backwards fine. Attachment updated. :-)



AND... conditionals. Is there anything MMV doesn't do?! I misspoke before investigating enough. The way the file is set up it doesn't actually need conditionals now the sort error is fixed. :-/
4_Poly_Z-Sort_Turntable_Bidirectional.magic
(2.99 KiB) Downloaded 421 times
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: Z-Order Sort for 4 Polygons

Post by blackdot »

artnik wrote:@Blackdot. Cool. Can you throw up a quick screenshot of what that looks like?
i wanted to make a little animation of an object that deforms in a certain way when i press different midi inputs. so i did a little test with 3 inputs. to "fake" the object behaving differently i made animations for every possible solution and triggered t hem depending on the inputs i pressed.
so with 3 buttons, you get 7 solutions:
A, B, C, AB, AC, BC and ABC (the order does not matter). so i rendered 7 image sequences and hooked them up like this:
Untitled.jpg
Untitled.jpg (95.7 KiB) Viewed 13679 times
i hope this is understandable :).

the values for 1.1, 1.2 and 1.35 i chose pretty randomly, hoping they would result in unique different numbers if they're added.
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Z-Order Sort for 4 Polygons

Post by artnik »

Thanks Blackdot! That's clever summing the inputs.

That makes total sense. I was having trouble with the syntax, and this makes it crystal clear.

Have you used CASE?
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: Z-Order Sort for 4 Polygons

Post by blackdot »

artnik wrote:Thanks Blackdot! That's clever summing the inputs.

That makes total sense. I was having trouble with the syntax, and this makes it crystal clear.

Have you used CASE?
well i dont know if we can use it :D. that would surely make it more easy instead of using 7 different modifiers. can we use that?
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Z-Order Sort for 4 Polygons

Post by artnik »

Well, if not perhaps in the future? It looks like that library supports more than single line code. It would be like adding scripting. :-)
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: Z-Order Sort for 4 Polygons

Post by blackdot »

woah, switch is actually working.

https://github.com/ArashPartow/exprtk/b ... e.txt#L514

i tried it with

Code: Select all

switch
{
	case x == 1.1 : 10;
	case x == 1.3 : 30;
	case x == 1.5 : 50;
	default : x;
}
and just copied the whole thing into t he expression modifier. it works. awesome :D.
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Z-Order Sort for 4 Polygons

Post by artnik »

Awesome!
damstraversaz
Posts: 176
Joined: Tue Aug 26, 2014 11:22 am

Re: Z-Order Sort for 4 Polygons

Post by damstraversaz »

what a great work, thanks a lot !
skarabee
Posts: 131
Joined: Fri Aug 28, 2015 3:11 am

Re: Z-Order Sort for 4 Polygons

Post by skarabee »

Thank you for this topic, I've learned a lot. I was afraid to use expressions. Now you have cleared the way a bit: I'm still afraid but I have some example to cut my teeth ;-)

Very clever and elegant solution for the Z sorting, hats off!
arash
Posts: 1
Joined: Mon Apr 17, 2017 11:45 pm

Re: Z-Order Sort for 4 Polygons

Post by arash »

@blockdot if the variable x is never exactly assigned the values (1.1, 1.3, 1.5), it's be better to use the 'equal' function which uses a quantized epsilon approach to determining equality between the floating point values.

For example 1.3 and 1.2999999999 (potential value of x) wont be considered equal in the original expression code, however in following code they will be:

Code: Select all

switch
{
   case equal(x,1.1) : 10;
   case equal(x,1.3) : 30;
   case equal(x,1.5) : 50;
   default : x;
}
Post Reply