PathEngine home previous: Defining an entry pointnext: The update loop
Contents, Programmers Guide, Example Projects, Tutorials, A basic application, Loading a mesh

Loading a mesh

To avoid the need for platform specific code inside PathEngine file system access for things like loading and saving are abstracted out, and must be performed by the client application.

We're going to load a ground mesh file. The first step for this will be to load the file into memory, with the resulting memory buffer then passed into PathEngine's loadMeshFromBuffer() method (iPathEngine::loadMeshFromBuffer()).

unique_ptr<iMesh> mesh;
        std::vector<char> buffer;
        LoadBinary("../resource/meshes/mesh1.xml", buffer);
        mesh = pathengine->loadMeshFromBuffer("xml", VectorBuffer(buffer), SizeUL(buffer), 0);

(The LoadBinary function is defined in the sampleShared directory, outside of the PathEngine API.)

The first argument to loadMeshFromBuffer() specifies how PathEngine should interpret the buffer.
See XML Ground Meshes for details about XML meshes.

The last argument to loadMeshFromBuffer() enables a set of arbitrary attributes to be passed in to control aspects of the mesh loading process.
(Refer to Handling Attributes for details about this attribute passing mechanism.)
In this case we simply pass a null pointer to indicate no attributes, since we just want the default mesh loading behaviour.

Note that the pointer to the newly created API object (pointing to an Interface iMesh object) is returned wrapped in a std::unique_ptr. This holds an 'external reference' to the API object for us, which will be released automatically when the unique_ptr goes out of scope, avoiding the need for error prone manual API object lifetime management. (See Ownership and Lifetimes.)

Setting the current mesh for the testbed

The following code sets the testbed current mesh to the mesh we have just loaded.
iTestBed::zoomExtents() tells the testbed to set up the camera so that the mesh fits nicely in the view.


Documentation for PathEngine release 6.03 - Copyright © 2002-2021 PathEnginenext: The update loop