source: OGRE/trunk/ogrenew/OgreMain/include/OgreStaticGeometry.h @ 657

Revision 657, 30.2 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

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#ifndef __StaticGeometry_H__
26#define __StaticGeometry_H__
27
28#include "OgrePrerequisites.h"
29#include "OgreMovableObject.h"
30#include "OgreRenderable.h"
31#include "OgreEdgeListBuilder.h"
32
33namespace Ogre {
34
35        /** Pre-transforms and batches up meshes for efficient use as static
36                geometry in a scene.
37        @remarks
38                Modern graphics cards (GPUs) prefer to receive geometry in large
39                batches. It is orders of magnitude faster to render 10 batches
40                of 10,000 triangles than it is to render 10,000 batches of 10
41                triangles, even though both result in the same number of on-screen
42                triangles.
43        @par
44                Therefore it is important when you are rendering a lot of geometry to
45                batch things up into as few rendering calls as possible. This
46                class allows you to build a batched object from a series of entities
47                in order to benefit from this behaviour.
48                Batching has implications of it's own though:
49                @li Batched geometry cannot be subdivided; that means that the whole
50                        group will be displayed, or none of it will. This obivously has
51                        culling issues.
52                @li A single world transform must apply to the entire batch. Therefore
53                        once you have batched things, you can't move them around relative to
54                        each other. That's why this class is most useful when dealing with
55                        static geometry (hence the name). In addition, geometry is
56                        effectively duplicated, so if you add 3 entities based on the same
57                        mesh in different positions, they will use 3 times the geometry
58                        space than the movable version (which re-uses the same geometry).
59                        So you trade memory     and flexibility of movement for pure speed when
60                        using this class.
61                @li A single material must apply for each batch. In fact this class
62                        allows you to use multiple materials, but you should be aware that
63                        internally this means that there is one batch per material.
64                        Therefore you won't gain as much benefit from the batching if you
65                        use many different materials; try to keep the number down.
66        @par
67                In order to retain some sort of culling, this class will batch up
68                meshes in localised regions. The size and shape of these blocks is
69                controlled by the SceneManager which contructs this object, since it
70                makes sense to batch things up in the most appropriate way given the
71                existing partitioning of the scene.
72        @par
73                The LOD settings of both the Mesh and the Materials used in
74                constructing this static geometry will be respected. This means that
75                if you use meshes/materials which have LOD, batches in the distance
76                will have a lower polygon count or material detail to those in the
77                foreground. Since each mesh might have different LOD distances, during
78                build the furthest distance at each LOD level from all meshes 
79                in that region is used. This means all the LOD levels change at the
80                same time, but at the furthest distance of any of them (so quality is
81                not degraded). Be aware that using Mesh LOD in this class will
82                further increase the memory required. Only generated LOD
83                is supported for meshes.
84        @par
85                There are 2 ways you can add geometry to this class; you can add
86                Entity objects directly with predetermined positions, scales and
87                orientations, or you can add an entire SceneNode and it's subtree,
88                including all the objects attached to it. Once you've added everthing
89                you need to, you have to call build() the fix the geometry in place.
90        @note
91                This class is not a replacement for world geometry (@see
92                SceneManager::setWorldGeometry). The single most efficient way to
93                render large amounts of static geometry is to use a SceneManager which
94                is specialised for dealing with that particular world structure.
95                However, this class does provide you with a good 'halfway house'
96                between generalised movable geometry (Entity) which works with all
97                SceneManagers but isn't efficient when using very large numbers, and
98                highly specialised world geometry which is extremely fast but not
99                generic and typically requires custom world editors.
100        @par
101                You should not construct instances of this class directly; instead, cal
102                SceneManager::createStaticGeometry, which gives the SceneManager the
103                option of providing you with a specialised version of this class if it
104                wishes, and also handles the memory management for you like other
105                classes.
106        */
107        class _OgreExport StaticGeometry
108        {
109        public:
110                /** Struct holding geometry optimised per SubMesh / lod level, ready
111                        for copying to instances.
112                @remarks
113                        Since we're going to be duplicating geometry lots of times, it's
114                        far more important that we don't have redundant vertex data. If a
115                        SubMesh uses shared geometry, or we're looking at a lower LOD, not
116                        all the vertices are being referenced by faces on that submesh.
117                        Therefore to duplicate them, potentially hundreds or even thousands
118                        of times, would be extremely wasteful. Therefore, if a SubMesh at
119                        a given LOD has wastage, we create an optimised version of it's
120                        geometry which is ready for copying with no wastage.
121                */
122                class _OgrePrivate OptimisedSubMeshGeometry
123                {
124                public:
125                        OptimisedSubMeshGeometry() :vertexData(0), indexData(0) {}
126                        ~OptimisedSubMeshGeometry()
127                        {
128                                delete vertexData;
129                                delete indexData;
130                        }
131                        VertexData *vertexData;
132                        IndexData *indexData;
133                };
134                typedef std::list<OptimisedSubMeshGeometry*> OptimisedSubMeshGeometryList;
135                /// Saved link between SubMesh at a LOD and vertex/index data
136                /// May point to original or optimised geometry
137                struct SubMeshLodGeometryLink
138                {
139                        VertexData* vertexData;
140                        IndexData* indexData;
141                };
142                typedef std::vector<SubMeshLodGeometryLink> SubMeshLodGeometryLinkList;
143                typedef std::map<SubMesh*, SubMeshLodGeometryLinkList*> SubMeshGeometryLookup;
144                /// Structure recording a queued submesh for the build
145                struct QueuedSubMesh
146                {
147                        SubMesh* submesh;
148                        /// Link to LOD list of geometry, potentially optimised
149                        SubMeshLodGeometryLinkList* geometryLodList;
150                        String materialName;
151                        Vector3 position;
152                        Quaternion orientation;
153                        Vector3 scale;
154                        /// Pre-transformed world AABB
155                        AxisAlignedBox worldBounds;
156                };
157                typedef std::vector<QueuedSubMesh*> QueuedSubMeshList;
158                /// Structure recording a queued geometry for low level builds
159                struct QueuedGeometry
160                {
161                        SubMeshLodGeometryLink* geometry;
162                        Vector3 position;
163                        Quaternion orientation;
164                        Vector3 scale;
165                };
166                typedef std::vector<QueuedGeometry*> QueuedGeometryList;
167               
168                // forward declarations
169                class LODBucket;
170                class MaterialBucket;
171                class Region;
172
173                /** A GeometryBucket is a the lowest level bucket where geometry with
174                        the same vertex & index format is stored. It also acts as the
175                        renderable.
176                */
177                class _OgreExport GeometryBucket : public Renderable
178                {
179                protected:
180                        /// Geometry which has been queued up pre-build (not for deallocation)
181                        QueuedGeometryList mQueuedGeometry;
182                        /// Pointer to parent bucket
183                        MaterialBucket* mParent;
184                        /// String identifying the vertex / index format
185                        String mFormatString;
186                        /// Vertex information, includes current number of vertices
187                        /// committed to be a part of this bucket
188                        VertexData* mVertexData;
189                        /// Index information, includes index type which limits the max
190                        /// number of vertices which are allowed in one bucket
191                        IndexData* mIndexData;
192                        /// Size of indexes
193                        HardwareIndexBuffer::IndexType mIndexType;
194                        /// Maximum vertex indexable
195                        size_t mMaxVertexIndex;
196
197                        template<typename T>
198                        void copyIndexes(const T* src, T* dst, size_t count, size_t indexOffset)
199                        {
200                                if (indexOffset == 0)
201                                {
202                                        memcpy(dst, src, sizeof(T) * count);
203                                }
204                                else
205                                {
206                                        while(count--)
207                                        {
208                                                *dst++ = static_cast<T>(*src++ + indexOffset);
209                                        }
210                                }
211                        }
212                public:
213                        GeometryBucket(MaterialBucket* parent, const String& formatString,
214                                const VertexData* vData, const IndexData* iData);
215                        virtual ~GeometryBucket();
216                        MaterialBucket* getParent(void) { return mParent; }
217                        /// Get the vertex data for this geometry
218                        const VertexData* getVertexData(void) const { return mVertexData; }
219                        /// Get the index data for this geometry
220                        const IndexData* getIndexData(void) const { return mIndexData; }
221                        /// @copydoc Renderable::getMaterial
222                        const MaterialPtr& getMaterial(void) const;
223                        Technique* getTechnique(void) const;
224                        void getRenderOperation(RenderOperation& op);
225                void getWorldTransforms(Matrix4* xform) const;
226                const Quaternion& getWorldOrientation(void) const;
227                const Vector3& getWorldPosition(void) const;
228                        Real getSquaredViewDepth(const Camera* cam) const;
229                const LightList& getLights(void) const;
230                        bool getCastsShadows(void) const;
231                       
232                        /** Try to assign geometry to this bucket.
233                        @returns false if there is no room left in this bucket
234                        */
235                        bool assign(QueuedGeometry* qsm);
236                        /// Build
237                        void build(bool stencilShadows);
238                        /// Dump contents for diagnostics
239                        void dump(std::ofstream& of) const;
240                };
241                /** A MaterialBucket is a collection of smaller buckets with the same
242                        Material (and implicitly the same LOD). */
243                class _OgreExport MaterialBucket
244                {
245                public:
246                        /// list of Geometry Buckets in this region
247                        typedef std::vector<GeometryBucket*> GeometryBucketList;
248                protected:
249                        /// Pointer to parent LODBucket
250                        LODBucket* mParent;
251                        /// Material being used
252                        String mMaterialName;
253                        /// Pointer to material being used
254                        MaterialPtr mMaterial;
255                        /// Active technique
256                        Technique* mTechnique;
257
258                        /// list of Geometry Buckets in this region
259                        GeometryBucketList mGeometryBucketList;
260                        // index to current Geometry Buckets for a given geometry format
261                        typedef std::map<String, GeometryBucket*> CurrentGeometryMap;
262                        CurrentGeometryMap mCurrentGeometryMap;
263                        /// Get a packed string identifying the geometry format
264                        String getGeometryFormatString(SubMeshLodGeometryLink* geom);
265                       
266                public:
267                        MaterialBucket(LODBucket* parent, const String& materialName);
268                        virtual ~MaterialBucket();
269                        LODBucket* getParent(void) { return mParent; }
270                        /// Get the material name
271                        const String& getMaterialName(void) const { return mMaterialName; }
272                        /// Assign geometry to this bucket
273                        void assign(QueuedGeometry* qsm);
274                        /// Build
275                        void build(bool stencilShadows);
276                        /// Add children to the render queue
277                        void addRenderables(RenderQueue* queue, RenderQueueGroupID group,
278                                Real camSquaredDist);
279                        /// Get the material for this bucket
280                        const MaterialPtr& getMaterial(void) const { return mMaterial; }
281                        /// Iterator over geometry
282                        typedef VectorIterator<GeometryBucketList> GeometryIterator;
283                        /// Get an iterator over the contained geometry
284                        GeometryIterator getGeometryIterator(void);
285                        /// Get the current Technique
286                        Technique* getCurrentTechnique(void) const { return mTechnique; }
287                        /// Dump contents for diagnostics
288                        void dump(std::ofstream& of) const;
289                };
290                /** A LODBucket is a collection of smaller buckets with the same LOD.
291                @remarks
292                        LOD refers to Mesh LOD here. Material LOD can change separately
293                        at the next bucket down from this.
294                */
295                class _OgreExport LODBucket
296                {
297                public:
298                        /// Lookup of Material Buckets in this region
299                        typedef std::map<String, MaterialBucket*> MaterialBucketMap;
300                protected:
301                        /// Pointer to parent region
302                        Region* mParent;
303                        /// LOD level (0 == full LOD)
304                        unsigned short mLod;
305                        /// distance at which this LOD starts to apply (squared)
306                        Real mSquaredDistance;
307                        /// Lookup of Material Buckets in this region
308                        MaterialBucketMap mMaterialBucketMap;
309                        /// Geometry queued for a single LOD (deallocated here)
310                        QueuedGeometryList mQueuedGeometryList;
311                public:
312                        LODBucket(Region* parent, unsigned short lod, Real lodDist);
313                        virtual ~LODBucket();
314                        Region* getParent(void) { return mParent; }
315                        /// Get the lod index
316                        ushort getLod(void) const { return mLod; }
317                        /// Get the lod squared distance
318                        Real getSquaredDistance(void) const { return mSquaredDistance; }
319                        /// Assign a queued submesh to this bucket, using specified mesh LOD
320                        void assign(QueuedSubMesh* qsm, ushort atLod);
321                        /// Build
322                        void build(bool stencilShadows);
323                        /// Add children to the render queue
324                        void addRenderables(RenderQueue* queue, RenderQueueGroupID group,
325                                Real camSquaredDistance);
326                        /// Iterator over the materials in this LOD
327                        typedef MapIterator<MaterialBucketMap> MaterialIterator;
328                        /// Get an iterator over the materials in this LOD
329                        MaterialIterator getMaterialIterator(void);
330                        /// Dump contents for diagnostics
331                        void dump(std::ofstream& of) const;
332                       
333                };
334                /** The details of a topological region which is the highest level of
335                        partitioning for this class.
336                @remarks
337                        The size & shape of regions entirely depends on the SceneManager
338                        specific implementation. It is a MovableObject since it will be
339                        attached to a node based on the local centre - in practice it
340                        won't actually move (although in theory it could).
341                */
342                class _OgreExport Region : public MovableObject
343                {
344                public:
345                        /// list of LOD Buckets in this region
346                        typedef std::vector<LODBucket*> LODBucketList;
347                protected:
348                        /** Nested class to allow region shadows. */
349                        class _OgreExport RegionShadowRenderable : public ShadowRenderable
350                        {
351                        protected:
352                                Region* mParent;
353                                // Shared link to position buffer
354                                HardwareVertexBufferSharedPtr mPositionBuffer;
355                                // Shared link to w-coord buffer (optional)
356                                HardwareVertexBufferSharedPtr mWBuffer;
357
358                        public:
359                                RegionShadowRenderable(Region* parent,
360                                        HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData,
361                                        bool createSeparateLightCap, bool isLightCap = false);
362                                ~RegionShadowRenderable();
363                                /// Overridden from ShadowRenderable
364                                void getWorldTransforms(Matrix4* xform) const;
365                                /// Overridden from ShadowRenderable
366                                const Quaternion& getWorldOrientation(void) const;
367                                /// Overridden from ShadowRenderable
368                                const Vector3& getWorldPosition(void) const;
369                                HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; }
370                                HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; }
371
372                        };
373                        /// Parent static geometry
374                        StaticGeometry* mParent;
375                        /// Generated name
376                        String mName;
377                        /// Scene manager link
378                        SceneManager* mSceneMgr;
379                        /// Scene node
380                        SceneNode* mNode;
381                        /// Local list of queued meshes (not used for deallocation)
382                        QueuedSubMeshList mQueuedSubMeshes;
383                        /// Unique identifier for the region
384                        uint32 mRegionID;
385                        /// Center of the region
386                        Vector3 mCentre;
387                        /// LOD distances (squared) as built up - use the max at each level
388                        std::vector<Real> mLodSquaredDistances;
389                        /// Local AABB relative to region centre
390                        AxisAlignedBox mAABB;
391                        /// Local bounding radius
392                        Real mBoundingRadius;
393                        /// The current lod level, as determined from the last camera
394                        ushort mCurrentLod;
395                        /// Current camera distance, passed on to do material lod later
396                        Real mCamDistanceSquared;
397                        /// List of LOD buckets                 
398                        LODBucketList mLodBucketList;
399                        /// List of lights for this region
400                        mutable LightList mLightList;
401                        /// The last frame that this light list was updated in
402                        mutable ulong mLightListUpdated;
403                        /// Hidden because of distance?
404                        bool mBeyondFarDistance;
405                        /// Edge list, used if stencil shadow casting is enabled
406                        EdgeData* mEdgeList;
407                        /// List of shadow renderables
408                        ShadowRenderableList mShadowRenderables;
409                        /// Is a vertex program in use somewhere in this region?
410                        bool mVertexProgramInUse;
411
412
413
414                public:
415                        Region(StaticGeometry* parent, const String& name, SceneManager* mgr,
416                                uint32 regionID, const Vector3& centre);
417                        virtual ~Region();
418                        // more fields can be added in subclasses
419                        StaticGeometry* getParent(void) const { return mParent;}
420                        /// Assign a queued mesh to this region, read for final build
421                        void assign(QueuedSubMesh* qmesh);
422                        /// Build this region
423                        void build(bool stencilShadows);
424                        /// Get the region ID of this region
425                        uint32 getID(void) const { return mRegionID; }
426                        /// Get the centre point of the region
427                        const Vector3& getCentre(void) const { return mCentre; }
428                        const String& getName(void) const;
429                        const String& getMovableType(void) const;
430                        void _notifyCurrentCamera(Camera* cam);
431                        const AxisAlignedBox& getBoundingBox(void) const;
432                        Real getBoundingRadius(void) const;
433                        void _updateRenderQueue(RenderQueue* queue);
434                        bool isVisible(void) const;
435
436                        typedef VectorIterator<LODBucketList> LODIterator;
437                        /// Get an iterator over the LODs in this region
438                        LODIterator getLODIterator(void);
439                        /// Shared set of lights for all GeometryBuckets
440                        const LightList& getLights(void) const;
441                        /// @copydoc ShadowCaster::getShadowVolumeRenderableIterator
442                        ShadowRenderableListIterator getShadowVolumeRenderableIterator(
443                                ShadowTechnique shadowTechnique, const Light* light,
444                                HardwareIndexBufferSharedPtr* indexBuffer,
445                                bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
446                        /// Overridden from MovableObject
447                        EdgeData* getEdgeList(void);
448
449
450                        /// Dump contents for diagnostics
451                        void dump(std::ofstream& of) const;
452                       
453                };
454                /** Indexed region map based on packed x/y/z region index, 10 bits for
455                        each axis.
456                @remarks
457                        Regions are indexed 0-1023 in all axes, where for example region
458                        0 in the x axis begins at mOrigin.x + (mRegionDimensions.x * -512),
459                        and region 1023 ends at mOrigin + (mRegionDimensions.x * 512).
460                */
461                typedef std::map<uint32, Region*> RegionMap;
462        protected:
463                // General state & settings
464                SceneManager* mOwner;
465                String mName;
466                bool mBuilt;
467                Real mUpperDistance;
468                Real mSquaredUpperDistance;
469                bool mCastShadows;
470                Vector3 mRegionDimensions;
471                Vector3 mHalfRegionDimensions;
472                Vector3 mOrigin;
473                bool mVisible;
474        /// The render queue to use when rendering this object
475        RenderQueueGroupID mRenderQueueID;
476                /// Flags whether the RenderQueue's default should be used.
477                bool mRenderQueueIDSet;
478
479                QueuedSubMeshList mQueuedSubMeshes;
480
481                /// List of geometry which has been optimised for SubMesh use
482                /// This is the primary storage used for cleaning up later
483                OptimisedSubMeshGeometryList mOptimisedSubMeshGeometryList;
484
485                /** Cached links from SubMeshes to (potentially optimised) geometry
486                        This is not used for deletion since the lookup may reference
487                        original vertex data
488                */
489                SubMeshGeometryLookup mSubMeshGeometryLookup;
490                       
491                /// Map of regions
492                RegionMap mRegionMap;
493
494                /** Virtual method for getting a region most suitable for the
495                        passed in bounds. Can be overridden by subclasses.
496                */
497                virtual Region* getRegion(const AxisAlignedBox& bounds, bool autoCreate);
498                /** Get the region within which a point lies */
499                virtual Region* getRegion(const Vector3& point, bool autoCreate);
500                /** Get the region using indexes */
501                virtual Region* getRegion(ushort x, ushort y, ushort z, bool autoCreate);
502                /** Get the region using a packed index, returns null if it doesn't exist. */
503                virtual Region* getRegion(uint32 index);
504                /** Get the region indexes for a point.
505                */
506                virtual void getRegionIndexes(const Vector3& point,
507                        ushort& x, ushort& y, ushort& z);
508                /** Pack 3 indexes into a single index value
509                */
510                virtual uint32 packIndex(ushort x, ushort y, ushort z);
511                /** Get the volume intersection for an indexed region with some bounds.
512                */
513                virtual Real getVolumeIntersection(const AxisAlignedBox& box, 
514                        ushort x, ushort y, ushort z);
515                /** Get the bounds of an indexed region.
516                */
517                virtual AxisAlignedBox getRegionBounds(ushort x, ushort y, ushort z);
518                /** Get the centre of an indexed region.
519                */
520                virtual Vector3 getRegionCentre(ushort x, ushort y, ushort z);
521                /** Calculate world bounds from a set of vertex data. */
522                virtual AxisAlignedBox calculateBounds(VertexData* vertexData,
523                        const Vector3& position, const Quaternion& orientation,
524                        const Vector3& scale);
525                /** Look up or calculate the geometry data to use for this SubMesh */
526                SubMeshLodGeometryLinkList* determineGeometry(SubMesh* sm);
527                /** Split some shared geometry into dedicated geometry. */
528                void splitGeometry(VertexData* vd, IndexData* id,
529                        SubMeshLodGeometryLink* targetGeomLink);
530
531                typedef std::map<size_t, size_t> IndexRemap;
532                /** Method for figuring out which vertices are used by an index buffer
533                        and calculating a remap lookup for a vertex buffer just containing
534                        those vertices.
535                */
536                template <typename T>
537                void buildIndexRemap(T* pBuffer, size_t numIndexes, IndexRemap& remap)
538                {
539                        remap.clear();
540                        for (size_t i = 0; i < numIndexes; ++i)
541                        {
542                                // use insert since duplicates are silently discarded
543                                remap.insert(IndexRemap::value_type(*pBuffer++, remap.size()));
544                                // this will have mapped oldindex -> new index IF oldindex
545                                // wasn't already there
546                        }
547                }
548                /** Method for altering indexes based on a remap. */
549                template <typename T>
550                void remapIndexes(T* src, T* dst, const IndexRemap& remap,
551                                size_t numIndexes)
552                {
553                        for (size_t i = 0; i < numIndexes; ++i)
554                        {
555                                // look up original and map to target
556                                IndexRemap::const_iterator ix = remap.find(*src++);
557                                assert(ix != remap.end());
558                                *dst++ = static_cast<T>(ix->second);
559                        }
560                }
561               
562        public:
563                /// Constructor; do not use directly (@see SceneManager::createStaticGeometry)
564                StaticGeometry(SceneManager* owner, const String& name);
565                /// Destructor
566                virtual ~StaticGeometry();
567
568                /// Get the name of this object
569                const String& getName(void) const { return mName; }
570                /** Adds an Entity to the static geometry.
571                @remarks
572                        This method takes an existing Entity and adds its details to the
573                        list of elements to include when building. Note that the Entity
574                        itself is not copied or referenced in this method; an Entity is
575                        passed simply so that you can change the materials of attached
576                        SubEntity objects if you want. You can add the same Entity
577                        instance multiple times with different material settings
578                        completely safely, and destroy the Entity before destroying
579                        this StaticGeometry if you like. The Entity passed in is simply
580                        used as a definition.
581                @note Must be called before 'build'.
582                @param ent The Entity to use as a definition (the Mesh and Materials
583                        referenced will be recorded for the build call).
584                @param position The world position at which to add this Entity
585                @param orientation The world orientation at which to add this Entity
586                @param scale The scale at which to add this entity
587                */
588                virtual void addEntity(Entity* ent, const Vector3& position,
589                        const Quaternion& orientation = Quaternion::IDENTITY,
590                        const Vector3& scale = Vector3::UNIT_SCALE);
591
592                /** Adds all the Entity objects attached to a SceneNode and all it's
593                        children to the static geometry.
594                @remarks
595                        This method performs just like addEntity, except it adds all the
596                        entities attached to an entire sub-tree to the geometry.
597                        The position / orientation / scale parameters are taken from the
598                        node structure instead of being specified manually.
599                @note
600                        The SceneNode you pass in will not be automatically detached from
601                        it's parent, so if you have this node already attached to the scene
602                        graph, you will need to remove it if you wish to avoid the overhead
603                        of rendering <i>both</i> the original objects and their new static
604                        versions! We don't do this for you incase you are preparing this
605                        in advance and so don't want the originals detached yet.
606                @note Must be called before 'build'.
607                @param node Pointer to the node to use to provide a set of Entity
608                        templates
609                */
610                virtual void addSceneNode(const SceneNode* node);
611
612                /** Build the geometry.
613                @remarks
614                        Based on all the entities which have been added, and the batching
615                        options which have been set, this method constructs     the batched
616                        geometry structures required. The batches are added to the scene
617                        and will be rendered unless you specifically hide them.
618                @note
619                        Once you have called this method, you can no longer add any more
620                        entities.
621                */
622                virtual void build(void);
623
624                /** Destroys all the built geometry state (reverse of build).
625                @remarks
626                        You can call build() again after this and it will pick up all the
627                        same entities / nodes you queued last time.
628                */
629                virtual void destroy(void);
630
631                /** Clears any of the entities / nodes added to this geometry and
632                        destroys anything which has already been built.
633                */
634                virtual void reset(void);
635
636                /** Sets the distance at which batches are no longer rendered.
637                @remarks
638                        This lets you turn off batches at a given distance. This can be
639                        useful for things like detail meshes (grass, foliage etc) and could
640                        be combined with a shader which fades the geometry out beforehand
641                        to lessen the effect.
642                @param dist Distance beyond which the batches will not be rendered
643                        (the default is 0, which means batches are always rendered).
644                */
645                virtual void setRenderingDistance(Real dist) {
646                        mUpperDistance = dist;
647                        mSquaredUpperDistance = mUpperDistance * mUpperDistance;
648                }
649
650                /** Gets the distance at which batches are no longer rendered. */
651                virtual Real getRenderingDistance(void) const { return mUpperDistance; }
652
653                /** Gets the squared distance at which batches are no longer rendered. */
654                virtual Real getSquaredRenderingDistance(void) const
655                { return mSquaredUpperDistance; }
656
657                /** Hides or shows all the batches. */
658                virtual void setVisible(bool visible);
659
660                /** Are the batches visible? */
661                virtual bool isVisible(void) const { return mVisible; }
662
663                /** Sets whether this geometry should cast shadows.
664                @remarks
665                        No matter what the settings on the original entities,
666                        the StaticGeometry class defaults to not casting shadows.
667                        This is because, being static, unless you have moving lights
668                        you'd be better to use precalculated shadows of some sort.
669                        However, if you need them, you can enable them using this
670                        method. If the SceneManager is set up to use stencil shadows,
671                        edge lists will be copied from the underlying meshes on build.
672                        It is essential that all meshes support stencil shadows in this
673                        case.
674                @note If you intend to use stencil shadows, you must set this to
675                        true before calling 'build' as well as making sure you set the
676                        scene's shadow type (that should always be the first thing you do
677                        anyway). You can turn shadows off temporarily but they can never
678                        be turned on if they were not at the time of the build.
679                */
680                virtual void setCastShadows(bool castShadows);
681                /// Will the geometry from this object cast shadows?
682                virtual bool getCastShadows(void) { return mCastShadows; }
683
684                /** Sets the size of a single region of geometry.
685                @remarks
686                        This method allows you to configure the physical world size of
687                        each region, so you can balance culling against batch size. Entities
688                        will be fitted within the batch they most closely fit, and the
689                        eventual bounds of each batch may well be slightly larger than this
690                        if they overlap a little. The default is Vector3(1000, 1000, 1000).
691                @note Must be called before 'build'.
692                @param size Vector3 expressing the 3D size of each region.
693                */
694                virtual void setRegionDimensions(const Vector3& size) {
695                        mRegionDimensions = size;
696                        mHalfRegionDimensions = size * 0.5;
697                }
698                /** Gets the size of a single batch of geometry. */
699                virtual const Vector3& getRegionDimensions(void) const { return mRegionDimensions; }
700                /** Sets the origin of the geometry.
701                @remarks
702                        This method allows you to configure the world centre of the geometry,
703                        thus the place which all regions surround. You probably don't need
704                        to mess with this unless you have a seriously large world, since the
705                        default set up can handle an area 1024 * mRegionDimensions, and
706                        the sparseness of population is no issue when it comes to rendering.
707                        The default is Vector3(0,0,0).
708                @note Must be called before 'build'.
709                @param size Vector3 expressing the 3D origin of the geometry.
710                */
711                virtual void setOrigin(const Vector3& origin) { mOrigin = origin; }
712                /** Gets the origin of this geometry. */
713                virtual const Vector3& getOrigin(void) const { return mOrigin; }
714
715        /** Sets the render queue group this object will be rendered through.
716        @remarks
717            Render queues are grouped to allow you to more tightly control the ordering
718            of rendered objects. If you do not call this method, all  objects default
719            to the default queue (RenderQueue::getDefaultQueueGroup), which is fine for
720                        most objects. You may want to alter this if you want to perform more complex
721                        rendering.
722        @par
723            See RenderQueue for more details.
724        @param queueID Enumerated value of the queue group to use.
725        */
726        virtual void setRenderQueueGroup(RenderQueueGroupID queueID);
727
728        /** Gets the queue group for this entity, see setRenderQueueGroup for full details. */
729        virtual RenderQueueGroupID getRenderQueueGroup(void) const;
730               
731                /// Iterator for iterating over contained regions
732                typedef MapIterator<RegionMap> RegionIterator;
733                /// Get an iterator over the regions in this geometry
734                RegionIterator getRegionIterator(void);
735
736                /** Dump the contents of this StaticGeometry to a file for diagnostic
737                        purposes.
738                */
739                virtual void dump(const String& filename) const;
740
741
742        };
743
744}
745
746#endif
747
Note: See TracBrowser for help on using the repository browser.