15 #include "occluderNode.h" 18 #include "cullTraverserData.h" 19 #include "cullTraverser.h" 20 #include "renderState.h" 23 #include "textureAttrib.h" 24 #include "colorAttrib.h" 25 #include "depthOffsetAttrib.h" 26 #include "cullFaceAttrib.h" 27 #include "transparencyAttrib.h" 28 #include "transformState.h" 29 #include "cullableObject.h" 30 #include "cullHandler.h" 31 #include "boundingSphere.h" 32 #include "geomVertexData.h" 33 #include "geomTriangles.h" 34 #include "geomLinestrips.h" 35 #include "geomVertexWriter.h" 38 #include "datagramIterator.h" 39 #include "bamReader.h" 40 #include "bamWriter.h" 45 PT(
Texture) OccluderNode::_viz_tex;
58 OccluderNode(
const string &name) :
80 _double_sided(copy._double_sided),
81 _min_coverage(copy._min_coverage),
82 _vertices(copy._vertices)
131 for (Vertices::iterator vi = _vertices.begin();
132 vi != _vertices.end();
168 new CullableObject(get_occluder_viz(trav, data), get_occluder_viz_state(trav, data),
169 data.get_internal_transform(trav));
173 nassertr(_frame_viz != (
Geom *)NULL,
false);
176 data.get_internal_transform(trav));
209 PandaNode::output(out);
222 int &internal_vertices,
224 Thread *current_thread)
const {
231 if (!_vertices.empty()) {
232 const LPoint3 *vertices_begin = &_vertices[0];
233 const LPoint3 *vertices_end = vertices_begin + _vertices.size();
234 gbv->
around(vertices_begin, vertices_end);
237 internal_bounds = bound;
238 internal_vertices = 0;
247 PT(
Geom) OccluderNode::
249 if (_occluder_viz == (
Geom *)NULL) {
250 nassertr(_vertices.size() == 4, NULL);
252 if (pgraph_cat.is_debug()) {
254 <<
"Recomputing viz for " << *
this <<
"\n";
258 (get_name(), GeomVertexFormat::get_v3n3t2(), Geom::UH_static);
261 LPlane plane(_vertices[0], _vertices[1], _vertices[2]);
262 LVector3 poly_normal = plane.get_normal();
284 triangles->add_vertices(0, 1, 2);
285 triangles->close_primitive();
286 triangles->add_vertices(0, 2, 3);
287 triangles->close_primitive();
289 _occluder_viz =
new Geom(vdata);
290 _occluder_viz->add_primitive(triangles);
293 lines->add_vertices(0, 1, 2, 3);
294 lines->add_vertex(0);
295 lines->close_primitive();
297 _frame_viz =
new Geom(vdata);
298 _frame_viz->add_primitive(lines);
301 return _occluder_viz;
311 if (_viz_tex == NULL) {
315 _viz_tex =
new Texture(
"occluder_viz");
316 _viz_tex->setup_2d_texture(2, 2, Texture::T_unsigned_byte, Texture::F_luminance);
318 image.set_data(
"\x20\x80\x80\x20");
319 _viz_tex->set_ram_image(image);
320 _viz_tex->set_minfilter(SamplerState::FT_nearest);
321 _viz_tex->set_magfilter(SamplerState::FT_nearest);
325 if (viz_state == NULL) {
326 viz_state = RenderState::make
327 (ColorAttrib::make_flat(
LVecBase4(1.0f, 1.0f, 1.0f, 0.5f)),
328 TransparencyAttrib::make(TransparencyAttrib::M_alpha),
329 DepthOffsetAttrib::make(),
330 TextureAttrib::make(_viz_tex));
331 viz_state = viz_state->adjust_all_priorities(1);
336 state = viz_state->set_attrib(CullFaceAttrib::make(CullFaceAttrib::M_cull_none), 1);
338 state = viz_state->set_attrib(CullFaceAttrib::make(CullFaceAttrib::M_cull_clockwise), 1);
341 return state->compose(viz_state);
352 if (viz_state == NULL) {
353 viz_state = RenderState::make
354 (ColorAttrib::make_flat(
LVecBase4(0.0f, 0.0f, 0.0f, 1.0f)),
355 TextureAttrib::make_off());
356 viz_state = viz_state->adjust_all_priorities(1);
359 return data._state->compose(viz_state);
384 for (Vertices::const_iterator vi = _vertices.begin();
385 vi != _vertices.end();
387 (*vi).write_datagram(dg);
419 parse_params(params, scan, manager);
420 node->fillin(scan, manager);
434 PandaNode::fillin(scan, manager);
438 _vertices.reserve(num_vertices);
439 for (
int i = 0; i < num_vertices; i++) {
442 _vertices.push_back(vertex);
A basic node of the scene graph or data graph.
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
CullHandler * get_cull_handler() const
Returns the object that will receive the culled Geoms.
void set_vertices(const LPoint3 &v0, const LPoint3 &v1, const LPoint3 &v2, const LPoint3 &v3)
Replaces the four vertices of the occluder polygon.
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this node by the indicated matrix, if it means anything to do so...
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 void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
void read_datagram(DatagramIterator &source)
Reads the vector from the Datagram using get_stdfloat().
static void register_with_read_factory()
Tells the BamReader how to create objects of type OccluderNode.
void set_min_coverage(PN_stdfloat value)
Minimum screen coverage needed before occluder used.
void set_double_sided(bool value)
If true, the back-face will also be used to occlude.
This defines a bounding sphere, consisting of a center and a radius.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Base class for objects that can be written to and read from Bam files.
void add_data2(PN_stdfloat x, PN_stdfloat y)
Sets the write row to a particular 2-component value, and advances the write row. ...
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
A node in the scene graph that can hold an occluder polygon, which must be a rectangle.
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
The smallest atom of cull.
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 a 4-by-4 transform matrix.
virtual void record_object(CullableObject *object, const CullTraverser *traverser)
This callback function is intended to be overridden by a derived class.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void add_data3(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Sets the write row to a particular 3-component value, and advances the write row. ...
void set_overall_hidden(bool overall_hidden)
Sets or clears the hidden flag.
virtual void output(ostream &out) const
Writes a brief description of the node to the indicated output stream.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
virtual bool preserve_name() const
Returns true if the node's name has extrinsic meaning and must be preserved across a flatten operatio...
This is the base class for all three-component vectors and points.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
A thread; that is, a lightweight process.
static LPoint3f rfu(float right, float fwd, float up, CoordinateSystem cs=CS_default)
Returns a point described by right, forward, up displacements from the origin, wherever that maps to ...
Defines a series of line strips.
Defines a series of disconnected triangles.
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
A class to retrieve the individual data elements previously stored in a Datagram. ...
bool is_double_sided()
Is this occluder double-sided.
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
bool around(const GeometricBoundingVolume **first, const GeometricBoundingVolume **last)
Resets the volume to enclose only the volumes indicated.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...