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