Panda3D
eggNode.h
1 // Filename: eggNode.h
2 // Created by: drose (16Jan99)
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 EGGNODE_H
16 #define EGGNODE_H
17 
18 #include "pandabase.h"
19 
20 #include "eggNamedObject.h"
21 
22 #include "typedObject.h"
23 #include "lmatrix.h"
24 #include "pointerTo.h"
25 #include "referenceCount.h"
26 
27 class EggGroupNode;
28 class EggRenderMode;
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : EggNode
33 // Description : A base class for things that may be directly added
34 // into the egg hierarchy. This includes groups,
35 // joints, polygons, vertex pools, etc., but does not
36 // include things like vertices.
37 ////////////////////////////////////////////////////////////////////
38 class EXPCL_PANDAEGG EggNode : public EggNamedObject {
39 PUBLISHED:
40  INLINE EggNode(const string &name = "");
41  INLINE EggNode(const EggNode &copy);
42  INLINE EggNode &operator = (const EggNode &copy);
43 
44  INLINE EggGroupNode *get_parent() const;
45  INLINE int get_depth() const;
46  INLINE bool is_under_instance() const;
47  INLINE bool is_under_transform() const;
48  INLINE bool is_local_coord() const;
49 
50  INLINE const LMatrix4d &get_vertex_frame() const;
51  INLINE const LMatrix4d &get_node_frame() const;
52  INLINE const LMatrix4d &get_vertex_frame_inv() const;
53  INLINE const LMatrix4d &get_node_frame_inv() const;
54  INLINE const LMatrix4d &get_vertex_to_node() const;
55  INLINE const LMatrix4d &get_node_to_vertex() const;
56 
57  INLINE const LMatrix4d *get_vertex_frame_ptr()const;
58  INLINE const LMatrix4d *get_node_frame_ptr()const;
59  INLINE const LMatrix4d *get_vertex_frame_inv_ptr()const;
60  INLINE const LMatrix4d *get_node_frame_inv_ptr()const;
61  INLINE const LMatrix4d *get_vertex_to_node_ptr()const;
62  INLINE const LMatrix4d *get_node_to_vertex_ptr()const;
63 
64  INLINE void transform(const LMatrix4d &mat);
65  INLINE void transform_vertices_only(const LMatrix4d &mat);
66  INLINE void flatten_transforms();
67  void apply_texmats();
68 
69  int rename_node(vector_string strip_prefix);
70 
71  virtual bool is_joint() const;
72  virtual bool is_anim_matrix() const;
73 
74  virtual EggRenderMode *determine_alpha_mode();
75  virtual EggRenderMode *determine_depth_write_mode();
76  virtual EggRenderMode *determine_depth_test_mode();
77  virtual EggRenderMode *determine_visibility_mode();
78  virtual EggRenderMode *determine_depth_offset();
79  virtual EggRenderMode *determine_draw_order();
80  virtual EggRenderMode *determine_bin();
81  virtual bool determine_indexed();
82  virtual bool determine_decal();
83 
84  virtual void write(ostream &out, int indent_level) const=0;
85  bool parse_egg(const string &egg_syntax);
86 
87 #ifdef _DEBUG
88  void test_under_integrity() const;
89 #else
90  void test_under_integrity() const { }
91 #endif // _DEBUG
92 
93 
94 protected:
95  enum UnderFlags {
96  UF_under_instance = 0x001,
97  UF_under_transform = 0x002,
98  UF_local_coord = 0x004,
99  };
100 
101  virtual bool egg_start_parse_body();
102 
103  virtual void update_under(int depth_offset);
104  virtual void adjust_under();
105  virtual bool has_primitives() const;
106  virtual bool joint_has_primitives() const;
107  virtual bool has_normals() const;
108 
109  virtual void r_transform(const LMatrix4d &mat, const LMatrix4d &inv,
110  CoordinateSystem to_cs);
111  virtual void r_transform_vertices(const LMatrix4d &mat);
112  virtual void r_mark_coordsys(CoordinateSystem cs);
113  virtual void r_flatten_transforms();
114  virtual void r_apply_texmats(EggTextureCollection &textures);
115 
116  // These members are updated automatically by prepare_add_child(),
117  // prepare_remove_child(), and update_under(). Other functions
118  // shouldn't be fiddling with them.
119 
120  EggGroupNode *_parent;
121  int _depth;
122  int _under_flags;
123 
125 
126  PT(MatrixFrame) _vertex_frame;
127  PT(MatrixFrame) _node_frame;
128  PT(MatrixFrame) _vertex_frame_inv;
129  PT(MatrixFrame) _node_frame_inv;
130  PT(MatrixFrame) _vertex_to_node;
131  PT(MatrixFrame) _node_to_vertex;
132 
133 
134 public:
135 
136  static TypeHandle get_class_type() {
137  return _type_handle;
138  }
139  static void init_type() {
140  EggNamedObject::init_type();
141  register_type(_type_handle, "EggNode",
142  EggNamedObject::get_class_type());
143  MatrixFrame::init_type();
144  }
145  virtual TypeHandle get_type() const {
146  return get_class_type();
147  }
148  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
149 
150 private:
151  static TypeHandle _type_handle;
152 
153  friend class EggGroupNode;
154  friend class EggTable;
155 };
156 
157 #include "eggNode.I"
158 
159 #endif
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
This is a collection of textures by TRef name.
This class stores miscellaneous rendering properties that is associated with geometry, and which may be set on the geometry primitive level, on the group above it, or indirectly via a texture.
Definition: eggRenderMode.h:36
This corresponds to a.
Definition: eggTable.h:31
This is a fairly low-level base class–any egg object that has a name.
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:38
Another kind of proxy, similar to RefCountProxy.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85