mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
it seems maya can give polygons with bad shader. make install! so this takes care of the null color_def pointer situation
This commit is contained in:
parent
2a39759b85
commit
94194f6703
@ -55,6 +55,7 @@ MayaShader(MObject engine) {
|
||||
if (!shader_plug.isNull()) {
|
||||
MPlugArray shader_pa;
|
||||
shader_plug.connectedTo(shader_pa, true, false);
|
||||
maya_cat.spam() << "shader plug connected to: " << shader_pa.length() << endl;
|
||||
for (size_t i = 0; i < shader_pa.length() && !found_shader; i++) {
|
||||
MObject shader = shader_pa[0].node();
|
||||
found_shader = read_surface_shader(shader);
|
||||
@ -93,9 +94,11 @@ void MayaShader::
|
||||
write(ostream &out) const {
|
||||
out << "Shader " << get_name() << "\n"
|
||||
<< " color:\n";
|
||||
|
||||
for (size_t i=0; i<_color.size(); ++i) {
|
||||
_color[i]->write(out);
|
||||
}
|
||||
|
||||
out << " transparency:\n";
|
||||
_transparency.write(out);
|
||||
}
|
||||
@ -108,7 +111,10 @@ write(ostream &out) const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
MayaShaderColorDef *MayaShader::
|
||||
get_color_def(size_t idx) const {
|
||||
return _color[idx];
|
||||
if (_color.size() > 0)
|
||||
return _color[idx];
|
||||
else
|
||||
return (MayaShaderColorDef *)NULL;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MayaShader::get_rgba
|
||||
@ -127,7 +133,7 @@ Colorf MayaShader::
|
||||
get_rgba(size_t idx) const {
|
||||
Colorf rgba(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
if (_color[idx]->_has_flat_color) {
|
||||
if (_color.size() && _color[idx]->_has_flat_color) {
|
||||
rgba[0] = (float)_color[idx]->_flat_color[0];
|
||||
rgba[1] = (float)_color[idx]->_flat_color[1];
|
||||
rgba[2] = (float)_color[idx]->_flat_color[2];
|
||||
|
@ -1703,7 +1703,7 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path,
|
||||
// Furthermore, if _always_show_vertex_color is true, we pretend
|
||||
// that the "vertex-color" flag is always set.
|
||||
bool ignore_vertex_color = false;
|
||||
if (shader != (MayaShader *)NULL) {
|
||||
if ( color_def != (MayaShaderColorDef *)NULL) {
|
||||
ignore_vertex_color = color_def->_has_texture && !(egg_vertex_color || _always_show_vertex_color);
|
||||
}
|
||||
|
||||
@ -1721,7 +1721,7 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path,
|
||||
long i;
|
||||
LPoint3d centroid(0.0, 0.0, 0.0);
|
||||
|
||||
if (shader != (MayaShader *)NULL && color_def->has_projection()) {
|
||||
if (color_def != (MayaShaderColorDef *)NULL && color_def->has_projection()) {
|
||||
// If the shader has a projection, we may need to compute the
|
||||
// polygon's centroid to avoid seams at the edges.
|
||||
for (i = 0; i < num_verts; i++) {
|
||||
@ -1751,7 +1751,7 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path,
|
||||
}
|
||||
|
||||
string uv_name("");
|
||||
if (shader != (MayaShader *)NULL && color_def->_has_texture) {
|
||||
if (color_def != (MayaShaderColorDef *)NULL && color_def->_has_texture) {
|
||||
// Go thru all the texture references for this primitive and set uvs
|
||||
mayaegg_cat.debug() << "shader->_color.size is " << shader->_color.size() << endl;
|
||||
mayaegg_cat.debug() << "primitive->tref.size is " << egg_poly->get_num_textures() << endl;
|
||||
@ -2200,12 +2200,16 @@ get_vertex_weights(const MDagPath &dag_path, const MFnNurbsSurface &surface,
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void MayaToEggConverter::
|
||||
set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, const MItMeshPolygon *pi) {
|
||||
|
||||
//mayaegg_cat.spam() << " set_shader_attributes : begin\n";
|
||||
|
||||
// In Maya, a polygon is either textured or colored. The texture,
|
||||
// if present, replaces the color. Also now there could be multiple textures
|
||||
MayaShaderColorDef *color_def;
|
||||
MayaShaderColorDef *color_def = NULL;
|
||||
const MayaShaderColorDef &trans_def = shader._transparency;
|
||||
for (size_t i=0; i<shader._color.size(); ++i) {
|
||||
color_def = shader.get_color_def(i);
|
||||
//mayaegg_cat.spam() << "got color_def: " << color_def << endl;
|
||||
if (color_def->_has_texture || trans_def._has_texture) {
|
||||
EggTexture tex(shader.get_name(), "");
|
||||
string uvset_name = color_def->_texture_name;
|
||||
@ -2326,7 +2330,7 @@ set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, const M
|
||||
|
||||
// The existence of a texture on either color channel completely
|
||||
// replaces the corresponding flat color.
|
||||
if (color_def->_has_texture) {
|
||||
if (color_def && color_def->_has_texture) {
|
||||
rgba[0] = 1.0f;
|
||||
rgba[1] = 1.0f;
|
||||
rgba[2] = 1.0f;
|
||||
@ -2336,12 +2340,16 @@ set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, const M
|
||||
}
|
||||
|
||||
// But the color gain always gets applied.
|
||||
rgba[0] *= color_def->_color_gain[0];
|
||||
rgba[1] *= color_def->_color_gain[1];
|
||||
rgba[2] *= color_def->_color_gain[2];
|
||||
rgba[3] *= color_def->_color_gain[3];
|
||||
if (color_def) {
|
||||
rgba[0] *= color_def->_color_gain[0];
|
||||
rgba[1] *= color_def->_color_gain[1];
|
||||
rgba[2] *= color_def->_color_gain[2];
|
||||
rgba[3] *= color_def->_color_gain[3];
|
||||
}
|
||||
|
||||
primitive.set_color(rgba);
|
||||
|
||||
//mayaegg_cat.spam() << " set_shader_attributes : end\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user