diff --git a/pandatool/src/maxegg/maxToEggConverter.cxx b/pandatool/src/maxegg/maxToEggConverter.cxx index 065c1afd23..1901c694e4 100755 --- a/pandatool/src/maxegg/maxToEggConverter.cxx +++ b/pandatool/src/maxegg/maxToEggConverter.cxx @@ -619,6 +619,8 @@ make_polyset(INode *max_node, Mesh *mesh, Face face = mesh->faces[iFace]; + const PandaMaterial &pmat = get_panda_material(max_node->GetMtl(), face.getMatID()); + // Get the vertices for the polygon. for ( int iVertex=0; iVertex < 3; iVertex++ ) { EggVertex vert; @@ -638,9 +640,12 @@ make_polyset(INode *max_node, Mesh *mesh, vert.set_normal(n3d); // Get the UVs for this vertex - if (mesh->getNumTVerts()) { - UVVert vertTexCoord = mesh->getTVert(mesh->tvFace[iFace].t[iVertex]); - vert.set_uv( TexCoordd(vertTexCoord.x, vertTexCoord.y)); + for (int iChan=0; iChanset_vertex(2, verts[0]); } - const PandaMaterial &pmat = get_panda_material(max_node->GetMtl(), face.getMatID()); for (int i=0; iset_texture(pmat._texture_list[i]); } @@ -685,7 +689,20 @@ make_polyset(INode *max_node, Mesh *mesh, } } +UVVert MaxToEggConverter::get_max_vertex_texcoord(Mesh *mesh, int faceNo, int vertNo, int channel) { + // extract the texture coordinate + UVVert uvVert(0,0,0); + if(mesh->mapSupport(channel)) { + TVFace *pTVFace = mesh->mapFaces(channel); + UVVert *pUVVert = mesh->mapVerts(channel); + uvVert = pUVVert[pTVFace[faceNo].t[vertNo]]; + } else if(mesh->numTVerts > 0) { + uvVert = mesh->tVerts[mesh->tvFace[faceNo].t[vertNo]]; + } + return uvVert; +} + Point3 MaxToEggConverter::get_max_vertex_normal(Mesh *mesh, int faceNo, int vertNo) { Face f = mesh->faces[faceNo]; @@ -879,12 +896,14 @@ get_panda_material(Mtl *mtl, MtlID matID) { bool has_diffuse_texture = false; bool has_trans_texture = false; Point3 diffuseColor = Point3(1, 1, 1); + int mapChan = 1; // Access the Diffuse map and see if it's a Bitmap texture diffuseTexmap = maxMaterial->GetSubTexmap(ID_DI); if (diffuseTexmap && (diffuseTexmap->ClassID() == Class_ID(BMTEX_CLASS_ID, 0))) { has_diffuse_texture = true; diffuseBitmapTex = (BitmapTex *) diffuseTexmap; + mapChan = diffuseBitmapTex->GetMapChannel(); } // Access the Opacity map and see if it's a Bitmap texture @@ -892,6 +911,7 @@ get_panda_material(Mtl *mtl, MtlID matID) { if (transTexmap && (transTexmap->ClassID() == Class_ID(BMTEX_CLASS_ID, 0))) { has_trans_texture = true; transBitmapTex = (BitmapTex *) transTexmap; + mapChan = transBitmapTex->GetMapChannel(); } if (has_diffuse_texture || has_trans_texture) { @@ -942,11 +962,15 @@ get_panda_material(Mtl *mtl, MtlID matID) { tex.set_format(EggTexture::F_alpha); apply_texture_properties(tex, maxMaterial); } + ostringstream uvname; + uvname << "m" << mapChan; + tex.set_uv_name(uvname.str()); EggTexture *new_tex = _textures.create_unique_texture(tex, ~EggTexture::E_tref_name); pandaMat._texture_list.push_back(new_tex); - + pandaMat._map_channels.push_back(mapChan); + // The existence of a texture on either color channel completely // replaces the corresponding flat color. if (!has_diffuse_texture) { diff --git a/pandatool/src/maxegg/maxToEggConverter.h b/pandatool/src/maxegg/maxToEggConverter.h index 93d9b036bd..9c94582ac3 100755 --- a/pandatool/src/maxegg/maxToEggConverter.h +++ b/pandatool/src/maxegg/maxToEggConverter.h @@ -48,6 +48,7 @@ class MaxToEggConverter { struct PandaMaterial { std::vector _texture_list; Colorf _color; + std::vector _map_channels; }; typedef std::map MaterialMap; MaxEggOptions *_options; @@ -80,8 +81,8 @@ class MaxToEggConverter { EggGroup *egg_group, Shader *default_shader = NULL); - //Gets the vertex normal for a given face and vertex. Go figure. Point3 get_max_vertex_normal(Mesh *mesh, int faceNo, int vertNo); + UVVert get_max_vertex_texcoord(Mesh *mesh, int faceNo, int vertNo, int channel); void get_vertex_weights(INode *max_node, EggVertexPool *vpool);