1#include "MeshGenerator.h"
3#include "MeshGeneratorCube.h"
4#include "MeshGeneratorSphere.h"
5#include "MeshGeneratorCylinder.h"
6#include "MeshGeneratorCone.h"
7#include "MeshGeneratorCircularArc.h"
9#include "Resources/MeshManager.h"
11#include <unordered_map>
19 std::unordered_map<size_t, MeshHandle> shapes;
24Cogs::Core::MeshGenerator::MeshGenerator(
Context * context) :
30Cogs::Core::MeshGenerator::~MeshGenerator()
34void Cogs::Core::MeshGenerator::cleanup()
43 refinementLevel(samples, kRefinementLevels, kMaxSamples),
49 size_t hashValue =
hash(definition);
51 auto found = cache->shapes.find(hashValue);
53 if (found != cache->shapes.end()) {
57 auto meshHandle = context->meshManager->create();
58 auto mesh = meshHandle.resolve();
60 getMesh(mesh, definition);
67void Cogs::Core::MeshGenerator::purgeCache()
69 cache->shapes.clear();
75 switch (definition.type) {
77 planeFactory(mesh, definition);
81 sphereGeoTexSphFactory<ShapeType::SphereGeoTexSph>(mesh, definition, kRefinementLevels, kMaxSamples);
84 sphereGeoTexSphFactory<ShapeType::SphereGeoTexCyl>(mesh, definition, kRefinementLevels, kMaxSamples);
87 cylinderFactory(mesh, definition, kRefinementLevels, kMaxSamples);
90 coneFactory(mesh, definition, kRefinementLevels, kMaxSamples);
94 cubeTex2DFactory(mesh, definition);
96 case ShapeType::WireCube:
97 wireCubeFactory(mesh, definition);
100 coordSysFactory(mesh, definition);
103 circularArcFactory(mesh, definition);
A Context instance contains all the services, systems and runtime components needed to use Cogs.
ShapeType
Shape types generated by mesh generator.
@ CubeTex2D
Cube shape with unit square texture coordinates over each face.
@ CircularArc
Flat circular arc with inner (size.x) and outer (size.y) radius on the XY plane. Can be extended (arc...
@ Cylinder
Generic cylinder shape.
@ SphereGeoTexCyl
Sphere shape with geodesic tessellation and cylindrical texture coordinates.
@ SphereGeoTexSph
Sphere shape with geodesic tessellation and spherical texture coordinates.
@ Cube
Generic cube shape.
@ Sphere
Generic sphere shape.
@ Cone
Generic cone shape.
@ CoordSys
Simple coordinate system where X axis is red, Y axis is green and Z axis is blue.
Contains all Cogs related functionality.
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
Meshes contain streams of vertex data in addition to index data and options defining geometry used fo...
Defines creation values for a unique shape.