15 #ifndef SPEEDTREENODE_H
16 #define SPEEDTREENODE_H
18 #include "pandabase.h"
19 #include "pandaNode.h"
20 #include "pointerTo.h"
22 #include "stTransform.h"
23 #include "stTerrain.h"
24 #include "callbackObject.h"
25 #include "loaderOptions.h"
26 #include "transformState.h"
28 #include "pStatCollector.h"
29 #include "randomizer.h"
30 #include "speedtree_api.h"
37 #if SPEEDTREE_VERSION_MAJOR > 5 || (SPEEDTREE_VERSION_MAJOR == 5 && SPEEDTREE_VERSION_MINOR >= 3)
38 #undef ST_DELETE_FOREST_HACK
40 #define ST_DELETE_FOREST_HACK
66 INLINE
bool operator < (
const InstanceList &other)
const;
69 INLINE
const STTree *get_tree()
const;
71 INLINE
int get_num_instances()
const;
73 MAKE_SEQ(get_instances, get_num_instances, get_instance);
74 INLINE
void set_instance(
int n,
const STTransform &transform);
76 INLINE
int add_instance(
const STTransform &transform);
77 INLINE
void remove_instance(
int n);
79 void output(ostream &out)
const;
80 void write(ostream &out,
int indent_level = 0)
const;
116 void add_instances(
const NodePath &root,
const TransformState *transform = TransformState::make_identity());
120 PN_stdfloat x_min, PN_stdfloat x_max,
121 PN_stdfloat y_min, PN_stdfloat y_max,
122 PN_stdfloat scale_min, PN_stdfloat scale_max,
123 PN_stdfloat height_min, PN_stdfloat height_max,
124 PN_stdfloat slope_min, PN_stdfloat slope_max,
150 static bool authorize(
const string &license =
"");
168 int &internal_vertices,
170 Thread *current_thread)
const;
172 virtual void output(ostream &out)
const;
173 virtual void write(ostream &out,
int indent_level)
const;
178 void set_transparent_texture_mode(SpeedTree::ETextureAlphaRenderMode eMode)
const;
182 void r_add_instances(
PandaNode *node,
const TransformState *transform,
186 void update_terrain_cells();
189 void render_forest_into_shadow_maps();
193 void print_forest_stats(
const SpeedTree::CForest::SPopulationStats &forest_stats)
const;
198 ALLOC_DELETED_CHAIN(DrawCallback);
209 static void init_type() {
210 CallbackObject::init_type();
211 register_type(_type_handle,
"SpeedTreeNode::DrawCallback",
212 CallbackObject::get_class_type());
215 return get_class_type();
217 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
224 string _os_shaders_dir;
230 #ifdef ST_DELETE_FOREST_HACK
231 SpeedTree::CForestRender &_forest_render;
233 SpeedTree::CForestRender _forest_render;
234 #endif // ST_DELETE_FOREST_HACK
235 SpeedTree::CView _view;
236 SpeedTree::SForestCullResultsRender _visible_trees;
237 SpeedTree::CForest::SPopulationStats _population_stats;
238 bool _needs_repopulate;
242 SpeedTree::CTerrainRender _terrain_render;
243 SpeedTree::STerrainCullResults _visible_terrain;
245 SpeedTree::Vec3 _light_dir;
251 SpeedTree::CView _light_view;
252 SpeedTree::SForestCullResultsRender _light_cull;
253 PN_stdfloat _shadow_split;
256 ShadowInfos _shadow_infos;
259 static double _global_time_delta;
261 static bool _authorized;
262 static bool _done_first_init;
286 static void init_type() {
287 PandaNode::init_type();
288 register_type(_type_handle,
"SpeedTreeNode",
289 PandaNode::get_class_type());
290 DrawCallback::init_type();
293 return get_class_type();
295 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
300 friend class SpeedTreeNode::DrawCallback;
304 instances.output(out);
308 #include "speedTreeNode.I"
const STTree * get_tree(int n) const
Returns the STTree pointer for the nth tree.
A basic node of the scene graph or data graph.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
int count_total_instances() const
Returns the total number of trees that will be rendered by this node, counting all instances of all t...
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...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
virtual PandaNode * combine_with(PandaNode *other)
Collapses this PandaNode with the other PandaNode, if possible, and returns a pointer to the combined...
Specifies parameters that may be passed to the loader.
static bool authorize(const string &license="")
Make this call to initialized the SpeedTree API and verify the license.
void add_instances(const NodePath &root, const TransformState *transform=TransformState::make_identity())
Walks the scene graph beginning at root, looking for nested SpeedTreeNodes.
Base class for objects that can be written to and read from Bam files.
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
void clear_terrain()
Removes the terrain associated with the node.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
bool setup_terrain(const Filename &terrain_file)
A convenience function to set up terrain geometry by reading a terrain.txt file as defined by SpeedTr...
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
int remove_tree(const STTree *tree)
Removes all instances of the indicated tree.
This is the abstract base class that defines the interface needed to describe a terrain for rendering...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
This is a generic data block that is passed along to a CallbackObject when a callback is made...
static double get_global_time_delta()
Returns an offset that is to be added each frame to the global clock's frame_time for the purpose of ...
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
STTree * modify_tree(int n)
Returns a modifiable STTree pointer for the nth tree instance.
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
static void set_global_time_delta(double delta)
Specifies an offset that is to be added each frame to the global clock's frame_time for the purpose o...
void set_time_delta(double delta)
Specifies an offset that is to be added each frame to the global clock's frame_time for the purpose o...
void snap_to_terrain()
Adjusts all the trees in this node so that their Z position matches the height of the terrain at thei...
bool has_instance_list(const STTree *tree) const
Returns true if the indicated tree has any instances within this node, false otherwise.
virtual void output(ostream &out) const
Writes a brief description of the node to the indicated output stream.
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
A lightweight class that represents a single element that may be timed and/or counted via stats...
virtual void compute_internal_bounds(CPT(BoundingVolume)&internal_bounds, int &internal_vertices, int pipeline_stage, Thread *current_thread) const
Returns a newly-allocated BoundingVolume that represents the internal contents of the node...
void set_terrain(STTerrain *terrain)
Associated a terrain with the node.
The name of a file, such as a texture file or an Egg file.
This class is used by the SceneGraphReducer to maintain and accumulate the set of attributes we have ...
void add_instance(const STTree *tree, const STTransform &transform)
Adds a new instance of the indicated tree at the indicated transform.
void remove_all_trees()
Removes all instances of all trees from the node.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
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, so that it will be drawn at render time.
STTerrain * get_terrain() const
Returns the terrain associated with the node, or NULL if there is no terrain.
Interfaces with the SpeedTree library to render SpeedTree objects, especially trees, within the Panda3D scene graph.
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
const InstanceList & get_instance_list(int n) const
Returns a list of transforms that corresponds to the instances at which the nth tree appears...
int get_num_trees() const
Returns the number of unique tree objects that have been added to the node.
bool has_terrain() const
Returns true if a valid terrain has been associated with the node, false otherwise.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
bool add_from_stf(const Filename &stf_filename, const LoaderOptions &options=LoaderOptions())
Opens and reads the named STF (SpeedTree Forest) file, and adds the SRT files named within as instanc...
double get_time_delta() const
Returns an offset that is to be added each frame to the global clock's frame_time for the purpose of ...
This is a generic object that can be assigned to a callback at various points in the rendering proces...
void reload_config()
Re-reads the current setting of all of the relevant config variables and applies them to this node...
bool is_valid() const
Returns true if the node is valid and ready to render, false otherwise.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A thread; that is, a lightweight process.
A handy class to return random numbers.
Encapsulates all the communication with a particular instance of a given rendering backend...
void add_instances_from(const SpeedTreeNode *other)
Adds all of the instances defined within the indicated SpeedTreeNode as instances of this node...
A class to retrieve the individual data elements previously stored in a Datagram. ...
InstanceList & modify_instance_list(const STTree *tree)
Returns a modifiable list of transforms that corresponds to the instances of this tree...
TypeHandle is the identifier used to differentiate C++ class types.
static void write_error(ostream &out)
Writes the current SpeedTree error message to the indicated stream.
void add_random_instances(const STTree *tree, int quantity, PN_stdfloat x_min, PN_stdfloat x_max, PN_stdfloat y_min, PN_stdfloat y_max, PN_stdfloat scale_min, PN_stdfloat scale_max, PN_stdfloat height_min, PN_stdfloat height_max, PN_stdfloat slope_min, PN_stdfloat slope_max, Randomizer &randomizer=Randomizer())
Creates a number of random instances of the indicated true, within the indicated range.
InstanceList & add_tree(const STTree *tree)
Adds a new tree for rendering.
void prepare_scene(GraphicsStateGuardianBase *gsg, const RenderState *node_state)
Walks through the scene graph beginning at this node, and does whatever initialization is required to...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Encapsulates a single tree model in the SpeedTree library, as loaded from an SRT file.
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
void set_wind(double strength, const LVector3 &direction)
Specifies the overall wind strength and direction.