mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
Support for map channels
This commit is contained in:
parent
a78fa265f6
commit
78a5739c04
@ -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; iChan<pmat._map_channels.size(); iChan++) {
|
||||
int channel = pmat._map_channels[iChan];
|
||||
ostringstream uvname;
|
||||
uvname << "m" << channel;
|
||||
UVVert uvw = get_max_vertex_texcoord(mesh, iFace, iVertex, channel);
|
||||
vert.set_uv( uvname.str(), TexCoordd(uvw.x, uvw.y));
|
||||
}
|
||||
|
||||
vert.set_external_index(face.v[iVertex]);
|
||||
@ -669,7 +674,6 @@ make_polyset(INode *max_node, Mesh *mesh,
|
||||
egg_poly->set_vertex(2, verts[0]);
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
@ -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) {
|
||||
|
@ -48,6 +48,7 @@ class MaxToEggConverter {
|
||||
struct PandaMaterial {
|
||||
std::vector<EggTexture*> _texture_list;
|
||||
Colorf _color;
|
||||
std::vector<int> _map_channels;
|
||||
};
|
||||
typedef std::map<Mtl*,PandaMaterial> 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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user