Panda3D

cLwoPoints.cxx

00001 // Filename: cLwoPoints.cxx
00002 // Created by:  drose (25Apr01)
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 "cLwoPoints.h"
00016 #include "lwoToEggConverter.h"
00017 #include "cLwoLayer.h"
00018 
00019 #include "lwoVertexMap.h"
00020 #include "string_utils.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: CLwoPoints::add_vmap
00024 //       Access: Public
00025 //  Description: Associates the indicated VertexMap with the points
00026 //               set.  This may define such niceties as UV coordinates
00027 //               or per-vertex color.
00028 ////////////////////////////////////////////////////////////////////
00029 void CLwoPoints::
00030 add_vmap(const LwoVertexMap *lwo_vmap) {
00031   IffId map_type = lwo_vmap->_map_type;
00032   const string &name = lwo_vmap->_name;
00033 
00034   bool inserted;
00035   if (map_type == IffId("TXUV")) {
00036     inserted =
00037       _txuv.insert(VMap::value_type(name, lwo_vmap)).second;
00038 
00039   } else if (map_type == IffId("PICK")) {
00040     inserted =
00041       _pick.insert(VMap::value_type(name, lwo_vmap)).second;
00042 
00043   } else {
00044     return;
00045   }
00046 
00047   if (!inserted) {
00048     nout << "Multiple vertex maps on the same points of type "
00049          << map_type << " named " << name << "\n";
00050   }
00051 }
00052 
00053 ////////////////////////////////////////////////////////////////////
00054 //     Function: CLwoPoints::get_uv
00055 //       Access: Public
00056 //  Description: Returns true if there is a UV of the indicated name
00057 //               associated with the given vertex, false otherwise.
00058 //               If true, fills in uv with the value.
00059 ////////////////////////////////////////////////////////////////////
00060 bool CLwoPoints::
00061 get_uv(const string &uv_name, int n, LPoint2f &uv) const {
00062   VMap::const_iterator ni = _txuv.find(uv_name);
00063   if (ni == _txuv.end()) {
00064     return false;
00065   }
00066 
00067   const LwoVertexMap *vmap = (*ni).second;
00068   if (vmap->_dimension != 2) {
00069     nout << "Unexpected dimension of " << vmap->_dimension
00070          << " for UV map " << uv_name << "\n";
00071     return false;
00072   }
00073 
00074   if (!vmap->has_value(n)) {
00075     return false;
00076   }
00077 
00078   PTA_float value = vmap->get_value(n);
00079 
00080   uv.set(value[0], value[1]);
00081   return true;
00082 }
00083 
00084 ////////////////////////////////////////////////////////////////////
00085 //     Function: CLwoPoints::make_egg
00086 //       Access: Public
00087 //  Description: Creates the egg structures associated with this
00088 //               Lightwave object.
00089 ////////////////////////////////////////////////////////////////////
00090 void CLwoPoints::
00091 make_egg() {
00092   // Generate a vpool name based on the layer index, for lack of
00093   // anything better.
00094   string vpool_name = "layer" + format_string(_layer->get_number());
00095   _egg_vpool = new EggVertexPool(vpool_name);
00096 }
00097 
00098 ////////////////////////////////////////////////////////////////////
00099 //     Function: CLwoPoints::connect_egg
00100 //       Access: Public
00101 //  Description: Connects all the egg structures together.
00102 ////////////////////////////////////////////////////////////////////
00103 void CLwoPoints::
00104 connect_egg() {
00105   if (!_egg_vpool->empty()) {
00106     _layer->_egg_group->add_child(_egg_vpool.p());
00107   }
00108 }
00109 
 All Classes Functions Variables Enumerations