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