Panda3D
eggVertexUV.I
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 eggVertexUV.I
10  * @author drose
11  * @date 2004-07-20
12  */
13 
14 /**
15  * Returns the actual name that should be set for a given name string.
16  * Usually this is the same string that is input, but for historical reasons
17  * the texture coordinate name "default" is mapped to the empty string.
18  */
19 INLINE std::string EggVertexUV::
20 filter_name(const std::string &name) {
21  if (name == "default") {
22  return std::string();
23  }
24  return name;
25 }
26 
27 /**
28  *
29  */
30 INLINE void EggVertexUV::
31 set_name(const std::string &name) {
32  Namable::set_name(filter_name(name));
33 }
34 
35 /**
36  * Returns the number of components of the texture coordinate set. This is
37  * either 2 (the normal case) or 3 (for a 3-d texture coordinate).
38  */
39 INLINE int EggVertexUV::
40 get_num_dimensions() const {
41  return has_w() ? 3 : 2;
42 }
43 
44 /**
45  * Returns true if the texture coordinate has a third, w component, false if
46  * it is just a normal 2-d texture coordinate.
47  */
48 INLINE bool EggVertexUV::
49 has_w() const {
50  return (_flags & F_has_w) != 0;
51 }
52 
53 /**
54  * Returns the texture coordinate pair, if get_num_dimensions() is 2.
55  */
56 INLINE LTexCoordd EggVertexUV::
57 get_uv() const {
58  nassertr(!has_w(), LTexCoordd::zero());
59  return LTexCoordd(_uvw[0], _uvw[1]);
60 }
61 
62 /**
63  * Returns the texture coordinate triple, if get_num_dimensions() is 3. This
64  * is also legal to call if get_num_dimensions() is 2 (but the last dimension
65  * will be zero).
66  */
67 INLINE const LTexCoord3d &EggVertexUV::
68 get_uvw() const {
69  return _uvw;
70 }
71 
72 /**
73  * Sets the texture coordinate pair. This makes the texture coordinate a 2-d
74  * texture coordinate, which is the usual case.
75  */
76 INLINE void EggVertexUV::
77 set_uv(const LTexCoordd &uv) {
78  _uvw.set(uv[0], uv[1], 0.0);
79  _flags &= ~F_has_w;
80 }
81 
82 /**
83  * Sets the texture coordinate triple. This makes the texture coordinate a
84  * 3-d texture coordinate.
85  */
86 INLINE void EggVertexUV::
87 set_uvw(const LTexCoord3d &uvw) {
88  _uvw = uvw;
89  _flags |= F_has_w;
90 }
91 
92 /**
93  *
94  */
95 INLINE bool EggVertexUV::
96 has_tangent() const {
97  return (_flags & F_has_tangent) != 0;
98 }
99 
100 /**
101  *
102  */
103 INLINE bool EggVertexUV::
104 has_tangent4() const {
105  return (_flags & F_has_tangent4) != 0;
106 }
107 
108 /**
109  *
110  */
111 INLINE const LNormald &EggVertexUV::
112 get_tangent() const {
113  nassertr(has_tangent(), _tangent);
114  return _tangent;
115 }
116 
117 /**
118  *
119  */
120 INLINE LVecBase4d EggVertexUV::
121 get_tangent4() const {
122  LVecBase4d tangent4(_tangent, 1.0);
123  nassertr_always(has_tangent(), tangent4);
124  if (_flags & F_flip_computed_binormal) {
125  tangent4[3] = -1.0;
126  }
127  return tangent4;
128 }
129 
130 /**
131  *
132  */
133 INLINE void EggVertexUV::
134 set_tangent(const LNormald &tangent) {
135  _tangent = tangent;
136  _flags |= F_has_tangent;
137  _flags &= ~(F_has_tangent4 | F_flip_computed_binormal);
138 }
139 
140 /**
141  * Sets the tangent vector, along with a fourth parameter that is multiplied
142  * with the result of cross(normal, tangent) when computing the binormal.
143  */
144 INLINE void EggVertexUV::
145 set_tangent4(const LVecBase4d &tangent) {
146  _tangent = tangent.get_xyz();
147  _flags |= F_has_tangent4 | F_has_tangent;
148  if (tangent[3] < 0.0) {
149  _flags |= F_flip_computed_binormal;
150  } else {
151  _flags &= ~F_flip_computed_binormal;
152  }
153 }
154 
155 /**
156  *
157  */
158 INLINE void EggVertexUV::
159 clear_tangent() {
160  _flags &= ~F_has_tangent;
161 }
162 
163 /**
164  *
165  */
166 INLINE bool EggVertexUV::
167 has_binormal() const {
168  return (_flags & F_has_binormal) != 0;
169 }
170 
171 /**
172  *
173  */
174 INLINE const LNormald &EggVertexUV::
175 get_binormal() const {
176  nassertr(has_binormal(), _binormal);
177  return _binormal;
178 }
179 
180 /**
181  *
182  */
183 INLINE void EggVertexUV::
184 set_binormal(const LNormald &binormal) {
185  _binormal = binormal;
186  _flags |= F_has_binormal;
187 }
188 
189 /**
190  *
191  */
192 INLINE void EggVertexUV::
193 clear_binormal() {
194  _flags &= ~F_has_binormal;
195 }
static std::string filter_name(const std::string &name)
Returns the actual name that should be set for a given name string.
Definition: eggVertexUV.I:20
LTexCoordd get_uv() const
Returns the texture coordinate pair, if get_num_dimensions() is 2.
Definition: eggVertexUV.I:57
bool has_w() const
Returns true if the texture coordinate has a third, w component, false if it is just a normal 2-d tex...
Definition: eggVertexUV.I:49
void set_uv(const LTexCoordd &texCoord)
Sets the texture coordinate pair.
Definition: eggVertexUV.I:77
int get_num_dimensions() const
Returns the number of components of the texture coordinate set.
Definition: eggVertexUV.I:40
void set_uvw(const LTexCoord3d &texCoord)
Sets the texture coordinate triple.
Definition: eggVertexUV.I:87
void set_tangent4(const LVecBase4d &tangent)
Sets the tangent vector, along with a fourth parameter that is multiplied with the result of cross(no...
Definition: eggVertexUV.I:145
const LTexCoord3d & get_uvw() const
Returns the texture coordinate triple, if get_num_dimensions() is 3.
Definition: eggVertexUV.I:68