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