source: OGRE/trunk/ogrenew/OgreMain/src/OgreSubMesh.cpp @ 690

Revision 690, 5.3 KB checked in by mattausch, 18 years ago (diff)

added ogre 1.07 main

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26#include "OgreSubMesh.h"
27
28#include "OgreMesh.h"
29#include "OgreException.h"
30#include "OgreMeshManager.h"
31
32namespace Ogre {
33    //-----------------------------------------------------------------------
34    SubMesh::SubMesh()
35    {
36                useSharedVertices = true;
37                vertexData = NULL;
38                indexData = new IndexData();
39        mMatInitialised = false;
40        mBoneAssignmentsOutOfDate = false;
41        operationType = RenderOperation::OT_TRIANGLE_LIST;
42
43    }
44    //-----------------------------------------------------------------------
45    SubMesh::~SubMesh()
46    {
47        if (vertexData)
48        {
49            delete vertexData;
50        }
51                delete indexData;
52
53                removeLodLevels();
54    }
55
56    //-----------------------------------------------------------------------
57    void SubMesh::setMaterialName(const String& name)
58    {
59        mMaterialName = name;
60        mMatInitialised = true;
61    }
62    //-----------------------------------------------------------------------
63    const String& SubMesh::getMaterialName() const
64    {
65        return mMaterialName;
66    }
67    //-----------------------------------------------------------------------
68    bool SubMesh::isMatInitialised(void) const
69    {
70        return mMatInitialised;
71
72    }
73    //-----------------------------------------------------------------------
74    void SubMesh::_getRenderOperation(RenderOperation& ro, ushort lodIndex)
75    {
76       
77                // SubMeshes always use indexes
78        ro.useIndexes = true;
79                if (lodIndex > 0 && static_cast< size_t >( lodIndex - 1 ) < mLodFaceList.size())
80                {
81                        // lodIndex - 1 because we don't store full detail version in mLodFaceList
82                        ro.indexData = mLodFaceList[lodIndex-1];
83        }
84        else
85        {
86                ro.indexData = indexData;
87        }
88                ro.operationType = operationType;
89                ro.vertexData = useSharedVertices? parent->sharedVertexData : vertexData;
90
91    }
92    //-----------------------------------------------------------------------
93    void SubMesh::addBoneAssignment(const VertexBoneAssignment& vertBoneAssign)
94    {
95        if (useSharedVertices)
96        {
97            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "This SubMesh uses shared geometry,  you "
98                "must assign bones to the Mesh, not the SubMesh", "SubMesh.addBoneAssignment");
99        }
100        mBoneAssignments.insert(
101            VertexBoneAssignmentList::value_type(vertBoneAssign.vertexIndex, vertBoneAssign));
102        mBoneAssignmentsOutOfDate = true;
103    }
104    //-----------------------------------------------------------------------
105    void SubMesh::clearBoneAssignments(void)
106    {
107        mBoneAssignments.clear();
108        mBoneAssignmentsOutOfDate = true;
109    }
110
111    //-----------------------------------------------------------------------
112    void SubMesh::_compileBoneAssignments(void)
113    {
114        unsigned short maxBones =
115            parent->_rationaliseBoneAssignments(vertexData->vertexCount, mBoneAssignments);
116
117        if (maxBones == 0)
118        {
119            // No bone assignments
120            return;
121        }
122
123        parent->compileBoneAssignments(mBoneAssignments, maxBones,
124            vertexData);
125
126        /*
127        if (parent->mUseSoftwareBlending)
128        {
129            parent->compileBoneAssignmentsSoftware(mBoneAssignments, maxBones, vertexData);
130        }
131        else
132        {
133            parent->compileBoneAssignmentsHardware(mBoneAssignments, maxBones, vertexData);
134        }
135        */
136
137        mBoneAssignmentsOutOfDate = false;
138    }
139    //---------------------------------------------------------------------
140    SubMesh::BoneAssignmentIterator SubMesh::getBoneAssignmentIterator(void)
141    {
142        return BoneAssignmentIterator(mBoneAssignments.begin(),
143            mBoneAssignments.end());
144    }
145    //---------------------------------------------------------------------
146    void SubMesh::removeLodLevels(void)
147    {
148        ProgressiveMesh::LODFaceList::iterator lodi, lodend;
149                lodend = mLodFaceList.end();
150                for (lodi = mLodFaceList.begin(); lodi != lodend; ++lodi)
151                {
152                        delete *lodi;
153                }
154
155        mLodFaceList.clear();
156
157    }
158
159
160
161}
162
Note: See TracBrowser for help on using the repository browser.