move mayaShader into maya

This commit is contained in:
David Rose 2002-05-13 16:18:12 +00:00
parent 213d45c53c
commit 9cea8f3074
8 changed files with 69 additions and 79 deletions

View File

@ -13,6 +13,8 @@
#define SOURCES \
config_maya.cxx config_maya.h \
mayaApi.cxx mayaApi.h \
mayaShader.cxx mayaShader.h \
mayaShaders.cxx mayaShaders.h \
maya_funcs.I maya_funcs.cxx maya_funcs.h \
post_maya_include.h pre_maya_include.h

View File

@ -18,12 +18,7 @@
#include "mayaShader.h"
#include "maya_funcs.h"
#include "mayaToEggConverter.h"
#include "config_mayaegg.h"
#include "eggPrimitive.h"
#include "eggTexture.h"
#include "eggTextureCollection.h"
#include "config_maya.h"
#include "pre_maya_include.h"
#include <maya/MFnDependencyNode.h>
@ -42,9 +37,7 @@
// relevant shader properties.
////////////////////////////////////////////////////////////////////
MayaShader::
MayaShader(MObject engine, MayaToEggConverter *converter) :
_converter(converter)
{
MayaShader(MObject engine) {
_has_color = false;
_transparency = 0.0;
@ -67,8 +60,8 @@ MayaShader(MObject engine, MayaToEggConverter *converter) :
_name = engine_fn.name().asChar();
if (mayaegg_cat.is_debug()) {
mayaegg_cat.debug()
if (maya_cat.is_debug()) {
maya_cat.debug()
<< "Reading shading engine " << _name << "\n";
}
@ -85,44 +78,6 @@ MayaShader(MObject engine, MayaToEggConverter *converter) :
}
}
////////////////////////////////////////////////////////////////////
// Function: MayaShader::set_attributes
// Access: Public
// Description: Applies the known shader attributes to the indicated
// egg primitive.
////////////////////////////////////////////////////////////////////
void MayaShader::
set_attributes(EggPrimitive &primitive, MayaToEggConverter &conv) {
// In Maya, a polygon is either textured or colored. The texture,
// if present, replaces the color.
if (_has_texture) {
EggTextureCollection &textures = conv._textures;
Filename pathname = _converter->convert_texture_path(_texture);
EggTexture tex(_name, pathname);
tex.set_wrap_u(_wrap_u ? EggTexture::WM_repeat : EggTexture::WM_clamp);
tex.set_wrap_v(_wrap_v ? EggTexture::WM_repeat : EggTexture::WM_clamp);
// Let's mipmap all textures by default.
tex.set_minfilter(EggTexture::FT_linear_mipmap_linear);
tex.set_magfilter(EggTexture::FT_linear);
LMatrix3d mat = compute_texture_matrix();
if (!mat.almost_equal(LMatrix3d::ident_mat())) {
tex.set_transform(mat);
}
EggTexture *new_tex =
textures.create_unique_texture(tex, ~EggTexture::E_tref_name);
primitive.set_texture(new_tex);
} else if (_has_color) {
primitive.set_color(Colorf(_color[0], _color[1], _color[2], 1.0));
}
}
////////////////////////////////////////////////////////////////////
// Function: MayaShader::compute_texture_matrix
// Access: Public
@ -181,8 +136,8 @@ read_surface_shader(MObject shader) {
MStatus status;
MFnDependencyNode shader_fn(shader);
if (mayaegg_cat.is_spam()) {
mayaegg_cat.spam()
if (maya_cat.is_spam()) {
maya_cat.spam()
<< " Reading surface shader " << shader_fn.name() << "\n";
}
@ -212,8 +167,8 @@ read_surface_shader(MObject shader) {
}
if (!_has_color && !_has_texture) {
if (mayaegg_cat.is_spam()) {
mayaegg_cat.spam()
if (maya_cat.is_spam()) {
maya_cat.spam()
<< " Color definition not found.\n";
}
}
@ -251,8 +206,8 @@ read_surface_color(MObject color) {
} else {
// This shader wasn't understood.
if (mayaegg_cat.is_debug()) {
mayaegg_cat.info()
if (maya_cat.is_debug()) {
maya_cat.info()
<< "**Don't know how to interpret color attribute type "
<< color.apiTypeStr() << "\n";
@ -261,7 +216,7 @@ read_surface_color(MObject color) {
// of unsupportted shader once.
static pset<MFn::Type> bad_types;
if (bad_types.insert(color.apiType()).second) {
mayaegg_cat.info()
maya_cat.info()
<< "**Don't know how to interpret color attribute type "
<< color.apiTypeStr() << "\n";
}

View File

@ -25,20 +25,19 @@
#include "lmatrix.h"
class MObject;
class MayaToEggConverter;
class EggPrimitive;
////////////////////////////////////////////////////////////////////
// Class : MayaShader
// Description : Corresponds to a single "shader" in Maya. This
// extracts out all the parameters of a Maya shader that
// are meaningful to egg.
// we might care about. There are many more parameters
// that we don't care about or don't know enough to
// extract.
////////////////////////////////////////////////////////////////////
class MayaShader {
public:
MayaShader(MObject engine, MayaToEggConverter *converter);
MayaShader(MObject engine);
void set_attributes(EggPrimitive &primitive, MayaToEggConverter &conv);
LMatrix3d compute_texture_matrix();
void output(ostream &out) const;
@ -68,11 +67,9 @@ public:
private:
bool read_surface_shader(MObject shader);
void read_surface_color(MObject color);
MayaToEggConverter *_converter;
};
inline ostream &operator << (ostream &out, const MayaShader &shader) {
INLINE ostream &operator << (ostream &out, const MayaShader &shader) {
shader.output(out);
return out;
}

View File

@ -19,7 +19,7 @@
#include "mayaShaders.h"
#include "mayaShader.h"
#include "maya_funcs.h"
#include "config_mayaegg.h"
#include "config_maya.h"
#include "pre_maya_include.h"
#include <maya/MStatus.h>
@ -36,9 +36,7 @@
// Description:
////////////////////////////////////////////////////////////////////
MayaShaders::
MayaShaders(MayaToEggConverter *converter) :
_converter(converter)
{
MayaShaders() {
}
////////////////////////////////////////////////////////////////////
@ -65,7 +63,7 @@ find_shader_for_node(MObject node) {
MObject iog_attr = node_fn.attribute("instObjGroups", &status);
if (!status) {
// The node is not renderable. What are you thinking?
mayaegg_cat.error()
maya_cat.error()
<< node_fn.name() << " : not a renderable object.\n";
return (MayaShader *)NULL;
}
@ -79,7 +77,7 @@ find_shader_for_node(MObject node) {
iog_plug.elementByLogicalIndex(0).connectedTo(iog_pa, false, true, &status);
if (!status) {
// No shading group defined for this object.
mayaegg_cat.error()
maya_cat.error()
<< node_fn.name() << " : no shading group defined.\n";
return (MayaShader *)NULL;
}
@ -97,7 +95,7 @@ find_shader_for_node(MObject node) {
}
// Well, we didn't find a ShadingEngine after all. Huh.
mayaegg_cat.info()
maya_cat.info()
<< node_fn.name() << " : no shading engine found.\n";
return (MayaShader *)NULL;
}
@ -123,7 +121,7 @@ find_shader_for_shading_engine(MObject engine) {
// All right, this is a newly encountered shading engine. Create a
// new MayaShader object to represent it.
MayaShader *shader = new MayaShader(engine, _converter);
MayaShader *shader = new MayaShader(engine);
// Record this for the future.
_shaders.insert(Shaders::value_type(engine_name, shader));

View File

@ -24,7 +24,6 @@
#include "pmap.h"
class MayaShader;
class MayaToEggConverter;
class MObject;
////////////////////////////////////////////////////////////////////
@ -34,7 +33,7 @@ class MObject;
////////////////////////////////////////////////////////////////////
class MayaShaders {
public:
MayaShaders(MayaToEggConverter *converter);
MayaShaders();
~MayaShaders();
MayaShader *find_shader_for_node(MObject node);
MayaShader *find_shader_for_shading_engine(MObject engine);
@ -44,8 +43,6 @@ public:
private:
typedef pmap<string, MayaShader *> Shaders;
Shaders _shaders;
MayaToEggConverter *_converter;
};
#endif

View File

@ -16,8 +16,6 @@
#define SOURCES \
config_mayaegg.cxx config_mayaegg.h \
mayaShader.cxx mayaShader.h \
mayaShaders.cxx mayaShaders.h \
mayaToEggConverter.cxx mayaToEggConverter.h
#end ss_lib_target

View File

@ -28,6 +28,9 @@
#include "eggNurbsSurface.h"
#include "eggNurbsCurve.h"
#include "eggPolygon.h"
#include "eggPrimitive.h"
#include "eggTexture.h"
#include "eggTextureCollection.h"
#include "string_utils.h"
#include "pre_maya_include.h"
@ -627,7 +630,7 @@ make_nurbs_surface(const MDagPath &dag_path, MFnNurbsSurface &surface,
egg_group->add_child(egg_nurbs);
if (shader != (MayaShader *)NULL) {
shader->set_attributes(*egg_nurbs, *this);
set_shader_attributes(*egg_nurbs, *shader);
}
}
@ -979,3 +982,40 @@ get_egg_group(const string &name, EggData &data) {
_groups.insert(Groups::value_type(name, egg_group));
return egg_group;
}
////////////////////////////////////////////////////////////////////
// Function: MayaShader::set_shader_attributes
// Access: Public
// Description: Applies the known shader attributes to the indicated
// egg primitive.
////////////////////////////////////////////////////////////////////
void MayaToEggConverter::
set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader) {
// In Maya, a polygon is either textured or colored. The texture,
// if present, replaces the color.
if (shader._has_texture) {
Filename pathname = convert_texture_path(_texture);
EggTexture tex(shader._name, pathname);
tex.set_wrap_u(shader._wrap_u ? EggTexture::WM_repeat : EggTexture::WM_clamp);
tex.set_wrap_v(shader._wrap_v ? EggTexture::WM_repeat : EggTexture::WM_clamp);
// Let's mipmap all textures by default.
tex.set_minfilter(EggTexture::FT_linear_mipmap_linear);
tex.set_magfilter(EggTexture::FT_linear);
LMatrix3d mat = shader.compute_texture_matrix();
if (!mat.almost_equal(LMatrix3d::ident_mat())) {
tex.set_transform(mat);
}
EggTexture *new_tex =
_textures.create_unique_texture(tex, ~EggTexture::E_tref_name);
primitive.set_texture(new_tex);
} else if (shader._has_color) {
primitive.set_color(Colorf(shader._color[0], shader._color[1],
shader._color[2], 1.0f));
}
}

View File

@ -32,6 +32,7 @@ class EggData;
class EggGroup;
class EggVertexPool;
class EggNurbsCurve;
class EggPrimitive;
class MDagPath;
class MFnNurbsSurface;
@ -89,6 +90,8 @@ private:
MayaShader *default_shader = NULL);
EggGroup *get_egg_group(const string &name, EggData &data);
void set_shader_attributes(EggPrimitive &primitive,
const MayaShader &shader);
typedef pmap<string, EggGroup *> Groups;
Groups _groups;