Panda3D

lwoInputFile.cxx

00001 // Filename: lwoInputFile.cxx
00002 // Created by:  drose (24Apr01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "lwoInputFile.h"
00016 #include "lwoBoundingBox.h"
00017 #include "lwoClip.h"
00018 #include "lwoDiscontinuousVertexMap.h"
00019 #include "lwoHeader.h"
00020 #include "lwoLayer.h"
00021 #include "lwoPoints.h"
00022 #include "lwoPolygons.h"
00023 #include "lwoPolygonTags.h"
00024 #include "lwoTags.h"
00025 #include "lwoSurface.h"
00026 #include "lwoVertexMap.h"
00027 
00028 TypeHandle LwoInputFile::_type_handle;
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: LwoInputFile::Constructor
00032 //       Access: Public
00033 //  Description:
00034 ////////////////////////////////////////////////////////////////////
00035 LwoInputFile::
00036 LwoInputFile() {
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: LwoInputFile::Destructor
00041 //       Access: Public, Virtual
00042 //  Description:
00043 ////////////////////////////////////////////////////////////////////
00044 LwoInputFile::
00045 ~LwoInputFile() {
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: LwoInputFile::get_vx
00050 //       Access: Public
00051 //  Description: Reads a Lightwave variable-length index.  This is
00052 //               either a 2-byte or 4-byte integer.
00053 ////////////////////////////////////////////////////////////////////
00054 int LwoInputFile::
00055 get_vx() {
00056   PN_uint16 top = get_be_uint16();
00057   if ((top & 0xff00) == 0xff00) {
00058     // The first byte is 0xff, which indicates we have a 4-byte
00059     // integer.
00060     PN_uint16 bottom = get_be_uint16();
00061     return ((int)(top & 0xff) << 16) | bottom;
00062   }
00063 
00064   // The first byte is not 0xff, which indicates we have a 2-byte
00065   // integer.
00066   return top;
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: LwoInputFile::get_vec3
00071 //       Access: Public
00072 //  Description: Reads a three-component vector of floats.
00073 ////////////////////////////////////////////////////////////////////
00074 LVecBase3 LwoInputFile::
00075 get_vec3() {
00076   LVecBase3 result;
00077   result[0] = get_be_float32();
00078   result[1] = get_be_float32();
00079   result[2] = get_be_float32();
00080   return result;
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: LwoInputFile::get_filename
00085 //       Access: Public
00086 //  Description: Reads a Lightwave platform-neutral filename and
00087 //               converts it to a Panda platform-neutral filename.
00088 ////////////////////////////////////////////////////////////////////
00089 Filename LwoInputFile::
00090 get_filename() {
00091   string name = get_string();
00092   size_t colon = name.find(':');
00093   if (colon == string::npos) {
00094     // No colon; it's just a relative path.
00095     return Filename(name);
00096   }
00097 
00098   // The colon separates the device and the path.
00099   string device = name.substr(0, colon);
00100   string path = name.substr(colon + 1);
00101 
00102   nout << "Ignoring filename device " << device << "\n";
00103   return Filename("/", path);
00104 }
00105 
00106 ////////////////////////////////////////////////////////////////////
00107 //     Function: LwoInputFile::make_new_chunk
00108 //       Access: Protected, Virtual
00109 //  Description: Allocates and returns a new chunk of the appropriate
00110 //               type based on the given ID.
00111 ////////////////////////////////////////////////////////////////////
00112 IffChunk *LwoInputFile::
00113 make_new_chunk(IffId id) {
00114   if (id == IffId("FORM")) {
00115     return new LwoHeader;
00116 
00117   } else if (id == IffId("LAYR")) {
00118     return new LwoLayer;
00119 
00120   } else if (id == IffId("PNTS")) {
00121     return new LwoPoints;
00122 
00123   } else if (id == IffId("VMAP")) {
00124     return new LwoVertexMap;
00125 
00126   } else if (id == IffId("VMAD")) {
00127     return new LwoDiscontinuousVertexMap;
00128 
00129   } else if (id == IffId("POLS")) {
00130     return new LwoPolygons;
00131 
00132   } else if (id == IffId("TAGS") ||
00133              id == IffId("SRFS")) {
00134     return new LwoTags;
00135 
00136   } else if (id == IffId("PTAG")) {
00137     return new LwoPolygonTags;
00138 
00139   } else if (id == IffId("CLIP")) {
00140     return new LwoClip;
00141 
00142   } else if (id == IffId("SURF")) {
00143     return new LwoSurface;
00144 
00145   } else if (id == IffId("BBOX")) {
00146     return new LwoBoundingBox;
00147 
00148   } else {
00149     return IffInputFile::make_new_chunk(id);
00150   }
00151 }
 All Classes Functions Variables Enumerations