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

pandatool/src/lwoegg/cLwoSurfaceBlock.cxx

Go to the documentation of this file.
00001 // Filename: cLwoSurfaceBlock.cxx
00002 // Created by:  drose (26Apr01)
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 "cLwoSurfaceBlock.h"
00020 #include "cLwoSurfaceBlockTMap.h"
00021 #include "lwoToEggConverter.h"
00022 
00023 #include "lwoSurfaceBlockChannel.h"
00024 #include "lwoSurfaceBlockEnabled.h"
00025 #include "lwoSurfaceBlockImage.h"
00026 #include "lwoSurfaceBlockRepeat.h"
00027 #include "lwoSurfaceBlockVMapName.h"
00028 #include "dcast.h"
00029 
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //     Function: CLwoSurfaceBlock::Constructor
00033 //       Access: Public
00034 //  Description:
00035 ////////////////////////////////////////////////////////////////////
00036 CLwoSurfaceBlock::
00037 CLwoSurfaceBlock(LwoToEggConverter *converter, const LwoSurfaceBlock *block) :
00038   _converter(converter),
00039   _block(block)
00040 {
00041   _block_type = _block->_header->get_id();
00042   _ordinal = _block->_header->_ordinal;
00043   _enabled = true;
00044   _opacity_type = LwoSurfaceBlockOpacity::T_additive;
00045   _opacity = 1.0;
00046   _transform = LMatrix4d::ident_mat();
00047   _inv_transform = LMatrix4d::ident_mat();
00048   _projection_mode = LwoSurfaceBlockProjection::M_uv;
00049   _axis = LwoSurfaceBlockAxis::A_y;
00050   _clip_index = -1;
00051   _w_wrap = LwoSurfaceBlockWrap::M_repeat;
00052   _h_wrap = LwoSurfaceBlockWrap::M_repeat;
00053   _w_repeat = 1.0;
00054   _h_repeat = 1.0;
00055   _tmap = (CLwoSurfaceBlockTMap *)NULL;
00056 
00057   // Scan the chunks in the header.
00058   int num_hchunks = _block->_header->get_num_chunks();
00059   for (int hi = 0; hi < num_hchunks; hi++) {
00060     const IffChunk *hchunk = _block->_header->get_chunk(hi);
00061 
00062     if (hchunk->is_of_type(LwoSurfaceBlockChannel::get_class_type())) {
00063       const LwoSurfaceBlockChannel *bc =
00064         DCAST(LwoSurfaceBlockChannel, hchunk);
00065       _channel_id = bc->_channel_id;
00066 
00067     } else if (hchunk->is_of_type(LwoSurfaceBlockEnabled::get_class_type())) {
00068       const LwoSurfaceBlockEnabled *ec =
00069         DCAST(LwoSurfaceBlockEnabled, hchunk);
00070       _enabled = ec->_enabled;
00071     }
00072   }
00073 
00074   // Scan the chunks in the body.
00075   int num_chunks = _block->get_num_chunks();
00076   for (int i = 0; i < num_chunks; i++) {
00077     const IffChunk *chunk = _block->get_chunk(i);
00078 
00079     if (chunk->is_of_type(LwoSurfaceBlockTMap::get_class_type())) {
00080       const LwoSurfaceBlockTMap *lwo_tmap = DCAST(LwoSurfaceBlockTMap, chunk);
00081       if (_tmap != (CLwoSurfaceBlockTMap *)NULL) {
00082         nout << "Two TMAP chunks encountered within surface block.\n";
00083         delete _tmap;
00084       }
00085       _tmap = new CLwoSurfaceBlockTMap(_converter, lwo_tmap);
00086 
00087     } else if (chunk->is_of_type(LwoSurfaceBlockProjection::get_class_type())) {
00088       const LwoSurfaceBlockProjection *proj = DCAST(LwoSurfaceBlockProjection, chunk);
00089       _projection_mode = proj->_mode;
00090 
00091     } else if (chunk->is_of_type(LwoSurfaceBlockAxis::get_class_type())) {
00092       const LwoSurfaceBlockAxis *axis = DCAST(LwoSurfaceBlockAxis, chunk);
00093       _axis = axis->_axis;
00094 
00095     } else if (chunk->is_of_type(LwoSurfaceBlockImage::get_class_type())) {
00096       const LwoSurfaceBlockImage *image = DCAST(LwoSurfaceBlockImage, chunk);
00097       _clip_index = image->_index;
00098 
00099     } else if (chunk->is_of_type(LwoSurfaceBlockWrap::get_class_type())) {
00100       const LwoSurfaceBlockWrap *wrap = DCAST(LwoSurfaceBlockWrap, chunk);
00101       _w_wrap = wrap->_width;
00102       _h_wrap = wrap->_height;
00103 
00104     } else if (chunk->is_of_type(LwoSurfaceBlockWrap::get_class_type())) {
00105       const LwoSurfaceBlockWrap *wrap = DCAST(LwoSurfaceBlockWrap, chunk);
00106       _w_wrap = wrap->_width;
00107       _h_wrap = wrap->_height;
00108 
00109     } else if (chunk->is_of_type(LwoSurfaceBlockVMapName::get_class_type())) {
00110       const LwoSurfaceBlockVMapName *vmap = DCAST(LwoSurfaceBlockVMapName, chunk);
00111       _uv_name = vmap->_name;
00112 
00113     } else if (chunk->is_of_type(LwoSurfaceBlockRepeat::get_class_type())) {
00114       const LwoSurfaceBlockRepeat *repeat = DCAST(LwoSurfaceBlockRepeat, chunk);
00115       if (repeat->get_id() == IffId("WRPW")) {
00116         _w_repeat = repeat->_cycles;
00117       } else if (repeat->get_id() == IffId("WRPH")) {
00118         _h_repeat = repeat->_cycles;
00119       }
00120     }
00121   }
00122 
00123   if (_tmap != (CLwoSurfaceBlockTMap *)NULL) {
00124     _tmap->get_transform(_transform);
00125   }
00126 
00127   // Also rotate the transform if we specify some axis other than Y.
00128   // (All the map_* uv mapping functions are written to assume Y is
00129   // the dominant axis.)
00130   switch (_axis) {
00131   case LwoSurfaceBlockAxis::A_x:
00132     _transform = LMatrix4d::rotate_mat(90.0,
00133                                        LVecBase3d::unit_z(),
00134                                        CS_yup_left) * _transform;
00135     break;
00136 
00137   case LwoSurfaceBlockAxis::A_y:
00138     break;
00139 
00140   case LwoSurfaceBlockAxis::A_z:
00141     _transform = LMatrix4d::rotate_mat(-90.0,
00142                                        LVecBase3d::unit_x(),
00143                                        CS_yup_left) * _transform;
00144     break;
00145   }
00146 
00147   _inv_transform.invert_from(_transform);
00148 }
00149 
00150 ////////////////////////////////////////////////////////////////////
00151 //     Function: CLwoSurfaceBlock::Destructor
00152 //       Access: Public
00153 //  Description:
00154 ////////////////////////////////////////////////////////////////////
00155 CLwoSurfaceBlock::
00156 ~CLwoSurfaceBlock() {
00157   if (_tmap != (CLwoSurfaceBlockTMap *)NULL) {
00158     delete _tmap;
00159   }
00160 }

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