forked from bartvdbraak/blender
Use a better compare function for RAS_IPolygonMaterial
Fix sharing verticies - must test pos, normal, uv & colour before sharing (not just index)
This commit is contained in:
parent
f03fa79d28
commit
648c21947c
@ -81,17 +81,44 @@ bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const
|
||||
|
||||
bool RAS_IPolyMaterial::Less(const RAS_IPolyMaterial& rhs) const
|
||||
{
|
||||
return (
|
||||
this->m_materialname < rhs.m_materialname ||
|
||||
this->m_texturename < rhs.m_texturename ||
|
||||
this->m_lightlayer < rhs.m_lightlayer ||
|
||||
this->m_tile < rhs.m_tile ||
|
||||
this->m_tilexrep < rhs.m_tilexrep ||
|
||||
this->m_tileyrep < rhs.m_tileyrep ||
|
||||
this->m_transparant < rhs.m_transparant ||
|
||||
this->m_drawingmode < rhs.m_drawingmode ||
|
||||
this->m_bIsTriangle < rhs.m_bIsTriangle
|
||||
);
|
||||
/**
|
||||
* @warning STL requires lhs.Less(rhs) == rhs.Less(lhs) implies lhs.Equals(rhs).
|
||||
* This function *must* return different values for lhs.Less(rhs) and rhs.Less(lhs) if
|
||||
* !lhs.Equals(rhs) !!
|
||||
*/
|
||||
if (m_materialname.hash() < rhs.m_materialname.hash())
|
||||
return true;
|
||||
|
||||
if (m_materialname.hash() > rhs.m_materialname.hash() ||
|
||||
m_texturename.hash() > rhs.m_texturename.hash())
|
||||
return false;
|
||||
|
||||
if (m_texturename.hash() < rhs.m_texturename.hash() ||
|
||||
m_lightlayer < rhs.m_lightlayer)
|
||||
return true;
|
||||
|
||||
if (m_lightlayer > rhs.m_lightlayer ||
|
||||
m_bIsTriangle > rhs.m_bIsTriangle)
|
||||
return false;
|
||||
|
||||
if (m_bIsTriangle < rhs.m_bIsTriangle ||
|
||||
m_drawingmode < rhs.m_drawingmode)
|
||||
return true;
|
||||
|
||||
if (m_drawingmode > rhs.m_drawingmode ||
|
||||
m_transparant > !rhs.m_transparant)
|
||||
return false;
|
||||
|
||||
if (m_transparant < rhs.m_transparant ||
|
||||
m_tileyrep < rhs.m_tileyrep)
|
||||
return true;
|
||||
|
||||
if (m_tileyrep > rhs.m_tileyrep ||
|
||||
m_tilexrep > rhs.m_tilexrep)
|
||||
return false;
|
||||
|
||||
return (m_tilexrep < rhs.m_tilexrep ||
|
||||
m_tile < rhs.m_tile);
|
||||
}
|
||||
|
||||
int RAS_IPolyMaterial::GetLightLayer()
|
||||
|
@ -132,14 +132,14 @@ RAS_Polygon* RAS_MeshObject::GetPolygon(int num)
|
||||
|
||||
|
||||
|
||||
set<RAS_MaterialBucket*>::iterator RAS_MeshObject::GetFirstMaterial()
|
||||
RAS_MaterialBucket::Set::iterator RAS_MeshObject::GetFirstMaterial()
|
||||
{
|
||||
return m_materials.begin();
|
||||
}
|
||||
|
||||
|
||||
|
||||
set<RAS_MaterialBucket*>::iterator RAS_MeshObject::GetLastMaterial()
|
||||
RAS_MaterialBucket::Set::iterator RAS_MeshObject::GetLastMaterial()
|
||||
{
|
||||
return m_materials.end();
|
||||
}
|
||||
@ -260,36 +260,33 @@ int RAS_MeshObject::FindOrAddVertex(int vtxarray,
|
||||
KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);//*(m_matVertexArrays[*mat]);
|
||||
|
||||
int numverts = ao->m_VertexArrayCache1[vtxarray]->size();//m_VertexArrayCount[vtxarray];
|
||||
|
||||
RAS_TexVert newvert(xyz,uv,rgbacolor,newnormal, 0);
|
||||
#define KX_FIND_SHARED_VERTICES
|
||||
#ifdef KX_FIND_SHARED_VERTICES
|
||||
|
||||
std::vector<RAS_MatArrayIndex>::iterator it = m_xyz_index_to_vertex_index_mapping[orgindex].begin();
|
||||
int index=-1;
|
||||
while (index < 0 && !(it == m_xyz_index_to_vertex_index_mapping[orgindex].end()))
|
||||
for (std::vector<RAS_MatArrayIndex>::iterator it = m_xyz_index_to_vertex_index_mapping[orgindex].begin();
|
||||
it != m_xyz_index_to_vertex_index_mapping[orgindex].end();
|
||||
it++)
|
||||
{
|
||||
if ((*it).m_arrayindex1 == ao->m_index1 &&
|
||||
((*it).m_array == vtxarray) &&
|
||||
(*(RAS_IPolyMaterial*) (*it).m_matid) == *mat
|
||||
(*it).m_array == vtxarray &&
|
||||
*(*it).m_matid == *mat &&
|
||||
(*ao->m_VertexArrayCache1[vtxarray])[(*it).m_index].closeTo(&newvert)
|
||||
)
|
||||
{
|
||||
return (*it).m_index;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
|
||||
if (index >= 0)
|
||||
return index;
|
||||
#endif // KX_FIND_SHARED_VERTICES
|
||||
|
||||
// no vertex found, add one
|
||||
ao->m_VertexArrayCache1[vtxarray]->push_back(RAS_TexVert (xyz,uv,rgbacolor,newnormal, 0));
|
||||
ao->m_VertexArrayCache1[vtxarray]->push_back(newvert);
|
||||
// printf("(%f,%f,%f) ",xyz[0],xyz[1],xyz[2]);
|
||||
RAS_MatArrayIndex idx;
|
||||
idx.m_arrayindex1 = ao->m_index1;
|
||||
idx.m_array = vtxarray;
|
||||
idx.m_index = numverts;
|
||||
idx.m_matid = (int) mat;
|
||||
idx.m_matid = mat;
|
||||
m_xyz_index_to_vertex_index_mapping[orgindex].push_back(idx);
|
||||
|
||||
return numverts;
|
||||
|
@ -89,10 +89,11 @@ class RAS_MatArrayIndex
|
||||
public:
|
||||
|
||||
int m_arrayindex1;
|
||||
int m_matid;
|
||||
RAS_IPolyMaterial* m_matid;
|
||||
int m_array;
|
||||
int m_index;
|
||||
|
||||
/*
|
||||
inline bool Less(const RAS_MatArrayIndex& lhs) const {
|
||||
bool result =
|
||||
( (m_matid < lhs.m_matid) ||
|
||||
@ -104,13 +105,14 @@ public:
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
};
|
||||
/*
|
||||
inline bool operator <( const RAS_MatArrayIndex& rhs,const RAS_MatArrayIndex& lhs)
|
||||
{
|
||||
return ( rhs.Less(lhs));
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* RAS_MeshObject stores mesh data for the renderer.
|
||||
|
Loading…
Reference in New Issue
Block a user