mayaShaderColorDef.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Filename: mayaShaderColorDef.h
  2. // Created by: drose (12Apr03)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef MAYASHADERCOLORDEF_H
  15. #define MAYASHADERCOLORDEF_H
  16. #include "pandatoolbase.h"
  17. #include "luse.h"
  18. #include "lmatrix.h"
  19. #include "pmap.h"
  20. #include "pvector.h"
  21. class MObject;
  22. class MPlug;
  23. class MayaShader;
  24. class MayaShaderColorDef;
  25. typedef pvector<MayaShaderColorDef *> MayaShaderColorList;
  26. typedef pmap<string, string> MayaFileToUVSetMap;
  27. ////////////////////////////////////////////////////////////////////
  28. // Class : MayaShaderColorDef
  29. // Description : This defines the various attributes that Maya may
  30. // associate with the "color" channel for a particular
  31. // shader (as well as on the "transparency" channel).
  32. ////////////////////////////////////////////////////////////////////
  33. class MayaShaderColorDef {
  34. public:
  35. MayaShaderColorDef();
  36. MayaShaderColorDef (MayaShaderColorDef&);
  37. ~MayaShaderColorDef();
  38. string strip_prefix(string full_name);
  39. LMatrix3d compute_texture_matrix() const;
  40. bool has_projection() const;
  41. LTexCoordd project_uv(const LPoint3d &pos, const LPoint3d &ref_point) const;
  42. bool reset_maya_texture(const Filename &texture);
  43. void write(ostream &out) const;
  44. enum BlendType {
  45. BT_unspecified,
  46. BT_modulate,
  47. BT_decal,
  48. BT_blend,
  49. BT_replace,
  50. BT_add,
  51. BT_blend_color_scale,
  52. BT_modulate_glow,
  53. BT_modulate_gloss,
  54. BT_normal,
  55. BT_normal_height,
  56. BT_gloss,
  57. BT_glow,
  58. BT_height,
  59. BT_selector,
  60. };
  61. enum ProjectionType {
  62. PT_off,
  63. PT_planar,
  64. PT_spherical,
  65. PT_cylindrical,
  66. PT_ball,
  67. PT_cubic,
  68. PT_triplanar,
  69. PT_concentric,
  70. PT_perspective,
  71. };
  72. BlendType _blend_type;
  73. ProjectionType _projection_type;
  74. LMatrix4d _projection_matrix;
  75. double _u_angle;
  76. double _v_angle;
  77. Filename _texture_filename;
  78. string _texture_name;
  79. LColor _color_gain;
  80. LVector2 _coverage;
  81. LVector2 _translate_frame;
  82. double _rotate_frame;
  83. bool _mirror;
  84. bool _stagger;
  85. bool _wrap_u;
  86. bool _wrap_v;
  87. LVector2 _repeat_uv;
  88. LVector2 _offset;
  89. double _rotate_uv;
  90. bool _is_alpha;
  91. string _uvset_name;
  92. MayaShaderColorDef *_opposite;
  93. string get_panda_uvset_name();
  94. private:
  95. MObject *_color_object;
  96. private:
  97. static void find_textures_modern(const string &shadername, MayaShaderColorList &list, MPlug inplug, bool is_alpha);
  98. void find_textures_legacy(MayaShader *shader, MObject color, bool trans=false);
  99. void set_projection_type(const string &type);
  100. LPoint2d map_planar(const LPoint3d &pos, const LPoint3d &centroid) const;
  101. LPoint2d map_spherical(const LPoint3d &pos, const LPoint3d &centroid) const;
  102. LPoint2d map_cylindrical(const LPoint3d &pos, const LPoint3d &centroid) const;
  103. // Define a pointer to one of the above member functions.
  104. LPoint2d (MayaShaderColorDef::*_map_uvs)(const LPoint3d &pos, const LPoint3d &centroid) const;
  105. friend class MayaShader;
  106. // Legacy Fields - these fields are only used by the
  107. // legacy codepath. These fields are deprecated for the
  108. // following reasons:
  109. //
  110. // * has_texture is redundant --- if there's no
  111. // texture, just don't allocate a MayaShaderColorDef.
  112. //
  113. // * has_flat_color and flat_color don't belong here,
  114. // they belong in the shader.
  115. //
  116. // * has_alpha_channel is not needed - there are better
  117. // ways to determine if a texture stage involves an alpha
  118. // channel.
  119. //
  120. // * keep_color, keep_alpha, and interpolate are all
  121. // adjuncts to blend_mode - it would make more sense just to
  122. // add some more blend_modes.
  123. public:
  124. bool _has_texture; // deprecated, see above.
  125. bool _has_flat_color; // deprecated, see above.
  126. LColord _flat_color; // deprecated, see above.
  127. bool _has_alpha_channel; // deprecated, see above.
  128. bool _keep_color; // deprecated, see above.
  129. bool _keep_alpha; // deprecated, see above.
  130. bool _interpolate; // deprecated, see above.
  131. };
  132. #endif