Panda3D
Loading...
Searching...
No Matches
geomNode.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 geomNode.h
10 * @author drose
11 * @date 2002-02-22
12 */
13
14#ifndef GEOMNODE_H
15#define GEOMNODE_H
16
17#include "pandabase.h"
18#include "config_pgraph.h"
19#include "pandaNode.h"
20#include "pointerToArray.h"
21#include "geom.h"
22#include "pipelineCycler.h"
23#include "cycleData.h"
24#include "pvector.h"
25#include "copyOnWritePointer.h"
26
28
29/**
30 * A node that holds Geom objects, renderable pieces of geometry. This is the
31 * primary kind of leaf node in the scene graph; almost all visible objects
32 * will be contained in a GeomNode somewhere.
33 */
34class EXPCL_PANDA_PGRAPH GeomNode : public PandaNode {
35PUBLISHED:
36 explicit GeomNode(const std::string &name);
37
38protected:
39 GeomNode(const GeomNode &copy);
40public:
41 virtual ~GeomNode();
42 virtual PandaNode *make_copy() const;
43 virtual void apply_attribs_to_vertices(const AccumulatedAttribs &attribs,
44 int attrib_types,
45 GeomTransformer &transformer);
46 virtual void xform(const LMatrix4 &mat);
47 virtual PandaNode *combine_with(PandaNode *other);
48 virtual CPT(TransformState)
49 calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point,
50 bool &found_any,
51 const TransformState *transform,
52 Thread *current_thread) const;
53 virtual bool is_renderable() const;
54 virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data);
55 virtual CollideMask get_legal_collide_mask() const;
56
57 virtual bool safe_to_flatten() const;
58 virtual bool safe_to_combine() const;
59
61 const RenderState *node_state,
62 GeomTransformer &transformer,
63 Thread *current_thread);
64
65PUBLISHED:
66 INLINE void set_preserved(bool value);
67 INLINE bool get_preserved() const;
68
69 INLINE int get_num_geoms() const;
70 INLINE CPT(Geom) get_geom(int n) const;
71 MAKE_SEQ(get_geoms, get_num_geoms, get_geom);
72 INLINE PT(Geom) modify_geom(int n);
73 MAKE_SEQ(modify_geoms, get_num_geoms, modify_geom);
74 INLINE const RenderState *get_geom_state(int n) const;
75 MAKE_SEQ(get_geom_states, get_num_geoms, get_geom_state);
76 INLINE void set_geom_state(int n, const RenderState *state);
77
78 void add_geom(Geom *geom, const RenderState *state = RenderState::make_empty());
79 void add_geoms_from(const GeomNode *other);
80 void set_geom(int n, Geom *geom);
81 INLINE void remove_geom(int n);
82 INLINE void remove_all_geoms();
83 bool check_valid() const;
84
85 void decompose();
86 void unify(int max_indices, bool preserve_order);
87
88 void write_geoms(std::ostream &out, int indent_level) const;
89 void write_verbose(std::ostream &out, int indent_level) const;
90
91 INLINE static CollideMask get_default_collide_mask();
92 MAKE_PROPERTY(default_collide_mask, get_default_collide_mask);
93
94public:
95 virtual void output(std::ostream &out) const;
96
97 virtual bool is_geom_node() const;
98
100 const RenderState *node_state,
101 GeomTransformer &transformer);
102
103protected:
104 virtual void r_mark_geom_bounds_stale(Thread *current_thread);
105 virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
106 int &internal_vertices,
107 int pipeline_stage,
108 Thread *current_thread) const;
109
110public:
111 // This must be declared public so that VC6 will allow the nested CData
112 // class to access it.
113 class GeomEntry {
114 public:
115 INLINE GeomEntry(Geom *geom, const RenderState *state);
116 COWPT(Geom) _geom;
117 CPT(RenderState) _state;
118 };
119
120 typedef CopyOnWriteObj< pvector<GeomEntry> > GeomList;
121
122private:
123
124 bool _preserved;
125 typedef pmap<const InternalName *, int> NameCount;
126
127 INLINE void count_name(NameCount &name_count, const InternalName *name);
128 INLINE int get_name_count(const NameCount &name_count, const InternalName *name);
129
130 // This is the data that must be cycled between pipeline stages.
131 class EXPCL_PANDA_PGRAPH CData : public CycleData {
132 public:
133 INLINE CData();
134 CData(const CData &copy);
135 virtual CycleData *make_copy() const;
136 virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
137 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
138 virtual void fillin(DatagramIterator &scan, BamReader *manager);
139 virtual TypeHandle get_parent_type() const {
140 return GeomNode::get_class_type();
141 }
142
143 INLINE CPT(GeomList) get_geoms() const;
144 INLINE PT(GeomList) modify_geoms();
145 INLINE void set_geoms(GeomList *geoms);
146
147 private:
148 COWPT(GeomList) _geoms;
149 };
150
151 PipelineCycler<CData> _cycler;
152 typedef CycleDataReader<CData> CDReader;
153 typedef CycleDataWriter<CData> CDWriter;
154 typedef CycleDataStageReader<CData> CDStageReader;
155 typedef CycleDataLockedStageReader<CData> CDLockedStageReader;
156 typedef CycleDataStageWriter<CData> CDStageWriter;
157
158public:
159 // This class is returned from get_geoms(). It is similar to
160 // PandaNode::get_children(); use this to walk through the list of geoms
161 // faster than walking through the geoms directly from the node.
162 class EXPCL_PANDA_PGRAPH Geoms {
163 public:
164 INLINE Geoms();
165 INLINE Geoms(const CData *cdata);
166 INLINE Geoms(const Geoms &copy);
167 INLINE Geoms(Geoms &&from) noexcept;
168
169 INLINE void operator = (const Geoms &copy);
170 INLINE void operator = (Geoms &&from) noexcept;
171
172 INLINE int get_num_geoms() const;
173 INLINE CPT(Geom) get_geom(int n) const;
174 INLINE const RenderState *get_geom_state(int n) const;
175
176 private:
177 CPT(GeomList) _geoms;
178 };
179
180 INLINE Geoms get_geoms(Thread *current_thread = Thread::get_current_thread()) const;
181
182 // This data is only needed when reading from a bam file.
184 public:
185 // We just hold a pointer to the RenderState that may otherwise lose its
186 // pointers before it can finalize.
187 CPT(RenderState) _hold_state;
188 };
189
190public:
191 static void register_with_read_factory();
192 virtual void write_datagram(BamWriter *manager, Datagram &dg);
193
194 virtual void finalize(BamReader *manager);
195
196protected:
197 static TypedWritable *make_from_bam(const FactoryParams &params);
198 void fillin(DatagramIterator &scan, BamReader *manager);
199
200public:
201 static TypeHandle get_class_type() {
202 return _type_handle;
203 }
204 static void init_type() {
205 GeomList::init_type();
206 PandaNode::init_type();
207 register_type(_type_handle, "GeomNode",
208 PandaNode::get_class_type());
209 }
210 virtual TypeHandle get_type() const {
211 return get_class_type();
212 }
213 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
214
215private:
216 static TypeHandle _type_handle;
217
218 friend class GeomTransformer;
219};
220
221#include "geomNode.I"
222
223#endif
This class is used by the SceneGraphReducer to maintain and accumulate the set of attributes we have ...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
This is similar to RefCountObj, but it implements a CopyOnWriteObject inheritance instead of a Refere...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
A single page of data maintained by a PipelineCycler.
Definition cycleData.h:50
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
int get_num_geoms() const
Returns the number of geoms of the node.
Definition geomNode.I:279
void add_geoms_from(const GeomNode *other)
Copies the Geoms (and their associated RenderStates) from the indicated GeomNode into this one.
Definition geomNode.cxx:633
void do_premunge(GraphicsStateGuardianBase *gsg, const RenderState *node_state, GeomTransformer &transformer)
Uses the indicated GSG to premunge the Geoms in this node to optimize them for eventual rendering.
Definition geomNode.cxx:892
void write_geoms(std::ostream &out, int indent_level) const
Writes a short description of all the Geoms in the node.
Definition geomNode.cxx:811
void add_geom(Geom *geom, const RenderState *state=RenderState::make_empty())
Adds a new Geom to the node.
Definition geomNode.cxx:612
get_num_geoms
Returns the number of geoms in the node.
Definition geomNode.h:71
Geoms get_geoms(Thread *current_thread=Thread::get_current_thread()) const
Returns an object that can be used to walk through the list of geoms of the node.
Definition geomNode.I:177
void unify(int max_indices, bool preserve_order)
Attempts to unify all of the Geoms contained within this node into a single Geom, or at least as few ...
Definition geomNode.cxx:740
void remove_all_geoms()
Removes all the geoms from the node at once.
Definition geomNode.I:126
void remove_geom(int n)
Removes the nth geom from the node.
Definition geomNode.I:113
get_geom_state
Returns the RenderState associated with the nth geom of the node.
Definition geomNode.h:75
void set_geom(int n, Geom *geom)
Replaces the nth Geom of the node with a new pointer.
Definition geomNode.cxx:663
get_default_collide_mask
Returns the default into_collide_mask assigned to new GeomNodes.
Definition geomNode.h:92
void write_verbose(std::ostream &out, int indent_level) const
Writes a detailed description of all the Geoms in the node.
Definition geomNode.cxx:827
void set_geom_state(int n, const RenderState *state)
Changes the RenderState associated with the nth geom of the node.
Definition geomNode.I:102
void set_preserved(bool value)
Sets the "preserved" flag.
Definition geomNode.I:19
bool check_valid() const
Verifies that the each Geom within the GeomNode reference vertices that actually exist within its Geo...
Definition geomNode.cxx:681
void decompose()
Calls decompose() on each Geom with the GeomNode.
Definition geomNode.cxx:704
bool get_preserved() const
Returns the "preserved" flag.
Definition geomNode.I:28
A container for geometry primitives.
Definition geom.h:54
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Encodes a string name in a hash table, mapping it to a pointer.
virtual bool is_geom_node() const
A simple downcast check.
virtual PandaNode * combine_with(PandaNode *other)
Collapses this PandaNode with the other PandaNode, if possible, and returns a pointer to the combined...
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
get_legal_collide_mask
Returns the subset of CollideMask bits that may be set for this particular type of PandaNode.
Definition pandaNode.h:265
virtual void r_prepare_scene(GraphicsStateGuardianBase *gsg, const RenderState *node_state, GeomTransformer &transformer, Thread *current_thread)
The recursive implementation of prepare_scene().
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so.
virtual void apply_attribs_to_vertices(const AccumulatedAttribs &attribs, int attrib_types, GeomTransformer &transformer)
Applies whatever attributes are specified in the AccumulatedAttribs object (and by the attrib_types b...
virtual ConstPointerTo< TransformState > calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point, bool &found_any, const TransformState *transform, Thread *current_thread=Thread::get_current_thread()) const
This is used to support NodePath::calc_tight_bounds().
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data)
Adds the node's contents to the CullResult we are building up during the cull traversal,...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual bool safe_to_flatten() const
Returns true if it is generally safe to flatten out this particular kind of PandaNode by duplicating ...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition renderState.h:47
A thread; that is, a lightweight process.
Definition thread.h:46
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition thread.h:109
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
This is our own Panda specialization on the default STL list.
Definition plist.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...