Browse Source

Add SphereLight class

rdb 9 years ago
parent
commit
2b7ef9c787

+ 3 - 0
panda/src/pgraphnodes/config_pgraphnodes.cxx

@@ -29,6 +29,7 @@
 #include "selectiveChildNode.h"
 #include "selectiveChildNode.h"
 #include "sequenceNode.h"
 #include "sequenceNode.h"
 #include "shaderGenerator.h"
 #include "shaderGenerator.h"
+#include "sphereLight.h"
 #include "spotlight.h"
 #include "spotlight.h"
 #include "switchNode.h"
 #include "switchNode.h"
 #include "uvScrollNode.h"
 #include "uvScrollNode.h"
@@ -123,6 +124,7 @@ init_libpgraphnodes() {
   SelectiveChildNode::init_type();
   SelectiveChildNode::init_type();
   SequenceNode::init_type();
   SequenceNode::init_type();
   ShaderGenerator::init_type();
   ShaderGenerator::init_type();
+  SphereLight::init_type();
   Spotlight::init_type();
   Spotlight::init_type();
   SwitchNode::init_type();
   SwitchNode::init_type();
   UvScrollNode::init_type();
   UvScrollNode::init_type();
@@ -137,6 +139,7 @@ init_libpgraphnodes() {
   PointLight::register_with_read_factory();
   PointLight::register_with_read_factory();
   SelectiveChildNode::register_with_read_factory();
   SelectiveChildNode::register_with_read_factory();
   SequenceNode::register_with_read_factory();
   SequenceNode::register_with_read_factory();
+  SphereLight::register_with_read_factory();
   Spotlight::register_with_read_factory();
   Spotlight::register_with_read_factory();
   SwitchNode::register_with_read_factory();
   SwitchNode::register_with_read_factory();
   UvScrollNode::register_with_read_factory();
   UvScrollNode::register_with_read_factory();

+ 2 - 0
panda/src/pgraphnodes/p3pgraphnodes_composite1.cxx

@@ -7,3 +7,5 @@
 #include "fadeLodNodeData.cxx"
 #include "fadeLodNodeData.cxx"
 #include "lightLensNode.cxx"
 #include "lightLensNode.cxx"
 #include "lightNode.cxx"
 #include "lightNode.cxx"
+#include "lodNode.cxx"
+#include "lodNodeType.cxx"

+ 1 - 2
panda/src/pgraphnodes/p3pgraphnodes_composite2.cxx

@@ -1,11 +1,10 @@
-#include "lodNode.cxx"
-#include "lodNodeType.cxx"
 #include "nodeCullCallbackData.cxx"
 #include "nodeCullCallbackData.cxx"
 #include "pointLight.cxx"
 #include "pointLight.cxx"
 #include "sceneGraphAnalyzer.cxx"
 #include "sceneGraphAnalyzer.cxx"
 #include "selectiveChildNode.cxx"
 #include "selectiveChildNode.cxx"
 #include "sequenceNode.cxx"
 #include "sequenceNode.cxx"
 #include "shaderGenerator.cxx"
 #include "shaderGenerator.cxx"
+#include "sphereLight.cxx"
 #include "spotlight.cxx"
 #include "spotlight.cxx"
 #include "switchNode.cxx"
 #include "switchNode.cxx"
 #include "uvScrollNode.cxx"
 #include "uvScrollNode.cxx"

+ 48 - 0
panda/src/pgraphnodes/sphereLight.I

@@ -0,0 +1,48 @@
+/**
+ * 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 sphereLight.I
+ * @author rdb
+ * @date 2016-04-15
+ */
+
+/**
+ *
+ */
+INLINE SphereLight::CData::
+CData() :
+  _radius(0.01f)
+{
+}
+
+/**
+ *
+ */
+INLINE SphereLight::CData::
+CData(const SphereLight::CData &copy) :
+  _radius(copy._radius)
+{
+}
+
+/**
+ * Returns the radius of the sphere.
+ */
+INLINE PN_stdfloat SphereLight::
+get_radius() const {
+  CDReader cdata(_cycler);
+  return cdata->_radius;
+}
+
+/**
+ * Sets the radius of the sphere.
+ */
+INLINE void SphereLight::
+set_radius(PN_stdfloat radius) {
+  CDWriter cdata(_cycler);
+  cdata->_radius = radius;
+}

+ 146 - 0
panda/src/pgraphnodes/sphereLight.cxx

@@ -0,0 +1,146 @@
+/**
+ * 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 sphereLight.cxx
+ * @author rdb
+ * @date 2016-04-15
+ */
+
+#include "sphereLight.h"
+#include "graphicsStateGuardianBase.h"
+#include "bamWriter.h"
+#include "bamReader.h"
+#include "datagram.h"
+#include "datagramIterator.h"
+
+TypeHandle SphereLight::_type_handle;
+
+/**
+ *
+ */
+CycleData *SphereLight::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 SphereLight::CData::
+write_datagram(BamWriter *manager, Datagram &dg) const {
+  dg.add_stdfloat(_radius);
+}
+
+/**
+ * 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 SphereLight::CData::
+fillin(DatagramIterator &scan, BamReader *manager) {
+  _radius = scan.get_stdfloat();
+}
+
+/**
+ *
+ */
+SphereLight::
+SphereLight(const string &name) :
+  PointLight(name)
+{
+}
+
+/**
+ * Do not call the copy constructor directly; instead, use make_copy() or
+ * copy_subgraph() to make a copy of a node.
+ */
+SphereLight::
+SphereLight(const SphereLight &copy) :
+  PointLight(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 *SphereLight::
+make_copy() const {
+  return new SphereLight(*this);
+}
+
+/**
+ * Transforms the contents of this PandaNode by the indicated matrix, if it
+ * means anything to do so.  For most kinds of PandaNodes, this does nothing.
+ */
+void SphereLight::
+xform(const LMatrix4 &mat) {
+  PointLight::xform(mat);
+  CDWriter cdata(_cycler);
+  cdata->_radius = mat.xform_vec(LVector3(0, 0, cdata->_radius)).length();
+  mark_viz_stale();
+}
+
+/**
+ *
+ */
+void SphereLight::
+write(ostream &out, int indent_level) const {
+  PointLight::write(out, indent_level);
+  indent(out, indent_level) << *this << ":\n";
+  indent(out, indent_level + 2)
+    << "radius " << get_radius() << "\n";
+}
+
+/**
+ * Tells the BamReader how to create objects of type SphereLight.
+ */
+void SphereLight::
+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 SphereLight::
+write_datagram(BamWriter *manager, Datagram &dg) {
+  PointLight::write_datagram(manager, dg);
+  manager->write_cdata(dg, _cycler);
+}
+
+/**
+ * This function is called by the BamReader's factory when a new object of
+ * type SphereLight is encountered in the Bam file.  It should create the
+ * SphereLight and extract its information from the file.
+ */
+TypedWritable *SphereLight::
+make_from_bam(const FactoryParams &params) {
+  SphereLight *node = new SphereLight("");
+  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 SphereLight.
+ */
+void SphereLight::
+fillin(DatagramIterator &scan, BamReader *manager) {
+  PointLight::fillin(scan, manager);
+
+  manager->read_cdata(scan, _cycler);
+}

+ 90 - 0
panda/src/pgraphnodes/sphereLight.h

@@ -0,0 +1,90 @@
+/**
+ * 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 sphereLight.h
+ * @author rdb
+ * @date 2016-04-15
+ */
+
+#ifndef SPHERELIGHT_H
+#define SPHERELIGHT_H
+
+#include "pandabase.h"
+
+#include "lightLensNode.h"
+
+/**
+ * A sphere light is like a point light, except that it represents a sphere
+ * with a radius, rather than being an infinitely thin point in space.
+ */
+class EXPCL_PANDA_PGRAPHNODES SphereLight : public PointLight {
+PUBLISHED:
+  SphereLight(const string &name);
+
+protected:
+  SphereLight(const SphereLight &copy);
+
+public:
+  virtual PandaNode *make_copy() const;
+  virtual void xform(const LMatrix4 &mat);
+  virtual void write(ostream &out, int indent_level) const;
+
+PUBLISHED:
+  INLINE PN_stdfloat get_radius() const;
+  INLINE void set_radius(PN_stdfloat radius);
+  MAKE_PROPERTY(radius, get_radius, set_radius);
+
+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 &copy);
+    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 SphereLight::get_class_type();
+    }
+
+    PN_stdfloat _radius;
+  };
+
+  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 &params);
+  void fillin(DatagramIterator &scan, BamReader *manager);
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    PointLight::init_type();
+    register_type(_type_handle, "SphereLight",
+                  PointLight::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 "sphereLight.I"
+
+#endif