Recovered from microbel
This commit is contained in:
1
util/asc2bog/.cvsignore
Normal file
1
util/asc2bog/.cvsignore
Normal file
@@ -0,0 +1 @@
|
||||
asc2bog asc_parse.h asc_parse.c asc_scan.c
|
||||
15
util/asc2bog/Makefile.am
Normal file
15
util/asc2bog/Makefile.am
Normal file
@@ -0,0 +1,15 @@
|
||||
INCLUDES = -I../../common/include @TIFF_CFLAGS@
|
||||
|
||||
bin_PROGRAMS = asc2bog
|
||||
|
||||
asc2bog_SOURCES = asc2bog.c asc_parse.y asc_scan.l parse.c util.c writebog.c
|
||||
|
||||
BUILT_SOURCES = asc_parse.c asc_parse.h
|
||||
|
||||
asc2bog_LDADD = -L../../common/lib/geometry -lgeometry -L../../common/lib/texture -ltexture -L../../common/lib/utils -lpvvmudutils -L../../common/lib/srvcli -lsrvcli @TIFF_LIBS@ -ltiff -lm
|
||||
|
||||
YFLAGS=-d
|
||||
|
||||
CC = $(CXX)
|
||||
|
||||
asc2bog.o: asc_parse.h
|
||||
345
util/asc2bog/Makefile.in
Normal file
345
util/asc2bog/Makefile.in
Normal file
@@ -0,0 +1,345 @@
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
SHELL = @SHELL@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
bindir = @bindir@
|
||||
sbindir = @sbindir@
|
||||
libexecdir = @libexecdir@
|
||||
datadir = @datadir@
|
||||
sysconfdir = @sysconfdir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
localstatedir = @localstatedir@
|
||||
libdir = @libdir@
|
||||
infodir = @infodir@
|
||||
mandir = @mandir@
|
||||
includedir = @includedir@
|
||||
oldincludedir = /usr/include
|
||||
|
||||
DESTDIR =
|
||||
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
|
||||
top_builddir = ../..
|
||||
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
transform = @program_transform_name@
|
||||
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
CXX = @CXX@
|
||||
GL_CFLAGS = @GL_CFLAGS@
|
||||
GL_LIBS = @GL_LIBS@
|
||||
LEX = @LEX@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
NETLIBS = @NETLIBS@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
TIFF_CFLAGS = @TIFF_CFLAGS@
|
||||
TIFF_LIBS = @TIFF_LIBS@
|
||||
VERSION = @VERSION@
|
||||
YACC = @YACC@
|
||||
|
||||
INCLUDES = -I../../common/include @TIFF_CFLAGS@
|
||||
|
||||
bin_PROGRAMS = asc2bog
|
||||
|
||||
asc2bog_SOURCES = asc2bog.c asc_parse.y asc_scan.l parse.c util.c writebog.c
|
||||
|
||||
BUILT_SOURCES = asc_parse.c asc_parse.h
|
||||
|
||||
asc2bog_LDADD = -L../../common/lib/geometry -lgeometry -L../../common/lib/texture -ltexture -L../../common/lib/utils -lpvvmudutils -L../../common/lib/srvcli -lsrvcli @TIFF_LIBS@ -ltiff -lm
|
||||
|
||||
YFLAGS = -d
|
||||
|
||||
CC = $(CXX)
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_CLEAN_FILES =
|
||||
PROGRAMS = $(bin_PROGRAMS)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir)
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
X_CFLAGS = @X_CFLAGS@
|
||||
X_LIBS = @X_LIBS@
|
||||
X_EXTRA_LIBS = @X_EXTRA_LIBS@
|
||||
X_PRE_LIBS = @X_PRE_LIBS@
|
||||
asc2bog_OBJECTS = asc2bog.o asc_parse.o asc_scan.o parse.o util.o \
|
||||
writebog.o
|
||||
asc2bog_DEPENDENCIES =
|
||||
asc2bog_LDFLAGS =
|
||||
LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
|
||||
LEXLIB = @LEXLIB@
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
DIST_COMMON = Makefile.am Makefile.in asc_parse.c asc_scan.c
|
||||
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
||||
TAR = gtar
|
||||
GZIP_ENV = --best
|
||||
DEP_FILES = .deps/asc2bog.P .deps/asc_parse.P .deps/asc_scan.P \
|
||||
.deps/parse.P .deps/util.P .deps/writebog.P
|
||||
SOURCES = $(asc2bog_SOURCES)
|
||||
OBJECTS = $(asc2bog_OBJECTS)
|
||||
|
||||
all: all-redirect
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .S .c .l .o .s .y
|
||||
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||
cd $(top_srcdir) && $(AUTOMAKE) --foreign util/asc2bog/Makefile
|
||||
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
|
||||
cd $(top_builddir) \
|
||||
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
|
||||
|
||||
|
||||
mostlyclean-binPROGRAMS:
|
||||
|
||||
clean-binPROGRAMS:
|
||||
-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
|
||||
|
||||
distclean-binPROGRAMS:
|
||||
|
||||
maintainer-clean-binPROGRAMS:
|
||||
|
||||
install-binPROGRAMS: $(bin_PROGRAMS)
|
||||
@$(NORMAL_INSTALL)
|
||||
$(mkinstalldirs) $(DESTDIR)$(bindir)
|
||||
@list='$(bin_PROGRAMS)'; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
|
||||
$(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-binPROGRAMS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
list='$(bin_PROGRAMS)'; for p in $$list; do \
|
||||
rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
|
||||
done
|
||||
|
||||
.s.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.S.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.o core *.core
|
||||
|
||||
clean-compile:
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
maintainer-clean-compile:
|
||||
|
||||
asc2bog: $(asc2bog_OBJECTS) $(asc2bog_DEPENDENCIES)
|
||||
@rm -f asc2bog
|
||||
$(LINK) $(asc2bog_LDFLAGS) $(asc2bog_OBJECTS) $(asc2bog_LDADD) $(LIBS)
|
||||
.l.c:
|
||||
$(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@
|
||||
.y.c:
|
||||
$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*.c
|
||||
if test -f y.tab.h; then \
|
||||
if cmp -s y.tab.h $*.h; then rm -f y.tab.h; else mv y.tab.h $*.h; fi; \
|
||||
else :; fi
|
||||
asc_parse.h: asc_parse.c
|
||||
|
||||
|
||||
tags: TAGS
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP)
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
here=`pwd` && cd $(srcdir) \
|
||||
&& mkid -f$$here/ID $$unique $(LISP)
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|
||||
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
|
||||
|
||||
mostlyclean-tags:
|
||||
|
||||
clean-tags:
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID
|
||||
|
||||
maintainer-clean-tags:
|
||||
|
||||
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
|
||||
|
||||
subdir = util/asc2bog
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
here=`cd $(top_builddir) && pwd`; \
|
||||
top_distdir=`cd $(top_distdir) && pwd`; \
|
||||
distdir=`cd $(distdir) && pwd`; \
|
||||
cd $(top_srcdir) \
|
||||
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign util/asc2bog/Makefile
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file || :; \
|
||||
fi; \
|
||||
done
|
||||
|
||||
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
|
||||
|
||||
-include $(DEP_FILES)
|
||||
|
||||
mostlyclean-depend:
|
||||
|
||||
clean-depend:
|
||||
|
||||
distclean-depend:
|
||||
-rm -rf .deps
|
||||
|
||||
maintainer-clean-depend:
|
||||
|
||||
%.o: %.c
|
||||
@echo '$(COMPILE) -c $<'; \
|
||||
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
|
||||
@-cp .deps/$(*F).pp .deps/$(*F).P; \
|
||||
tr ' ' '\012' < .deps/$(*F).pp \
|
||||
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
|
||||
>> .deps/$(*F).P; \
|
||||
rm .deps/$(*F).pp
|
||||
|
||||
%.lo: %.c
|
||||
@echo '$(LTCOMPILE) -c $<'; \
|
||||
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
|
||||
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
|
||||
< .deps/$(*F).pp > .deps/$(*F).P; \
|
||||
tr ' ' '\012' < .deps/$(*F).pp \
|
||||
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
|
||||
>> .deps/$(*F).P; \
|
||||
rm -f .deps/$(*F).pp
|
||||
info-am:
|
||||
info: info-am
|
||||
dvi-am:
|
||||
dvi: dvi-am
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
installcheck-am:
|
||||
installcheck: installcheck-am
|
||||
install-exec-am: install-binPROGRAMS
|
||||
install-exec: install-exec-am
|
||||
|
||||
install-data-am:
|
||||
install-data: install-data-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
install: install-am
|
||||
uninstall-am: uninstall-binPROGRAMS
|
||||
uninstall: uninstall-am
|
||||
all-am: Makefile $(PROGRAMS)
|
||||
all-redirect: all-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
|
||||
installdirs:
|
||||
$(mkinstalldirs) $(DESTDIR)$(bindir)
|
||||
|
||||
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-rm -f Makefile $(CONFIG_CLEAN_FILES)
|
||||
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
|
||||
|
||||
maintainer-clean-generic:
|
||||
-test -z "asc_scanlasc_parsehasc_parsec$(BUILT_SOURCES)" || rm -f asc_scanl asc_parseh asc_parsec $(BUILT_SOURCES)
|
||||
mostlyclean-am: mostlyclean-binPROGRAMS mostlyclean-compile \
|
||||
mostlyclean-tags mostlyclean-depend mostlyclean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
clean-am: clean-binPROGRAMS clean-compile clean-tags clean-depend \
|
||||
clean-generic mostlyclean-am
|
||||
|
||||
clean: clean-am
|
||||
|
||||
distclean-am: distclean-binPROGRAMS distclean-compile distclean-tags \
|
||||
distclean-depend distclean-generic clean-am
|
||||
|
||||
distclean: distclean-am
|
||||
|
||||
maintainer-clean-am: maintainer-clean-binPROGRAMS \
|
||||
maintainer-clean-compile maintainer-clean-tags \
|
||||
maintainer-clean-depend maintainer-clean-generic \
|
||||
distclean-am
|
||||
@echo "This command is intended for maintainers to use;"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
|
||||
.PHONY: mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \
|
||||
maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \
|
||||
mostlyclean-compile distclean-compile clean-compile \
|
||||
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
|
||||
clean-tags maintainer-clean-tags distdir mostlyclean-depend \
|
||||
distclean-depend clean-depend maintainer-clean-depend info-am info \
|
||||
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
|
||||
install-exec install-data-am install-data install-am install \
|
||||
uninstall-am uninstall all-redirect all-am all installdirs \
|
||||
mostlyclean-generic distclean-generic clean-generic \
|
||||
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
|
||||
|
||||
|
||||
asc2bog.o: asc_parse.h
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
90
util/asc2bog/asc2bog.c
Normal file
90
util/asc2bog/asc2bog.c
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include "globals.h"
|
||||
#include "parse.h"
|
||||
#include "writebog.h"
|
||||
|
||||
FILE * source;
|
||||
FILE * outfile;
|
||||
FILE * ndbFile;
|
||||
|
||||
TreeNode_t * parseTree;
|
||||
|
||||
int main(int argc, char * argv[]){
|
||||
char ascfile[256];
|
||||
char ndbfile[256];
|
||||
char bogfile[256];
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr,"usage: %s <filename>\n",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
strcpy(ascfile,argv[1]);
|
||||
if (strrchr (ascfile, '/') != NULL){
|
||||
if (strchr (strrchr(ascfile,'/'), '.') == NULL)
|
||||
strcat(ascfile,".ase");
|
||||
} else if (strchr (ascfile, '.') == NULL)
|
||||
strcat(ascfile,".ase");
|
||||
|
||||
source = fopen(ascfile,"r");
|
||||
if (source == NULL){
|
||||
fprintf(stderr,"File %s not found\n",ascfile);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (strrchr(ascfile,'/') != NULL){
|
||||
strcpy(bogfile,strrchr(ascfile,'/')+1);
|
||||
} else strcpy(bogfile,ascfile);
|
||||
|
||||
strcpy(strchr(bogfile,'.'),".bog");
|
||||
strcpy(ndbfile,bogfile);
|
||||
strcpy(strchr(ndbfile,'.'),".ndb");
|
||||
|
||||
|
||||
|
||||
parseTree = parse();
|
||||
|
||||
fclose(source);
|
||||
|
||||
outfile = fopen(bogfile,"w");
|
||||
|
||||
if (outfile == NULL){
|
||||
fprintf(stderr,"Error: Failed to open output file %s\n",bogfile);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ndbFile = fopen(ndbfile,"w");
|
||||
|
||||
if (ndbFile == NULL){
|
||||
fprintf(stderr,"Error: Failed to open output file %s\n",ndbfile);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
writebogfile(parseTree,outfile,ndbFile);
|
||||
|
||||
fclose(outfile);
|
||||
fclose(ndbFile);
|
||||
|
||||
/* printTree(parseTree); */
|
||||
|
||||
return 0;
|
||||
}
|
||||
29
util/asc2bog/asc2bog.html
Normal file
29
util/asc2bog/asc2bog.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>PVVMUD - asc2bog file converter</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<H1>asc2bog file converter</H1>
|
||||
|
||||
<P>asc2bog convert from 3DStudio asc file format to
|
||||
<A HREF="../../doc/bogfileformat.html">bog file format</A> with a material
|
||||
<A HREF="../../doc/ndbfileformat.html">ndb file</A>.</P>
|
||||
|
||||
<P><PRE>
|
||||
Syntax: asc2bog file[.asc]
|
||||
Output: file.bog and file.ndb
|
||||
</PRE></P>
|
||||
|
||||
<P>The 3DStudioMax asc file export plugin are a example for developers of
|
||||
3DStudioMax file exports plugins. The plugin and source code are located on the
|
||||
3DStudioMAX CD. In time this utility will be replaced by a 3DStudioMAX plugin
|
||||
that exports bog files.</P>
|
||||
|
||||
<P>Known buggs:
|
||||
<UL>
|
||||
<LI>Don't convert UV mapping
|
||||
</UL>
|
||||
</P>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
126
util/asc2bog/asc_parse.y
Normal file
126
util/asc2bog/asc_parse.y
Normal file
@@ -0,0 +1,126 @@
|
||||
/* The geo2bog Yacc/Bison spesification file */
|
||||
%{
|
||||
#define YYPARSER /* distinguishes yacc output from other code files */
|
||||
|
||||
#include "globals.h"
|
||||
#include "parse.h"
|
||||
#include "util.h"
|
||||
|
||||
#define YYSTYPE TreeNode_t *
|
||||
|
||||
static TreeNode_t * savedTree; /* Stores syntax tree for later return */
|
||||
|
||||
%}
|
||||
|
||||
%token AMBIENT_LIGHT_COLOR NAMED_OBJECT TRIMESH VERTICES FACES MAPPED
|
||||
%token MATERIAL VERTEX VERTEX_LIST FACE_LIST FACE SMOOTHING AB BC CA
|
||||
%token RED GREEN BLUE ASSIGN SOLID_BACKGROUND_COLOR
|
||||
%token FLOAT NUM STRING
|
||||
%token ERROR
|
||||
|
||||
%%
|
||||
geometry: head object_seq
|
||||
{ savedTree = newGeometry($1,$2); }
|
||||
;
|
||||
head: AMBIENT_LIGHT_COLOR ':' color
|
||||
{ $$ = newHead(); }
|
||||
| AMBIENT_LIGHT_COLOR ':' color SOLID_BACKGROUND_COLOR ':' color { $$ = newHead(); }
|
||||
;
|
||||
color: RED ASSIGN float_num GREEN ASSIGN float_num BLUE ASSIGN float_num
|
||||
;
|
||||
float_num: FLOAT
|
||||
{ $$ = newFloat(atof(tokenString)); }
|
||||
;
|
||||
object_seq: object_seq object
|
||||
{ $$ = linkNode($1,$2); }
|
||||
| object
|
||||
{ $$ = $1; }
|
||||
;
|
||||
object: object_head object_geo
|
||||
{ $$ = newObject($1,$2); }
|
||||
;
|
||||
object_head: NAMED_OBJECT ':' STRING
|
||||
{
|
||||
tokenString[strlen(tokenString)-1] = '\0';
|
||||
$$ = newObjectHead(copyString(tokenString+1));
|
||||
}
|
||||
;
|
||||
object_geo: trimesh_head vertex_list face_list
|
||||
{ $$ = newTriMesh($1,$2,$3); }
|
||||
;
|
||||
trimesh_head: TRIMESH ',' VERTICES ':' num FACES ':' num MAPPED
|
||||
{ $$ = newTriMeshHead($5,$8,TRUE); }
|
||||
| TRIMESH ',' VERTICES ':' num FACES ':' num
|
||||
{ $$ = newTriMeshHead($5,$8,FALSE); }
|
||||
;
|
||||
num: NUM
|
||||
{ $$ = newNum(atoi(tokenString)); }
|
||||
;
|
||||
vertex_list: VERTEX_LIST ':' vertex_seq
|
||||
{ $$ = $3; }
|
||||
;
|
||||
vertex_seq: vertex_seq vertex
|
||||
{ $$ = linkNode($1,$2); }
|
||||
| vertex
|
||||
{ $$ = $1; }
|
||||
;
|
||||
vertex: vertex_coord uv_mapping
|
||||
{ $$ = linkNode($1,$2); }
|
||||
| vertex_coord
|
||||
{ $$ = $1; }
|
||||
;
|
||||
uv_mapping: 'U' ':' float_num 'V' ':' float_num
|
||||
{ $$ = newUVMapping($3,$6); }
|
||||
vertex_coord: VERTEX num ':' 'X' ':' float_num 'Y' ':' float_num 'Z' ':' float_num
|
||||
{ $$ = newVertex($2,$6,$9,$12); }
|
||||
;
|
||||
face_list: FACE_LIST ':' face_seq
|
||||
{ $$ = $3; }
|
||||
;
|
||||
face_seq: face_seq face_index
|
||||
{ $$ = linkNode($1,$2); }
|
||||
| face_index
|
||||
{ $$ = $1; }
|
||||
;
|
||||
face_index: face face_opt_seq
|
||||
{ $$ = linkNode($1,$2); }
|
||||
| face
|
||||
{ $$ = $1; }
|
||||
;
|
||||
face: FACE num ':' 'A' ':' num 'B' ':' num 'C' ':' num AB ':' num BC ':' num CA ':' num
|
||||
{ $$ = newFace($2,$6,$9,$12); }
|
||||
;
|
||||
face_opt_seq: face_opt_seq face_opt
|
||||
{ $$ = linkNode($1,$2); }
|
||||
| face_opt
|
||||
{ $$ = $1; }
|
||||
;
|
||||
face_opt: material
|
||||
{ $$ = $1; }
|
||||
| smoothing
|
||||
{ $$ = $1; }
|
||||
;
|
||||
material: MATERIAL ':' STRING
|
||||
{
|
||||
tokenString[strlen(tokenString)-1] = '\0';
|
||||
$$ = newMaterial(copyString(tokenString+1));
|
||||
}
|
||||
;
|
||||
smoothing: SMOOTHING ':' num
|
||||
{ $$ = newSmoothing($3); }
|
||||
;
|
||||
%%
|
||||
|
||||
static TokenType yylex(){
|
||||
return getToken();
|
||||
}
|
||||
|
||||
int yyerror(char * message){
|
||||
printf("Syntax error at line %d: %s\n",lineno,message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
TreeNode_t * parse(){
|
||||
yyparse();
|
||||
return savedTree;
|
||||
}
|
||||
76
util/asc2bog/asc_scan.l
Normal file
76
util/asc2bog/asc_scan.l
Normal file
@@ -0,0 +1,76 @@
|
||||
/* Lex spesification for asc2bog */
|
||||
%option noyywrap
|
||||
%o 4000
|
||||
%{
|
||||
#define YYLEX
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
|
||||
int lineno;
|
||||
|
||||
char tokenString[MAXTOKENLEN+1];
|
||||
|
||||
%}
|
||||
|
||||
digit [0-9]
|
||||
nat {digit}+
|
||||
signedNat ("+"|"-")?{nat}
|
||||
floating {signedNat}("."{nat})?
|
||||
string \"([^\"]|\\\")+\"
|
||||
newline \n
|
||||
whitespace [ \t\r]+
|
||||
|
||||
%%
|
||||
|
||||
"Ambient light color" { return AMBIENT_LIGHT_COLOR; }
|
||||
"Solid background color" { return SOLID_BACKGROUND_COLOR; }
|
||||
"Red" { return RED; }
|
||||
"Green" { return GREEN; }
|
||||
"Blue" { return BLUE; }
|
||||
"Named object" { return NAMED_OBJECT; }
|
||||
"Tri-mesh" { return TRIMESH; }
|
||||
"Vertices" { return VERTICES; }
|
||||
"Faces" { return FACES; }
|
||||
"Mapped" { return MAPPED; }
|
||||
"Vertex list" { return VERTEX_LIST; }
|
||||
"Vertex" { return VERTEX; }
|
||||
"Face list" { return FACE_LIST; }
|
||||
"Face" { return FACE; }
|
||||
"Material" { return MATERIAL; }
|
||||
"Smoothing" { return SMOOTHING; }
|
||||
"AB" { return AB; }
|
||||
"BC" { return BC; }
|
||||
"CA" { return CA; }
|
||||
"=" { return ASSIGN; }
|
||||
[:,XYZUVABC] { return yytext[0]; }
|
||||
{nat} { return NUM; }
|
||||
{floating} { return FLOAT; }
|
||||
{string} { return STRING; }
|
||||
{whitespace} { /* Skip */ }
|
||||
{newline} { lineno++; }
|
||||
. { return ERROR; }
|
||||
%%
|
||||
|
||||
TokenType getToken(){
|
||||
TokenType currentToken;
|
||||
static int firstTime = TRUE;
|
||||
|
||||
if (firstTime){
|
||||
firstTime = FALSE;
|
||||
yyin = source;
|
||||
lineno++;
|
||||
}
|
||||
|
||||
currentToken = yylex();
|
||||
strncpy(tokenString,yytext,MAXTOKENLEN);
|
||||
|
||||
return currentToken;
|
||||
}
|
||||
|
||||
#if 0 /* ndef LINUX */
|
||||
int yywrap(void){
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
86
util/asc2bog/globals.h
Normal file
86
util/asc2bog/globals.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#ifndef _GLOBALS_H
|
||||
#define _GLOBALS_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "bogfile.H"
|
||||
|
||||
#ifndef YYPARSER
|
||||
|
||||
#include "asc_parse.h"
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#define WORD unsigned short int
|
||||
|
||||
|
||||
#define MAXTOKENLEN 64
|
||||
#define MAXCHILDREN 4
|
||||
|
||||
typedef int TokenType;
|
||||
|
||||
|
||||
extern int lineno;
|
||||
extern char tokenString[MAXTOKENLEN+1];
|
||||
extern FILE * source;
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Syntax tree for parsing
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
typedef enum {GeometryK,FloatK,HeadK,ObjectK,NumK,ObjectHeadK,UVMappingK,VertexK,FaceK,MaterialK,SmoothingK,TriMeshK,TriMeshHeadK} NodeKind_t;
|
||||
|
||||
|
||||
typedef struct treeNode {
|
||||
NodeKind_t nodeKind;
|
||||
struct treeNode * sibling;
|
||||
struct treeNode * child[MAXCHILDREN];
|
||||
union {
|
||||
int index;
|
||||
int num;
|
||||
int mapped;
|
||||
float value;
|
||||
char * name;
|
||||
PolyType_t polyType;
|
||||
} attr;
|
||||
} TreeNode_t;
|
||||
|
||||
|
||||
/*
|
||||
Declarations to prevent SYMBOL NOT FOUND in c+
|
||||
*/
|
||||
static TokenType yylex();
|
||||
int yyerror(char *);
|
||||
extern int getToken();
|
||||
|
||||
#endif /* _GLOBALS_H */
|
||||
244
util/asc2bog/parse.c
Normal file
244
util/asc2bog/parse.c
Normal file
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include "globals.h"
|
||||
#include "parse.h"
|
||||
|
||||
TreeNode_t * linkNode(TreeNode_t * n1, TreeNode_t * n2){
|
||||
TreeNode_t * t = n1;
|
||||
if (t != NULL) {
|
||||
while (t->sibling != NULL)
|
||||
t = t->sibling;
|
||||
t->sibling = n2;
|
||||
return n1;
|
||||
} else return n2;
|
||||
}
|
||||
|
||||
TreeNode_t * newGeometry(TreeNode_t * head, TreeNode_t * object){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = GeometryK;
|
||||
treeNode->child[0] = head;
|
||||
treeNode->child[1] = object;
|
||||
treeNode->sibling = NULL;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newHead(){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = HeadK;
|
||||
treeNode->sibling = NULL;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newFloat(float value){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = FloatK;
|
||||
treeNode->attr.value = value;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newObject(TreeNode_t * head, TreeNode_t * objGeo){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = ObjectK;
|
||||
treeNode->child[0] = head;
|
||||
treeNode->child[1] = objGeo;
|
||||
treeNode->sibling = NULL;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newTriMesh(TreeNode_t * triMeshHead, TreeNode_t * vertexList, TreeNode_t * faceList){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = TriMeshK;
|
||||
treeNode->child[0] = triMeshHead;
|
||||
treeNode->child[1] = vertexList;
|
||||
treeNode->child[2] = faceList;
|
||||
treeNode->sibling = NULL;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newNum(int num){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = NumK;
|
||||
treeNode->attr.num = num;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newObjectHead(char * name){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = ObjectHeadK;
|
||||
treeNode->attr.name = name;
|
||||
treeNode->sibling = NULL;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newTriMeshHead(TreeNode_t * vertexNum, TreeNode_t * faceNum, int mapped){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = TriMeshHeadK;
|
||||
treeNode->child[0] = vertexNum;
|
||||
treeNode->child[1] = faceNum;
|
||||
treeNode->sibling = NULL;
|
||||
treeNode->attr.mapped = mapped;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newVertex(TreeNode_t * num, TreeNode_t * v1, TreeNode_t * v2, TreeNode_t * v3){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = VertexK;
|
||||
treeNode->child[0] = num;
|
||||
treeNode->child[1] = v1;
|
||||
treeNode->child[2] = v2;
|
||||
treeNode->child[3] = v3;
|
||||
treeNode->sibling = NULL;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newUVMapping(TreeNode_t * u, TreeNode_t * v){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = UVMappingK;
|
||||
treeNode->child[0] = u;
|
||||
treeNode->child[1] = v;
|
||||
treeNode->sibling = NULL;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newFace(TreeNode_t * num, TreeNode_t * v1, TreeNode_t * v2, TreeNode_t * v3){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = FaceK;
|
||||
treeNode->child[0] = num;
|
||||
treeNode->child[1] = v1;
|
||||
treeNode->child[2] = v2;
|
||||
treeNode->child[3] = v3;
|
||||
treeNode->sibling = NULL;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newMaterial(char * name){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = MaterialK;
|
||||
treeNode->attr.name = name;
|
||||
treeNode->sibling = NULL;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
TreeNode_t * newSmoothing(TreeNode_t * smoothing){
|
||||
TreeNode_t * treeNode = (TreeNode_t *)malloc( sizeof (TreeNode_t) );
|
||||
treeNode->nodeKind = SmoothingK;
|
||||
treeNode->child[0] = smoothing;
|
||||
treeNode->sibling = NULL;
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
void printTree(TreeNode_t * node){
|
||||
|
||||
if (node == NULL) return;
|
||||
|
||||
switch (node->nodeKind){
|
||||
case GeometryK:
|
||||
printf("Geometry {\n");
|
||||
printTree(node->child[0]);
|
||||
printTree(node->child[1]);
|
||||
printf("}\n");
|
||||
break;
|
||||
case HeadK:
|
||||
printf("\tHead\n");
|
||||
break;
|
||||
case FloatK:
|
||||
printf("%f",node->attr.value);
|
||||
break;
|
||||
case ObjectK:
|
||||
printf("\tObject = [\n");
|
||||
printTree(node->child[0]);
|
||||
printTree(node->child[1]);
|
||||
printf("\t];\n");
|
||||
printTree(node->sibling);
|
||||
break;
|
||||
case ObjectHeadK:
|
||||
printf("\t\tHead %s\n",node->attr.name);
|
||||
break;
|
||||
case TriMeshK:
|
||||
printf("\t\tTri-Mesh [\n");
|
||||
printTree(node->child[0]);
|
||||
printTree(node->child[1]);
|
||||
printTree(node->child[2]);
|
||||
printf("\t\t];\n");
|
||||
break;
|
||||
case TriMeshHeadK:
|
||||
printf("\t\t\tHead ( ");
|
||||
printTree(node->child[0]);
|
||||
printf(", ");
|
||||
printTree(node->child[1]);
|
||||
printf(", %i)\n",node->attr.mapped);
|
||||
break;
|
||||
case NumK:
|
||||
printf("%i",node->attr.num);
|
||||
if (node->sibling != NULL){
|
||||
printf(", ");
|
||||
printTree(node->sibling);
|
||||
}
|
||||
break;
|
||||
case VertexK:
|
||||
printf("\t\t\tXYZ ( ");
|
||||
printTree(node->child[0]);
|
||||
printf(": ");
|
||||
printTree(node->child[1]);
|
||||
printf(", ");
|
||||
printTree(node->child[2]);
|
||||
printf(", ");
|
||||
printTree(node->child[3]);
|
||||
printf(")\n");
|
||||
if (node->sibling != NULL) {
|
||||
printTree(node->sibling);
|
||||
}
|
||||
break;
|
||||
case UVMappingK:
|
||||
printf("\t\t\tUV ( ");
|
||||
printTree(node->child[0]);
|
||||
printf(", ");
|
||||
printTree(node->child[1]);
|
||||
printf(")\n");
|
||||
if (node->sibling != NULL) {
|
||||
printTree(node->sibling);
|
||||
}
|
||||
break;
|
||||
case FaceK:
|
||||
printf("\t\t\tFace( ");
|
||||
printTree(node->child[0]);
|
||||
printf(": ");
|
||||
printTree(node->child[1]);
|
||||
printf(", ");
|
||||
printTree(node->child[2]);
|
||||
printf(", ");
|
||||
printTree(node->child[3]);
|
||||
printf(")\n");
|
||||
if (node->sibling != NULL) {
|
||||
printTree(node->sibling);
|
||||
}
|
||||
break;
|
||||
case MaterialK:
|
||||
printf("\t\t\tMaterial = \"%s\"\n",node->attr.name);
|
||||
printTree(node->sibling);
|
||||
break;
|
||||
case SmoothingK:
|
||||
printf("\t\t\tSmoothing = ");
|
||||
printTree(node->child[0]);
|
||||
printf("\n");
|
||||
printTree(node->sibling);
|
||||
break;
|
||||
}
|
||||
}
|
||||
44
util/asc2bog/parse.h
Normal file
44
util/asc2bog/parse.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#ifndef _PARS_H
|
||||
#define _PARS_H
|
||||
|
||||
TreeNode_t * parse(void);
|
||||
|
||||
TreeNode_t * linkNode(TreeNode_t * n1, TreeNode_t * n2 );
|
||||
|
||||
|
||||
TreeNode_t * newGeometry(TreeNode_t * head, TreeNode_t * object);
|
||||
TreeNode_t * newHead();
|
||||
TreeNode_t * newFloat(float value);
|
||||
TreeNode_t * newObject(TreeNode_t * head, TreeNode_t * objGeo);
|
||||
TreeNode_t * newNum(int num);
|
||||
TreeNode_t * newObjectHead(char * name);
|
||||
TreeNode_t * newTriMesh(TreeNode_t * triMeshHead, TreeNode_t * vertexList, TreeNode_t * faceList);
|
||||
TreeNode_t * newTriMeshHead(TreeNode_t * vertexnum, TreeNode_t * facenum, int mapped);
|
||||
TreeNode_t * newVertex(TreeNode_t * num, TreeNode_t * v1, TreeNode_t * v2, TreeNode_t * v3);
|
||||
TreeNode_t * newUVMapping(TreeNode_t * u, TreeNode_t * v);
|
||||
TreeNode_t * newFace(TreeNode_t * num, TreeNode_t * v1, TreeNode_t * v2, TreeNode_t * v3);
|
||||
TreeNode_t * newMaterial(char * name );
|
||||
TreeNode_t * newSmoothing(TreeNode_t * smoothing);
|
||||
|
||||
void printTree(TreeNode_t * node);
|
||||
|
||||
#endif /* _PARS_H */
|
||||
35
util/asc2bog/util.c
Normal file
35
util/asc2bog/util.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include "globals.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
char * copyString(char * s){
|
||||
int n;
|
||||
char * t;
|
||||
if (s==NULL) return NULL;
|
||||
n = strlen(s)+1;
|
||||
t = (char *)malloc(n);
|
||||
if (t==NULL)
|
||||
printf("Error: Out of memory error at line %d\n",lineno);
|
||||
else strcpy(t,s);
|
||||
return t;
|
||||
}
|
||||
|
||||
22
util/asc2bog/util.h
Normal file
22
util/asc2bog/util.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
char * copyString(char * s);
|
||||
228
util/asc2bog/writebog.c
Normal file
228
util/asc2bog/writebog.c
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include <GL/gl.h>
|
||||
#include <math.h>
|
||||
#include "globals.h"
|
||||
#include "writebog.h"
|
||||
#include "geometry.H"
|
||||
#include "namedb.H"
|
||||
|
||||
|
||||
void countElements(TreeNode_t * node, WORD * numV, WORD * numN,
|
||||
WORD * numTC, WORD * numP){
|
||||
|
||||
if (node == NULL) return;
|
||||
|
||||
switch (node->nodeKind){
|
||||
case GeometryK:
|
||||
countElements(node->child[1],numV,numN,numTC,numP);
|
||||
break;
|
||||
case ObjectK:
|
||||
countElements(node->child[1],numV,numN,numTC,numP);
|
||||
countElements(node->sibling,numV,numN,numTC,numP);
|
||||
break;
|
||||
case VertexK:
|
||||
(*numV)++;
|
||||
countElements(node->sibling,numV,numN,numTC,numP);
|
||||
break;
|
||||
case UVMappingK:
|
||||
(*numTC)++;
|
||||
countElements(node->sibling,numV,numN,numTC,numP);
|
||||
break;
|
||||
case FaceK:
|
||||
(*numN)++;
|
||||
countElements(node->sibling,numV,numN,numTC,numP);
|
||||
break;
|
||||
case MaterialK:
|
||||
case SmoothingK:
|
||||
countElements(node->sibling,numV,numN,numTC,numP);
|
||||
break;
|
||||
case TriMeshK:
|
||||
(*numP)++;
|
||||
countElements(node->child[1],numV,numN,numTC,numP);
|
||||
countElements(node->child[2],numV,numN,numTC,numP);
|
||||
countElements(node->sibling,numV,numN,numTC,numP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CalcNorm(CGeometry * geo,float * xx, float * yy,float * zz,
|
||||
int v1, int v2, int v3){
|
||||
double dx1,dy1,dz1,dx2,dy2,dz2;
|
||||
double v1x,v1y,v1z,v2x,v2y,v2z,v3x,v3y,v3z;
|
||||
double x,y,z,l;
|
||||
|
||||
geo->getVertex(v1,&v1x,&v1y,&v1z);
|
||||
geo->getVertex(v2,&v2x,&v2y,&v2z);
|
||||
geo->getVertex(v3,&v3x,&v3y,&v3z);
|
||||
|
||||
dx1 = v1x - v2x;
|
||||
dy1 = v1y - v2y;
|
||||
dz1 = v1z - v2z;
|
||||
dx2 = v2x - v3x;
|
||||
dy2 = v2y - v3y;
|
||||
dz2 = v2z - v3z;
|
||||
|
||||
x = dy1*dz2 - dy2*dz1;
|
||||
y = dx2*dz1 - dx1*dz2;
|
||||
z = dx1*dy2 - dx2*dy1;
|
||||
|
||||
l = sqrt(x*x+y*y+z*z);
|
||||
|
||||
*xx = x/l;
|
||||
*yy = y/l;
|
||||
*zz = z/l;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int * vertexIndexMap;
|
||||
CPolygon * poly;
|
||||
int normalIndex;
|
||||
int * normalIndexMap;
|
||||
int * texCoordIndexMap;
|
||||
int texCoordIndex;
|
||||
CNameDB * nameDB;
|
||||
|
||||
void buildGeo(CGeometry * geo, TreeNode_t * node){
|
||||
int ii,index,v1,v2,v3;
|
||||
int numVertices,numFaces,numTexCoords;
|
||||
float xx,yy,zz;
|
||||
|
||||
if (node == NULL) return;
|
||||
|
||||
switch (node->nodeKind){
|
||||
case GeometryK:
|
||||
vertexIndexMap = NULL;
|
||||
normalIndex = 0;
|
||||
buildGeo(geo,node->child[1]);
|
||||
break;
|
||||
case ObjectK:
|
||||
buildGeo(geo,node->child[1]);
|
||||
buildGeo(geo,node->sibling);
|
||||
break;
|
||||
case TriMeshK:
|
||||
buildGeo(geo,node->child[0]);
|
||||
buildGeo(geo,node->child[1]);
|
||||
buildGeo(geo,node->child[2]);
|
||||
geo->addPolygon(poly);
|
||||
break;
|
||||
case TriMeshHeadK:
|
||||
if (vertexIndexMap != NULL) free(vertexIndexMap);
|
||||
if (texCoordIndexMap != NULL) free(texCoordIndexMap);
|
||||
|
||||
numVertices = node->child[0]->attr.num;
|
||||
numFaces = node->child[1]->attr.num;
|
||||
numTexCoords = (node->attr.mapped ? numFaces*3 : 0 );
|
||||
|
||||
vertexIndexMap = (int *)malloc( numVertices * sizeof(int) );
|
||||
if (numTexCoords != 0){
|
||||
texCoordIndexMap = (int *)malloc( numTexCoords * sizeof(int) );
|
||||
} else texCoordIndexMap = NULL;
|
||||
|
||||
poly = new CPolygon( PT_Triangles , 0, numFaces*3, numFaces, numTexCoords );
|
||||
|
||||
break;
|
||||
case VertexK:
|
||||
index = node->child[0]->attr.num;
|
||||
xx = node->child[1]->attr.value;
|
||||
yy = node->child[2]->attr.value;
|
||||
zz = node->child[3]->attr.value;
|
||||
vertexIndexMap[index] = geo->addVertex(xx,yy,zz);
|
||||
texCoordIndex = index;
|
||||
buildGeo(geo,node->sibling);
|
||||
break;
|
||||
case FaceK:
|
||||
v1 = node->child[1]->attr.num;
|
||||
v2 = node->child[2]->attr.num;
|
||||
v3 = node->child[3]->attr.num;
|
||||
|
||||
poly->addVertexIndex(vertexIndexMap[v1]);
|
||||
poly->addVertexIndex(vertexIndexMap[v2]);
|
||||
poly->addVertexIndex(vertexIndexMap[v3]);
|
||||
|
||||
if (texCoordIndexMap != NULL){
|
||||
poly->addTexCoordIndex(texCoordIndexMap[v1]);
|
||||
poly->addTexCoordIndex(texCoordIndexMap[v2]);
|
||||
poly->addTexCoordIndex(texCoordIndexMap[v3]);
|
||||
}
|
||||
|
||||
/* Calculate Normal vector to Face */
|
||||
|
||||
CalcNorm(geo,&xx,&yy,&zz,vertexIndexMap[v1],
|
||||
vertexIndexMap[v2],vertexIndexMap[v3]);
|
||||
|
||||
normalIndexMap[normalIndex] = geo->addNormal(xx,yy,zz);
|
||||
|
||||
poly->addNormalIndex(normalIndexMap[normalIndex]);
|
||||
normalIndex++;
|
||||
buildGeo(geo,node->sibling);
|
||||
break;
|
||||
case MaterialK:
|
||||
poly->setMaterial(nameDB->insert(node->attr.name));
|
||||
buildGeo(geo,node->sibling);
|
||||
break;
|
||||
case SmoothingK:
|
||||
buildGeo(geo,node->sibling);
|
||||
break;
|
||||
case UVMappingK:
|
||||
xx = node->child[0]->attr.value;
|
||||
yy = node->child[1]->attr.value;
|
||||
if (texCoordIndexMap != NULL){
|
||||
texCoordIndexMap[texCoordIndex] = geo->addTexCoord(xx,yy);
|
||||
}
|
||||
buildGeo(geo,node->sibling);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void writebogfile(TreeNode_t * node, FILE * bogfile, FILE * ndbfile ){
|
||||
WORD numVertices,numNormals,numTexCoords,numPolygons;
|
||||
CGeometry * geo;
|
||||
|
||||
numVertices = 0;
|
||||
numNormals = 0;
|
||||
numTexCoords = 0;
|
||||
numPolygons = 0;
|
||||
|
||||
countElements(node,&numVertices,&numNormals,&numTexCoords,&numPolygons);
|
||||
|
||||
|
||||
geo = new CGeometry(0,numVertices,numNormals,
|
||||
numTexCoords,numPolygons);
|
||||
|
||||
normalIndexMap = (int *)malloc( numNormals * sizeof(int) );
|
||||
|
||||
nameDB = new CNameDB();
|
||||
|
||||
buildGeo(geo,node);
|
||||
|
||||
geo->writeBOG(bogfile);
|
||||
nameDB->writeNDB(ndbfile);
|
||||
|
||||
delete geo;
|
||||
delete nameDB;
|
||||
}
|
||||
|
||||
|
||||
|
||||
25
util/asc2bog/writebog.h
Normal file
25
util/asc2bog/writebog.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#ifndef _WRITEBOG_H
|
||||
#define _WRITEBOG_H
|
||||
|
||||
void writebogfile(TreeNode_t * node, FILE * bogfile, FILE * ndbfile);
|
||||
|
||||
#endif /* _WRITEBOG_H */
|
||||
Reference in New Issue
Block a user