#!/usr/bin/perl -w
# XRACER (C) 1999-2000 Richard W.M. Jones <rich@annexia.org> and other AUTHORS
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# $Id: xracer-mkcraft.pl,v 1.1 2000/01/03 22:42:43 rich Exp $

use strict;

use Getopt::Long;

use lib '../../XRacer/blib/lib'; # So you can run this without installing it.
use XRacer::BVRML;

# Read command line arguments.
my $outputfilename;
my $verbose;
my $help;

GetOptions ("output=s" => \$outputfilename,
	    "verbose" => \$verbose,
	    "help|?" => \$help);

if ($help)
  {
    print STDERR "$0 [--output OUTPUTFILE] [--verbose] [INPUTFILE]\n";
    print STDERR "where: OUTPUTFILE is the C file to write\n";
    print STDERR "       INPUTFILE is the input Blender VRML (.wrl) file\n";
    exit 1;
  }

# Parse the input file.
my $world = undef;
my $filename;

foreach $filename (@ARGV)
  {
    $world = XRacer::BVRML->parse ($filename, $world)
      or die "cannot parse input file: $filename: $!";
  }

# Print some info about this object.
if ($verbose)
  {
    print "number of vertices: ", $world->nr_vertices, "\n";
    print "number of faces:    ", $world->nr_faces, "\n";
    print "bounding box:       ", join (", ", $world->bbox), "\n";
  }

# Generate the C output file.
if ($outputfilename)
  {
    open C, ">$outputfilename"
      or die "$outputfilename: $!";

    print C "/* This file describes the shape of a craft.\n * It is automatically generated.\n */\n\n#include \"common.h\"\n\n";

    $world->write_display_function ( name => "display_craft",
				     filehandle => \*C
				   );

    print C "/* EOF */\n";

    close C;
  }

exit 0;

=pod

=head1 NAME

xracer-mkcraft - generate a XRacer vehicle from a Blender VRML file

=head1 SYNOPSIS

xracer-mkcraft [ B<--output> OUTPUTFILE ] [ B<--verbose> ] [ INPUTFILE ]

=head1 DESCRIPTION

I<xracer-mkcraft> is a perl script that takes a Blender VRML file (.wrl)
INPUTFILE and optionally generates a C source file OUTPUTFILE that contains
code suitable to be used as a vehicle description in the game XRacer.

=head1 OPTIONS

=over 7

=item B<--output> I<OUTPUTFILE>

Specifies the C source file to write the vehicle description to. If omitted,
B<xracer-mkcraft> just processes the INPUTFILE and checks for validity.

=item B<--verbose>

Be verbose in the processing of the .wrl INPUTFILE

=back

=head1 SEE ALSO

L<xracer(6)>, L<XRacer::BVRML(3pm)>

=head1 AUTHOR

This documentation for B<xracer-mkcraft> was written by Filip Van Raemdonck
(mechanix@digibel.org) for the Debian prepackaged version of XRacer. It is
uncertain which of the persons listed in the AUTHORS file distributed with the
XRacer sources has written the actual script.

=cut
