hello all....
I'm a noob to anim8or and ASL... been playing with anim8or for a couple of months and decided i could use some plug-ins for my models of houses, specifically the windows. I have tried ever possible permutation of SetMaterial to try and set the window frame to one material and the glass to another, none of which works... sooooo... is this possible with a script??? the docs say I should be able to do this, but as I said, I'm sure I've tried every combination of instructions with no luck.... the resulting model .an8 file shows only face 4 4 0 -1(trim) (no face 4 4 1 -1(glass)).. could sure use some help with this, as most of my plug-ins will need to have at least two materials.
I've read most of the posts and find no subjects addressing this problem,(maybe i'm just too stoopid to realize my mistake...lol), but at the same time I saw a lot of requests for a script hat would make an ASL plug-in from a model, so I wrote this little gem which will do just that for most
simple! models...its works fine on my windows(some have over a thousand faces!!!). I'm not sure if it is allowed to post a perl script on this board, but I have no website to post it to.... so here it is:
Model2script.pl (m2s.pl)
#!/perl/bin/perl
##### Windows perl =
http://www.activestate.com/activeperl/downloads ActivePerl-5.8.8.822-MSWin32-x86-280952.msi... free!!!!
##### a little script that extracts the points and faces from an anim8or model.an8 file
##### then uses them to write them to write an .a8s script...
##### command line = c:\>m2s.pl model-name.an8... this program expects the model to be in C:/anim8or/projects
##### output = c:/anim8or/scripts/model-name.a8s
##### notes: 1. output is formatted for Notepad... arial/regular 12 pt...
##### 2. this will only extract the first mesh of a model... so <join solids> and <convert to mesh> the model first....
##### 3. you will have to apply texcoords to the generated model yourself... it was becoming too much of a chore as it was...
##### 4. the plug-in will show as the default electric plug... you'll have figure out the bit map button yerself... lol
##### 5. the newly generated parametric is NOT editable, even if you convert it to a mesh...if you need to edit the new model,
##### save it first, reopen he saved model and then you can do any editing.....
##### I haven't really figured out how the meshes are drawn orignally, so the script creates double points for some faces...
##### but saving it will remove the extra points and then all is well.... rick... FIXED!!!...sorta... lol
use strict;
use warnings;
our ($s, $ps, $x, $fp, $file, $i, $f, @pts, $p, $l, $fs, $ts, $ii, $pc, $sx);
our $spaces = " "x50;
$file = shift;
open IN, "<C:/anim8or/projects/$file"; print "Working with $file\n";
while (<IN>)
{
if ($_ eq " points {\n")
{
while ( <IN> )
{
if ( $_ eq " }\n" ){goto faces;} # can't modify $_ ... and a little lesson in regex ... lol
$s = $_; # $s = " (x.xxxxx x.xxxxx x.xxxxx) (x.xxxxx x.xxxxx x.xxxxx) " ...etc.
$s =~ s/^\s+//; # ^^^^^^ remove these leading spaces...
$s =~ s/\s{1}/\,/g; # ^ ^ ^ ^ ^ ^ substitute "," for " "
$s =~ s/\),/\)\; /g; # ^ substitute "); " for "),"
$s =~ s/\s\,$/ /; # ^ substitute " " for trailing " ,"
$ps .= $s; # append the line to a new string
}
}
faces:
if ($_ eq " faces {\n")
{
$i = 0; $ts=""; $ii = 0;
while ($s = <IN>)
{
if ( $s eq " }\n" ){goto done;}
$s =~ s/^\s+//;
if ( $s !~ /\)\s\)$|\)\s\)\s$/ )
{
$sx = <IN>; $sx=~ s/^\s+//;
$s .= $sx;
$s =~ s/\)\(/) (/;
}
$s =~ s/(\d+)\s(\d+)//;
$fs .= "\$faces\[$ii\] = ($1, $2); ". substr ($spaces, 0, 20-(17+(length($1)+length($2)-length($ii))));
$ii++; if ( $ii%6 == 0 ){$fs .= "\n";}
$s =~ s/(\s\d*\s)(\-\d*\s\(\s)//;
while ( length($s) > 3 )
{
$s =~ s/\((\d*)\s\d*\)\s//;
$s =~ s/\((\d*)\)\s//;
$ts .= "\$q[$i] = $1; ". substr ($spaces, 0, 20-(14+length($1)+length($i)));
$i++; if ( $i%10 == 0 ){$ts .= "\n";}
}
}
}
}
done: close IN; # if you want more then one plug-in generated by this script, you'll need to change
# \$basic to something else(\$basic2 comes to mind...lol)all thru this script...
$fp = "/*$spaces m2s.pl generated script for: $file. By: Freesailor Raceware */\n
/* Define Directives */
\#plugin(\"object\", \"mesh\", \"Basic\")\;
\#return(\$basic)\;
/* Declare Variables */
shape \$basic;
int \$i, \$x, \$pc, \$q[$i];\n";
@pts = split (" ", $ps); # split string into an array...
$x = scalar(@pts)-1; $f = $x+1; $l = 0; # $x = numer of array elements...
$fp.= "point3 \$p[$f];
point2 \$faces[$ii];\n
/* Make Assignments */\n";
for $i ( 0..$x ) # get largest array element length...
{
if ( length( $pts[$i] ) > $l )
{
$l = length( $pts[$i] )
}
}
$l = $l+11; $f = 0; # this works up to array element 999... if array is larger change 11 to 12...
for $i ( 0..$x )
{
$p = "\$p\[$i\] = $pts[$i] "; # here we format the output to print the correct asl assignment instruction...
# if you modify for all meshes..
$p .= substr ($spaces, 0, $l-length($p)); # make it look pretty...
$fp.= $p; # append to final print line...
$f++; if ($f == 4) { $fp .= "\n"; $f = 0; } # $f = number of point3 arrays per line...
}
$fp .= "\n$fs\n\n$ts\n"; # add our face and face vertex index arrays to the print line...then the code to execute...
$fp .= "
/* Draw Parametric */
\$pc = 0;
\$basic.Open();
for \$i = 0 to \$p.size-1 do
{
\$basic.AddPoint(\$p[\$i]);
}
for \$i = 0 to \$faces.size-1 do
{
\$basic.OpenFace(0,4);
for \$x = \$pc to \$pc+(\$faces[\$i].x-1) do
{
\$basic.VertexN(\$q[\$x]);
}
\$basic.CloseFace();
\$pc = \$pc+\$faces[\$i].x;
}
\$basic.Close();
\n";
$fp .= "/*$spaces script for $file$spaces */";
print "\n$fp\n";
$file =~ s/.an8/.a8s/;
open OUT, ">C:/anim8or/scripts/$file";
print OUT "$fp\n";
close OUT;
exit;
hmmmm.. comments didn't copy so well, but you get the idea...lol
as the script comments, it does have some flaws, but will create a .a8s script that duplicates your model(simple ones please!!!)
aloha
freesailor