Getting ready to add multitexturing

This commit is contained in:
Josh Yelon 2008-08-21 04:36:18 +00:00
parent 7a9db0efd7
commit a78fa265f6
2 changed files with 32 additions and 47 deletions

View File

@ -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; i<pmat._texture_list.size(); i++) {
egg_poly->set_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; i<pmat._texture_list.size(); i++) {
primitive.set_texture(pmat._texture_list[i]);
}
primitive.set_color(pmat._color);
} else if ( maxMaterial->ClassID() == 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

View File

@ -49,7 +49,7 @@ class MaxToEggConverter {
std::vector<EggTexture*> _texture_list;
Colorf _color;
};
typedef std::map<StdMat*,PandaMaterial> MaterialMap;
typedef std::map<Mtl*,PandaMaterial> 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);