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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
#!/opt/bin/perl
# [10/27/1999] v0.0.1 First version.
# (c) Copyright by Tels www.bloodgate.com 1999.
# generate a brick texture for using in 3d games
#
# params: brick width/height, brick pattern, random light skew, border color
#
# 12/5/03: <sjburges@gimp.org> updated to use gimp_image_get_floating_sel,
# rather than gimp_image_floating_sel, gimp_undo_push/gimp_image_undo_push
#
# 25/2/04: <sjbkurges@gimp.org> changed color specifiers. Reordered so that
# pasting happens after layer mask is attached to image. Removed harmful
# gimp_layer_delete() calls. s/gimp_channel_ops_offset/gimp_drawable_offset/.
#
# The plug-in is certainly incomplete, with unused parameters, artficial limiation
# on max/min size (which silently moves it to 256?). Doesn't save/restore current
# gimp pattern/colors before setting them. Otherwise, it seems to work OK now :)
use Gimp qw(:auto N_);
use Gimp::Fu;
use Gimp::Util;
sub do_bricks {
my ($pattern,$pattern2,$bp,$clr,$bw,$brickx,$bricky,$imgw,$imgh,$skew) = @_;
my ($image, $layer, $state, $layerpat);
$imgw = abs($imgw); $imgw = 256 if (($imgw < 32) || ($imgw > 4096));
$imgh = abs($imgh); $imgh = 256 if (($imgh < 32) || ($imgh > 4096));
#print "Creating texture $imgw"."x$imgh\n";
$image = gimp_image_new($imgw,$imgh,RGB);
# make background
gimp_patterns_set_pattern($pattern);
$layerpat = gimp_image_add_new_layer($image,0,0,0);
gimp_selection_all($image);
gimp_edit_bucket_fill($layerpat,2,0,100,0,0,1,1);
# make border lines
gimp_palette_set_foreground ([1,1,1]);
$layer = gimp_image_add_new_layer($image,0,0,0);
gimp_drawable_fill($layer,3);
my $w = 1; my $h = 1; my $j = 0; my $wo = 0;
my $brickw = ($imgw / $brickx); my $brickh = ($imgh / $bricky);
gimp_image_undo_group_start($image);
while ($h < $imgh)
{
gimp_rect_select($image,0,$h,$imgw,$bw,2,0,0);
gimp_edit_bucket_fill($layer,0,0,100,0,0,0,0);
$w = 1;
$wo = 0; $wo = ($brickw / 2) if ($j == 1);
while ($w < $imgw)
{
gimp_rect_select($image,$w+$wo,$h,$bw,$brickh+1,2,0,0);
gimp_edit_bucket_fill($layer,0,0,100,0,0,1,1);
# print "$h $w\n";
$w += $brickw;
}
$j = 1 - $j;
$h += $brickh;
}
gimp_image_undo_group_end($image);
# make a copy of it for bump mapping
gimp_selection_all($image);
$layer->edit_copy();
$border = gimp_image_add_new_layer($image,0,0,0);
#print "$border\n";
$border->edit_paste(0);
gimp_floating_sel_anchor(gimp_image_get_floating_sel($image));
gimp_selection_none($image);
# somebody seems to have changed the parameter for the following 3 lines
# omy office machine use the old variant, at home I need the new :(
# Changed text:
#plug_in_gauss_iir (1,$image,$border,1,1,1);
#plug_in_gauss_iir (1,$image,$layer,2,1,1);
#plug_in_bump_map (1,$image,$layerpat,$layer,257,40,3,0,0,0,0,1,0,1);
plug_in_gauss_iir (1,$border,1,1,1);
plug_in_gauss_iir (1,$layer,2,1,1);
plug_in_bump_map (1,$layerpat,$layer,280,40,2,0,0,0,0,1,0,1);
# overlay border lines and random skew bricks
gimp_image_undo_group_start($image);
$h = 0; $j = 0; $wo = 0;
while ($h < $imgh)
{
$w = 0; $wo = 0; $wo = ($brickw / 2) if ($j == 1);
while ($w < $imgw)
{
$r = int(rand ($skew) - ($skew / 1));
if ($r != 0)
{
gimp_palette_set_foreground ("#ffffff") if ($r > 0);
gimp_palette_set_foreground ("#000000") if ($r < 0);
gimp_rect_select($image,$w+$wo+$bp,$h+$bp,$brickw,$brickh,2,0,0);
gimp_edit_bucket_fill($layerpat,0,0,4*abs($r),0,0,1,1);
# halves
if (($j == 1) && ($w+$wo+$brickw > $imgw))
{
gimp_rect_select($image,0,$h+$bp,$brickw/2,$brickh,2,0,0);
gimp_edit_bucket_fill($layerpat,0,0,4*abs($r),0,0,1,1);
}
}
$w += $brickw;
}
$j = 1 - $j;
$h += $brickh;
}
gimp_image_undo_group_end($image);
gimp_palette_set_background ($clr);
$layerb = gimp_image_add_new_layer($image,1,BACKGROUND_FILL,0);
gimp_selection_all($image);
if ($bp ne "")
{
gimp_patterns_set_pattern($bp);
gimp_edit_bucket_fill($layerb,2,0,100,0,0,1,1);
}
$border->edit_copy();
gimp_layer_add_alpha($layerb);
$mask = gimp_layer_create_mask($layerb,0);
gimp_image_add_layer_mask($image,$layerb,$mask);
$mask->edit_paste(0);
gimp_floating_sel_anchor(gimp_image_get_floating_sel($image));
gimp_selection_none($image);
gimp_image_remove_layer ($border);
gimp_image_remove_layer ($layer);
gimp_image_remove_layer_mask ($image,$layerb,0);
gimp_drawable_offset ($layerpat,1,0,-1,-1);
gimp_drawable_offset ($layerb,1,0,-1,-1);
$image;
}
register
"do_bricks",
"Generate brick texture",
"Try it out",
"Tels",
"http://bloodgate.com",
"10/26/1999a",
N_"<Toolbox>/Xtns/Render/Bricks...",
undef,
[
[PF_PATTERN, "background", "Brick pattern", "Leather"],
[PF_STRING, "highlight", "Second brick pattern for some highlightin (unused)", "unused yet"],
[PF_STRING, "borderpattern", "Border pattern (empty for none)", ""],
[PF_COLOR, "color", "Border color", [0.80,0.80,0.80]],
[PF_SPINNER, "borderwidth", "Border width", 1, [0,1000,1]],
[PF_STRING, "brickx", "Bricks in X", 8],
[PF_STRING, "bricky", "Bricks in Y", 16],
[PF_STRING, "imagew", "Width of image", 256],
[PF_STRING, "imageh", "Height of image", 256],
[PF_STRING, "skew", "Random darken/lighten factor (0..20)", 0]
],
\&do_bricks;
exit main();
=head1 LICENSE
Copyright Tels.
Licenced under the GNU Public License.
=cut
|