Panda3D
 All Classes Functions Variables Enumerations
cLwoPoints.cxx
1 // Filename: cLwoPoints.cxx
2 // Created by: drose (25Apr01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "cLwoPoints.h"
16 #include "lwoToEggConverter.h"
17 #include "cLwoLayer.h"
18 
19 #include "pta_stdfloat.h"
20 #include "lwoVertexMap.h"
21 #include "string_utils.h"
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: CLwoPoints::add_vmap
25 // Access: Public
26 // Description: Associates the indicated VertexMap with the points
27 // set. This may define such niceties as UV coordinates
28 // or per-vertex color.
29 ////////////////////////////////////////////////////////////////////
30 void CLwoPoints::
31 add_vmap(const LwoVertexMap *lwo_vmap) {
32  IffId map_type = lwo_vmap->_map_type;
33  const string &name = lwo_vmap->_name;
34 
35  bool inserted;
36  if (map_type == IffId("TXUV")) {
37  inserted =
38  _txuv.insert(VMap::value_type(name, lwo_vmap)).second;
39 
40  } else if (map_type == IffId("PICK")) {
41  inserted =
42  _pick.insert(VMap::value_type(name, lwo_vmap)).second;
43 
44  } else {
45  return;
46  }
47 
48  if (!inserted) {
49  nout << "Multiple vertex maps on the same points of type "
50  << map_type << " named " << name << "\n";
51  }
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: CLwoPoints::get_uv
56 // Access: Public
57 // Description: Returns true if there is a UV of the indicated name
58 // associated with the given vertex, false otherwise.
59 // If true, fills in uv with the value.
60 ////////////////////////////////////////////////////////////////////
61 bool CLwoPoints::
62 get_uv(const string &uv_name, int n, LPoint2 &uv) const {
63  VMap::const_iterator ni = _txuv.find(uv_name);
64  if (ni == _txuv.end()) {
65  return false;
66  }
67 
68  const LwoVertexMap *vmap = (*ni).second;
69  if (vmap->_dimension != 2) {
70  nout << "Unexpected dimension of " << vmap->_dimension
71  << " for UV map " << uv_name << "\n";
72  return false;
73  }
74 
75  if (!vmap->has_value(n)) {
76  return false;
77  }
78 
79  PTA_stdfloat value = vmap->get_value(n);
80 
81  uv.set(value[0], value[1]);
82  return true;
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: CLwoPoints::make_egg
87 // Access: Public
88 // Description: Creates the egg structures associated with this
89 // Lightwave object.
90 ////////////////////////////////////////////////////////////////////
91 void CLwoPoints::
93  // Generate a vpool name based on the layer index, for lack of
94  // anything better.
95  string vpool_name = "layer" + format_string(_layer->get_number());
96  _egg_vpool = new EggVertexPool(vpool_name);
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: CLwoPoints::connect_egg
101 // Access: Public
102 // Description: Connects all the egg structures together.
103 ////////////////////////////////////////////////////////////////////
104 void CLwoPoints::
106  if (!_egg_vpool->empty()) {
107  _layer->_egg_group->add_child(_egg_vpool.p());
108  }
109 }
110 
void make_egg()
Creates the egg structures associated with this Lightwave object.
Definition: cLwoPoints.cxx:92
void add_vmap(const LwoVertexMap *lwo_vmap)
Associates the indicated VertexMap with the points set.
Definition: cLwoPoints.cxx:31
bool has_value(int index) const
Returns true if the map has a value associated with the given index, false otherwise.
int get_number() const
Returns the index number associated with this particular layer.
Definition: cLwoLayer.I:36
A mapping of floating-point values per integer index.
Definition: lwoVertexMap.h:30
void connect_egg()
Connects all the egg structures together.
Definition: cLwoPoints.cxx:105
bool get_uv(const string &uv_name, int n, LPoint2 &uv) const
Returns true if there is a UV of the indicated name associated with the given vertex, false otherwise.
Definition: cLwoPoints.cxx:62
This is a two-component point in space.
Definition: lpoint2.h:92
A four-byte chunk ID appearing in an &quot;IFF&quot; file.
Definition: iffId.h:29
A collection of vertices.
Definition: eggVertexPool.h:46
PTA_stdfloat get_value(int index) const
Returns the mapping value associated with the given index, or an empty PTA_stdfloat if there is no ma...