Polylight API

This commit is contained in:
Shalin Shodhan 2004-06-14 18:43:05 +00:00
parent 5c2abc514d
commit 3887f5681a
10 changed files with 447 additions and 342 deletions

View File

@ -42,6 +42,7 @@
#include "sequenceNode.h"
#include "switchNode.h"
#include "portalNode.h"
#include "polylightNode.h"
#include "lodNode.h"
#include "modelNode.h"
#include "modelRoot.h"
@ -1626,7 +1627,24 @@ make_node(EggGroup *egg_group, PandaNode *parent) {
if (pnode->get_num_vertices() == 0) {
egg2pg_cat.warning()
<< "Portal " << egg_group->get_name() << " has no vertices!\n";
}
}
} else if (egg_group->get_polylight_flag()) {
// Create a polylight instead of a regular polyset.
// use make_sphere to get the center, radius and color
//egg2pg_cat.debug() << "polylight node\n";
LPoint3f center;
Colorf color;
float radius;
if(!make_sphere(egg_group,center,radius,color)) {
egg2pg_cat.warning()
<< "Polylight " << egg_group->get_name() << " make_sphere failed!\n";
}
PolylightNode *pnode = new PolylightNode(egg_group->get_name(),
center[0], center[1], center[2], color[0], color[1], color[2],
radius, "linear", false, "random");
node = pnode;
} else {
// A normal group; just create a normal node, and traverse.
@ -1832,7 +1850,7 @@ find_first_polygon(EggGroup *egg_group) {
// Polylight sphere. It could be used for other spheres.
////////////////////////////////////////////////////////////////////
bool EggLoader::
make_sphere(EggGroup *egg_group, LPoint3f &center, float &radius) {
make_sphere(EggGroup *egg_group, LPoint3f &center, float &radius, Colorf &color) {
bool success=false;
EggGroup *geom_group = find_collision_geometry(egg_group);
if (geom_group != (EggGroup *)NULL) {
@ -1863,6 +1881,7 @@ make_sphere(EggGroup *egg_group, LPoint3f &center, float &radius) {
if (num_vertices > 0) {
d_center /= (double)num_vertices;
//egg2pg_cat.debug() << "make_sphere d_center: " << d_center << "\n";
LMatrix4d mat = egg_group->get_vertex_to_node();
d_center = d_center * mat;
@ -1872,13 +1891,23 @@ make_sphere(EggGroup *egg_group, LPoint3f &center, float &radius) {
for (vi = vertices.begin(); vi != vertices.end(); ++vi) {
EggVertex *vtx = (*vi);
LPoint3d p3 = vtx->get_pos3();
LVector3d v = p3 * mat - d_center;
LVector3d v = p3 * mat - d_center;
radius2 = max(radius2, v.length_squared());
}
center = LCAST(float,d_center);
float radius = sqrtf(radius2);
radius = sqrtf(radius2);
//egg2pg_cat.debug() << "make_sphere radius: " << radius << "\n";
vi = vertices.begin();
EggVertex *clr_vtx = (*vi);
if (clr_vtx->has_color()) {
color = clr_vtx->get_color();
}
else {
color = Colorf(1.0,1.0,1.0,1.0);
}
success = true;
}
}
return success;
@ -2015,7 +2044,8 @@ make_collision_sphere(EggGroup *egg_group, CollisionNode *cnode,
EggGroup::CollideFlags flags) {
LPoint3f center;
float radius;
if (make_sphere(egg_group, center, radius)) {
Colorf dummycolor;
if (make_sphere(egg_group, center, radius, dummycolor)) {
CollisionSphere *cssphere =
new CollisionSphere(center, radius);
apply_collision_flags(cssphere, flags);
@ -2479,6 +2509,9 @@ expand_object_types(EggGroup *egg_group, const pset<string> &expanded,
// Ignorable group; stop here.
return false;
}
//else
//egg2pg_cat.debug() << "returned true\n";
}
}
@ -2551,6 +2584,7 @@ do_expand_object_type(EggGroup *egg_group, const pset<string> &expanded,
egg2pg_cat.error()
<< "Unknown ObjectType " << object_type << "\n";
_error = true;
egg2pg_cat.debug() << "returning true\n";
return true;
}
}

View File

@ -52,6 +52,7 @@ class CollisionNode;
class CollisionPlane;
class CollisionPolygon;
class PortalNode;
class PolylightNode;
///////////////////////////////////////////////////////////////////
// Class : EggLoader
@ -113,7 +114,7 @@ private:
void set_portal_polygon(EggGroup *egg_group, PortalNode *pnode);
EggPolygon *find_first_polygon(EggGroup *egg_group);
bool make_sphere(EggGroup *start_group, LPoint3f &center, float &radius);
bool make_sphere(EggGroup *start_group, LPoint3f &center, float &radius, Colorf &color);
void make_collision_solids(EggGroup *start_group, EggGroup *egg_group,
CollisionNode *cnode);

View File

@ -69,6 +69,8 @@
pandaNode.I pandaNode.h \
planeNode.I planeNode.h \
pointLight.I pointLight.h \
polylightNode.I polylightNode.h \
polylightEffect.I polylightEffect.h \
portalNode.I portalNode.h \
portalClipper.I portalClipper.h \
renderAttrib.I renderAttrib.h \
@ -155,6 +157,8 @@
pandaNode.cxx \
planeNode.cxx \
pointLight.cxx \
polylightNode.cxx \
polylightEffect.cxx \
portalNode.cxx \
portalClipper.cxx \
renderAttrib.cxx \
@ -237,6 +241,8 @@
pandaNode.I pandaNode.h \
planeNode.I planeNode.h \
pointLight.I pointLight.h \
polylightNode.I polylightNode.h \
polylightEffect.I polylightEffect.h \
portalNode.I portalNode.h \
portalClipper.I portalClipper.h \
renderAttrib.I renderAttrib.h \

View File

@ -62,6 +62,8 @@
#include "pandaNode.h"
#include "planeNode.h"
#include "pointLight.h"
#include "polylightNode.h"
#include "polylightEffect.h"
#include "portalNode.h"
#include "portalClipper.h"
#include "renderAttrib.h"
@ -203,12 +205,15 @@ init_libpgraph() {
LoaderFileTypeBam::init_type();
MaterialAttrib::init_type();
ModelNode::init_type();
ModelRoot::init_type();
NodePath::init_type();
NodePathComponent::init_type();
PandaNode::init_type();
PlaneNode::init_type();
PointLight::init_type();
PolylightNode::init_type();
PolylightEffect::init_type();
PortalNode::init_type();
PortalClipper::init_type();
RenderAttrib::init_type();

View File

@ -18,14 +18,15 @@
#include "cullTraverserData.h"
#include "cullTraverser.h"
#include "config_pgraph.h"
#include "pandaNode.h"
#include "colorAttrib.h"
#include "config_pgraph.h"
#include "textureAttrib.h"
#include "renderModeAttrib.h"
#include "billboardEffect.h"
#include "compassEffect.h"
#include "polylightEffect.h"
#include "renderState.h"
////////////////////////////////////////////////////////////////////
// Function: CullTraverserData::apply_specific_transform
// Access: Public
@ -42,20 +43,33 @@ apply_transform_and_state(CullTraverser *trav,
// compass and billboard effects.
_net_transform = _net_transform->compose(node_transform);
const CompassEffect *compass = node_effects->get_compass();
if (compass != (const CompassEffect *)NULL) {
CPT(TransformState) compass_transform =
compass->do_compass(_net_transform, node_transform);
_net_transform = _net_transform->compose(compass_transform);
node_transform = node_transform->compose(compass_transform);
}
if (!node_effects->is_empty()) {
const CompassEffect *compass = node_effects->get_compass();
if (compass != (const CompassEffect *)NULL) {
CPT(TransformState) compass_transform =
compass->do_compass(_net_transform, node_transform);
_net_transform = _net_transform->compose(compass_transform);
node_transform = node_transform->compose(compass_transform);
}
const BillboardEffect *billboard = node_effects->get_billboard();
if (billboard != (const BillboardEffect *)NULL) {
CPT(TransformState) billboard_transform =
billboard->do_billboard(_net_transform, trav->get_camera_transform());
_net_transform = _net_transform->compose(billboard_transform);
node_transform = node_transform->compose(billboard_transform);
}
const PolylightEffect *poly_light = node_effects->get_polylight();
if(poly_light != (const PolylightEffect *) NULL) {
if(poly_light->is_enabled()) {
CPT(RenderAttrib) poly_light_attrib = poly_light->do_poly_light( this , node_transform);
CPT(RenderState) poly_light_state=RenderState::make(poly_light_attrib);
node_state=node_state->compose(poly_light_state);
}
}
const BillboardEffect *billboard = node_effects->get_billboard();
if (billboard != (const BillboardEffect *)NULL) {
CPT(TransformState) billboard_transform =
billboard->do_billboard(_net_transform, trav->get_camera_transform());
_net_transform = _net_transform->compose(billboard_transform);
node_transform = node_transform->compose(billboard_transform);
}
if (!node_transform->is_identity()) {

View File

@ -18,6 +18,8 @@
#include "pandaNode.cxx"
#include "planeNode.cxx"
#include "pointLight.cxx"
#include "polylightNode.cxx"
#include "polylightEffect.cxx"
#include "portalNode.cxx"
#include "portalClipper.cxx"
#include "renderAttrib.cxx"

View File

@ -200,6 +200,25 @@ get_compass() const {
return _compass;
}
////////////////////////////////////////////////////////////////////
// Function: RenderEffects::get_polylight
// Access: Public
// Description: This function is provided as an optimization, to
// speed up the render-time checking for the existance
// of a PolylightEffect on this state. It returns a
// pointer to the PolylightEffect, if there is one, or
// NULL if there is not.
////////////////////////////////////////////////////////////////////
INLINE const PolylightEffect *RenderEffects::
get_polylight() const {
if ((_flags & F_checked_polylight) == 0) {
// We pretend this function is const, even though it transparently
// modifies the internal polylight cache.
((RenderEffects *)this)->determine_polylight();
}
return _polylight;
}
////////////////////////////////////////////////////////////////////
// Function: RenderEffects::has_show_bounds
// Access: Public

View File

@ -20,6 +20,7 @@
#include "billboardEffect.h"
#include "decalEffect.h"
#include "compassEffect.h"
#include "polylightEffect.h"
#include "showBoundsEffect.h"
#include "config_pgraph.h"
#include "bamReader.h"
@ -476,6 +477,23 @@ determine_compass() {
_flags |= F_checked_compass;
}
////////////////////////////////////////////////////////////////////
// Function: RenderEffects::determine_polylight
// Access: Private
// Description: This is the private implementation of has_polylight().
////////////////////////////////////////////////////////////////////
void RenderEffects::
determine_polylight() {
const RenderEffect *effect = get_effect(PolylightEffect::get_class_type());
_polylight = (const PolylightEffect *)NULL;
if (effect != (const RenderEffect *)NULL) {
_polylight = DCAST(PolylightEffect, effect);
}
_flags |= F_checked_polylight;
}
////////////////////////////////////////////////////////////////////
// Function: RenderEffects::determine_show_bounds
// Access: Private

View File

@ -29,6 +29,7 @@
class BillboardEffect;
class CompassEffect;
class PolylightEffect;
class FactoryParams;
////////////////////////////////////////////////////////////////////
@ -91,6 +92,7 @@ public:
INLINE const BillboardEffect *get_billboard() const;
INLINE bool has_decal() const;
INLINE const CompassEffect *get_compass() const;
INLINE const PolylightEffect *get_polylight() const;
INLINE bool has_show_bounds() const;
private:
@ -98,6 +100,7 @@ private:
void determine_billboard();
void determine_decal();
void determine_compass();
void determine_polylight();
void determine_show_bounds();
private:
@ -133,6 +136,7 @@ private:
// state, if they exist.
const BillboardEffect *_billboard;
const CompassEffect *_compass;
const PolylightEffect *_polylight;
enum Flags {
F_checked_billboard = 0x0001,
@ -141,9 +145,11 @@ private:
F_checked_show_bounds = 0x0008,
F_has_show_bounds = 0x0010,
F_checked_compass = 0x0020,
F_checked_polylight = 0x0040,
};
short _flags;
public:
static void register_with_read_factory();
virtual void write_datagram(BamWriter *manager, Datagram &dg);