OgrePlant        

From the Famfamfam Silk icon collection, a white page with black text. Description

The following classes are a C++ implementation of an ngplant to Ogre converter.

This is a somewhat bare-bones implementation, missing such obvious enhancements as customizable generated mesh and material names. It does include the necessary code to make ngp files first class Ogre resources.

This release is labeled version 1.1.

What works:

  • Material generation
  • Mesh generation
  • Usage of serialized mesh files

What's not implemented:

  • Support for ngplant's built-in LOD scheme
  • Support for ngplant's AUX0 and AUX1 textures

What's not tested:

  • Material generation with support for normal textures


No value assigned

Ogre 1.7

From the Famfamfam Silk collection, a white page with camera. Screenshots


Here's a sample of 7 different species of tree, with multiple varieties:

Panoramic sample of trees
Panoramic sample of trees

Here's a close-up of one of the species:

Close up of an individual
Close up of an individual

From the Famfamfam Silk icon collection, a green arrow pointing down. Download

Downloadable 7-Zip archive of all eight source files:

From the Famfamfam Silk icon collection, a white page with the yellow compressed icon reminiscent of the Winzip icon.

 Plugin disabled

Plugin attach cannot be executed.

Alternatively, the latest source can be downloaded from the
OgrePlant github repository

From the Famfamfam Silk icon collection, a white page with blue 'C++' text. Usage

  • Compile ngpcoreOnly the ngpcore library from ngplant is necessary to use this code. You may use its included SConstruct configuration to build it or simply manually include its source files in your project, either directly or as a library.
  • Add the eight source files to your project
  • Add the ngpcore include path to your project
  • Add the ngpcore link library and path to your project
  • Add the following somewhere in your project:

The following fragments won't work as-is. You'll need to put them in appropriate places to integrate them with your code.

First the necessary includes:

#include "OgrePlant.h"
#include "NGPFileManager.h"

Then initialization:

// Do this somewhere early in your initialization process.  It registers the ngpfile type.
// This pointer may be discarded since the NGPFileManager is an Ogre Singleton.
NGPFileManager *ngpFileManager = new NGPFileManager();

// Add a resource path that contains ngp files
Ogre::ResourceGroupmanager::getSingleton().addResourceLocation("media/plants", "Filesystem");

PlantManager pm;

Then to create a plant:

Entity *entity;

if(pm.loadPlant("samplefern.ngp"))
{
  OGRE_LOG("Successfully loaded samplefern.ngp")
  entity = mSceneManager->createEntity("Sample Fern", "samplefern.ngp.mesh");
}
else
  OGRE_LOG("Failed to load samplefern.ngp")

To get different variations of the same plant, pass in a seed:

 Caveat

The generated mesh is always named "input.ngp.mesh", so you'll have to remove or rename a mesh generated with a different seed before reusing an ngp file with loadPlant() to avoid a collision in Ogre's resource system. FIXED - name now "input.ngp_seed.mesh"

 Note

This version always serializes the generated mesh and material files to disk when calling loadPlant(). Serious users will probably want to modify that behavior. FIXED - use loadPlantAsMesh() instead, as below.

Entity *entity;

if(pm.loadPlant("samplefern.ngp", 1234))
{
  OGRE_LOG("Successfully loaded samplefern.ngp")
  entity = mSceneManager->createEntity("Sample Fern 1234", "samplefern.ngp.mesh");
}
else
  OGRE_LOG("Failed to load samplefern.ngp")



To load the same plant with seed, but without serializing the mesh and materials to disk:

Entity *entity;

Ogre::MeshPtr mesh_ptr = pm.loadPlantAsMesh("samplefern.ngp", 1234);
if(!mesh_ptr.isNull())
{
  OGRE_LOG("Successfully loaded samplefern.ngp")
  entity = mSceneManager->createEntity("Sample Fern 1234", mesh_ptr);
  // if you wish to later serialize the .mesh and .materials, call:
  // pm.serializePlant(mesh_ptr);
}
else
  OGRE_LOG("Failed to load samplefern.ngp")

Assuming samplefern.ngp is in the media/plants directory (in this example) and its texture is in the same or another of your resource paths, once this code executes you'll have an Ogre entity suitable for attaching to a SceneNode. It can also be used in Paged Geometry running in DirectX. It will not work correctly in Paged Geometry under OpenGL due to a bug in Paged Geometry. However, if you put the resulting .mesh and .material files into one of your resource paths and create an entity by loading them, it will work just fine in Paged Geometry in either DX or GL.

[+] From the Famfamfam Silk icon collection, a white page with blue 'C++' text. Source

The Ogre eye 16x16 icon. Compatibility

This code is known to work in Ogre 1.7 and Ogre 1.8 and Ogre 1.9.