#!/usr/bin/perl

#
# Duplicate the selected item a handful of times, offsetting each,
# and putting all the instances into a fresh group.
#
# poly@omino.com
# www.omino.com/pixelblog/
#

use strict;

BEGIN { push( @INC, "/Users/poly/Sites/src/modo/misc"); }
use omino_modo_lib;


my $G_VARIABLES = {
    x_repeats => "integer" ,
    x_offset => "float" ,
    y_repeats => "integer",
    y_offset => "float",
    z_repeats => "integer",
    z_offset => "float"
};

my $G_PREFIX = "omino_dupes";

lxSetVariables($G_VARIABLES,$G_PREFIX);

# |
# | omGroups is a list of letters, like "abjk".
# |
sub dupes($)
{
    my ($args) = (@_);
    my $xOffset = $$args{x_offset};
    my $yOffset = $$args{y_offset};
    my $zOffset = $$args{z_offset};
    my $xRepeats = $$args{x_repeats};
    my $yRepeats = $$args{y_repeats};
    my $zRepeats = $$args{z_repeats};

    for(my $x = 0; $x < $xRepeats; $x++)
    {
        for(my $y = 0; $y < $yRepeats; $y++)
        {
            for(my $z = 0; $z < $zRepeats; $z++)
            {
                next if $x == 0 && $y == 0 && $z == 0;
                lx("item.duplicate instance:true");
                lx("item.channel name:pos.X value:" . ($x * $xOffset));
                lx("item.channel name:pos.Y value:" . ($y * $yOffset));
                lx("item.channel name:pos.Z value:" . ($z * $zOffset));
            }
        }
    }
}

sub main(@)
{
    
    my $args = lxGetVariables(@_);
    my $s;

    foreach my $key (keys(%$args))
    {
        $s .= $key . "=" . $$args{$key} . ";";
    }

    lxInfo("" . $s);
    dupes($args);
}

main(@ARGV);

