summaryrefslogtreecommitdiffstats
path: root/tools/MayaTools/Maya4.0/scripts/SimpsonsArt/snapCurveY.mel
blob: 8292125e3ba1654dcdead1ea2c2f9369ca9696cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
global proc int srrRound( float $val )
{
    int     $intPart = trunc( $val );
    float   $decPart = $val - $intPart;

    $val = $intPart;
    if ( $decPart >= 0.5 ) $val += 1;

    return $val;
}


global proc snapCurveY( float $precision )
{
    $precision = abs( $precision );

    string $curves[];
    $curves = `ls -type nurbsCurve`;

    string $curve;
    for ( $curve in $curves )
    {
        int $numcvs;
        string $curvecmd = ($curve + ".cp");
        $numcvs = `eval getAttr -size $curvecmd`;
		
        float $cv[ 3 ];
        int $i = 0;
        for ( $i = 0; $i < $numcvs; $i++ )
        {
            $curvecmd = ($curve + ".cp[" + $i + "]");
            $cv = `eval getAttr $curvecmd`;
            
            if ( $precision == 1 )
            {
                $cv[ 1 ] = ceil( $cv[ 1 ] );
            }

            if ( $precision > 1 )
            {
                float $div = $cv[ 1 ] / $precision;

                int $integerpart = trunc( $div );
                float $decpart = $div - $integerpart;

                if ( $decpart < 0.5 )
                {
                    $decpart = 0;
                }
                else
                {
                    $decpart = 1;
                }

                float $newdiv = $integerpart + $decpart;

                $cv[ 1 ] = $precision * $newdiv;
            }

            if ( $precision < 1 )
            {
                float $div = $cv[ 1 ] / $precision;

                $div = srrRound( $div );

                float $newdec = $precision * $div;

                $cv[ 1 ] = $newdec;
            }

            $curvecmd = ($curve + ".cp[" + $i + "].yv");
            eval setAttr $curvecmd $cv[ 1 ];
        }
    }
}