20 #include <maya/MStatus.h> 21 #include <maya/MObject.h> 22 #include <maya/MFnDependencyNode.h> 23 #include <maya/MFnMesh.h> 24 #include <maya/MObjectArray.h> 25 #include <maya/MPlug.h> 26 #include <maya/MPlugArray.h> 53 MFnDependencyNode node_fn(node);
55 MObject iog_attr = node_fn.attribute(
"instObjGroups", &status);
59 << node_fn.name().asChar() <<
" : not a renderable object.\n";
67 MPlug iog_plug(node, iog_attr);
69 iog_plug.elementByLogicalIndex(0).connectedTo(iog_pa,
false,
true, &status);
73 << node_fn.name().asChar() <<
" : no shading group defined.\n";
82 for (i = 0; i < iog_pa.length(); i++) {
83 MObject engine = iog_pa[i].node();
84 if (engine.hasFn(MFn::kShadingEngine)) {
91 << node_fn.name().asChar() <<
" : no shading engine found.\n";
100 _uvset_names.clear();
101 _file_to_uvset.clear();
103 if (mesh.hasFn(MFn::kMesh)) {
104 MFnMesh mesh_fn(mesh);
106 MStringArray maya_uvset_names;
107 status = mesh_fn.getUVSetNames(maya_uvset_names);
108 for (
size_t i=0; i<maya_uvset_names.length(); ++i) {
110 string uvset_name = maya_uvset_names[i].asChar();
111 _uvset_names.push_back(uvset_name);
112 mesh_fn.getAssociatedUVSetTextures(maya_uvset_names[i], moa);
113 for (
size_t j=0; j<moa.length(); ++j){
114 MFnDependencyNode dt(moa[j]);
115 string tex_name = dt.name().asChar();
116 _file_to_uvset[tex_name] = uvset_name;
121 Shaders::iterator sha;
122 for (sha=_shaders.begin(); sha!=_shaders.end(); sha++) {
123 (*sha).second->bind_uvsets(_file_to_uvset);
134 MFnDependencyNode engine_fn(engine);
136 string engine_name = engine_fn.name().asChar();
137 Shaders::const_iterator si = _shaders.find(engine_name);
138 if (si != _shaders.end()) {
148 _shaders.insert(Shaders::value_type(engine_name, shader));
149 _shaders_in_order.push_back(shader);
159 MayaFileToUVSetMap::iterator it = _file_to_uvset.find(match);
160 if (it == _file_to_uvset.end()) {
172 return _shaders_in_order.size();
180 nassertr(n >= 0 && n < (
int)_shaders_in_order.size(),
nullptr);
181 return _shaders_in_order[n];
190 ShadersInOrder::iterator si;
191 for (si = _shaders_in_order.begin(); si != _shaders_in_order.end(); ++si) {
196 _shaders_in_order.clear();
197 _file_to_uvset.clear();
void bind_uvsets(MObject mesh)
Causes all shaders in the set to use the given mesh as a file-to-uvset map.
MayaShader * find_shader_for_node(MObject node, bool legacy_shader)
Extracts the shader assigned to the indicated node.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
MayaShader * get_shader(int n) const
Returns the nth MayaShader that has been discovered so far.
Corresponds to a single "shader" in Maya.
MayaShader * find_shader_for_shading_engine(MObject engine, bool legacy_shader)
Returns the MayaShader object associated with the indicated "shading engine".
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
MayaShader(MObject engine, bool legacy_shader)
Reads the Maya "shading engine" to determine the relevant shader properties.
std::string find_uv_link(const std::string &match)
Returns the current mapping from file to uvset for the given file texture name.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void clear()
Frees all of the previously-defined MayaShader objects associated with this set.
int get_num_shaders() const
Returns the number of unique MayaShaders that have been discovered so far.
void bind_uvsets(MayaFileToUVSetMap &map)
Assigns the uvset_name of each MayaShaderColorDef using the given file-to- uvset map.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.