mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 17:35:34 -04:00
Polylight API
This commit is contained in:
parent
5c2abc514d
commit
3887f5681a
@ -42,6 +42,7 @@
|
|||||||
#include "sequenceNode.h"
|
#include "sequenceNode.h"
|
||||||
#include "switchNode.h"
|
#include "switchNode.h"
|
||||||
#include "portalNode.h"
|
#include "portalNode.h"
|
||||||
|
#include "polylightNode.h"
|
||||||
#include "lodNode.h"
|
#include "lodNode.h"
|
||||||
#include "modelNode.h"
|
#include "modelNode.h"
|
||||||
#include "modelRoot.h"
|
#include "modelRoot.h"
|
||||||
@ -1626,7 +1627,24 @@ make_node(EggGroup *egg_group, PandaNode *parent) {
|
|||||||
if (pnode->get_num_vertices() == 0) {
|
if (pnode->get_num_vertices() == 0) {
|
||||||
egg2pg_cat.warning()
|
egg2pg_cat.warning()
|
||||||
<< "Portal " << egg_group->get_name() << " has no vertices!\n";
|
<< "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 {
|
} else {
|
||||||
// A normal group; just create a normal node, and traverse.
|
// 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.
|
// Polylight sphere. It could be used for other spheres.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool EggLoader::
|
bool EggLoader::
|
||||||
make_sphere(EggGroup *egg_group, LPoint3f ¢er, float &radius) {
|
make_sphere(EggGroup *egg_group, LPoint3f ¢er, float &radius, Colorf &color) {
|
||||||
bool success=false;
|
bool success=false;
|
||||||
EggGroup *geom_group = find_collision_geometry(egg_group);
|
EggGroup *geom_group = find_collision_geometry(egg_group);
|
||||||
if (geom_group != (EggGroup *)NULL) {
|
if (geom_group != (EggGroup *)NULL) {
|
||||||
@ -1863,6 +1881,7 @@ make_sphere(EggGroup *egg_group, LPoint3f ¢er, float &radius) {
|
|||||||
|
|
||||||
if (num_vertices > 0) {
|
if (num_vertices > 0) {
|
||||||
d_center /= (double)num_vertices;
|
d_center /= (double)num_vertices;
|
||||||
|
//egg2pg_cat.debug() << "make_sphere d_center: " << d_center << "\n";
|
||||||
|
|
||||||
LMatrix4d mat = egg_group->get_vertex_to_node();
|
LMatrix4d mat = egg_group->get_vertex_to_node();
|
||||||
d_center = d_center * mat;
|
d_center = d_center * mat;
|
||||||
@ -1872,13 +1891,23 @@ make_sphere(EggGroup *egg_group, LPoint3f ¢er, float &radius) {
|
|||||||
for (vi = vertices.begin(); vi != vertices.end(); ++vi) {
|
for (vi = vertices.begin(); vi != vertices.end(); ++vi) {
|
||||||
EggVertex *vtx = (*vi);
|
EggVertex *vtx = (*vi);
|
||||||
LPoint3d p3 = vtx->get_pos3();
|
LPoint3d p3 = vtx->get_pos3();
|
||||||
LVector3d v = p3 * mat - d_center;
|
LVector3d v = p3 * mat - d_center;
|
||||||
radius2 = max(radius2, v.length_squared());
|
radius2 = max(radius2, v.length_squared());
|
||||||
}
|
}
|
||||||
|
|
||||||
center = LCAST(float,d_center);
|
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;
|
success = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
@ -2015,7 +2044,8 @@ make_collision_sphere(EggGroup *egg_group, CollisionNode *cnode,
|
|||||||
EggGroup::CollideFlags flags) {
|
EggGroup::CollideFlags flags) {
|
||||||
LPoint3f center;
|
LPoint3f center;
|
||||||
float radius;
|
float radius;
|
||||||
if (make_sphere(egg_group, center, radius)) {
|
Colorf dummycolor;
|
||||||
|
if (make_sphere(egg_group, center, radius, dummycolor)) {
|
||||||
CollisionSphere *cssphere =
|
CollisionSphere *cssphere =
|
||||||
new CollisionSphere(center, radius);
|
new CollisionSphere(center, radius);
|
||||||
apply_collision_flags(cssphere, flags);
|
apply_collision_flags(cssphere, flags);
|
||||||
@ -2479,6 +2509,9 @@ expand_object_types(EggGroup *egg_group, const pset<string> &expanded,
|
|||||||
// Ignorable group; stop here.
|
// Ignorable group; stop here.
|
||||||
return false;
|
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()
|
egg2pg_cat.error()
|
||||||
<< "Unknown ObjectType " << object_type << "\n";
|
<< "Unknown ObjectType " << object_type << "\n";
|
||||||
_error = true;
|
_error = true;
|
||||||
|
egg2pg_cat.debug() << "returning true\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ class CollisionNode;
|
|||||||
class CollisionPlane;
|
class CollisionPlane;
|
||||||
class CollisionPolygon;
|
class CollisionPolygon;
|
||||||
class PortalNode;
|
class PortalNode;
|
||||||
|
class PolylightNode;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////
|
||||||
// Class : EggLoader
|
// Class : EggLoader
|
||||||
@ -113,7 +114,7 @@ private:
|
|||||||
void set_portal_polygon(EggGroup *egg_group, PortalNode *pnode);
|
void set_portal_polygon(EggGroup *egg_group, PortalNode *pnode);
|
||||||
EggPolygon *find_first_polygon(EggGroup *egg_group);
|
EggPolygon *find_first_polygon(EggGroup *egg_group);
|
||||||
|
|
||||||
bool make_sphere(EggGroup *start_group, LPoint3f ¢er, float &radius);
|
bool make_sphere(EggGroup *start_group, LPoint3f ¢er, float &radius, Colorf &color);
|
||||||
|
|
||||||
void make_collision_solids(EggGroup *start_group, EggGroup *egg_group,
|
void make_collision_solids(EggGroup *start_group, EggGroup *egg_group,
|
||||||
CollisionNode *cnode);
|
CollisionNode *cnode);
|
||||||
|
@ -69,6 +69,8 @@
|
|||||||
pandaNode.I pandaNode.h \
|
pandaNode.I pandaNode.h \
|
||||||
planeNode.I planeNode.h \
|
planeNode.I planeNode.h \
|
||||||
pointLight.I pointLight.h \
|
pointLight.I pointLight.h \
|
||||||
|
polylightNode.I polylightNode.h \
|
||||||
|
polylightEffect.I polylightEffect.h \
|
||||||
portalNode.I portalNode.h \
|
portalNode.I portalNode.h \
|
||||||
portalClipper.I portalClipper.h \
|
portalClipper.I portalClipper.h \
|
||||||
renderAttrib.I renderAttrib.h \
|
renderAttrib.I renderAttrib.h \
|
||||||
@ -155,6 +157,8 @@
|
|||||||
pandaNode.cxx \
|
pandaNode.cxx \
|
||||||
planeNode.cxx \
|
planeNode.cxx \
|
||||||
pointLight.cxx \
|
pointLight.cxx \
|
||||||
|
polylightNode.cxx \
|
||||||
|
polylightEffect.cxx \
|
||||||
portalNode.cxx \
|
portalNode.cxx \
|
||||||
portalClipper.cxx \
|
portalClipper.cxx \
|
||||||
renderAttrib.cxx \
|
renderAttrib.cxx \
|
||||||
@ -237,6 +241,8 @@
|
|||||||
pandaNode.I pandaNode.h \
|
pandaNode.I pandaNode.h \
|
||||||
planeNode.I planeNode.h \
|
planeNode.I planeNode.h \
|
||||||
pointLight.I pointLight.h \
|
pointLight.I pointLight.h \
|
||||||
|
polylightNode.I polylightNode.h \
|
||||||
|
polylightEffect.I polylightEffect.h \
|
||||||
portalNode.I portalNode.h \
|
portalNode.I portalNode.h \
|
||||||
portalClipper.I portalClipper.h \
|
portalClipper.I portalClipper.h \
|
||||||
renderAttrib.I renderAttrib.h \
|
renderAttrib.I renderAttrib.h \
|
||||||
|
@ -62,6 +62,8 @@
|
|||||||
#include "pandaNode.h"
|
#include "pandaNode.h"
|
||||||
#include "planeNode.h"
|
#include "planeNode.h"
|
||||||
#include "pointLight.h"
|
#include "pointLight.h"
|
||||||
|
#include "polylightNode.h"
|
||||||
|
#include "polylightEffect.h"
|
||||||
#include "portalNode.h"
|
#include "portalNode.h"
|
||||||
#include "portalClipper.h"
|
#include "portalClipper.h"
|
||||||
#include "renderAttrib.h"
|
#include "renderAttrib.h"
|
||||||
@ -203,12 +205,15 @@ init_libpgraph() {
|
|||||||
LoaderFileTypeBam::init_type();
|
LoaderFileTypeBam::init_type();
|
||||||
MaterialAttrib::init_type();
|
MaterialAttrib::init_type();
|
||||||
ModelNode::init_type();
|
ModelNode::init_type();
|
||||||
|
|
||||||
ModelRoot::init_type();
|
ModelRoot::init_type();
|
||||||
NodePath::init_type();
|
NodePath::init_type();
|
||||||
NodePathComponent::init_type();
|
NodePathComponent::init_type();
|
||||||
PandaNode::init_type();
|
PandaNode::init_type();
|
||||||
PlaneNode::init_type();
|
PlaneNode::init_type();
|
||||||
PointLight::init_type();
|
PointLight::init_type();
|
||||||
|
PolylightNode::init_type();
|
||||||
|
PolylightEffect::init_type();
|
||||||
PortalNode::init_type();
|
PortalNode::init_type();
|
||||||
PortalClipper::init_type();
|
PortalClipper::init_type();
|
||||||
RenderAttrib::init_type();
|
RenderAttrib::init_type();
|
||||||
|
@ -18,14 +18,15 @@
|
|||||||
|
|
||||||
#include "cullTraverserData.h"
|
#include "cullTraverserData.h"
|
||||||
#include "cullTraverser.h"
|
#include "cullTraverser.h"
|
||||||
|
#include "config_pgraph.h"
|
||||||
#include "pandaNode.h"
|
#include "pandaNode.h"
|
||||||
#include "colorAttrib.h"
|
#include "colorAttrib.h"
|
||||||
#include "config_pgraph.h"
|
|
||||||
#include "textureAttrib.h"
|
#include "textureAttrib.h"
|
||||||
#include "renderModeAttrib.h"
|
#include "renderModeAttrib.h"
|
||||||
#include "billboardEffect.h"
|
#include "billboardEffect.h"
|
||||||
#include "compassEffect.h"
|
#include "compassEffect.h"
|
||||||
|
#include "polylightEffect.h"
|
||||||
|
#include "renderState.h"
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CullTraverserData::apply_specific_transform
|
// Function: CullTraverserData::apply_specific_transform
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -42,20 +43,33 @@ apply_transform_and_state(CullTraverser *trav,
|
|||||||
// compass and billboard effects.
|
// compass and billboard effects.
|
||||||
_net_transform = _net_transform->compose(node_transform);
|
_net_transform = _net_transform->compose(node_transform);
|
||||||
|
|
||||||
const CompassEffect *compass = node_effects->get_compass();
|
if (!node_effects->is_empty()) {
|
||||||
if (compass != (const CompassEffect *)NULL) {
|
const CompassEffect *compass = node_effects->get_compass();
|
||||||
CPT(TransformState) compass_transform =
|
if (compass != (const CompassEffect *)NULL) {
|
||||||
compass->do_compass(_net_transform, node_transform);
|
CPT(TransformState) compass_transform =
|
||||||
_net_transform = _net_transform->compose(compass_transform);
|
compass->do_compass(_net_transform, node_transform);
|
||||||
node_transform = node_transform->compose(compass_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()) {
|
if (!node_transform->is_identity()) {
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
#include "pandaNode.cxx"
|
#include "pandaNode.cxx"
|
||||||
#include "planeNode.cxx"
|
#include "planeNode.cxx"
|
||||||
#include "pointLight.cxx"
|
#include "pointLight.cxx"
|
||||||
|
#include "polylightNode.cxx"
|
||||||
|
#include "polylightEffect.cxx"
|
||||||
#include "portalNode.cxx"
|
#include "portalNode.cxx"
|
||||||
#include "portalClipper.cxx"
|
#include "portalClipper.cxx"
|
||||||
#include "renderAttrib.cxx"
|
#include "renderAttrib.cxx"
|
||||||
|
@ -200,6 +200,25 @@ get_compass() const {
|
|||||||
return _compass;
|
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
|
// Function: RenderEffects::has_show_bounds
|
||||||
// Access: Public
|
// Access: Public
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "billboardEffect.h"
|
#include "billboardEffect.h"
|
||||||
#include "decalEffect.h"
|
#include "decalEffect.h"
|
||||||
#include "compassEffect.h"
|
#include "compassEffect.h"
|
||||||
|
#include "polylightEffect.h"
|
||||||
#include "showBoundsEffect.h"
|
#include "showBoundsEffect.h"
|
||||||
#include "config_pgraph.h"
|
#include "config_pgraph.h"
|
||||||
#include "bamReader.h"
|
#include "bamReader.h"
|
||||||
@ -476,6 +477,23 @@ determine_compass() {
|
|||||||
_flags |= F_checked_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
|
// Function: RenderEffects::determine_show_bounds
|
||||||
// Access: Private
|
// Access: Private
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
class BillboardEffect;
|
class BillboardEffect;
|
||||||
class CompassEffect;
|
class CompassEffect;
|
||||||
|
class PolylightEffect;
|
||||||
class FactoryParams;
|
class FactoryParams;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -91,6 +92,7 @@ public:
|
|||||||
INLINE const BillboardEffect *get_billboard() const;
|
INLINE const BillboardEffect *get_billboard() const;
|
||||||
INLINE bool has_decal() const;
|
INLINE bool has_decal() const;
|
||||||
INLINE const CompassEffect *get_compass() const;
|
INLINE const CompassEffect *get_compass() const;
|
||||||
|
INLINE const PolylightEffect *get_polylight() const;
|
||||||
INLINE bool has_show_bounds() const;
|
INLINE bool has_show_bounds() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -98,6 +100,7 @@ private:
|
|||||||
void determine_billboard();
|
void determine_billboard();
|
||||||
void determine_decal();
|
void determine_decal();
|
||||||
void determine_compass();
|
void determine_compass();
|
||||||
|
void determine_polylight();
|
||||||
void determine_show_bounds();
|
void determine_show_bounds();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -133,6 +136,7 @@ private:
|
|||||||
// state, if they exist.
|
// state, if they exist.
|
||||||
const BillboardEffect *_billboard;
|
const BillboardEffect *_billboard;
|
||||||
const CompassEffect *_compass;
|
const CompassEffect *_compass;
|
||||||
|
const PolylightEffect *_polylight;
|
||||||
|
|
||||||
enum Flags {
|
enum Flags {
|
||||||
F_checked_billboard = 0x0001,
|
F_checked_billboard = 0x0001,
|
||||||
@ -141,9 +145,11 @@ private:
|
|||||||
F_checked_show_bounds = 0x0008,
|
F_checked_show_bounds = 0x0008,
|
||||||
F_has_show_bounds = 0x0010,
|
F_has_show_bounds = 0x0010,
|
||||||
F_checked_compass = 0x0020,
|
F_checked_compass = 0x0020,
|
||||||
|
F_checked_polylight = 0x0040,
|
||||||
};
|
};
|
||||||
short _flags;
|
short _flags;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void register_with_read_factory();
|
static void register_with_read_factory();
|
||||||
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user