From 7cc69d4d66ccf9846d6cfc5359b46479eb13ab44 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 5 Mar 2003 09:56:56 +0000 Subject: [PATCH] Added md2 plugin from Vladimir Vukicevic. --- AUTHORS.txt | 48 ++- Make/makedirdefs | 31 +- VisualStudio/VisualStudio.dsw | 18 ++ VisualStudio/osgPlugins/md2/md2.dsp | 113 +++++++ src/osgPlugins/md2/Makefile | 16 + src/osgPlugins/md2/ReaderWriterMD2.cpp | 408 +++++++++++++++++++++++++ src/osgPlugins/md2/anorms.h | 181 +++++++++++ 7 files changed, 772 insertions(+), 43 deletions(-) create mode 100644 VisualStudio/osgPlugins/md2/md2.dsp create mode 100644 src/osgPlugins/md2/Makefile create mode 100644 src/osgPlugins/md2/ReaderWriterMD2.cpp create mode 100644 src/osgPlugins/md2/anorms.h diff --git a/AUTHORS.txt b/AUTHORS.txt index d8edb5ff5..af0081593 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -4,8 +4,8 @@ # Feel free to add your name and change list. Robert Osfield - - osg, osgUtil and osgDB. - - pfb, 3ds, gif, jpeg, tiff, tga, pic, tgz & zip plugins. + - osg, osgUtil, osgText, osgSim and osgDB. + - osg, osgText, pfb, 3ds, gif, jpeg, tiff, tga, pic, tgz & zip plugins. - sgv, various revisions, now most of code is in osgGLUT. - 2nd iteration of impostor implemtentation. - 2nd iteration of shadow occlusion culling. @@ -14,14 +14,21 @@ Robert Osfield - project adim & lead. Don Burns + - Open Producer + - unix makefiles. - osg (particularily OpenGL) - first version of sgv. - - fly database & osgtgz plugins. - - unix makefiles. + - osghangglide database & osgtgz plugins. +Brede Johansen + - flt loader. + - osg::Point. + - osg::TextureCubeMap + - osg::VertexProgram + - assistance on visual studio workspace files. + Karsten Weiss - 1st iteration of impostor implemtentation. - - autoconfiscation of the project (currently a seperate branch.) - rpm spec file. - documentation. - bug fixes. @@ -35,12 +42,6 @@ Neil Salter - first incarnation of osgUtil, Camera and Manipulators. - web site. -Brede Johansen - - flt loader. - - osg::Point. - - osg::TextureCubeMap - - assistance on visual studio workspace files. - Ben Discoe - osgWX and wxsgv demos for integration of OSG with wxWindows. - png plugin. @@ -50,10 +51,6 @@ Maroc Jez - osgParticle - IO support for osgText. -Byan Woods - - Port to MacOS, various code changes to support this. - - Metrowerks CodeWarrior makefiles. - Randall Hopper - port to FreeBSD. - warning fixes to IRIX compilation. @@ -72,21 +69,13 @@ Axel Volley Geoff Michel - .dw (design workshop) loader plugin. - - .bmp (Windows Bitmap fiile) loader plugin. + - .bmp (Windows Bitmap file) loader plugin. + - .geo (Carbon Graphics GEO) loader plugin. - OpenGL based stats reporting added to osgGLUT::Viewer. -Max Rheiner - - osgText wrapping of FTGL text library. - - osgtext demo application. - -Henry Maddocks - - FTGL from which osgText is based. - Mike Connell - First implementation of shadow occlusion culling. - -Paul Fredrikson - - new Matrix implementation. + - improvements to 3ds plugin. Phil Atkin - MacOS X port. @@ -130,11 +119,14 @@ Alberto Barbati - lazy evaluation of the inverse in the MatrixTransform. Gideon May - - fixed spacing in osgText. + - Fixed spacing in osgText. Tree - - support for encoded text types in osgText. + - Support for encoded text types in osgText. +Vladimir Vukicevic + - md2 loader. + Indirect Contributors --------------------- diff --git a/Make/makedirdefs b/Make/makedirdefs index ad0f08c50..7b14153e5 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -17,7 +17,7 @@ SRC_DIRS = \ osgText\ osgSim\ osgPlugins\ - ../examples\ + ../examples\ src/Demos @@ -25,27 +25,28 @@ SRC_DIRS = \ # Directories traversed in the TOPDIR/src/osgPlugins directory PLUGIN_DIRS = \ - osg\ - osgParticle\ - osgText\ - rgb\ - ac3d\ - lib3ds\ + ac3d\ + bmp\ directx\ + dw\ flt\ freetype\ - iv\ - obj\ - lwo\ geo\ - txp\ - dw\ - bmp\ - pic\ - tga\ + iv\ + lib3ds\ logos\ + lwo\ + md2\ + obj\ + osgParticle\ + osgText\ + osg\ osgtgz\ + pic\ + rgb\ + tga\ tgz\ + txp\ zip # comment in if you have Performer installed. diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index 96ac0c888..08b3dba7e 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -1575,6 +1575,24 @@ Package=<4> ############################################################################### +Project: "osgPlugin md2"=.\osgPlugins\md2\md2.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name Core osg + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgDB + End Project Dependency +}}} + +############################################################################### + Project: "osgPlugin rgb"=.\osgPlugins\rgb\rgb.dsp - Package Owner=<4> Package=<5> diff --git a/VisualStudio/osgPlugins/md2/md2.dsp b/VisualStudio/osgPlugins/md2/md2.dsp new file mode 100644 index 000000000..9a9af4f89 --- /dev/null +++ b/VisualStudio/osgPlugins/md2/md2.dsp @@ -0,0 +1,113 @@ +# Microsoft Developer Studio Project File - Name="osgPlugin md2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=osgPlugin md2 - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "md2.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "md2.mak" CFG="osgPlugin md2 - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "osgPlugin md2 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "osgPlugin md2 - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "osgPlugin md2 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "../../../lib" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 /nologo /dll /pdb:none /machine:I386 /nodefaultlib:"LIBC" /out:"../../../bin/osgdb_md2.dll" /libpath:"../../../lib" +# SUBTRACT LINK32 /nodefaultlib + +!ELSEIF "$(CFG)" == "osgPlugin md2 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "../../../lib" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /vmg /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIN32" /D "_DEBUG" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /dll /debug /machine:I386 /nodefaultlib:"LIBC" /out:"../../../bin/osgdb_md2d.dll" /pdbtype:sept /libpath:"../../../lib" +# SUBTRACT LINK32 /nodefaultlib + +!ENDIF + +# Begin Target + +# Name "osgPlugin md2 - Win32 Release" +# Name "osgPlugin md2 - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\..\src\osgPlugins\md2\ReaderWriterMD2.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=..\..\..\src\osgPlugins\md2\anorms.h +# End Source File +# End Group +# End Target +# End Project diff --git a/src/osgPlugins/md2/Makefile b/src/osgPlugins/md2/Makefile new file mode 100644 index 000000000..9341df477 --- /dev/null +++ b/src/osgPlugins/md2/Makefile @@ -0,0 +1,16 @@ +TOPDIR = ../../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + ReaderWriterMD2.cpp\ + + +INC += -I$(THISDIR) + +LIBS += $(OSG_LIBS) $(OTHER_LIBS) + +TARGET_BASENAME = md2 +include $(TOPDIR)/Make/cygwin_plugin_def +PLUGIN = $(PLUGIN_PREFIX)$(TARGET_BASENAME).$(PLUGIN_EXT) + +include $(TOPDIR)/Make/makerules diff --git a/src/osgPlugins/md2/ReaderWriterMD2.cpp b/src/osgPlugins/md2/ReaderWriterMD2.cpp new file mode 100644 index 000000000..ac4c395a7 --- /dev/null +++ b/src/osgPlugins/md2/ReaderWriterMD2.cpp @@ -0,0 +1,408 @@ +/* + * ReaderWriterMD2.cpp + * + * MD2 Reading code + * + * Author(s): Vladimir Vukicevic + * + */ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +static osg::Node* load_md2 (const char *filename); + +class ReaderWriterMD2 : public osgDB::ReaderWriter +{ +public: + ReaderWriterMD2 () { } + + virtual const char* className () { + return "Quake MD2 Reader"; + } + + virtual bool acceptsExtension (const std::string& extension) { + return osgDB::equalCaseInsensitive (extension, "md2") ? true : false; + } + + virtual ReadResult readNode (const std::string& filename, + const osgDB::ReaderWriter::Options* options); +}; + +osgDB::RegisterReaderWriterProxy g_readerWriter_MD2_Proxy; + +osgDB::ReaderWriter::ReadResult +ReaderWriterMD2::readNode (const std::string& filename, + const osgDB::ReaderWriter::Options* options) +{ + return load_md2 (filename.data()); +} + + +/////////////////// MD2 parsing code ////////////////////// + +typedef struct { + int magic; + int version; + int skinWidth; + int skinHeight; + int frameSize; // size of each frame in bytes + int numSkins; + int numVertices; // number of vertices in each frame + int numTexcoords; // number of texcoords in each frame (usually same as numVertices) + int numTriangles; // number of triangles in each frame + int numGlCommands; + int numFrames; // number of frames + int offsetSkins; + int offsetTexCoords; + int offsetTriangles; + int offsetFrames; + int offsetGlCommands; // num dwords in gl commands list + int offsetEnd; +} MD2_HEADER; + +#define MD2_HEADER_MAGIC 0x32504449 + +typedef struct { + unsigned char vertex[3]; + unsigned char lightNormalIndex; +} MD2_VERTEX; + +typedef struct { + float scale[3]; + float translate[3]; + char name[16]; + MD2_VERTEX vertices[1]; +} MD2_FRAME; + +typedef struct { + short vertexIndices[3]; + short textureIndices[3]; +} MD2_TRIANGLE; + +typedef struct { + float s; + float t; + int vertexIndex; +} MD2_GLCOMMANDVERTEX; + +typedef struct { + short s; + short t; +} MD2_TEXTURECOORDINATE; + +typedef struct { + char name[64]; +} MD2_SKIN; + +#define NUMVERTEXNORMALS 162 +float g_md2VertexNormals[NUMVERTEXNORMALS][3] = { +#include "anorms.h" +}; + +osg::Vec3Array *g_md2NormalsArray = NULL; + +// +// the result will be an osg::Switch +// whose children will be osg::Sequences, one for each animation +// the children of the osg::Sequence will be the osg::Geode that contains the +// osg::Geometry of the relevant frame. The osg::Geode will have a osg::StateSet +// containing the texture information. +// + +// this is also quite non-portable to non-little-endian architectures + +static osg::Node* +load_md2 (const char *filename) +{ + struct stat st; + void *mapbase; + void *p; + int file_fd; + osg::Node* result = NULL; + + if (stat (filename, &st) < 0) { + return NULL; + } + + file_fd = open (filename, O_RDONLY); + if (file_fd <= 0) { + return NULL; + } + +#if 0 + mapbase = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, file_fd, 0); + if (mapbase == NULL) { + close (file_fd); + return NULL; + } +#else + mapbase = malloc (st.st_size); + read (file_fd, mapbase, st.st_size); +#endif + + if (g_md2NormalsArray == NULL) { + g_md2NormalsArray = new osg::Vec3Array; + for (int i = 0; i < NUMVERTEXNORMALS; i++) + g_md2NormalsArray->push_back (osg::Vec3 (g_md2VertexNormals[i][0], g_md2VertexNormals[i][1], g_md2VertexNormals[i][2])); + } + + + MD2_HEADER *md2_header = (MD2_HEADER *) mapbase; + if (md2_header->magic != MD2_HEADER_MAGIC || md2_header->version != 8) { +#if 0 + munmap (mapbase); +#else + free (mapbase); +#endif + close (file_fd); + return NULL; + } + + MD2_SKIN *md2_skins = (MD2_SKIN *) ((unsigned char *) mapbase + md2_header->offsetSkins); + MD2_TEXTURECOORDINATE *md2_texcoords = (MD2_TEXTURECOORDINATE *) ((unsigned char *) mapbase + md2_header->offsetTexCoords); + MD2_TRIANGLE *md2_triangles = (MD2_TRIANGLE *) ((unsigned char *) mapbase + md2_header->offsetTriangles); + + osg::Switch *base_switch = new osg::Switch (); + osg::Sequence *current_sequence = NULL; + + // read in the frame info into a vector + const char *last_frame_name = NULL; + + osg::Vec3Array *vertexCoords = NULL; + osg::Vec2Array *texCoords = NULL; + osg::UIntArray *vertexIndices = NULL; + osg::UIntArray *texIndices = NULL; + osg::Vec3Array *normalCoords = NULL; + osg::UIntArray *normalIndices = NULL; + + // load the texture skins + + // there is code here to support multiple skins, but there's no need for it + // since we really just want to support one; we have no way of returning more + // than one to the user in any case. +#if 0 + std::vector skin_textures; + + for (int si = 0; si < md2_header->numSkins; si++) { + osg::Image *img; + osg::Texture2D *tex; + std::string imgname (md2_skins[si].name); + + // first try loading the imgname straight + img = osgDB::readImageFile (imgname); + if (img) { + tex = new osg::Texture2D; + tex->setImage (img); + skin_textures.push_back (tex); + continue; + } + + // we failed, so check if it's a PCX image + if (imgname.size() > 4 && + osgDB::equalCaseInsensitive (imgname.substr (imgname.size() - 3, 3), "pcx")) + { + // it's a pcx, so try bmp and tga, since pcx sucks + std::string basename = imgname.substr (0, imgname.size() - 3); + img = osgDB::readImageFile (basename + "bmp"); + if (img) { + tex = new osg::Texture2D; + tex->setImage (img); + skin_textures.push_back (tex); + continue; + } + + img = osgDB::readImageFile (basename + "tga"); + if (img) { + tex = new osg::Texture2D; + tex->setImage (img); + skin_textures.push_back (tex); + continue; + } + } + + // couldn't find the referenced texture skin for this model + skin_textures.push_back (NULL); + osg::notify(osg::WARN) << "MD2 Loader: Couldn't load skin " << imgname << " referenced by model " << filename << std::endl; + } +#else + // load the single skin + osg::Image *skin_image = NULL; + osg::Texture2D *skin_texture = NULL; + + if (md2_header->numSkins > 0) { + std::string imgname (md2_skins[0].name); + + do { + // first try loading the imgname straight + skin_image = osgDB::readImageFile (imgname); + if (skin_image) break; + + // we failed, so check if it's a PCX image + if (imgname.size() > 4 && + osgDB::equalCaseInsensitive (imgname.substr (imgname.size() - 3, 3), "pcx")) + { + // it's a pcx, so try bmp and tga, since pcx sucks + std::string basename = imgname.substr (0, imgname.size() - 3); + skin_image = osgDB::readImageFile (basename + "bmp"); + if (skin_image) break; + + skin_image = osgDB::readImageFile (basename + "tga"); + if (skin_image) break; + } + } while (0); + + if (skin_image) { + skin_texture = new osg::Texture2D; + skin_texture->setImage (skin_image); + skin_texture->setFilter (osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST); + } else { + // couldn't find the referenced texture skin for this model + osg::notify(osg::WARN) << "MD2 Loader: Couldn't load skin " << imgname << " referenced by model " << filename << std::endl; + } + } + +#endif + + int sequence_frame = 0; + + for (int curFrame = 0; curFrame < md2_header->numFrames; curFrame++) { + // std::cerr << "Num vertices " << md2_header->numVertices << std::endl; + + long *command = (long *) ((unsigned char *) mapbase + md2_header->offsetGlCommands); + + MD2_FRAME *frame = (MD2_FRAME *) ((unsigned char *) mapbase + md2_header->offsetFrames + (md2_header->frameSize * curFrame)); + MD2_VERTEX *frame_vertices = frame->vertices; + + + // std::cerr << "Reading frame " << curFrame << " (gl offset: " << md2_header->offsetGlCommands << ") name: " << frame->name << std::endl; + + int last_len = last_frame_name ? strcspn (last_frame_name, "0123456789") : 0; + int cur_len = strcspn (frame->name, "0123456789"); + + if (last_len != cur_len || strncmp (last_frame_name, frame->name, last_len) != 0) { + if (current_sequence) { + current_sequence->setInterval (osg::Sequence::LOOP, 0, -1); + base_switch->addChild (current_sequence); + } + + current_sequence = new osg::Sequence (); + current_sequence->setMode (osg::Sequence::START); + current_sequence->setDuration (1.0f, -1); + sequence_frame = 0; + + current_sequence->setName (std::string (frame->name, cur_len)); + } + + vertexCoords = new osg::Vec3Array; + normalCoords = new osg::Vec3Array; + + for (int vi = 0; vi < md2_header->numVertices; vi++) { + vertexCoords->push_back + (osg::Vec3 + (frame_vertices[vi].vertex[0] * frame->scale[0] + frame->translate[0], + -1 * (frame_vertices[vi].vertex[2] * frame->scale[2] + frame->translate[2]), + frame_vertices[vi].vertex[1] * frame->scale[1] + frame->translate[1])); + osg::Vec3 z = (*g_md2NormalsArray) [frame_vertices[vi].lightNormalIndex]; + normalCoords->push_back (z); + } + + if (curFrame == 0) { + vertexIndices = new osg::UIntArray; + normalIndices = new osg::UIntArray; + + texCoords = new osg::Vec2Array; + texIndices = new osg::UIntArray; + + for (int vi = 0; vi < md2_header->numTexcoords; vi++) { + texCoords->push_back + (osg::Vec2 ((float) md2_texcoords[vi].s / md2_header->skinWidth, + 1.0f - (float) md2_texcoords[vi].t / md2_header->skinHeight)); + } + + for (int ti = 0; ti < md2_header->numTriangles; ti++) { + vertexIndices->push_back (md2_triangles[ti].vertexIndices[0]); + vertexIndices->push_back (md2_triangles[ti].vertexIndices[1]); + vertexIndices->push_back (md2_triangles[ti].vertexIndices[2]); + + normalIndices->push_back (md2_triangles[ti].vertexIndices[0]); + normalIndices->push_back (md2_triangles[ti].vertexIndices[1]); + normalIndices->push_back (md2_triangles[ti].vertexIndices[2]); + + texIndices->push_back (md2_triangles[ti].textureIndices[0]); + texIndices->push_back (md2_triangles[ti].textureIndices[1]); + texIndices->push_back (md2_triangles[ti].textureIndices[2]); + } + } + + osg::Geometry *geom = new osg::Geometry; + + geom->setVertexArray (vertexCoords); + geom->setVertexIndices (vertexIndices); + + geom->setTexCoordArray (0, texCoords); + geom->setTexCoordIndices (0, texIndices); + + geom->setNormalArray (g_md2NormalsArray); + geom->setNormalIndices (normalIndices); + geom->setNormalBinding (osg::Geometry::BIND_PER_VERTEX); + + geom->addPrimitiveSet (new osg::DrawArrays (osg::PrimitiveSet::TRIANGLES, 0, vertexIndices->size ())); + + osg::Geode *geode = new osg::Geode; + geode->addDrawable (geom); + + current_sequence->addChild (geode); + current_sequence->setTime (sequence_frame, 0.2); + sequence_frame++; + + last_frame_name = frame->name; + } + + if (current_sequence) { + current_sequence->setInterval (osg::Sequence::LOOP, 0, -1); + base_switch->addChild (current_sequence); + } + + osg::StateSet *state = new osg::StateSet; + + if (skin_texture != NULL) { + state->setTextureAttributeAndModes (0, skin_texture, osg::StateAttribute::ON); + } + base_switch->setStateSet (state); + + //base_switch->setAllChildrenOff (); + + base_switch->setSingleChildOn(0); + + result = base_switch; + +#if 0 + munamp (mapbase); +#else + free (mapbase); +#endif + close (file_fd); + return result; +} diff --git a/src/osgPlugins/md2/anorms.h b/src/osgPlugins/md2/anorms.h new file mode 100644 index 000000000..212b0387d --- /dev/null +++ b/src/osgPlugins/md2/anorms.h @@ -0,0 +1,181 @@ + /* +Copyright (C) 1997-2001 Id Software, Inc. + +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. + +*/ +{-0.525731, 0.000000, 0.850651}, +{-0.442863, 0.238856, 0.864188}, +{-0.295242, 0.000000, 0.955423}, +{-0.309017, 0.500000, 0.809017}, +{-0.162460, 0.262866, 0.951056}, +{0.000000, 0.000000, 1.000000}, +{0.000000, 0.850651, 0.525731}, +{-0.147621, 0.716567, 0.681718}, +{0.147621, 0.716567, 0.681718}, +{0.000000, 0.525731, 0.850651}, +{0.309017, 0.500000, 0.809017}, +{0.525731, 0.000000, 0.850651}, +{0.295242, 0.000000, 0.955423}, +{0.442863, 0.238856, 0.864188}, +{0.162460, 0.262866, 0.951056}, +{-0.681718, 0.147621, 0.716567}, +{-0.809017, 0.309017, 0.500000}, +{-0.587785, 0.425325, 0.688191}, +{-0.850651, 0.525731, 0.000000}, +{-0.864188, 0.442863, 0.238856}, +{-0.716567, 0.681718, 0.147621}, +{-0.688191, 0.587785, 0.425325}, +{-0.500000, 0.809017, 0.309017}, +{-0.238856, 0.864188, 0.442863}, +{-0.425325, 0.688191, 0.587785}, +{-0.716567, 0.681718, -0.147621}, +{-0.500000, 0.809017, -0.309017}, +{-0.525731, 0.850651, 0.000000}, +{0.000000, 0.850651, -0.525731}, +{-0.238856, 0.864188, -0.442863}, +{0.000000, 0.955423, -0.295242}, +{-0.262866, 0.951056, -0.162460}, +{0.000000, 1.000000, 0.000000}, +{0.000000, 0.955423, 0.295242}, +{-0.262866, 0.951056, 0.162460}, +{0.238856, 0.864188, 0.442863}, +{0.262866, 0.951056, 0.162460}, +{0.500000, 0.809017, 0.309017}, +{0.238856, 0.864188, -0.442863}, +{0.262866, 0.951056, -0.162460}, +{0.500000, 0.809017, -0.309017}, +{0.850651, 0.525731, 0.000000}, +{0.716567, 0.681718, 0.147621}, +{0.716567, 0.681718, -0.147621}, +{0.525731, 0.850651, 0.000000}, +{0.425325, 0.688191, 0.587785}, +{0.864188, 0.442863, 0.238856}, +{0.688191, 0.587785, 0.425325}, +{0.809017, 0.309017, 0.500000}, +{0.681718, 0.147621, 0.716567}, +{0.587785, 0.425325, 0.688191}, +{0.955423, 0.295242, 0.000000}, +{1.000000, 0.000000, 0.000000}, +{0.951056, 0.162460, 0.262866}, +{0.850651, -0.525731, 0.000000}, +{0.955423, -0.295242, 0.000000}, +{0.864188, -0.442863, 0.238856}, +{0.951056, -0.162460, 0.262866}, +{0.809017, -0.309017, 0.500000}, +{0.681718, -0.147621, 0.716567}, +{0.850651, 0.000000, 0.525731}, +{0.864188, 0.442863, -0.238856}, +{0.809017, 0.309017, -0.500000}, +{0.951056, 0.162460, -0.262866}, +{0.525731, 0.000000, -0.850651}, +{0.681718, 0.147621, -0.716567}, +{0.681718, -0.147621, -0.716567}, +{0.850651, 0.000000, -0.525731}, +{0.809017, -0.309017, -0.500000}, +{0.864188, -0.442863, -0.238856}, +{0.951056, -0.162460, -0.262866}, +{0.147621, 0.716567, -0.681718}, +{0.309017, 0.500000, -0.809017}, +{0.425325, 0.688191, -0.587785}, +{0.442863, 0.238856, -0.864188}, +{0.587785, 0.425325, -0.688191}, +{0.688191, 0.587785, -0.425325}, +{-0.147621, 0.716567, -0.681718}, +{-0.309017, 0.500000, -0.809017}, +{0.000000, 0.525731, -0.850651}, +{-0.525731, 0.000000, -0.850651}, +{-0.442863, 0.238856, -0.864188}, +{-0.295242, 0.000000, -0.955423}, +{-0.162460, 0.262866, -0.951056}, +{0.000000, 0.000000, -1.000000}, +{0.295242, 0.000000, -0.955423}, +{0.162460, 0.262866, -0.951056}, +{-0.442863, -0.238856, -0.864188}, +{-0.309017, -0.500000, -0.809017}, +{-0.162460, -0.262866, -0.951056}, +{0.000000, -0.850651, -0.525731}, +{-0.147621, -0.716567, -0.681718}, +{0.147621, -0.716567, -0.681718}, +{0.000000, -0.525731, -0.850651}, +{0.309017, -0.500000, -0.809017}, +{0.442863, -0.238856, -0.864188}, +{0.162460, -0.262866, -0.951056}, +{0.238856, -0.864188, -0.442863}, +{0.500000, -0.809017, -0.309017}, +{0.425325, -0.688191, -0.587785}, +{0.716567, -0.681718, -0.147621}, +{0.688191, -0.587785, -0.425325}, +{0.587785, -0.425325, -0.688191}, +{0.000000, -0.955423, -0.295242}, +{0.000000, -1.000000, 0.000000}, +{0.262866, -0.951056, -0.162460}, +{0.000000, -0.850651, 0.525731}, +{0.000000, -0.955423, 0.295242}, +{0.238856, -0.864188, 0.442863}, +{0.262866, -0.951056, 0.162460}, +{0.500000, -0.809017, 0.309017}, +{0.716567, -0.681718, 0.147621}, +{0.525731, -0.850651, 0.000000}, +{-0.238856, -0.864188, -0.442863}, +{-0.500000, -0.809017, -0.309017}, +{-0.262866, -0.951056, -0.162460}, +{-0.850651, -0.525731, 0.000000}, +{-0.716567, -0.681718, -0.147621}, +{-0.716567, -0.681718, 0.147621}, +{-0.525731, -0.850651, 0.000000}, +{-0.500000, -0.809017, 0.309017}, +{-0.238856, -0.864188, 0.442863}, +{-0.262866, -0.951056, 0.162460}, +{-0.864188, -0.442863, 0.238856}, +{-0.809017, -0.309017, 0.500000}, +{-0.688191, -0.587785, 0.425325}, +{-0.681718, -0.147621, 0.716567}, +{-0.442863, -0.238856, 0.864188}, +{-0.587785, -0.425325, 0.688191}, +{-0.309017, -0.500000, 0.809017}, +{-0.147621, -0.716567, 0.681718}, +{-0.425325, -0.688191, 0.587785}, +{-0.162460, -0.262866, 0.951056}, +{0.442863, -0.238856, 0.864188}, +{0.162460, -0.262866, 0.951056}, +{0.309017, -0.500000, 0.809017}, +{0.147621, -0.716567, 0.681718}, +{0.000000, -0.525731, 0.850651}, +{0.425325, -0.688191, 0.587785}, +{0.587785, -0.425325, 0.688191}, +{0.688191, -0.587785, 0.425325}, +{-0.955423, 0.295242, 0.000000}, +{-0.951056, 0.162460, 0.262866}, +{-1.000000, 0.000000, 0.000000}, +{-0.850651, 0.000000, 0.525731}, +{-0.955423, -0.295242, 0.000000}, +{-0.951056, -0.162460, 0.262866}, +{-0.864188, 0.442863, -0.238856}, +{-0.951056, 0.162460, -0.262866}, +{-0.809017, 0.309017, -0.500000}, +{-0.864188, -0.442863, -0.238856}, +{-0.951056, -0.162460, -0.262866}, +{-0.809017, -0.309017, -0.500000}, +{-0.681718, 0.147621, -0.716567}, +{-0.681718, -0.147621, -0.716567}, +{-0.850651, 0.000000, -0.525731}, +{-0.688191, 0.587785, -0.425325}, +{-0.587785, 0.425325, -0.688191}, +{-0.425325, 0.688191, -0.587785}, +{-0.425325, -0.688191, -0.587785}, +{-0.587785, -0.425325, -0.688191}, +{-0.688191, -0.587785, -0.425325},