Panda3D
xFileVertex.cxx
1 // Filename: xFileVertex.cxx
2 // Created by: drose (19Jun01)
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 "xFileVertex.h"
16 #include "eggVertex.h"
17 #include "eggPrimitive.h"
18 #include "config_xfile.h"
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: XFileVertex::Constructor
22 // Access: Public
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 XFileVertex::
26 XFileVertex() {
27  _has_color = false;
28  _has_uv = false;
29  _point.set(0.0, 0.0, 0.0);
30  _uv.set(0.0, 0.0);
31  _color.set(1.0f, 1.0f, 1.0f, 1.0f);
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: XFileVertex::set_from_egg
36 // Access: Public
37 // Description: Sets the structure up from the indicated egg data.
38 ////////////////////////////////////////////////////////////////////
39 void XFileVertex::
40 set_from_egg(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
41  LVertexd pos = egg_vertex->get_pos3();
42 
43  if (xfile_one_mesh) {
44  // If this is going into one big mesh, we must ensure every
45  // vertex is in world coordinates.
46  pos = pos * egg_prim->get_vertex_frame();
47  } else {
48  // Otherwise, we ensure the vertex is in local coordinates.
49  pos = pos * egg_prim->get_vertex_to_node();
50  }
51 
52  _point = pos;
53 
54  if (egg_vertex->has_uv()) {
55  LTexCoordd uv = egg_vertex->get_uv();
56  if (egg_prim->has_texture()) {
57  // Check if there's a texture matrix on the texture.
58  EggTexture *egg_tex = egg_prim->get_texture();
59  if (egg_tex->has_transform2d()) {
60  uv = uv * egg_tex->get_transform2d();
61  }
62  }
63 
64  _uv[0] = uv[0];
65  // Windows draws the UV's upside-down.
66  _uv[1] = 1.0 - uv[1];
67  _has_uv = true;
68  }
69 
70  if (egg_vertex->has_color()) {
71  _color = egg_vertex->get_color();
72  _has_color = true;
73  } else if (egg_prim->has_color()) {
74  _color = egg_prim->get_color();
75  _has_color = true;
76  }
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: XFileVertex::compare_to
81 // Access: Public
82 // Description:
83 ////////////////////////////////////////////////////////////////////
84 int XFileVertex::
85 compare_to(const XFileVertex &other) const {
86  int ct;
87  ct = _point.compare_to(other._point);
88  if (ct == 0) {
89  ct = _uv.compare_to(other._uv);
90  }
91  if (ct == 0) {
92  ct = _color.compare_to(other._color);
93  }
94  return ct;
95 }
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
Definition: eggPrimitive.h:51
LMatrix3d get_transform2d() const
Returns the overall transform as a 3x3 matrix.
Definition: eggTransform.I:234
bool has_transform2d() const
Returns true if the transform is specified as a 2-d transform, e.g.
Definition: eggTransform.I:180
int compare_to(const LVecBase2d &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
Definition: lvecBase2.h:1923
const LMatrix4d & get_vertex_frame() const
Returns the coordinate frame of the vertices referenced by primitives at or under this node...
Definition: eggNode.I:135
LTexCoordd get_uv() const
Returns the unnamed UV coordinate pair on the vertex.
Definition: eggVertex.I:222
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:33
EggTexture * get_texture() const
Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive...
Definition: eggPrimitive.I:182
This is a two-component point in space.
Definition: lpoint2.h:424
LVertexd get_pos3() const
Valid if get_num_dimensions() returns 3 or 4.
Definition: eggVertex.I:160
LColor get_color() const
Returns the color set on this particular attribute.
void set_from_egg(EggVertex *egg_vertex, EggPrimitive *egg_poly)
Sets the structure up from the indicated egg data.
Definition: xFileVertex.cxx:40
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
int compare_to(const LVecBase4f &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
Definition: lvecBase4.h:988
bool has_uv() const
Returns true if the vertex has an unnamed UV coordinate pair, false otherwise.
Definition: eggVertex.I:194
bool has_texture() const
Returns true if the primitive has any textures specified, false otherwise.
Definition: eggPrimitive.I:155
This represents a single vertex associated with an XFileFace.
Definition: xFileVertex.h:29
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:544
int compare_to(const LVecBase3d &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
Definition: lvecBase3.h:2306
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:203