00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "lwoPolygons.h"
00016 #include "lwoInputFile.h"
00017
00018 #include "dcast.h"
00019 #include "indent.h"
00020
00021 TypeHandle LwoPolygons::_type_handle;
00022
00023
00024
00025
00026
00027
00028 int LwoPolygons::
00029 get_num_polygons() const {
00030 return _polygons.size();
00031 }
00032
00033
00034
00035
00036
00037
00038 LwoPolygons::Polygon *LwoPolygons::
00039 get_polygon(int n) const {
00040 nassertr(n >= 0 && n < (int)_polygons.size(), (Polygon *)NULL);
00041 return _polygons[n];
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 bool LwoPolygons::
00055 read_iff(IffInputFile *in, size_t stop_at) {
00056 LwoInputFile *lin = DCAST(LwoInputFile, in);
00057
00058 if (lin->get_lwo_version() >= 6.0) {
00059
00060
00061
00062 _polygon_type = lin->get_id();
00063
00064 while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
00065 int nf = lin->get_be_uint16();
00066 int num_vertices = nf & PF_numverts_mask;
00067
00068 PT(Polygon) poly = new Polygon;
00069 poly->_flags = nf & ~PF_numverts_mask;
00070 poly->_surface_index = -1;
00071
00072 for (int i = 0; i < num_vertices; i++) {
00073 int vindex = lin->get_vx();
00074 poly->_vertices.push_back(vindex);
00075 }
00076
00077 _polygons.push_back(poly);
00078 }
00079
00080 } else {
00081
00082
00083 _polygon_type = IffId("FACE");
00084
00085 int num_decals = 0;
00086 while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
00087 int num_vertices = lin->get_be_uint16();
00088
00089 PT(Polygon) poly = new Polygon;
00090 poly->_flags = 0;
00091
00092 for (int i = 0; i < num_vertices; i++) {
00093 int vindex = lin->get_vx();
00094 poly->_vertices.push_back(vindex);
00095 }
00096
00097 int surface = lin->get_be_int16();
00098
00099 if (num_decals > 0) {
00100
00101 num_decals--;
00102 poly->_flags |= PF_decal;
00103
00104 } else {
00105 if (surface < 0) {
00106 num_decals = lin->get_be_int16();
00107 surface = -surface;
00108 }
00109 }
00110
00111
00112
00113 poly->_surface_index = surface - 1;
00114
00115 _polygons.push_back(poly);
00116 }
00117 }
00118
00119 return true;
00120 }
00121
00122
00123
00124
00125
00126
00127 void LwoPolygons::
00128 write(ostream &out, int indent_level) const {
00129 indent(out, indent_level)
00130 << get_id() << " { polygon_type = " << _polygon_type
00131 << ", " << _polygons.size() << " polygons }\n";
00132 }