New ogre plug-in pagedgeometry (massive scenario optimization and paging scheduling)

Source: Internet
Author: User

1. Introduction:
Pagedgeometry is a plug-in of the Ogre engine. It provides optimization policies for rendering massive grids in (infinite) regions. It is very suitable for dense forests and outdoor scenarios, where there are a large number of scenario objects such as trees, grass, rocks, and bushes.

2. pagedgeometry Management

Pagedgeometry class

This class is responsible for loading the scene ry that requires immediate (or rapid) visibility without loading other scenes to save memory space. The pagedgeometry engine can display entity objects through methods such as static ry and imposters ). These methods are related to the distance between the entity and the scene camera and your configuration.
Page loading is completed through the User-Defined pageloader. In this way, you can program to load pages, whether from files on the hard disk, programs, or other places.

Geometrypagemanager

It is used in the pagedgeometry class to manage paging pages and perform cacheing, deleting, and other work as needed. It calculates the page cathe speed by analyzing the camera distance, and deletes invisible pages that have passed the specified time.

Call pagedgeometry: adddetaillevel () to create geometrypagemanager.

Adddetaillevel () returns a pointer to this page manager, allowing you access to some useful functions, using ented below.

Some member functions in the class comment do not use and cannot be used by users. They are used in pagedgeometry.

Adddetaillevel ()

Adds a detail level to the pagedgeometry object.

Pagetype for this detail level, the type of page you want to use. It is not a function parameter, but a template parameter.

Maxrange: the maximum distance used by the detail level (the camera's line of sight)

Expected attenuation transition length of transitionlength-(optional)

Example:

Pagedtrees-> adddetaillevel (100); // use batched geometry from 0-100

Pagedtrees-> adddetaillevel (500); // use impostors from 100-500

The pagedgeometry object named pagedtrees uses batched (batch ry, static ry) within a range of 0-units of camera distance and imposters within a range of-units of distance.

If the existing page type is not suitable, you can easily add a custom geometrypage subclass.

The transitionlength parameter is not available by default, but you can add it by yourself. Its function is to make the detailed hierarchy more smooth. However, when using parameters, the rendering efficiency may be reduced by 10%-30%.

3. Page type

Class geometrypage

As mentioned above, this class is a virtual base class. You can extend the inheritance class to implement different methods to replace rendered entities, such as batched and imposters. If you need other page types, you can implement them by yourself.

The following are virtual functions that must be implemented in sub-classes:

Virtual void Init (scenemanager * Mgr, Camera * cam) = 0;

Virtual void setregion (real left, real top, real right, real bottom) = 0;

Virtual void addentity (entity * ent, const vector3 % 26amp; position, const quaternion % 26amp; rotation, const vector3 % 26amp; scale, const ogre: colourvalue % 26amp; color) = 0;

Virtual void build (){}

Virtual void removeentities () = 0;

Virtual void setvisible (bool visible) = 0;

Virtual void setfade (bool enabled, real visibledist, real invisibledist) = 0;

Virtual void Update (){}

The following figure shows how page Manager uses the above functions:

1. When pagedgeometry first creates a geometrypage and immediately calls its Init (), this function is like a constructor.

2. Prepare a geometric page for the object to be rendered and set the page area.

3. Add an object to the page, initialize the object location, and set the direction.

4. Add the entity to the last step in the scenario. It is automatically called after all object objects are added.

5. Delete the object from the page.

6. Make the entire page visible.

7. Set the page's reduction attribute.

8. Ensure that the page ry is updated in the frame loop.

Class batchpage

The batchpage class renders objects as static ry.

Static ry (staticgeometry): Many entities in a scenario do not move since they are added to the scenario, such as houses and trees. Ogre provides the staticgeometry class for this situation, it allows you to batch render many objects. this is usually much faster than manually adding scenenodes.

Class imposterpage

The impostorpage class. uses an object as an impostors (A Paster image that looks like a real object) for rendering.

Among all page types, this is the fastest. It uses impostors to replace the entities to be rendered. In this way, the video card only needs to render a series of 2D images instead of 3D mesh.

Class grasspage

A custom page type designed specifically for use with grassloader.

The grasspage page type is designed to work with grassloader.

This type has not been optimized. It just clones the given entity and binds it to a new scene node. This means poor performance.

4. batchedgeometry-a version of static ry

Class batchedgeometry

It is a lightweight version of ogre: staticgeometry.

Staticgeometry is a batch rendering class provided by Ogre for users. It can render all the "static" entities (entities) in the scene at one time, such as houses and trees.

It provides you with more control over Batch materials.

Class subbatch: Public ogre: renderable

Subbatch inherits from renderable and is an internal class of batchedgeometry. Its constructor transmits the batchedgeometry pointer and submesh pointer, which are included in batchedgeometry.

5. Loading entities

Class pageloader

Virtual base class. You can expand it to provide callback functions for page loading.

Pagedgeometry is preinstalled with several different loaders inherited from pageloader. Unlike many Object managers, pagedgeometry does not allow users to add all entities to objects at one time, because it is used in large-scale game scenarios, it will pagination the world's ry, and then schedule, Just load the page to be drawn.

As long as the engine needs to determine that the area of the world's ry needs to be loaded, it must call the pageloader member loadpage (). The pageinfo struct in the function provides information about the page's surrounding body. In the function

Addentity () to add an object to this page. You can also define attributes such as the scale, position, and rotation of the object.

After you create your own loader object, you must import its attatch to the pagedgeometry object. As follows:

Pagedgeometry-> setpageloader (yourpageloader );

Pageinfo: struct. Useful page information provided to pageloader. The basic information is to define the loaded region and other information about the region.

The structure contains a tbound (typedef ogre: trect tbounds). All objects on this page must be placed in this rectangle.

Specific loaders:

(1) grassloader inherits from pageloader and is used to generate real grassland scenarios together with pagedgeometry. The so-called real grassland simulation uses the grassloader member function addlayer () to add grass and updateanimation () to drive the animation.

After you create a grassloader object, you must attatch It To The pagedgeometry object. As follows:

Pagedgeometry-> setpageloader (grassloader );

Grasspage is recommended for lawn loader when using the geometric page type. This rendering efficiency is high, while grasspage is inefficient when using other types.

At the same time, a data structure is provided to fully control the grass Attribute Class grasslayer, which is added through addlayer (). This class provides a series of "set" methods, used to configure attributes such as material, density, and size of grass.

(2) treeloader2d inherits from pageloader and is used together with pagedgeometry to easily implement tree placement on the terrain.

The usage method is the same as the preceding. When used, addtrees () method adds trees to the scenario. It should be noted that the loader does not know the height of the terrain when loading trees, but assumes that the height is 0, which requires the current value (that is, when the X and Z values are given) the terrain height. Loader provides these methods.

(3) treeloader3d is similar to 2D, but the efficiency is about 40% lower. Treeloader3d is highly efficient in packaging trees in the memory. It is about 10 bytes of a tree, equivalent to 1 million trees with only MB of memory space. This is suitable for large-scale forest rendering.

The engine is 2D, and 3dloader provides some common tool classes, such as class treeref. The nature of inner functions provides get mathematical operations such as position, rotation, size, and direction for loader. Treeiterator2d and treeiterator3d provide the tree pointer operation for loader.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.