mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 17:35:34 -04:00
Add RectangleLight class
This commit is contained in:
parent
4b5c317160
commit
da79c28a6c
@ -26,6 +26,7 @@
|
||||
#include "lodNode.h"
|
||||
#include "nodeCullCallbackData.h"
|
||||
#include "pointLight.h"
|
||||
#include "rectangleLight.h"
|
||||
#include "selectiveChildNode.h"
|
||||
#include "sequenceNode.h"
|
||||
#include "shaderGenerator.h"
|
||||
@ -121,6 +122,7 @@ init_libpgraphnodes() {
|
||||
LODNode::init_type();
|
||||
NodeCullCallbackData::init_type();
|
||||
PointLight::init_type();
|
||||
RectangleLight::init_type();
|
||||
SelectiveChildNode::init_type();
|
||||
SequenceNode::init_type();
|
||||
ShaderGenerator::init_type();
|
||||
@ -137,6 +139,7 @@ init_libpgraphnodes() {
|
||||
LightNode::register_with_read_factory();
|
||||
LODNode::register_with_read_factory();
|
||||
PointLight::register_with_read_factory();
|
||||
RectangleLight::register_with_read_factory();
|
||||
SelectiveChildNode::register_with_read_factory();
|
||||
SequenceNode::register_with_read_factory();
|
||||
SphereLight::register_with_read_factory();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "nodeCullCallbackData.cxx"
|
||||
#include "pointLight.cxx"
|
||||
#include "rectangleLight.cxx"
|
||||
#include "sceneGraphAnalyzer.cxx"
|
||||
#include "selectiveChildNode.cxx"
|
||||
#include "sequenceNode.cxx"
|
||||
|
59
panda/src/pgraphnodes/rectangleLight.I
Normal file
59
panda/src/pgraphnodes/rectangleLight.I
Normal file
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file rectangleLight.I
|
||||
* @author rdb
|
||||
* @date 2016-12-19
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
INLINE RectangleLight::CData::
|
||||
CData() :
|
||||
_max_distance(make_inf((PN_stdfloat)0))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
INLINE RectangleLight::CData::
|
||||
CData(const RectangleLight::CData ©) :
|
||||
_max_distance(copy._max_distance)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color of specular highlights generated by the light. This is
|
||||
* usually the same as get_color().
|
||||
*/
|
||||
INLINE const LColor &RectangleLight::
|
||||
get_specular_color() const {
|
||||
return get_color();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum distance at which the light has any effect, as previously
|
||||
* specified by set_max_distance.
|
||||
*/
|
||||
INLINE PN_stdfloat RectangleLight::
|
||||
get_max_distance() const {
|
||||
CDReader cdata(_cycler);
|
||||
return cdata->_max_distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the radius of the light's sphere of influence. Beyond this distance, the
|
||||
* light may be attenuated to zero, if this is supported by the shader.
|
||||
*/
|
||||
INLINE void RectangleLight::
|
||||
set_max_distance(PN_stdfloat max_distance) {
|
||||
CDWriter cdata(_cycler);
|
||||
cdata->_max_distance = max_distance;
|
||||
}
|
150
panda/src/pgraphnodes/rectangleLight.cxx
Normal file
150
panda/src/pgraphnodes/rectangleLight.cxx
Normal file
@ -0,0 +1,150 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file rectangleLight.cxx
|
||||
* @author rdb
|
||||
* @date 2016-12-19
|
||||
*/
|
||||
|
||||
#include "rectangleLight.h"
|
||||
#include "graphicsStateGuardianBase.h"
|
||||
#include "bamWriter.h"
|
||||
#include "bamReader.h"
|
||||
#include "datagram.h"
|
||||
#include "datagramIterator.h"
|
||||
|
||||
TypeHandle RectangleLight::_type_handle;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
CycleData *RectangleLight::CData::
|
||||
make_copy() const {
|
||||
return new CData(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the contents of this object to the datagram for shipping out to a
|
||||
* Bam file.
|
||||
*/
|
||||
void RectangleLight::CData::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) const {
|
||||
dg.add_stdfloat(_max_distance);
|
||||
}
|
||||
|
||||
/**
|
||||
* This internal function is called by make_from_bam to read in all of the
|
||||
* relevant data from the BamFile for the new Light.
|
||||
*/
|
||||
void RectangleLight::CData::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
_max_distance = scan.get_stdfloat();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
RectangleLight::
|
||||
RectangleLight(const string &name) :
|
||||
LightLensNode(name)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not call the copy constructor directly; instead, use make_copy() or
|
||||
* copy_subgraph() to make a copy of a node.
|
||||
*/
|
||||
RectangleLight::
|
||||
RectangleLight(const RectangleLight ©) :
|
||||
LightLensNode(copy),
|
||||
_cycler(copy._cycler)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a newly-allocated PandaNode that is a shallow copy of this one. It
|
||||
* will be a different pointer, but its internal data may or may not be shared
|
||||
* with that of the original PandaNode. No children will be copied.
|
||||
*/
|
||||
PandaNode *RectangleLight::
|
||||
make_copy() const {
|
||||
return new RectangleLight(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void RectangleLight::
|
||||
write(ostream &out, int indent_level) const {
|
||||
LightLensNode::write(out, indent_level);
|
||||
indent(out, indent_level) << *this << "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the relative priority associated with all lights of this class.
|
||||
* This priority is used to order lights whose instance priority
|
||||
* (get_priority()) is the same--the idea is that other things being equal,
|
||||
* AmbientLights (for instance) are less important than DirectionalLights.
|
||||
*/
|
||||
int RectangleLight::
|
||||
get_class_priority() const {
|
||||
return (int)CP_area_priority;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void RectangleLight::
|
||||
bind(GraphicsStateGuardianBase *gsg, const NodePath &light, int light_id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the BamReader how to create objects of type RectangleLight.
|
||||
*/
|
||||
void RectangleLight::
|
||||
register_with_read_factory() {
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the contents of this object to the datagram for shipping out to a
|
||||
* Bam file.
|
||||
*/
|
||||
void RectangleLight::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
LightLensNode::write_datagram(manager, dg);
|
||||
manager->write_cdata(dg, _cycler);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called by the BamReader's factory when a new object of
|
||||
* type RectangleLight is encountered in the Bam file. It should create the
|
||||
* RectangleLight and extract its information from the file.
|
||||
*/
|
||||
TypedWritable *RectangleLight::
|
||||
make_from_bam(const FactoryParams ¶ms) {
|
||||
RectangleLight *node = new RectangleLight("");
|
||||
DatagramIterator scan;
|
||||
BamReader *manager;
|
||||
|
||||
parse_params(params, scan, manager);
|
||||
node->fillin(scan, manager);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* This internal function is called by make_from_bam to read in all of the
|
||||
* relevant data from the BamFile for the new RectangleLight.
|
||||
*/
|
||||
void RectangleLight::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
LightLensNode::fillin(scan, manager);
|
||||
|
||||
manager->read_cdata(scan, _cycler);
|
||||
}
|
98
panda/src/pgraphnodes/rectangleLight.h
Normal file
98
panda/src/pgraphnodes/rectangleLight.h
Normal file
@ -0,0 +1,98 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file rectangleLight.h
|
||||
* @author rdb
|
||||
* @date 2016-12-19
|
||||
*/
|
||||
|
||||
#ifndef RECTANGLELIGHT_H
|
||||
#define RECTANGLELIGHT_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "lightLensNode.h"
|
||||
#include "pointLight.h"
|
||||
|
||||
/**
|
||||
* This is a type of area light that is an axis aligned rectangle, pointing
|
||||
* along the Y axis in the positive direction.
|
||||
*/
|
||||
class EXPCL_PANDA_PGRAPHNODES RectangleLight : public LightLensNode {
|
||||
PUBLISHED:
|
||||
RectangleLight(const string &name);
|
||||
|
||||
protected:
|
||||
RectangleLight(const RectangleLight ©);
|
||||
|
||||
public:
|
||||
virtual PandaNode *make_copy() const;
|
||||
virtual void write(ostream &out, int indent_level) const;
|
||||
|
||||
PUBLISHED:
|
||||
INLINE const LColor &get_specular_color() const FINAL;
|
||||
|
||||
INLINE PN_stdfloat get_max_distance() const;
|
||||
INLINE void set_max_distance(PN_stdfloat max_distance);
|
||||
MAKE_PROPERTY(max_distance, get_max_distance, set_max_distance);
|
||||
|
||||
virtual int get_class_priority() const;
|
||||
|
||||
public:
|
||||
virtual void bind(GraphicsStateGuardianBase *gsg, const NodePath &light,
|
||||
int light_id);
|
||||
|
||||
private:
|
||||
// This is the data that must be cycled between pipeline stages.
|
||||
class EXPCL_PANDA_PGRAPHNODES CData : public CycleData {
|
||||
public:
|
||||
INLINE CData();
|
||||
INLINE CData(const CData ©);
|
||||
virtual CycleData *make_copy() const;
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
|
||||
virtual void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
virtual TypeHandle get_parent_type() const {
|
||||
return RectangleLight::get_class_type();
|
||||
}
|
||||
|
||||
PN_stdfloat _max_distance;
|
||||
};
|
||||
|
||||
PipelineCycler<CData> _cycler;
|
||||
typedef CycleDataReader<CData> CDReader;
|
||||
typedef CycleDataWriter<CData> CDWriter;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
||||
|
||||
protected:
|
||||
static TypedWritable *make_from_bam(const FactoryParams ¶ms);
|
||||
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
LightLensNode::init_type();
|
||||
register_type(_type_handle, "RectangleLight",
|
||||
LightLensNode::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
#include "rectangleLight.I"
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user