Skip to content

Commit

Permalink
0.62
Browse files Browse the repository at this point in the history
  • Loading branch information
creaktive committed Jul 19, 2003
1 parent 74c8696 commit 6f665e1
Show file tree
Hide file tree
Showing 16 changed files with 63,925 additions and 62,050 deletions.
2 changes: 1 addition & 1 deletion acftools.pl
Expand Up @@ -28,7 +28,7 @@
use File::Spec::Functions;

use vars qw($VERSION);
$VERSION = '0.61';
$VERSION = '0.62';
use constant DEFS => 'defs';
use constant LIB => 'lib';

Expand Down
3 changes: 3 additions & 0 deletions data/airfoil.lst
Expand Up @@ -65,3 +65,6 @@ MV 3211 HS.afl goe09k.dat

# F14.acf
Flat Platef14hstab.afl goe09k.dat

# Piper Malibu.acf
NACA 23015 (standrough).afl naca23015.dat
5 changes: 5 additions & 0 deletions docs/ChangeLog.txt
Expand Up @@ -29,3 +29,8 @@ v0.61
- ACFTools can now run from PATH
- minor docs/help fixes
- added models/Seabee.ac model by Tracy Walker sample
v0.62
- rewritten major part of XPlane::Convert::AC3Dparse
- now using AC3D 'loc' attribute to get/set bodies arm
- Win32 binary is now made with PAR - Perl Archive Toolkit
- recreated models/*
2 changes: 1 addition & 1 deletion docs/README.txt
@@ -1,5 +1,5 @@
##############################################################################
[ACFTools v0.61] Set of tools to play with ACF files outside of Plane-Maker
[ACFTools v0.62] Set of tools to play with ACF files outside of Plane-Maker
Perl script and modules coded by Stanislaw Pusep <stas@sysd.org>
Site of this and another X-Plane projects of mine: http://xplane.sysd.org/

Expand Down
9 changes: 3 additions & 6 deletions lib/XPlane/Convert/AC3Dgen.pm
Expand Up @@ -102,12 +102,6 @@ sub AC3Dgen {

# next if $v[0] == 0 && $v[1] == 0 && $v[2] == 0;

if (defined $arm[$part]) {
for (my $i = 0; $i < 3; $i++) {
$v[$i] += ${$arm[$part]}[$i];
}
}

push @{$ver[$part]}, [@v];
} elsif ($lval =~ /_is_left\[(\d+)\]/) {
wparm (\@wng, $1, 'is_left', $rval);
Expand Down Expand Up @@ -254,9 +248,12 @@ EOH
$nv += $nver;
$np++;

my $loc = join ' ', @{$arm[$part]};

print AC3D <<EOO
OBJECT poly
name "body[$part]"
loc $loc
numvert $nver
EOO
;
Expand Down
22 changes: 15 additions & 7 deletions lib/XPlane/Convert/AC3Dmerge.pm
Expand Up @@ -38,14 +38,20 @@ sub AC3Dmerge {
my ($ac3, $txt, $noorder) = @_;
local $_;

my ($name, @ver) = AC3Dparse ($ac3);
my $numvert = scalar @ver;
my ($name, $ver, $arm) = AC3Dparse ($ac3);
my $part;
if ($name =~ /\[(\d+)\]/) {
$part = $1;
} else {
die "Malformed object name (should be 'body[N]' where N is proper integer)\n";
}
my $numvert = scalar @{$ver};
if ($numvert != 360) {
print STDERR "Warning: I expect 360 vertices and $ac3 has $numvert\n";
}
$name = quotemeta $name;

@ver = ACForder (18, @ver) unless $noorder;
$ver = ACForder (18, $ver) unless $noorder;

local @ARGV = ($txt);
$^I = '.bak';
Expand All @@ -63,13 +69,15 @@ sub AC3Dmerge {
my ($type, $lval, $rval) = split /\s+/, $_, 3;
my $start = "$type\t$lval\t= ";
if ($lval =~ /$name/) {
if (@ver) {
$line = $start . '{ ' . join (', ', @{shift @ver}) . " }\n";
if (@{$ver}) {
$line = $start . '{ ' . join (', ', @{shift @{$ver}}) . " }\n";
$nv++;
} else {
$line = $start . '{ 0, 0, 0 }' . "\n";
$dfct++;
}
} elsif (@{$arm} == 3 && $lval =~ /_arm\[$part\]$/) {
$line = $start . '{ ' . join (', ', @{$arm}) . "}\n";
}
} continue {
print $line;
Expand All @@ -78,8 +86,8 @@ sub AC3Dmerge {

if ($dfct) {
printf STDERR "Import warning: %d vertex deficit!\n", $dfct;
} elsif (@ver) {
printf STDERR "Import warning: %d vertex exceeded!\n", scalar @ver;
} elsif (@{$ver}) {
printf STDERR "Import warning: %d vertex exceeded!\n", scalar @{$ver};
}

return ($nv, $nl);
Expand Down
89 changes: 47 additions & 42 deletions lib/XPlane/Convert/AC3Dparse.pm
Expand Up @@ -37,56 +37,70 @@ sub AC3Dparse {
local $_;

open (AC3D, $ac3) || die "Can't open $ac3: $!\n";
$_ = <AC3D>;
$_ = scalar <AC3D>;
die "Unknown AC3D file format!\n" unless /^AC3Db/i;

my $kids = &seek_key (\*AC3D, 'kids');
die "Can only import one object per AC3D file!\nPlease delete objects you do not need to merge or put them into separate files.\n" if $kids != 1;
my $name = &seek_key (\*AC3D, 'name');
my @ac3d = ();
while (<AC3D>) {
chomp;
s/\s+$//;
next unless $_;
push @ac3d, $_;
}
close AC3D;

my $count = 0;
my %header = ();
foreach (@ac3d) {
if (/^\d/) {
last;
} elsif (/^([a-z]+)\s+(.+)$/i) {
$header{$1} = $2;
}

$count++;
}

my $kids = &check (kids => \%header);
if ($kids != 1) {
die "Can only import one object per AC3D file!\n" .
"Please delete objects you do not need to merge or put them into separate files.\n";
}
my $name = &check (name => \%header);
$name =~ s/^"//;
$name =~ s/"$//;
my $numvert = &seek_key (\*AC3D, 'numvert');
my $numvert = &check (numvert => \%header);

my @loc = ();
if (defined $header{loc}) {
@loc = split /\s+/, $header{loc};
die "Broken AC3D format with non-3D coordinate ;)\n" if @loc != 3;
}

my @ver = ();
my @max = qw(0 0 0);
my @min = qw(0 0 0);
for (my $i = 0; $i < $numvert; $i++) {
$_ = <AC3D>;
$_ = $ac3d[$count++];
chomp;
s/\s+$//;
my @v = split /\s+/, $_;
die "Vertex #$i doesn't looks good!\n" unless @v == 3;
push @ver, [@v];

&centre (\@v, \@min, \@max);
}
die "$ac3 seems to be broken!\n" if scalar @ver != $numvert;
close AC3D;

my @arm = ();
for (0..2) {
$arm[$_] = $min[$_] + (($max[$_] - $min[$_]) / 2);
}

for (my $i = 0; $i < $numvert; $i++) {
for (0..2) {
${$ver[$i]}[$_] -= $arm[$_];
}
}

return ($name, @ver);
return ($name, [@ver], [@loc]);
}

sub ACForder {
my ($verps, @ver) = @_;
my $numvert = scalar @ver;
my ($verps, $ver) = @_;
my $numvert = scalar @{$ver};
die "AC3D file can't be ordered in $verps-vertex sections!\n" if $numvert % $verps;

my @sort = ();
my (@max, @min);
for (my $i = 0; $i < $numvert / $verps; $i++) {
my %sort = ();
my @sect = splice @ver, 0, $verps;
my @sect = splice @{$ver}, 0, $verps;

@max = qw(0 0 0);
@min = qw(0 0 0);
Expand Down Expand Up @@ -137,22 +151,7 @@ sub ACForder {
}
}

return @sort;
}

sub seek_key {
my ($file, $key) = @_;
local $_;
my $val = '';
while (<$file>) {
chomp;
s/\s+$//;
if (/^$key\s+(.+)$/i) {
$val = $1;
last;
}
}
return $val;
return [@sort];
}

sub centre {
Expand All @@ -167,4 +166,10 @@ sub centre {
return;
}

sub check {
my ($var, $header) = @_;
die "AC3D attribute '$var' undefined!\n" unless defined ${$header} {$var};
return ${$header} {$var};
}

1;
3 changes: 2 additions & 1 deletion lib/XPlane/Convert/ACFparse.pm
Expand Up @@ -64,7 +64,8 @@ sub ACFparse {
sysread (ACF, $_, 4) || die "Can't read signature from $acf: $!\n";
$_ = reverse $_ if $endian_swap;
my $version = unpack 'i', $_;
print STDERR "ACF appears to come from X-Plane version [$version]\n\n";
print STDERR "ACF appears to come from X-Plane version [$version]\n",
"Using definition '$def'\n\n";

sysseek (ACF, 0, SEEK_SET);

Expand Down
9 changes: 3 additions & 6 deletions lib/XPlane/Wing.pm
Expand Up @@ -99,11 +99,13 @@ sub wing {
}
}

my $loc = join ' ', @{$data{arm}};

my $nv = scalar @sec;
print $file <<EOH
OBJECT poly
name "wing[$data{index}] // $fname"
loc 0 0 0
loc $loc
numvert $nv
EOH
;
Expand Down Expand Up @@ -154,11 +156,6 @@ sub wsec {
@ver = (-$z, $y, $x);
}

# arm
for (0..2) {
$ver[$_] += $$arm[$_];
}

# save
push @wsec, [@ver];
}
Expand Down
Binary file added lib/airplane.ico
Binary file not shown.
1 change: 1 addition & 0 deletions lib/make_exe.bat
@@ -0,0 +1 @@
@pp -v -i airplane.ico -o ../acftools.exe ../acftools.pl

0 comments on commit 6f665e1

Please sign in to comment.