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