Panda3D
 All Classes Functions Variables Enumerations
lwoSurface.cxx
00001 // Filename: lwoSurface.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 "lwoSurface.h"
00016 #include "iffInputFile.h"
00017 #include "lwoSurfaceBlock.h"
00018 #include "lwoSurfaceColor.h"
00019 #include "lwoSurfaceParameter.h"
00020 #include "lwoSurfaceSidedness.h"
00021 #include "lwoSurfaceSmoothingAngle.h"
00022 
00023 #include "indent.h"
00024 
00025 TypeHandle LwoSurface::_type_handle;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: LwoSurface::read_iff
00029 //       Access: Public, Virtual
00030 //  Description: Reads the data of the chunk in from the given input
00031 //               file, if possible.  The ID and length of the chunk
00032 //               have already been read.  stop_at is the byte position
00033 //               of the file to stop at (based on the current position
00034 //               at in->get_bytes_read()).  Returns true on success,
00035 //               false otherwise.
00036 ////////////////////////////////////////////////////////////////////
00037 bool LwoSurface::
00038 read_iff(IffInputFile *in, size_t stop_at) {
00039   _name = in->get_string();
00040   _source = in->get_string();
00041   read_subchunks_iff(in, stop_at);
00042   return true;
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: LwoSurface::write
00047 //       Access: Public, Virtual
00048 //  Description:
00049 ////////////////////////////////////////////////////////////////////
00050 void LwoSurface::
00051 write(ostream &out, int indent_level) const {
00052   indent(out, indent_level)
00053     << get_id() << " {\n";
00054   indent(out, indent_level + 2)
00055     << "name = \"" << _name << "\", source = \"" << _source << "\"\n";
00056   write_chunks(out, indent_level + 2);
00057   indent(out, indent_level)
00058     << "}\n";
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: LwoSurface::make_new_chunk
00063 //       Access: Protected, Virtual
00064 //  Description: Allocates and returns a new chunk of the appropriate
00065 //               type based on the given ID, according to the context
00066 //               given by this chunk itself.
00067 ////////////////////////////////////////////////////////////////////
00068 IffChunk *LwoSurface::
00069 make_new_chunk(IffInputFile *in, IffId id) {
00070   if (id == IffId("COLR")) {
00071     return new LwoSurfaceColor;
00072 
00073   } else if (id == IffId("DIFF") ||
00074              id == IffId("LUMI") ||
00075              id == IffId("SPEC") ||
00076              id == IffId("REFL") ||
00077              id == IffId("TRAN") ||
00078              id == IffId("TRNL") ||
00079              id == IffId("GLOS") ||
00080              id == IffId("SHRP") ||
00081              id == IffId("BUMP") ||
00082              id == IffId("RSAN") ||
00083              id == IffId("RIND")) {
00084     return new LwoSurfaceParameter;
00085 
00086   } else if (id == IffId("SIDE")) {
00087     return new LwoSurfaceSidedness;
00088 
00089   } else if (id == IffId("SMAN")) {
00090     return new LwoSurfaceSmoothingAngle;
00091 
00092   } else if (id == IffId("BLOK")) {
00093     return new LwoSurfaceBlock;
00094 
00095   } else {
00096     return IffChunk::make_new_chunk(in, id);
00097   }
00098 }
00099 
 All Classes Functions Variables Enumerations