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"
63 set_overall_hidden(
true);
64 set_double_sided(
false);
65 set_min_coverage(0.0);
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;
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();
267 vertex.add_data3(_vertices[0]);
268 normal.add_data3(poly_normal);
269 texcoord.add_data2(0.0, 0.0);
271 vertex.add_data3(_vertices[1]);
272 normal.add_data3(poly_normal);
273 texcoord.add_data2(8.0, 0.0);
275 vertex.add_data3(_vertices[2]);
276 normal.add_data3(poly_normal);
277 texcoord.add_data2(8.0, 8.0);
279 vertex.add_data3(_vertices[3]);
280 normal.add_data3(poly_normal);
281 texcoord.add_data2(0.0, 8.0);
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);
335 if (is_double_sided()) {
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...
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...
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.
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.
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 ...
virtual bool preserve_name() const
Returns true if the node's name has extrinsic meaning and must be preserved across a flatten operatio...
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...
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
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.
CullHandler * get_cull_handler() const
Returns the object that will receive the culled Geoms.
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...
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.
This is the base class for all three-component vectors and points.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
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.
A class to retrieve the individual data elements previously stored in a Datagram. ...
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 ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...