Pārlūkot izejas kodu

support color gain

David Rose 23 gadi atpakaļ
vecāks
revīzija
05b08da109

+ 11 - 1
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;

+ 1 - 0
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;

+ 37 - 0
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

+ 4 - 0
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);

+ 5 - 0
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);
 }