251
254
RAS_IPolyMaterial* mat,
256
newnormal[0]=(short)((normal[0])*32767.0);
257
newnormal[1]=(short)((normal[1])*32767.0);
258
newnormal[2]=(short)((normal[2])*32767.0);
260
257
KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);//*(m_matVertexArrays[*mat]);
262
259
int numverts = ao->m_VertexArrayCache1[vtxarray]->size();//m_VertexArrayCount[vtxarray];
263
RAS_TexVert newvert(xyz,uv,rgbacolor,newnormal, 0);
260
RAS_TexVert newvert(xyz,uv,rgbacolor,normal, 0);
264
261
#define KX_FIND_SHARED_VERTICES
265
262
#ifdef KX_FIND_SHARED_VERTICES
555
void RAS_MeshObject::SchedulePolygons(int drawingmode,RAS_IRasterizer* rasty)
550
struct RAS_MeshObject::polygonSlot
555
polygonSlot(float z, RAS_Polygon* poly) :
560
* pnorm and pval form the plane equation that the distance from is used to
563
polygonSlot(const MT_Vector3 &pnorm, const MT_Scalar &pval, RAS_MeshObject *mesh, RAS_Polygon* poly) :
566
const KX_VertexIndex &base = m_poly->GetIndexBase();
567
RAS_TexVert *vert = mesh->GetVertex(base.m_vtxarray, base.m_indexarray[0], poly->GetMaterial()->GetPolyMaterial());
568
m_z = MT_dot(pnorm, vert->getLocalXYZ()) + pval;
570
for(int i = 1; i < m_poly->VertexCount(); i++)
572
vert = mesh->GetVertex(base.m_vtxarray, base.m_indexarray[i], poly->GetMaterial()->GetPolyMaterial());
573
float z = MT_dot(pnorm, vert->getLocalXYZ()) + pval;
576
m_z /= m_poly->VertexCount();
580
struct RAS_MeshObject::backtofront
582
bool operator()(const polygonSlot &a, const polygonSlot &b) const
584
return a.m_z < b.m_z;
588
struct RAS_MeshObject::fronttoback
590
bool operator()(const polygonSlot &a, const polygonSlot &b) const
592
return a.m_z > b.m_z;
597
void RAS_MeshObject::SortPolygons(const MT_Transform &transform)
602
// Extract camera Z plane...
603
const MT_Vector3 pnorm(transform.getBasis()[2]);
604
const MT_Scalar pval = transform.getOrigin()[2];
606
unsigned int numpolys = m_Polygons.size();
607
std::multiset<polygonSlot, backtofront> alphapolyset;
608
std::multiset<polygonSlot, fronttoback> solidpolyset;
610
for (unsigned int p = 0; p < numpolys; p++)
612
RAS_Polygon* poly = m_Polygons[p];
613
if (poly->IsVisible())
615
if (poly->GetMaterial()->GetPolyMaterial()->IsTransparant())
617
alphapolyset.insert(polygonSlot(pnorm, pval, this, poly));
619
solidpolyset.insert(polygonSlot(pnorm, pval, this, poly));
624
// Clear current array data.
625
for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it)
627
vector<KX_IndexArray*> *indexcache = &GetArrayOptimizer((*it)->GetPolyMaterial())->m_IndexArrayCache1;
628
for (vector<KX_IndexArray*>::iterator iit = indexcache->begin(); iit != indexcache->end(); ++iit)
632
std::multiset<polygonSlot, fronttoback>::iterator sit = solidpolyset.begin();
633
for (; sit != solidpolyset.end(); ++sit)
634
SchedulePoly((*sit).m_poly->GetVertexIndexBase(), (*sit).m_poly->VertexCount(), (*sit).m_poly->GetMaterial()->GetPolyMaterial());
636
std::multiset<polygonSlot, backtofront>::iterator ait = alphapolyset.begin();
637
for (; ait != alphapolyset.end(); ++ait)
638
SchedulePoly((*ait).m_poly->GetVertexIndexBase(), (*ait).m_poly->VertexCount(), (*ait).m_poly->GetMaterial()->GetPolyMaterial());
642
void RAS_MeshObject::SchedulePolygons(const MT_Transform &transform, int drawingmode)
557
644
// int nummaterials = m_materials.size();
564
651
RAS_MaterialBucket* bucket = *it;
566
653
bucket->SchedulePolygons(drawingmode);
654
if (bucket->GetPolyMaterial()->IsZSort())
569
658
int numpolys = m_Polygons.size();
571
if ((rasty->GetDrawingMode() > RAS_IRasterizer::KX_BOUNDINGBOX) &&
572
(rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID))
660
if ((drawingmode > RAS_IRasterizer::KX_BOUNDINGBOX) &&
661
(drawingmode < RAS_IRasterizer::KX_SOLID))
574
663
for (i=0;i<numpolys;i++)