diff --git a/panda/src/pgraph/colorScaleAttrib.h b/panda/src/pgraph/colorScaleAttrib.h index fd1f14da45..86a2b66b03 100644 --- a/panda/src/pgraph/colorScaleAttrib.h +++ b/panda/src/pgraph/colorScaleAttrib.h @@ -53,10 +53,10 @@ public: virtual bool lower_attrib_can_override() const; virtual void output(ostream &out) const; virtual void store_into_slot(AttribSlots *slots) const; + virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const; protected: virtual int compare_to_impl(const RenderAttrib *other) const; - virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const; virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const; virtual RenderAttrib *make_default_impl() const; diff --git a/panda/src/pgraph/nodePath.I b/panda/src/pgraph/nodePath.I index 1f2952198d..0407c79565 100644 --- a/panda/src/pgraph/nodePath.I +++ b/panda/src/pgraph/nodePath.I @@ -1179,6 +1179,16 @@ set_color_scale(float sr, float sg, float sb, float sa, int priority) { set_color_scale(LVecBase4f(sr, sg, sb, sa), priority); } +//////////////////////////////////////////////////////////////////// +// Function: NodePath::compose_color_scale +// Access: Published +// Description: Sets the color scale component of the transform +//////////////////////////////////////////////////////////////////// +INLINE void NodePath:: +compose_color_scale(float sr, float sg, float sb, float sa, int priority) { + compose_color_scale(LVecBase4f(sr, sg, sb, sa), priority); +} + //////////////////////////////////////////////////////////////////// // Function: NodePath::set_sr // Access: Published diff --git a/panda/src/pgraph/nodePath.cxx b/panda/src/pgraph/nodePath.cxx index dd709434d1..e550acaeb7 100644 --- a/panda/src/pgraph/nodePath.cxx +++ b/panda/src/pgraph/nodePath.cxx @@ -2146,6 +2146,39 @@ clear_color_scale() { node()->clear_attrib(ColorScaleAttrib::get_class_type()); } +//////////////////////////////////////////////////////////////////// +// Function: NodePath::compose_color_scale +// Access: Published +// Description: multiplies the color scale component of the transform, +// with previous color scale leaving translation and +// rotation untouched. +//////////////////////////////////////////////////////////////////// +void NodePath:: +compose_color_scale(const LVecBase4f &scale, int priority) { + nassertv_always(!is_empty()); + + const RenderAttrib *attrib = + node()->get_attrib(ColorScaleAttrib::get_class_type()); + if (attrib != (const RenderAttrib *)NULL) { + priority = max(priority, + node()->get_state()->get_override(ColorScaleAttrib::get_class_type())); + const ColorScaleAttrib *csa = DCAST(ColorScaleAttrib, attrib); + + // Modify the existing ColorScaleAttrib by multiplying with the + // indicated colorScale. + LVecBase4f prev_color_scale = csa->get_scale(); + LVecBase4f new_color_scale(prev_color_scale[0]*scale[0], + prev_color_scale[1]*scale[1], + prev_color_scale[2]*scale[2], + prev_color_scale[3]*scale[3]); + node()->set_attrib(csa->set_scale(new_color_scale), priority); + + } else { + // Create a new ColorScaleAttrib for this node. + node()->set_attrib(ColorScaleAttrib::make(scale), priority); + } +} + //////////////////////////////////////////////////////////////////// // Function: NodePath::set_color_scale // Access: Published diff --git a/panda/src/pgraph/nodePath.h b/panda/src/pgraph/nodePath.h index f2031bf3e8..db485969f3 100644 --- a/panda/src/pgraph/nodePath.h +++ b/panda/src/pgraph/nodePath.h @@ -512,8 +512,12 @@ PUBLISHED: int priority = 0); INLINE void set_color_scale(float sx, float sy, float sz, float sa, int priority = 0); + void compose_color_scale(const LVecBase4f &scale, + int priority = 0); + INLINE void compose_color_scale(float sx, float sy, float sz, float sa, + int priority = 0); void set_color_scale_off(int priority = 0); - + void set_alpha_scale(float scale, int priority = 0); void set_all_color_scale(float scale, int priority = 0); INLINE void set_sr(float sr); diff --git a/panda/src/pgraph/nodePathCollection.cxx b/panda/src/pgraph/nodePathCollection.cxx index 6379bde748..43882e4d47 100644 --- a/panda/src/pgraph/nodePathCollection.cxx +++ b/panda/src/pgraph/nodePathCollection.cxx @@ -470,6 +470,30 @@ set_color_scale(const Colorf &color, int priority) { } } +//////////////////////////////////////////////////////////////////// +// Function: NodePathCollection::compose_color_scale +// Access: Published +// Description: Applies color scales to all NodePaths in the collection +//////////////////////////////////////////////////////////////////// +void NodePathCollection:: +compose_color_scale(float r, float g, float b, float a, int priority) { + for (int i = 0; i < get_num_paths(); i++) { + get_path(i).compose_color_scale(Colorf(r, g, b, a), priority); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: NodePathCollection::compose_color_scale +// Access: Published +// Description: Applies color scales to all NodePaths in the collection +//////////////////////////////////////////////////////////////////// +void NodePathCollection:: +compose_color_scale(const Colorf &color, int priority) { + for (int i = 0; i < get_num_paths(); i++) { + get_path(i).compose_color_scale(color, priority); + } +} + //////////////////////////////////////////////////////////////////// // Function: NodePathCollection::output // Access: Published diff --git a/panda/src/pgraph/nodePathCollection.h b/panda/src/pgraph/nodePathCollection.h index f70686251d..8e0b04e0a0 100644 --- a/panda/src/pgraph/nodePathCollection.h +++ b/panda/src/pgraph/nodePathCollection.h @@ -76,6 +76,10 @@ PUBLISHED: int priority = 0); void set_color_scale(const Colorf &color, int priority = 0); + void compose_color_scale(float r, float g, float b, float a = 1.0, + int priority = 0); + void compose_color_scale(const Colorf &color, int priority = 0); + void output(ostream &out) const; void write(ostream &out, int indent_level = 0) const;