re: Geometry factory
Posted: Sun May 16, 2010 11:41 pm
We have lots of cool algorithms which create IMesh instances. In the engine we have cubes, spheres, skyboxes, skydomes, hillplanes, terrains, cylinders, cones, arrows and volume lights.
Currently there's no extensible way to add new creators, so they aren't serializable and there's no standard way to cache them.
As hybrid said earlier, it would be cool to support geometry factories. We could rename CGeometryCreator to CStandardGeometryFactory and have it inherit IGeometryFactory as well as IGeometryCreator, then add some new methods to the scene manager:
Okay, here's the bit which people may not like: we abuse mesh loaders and file archives to make them both serializable and actual files, using only the file name and mesh writers.
When the scene manager creates a piece of geometry using one of the factories, it also sets its name to something like: "geom:meshType/parameters.irrMesh"
Firstly, this acts as the name of and path to the file, which allows geometry creator meshes to exist in the mesh cache. The first part of the file name "geom:" is used to invoke the geometry file archive, which uses the geometry creators and the ".irrMesh" writer to create real file for reading!
We also add a "geom:" mesh loader, which is processed before all others and creates the meshes using the geometry creator.
The solution means that we have cacheable, serializable meshes which exist as virtual files in any format supported by the mesh writers!
Currently there's no extensible way to add new creators, so they aren't serializable and there's no standard way to cache them.
As hybrid said earlier, it would be cool to support geometry factories. We could rename CGeometryCreator to CStandardGeometryFactory and have it inherit IGeometryFactory as well as IGeometryCreator, then add some new methods to the scene manager:
Code: Select all
IMesh* createGeometry(const stringc &type, IAttributes *params);
u32 registerGeometryFactory(const IGeometryFactory* factory);
IGeometryFactory* getGeometryFactory(u32 index) const;
void unregisterGeometryFactory(u32 index);
When the scene manager creates a piece of geometry using one of the factories, it also sets its name to something like: "geom:meshType/parameters.irrMesh"
Firstly, this acts as the name of and path to the file, which allows geometry creator meshes to exist in the mesh cache. The first part of the file name "geom:" is used to invoke the geometry file archive, which uses the geometry creators and the ".irrMesh" writer to create real file for reading!
We also add a "geom:" mesh loader, which is processed before all others and creates the meshes using the geometry creator.
The solution means that we have cacheable, serializable meshes which exist as virtual files in any format supported by the mesh writers!