From 16b5c0f9eea6451e58d6ddb5b6a95b092aa4afbd Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 20 Jun 2001 23:38:15 +0000 Subject: [PATCH] various interface improvements --- panda/src/egg/Sources.pp | 6 +-- panda/src/egg/eggAttributes.I | 12 ++++-- panda/src/egg/eggAttributes.h | 2 +- panda/src/egg/eggBinMaker.cxx | 20 +++++++++- panda/src/egg/eggBinMaker.h | 3 +- panda/src/egg/eggGroup.cxx | 6 +++ panda/src/egg/eggMorphList.I | 11 ++++++ panda/src/egg/eggMorphList.h | 1 + panda/src/egg/eggPolysetMaker.cxx | 66 +++++++++++++++++++++++++++++++ panda/src/egg/eggPolysetMaker.h | 56 ++++++++++++++++++++++++++ panda/src/egg/egg_composite2.cxx | 1 + 11 files changed, 174 insertions(+), 10 deletions(-) create mode 100644 panda/src/egg/eggPolysetMaker.cxx create mode 100644 panda/src/egg/eggPolysetMaker.h diff --git a/panda/src/egg/Sources.pp b/panda/src/egg/Sources.pp index 0b8a87886c..ef46b11e41 100644 --- a/panda/src/egg/Sources.pp +++ b/panda/src/egg/Sources.pp @@ -25,7 +25,7 @@ eggNode.I eggNode.h eggNurbsCurve.I eggNurbsCurve.h \ eggNurbsSurface.I eggNurbsSurface.h eggObject.I eggObject.h \ eggParameters.h eggPoint.I eggPoint.h eggPolygon.I \ - eggPolygon.h eggPoolUniquifier.h eggPrimitive.I \ + eggPolygon.h eggPolysetMaker.h eggPoolUniquifier.h eggPrimitive.I \ eggPrimitive.h eggRenderMode.I eggRenderMode.h \ eggSAnimData.I eggSAnimData.h eggSurface.I eggSurface.h \ eggSwitchCondition.h eggTable.I eggTable.h eggTexture.I \ @@ -46,7 +46,7 @@ eggMaterialCollection.cxx eggMiscFuncs.cxx eggMorphList.cxx \ eggNamedObject.cxx eggNameUniquifier.cxx eggNode.cxx \ eggNurbsCurve.cxx eggNurbsSurface.cxx eggObject.cxx \ - eggParameters.cxx eggPoint.cxx eggPolygon.cxx \ + eggParameters.cxx eggPoint.cxx eggPolygon.cxx eggPolysetMaker.cxx \ eggPoolUniquifier.cxx eggPrimitive.cxx eggRenderMode.cxx \ eggSAnimData.cxx eggSurface.cxx eggSwitchCondition.cxx \ eggTable.cxx eggTexture.cxx eggTextureCollection.cxx \ @@ -69,7 +69,7 @@ eggNamedObject.I eggNamedObject.h eggNameUniquifier.h eggNode.I eggNode.h \ eggNurbsCurve.I eggNurbsCurve.h eggNurbsSurface.I eggNurbsSurface.h \ eggObject.I eggObject.h eggParameters.h eggPoint.I eggPoint.h \ - eggPolygon.I eggPolygon.h eggPoolUniquifier.h \ + eggPolygon.I eggPolygon.h eggPolysetMaker.h eggPoolUniquifier.h \ eggPrimitive.I eggPrimitive.h eggRenderMode.I eggRenderMode.h \ eggSAnimData.I eggSAnimData.h eggSurface.I eggSurface.h \ eggSwitchCondition.h eggTable.I eggTable.h eggTexture.I \ diff --git a/panda/src/egg/eggAttributes.I b/panda/src/egg/eggAttributes.I index 9bb3b58a6f..75a1716700 100644 --- a/panda/src/egg/eggAttributes.I +++ b/panda/src/egg/eggAttributes.I @@ -116,12 +116,16 @@ has_color() const { //////////////////////////////////////////////////////////////////// // Function: EggAttributes::get_color // Access: Public -// Description: +// Description: Returns the color set on this particular attribute. +// If there is no color set, returns white. //////////////////////////////////////////////////////////////////// -INLINE const Colorf &EggAttributes:: +INLINE Colorf EggAttributes:: get_color() const { - nassertr(has_color(), _color); - return _color; + if (has_color()) { + return _color; + } else { + return Colorf(1.0, 1.0, 1.0, 1.0); + } } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/egg/eggAttributes.h b/panda/src/egg/eggAttributes.h index 0e7b29bb76..6797908163 100644 --- a/panda/src/egg/eggAttributes.h +++ b/panda/src/egg/eggAttributes.h @@ -55,7 +55,7 @@ public: INLINE void clear_uv(); INLINE bool has_color() const; - INLINE const Colorf &get_color() const; + INLINE Colorf get_color() const; INLINE void set_color(const Colorf &Color); INLINE void clear_color(); diff --git a/panda/src/egg/eggBinMaker.cxx b/panda/src/egg/eggBinMaker.cxx index de2d8c6820..a1bbc1d675 100644 --- a/panda/src/egg/eggBinMaker.cxx +++ b/panda/src/egg/eggBinMaker.cxx @@ -49,6 +49,24 @@ operator ()(const EggNode *a, const EggNode *b) const { return _ebm->sorts_less(bin_number_a, a, b); } +//////////////////////////////////////////////////////////////////// +// Function: EggBinMaker::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +EggBinMaker:: +EggBinMaker() { +} + +//////////////////////////////////////////////////////////////////// +// Function: EggBinMaker::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +EggBinMaker:: +~EggBinMaker() { +} + //////////////////////////////////////////////////////////////////// // Function: EggBinMaker::make_bins @@ -122,7 +140,7 @@ get_bin_name(int) { void EggBinMaker:: collect_nodes(EggGroupNode *group) { // We have to play games with this next iterator, because we might - // be destructively operation on the child list as we traverse it. + // be destructively operating on the child list as we traverse it. EggGroupNode::iterator i, next; bool first_in_group = true; diff --git a/panda/src/egg/eggBinMaker.h b/panda/src/egg/eggBinMaker.h index 629904fe48..6905fb812b 100644 --- a/panda/src/egg/eggBinMaker.h +++ b/panda/src/egg/eggBinMaker.h @@ -249,7 +249,8 @@ public: //////////////////////////////////////////////////////////////////// class EXPCL_PANDAEGG EggBinMaker : public EggObject { public: - EggBinMaker() { } + EggBinMaker(); + ~EggBinMaker(); int make_bins(EggGroupNode *root_group); diff --git a/panda/src/egg/eggGroup.cxx b/panda/src/egg/eggGroup.cxx index 425e625167..73b377ad9c 100644 --- a/panda/src/egg/eggGroup.cxx +++ b/panda/src/egg/eggGroup.cxx @@ -19,6 +19,7 @@ #include "eggGroup.h" #include "eggMiscFuncs.h" #include "eggVertexPool.h" +#include "eggBin.h" #include "lexerDefs.h" #include @@ -179,6 +180,11 @@ write(ostream &out, int indent_level) const { nassertv(false); } + if (is_of_type(EggBin::get_class_type())) { + indent(out, indent_level + 2) + << "// Bin " << DCAST(EggBin, this)->get_bin_number() << "\n"; + } + if (has_lod()) { get_lod().write(out, indent_level + 2); } diff --git a/panda/src/egg/eggMorphList.I b/panda/src/egg/eggMorphList.I index 5450cdcb5f..89afba8f2f 100644 --- a/panda/src/egg/eggMorphList.I +++ b/panda/src/egg/eggMorphList.I @@ -191,6 +191,17 @@ insert(const MorphType &value) { return result; } +//////////////////////////////////////////////////////////////////// +// Function: EggMorphList::clear +// Access: Public +// Description: Empties the list of morphs. +//////////////////////////////////////////////////////////////////// +template +INLINE void EggMorphList:: +clear() { + _morphs.clear(); +} + //////////////////////////////////////////////////////////////////// // Function: EggMorphList::write // Access: Public diff --git a/panda/src/egg/eggMorphList.h b/panda/src/egg/eggMorphList.h index e424d62f0f..fbf26290cf 100644 --- a/panda/src/egg/eggMorphList.h +++ b/panda/src/egg/eggMorphList.h @@ -59,6 +59,7 @@ public: INLINE bool empty() const; pair insert(const MorphType &value); + INLINE void clear(); void write(ostream &out, int indent_level) const; diff --git a/panda/src/egg/eggPolysetMaker.cxx b/panda/src/egg/eggPolysetMaker.cxx new file mode 100644 index 0000000000..b1fac801bf --- /dev/null +++ b/panda/src/egg/eggPolysetMaker.cxx @@ -0,0 +1,66 @@ +// Filename: eggPolysetMaker.cxx +// Created by: drose (20Jun01) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "eggPolysetMaker.h" +#include "eggPolygon.h" + +//////////////////////////////////////////////////////////////////// +// Function: EggPolysetMaker::get_bin_number +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +int EggPolysetMaker:: +get_bin_number(const EggNode *node) { + if (node->is_of_type(EggPolygon::get_class_type())) { + return (int)BN_polyset; + } + + return (int)BN_none; +} + + +//////////////////////////////////////////////////////////////////// +// Function: EggPolysetMaker::sorts_less +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +bool EggPolysetMaker:: +sorts_less(int bin_number, const EggNode *a, const EggNode *b) { + nassertr((BinNumber)bin_number == BN_polyset, false); + + const EggPolygon *pa = DCAST(EggPolygon, a); + const EggPolygon *pb = DCAST(EggPolygon, b); + + if (pa->has_texture() != pb->has_texture()) { + return ((int)pa->has_texture() < (int)pb->has_texture()); + } + if (pa->has_texture()) { + return (pa->get_texture()->sorts_less_than(*pb->get_texture(), ~EggTexture::E_tref_name)); + } + if (pa->has_material() != pb->has_material()) { + return ((int)pa->has_material() < (int)pb->has_material()); + } + if (pa->has_material()) { + return (pa->get_material()->sorts_less_than(*pb->get_material(), ~EggMaterial::E_mref_name)); + } + if (pa->get_bface_flag() != pb->get_bface_flag()) { + return ((int)pa->get_bface_flag() < (int)pb->get_bface_flag()); + } + + return false; +} diff --git a/panda/src/egg/eggPolysetMaker.h b/panda/src/egg/eggPolysetMaker.h new file mode 100644 index 0000000000..083472d2b2 --- /dev/null +++ b/panda/src/egg/eggPolysetMaker.h @@ -0,0 +1,56 @@ +// Filename: eggPolysetMaker.h +// Created by: drose (19Jun01) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#ifndef EGGPOLYSETMAKER_H +#define EGGPOLYSETMAKER_H + +#include + +#include "eggBinMaker.h" + +/////////////////////////////////////////////////////////////////// +// Class : EggPolysetMaker +// Description : A specialization on EggBinMaker for making polysets +// that share the same basic rendering characteristic. +// This really just defines the example functions +// described in the leading comment to EggBinMaker. +// +// It makes some common assumptions about how polysets +// should be grouped; if these are not sufficient, you +// can always rederive your own further specialization +// of this class. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAEGG EggPolysetMaker : public EggBinMaker { +public: + + // The BinNumber serves to identify why a particular EggBin was + // created. + enum BinNumber { + BN_none = 0, + BN_polyset, + }; + + virtual int + get_bin_number(const EggNode *node); + + virtual bool + sorts_less(int bin_number, const EggNode *a, const EggNode *b); +}; + + +#endif diff --git a/panda/src/egg/egg_composite2.cxx b/panda/src/egg/egg_composite2.cxx index fa6016f19a..57285a8682 100644 --- a/panda/src/egg/egg_composite2.cxx +++ b/panda/src/egg/egg_composite2.cxx @@ -3,6 +3,7 @@ #include "eggParameters.cxx" #include "eggPoint.cxx" #include "eggPolygon.cxx" +#include "eggPolysetMaker.cxx" #include "eggPoolUniquifier.cxx" #include "eggPrimitive.cxx" #include "eggRenderMode.cxx"