diff -uNr lib3ds-1.3.0.orig/tools/3ds2m.1 lib3ds-1.3.0/tools/3ds2m.1 --- lib3ds-1.3.0.orig/tools/3ds2m.1 1970-01-01 01:00:00.000000000 +0100 +++ lib3ds-1.3.0/tools/3ds2m.1 2007-11-03 07:23:44.000000000 +0100 @@ -0,0 +1,38 @@ +.TH 3ds2m 1 "12 Jan 2001" Version 1.0 +.SH NAME +3ds2m - Converts meshes of a 3DS file into a m-file. +.SH SYNOPSIS +.B 3ds2m +[options] filename [options] +.SH DESCRIPTION +.PP +\fI3ds2m\fP is a tool to convert meshes of a 3DS file into a m-file. +.SH OPTIONS +.l +\fI3ds2m\fP accepts the following options: +.TP 8 +.B -h/--help +This help +.TP 8 +.B -o/--output +Write output to instead of stdout +.TP 8 +.B -m/--mesh name +Write only specific mesh.B -c/--camera +.SH COPYRIGHT +3ds2m Copyright \(co 1996-2001 by J.E. Hoffmann +.PP +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. +.PP +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. +.PP +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., 675 Mass Ave, Cambridge, MA 02139, USA. + diff -uNr lib3ds-1.3.0.orig/tools/3ds2m.c lib3ds-1.3.0/tools/3ds2m.c --- lib3ds-1.3.0.orig/tools/3ds2m.c 1970-01-01 01:00:00.000000000 +0100 +++ lib3ds-1.3.0/tools/3ds2m.c 2007-11-03 07:23:44.000000000 +0100 @@ -0,0 +1,211 @@ +/* + * The 3D Studio File Format Library + * Copyright (C) 1996-2001 by J.E. Hoffmann + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 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 Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id: lib3ds-1.3.0-3ds2m.diff,v 1.1 2007/11/03 07:34:11 corsepiu Exp $ + */ +#include +#include +#include +#include +#include +#include +#ifdef WITH_DMALLOC +#include +#endif + + +/*! +\example 3ds2m.c + +Converts meshes of a 3DS file into a m-file. + +\code +Syntax: 3ds2m [options] filename [options] + +Options: + -h/--help This help + -o/--output filename Write output to file instead of stdout + -m/--mesh name Write only specific mesh +\endcode + +A m-file is a simple data format storing vertex and face information of a polygonal mesh. +It has the following structure. + +\code +# +# +# +Vertex +... +Face ... +\endcode + +\author J.E. Hoffmann +*/ + + +static void +help() +{ + fprintf(stderr, +"The 3D Studio File Format Library - 3ds2m Version " VERSION "\n" +"Copyright (C) 1996-2001 by J.E. Hoffmann \n" +"All rights reserved.\n" +"" +"Syntax: 3ds2m [options] filename [options]\n" +"\n" +"Options:\n" +" -h/--help This help\n" +" -o/--output filename Write output to file instead of stdout\n" +" -m/--mesh name Write only specific mesh\n" +"\n" +); + exit(1); +} + + +static const char* filename=0; +static const char* output=0; +static const char* mesh=0; + + +static void +parse_args(int argc, char **argv) +{ + int i; + + for (i=1; i=argc)) { + help(); + } + output=argv[i]; + } + else + if ((strcmp(argv[i],"-m")==0) || (strcmp(argv[i],"--mesh")==0)) { + ++i; + if (mesh || (i>=argc)) { + help(); + } + mesh=argv[i]; + } + else { + help(); + } + } + else { + if (filename) { + help(); + } + filename=argv[i]; + } + } + if (!filename) { + help(); + } +} + + +static void +dump_m_file(Lib3dsFile *f, FILE *o) +{ + Lib3dsMesh *m; + int points=0; + int faces=0; + unsigned i; + Lib3dsVector pos; + + fprintf(o, "#\n"); + fprintf(o, "# Created by lib3ds2m (http://lib3ds.sourceforge.net)\n"); + fprintf(o, "#\n"); + for (m=f->meshes; m; m=m->next) { + if (mesh) { + if (strcmp(mesh, m->name)!=0) { + continue; + } + } + + fprintf(o, "#\n"); + fprintf(o, "# %s vertices=%ld faces=%ld\n", + m->name, + m->points, + m->faces + ); + fprintf(o, "#\n"); + + for (i=0; ipoints; ++i) { + lib3ds_vector_copy(pos, m->pointL[i].pos); + fprintf(o, "Vertex %d %f %f %f\n", points+i, pos[0], pos[1],pos[2]); + } + + for (i=0; ifaces; ++i) { + fprintf(o, "Face %d %d %d %d\n", + faces+i, + points+m->faceL[i].points[0], + points+m->faceL[i].points[1], + points+m->faceL[i].points[2] + ); + } + + points+=m->points; + faces+=m->faces; + } +} + + +int +main(int argc, char **argv) +{ + Lib3dsFile *f=0; + + parse_args(argc, argv); + f=lib3ds_file_load(filename); + if (!f) { + fprintf(stderr, "***ERROR***\nLoading file %s failed\n", filename); + exit(1); + } + if (output) { + FILE *o=fopen(output, "w+"); + if (!o) { + fprintf(stderr, "***ERROR***\nCan't open %s for writing\n", output); + exit(1); + } + dump_m_file(f,o); + fclose(o); + } + else { + dump_m_file(f,stdout); + } + + lib3ds_file_free(f); + return(0); +} + + + + + + + diff -uNr lib3ds-1.3.0.orig/tools/Makefile.am lib3ds-1.3.0/tools/Makefile.am --- lib3ds-1.3.0.orig/tools/Makefile.am 2007-06-14 11:59:10.000000000 +0200 +++ lib3ds-1.3.0/tools/Makefile.am 2007-11-03 07:25:10.000000000 +0100 @@ -24,13 +24,13 @@ -I$(top_srcdir) bin_PROGRAMS = \ - 3dsdump + 3dsdump 3ds2m LDADD = \ $(top_builddir)/lib3ds/lib3ds.la MANPAGES = \ - 3dsdump.1 + 3dsdump.1 3ds2m.1 man_MANS = $(MANPAGES) EXTRA_DIST = $(MANPAGES) diff -uNr lib3ds-1.3.0.orig/tools/Makefile.in lib3ds-1.3.0/tools/Makefile.in --- lib3ds-1.3.0.orig/tools/Makefile.in 2007-06-27 08:37:20.000000000 +0200 +++ lib3ds-1.3.0/tools/Makefile.in 2007-11-03 07:25:30.000000000 +0100 @@ -32,7 +32,7 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -bin_PROGRAMS = 3dsdump$(EXEEXT) +bin_PROGRAMS = 3dsdump$(EXEEXT) 3ds2m$(EXEEXT) subdir = tools DIST_COMMON = $(srcdir)/3dsdump.1.in $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in @@ -50,6 +50,10 @@ 3dsdump_OBJECTS = 3dsdump.$(OBJEXT) 3dsdump_LDADD = $(LDADD) 3dsdump_DEPENDENCIES = $(top_builddir)/lib3ds/lib3ds.la +3ds2m_SOURCES = 3ds2m.c +3ds2m_OBJECTS = 3ds2m.$(OBJEXT) +3ds2m_LDADD = $(LDADD) +3ds2m_DEPENDENCIES = $(top_builddir)/lib3ds/lib3ds.la DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -62,8 +66,8 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ -SOURCES = 3dsdump.c -DIST_SOURCES = 3dsdump.c +SOURCES = 3dsdump.c 3ds2m.c +DIST_SOURCES = 3dsdump.c 3ds2m.c man1dir = $(mandir)/man1 NROFF = nroff MANS = $(man_MANS) @@ -187,7 +191,7 @@ $(top_builddir)/lib3ds/lib3ds.la MANPAGES = \ - 3dsdump.1 + 3dsdump.1 3ds2m.1 man_MANS = $(MANPAGES) EXTRA_DIST = $(MANPAGES) @@ -257,6 +261,9 @@ 3dsdump$(EXEEXT): $(3dsdump_OBJECTS) $(3dsdump_DEPENDENCIES) @rm -f 3dsdump$(EXEEXT) $(LINK) $(3dsdump_OBJECTS) $(3dsdump_LDADD) $(LIBS) +3ds2m$(EXEEXT): $(3ds2m_OBJECTS) $(3ds2m_DEPENDENCIES) + @rm -f 3ds2m$(EXEEXT) + $(LINK) $(3ds2m_OBJECTS) $(3ds2m_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -265,6 +272,7 @@ -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/3dsdump.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/3ds2m.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<