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