Panda3D
xFileMesh.h
1 // Filename: xFileMesh.h
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 #ifndef XFILEMESH_H
16 #define XFILEMESH_H
17 
18 #include "pandatoolbase.h"
19 #include "pvector.h"
20 #include "epvector.h"
21 #include "pmap.h"
22 #include "indirectCompareTo.h"
23 #include "namable.h"
24 #include "coordinateSystem.h"
25 
26 class XFileNode;
27 class XFileDataNode;
28 class XFileMesh;
29 class XFileVertex;
30 class XFileNormal;
31 class XFileMaterial;
32 class XFileFace;
34 class XFileDataNode;
35 class EggGroupNode;
36 class EggVertex;
37 class EggPolygon;
38 class EggPrimitive;
39 class Datagram;
40 
41 ////////////////////////////////////////////////////////////////////
42 // Class : XFileMesh
43 // Description : This is a collection of polygons; i.e. a polyset.
44 ////////////////////////////////////////////////////////////////////
45 class XFileMesh : public Namable {
46 public:
47  XFileMesh(CoordinateSystem cs = CS_yup_left);
48  ~XFileMesh();
49 
50  void clear();
51 
52  void add_polygon(EggPolygon *egg_poly);
53  int add_vertex(EggVertex *egg_vertex, EggPrimitive *egg_prim);
54  int add_normal(EggVertex *egg_vertex, EggPrimitive *egg_prim);
55  int add_material(EggPrimitive *egg_prim);
56 
57  int add_vertex(XFileVertex *vertex);
58  int add_normal(XFileNormal *normal);
59  int add_material(XFileMaterial *material);
60 
61  void set_egg_parent(EggGroupNode *egg_parent);
62 
63  bool create_polygons(XFileToEggConverter *converter);
64 
65  bool has_normals() const;
66  bool has_colors() const;
67  bool has_uvs() const;
68  bool has_materials() const;
69 
70  int get_num_materials() const;
71  XFileMaterial *get_material(int n) const;
72 
73  XFileDataNode *make_x_mesh(XFileNode *x_parent, const string &suffix);
74  XFileDataNode *make_x_normals(XFileNode *x_mesh, const string &suffix);
75  XFileDataNode *make_x_colors(XFileNode *x_mesh, const string &suffix);
76  XFileDataNode *make_x_uvs(XFileNode *x_mesh, const string &suffix);
77  XFileDataNode *make_x_material_list(XFileNode *x_mesh, const string &suffix);
78 
79  bool fill_mesh(XFileDataNode *obj);
80  bool fill_mesh_child(XFileDataNode *obj);
81  bool fill_normals(XFileDataNode *obj);
82  bool fill_colors(XFileDataNode *obj);
83  bool fill_uvs(XFileDataNode *obj);
86 
87 private:
92 
93  CoordinateSystem _cs;
94 
95  Vertices _vertices;
96  Normals _normals;
97  Materials _materials;
98  Faces _faces;
99 
101 
102  class SkinWeightsData {
103  public:
104  LMatrix4d _matrix_offset;
105  string _joint_name;
106  WeightMap _weight_map;
107  };
108  typedef epvector<SkinWeightsData> SkinWeights;
109  SkinWeights _skin_weights;
110 
114  UniqueVertices _unique_vertices;
115  UniqueNormals _unique_normals;
116  UniqueMaterials _unique_materials;
117 
118  bool _has_normals;
119  bool _has_colors;
120  bool _has_uvs;
121  bool _has_materials;
122 
123  EggGroupNode *_egg_parent;
124 };
125 
126 #endif
127 
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
Definition: eggPrimitive.h:51
void clear()
Empties all data from the mesh.
Definition: xFileMesh.cxx:58
bool fill_mesh(XFileDataNode *obj)
Fills the structure based on the raw data from the X file&#39;s Mesh object.
Definition: xFileMesh.cxx:675
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
This is a collection of polygons; i.e.
Definition: xFileMesh.h:45
bool has_normals() const
Returns true if any of the vertices or faces added to this mesh used a normal, false otherwise...
Definition: xFileMesh.cxx:427
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
This represents a single normal associated with an XFileFace.
Definition: xFileNormal.h:31
bool has_uvs() const
Returns true if any of the vertices added to this mesh used a texture coordinate, false otherwise...
Definition: xFileMesh.cxx:449
bool fill_normals(XFileDataNode *obj)
Fills the structure based on the raw data from the MeshNormals template.
Definition: xFileMesh.cxx:768
int add_vertex(EggVertex *egg_vertex, EggPrimitive *egg_prim)
Creates a new XFileVertex, if one does not already exist for the indicated vertex, and returns its index.
Definition: xFileMesh.cxx:115
int add_material(EggPrimitive *egg_prim)
Creates a new XFileMaterial, if one does not already exist for the indicated material, and returns its index.
Definition: xFileMesh.cxx:181
XFileDataNode * make_x_material_list(XFileNode *x_mesh, const string &suffix)
Creates a MeshMaterialList table for the mesh.
Definition: xFileMesh.cxx:638
bool fill_material_list(XFileDataNode *obj)
Fills the structure based on the raw data from the MeshMaterialList template.
Definition: xFileMesh.cxx:908
bool fill_skin_weights(XFileDataNode *obj)
Fills the structure based on the raw data from the SkinWeights template.
Definition: xFileMesh.cxx:865
int add_normal(EggVertex *egg_vertex, EggPrimitive *egg_prim)
Creates a new XFileNormal, if one does not already exist for the indicated normal, and returns its index.
Definition: xFileMesh.cxx:150
void add_polygon(EggPolygon *egg_poly)
Adds the indicated polygon to the mesh.
Definition: xFileMesh.cxx:101
XFileDataNode * make_x_normals(XFileNode *x_mesh, const string &suffix)
Creates a MeshNormals table for the mesh.
Definition: xFileMesh.cxx:552
XFileMaterial * get_material(int n) const
Returns a pointer to the nth materials associated with the mesh.
Definition: xFileMesh.cxx:482
A single node of an X file.
Definition: xFileNode.h:42
A base class for all things which can have a name.
Definition: namable.h:29
bool fill_colors(XFileDataNode *obj)
Fills the structure based on the raw data from the MeshVertexColors template.
Definition: xFileMesh.cxx:814
void set_egg_parent(EggGroupNode *egg_parent)
Specifies the egg node that will eventually be the parent of this mesh, when create_polygons() is lat...
Definition: xFileMesh.cxx:276
XFileDataNode * make_x_colors(XFileNode *x_mesh, const string &suffix)
Creates a MeshVertexColors table for the mesh.
Definition: xFileMesh.cxx:591
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
bool fill_uvs(XFileDataNode *obj)
Fills the structure based on the raw data from the MeshTextureCoords template.
Definition: xFileMesh.cxx:840
bool fill_mesh_child(XFileDataNode *obj)
Fills the structure based on one of the children of the Mesh object.
Definition: xFileMesh.cxx:721
A single polygon.
Definition: eggPolygon.h:26
This represents a single vertex associated with an XFileFace.
Definition: xFileVertex.h:29
XFileDataNode * make_x_mesh(XFileNode *x_parent, const string &suffix)
Creates an X structure corresponding to the mesh.
Definition: xFileMesh.cxx:493
This represents a single face of an XFileMesh.
Definition: xFileFace.h:28
bool create_polygons(XFileToEggConverter *converter)
Creates a slew of EggPolygons according to the faces in the mesh, and adds them to the previously-ind...
Definition: xFileMesh.cxx:292
This represents an X file "material", which consists of a color, lighting, and/or texture specificati...
Definition: xFileMaterial.h:33
This is an abstract base class for an XFileNode which is also an XFileDataObject. ...
Definition: xFileDataNode.h:36
bool has_colors() const
Returns true if any of the vertices or faces added to this mesh used a color, false otherwise...
Definition: xFileMesh.cxx:438
bool has_materials() const
Returns true if any of the faces added to this mesh used a real material, false otherwise.
Definition: xFileMesh.cxx:460
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
XFileDataNode * make_x_uvs(XFileNode *x_mesh, const string &suffix)
Creates a MeshTextureCoords table for the mesh.
Definition: xFileMesh.cxx:616
int get_num_materials() const
Returns the number of distinct materials associated with the mesh.
Definition: xFileMesh.cxx:471