Panda3D
 All Classes Functions Variables Enumerations
mayaShaderColorDef.h
00001 // Filename: mayaShaderColorDef.h
00002 // Created by:  drose (12Apr03)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef MAYASHADERCOLORDEF_H
00016 #define MAYASHADERCOLORDEF_H
00017 
00018 #include "pandatoolbase.h"
00019 
00020 #include "luse.h"
00021 #include "lmatrix.h"
00022 #include "pmap.h"
00023 #include "pvector.h"
00024 
00025 class MObject;
00026 class MPlug;
00027 class MayaShader;
00028 class MayaShaderColorDef;
00029 typedef pvector<MayaShaderColorDef *> MayaShaderColorList;
00030 typedef pmap<string, string> MayaFileToUVSetMap;
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //       Class : MayaShaderColorDef
00034 // Description : This defines the various attributes that Maya may
00035 //               associate with the "color" channel for a particular
00036 //               shader (as well as on the "transparency" channel).
00037 ////////////////////////////////////////////////////////////////////
00038 class MayaShaderColorDef {
00039 public:
00040   MayaShaderColorDef();
00041   MayaShaderColorDef (MayaShaderColorDef&);
00042   ~MayaShaderColorDef();
00043 
00044   string strip_prefix(string full_name);
00045   
00046   LMatrix3d compute_texture_matrix() const;
00047   bool has_projection() const;
00048   LTexCoordd project_uv(const LPoint3d &pos, const LPoint3d &ref_point) const;
00049   bool reset_maya_texture(const Filename &texture);
00050   
00051   void write(ostream &out) const;
00052 
00053   enum BlendType {
00054     BT_unspecified, 
00055     BT_modulate, 
00056     BT_decal,
00057     BT_blend,
00058     BT_replace,
00059     BT_add,
00060     BT_blend_color_scale,
00061     BT_modulate_glow,
00062     BT_modulate_gloss,
00063     BT_normal,
00064     BT_normal_height,
00065     BT_gloss,
00066     BT_glow,
00067     BT_height,
00068     BT_selector,
00069   };
00070 
00071   enum ProjectionType {
00072     PT_off,
00073     PT_planar,
00074     PT_spherical,
00075     PT_cylindrical,
00076     PT_ball,
00077     PT_cubic,
00078     PT_triplanar,
00079     PT_concentric,
00080     PT_perspective,
00081   };
00082   
00083   BlendType _blend_type;
00084   ProjectionType _projection_type;
00085   LMatrix4d _projection_matrix;
00086   double _u_angle;
00087   double _v_angle;
00088     
00089   Filename _texture_filename;
00090   string _texture_name;
00091   LColor _color_gain;
00092   
00093   LVector2 _coverage;
00094   LVector2 _translate_frame;
00095   double _rotate_frame;
00096   
00097   bool _mirror;
00098   bool _stagger;
00099   bool _wrap_u;
00100   bool _wrap_v;
00101 
00102   LVector2 _repeat_uv;
00103   LVector2 _offset;
00104   double _rotate_uv;
00105 
00106   bool _is_alpha;
00107   
00108   string _uvset_name;
00109   MayaShaderColorDef *_opposite;
00110   
00111   string get_panda_uvset_name();
00112 
00113 private:
00114   MObject *_color_object;
00115   
00116 private:
00117   static void find_textures_modern(const string &shadername, MayaShaderColorList &list, MPlug inplug, bool is_alpha);
00118   void find_textures_legacy(MayaShader *shader, MObject color, bool trans=false);
00119 
00120   void set_projection_type(const string &type);
00121 
00122   LPoint2d map_planar(const LPoint3d &pos, const LPoint3d &centroid) const;
00123   LPoint2d map_spherical(const LPoint3d &pos, const LPoint3d &centroid) const;
00124   LPoint2d map_cylindrical(const LPoint3d &pos, const LPoint3d &centroid) const;
00125 
00126   // Define a pointer to one of the above member functions.
00127   LPoint2d (MayaShaderColorDef::*_map_uvs)(const LPoint3d &pos, const LPoint3d &centroid) const;
00128   
00129   friend class MayaShader;
00130 
00131 
00132   // Legacy Fields - these fields are only used by the
00133   // legacy codepath.  These fields are deprecated for the
00134   // following reasons:
00135   //
00136   // * has_texture is redundant --- if there's no
00137   // texture, just don't allocate a MayaShaderColorDef.
00138   //
00139   // * has_flat_color and flat_color don't belong here,
00140   // they belong in the shader. 
00141   //
00142   // * has_alpha_channel is not needed - there are better
00143   // ways to determine if a texture stage involves an alpha
00144   // channel.
00145   //
00146   // * keep_color, keep_alpha, and interpolate are all
00147   // adjuncts to blend_mode - it would make more sense just to
00148   // add some more blend_modes.  
00149 
00150 public:
00151   bool     _has_texture;       // deprecated, see above.
00152   bool     _has_flat_color;    // deprecated, see above.
00153   LColord   _flat_color;        // deprecated, see above.
00154   bool     _has_alpha_channel; // deprecated, see above.
00155   bool     _keep_color;        // deprecated, see above.
00156   bool     _keep_alpha;        // deprecated, see above.
00157   bool     _interpolate;       // deprecated, see above.
00158 
00159 };
00160 
00161 #endif
00162 
 All Classes Functions Variables Enumerations