ICE - Modulo trick and variants

Here you can find ICE tutorials and learning material
Post Reply
User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

ICE - Modulo trick and variants

Post by Daniel Brassard » 17 Oct 2011, 01:33

I was made aware a while ago of the modulo trick to replace loop and counters. The first time was back in May when Stephen Blair poster a screen grab of the modulo trick on XSI Support Blog to generate a better duplicator (screen below).

Then this month Chris_TC posted a variation of the modulo trick on XSI Base to generate an array of points in x and z (screen below as well).

During my experiment with the Bezier surfaces, I used the modulo trick to generate numbers in u and v. The trick was very much similar to Chris_TC.

The modulo trick is still talked about, even on XSI List and I wanted to share some screen of my own to contribute to the conversation about the usefullness of this trick.
Attachments
Stephen_Blair_dup_vertexarray.png
Stephen_Blair_dup_vertexarray.png (132.18 KiB) Viewed 5498 times
point-gridvruu.jpg
point-gridvruu.jpg (121.75 KiB) Viewed 5498 times
Last edited by Daniel Brassard on 17 Oct 2011, 18:00, edited 1 time in total.
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: ICE - Modulo trick and variants

Post by Daniel Brassard » 17 Oct 2011, 01:44

The first thing we notice between Stephen Blair and Chris_TC is Chris is using the build index array node and Stephen is using the build array from constant + get array sub indices combination to feed to the modulo. If you open the build index array compound you will notice that the two nodes that Stephen uses are the build index array. Technically, Chris and Stephen are using the same compounds. Good, to simplify then we will use the build index array.

So, the basic Modulo trick is illustrated as follow.
Attachments
Modulo_basic1.jpg
Modulo_basic1.jpg (25.27 KiB) Viewed 5593 times
Modulo_basic3.jpg
Modulo_basic3.jpg (26.96 KiB) Viewed 5593 times
Modulo_basic2.jpg
Modulo_basic2.jpg (20.29 KiB) Viewed 5593 times
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: ICE - Modulo trick and variants

Post by Daniel Brassard » 17 Oct 2011, 01:55

So, our first experiment is to generate a simple counter / repeat.

Here is the ICE tree and its result.

What does it do, it count from 0 to n-1 (0,1,2 in this case as the modulo by value n is equal to 3) basically repeating these numbers four time. We can use the output from the modulo to select numbers from an arrays to feed the index input of a select from array node and repeat these numbers n times (see Stephen Blair screen at the start of the thread for an example).
Attachments
Modulo_basic5.jpg
Modulo_basic5.jpg (62.87 KiB) Viewed 5593 times
Last edited by Daniel Brassard on 17 Oct 2011, 18:50, edited 5 times in total.
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: ICE - Modulo trick and variants

Post by Daniel Brassard » 17 Oct 2011, 01:59

Using this trick can be advantegeous. Chris_TC used a variation of the trick to generate points on a grid like structure.

Basically, he used the Modulo to give him a basic repeat and both integers inputs to calculate the location of the next point on the grid.
Attachments
Chris_TC.jpg
Chris_TC.jpg (79.58 KiB) Viewed 5498 times
Last edited by Daniel Brassard on 17 Oct 2011, 18:01, edited 1 time in total.
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: ICE - Modulo trick and variants

Post by Daniel Brassard » 17 Oct 2011, 02:04

Here is my take of Chris_TC trick. Both (Chris_TC and Mine) will generate the same numbers/points.

My take is to use a combination of Modulo and Sort to generate the first series of numbers in the array (x). The second numbers are the same between Chris and I.
Attachments
Chris_TC_variant.jpg
Chris_TC_variant.jpg (80.29 KiB) Viewed 5592 times
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: ICE - Modulo trick and variants

Post by Daniel Brassard » 17 Oct 2011, 02:20

Expanding in the third dimension is very similar. This time we have to generate the numbers in a certain order to get the effect we want.

Below is the ICE Tree that expand the trick in the third dimension. This can be used to select numbers in three different arrays to generate effects or points.

You will notice that the top and bottom row of nodes are the same as the uv ICE tree above. The trick is the middle row of nodes that include two modulo nodes and one sort node.
Attachments
UVW_Counter2.jpg
UVW_Counter2.jpg (71.37 KiB) Viewed 5592 times
UVW_Counter.jpg
UVW_Counter.jpg (67.16 KiB) Viewed 5592 times
Last edited by Daniel Brassard on 17 Oct 2011, 18:12, edited 5 times in total.
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: ICE - Modulo trick and variants

Post by Daniel Brassard » 17 Oct 2011, 02:25

Using the Modulo trick, here is the ICE tree of the counter I used to generate the UV numbers (between 0 and 1) for the Bezier surface.
Attachments
UV_Counter.jpg
UV_Counter.jpg (56.13 KiB) Viewed 5591 times
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: ICE - Modulo trick and variants

Post by Daniel Brassard » 17 Oct 2011, 02:28

And the UVW version of the ICE tree (with output between 0 and 1 in x, y and z).
Attachments
UVW_Counter3.jpg
UVW_Counter3.jpg (64.03 KiB) Viewed 5591 times
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: ICE - Modulo trick and variants

Post by Daniel Brassard » 17 Oct 2011, 02:30

Here it is, my little contribution to the modulo trick. Hope this information will be useful.

If you have a Modulo trick of your own, feel free to share using this thread.

Cheers!

Dan
Last edited by Daniel Brassard on 17 Oct 2011, 18:18, edited 2 times in total.
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: ICE - Modulo trick and variants

Post by Hirazi Blue » 17 Oct 2011, 12:06

Interesting, thanks... ;)
This being a tutorial (of sorts) I took the liberty to move it to the "ICE Tutorials" forum
Stay safe, sane & healthy!

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: ICE - Modulo trick and variants

Post by Daniel Brassard » 17 Oct 2011, 18:04

Thanks Hirazi Blue.
$ifndef "Softimage"
set "Softimage" "true"
$endif

Chris_TC
Posts: 411
Joined: 22 Mar 2010, 17:43

Re: ICE - Modulo trick and variants

Post by Chris_TC » 22 Oct 2011, 11:18

Thank you for the thread. Even though I use the modulo trick, I always have to do trial and error because it requires a somewhat unusual way of thinking.
Is there a specific thread on XSI list that discusses it?

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: ICE - Modulo trick and variants

Post by Daniel Brassard » 23 Oct 2011, 23:02

Thank Chris.

A couple of threads on XSI List are about using the modulo trick to avoid the repeat node and multiple mention of the trick to generate sequential numbers, but I have not stumble yet on a specific thread about the trick itself. That is why I create this thread.

The closest, is probably the one from Steve Blair on XSI Support.

http://xsisupport.wordpress.com/2011/05 ... -compound/
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: ICE - Modulo trick and variants

Post by Daniel Brassard » 02 Nov 2011, 03:04

This trick use the modulo to create the quad description for my bezier patch topology.

You can use this trick to create the polygon description of a grid topology of any U and V size!

Simple, effective and quick! No repeat here!
Attachments
Modulo_quads.jpg
Modulo_quads.jpg (60.01 KiB) Viewed 3089 times
$ifndef "Softimage"
set "Softimage" "true"
$endif

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests