From 05b08da10948316d75ecd9fcd3790364b74eb2e9 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 17 Apr 2003 01:38:08 +0000 Subject: [PATCH] support color gain --- pandatool/src/maya/mayaShaderColorDef.cxx | 12 ++++++- pandatool/src/maya/mayaShaderColorDef.h | 1 + pandatool/src/maya/maya_funcs.cxx | 37 ++++++++++++++++++++ pandatool/src/maya/maya_funcs.h | 4 +++ pandatool/src/mayaegg/mayaToEggConverter.cxx | 5 +++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/pandatool/src/maya/mayaShaderColorDef.cxx b/pandatool/src/maya/mayaShaderColorDef.cxx index ed83a98617..90f675d6ba 100644 --- a/pandatool/src/maya/mayaShaderColorDef.cxx +++ b/pandatool/src/maya/mayaShaderColorDef.cxx @@ -37,6 +37,8 @@ //////////////////////////////////////////////////////////////////// MayaShaderColorDef:: MayaShaderColorDef() { + _color_gain.set(1.0f, 1.0f, 1.0f); + _has_flat_color = false; _flat_color.set(0.0, 0.0, 0.0, 0.0); @@ -137,7 +139,8 @@ write(ostream &out) const { << " wrap_v is " << _wrap_v << "\n" << " repeat_uv is " << _repeat_uv << "\n" << " offset is " << _offset << "\n" - << " rotate_uv is " << _rotate_uv << "\n"; + << " rotate_uv is " << _rotate_uv << "\n" + << " color_gain is " << _color_gain << "\n"; } else if (_has_flat_color) { out << " flat color is " << _flat_color << "\n"; @@ -179,6 +182,13 @@ reset_maya_texture(const Filename &texture) { //////////////////////////////////////////////////////////////////// void MayaShaderColorDef:: read_surface_color(MObject color) { + RGBColorf color_gain; + if (get_vec3f_attribute(color, "colorGain", color_gain)) { + _color_gain[0] *= color_gain[0]; + _color_gain[1] *= color_gain[1]; + _color_gain[2] *= color_gain[2]; + } + if (color.hasFn(MFn::kFileTexture)) { _color_object = new MObject(color); string filename; diff --git a/pandatool/src/maya/mayaShaderColorDef.h b/pandatool/src/maya/mayaShaderColorDef.h index d5502e29e2..759039214e 100755 --- a/pandatool/src/maya/mayaShaderColorDef.h +++ b/pandatool/src/maya/mayaShaderColorDef.h @@ -58,6 +58,7 @@ public: bool _has_texture; Filename _texture; + RGBColorf _color_gain; bool _has_flat_color; Colord _flat_color; diff --git a/pandatool/src/maya/maya_funcs.cxx b/pandatool/src/maya/maya_funcs.cxx index 5ae5f2b44f..5f09c83834 100644 --- a/pandatool/src/maya/maya_funcs.cxx +++ b/pandatool/src/maya/maya_funcs.cxx @@ -172,6 +172,43 @@ get_vec2f_attribute(MObject &node, const string &attribute_name, return true; } +//////////////////////////////////////////////////////////////////// +// Function: get_vec3f_attribute +// Description: Extracts the named three-component vector from the +// MObject. +//////////////////////////////////////////////////////////////////// +bool +get_vec3f_attribute(MObject &node, const string &attribute_name, + LVecBase3f &value) { + MStatus status; + + MObject vec3f_object; + if (!get_maya_attribute(node, attribute_name, vec3f_object)) { + maya_cat.error() + << "Attribute " << attribute_name + << " does not have a vec3f object value.\n"; + describe_maya_attribute(node, attribute_name); + return false; + } + + MFnNumericData data(vec3f_object, &status); + if (!status) { + maya_cat.error() + << "Attribute " << attribute_name << " is of type " + << vec3f_object.apiTypeStr() << ", not a NumericData.\n"; + return false; + } + + status = data.getData(value[0], value[1], value[2]); + if (!status) { + maya_cat.error() + << "Unable to extract 3 floats from " << attribute_name + << ", of type " << vec3f_object.apiTypeStr() << "\n"; + } + + return true; +} + //////////////////////////////////////////////////////////////////// // Function: get_vec2d_attribute // Description: Extracts the named two-component vector from the diff --git a/pandatool/src/maya/maya_funcs.h b/pandatool/src/maya/maya_funcs.h index a7a30a91a5..635ade773f 100644 --- a/pandatool/src/maya/maya_funcs.h +++ b/pandatool/src/maya/maya_funcs.h @@ -63,6 +63,10 @@ bool get_vec2f_attribute(MObject &node, const string &attribute_name, LVecBase2f &value); +bool +get_vec3f_attribute(MObject &node, const string &attribute_name, + LVecBase3f &value); + bool get_vec2d_attribute(MObject &node, const string &attribute_name, LVecBase2d &value); diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index 5c39189720..82cc2f3bf1 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -1940,6 +1940,11 @@ set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader) { } } + // But the color gain always gets applied. + rgba[0] *= color_def._color_gain[0]; + rgba[1] *= color_def._color_gain[1]; + rgba[2] *= color_def._color_gain[2]; + primitive.set_color(rgba); }