Panda3D
xFileVertex.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 xFileVertex.cxx
10  * @author drose
11  * @date 2001-06-19
12  */
13 
14 #include "xFileVertex.h"
15 #include "eggVertex.h"
16 #include "eggPrimitive.h"
17 #include "config_xfile.h"
18 
19 /**
20  *
21  */
22 XFileVertex::
23 XFileVertex() {
24  _has_color = false;
25  _has_uv = false;
26  _point.set(0.0, 0.0, 0.0);
27  _uv.set(0.0, 0.0);
28  _color.set(1.0f, 1.0f, 1.0f, 1.0f);
29 }
30 
31 /**
32  * Sets the structure up from the indicated egg data.
33  */
34 void XFileVertex::
35 set_from_egg(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
36  LVertexd pos = egg_vertex->get_pos3();
37 
38  if (xfile_one_mesh) {
39  // If this is going into one big mesh, we must ensure every vertex is in
40  // world coordinates.
41  pos = pos * egg_prim->get_vertex_frame();
42  } else {
43  // Otherwise, we ensure the vertex is in local coordinates.
44  pos = pos * egg_prim->get_vertex_to_node();
45  }
46 
47  _point = pos;
48 
49  if (egg_vertex->has_uv()) {
50  LTexCoordd uv = egg_vertex->get_uv();
51  if (egg_prim->has_texture()) {
52  // Check if there's a texture matrix on the texture.
53  EggTexture *egg_tex = egg_prim->get_texture();
54  if (egg_tex->has_transform2d()) {
55  uv = uv * egg_tex->get_transform2d();
56  }
57  }
58 
59  _uv[0] = uv[0];
60  // Windows draws the UV's upside-down.
61  _uv[1] = 1.0 - uv[1];
62  _has_uv = true;
63  }
64 
65  if (egg_vertex->has_color()) {
66  _color = egg_vertex->get_color();
67  _has_color = true;
68  } else if (egg_prim->has_color()) {
69  _color = egg_prim->get_color();
70  _has_color = true;
71  }
72 }
73 
74 /**
75  *
76  */
77 int XFileVertex::
78 compare_to(const XFileVertex &other) const {
79  int ct;
80  ct = _point.compare_to(other._point);
81  if (ct == 0) {
82  ct = _uv.compare_to(other._uv);
83  }
84  if (ct == 0) {
85  ct = _color.compare_to(other._color);
86  }
87  return ct;
88 }
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
Definition: eggPrimitive.h:47
LMatrix3d get_transform2d() const
Returns the overall transform as a 3x3 matrix.
Definition: eggTransform.I:198
bool has_transform2d() const
Returns true if the transform is specified as a 2-d transform, e.g.
Definition: eggTransform.I:156
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const LMatrix4d & get_vertex_frame() const
Returns the coordinate frame of the vertices referenced by primitives at or under this node.
Definition: eggNode.I:108
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LTexCoordd get_uv() const
Returns the unnamed UV coordinate pair on the vertex.
Definition: eggVertex.I:179
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:30
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LVertexd get_pos3() const
Valid if get_num_dimensions() returns 3 or 4.
Definition: eggVertex.I:131
LColor get_color() const
Returns the color set on this particular attribute.
Definition: eggAttributes.I:91
void set_from_egg(EggVertex *egg_vertex, EggPrimitive *egg_poly)
Sets the structure up from the indicated egg data.
Definition: xFileVertex.cxx:35
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
Definition: eggVertex.h:39
bool has_uv() const
Returns true if the vertex has an unnamed UV coordinate pair, false otherwise.
Definition: eggVertex.I:158
bool has_texture() const
Returns true if the primitive has any textures specified, false otherwise.
Definition: eggPrimitive.I:128
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents a single vertex associated with an XFileFace.
Definition: xFileVertex.h:26
get_texture
Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive...
Definition: eggPrimitive.h:100
const LMatrix4d & get_vertex_to_node() const
Returns the transformation matrix suitable for converting the vertices as read from the egg file into...
Definition: eggNode.I:166