~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/gameengine/Rasterizer/RAS_MeshObject.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: RAS_MeshObject.cpp,v 1.7 2004/05/04 13:17:36 kester Exp $
 
2
 * $Id: RAS_MeshObject.cpp,v 1.14 2005/03/09 19:45:59 lukep Exp $
3
3
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or
29
29
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
30
30
 */
31
31
 
 
32
#ifdef HAVE_CONFIG_H
 
33
#include <config.h>
 
34
#endif
 
35
 
32
36
#include "RAS_MeshObject.h"
33
37
#include "RAS_IRasterizer.h"
34
38
#include "MT_MinMax.h"
 
39
#include "MT_Point3.h"
35
40
 
36
 
#ifdef HAVE_CONFIG_H
37
 
#include <config.h>
38
 
#endif
39
41
 
40
42
STR_String RAS_MeshObject::s_emptyname = "";
41
43
 
67
69
RAS_MeshObject::RAS_MeshObject(int lightlayer)
68
70
        : m_bModified(true),
69
71
        m_lightlayer(lightlayer),
 
72
        m_zsort(false),
70
73
        m_class(0)
71
74
{
72
75
}
251
254
                                                                        RAS_IPolyMaterial* mat,
252
255
                                                                        int orgindex)
253
256
{
254
 
        short newnormal[3];
255
 
        
256
 
        newnormal[0]=(short)((normal[0])*32767.0);
257
 
        newnormal[1]=(short)((normal[1])*32767.0);
258
 
        newnormal[2]=(short)((normal[2])*32767.0);
259
 
        
260
257
        KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);//*(m_matVertexArrays[*mat]);
261
258
        
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
266
263
        
455
452
 * it is the clients responsibility to make sure the array and index are valid
456
453
 */
457
454
RAS_TexVert* RAS_MeshObject::GetVertex(short array,
458
 
                                                                           short index,
 
455
                                                                           unsigned int index,
459
456
                                                                           RAS_IPolyMaterial* polymat)
460
457
{
461
458
         KX_ArrayOptimizer* ao = GetArrayOptimizer(polymat);//*(m_matVertexArrays[*polymat]);
466
463
 
467
464
void RAS_MeshObject::ClearArrayData()
468
465
{
469
 
        for (unsigned int i=0;i<m_matVertexArrayS.size();i++)
 
466
        for (int i=0;i<m_matVertexArrayS.size();i++)
470
467
        {
471
468
                KX_ArrayOptimizer** ao = m_matVertexArrayS.at(i);
472
469
                if (ao)
491
488
        {
492
489
                if ( (ao->m_TriangleArrayCount[i] + (numverts-2)) < BUCKET_MAX_TRIANGLES) 
493
490
                {
494
 
                         if((ao->m_VertexArrayCache1[i]->size()+numverts < BUCKET_MAX_INDICES))
495
 
                                {
496
 
                                        array = i;
497
 
                                        ao->m_TriangleArrayCount[array]+=numverts-2;
498
 
                                        break;
499
 
                                }
 
491
                        if((ao->m_VertexArrayCache1[i]->size()+numverts < BUCKET_MAX_INDICES))
 
492
                        {
 
493
                                array = i;
 
494
                                ao->m_TriangleArrayCount[array]+=numverts-2;
 
495
                                break;
 
496
                        }
500
497
                }
501
498
        }
502
499
 
550
547
        }
551
548
}
552
549
 
553
 
 
554
 
 
555
 
void RAS_MeshObject::SchedulePolygons(int drawingmode,RAS_IRasterizer* rasty)
 
550
struct RAS_MeshObject::polygonSlot
 
551
{
 
552
        float        m_z;
 
553
        RAS_Polygon *m_poly;
 
554
                
 
555
        polygonSlot(float z, RAS_Polygon* poly) :
 
556
                m_z(z),
 
557
                m_poly(poly)
 
558
        {}
 
559
        /**
 
560
         * pnorm and pval form the plane equation that the distance from is used to
 
561
         * sort against.
 
562
         */
 
563
        polygonSlot(const MT_Vector3 &pnorm, const MT_Scalar &pval, RAS_MeshObject *mesh, RAS_Polygon* poly) :
 
564
                        m_poly(poly)
 
565
        {
 
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;
 
569
                
 
570
                for(int i = 1; i < m_poly->VertexCount(); i++)
 
571
                {
 
572
                        vert = mesh->GetVertex(base.m_vtxarray, base.m_indexarray[i], poly->GetMaterial()->GetPolyMaterial());
 
573
                        float z = MT_dot(pnorm, vert->getLocalXYZ()) + pval;
 
574
                        m_z += z;
 
575
                }
 
576
                m_z /= m_poly->VertexCount();
 
577
        }
 
578
};
 
579
        
 
580
struct RAS_MeshObject::backtofront
 
581
{
 
582
        bool operator()(const polygonSlot &a, const polygonSlot &b) const
 
583
        {
 
584
                return a.m_z < b.m_z;
 
585
        }
 
586
};
 
587
 
 
588
struct RAS_MeshObject::fronttoback
 
589
{
 
590
        bool operator()(const polygonSlot &a, const polygonSlot &b) const
 
591
        {
 
592
                return a.m_z > b.m_z;
 
593
        }
 
594
};
 
595
 
 
596
 
 
597
void RAS_MeshObject::SortPolygons(const MT_Transform &transform)
 
598
{
 
599
        if (!m_zsort)
 
600
                return;
 
601
                
 
602
        // Extract camera Z plane...
 
603
        const MT_Vector3 pnorm(transform.getBasis()[2]);
 
604
        const MT_Scalar pval = transform.getOrigin()[2];
 
605
        
 
606
        unsigned int numpolys = m_Polygons.size();
 
607
        std::multiset<polygonSlot, backtofront> alphapolyset;
 
608
        std::multiset<polygonSlot, fronttoback> solidpolyset;
 
609
        
 
610
        for (unsigned int p = 0; p < numpolys; p++)
 
611
        {
 
612
                RAS_Polygon* poly = m_Polygons[p];
 
613
                if (poly->IsVisible())
 
614
                {
 
615
                        if (poly->GetMaterial()->GetPolyMaterial()->IsTransparant())
 
616
                        {
 
617
                                alphapolyset.insert(polygonSlot(pnorm, pval, this, poly));
 
618
                        } else {
 
619
                                solidpolyset.insert(polygonSlot(pnorm, pval, this, poly));
 
620
                        }
 
621
                }
 
622
        }
 
623
        
 
624
        // Clear current array data.
 
625
        for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it)
 
626
        {
 
627
                vector<KX_IndexArray*> *indexcache = &GetArrayOptimizer((*it)->GetPolyMaterial())->m_IndexArrayCache1;
 
628
                for (vector<KX_IndexArray*>::iterator iit = indexcache->begin(); iit != indexcache->end(); ++iit)
 
629
                        (*iit)->clear();
 
630
        }
 
631
 
 
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());
 
635
        
 
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());
 
639
}
 
640
 
 
641
 
 
642
void RAS_MeshObject::SchedulePolygons(const MT_Transform &transform, int drawingmode)
556
643
{
557
644
//      int nummaterials = m_materials.size();
558
645
        int i;
564
651
                        RAS_MaterialBucket* bucket = *it;
565
652
 
566
653
                        bucket->SchedulePolygons(drawingmode);
 
654
                        if (bucket->GetPolyMaterial()->IsZSort())
 
655
                                m_zsort = true;
567
656
                }
568
657
 
569
658
                int numpolys = m_Polygons.size();
570
659
                
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))
573
662
                {
574
663
                        for (i=0;i<numpolys;i++)
575
664
                        {
579
668
                                        ,poly->GetMaterial()->GetPolyMaterial());
580
669
                                
581
670
                        }
 
671
                        m_zsort = false;
582
672
                }
583
673
                else
584
674
                {
585
 
                        for (i=0;i<numpolys;i++)
 
675
                        if (!m_zsort)
586
676
                        {
587
 
                                RAS_Polygon* poly = m_Polygons[i];
588
 
                                if (poly->IsVisible())
 
677
                                for (i=0;i<numpolys;i++)
589
678
                                {
590
 
                                        SchedulePoly(poly->GetVertexIndexBase(),poly->VertexCount(),poly->GetMaterial()->GetPolyMaterial());
 
679
                                        RAS_Polygon* poly = m_Polygons[i];
 
680
                                        if (poly->IsVisible())
 
681
                                        {
 
682
                                                SchedulePoly(poly->GetVertexIndexBase(),poly->VertexCount(),poly->GetMaterial()->GetPolyMaterial());
 
683
                                        }
591
684
                                }
592
685
                        }
593
686
                }
594
687
 
595
688
                m_bModified = false;
596
689
        } 
597
 
        //      }
598
690
}