xFileVertex.cxx

00001 // Filename: xFileVertex.cxx
00002 // Created by:  drose (19Jun01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "xFileVertex.h"
00016 #include "eggVertex.h"
00017 #include "eggPrimitive.h"
00018 #include "config_xfile.h"
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: XFileVertex::Constructor
00022 //       Access: Public
00023 //  Description:
00024 ////////////////////////////////////////////////////////////////////
00025 XFileVertex::
00026 XFileVertex() {
00027   _has_color = false;
00028   _has_uv = false;
00029   _point.set(0.0, 0.0, 0.0);
00030   _uv.set(0.0, 0.0);
00031   _color.set(1.0f, 1.0f, 1.0f, 1.0f);
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: XFileVertex::set_from_egg
00036 //       Access: Public
00037 //  Description: Sets the structure up from the indicated egg data.
00038 ////////////////////////////////////////////////////////////////////
00039 void XFileVertex::
00040 set_from_egg(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
00041   Vertexd pos = egg_vertex->get_pos3();
00042 
00043   if (xfile_one_mesh) {
00044     // If this is going into one big mesh, we must ensure every
00045     // vertex is in world coordinates.
00046     pos = pos * egg_prim->get_vertex_frame();
00047   } else {
00048     // Otherwise, we ensure the vertex is in local coordinates.
00049     pos = pos * egg_prim->get_vertex_to_node();
00050   }
00051 
00052   _point = pos;
00053 
00054   if (egg_vertex->has_uv()) {
00055     TexCoordd uv = egg_vertex->get_uv();
00056     if (egg_prim->has_texture()) {
00057       // Check if there's a texture matrix on the texture.
00058       EggTexture *egg_tex = egg_prim->get_texture();
00059       if (egg_tex->has_transform2d()) {
00060         uv = uv * egg_tex->get_transform2d();
00061       }
00062     }
00063 
00064     _uv[0] = uv[0];
00065     // Windows draws the UV's upside-down.
00066     _uv[1] = 1.0 - uv[1];
00067     _has_uv = true;
00068   }
00069 
00070   if (egg_vertex->has_color()) {
00071     _color = egg_vertex->get_color();
00072     _has_color = true;
00073   } else if (egg_prim->has_color()) {
00074     _color = egg_prim->get_color();
00075     _has_color = true;
00076   }
00077 }
00078 
00079 ////////////////////////////////////////////////////////////////////
00080 //     Function: XFileVertex::compare_to
00081 //       Access: Public
00082 //  Description:
00083 ////////////////////////////////////////////////////////////////////
00084 int XFileVertex::
00085 compare_to(const XFileVertex &other) const {
00086   int ct;
00087   ct = _point.compare_to(other._point);
00088   if (ct == 0) {
00089     ct = _uv.compare_to(other._uv);
00090   }
00091   if (ct == 0) {
00092     ct = _color.compare_to(other._color);
00093   }
00094   return ct;
00095 }