24int ColorScaleAttrib::_attrib_slot;
31ColorScaleAttrib(
bool off,
const LVecBase4 &scale) :
36 _has_scale = !_scale.almost_equal(LVecBase4(1.0f, 1.0f, 1.0f, 1.0f));
37 _has_rgb_scale = !LVecBase3(_scale[0], _scale[1], _scale[2]).almost_equal(LVecBase3(1.0f, 1.0f, 1.0f));
38 _has_alpha_scale = !IS_NEARLY_EQUAL(_scale[3], 1.0f);
48 if (_identity_attrib ==
nullptr) {
49 ColorScaleAttrib *attrib =
new ColorScaleAttrib(
false, LVecBase4(1.0f, 1.0f, 1.0f, 1.0f));;
50 _identity_attrib = return_new(attrib);
53 return _identity_attrib;
61make(
const LVecBase4 &scale) {
62 ColorScaleAttrib *attrib =
new ColorScaleAttrib(
false, scale);
63 return return_new(attrib);
73 ColorScaleAttrib *attrib =
74 new ColorScaleAttrib(
true, LVecBase4(1.0f, 1.0f, 1.0f, 1.0f));
75 return return_new(attrib);
84 return return_new(
new ColorScaleAttrib(
false, LVecBase4(1.0f, 1.0f, 1.0f, 1.0f)));
93 ColorScaleAttrib *attrib =
new ColorScaleAttrib(*
this);
94 attrib->_scale = scale;
95 attrib->quantize_scale();
96 attrib->_has_scale = !scale.almost_equal(LVecBase4(1.0f, 1.0f, 1.0f, 1.0f));
97 attrib->_has_rgb_scale = !LVecBase3(scale[0], scale[1], scale[2]).almost_equal(LVecBase3(1.0f, 1.0f, 1.0f));
98 attrib->_has_alpha_scale = !IS_NEARLY_EQUAL(scale[3], 1.0f);
99 return return_new(attrib);
131void ColorScaleAttrib::
132output(std::ostream &out)
const {
133 out << get_type() <<
":";
157int ColorScaleAttrib::
159 const ColorScaleAttrib *ta = (
const ColorScaleAttrib *)other;
174size_t ColorScaleAttrib::
175get_hash_impl()
const {
178 hash = _scale.add_hash(hash);
195 const ColorScaleAttrib *ta = (
const ColorScaleAttrib *)other;
201 LVecBase4 new_scale(ta->_scale[0] * _scale[0],
202 ta->_scale[1] * _scale[1],
203 ta->_scale[2] * _scale[2],
204 ta->_scale[3] * _scale[3]);
206 ColorScaleAttrib *attrib =
new ColorScaleAttrib(
is_off(), new_scale);
207 return return_new(attrib);
221 const ColorScaleAttrib *ta = (
const ColorScaleAttrib *)other;
223 LVecBase4 new_scale(_scale[0] == 0.0f ? 1.0f : ta->_scale[0] / _scale[0],
224 _scale[1] == 0.0f ? 1.0f : ta->_scale[1] / _scale[1],
225 _scale[2] == 0.0f ? 1.0f : ta->_scale[2] / _scale[2],
226 _scale[3] == 0.0f ? 1.0f : ta->_scale[3] / _scale[3]);
228 ColorScaleAttrib *attrib =
new ColorScaleAttrib(
false, new_scale);
229 return return_new(attrib);
236void ColorScaleAttrib::
238 _scale[0] = cfloor(_scale[0] * 1024.0f + 0.5f) / 1024.0f;
239 _scale[1] = cfloor(_scale[1] * 1024.0f + 0.5f) / 1024.0f;
240 _scale[2] = cfloor(_scale[2] * 1024.0f + 0.5f) / 1024.0f;
241 _scale[3] = cfloor(_scale[3] * 1024.0f + 0.5f) / 1024.0f;
264 _scale.write_datagram(dg);
279 attrib->fillin(scan, manager);
288void ColorScaleAttrib::
290 RenderAttrib::fillin(scan, manager);
293 _scale.read_datagram(scan);
295 _has_scale = !_scale.almost_equal(LVecBase4(1.0f, 1.0f, 1.0f, 1.0f));
296 _has_rgb_scale = !LVecBase3(_scale[0], _scale[1], _scale[2]).almost_equal(LVecBase3(1.0f, 1.0f, 1.0f));
297 _has_alpha_scale = !IS_NEARLY_EQUAL(_scale[3], 1.0f);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Applies a scale to colors in the scene graph and on vertices.
static ConstPointerTo< RenderAttrib > make_identity()
Constructs an identity scale attrib.
static ConstPointerTo< RenderAttrib > make_off()
Constructs a new ColorScaleAttrib object that ignores any ColorScaleAttrib inherited from above.
static ConstPointerTo< RenderAttrib > make(const LVecBase4 &scale)
Constructs a new ColorScaleAttrib object that indicates geometry should be scaled by the indicated fa...
virtual bool lower_attrib_can_override() const
Intended to be overridden by derived RenderAttrib types to specify how two consecutive RenderAttrib o...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
has_scale
Returns true if the ColorScaleAttrib has a non-identity scale, false otherwise (in which case it migh...
static ConstPointerTo< RenderAttrib > make_default()
Returns a RenderAttrib that corresponds to whatever the standard default properties for render attrib...
get_scale
Returns the scale to be applied to colors.
bool is_off() const
Returns true if the ColorScaleAttrib will ignore any color scales inherited from above,...
static void register_with_read_factory()
Tells the BamReader how to create objects of type ColorScaleAttrib.
ConstPointerTo< RenderAttrib > set_scale(const LVecBase4 &scale) const
Returns a new ColorScaleAttrib, just like this one, but with the scale changed to the indicated value...
A class to retrieve the individual data elements previously stored in a Datagram.
bool get_bool()
Extracts a boolean value.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_bool(bool value)
Adds a boolean value to the datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
TypeHandle is the identifier used to differentiate C++ class types.
int compare_to(const TypeHandle &other) const
Sorts TypeHandles arbitrarily (according to <, >, etc.).
Base class for objects that can be written to and read from Bam files.
static size_t add_hash(size_t start, const int &key)
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.