samedi 28 décembre 2019

What is the best design pattern to build an object with different argument requirements depending on its creation?

I have a C++ program that renders 3D objects. Each object is represented by a mesh. To minimize the memory usage, I'd like to avoid identical meshes being loaded more than once and instead have objects regardless of material and other rendering parameters reference the same mesh in a mesh manager class. Mesh creation could be requested from the mesh manager class. Provided an identical mesh is not already created, a new mesh would be generated. However, meshes can be created any number of ways, either procedurally as primitives, such as spheres, cubes, planes, cones, etc., or loaded from various file types. The issue, though, is that each mesh creation option has its own unique argument requirements and mesh creation must be extensible for future scaling. A cone would require a radius of the base and height while a cube requires only a side length and for a file, a file location and/or file type to be loaded from. I have thought about factory and builder design patterns but examples of both are generally shown where each polymorphic creation has the same arguments. For this particular problem, what are the best design patterns or approaches?

Aucun commentaire:

Enregistrer un commentaire