Panda3D
mayaShaderColorDef.h
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 
15 #ifndef MAYASHADERCOLORDEF_H
16 #define MAYASHADERCOLORDEF_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "luse.h"
21 #include "lmatrix.h"
22 #include "pmap.h"
23 #include "pvector.h"
24 
25 class MObject;
26 class MPlug;
27 class MayaShader;
28 class MayaShaderColorDef;
31 
32 ////////////////////////////////////////////////////////////////////
33 // Class : MayaShaderColorDef
34 // Description : This defines the various attributes that Maya may
35 // associate with the "color" channel for a particular
36 // shader (as well as on the "transparency" channel).
37 ////////////////////////////////////////////////////////////////////
39 public:
43 
44  string strip_prefix(string full_name);
45 
47  bool has_projection() const;
48  LTexCoordd project_uv(const LPoint3d &pos, const LPoint3d &ref_point) const;
49  bool reset_maya_texture(const Filename &texture);
50 
51  void write(ostream &out) const;
52 
53  enum BlendType {
54  BT_unspecified,
55  BT_modulate,
56  BT_decal,
57  BT_blend,
58  BT_replace,
59  BT_add,
60  BT_blend_color_scale,
61  BT_modulate_glow,
62  BT_modulate_gloss,
63  BT_normal,
64  BT_normal_height,
65  BT_gloss,
66  BT_glow,
67  BT_height,
68  BT_selector,
69  };
70 
71  enum ProjectionType {
72  PT_off,
73  PT_planar,
74  PT_spherical,
75  PT_cylindrical,
76  PT_ball,
77  PT_cubic,
78  PT_triplanar,
79  PT_concentric,
80  PT_perspective,
81  };
82 
83  BlendType _blend_type;
84  ProjectionType _projection_type;
85  LMatrix4d _projection_matrix;
86  double _u_angle;
87  double _v_angle;
88 
89  Filename _texture_filename;
90  string _texture_name;
91  LColor _color_gain;
92 
93  LVector2 _coverage;
94  LVector2 _translate_frame;
95  double _rotate_frame;
96 
97  bool _mirror;
98  bool _stagger;
99  bool _wrap_u;
100  bool _wrap_v;
101 
102  LVector2 _repeat_uv;
103  LVector2 _offset;
104  double _rotate_uv;
105 
106  bool _is_alpha;
107 
108  string _uvset_name;
109  MayaShaderColorDef *_opposite;
110 
111  string get_panda_uvset_name();
112 
113 private:
114  MObject *_color_object;
115 
116 private:
117  static void find_textures_modern(const string &shadername, MayaShaderColorList &list, MPlug inplug, bool is_alpha);
118  void find_textures_legacy(MayaShader *shader, MObject color, bool trans=false);
119 
120  void set_projection_type(const string &type);
121 
122  LPoint2d map_planar(const LPoint3d &pos, const LPoint3d &centroid) const;
123  LPoint2d map_spherical(const LPoint3d &pos, const LPoint3d &centroid) const;
124  LPoint2d map_cylindrical(const LPoint3d &pos, const LPoint3d &centroid) const;
125 
126  // Define a pointer to one of the above member functions.
127  LPoint2d (MayaShaderColorDef::*_map_uvs)(const LPoint3d &pos, const LPoint3d &centroid) const;
128 
129  friend class MayaShader;
130 
131 
132  // Legacy Fields - these fields are only used by the
133  // legacy codepath. These fields are deprecated for the
134  // following reasons:
135  //
136  // * has_texture is redundant --- if there's no
137  // texture, just don't allocate a MayaShaderColorDef.
138  //
139  // * has_flat_color and flat_color don't belong here,
140  // they belong in the shader.
141  //
142  // * has_alpha_channel is not needed - there are better
143  // ways to determine if a texture stage involves an alpha
144  // channel.
145  //
146  // * keep_color, keep_alpha, and interpolate are all
147  // adjuncts to blend_mode - it would make more sense just to
148  // add some more blend_modes.
149 
150 public:
151  bool _has_texture; // deprecated, see above.
152  bool _has_flat_color; // deprecated, see above.
153  LColord _flat_color; // deprecated, see above.
154  bool _has_alpha_channel; // deprecated, see above.
155  bool _keep_color; // deprecated, see above.
156  bool _keep_alpha; // deprecated, see above.
157  bool _interpolate; // deprecated, see above.
158 
159 };
160 
161 #endif
162 
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
LTexCoordd project_uv(const LPoint3d &pos, const LPoint3d &ref_point) const
If the shader has a projection (has_projection() returns true), this computes the appropriate UV corr...
string get_panda_uvset_name()
Maya's default uvset name is "map1".
bool has_projection() const
Returns true if the shader has a projection in effect.
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:1677
LMatrix3d compute_texture_matrix() const
Returns a texture matrix corresponding to the texture transforms indicated by the shader...
This is a two-component point in space.
Definition: lpoint2.h:424
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:4375
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This defines the various attributes that Maya may associate with the "color" channel for a particular...
Corresponds to a single "shader" in Maya.
Definition: mayaShader.h:35
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is a two-component vector offset.
Definition: lvector2.h:91
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:544
bool reset_maya_texture(const Filename &texture)
Changes the texture filename stored in the Maya file for this particular shader.