mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
move mayaShader into maya
This commit is contained in:
parent
213d45c53c
commit
9cea8f3074
@ -13,6 +13,8 @@
|
|||||||
#define SOURCES \
|
#define SOURCES \
|
||||||
config_maya.cxx config_maya.h \
|
config_maya.cxx config_maya.h \
|
||||||
mayaApi.cxx mayaApi.h \
|
mayaApi.cxx mayaApi.h \
|
||||||
|
mayaShader.cxx mayaShader.h \
|
||||||
|
mayaShaders.cxx mayaShaders.h \
|
||||||
maya_funcs.I maya_funcs.cxx maya_funcs.h \
|
maya_funcs.I maya_funcs.cxx maya_funcs.h \
|
||||||
post_maya_include.h pre_maya_include.h
|
post_maya_include.h pre_maya_include.h
|
||||||
|
|
||||||
|
@ -18,12 +18,7 @@
|
|||||||
|
|
||||||
#include "mayaShader.h"
|
#include "mayaShader.h"
|
||||||
#include "maya_funcs.h"
|
#include "maya_funcs.h"
|
||||||
#include "mayaToEggConverter.h"
|
#include "config_maya.h"
|
||||||
#include "config_mayaegg.h"
|
|
||||||
|
|
||||||
#include "eggPrimitive.h"
|
|
||||||
#include "eggTexture.h"
|
|
||||||
#include "eggTextureCollection.h"
|
|
||||||
|
|
||||||
#include "pre_maya_include.h"
|
#include "pre_maya_include.h"
|
||||||
#include <maya/MFnDependencyNode.h>
|
#include <maya/MFnDependencyNode.h>
|
||||||
@ -42,9 +37,7 @@
|
|||||||
// relevant shader properties.
|
// relevant shader properties.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
MayaShader::
|
MayaShader::
|
||||||
MayaShader(MObject engine, MayaToEggConverter *converter) :
|
MayaShader(MObject engine) {
|
||||||
_converter(converter)
|
|
||||||
{
|
|
||||||
_has_color = false;
|
_has_color = false;
|
||||||
_transparency = 0.0;
|
_transparency = 0.0;
|
||||||
|
|
||||||
@ -67,8 +60,8 @@ MayaShader(MObject engine, MayaToEggConverter *converter) :
|
|||||||
|
|
||||||
_name = engine_fn.name().asChar();
|
_name = engine_fn.name().asChar();
|
||||||
|
|
||||||
if (mayaegg_cat.is_debug()) {
|
if (maya_cat.is_debug()) {
|
||||||
mayaegg_cat.debug()
|
maya_cat.debug()
|
||||||
<< "Reading shading engine " << _name << "\n";
|
<< "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
|
// Function: MayaShader::compute_texture_matrix
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -181,8 +136,8 @@ read_surface_shader(MObject shader) {
|
|||||||
MStatus status;
|
MStatus status;
|
||||||
MFnDependencyNode shader_fn(shader);
|
MFnDependencyNode shader_fn(shader);
|
||||||
|
|
||||||
if (mayaegg_cat.is_spam()) {
|
if (maya_cat.is_spam()) {
|
||||||
mayaegg_cat.spam()
|
maya_cat.spam()
|
||||||
<< " Reading surface shader " << shader_fn.name() << "\n";
|
<< " Reading surface shader " << shader_fn.name() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,8 +167,8 @@ read_surface_shader(MObject shader) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!_has_color && !_has_texture) {
|
if (!_has_color && !_has_texture) {
|
||||||
if (mayaegg_cat.is_spam()) {
|
if (maya_cat.is_spam()) {
|
||||||
mayaegg_cat.spam()
|
maya_cat.spam()
|
||||||
<< " Color definition not found.\n";
|
<< " Color definition not found.\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,8 +206,8 @@ read_surface_color(MObject color) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// This shader wasn't understood.
|
// This shader wasn't understood.
|
||||||
if (mayaegg_cat.is_debug()) {
|
if (maya_cat.is_debug()) {
|
||||||
mayaegg_cat.info()
|
maya_cat.info()
|
||||||
<< "**Don't know how to interpret color attribute type "
|
<< "**Don't know how to interpret color attribute type "
|
||||||
<< color.apiTypeStr() << "\n";
|
<< color.apiTypeStr() << "\n";
|
||||||
|
|
||||||
@ -261,7 +216,7 @@ read_surface_color(MObject color) {
|
|||||||
// of unsupportted shader once.
|
// of unsupportted shader once.
|
||||||
static pset<MFn::Type> bad_types;
|
static pset<MFn::Type> bad_types;
|
||||||
if (bad_types.insert(color.apiType()).second) {
|
if (bad_types.insert(color.apiType()).second) {
|
||||||
mayaegg_cat.info()
|
maya_cat.info()
|
||||||
<< "**Don't know how to interpret color attribute type "
|
<< "**Don't know how to interpret color attribute type "
|
||||||
<< color.apiTypeStr() << "\n";
|
<< color.apiTypeStr() << "\n";
|
||||||
}
|
}
|
@ -25,20 +25,19 @@
|
|||||||
#include "lmatrix.h"
|
#include "lmatrix.h"
|
||||||
|
|
||||||
class MObject;
|
class MObject;
|
||||||
class MayaToEggConverter;
|
|
||||||
class EggPrimitive;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Class : MayaShader
|
// Class : MayaShader
|
||||||
// Description : Corresponds to a single "shader" in Maya. This
|
// Description : Corresponds to a single "shader" in Maya. This
|
||||||
// extracts out all the parameters of a Maya shader that
|
// 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 {
|
class MayaShader {
|
||||||
public:
|
public:
|
||||||
MayaShader(MObject engine, MayaToEggConverter *converter);
|
MayaShader(MObject engine);
|
||||||
|
|
||||||
void set_attributes(EggPrimitive &primitive, MayaToEggConverter &conv);
|
|
||||||
LMatrix3d compute_texture_matrix();
|
LMatrix3d compute_texture_matrix();
|
||||||
|
|
||||||
void output(ostream &out) const;
|
void output(ostream &out) const;
|
||||||
@ -68,11 +67,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool read_surface_shader(MObject shader);
|
bool read_surface_shader(MObject shader);
|
||||||
void read_surface_color(MObject color);
|
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);
|
shader.output(out);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
@ -19,7 +19,7 @@
|
|||||||
#include "mayaShaders.h"
|
#include "mayaShaders.h"
|
||||||
#include "mayaShader.h"
|
#include "mayaShader.h"
|
||||||
#include "maya_funcs.h"
|
#include "maya_funcs.h"
|
||||||
#include "config_mayaegg.h"
|
#include "config_maya.h"
|
||||||
|
|
||||||
#include "pre_maya_include.h"
|
#include "pre_maya_include.h"
|
||||||
#include <maya/MStatus.h>
|
#include <maya/MStatus.h>
|
||||||
@ -36,9 +36,7 @@
|
|||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
MayaShaders::
|
MayaShaders::
|
||||||
MayaShaders(MayaToEggConverter *converter) :
|
MayaShaders() {
|
||||||
_converter(converter)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -65,7 +63,7 @@ find_shader_for_node(MObject node) {
|
|||||||
MObject iog_attr = node_fn.attribute("instObjGroups", &status);
|
MObject iog_attr = node_fn.attribute("instObjGroups", &status);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
// The node is not renderable. What are you thinking?
|
// The node is not renderable. What are you thinking?
|
||||||
mayaegg_cat.error()
|
maya_cat.error()
|
||||||
<< node_fn.name() << " : not a renderable object.\n";
|
<< node_fn.name() << " : not a renderable object.\n";
|
||||||
return (MayaShader *)NULL;
|
return (MayaShader *)NULL;
|
||||||
}
|
}
|
||||||
@ -79,7 +77,7 @@ find_shader_for_node(MObject node) {
|
|||||||
iog_plug.elementByLogicalIndex(0).connectedTo(iog_pa, false, true, &status);
|
iog_plug.elementByLogicalIndex(0).connectedTo(iog_pa, false, true, &status);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
// No shading group defined for this object.
|
// No shading group defined for this object.
|
||||||
mayaegg_cat.error()
|
maya_cat.error()
|
||||||
<< node_fn.name() << " : no shading group defined.\n";
|
<< node_fn.name() << " : no shading group defined.\n";
|
||||||
return (MayaShader *)NULL;
|
return (MayaShader *)NULL;
|
||||||
}
|
}
|
||||||
@ -97,7 +95,7 @@ find_shader_for_node(MObject node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Well, we didn't find a ShadingEngine after all. Huh.
|
// Well, we didn't find a ShadingEngine after all. Huh.
|
||||||
mayaegg_cat.info()
|
maya_cat.info()
|
||||||
<< node_fn.name() << " : no shading engine found.\n";
|
<< node_fn.name() << " : no shading engine found.\n";
|
||||||
return (MayaShader *)NULL;
|
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
|
// All right, this is a newly encountered shading engine. Create a
|
||||||
// new MayaShader object to represent it.
|
// new MayaShader object to represent it.
|
||||||
MayaShader *shader = new MayaShader(engine, _converter);
|
MayaShader *shader = new MayaShader(engine);
|
||||||
|
|
||||||
// Record this for the future.
|
// Record this for the future.
|
||||||
_shaders.insert(Shaders::value_type(engine_name, shader));
|
_shaders.insert(Shaders::value_type(engine_name, shader));
|
@ -24,7 +24,6 @@
|
|||||||
#include "pmap.h"
|
#include "pmap.h"
|
||||||
|
|
||||||
class MayaShader;
|
class MayaShader;
|
||||||
class MayaToEggConverter;
|
|
||||||
class MObject;
|
class MObject;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -34,7 +33,7 @@ class MObject;
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class MayaShaders {
|
class MayaShaders {
|
||||||
public:
|
public:
|
||||||
MayaShaders(MayaToEggConverter *converter);
|
MayaShaders();
|
||||||
~MayaShaders();
|
~MayaShaders();
|
||||||
MayaShader *find_shader_for_node(MObject node);
|
MayaShader *find_shader_for_node(MObject node);
|
||||||
MayaShader *find_shader_for_shading_engine(MObject engine);
|
MayaShader *find_shader_for_shading_engine(MObject engine);
|
||||||
@ -44,8 +43,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
typedef pmap<string, MayaShader *> Shaders;
|
typedef pmap<string, MayaShader *> Shaders;
|
||||||
Shaders _shaders;
|
Shaders _shaders;
|
||||||
|
|
||||||
MayaToEggConverter *_converter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
#define SOURCES \
|
#define SOURCES \
|
||||||
config_mayaegg.cxx config_mayaegg.h \
|
config_mayaegg.cxx config_mayaegg.h \
|
||||||
mayaShader.cxx mayaShader.h \
|
|
||||||
mayaShaders.cxx mayaShaders.h \
|
|
||||||
mayaToEggConverter.cxx mayaToEggConverter.h
|
mayaToEggConverter.cxx mayaToEggConverter.h
|
||||||
|
|
||||||
#end ss_lib_target
|
#end ss_lib_target
|
||||||
|
@ -28,6 +28,9 @@
|
|||||||
#include "eggNurbsSurface.h"
|
#include "eggNurbsSurface.h"
|
||||||
#include "eggNurbsCurve.h"
|
#include "eggNurbsCurve.h"
|
||||||
#include "eggPolygon.h"
|
#include "eggPolygon.h"
|
||||||
|
#include "eggPrimitive.h"
|
||||||
|
#include "eggTexture.h"
|
||||||
|
#include "eggTextureCollection.h"
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
|
|
||||||
#include "pre_maya_include.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);
|
egg_group->add_child(egg_nurbs);
|
||||||
|
|
||||||
if (shader != (MayaShader *)NULL) {
|
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));
|
_groups.insert(Groups::value_type(name, egg_group));
|
||||||
return 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -32,6 +32,7 @@ class EggData;
|
|||||||
class EggGroup;
|
class EggGroup;
|
||||||
class EggVertexPool;
|
class EggVertexPool;
|
||||||
class EggNurbsCurve;
|
class EggNurbsCurve;
|
||||||
|
class EggPrimitive;
|
||||||
|
|
||||||
class MDagPath;
|
class MDagPath;
|
||||||
class MFnNurbsSurface;
|
class MFnNurbsSurface;
|
||||||
@ -89,6 +90,8 @@ private:
|
|||||||
MayaShader *default_shader = NULL);
|
MayaShader *default_shader = NULL);
|
||||||
|
|
||||||
EggGroup *get_egg_group(const string &name, EggData &data);
|
EggGroup *get_egg_group(const string &name, EggData &data);
|
||||||
|
void set_shader_attributes(EggPrimitive &primitive,
|
||||||
|
const MayaShader &shader);
|
||||||
|
|
||||||
typedef pmap<string, EggGroup *> Groups;
|
typedef pmap<string, EggGroup *> Groups;
|
||||||
Groups _groups;
|
Groups _groups;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user