#!/usr/bin/perl

#
# This MODO script will enable and disable items in your scene
# based on the name. You can mark items as being a member of a
# group, a-z, by adding onto the name omg:a or omg:abc or omg:x.
# At item can be a member of multiple groups.
#
# Run the script like:
#     omg.pl a  -- turn on all group a, turn off all other groups
#     omg.pl d  -- turn on all group d, turn off all other groups
#     omg.pl abx  -- turn on all group a,b, and x, turn off rest
#
# A second argument will enable and disable indirect illumination,
# 1 for on, 0 for off.
#
# To leave all the named groups as is, pass -. So
# omg.pl - 1 turns on indirect illumination, leaving groups as-is
#
# poly@omino.com
# www.omino.com/pixelblog/
#

use strict;
use omino_modo_lib;


# |
# | omGroups is a list of letters, like "abjk".
# |
sub switchItems($)
{
    my ($omGroups) = (@_);

    my $omGroupsPattern = "[$omGroups]"; # cheesy but effective

    my $k = lxGetItemCount();
    for(my $i = 0; $i < $k; $i++)
    {
        my $name = lxGetItemName($i);
        my $type = lxGetItemType($i);
        my $id = lxGetItemId($i);
        {
            if($name =~ /omg:([a-zA-Z]*)/)
            {
                # this item is tagged 
                my $letters = $1;
                my $gotIt = -1;
                if($letters =~ /$omGroupsPattern/)
                {
                    $gotIt = 1;
                }
                lxSetLayerVisible($i,$gotIt);
            }
        }
    }
}

sub main(@)
{

    my ($arg1,$arg2) = (@_);
    # arg1 is which omg-letters to activate
    # arg2 is boolean for global illumination
    if($arg1 ne "-")
    {
        switchItems($arg1);
    }

    if($arg2 ne "-")
    {
        lxSetIndirectIllum($arg2);
    }
}

main(@ARGV);

