diff --git a/pandatool/src/maxegg/maxToEggConverter.cxx b/pandatool/src/maxegg/maxToEggConverter.cxx index 0e5852bc64..065c1afd23 100755 --- a/pandatool/src/maxegg/maxToEggConverter.cxx +++ b/pandatool/src/maxegg/maxToEggConverter.cxx @@ -669,7 +669,11 @@ make_polyset(INode *max_node, Mesh *mesh, egg_poly->set_vertex(2, verts[0]); } - set_material_attributes(*egg_poly, max_node->GetMtl(), &face); + const PandaMaterial &pmat = get_panda_material(max_node->GetMtl(), face.getMatID()); + for (int i=0; iset_texture(pmat._texture_list[i]); + } + egg_poly->set_color(pmat._color); } // Now that we've added all the polygons (and created all the @@ -836,16 +840,37 @@ get_vertex_weights(INode *max_node, EggVertexPool *vpool) { // and a primitive color. //////////////////////////////////////////////////////////////////// const MaxToEggConverter::PandaMaterial &MaxToEggConverter:: -get_material_textures(StdMat *maxMaterial) { +get_panda_material(Mtl *mtl, MtlID matID) { - MaterialMap::iterator it = _material_map.find(maxMaterial); + MaterialMap::iterator it = _material_map.find(mtl); if (it != _material_map.end()) { return (*it).second; } - - PandaMaterial &pandaMat = _material_map[maxMaterial]; + + PandaMaterial &pandaMat = _material_map[mtl]; pandaMat._color = Colorf(1,1,1,1); + + // If it's a multi-material, dig down. + + while (( mtl != 0) && (mtl->ClassID() == Class_ID(MULTI_CLASS_ID, 0 ))) { + if (matID < mtl->NumSubMtls()) { + mtl = mtl->GetSubMtl(matID); + } else { + mtl = 0; + } + } + + // If it's a null material or an incomprehensible material, return a blank. + + if ((mtl == 0) || (mtl->ClassID() != Class_ID(DMTL_CLASS_ID, 0 ))) { + return pandaMat; + } + + // Process the standard material. + + StdMat *maxMaterial = (StdMat*)mtl; + Texmap *diffuseTexmap; Texmap *transTexmap; Bitmap *diffuseBitmap; @@ -939,46 +964,6 @@ get_material_textures(StdMat *maxMaterial) { return pandaMat; } -//////////////////////////////////////////////////////////////////// -// Function: MaxToEggConverter::set_material_attributes -// Access: Private -// Description: Applies the known material attributes to the indicated -// egg primitive. -//////////////////////////////////////////////////////////////////// -void MaxToEggConverter:: -set_material_attributes(EggPrimitive &primitive, Mtl *maxMaterial, Face *face) { - // Mtl *maxMaterial; - StdMat *maxStandardMaterial; - EggTexture *myEggTexture = null; - string outString; - string outHandle; - - //First, get the material data associated with this node. - if ( !maxMaterial ) { - return; - } - - //Now, determine wether it's a standard or multi material - if ( maxMaterial->ClassID() == Class_ID(DMTL_CLASS_ID, 0 )) { - const PandaMaterial &pmat = get_material_textures((StdMat *)maxMaterial); - for (int i=0; iClassID() == Class_ID(MULTI_CLASS_ID, 0 )) { - // It's a multi-material. Find the submaterial for this face. - // and call set_material_attributes again on the submaterial. - MtlID matID = face->getMatID(); - if (matID < maxMaterial->NumSubMtls()) { - set_material_attributes(primitive, maxMaterial->GetSubMtl(matID), face); - } - } else { - // It's another non-standard material. At the moment, let's just - // return - return; - } -} - //////////////////////////////////////////////////////////////////// // Function: MayaShader::apply_texture_properties // Access: Private diff --git a/pandatool/src/maxegg/maxToEggConverter.h b/pandatool/src/maxegg/maxToEggConverter.h index ef30cfc421..93d9b036bd 100755 --- a/pandatool/src/maxegg/maxToEggConverter.h +++ b/pandatool/src/maxegg/maxToEggConverter.h @@ -49,7 +49,7 @@ class MaxToEggConverter { std::vector _texture_list; Colorf _color; }; - typedef std::map MaterialMap; + typedef std::map MaterialMap; MaxEggOptions *_options; int _current_frame; PT(EggData) _egg_data; @@ -89,7 +89,7 @@ class MaxToEggConverter { void set_material_attributes(EggPrimitive &primitive, Mtl *maxMaterial, Face *face); - const PandaMaterial &get_material_textures(StdMat *mtl); + const PandaMaterial &get_panda_material(Mtl *mtl, MtlID id); void apply_texture_properties(EggTexture &tex, StdMat *maxMaterial);