Panda3D
xFileMesh.h
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 xFileMesh.h
10  * @author drose
11  * @date 2001-06-19
12  */
13 
14 #ifndef XFILEMESH_H
15 #define XFILEMESH_H
16 
17 #include "pandatoolbase.h"
18 #include "pvector.h"
19 #include "epvector.h"
20 #include "pmap.h"
21 #include "indirectCompareTo.h"
22 #include "namable.h"
23 #include "coordinateSystem.h"
24 
25 #include "luse.h"
26 
27 class XFileNode;
28 class XFileDataNode;
29 class XFileMesh;
30 class XFileVertex;
31 class XFileNormal;
32 class XFileMaterial;
33 class XFileFace;
35 class XFileDataNode;
36 class EggGroupNode;
37 class EggVertex;
38 class EggPolygon;
39 class EggPrimitive;
40 class Datagram;
41 
42 /**
43  * 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 std::string &suffix);
74  XFileDataNode *make_x_normals(XFileNode *x_mesh, const std::string &suffix);
75  XFileDataNode *make_x_colors(XFileNode *x_mesh, const std::string &suffix);
76  XFileDataNode *make_x_uvs(XFileNode *x_mesh, const std::string &suffix);
77  XFileDataNode *make_x_material_list(XFileNode *x_mesh, const std::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  std::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
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
Definition: eggPrimitive.h:47
void clear()
Empties all data from the mesh.
Definition: xFileMesh.cxx:56
XFileDataNode * make_x_colors(XFileNode *x_mesh, const std::string &suffix)
Creates a MeshVertexColors table for the mesh.
Definition: xFileMesh.cxx:543
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool fill_mesh(XFileDataNode *obj)
Fills the structure based on the raw data from the X file's Mesh object.
Definition: xFileMesh.cxx:619
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:397
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:46
This represents a single normal associated with an XFileFace.
Definition: xFileNormal.h:28
bool has_uvs() const
Returns true if any of the vertices added to this mesh used a texture coordinate, false otherwise.
Definition: xFileMesh.cxx:415
bool fill_normals(XFileDataNode *obj)
Fills the structure based on the raw data from the MeshNormals template.
Definition: xFileMesh.cxx:706
int add_vertex(EggVertex *egg_vertex, EggPrimitive *egg_prim)
Creates a new XFileVertex, if one does not already exist for the indicated vertex,...
Definition: xFileMesh.cxx:108
int add_material(EggPrimitive *egg_prim)
Creates a new XFileMaterial, if one does not already exist for the indicated material,...
Definition: xFileMesh.cxx:168
XFileDataNode * make_x_material_list(XFileNode *x_mesh, const std::string &suffix)
Creates a MeshMaterialList table for the mesh.
Definition: xFileMesh.cxx:586
bool fill_material_list(XFileDataNode *obj)
Fills the structure based on the raw data from the MeshMaterialList template.
Definition: xFileMesh.cxx:837
bool fill_skin_weights(XFileDataNode *obj)
Fills the structure based on the raw data from the SkinWeights template.
Definition: xFileMesh.cxx:796
int add_normal(EggVertex *egg_vertex, EggPrimitive *egg_prim)
Creates a new XFileNormal, if one does not already exist for the indicated normal,...
Definition: xFileMesh.cxx:140
void add_polygon(EggPolygon *egg_poly)
Adds the indicated polygon to the mesh.
Definition: xFileMesh.cxx:97
XFileMaterial * get_material(int n) const
Returns a pointer to the nth materials associated with the mesh.
Definition: xFileMesh.cxx:440
A single node of an X file.
Definition: xFileNode.h:39
A base class for all things which can have a name.
Definition: namable.h:26
bool fill_colors(XFileDataNode *obj)
Fills the structure based on the raw data from the MeshVertexColors template.
Definition: xFileMesh.cxx:750
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:251
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
Definition: eggVertex.h:39
bool fill_uvs(XFileDataNode *obj)
Fills the structure based on the raw data from the MeshTextureCoords template.
Definition: xFileMesh.cxx:774
bool fill_mesh_child(XFileDataNode *obj)
Fills the structure based on one of the children of the Mesh object.
Definition: xFileMesh.cxx:662
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileDataNode * make_x_uvs(XFileNode *x_mesh, const std::string &suffix)
Creates a MeshTextureCoords table for the mesh.
Definition: xFileMesh.cxx:566
A single polygon.
Definition: eggPolygon.h:24
This represents a single vertex associated with an XFileFace.
Definition: xFileVertex.h:26
XFileDataNode * make_x_mesh(XFileNode *x_parent, const std::string &suffix)
Creates an X structure corresponding to the mesh.
Definition: xFileMesh.cxx:449
This represents a single face of an XFileMesh.
Definition: xFileFace.h:26
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:264
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents an X file "material", which consists of a color, lighting, and/or texture specificati...
Definition: xFileMaterial.h:31
This is an abstract base class for an XFileNode which is also an XFileDataObject.
Definition: xFileDataNode.h:33
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:406
bool has_materials() const
Returns true if any of the faces added to this mesh used a real material, false otherwise.
Definition: xFileMesh.cxx:424
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_num_materials() const
Returns the number of distinct materials associated with the mesh.
Definition: xFileMesh.cxx:432
XFileDataNode * make_x_normals(XFileNode *x_mesh, const std::string &suffix)
Creates a MeshNormals table for the mesh.
Definition: xFileMesh.cxx:506