Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/lwo/lwoSurfaceBlock.cxx

Go to the documentation of this file.
00001 // Filename: lwoSurfaceBlock.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 "lwoSurfaceBlock.h"
00020 #include "iffInputFile.h"
00021 #include "lwoSurfaceBlockAxis.h"
00022 #include "lwoSurfaceBlockImage.h"
00023 #include "lwoSurfaceBlockHeader.h"
00024 #include "lwoSurfaceBlockProjection.h"
00025 #include "lwoSurfaceBlockRepeat.h"
00026 #include "lwoSurfaceBlockTMap.h"
00027 #include "lwoSurfaceBlockWrap.h"
00028 #include "lwoSurfaceBlockVMapName.h"
00029 
00030 #include "dcast.h"
00031 #include "indent.h"
00032 
00033 TypeHandle LwoSurfaceBlock::_type_handle;
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: LwoSurfaceBlock::read_iff
00037 //       Access: Public, Virtual
00038 //  Description: Reads the data of the chunk in from the given input
00039 //               file, if possible.  The ID and length of the chunk
00040 //               have already been read.  stop_at is the byte position
00041 //               of the file to stop at (based on the current position
00042 //               at in->get_bytes_read()).  Returns true on success,
00043 //               false otherwise.
00044 ////////////////////////////////////////////////////////////////////
00045 bool LwoSurfaceBlock::
00046 read_iff(IffInputFile *in, size_t stop_at) {
00047   PT(IffChunk) chunk = in->get_subchunk(this);
00048   if (chunk == (IffChunk *)NULL) {
00049     return false;
00050   }
00051   if (!chunk->is_of_type(LwoSurfaceBlockHeader::get_class_type())) {
00052     nout << "Invalid chunk for header of surface block: " << *chunk << "\n";
00053     return false;
00054   }
00055 
00056   _header = DCAST(LwoSurfaceBlockHeader, chunk);
00057 
00058   read_subchunks_iff(in, stop_at);
00059   return true;
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: LwoSurfaceBlock::write
00064 //       Access: Public, Virtual
00065 //  Description:
00066 ////////////////////////////////////////////////////////////////////
00067 void LwoSurfaceBlock::
00068 write(ostream &out, int indent_level) const {
00069   indent(out, indent_level)
00070     << get_id() << " {\n";
00071   _header->write(out, indent_level + 2);
00072   out << "\n";
00073   write_chunks(out, indent_level + 2);
00074   indent(out, indent_level)
00075     << "}\n";
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: LwoSurfaceBlock::make_new_chunk
00080 //       Access: Protected, Virtual
00081 //  Description: Allocates and returns a new chunk of the appropriate
00082 //               type based on the given ID, according to the context
00083 //               given by this chunk itself.
00084 ////////////////////////////////////////////////////////////////////
00085 IffChunk *LwoSurfaceBlock::
00086 make_new_chunk(IffInputFile *in, IffId id) {
00087   if (id == IffId("IMAP") ||
00088       id == IffId("PROC") ||
00089       id == IffId("GRAD") ||
00090       id == IffId("SHDR")) {
00091     return new LwoSurfaceBlockHeader;
00092 
00093   } else if (id == IffId("TMAP")) {
00094     return new LwoSurfaceBlockTMap;
00095 
00096   } else if (id == IffId("PROJ")) {
00097     return new LwoSurfaceBlockProjection;
00098 
00099   } else if (id == IffId("AXIS")) {
00100     return new LwoSurfaceBlockAxis;
00101 
00102   } else if (id == IffId("IMAG")) {
00103     return new LwoSurfaceBlockImage;
00104 
00105   } else if (id == IffId("WRAP")) {
00106     return new LwoSurfaceBlockWrap;
00107 
00108   } else if (id == IffId("WRPH") ||
00109              id == IffId("WRPW")) {
00110     return new LwoSurfaceBlockRepeat;
00111 
00112   } else if (id == IffId("VMAP")) {
00113     return new LwoSurfaceBlockVMapName;
00114 
00115   } else  {
00116     return IffChunk::make_new_chunk(in, id);
00117   }
00118 }
00119 

Generated on Fri May 2 03:20:45 2003 for Panda-Tool by doxygen1.3