Functions to generate stock resources. More...
#include <sceneview/stock_resources.hpp>
Public Types | |
enum | StockShaderId { kUniformColorNoLighting, kUniformColorLighting, kPerVertexColorNoLighting, kPerVertexColorLighting, kTextureUniformColorNoLighting, kTextureUniformColorLighting, kBillboardTextured, kBillboardUniformColor } |
Public Member Functions | |
StockResources (const ResourceManager::Ptr &resources) | |
Constructor. | |
GeometryResource::Ptr | Cone () |
Retrieves the stock cone geometry resource. More... | |
GeometryResource::Ptr | Cube () |
Retrieves the stock cone geometry resource. More... | |
GeometryResource::Ptr | Cylinder () |
Retrieve the stock cylinder geometry resource. More... | |
GeometryResource::Ptr | Sphere () |
Retrieve the stock sphere geometry resource. More... | |
Drawable::Ptr | UnitAxes () |
Stock unit axes, with: More... | |
ShaderResource::Ptr | Shader (StockShaderId id) |
Retrieve the shader resource corresponding to the specified stock shader. | |
MaterialResource::Ptr | NewMaterial (StockShaderId id) |
Convenience method that makes a new material attached to a stock shader. More... | |
Static Public Member Functions | |
static GeometryData | ConeData () |
Generate geometry data for a cone. More... | |
static GeometryData | CubeData () |
Generate geometry data for a unit cube. More... | |
static GeometryData | CylinderData () |
Generate geometry data for a cylinder that fits in a unit cube centered on the origin. More... | |
static GeometryData | SphereData () |
Generate geometry data for a sphere of diameter 1 centered at the origin. | |
static GeometryData | UnitAxesData () |
Generate geometry data for a set of unit axes. | |
Functions to generate stock resources.
The following methods can be used to retrieve stock geometry resources:
When using these methods, each stock geometry resource is reused if it's already been created. They are maintained with a reference counted pointer, so when the last reference to the goes out of scope, the geometry is destroyed.
e.g.,:
Similar to the methods for retrieving stock geometry resources, there are also static methods for generating the raw geometry data used by the resources. These methods might be useful if you're bypassing the Sceneview rendering engine, or you want to modify the data somehow before using it.
Enumerator | |
---|---|
kUniformColorNoLighting |
Color is identical for all vertices, and there is no lighting. To specify the color, use the MaterialResource parameter sv::kColor. For example: ResourceManager::Ptr resources = GetResourceManager();
Scene::Ptr scene = GetScene();
StockResources stock(resources);
MaterialResource::Ptr material =
stock.NewMaterial(StockResources::kUniformColorNoLighting);
material->SetParam(sv::kColor, 0.0, 1.0, 0.0, 1.0);
scene->MakeDrawNode(scene->Root(), stock.Cube(), material);
|
kUniformColorLighting |
Uses the stock lighting model with identical colors for all vertices. To specify the colors, use the following MaterialResource parameters:
All parameters are optional, and if not specified default to 0.0. For example: ResourceManager::Ptr resources = GetResourceManager();
Scene::Ptr scene = GetScene();
StockResources stock(resources);
MaterialResource::Ptr material =
stock.NewMaterial(StockResources::kUniformColorLighting);
material->SetParam(sv::kDiffuse, 0.9, 0.0, 0.0, 1.0);
scene->MakeDrawNode(scene->Root(), stock.Cube(), material);
|
kPerVertexColorNoLighting |
Color is specified on a per-vertex basis, with no lighting calculations. To specify the vertex color, use the GeometryData::diffuse field. |
kPerVertexColorLighting |
Uses the stock lighting model with colors specified on a per-vertex basis. To specify a vertex color, use the diffuse, specular, and shininess fields of the GeometryData structure. For example: GeometryData gdata;
gdata.gl_mode = GL_TRIANGLES;
gdata.vertices.emplace_back(0, 0, 0);
gdata.vertices.emplace_back(1, 0, 0);
gdata.vertices.emplace_back(0, 1, 0);
gdata.normals.emplace_back(0, 0, 1);
gdata.normals.emplace_back(0, 0, 1);
gdata.normals.emplace_back(0, 0, 1);
gdata.diffuse.emplace_back(1, 0, 0);
gdata.diffuse.emplace_back(0, 1, 0);
gdata.diffuse.emplace_back(0, 0, 1);
gdata.specular.emplace_back(1, 0, 0);
gdata.specular.emplace_back(0, 1, 0);
gdata.specular.emplace_back(0, 0, 1);
gdata.shininess.push_back(16);
gdata.shininess.push_back(16);
gdata.shininess.push_back(16);
ResourceManager::Ptr resources = GetResourceManager();
GeometryResource::Ptr geometry = resources->MakeGeometry();
geometry->Load(gdata);
StockResources stock(resources);
MaterialResource::Ptr material =
stock.NewMaterial(StockResources::kPerVertexColorLighting);
Scene::Ptr scene = GetScene();
scene->MakeDrawNode(scene->Root(), geometry, material);
|
kTextureUniformColorNoLighting |
Like kUniformColorNoLighting with the addition of a texture map. Color is calculated by multiplying the uniform color by the texture color. To use this shader with a material:
For example: GeometryData gdata;
gdata.gl_mode = GL_TRIANGLES;
gdata.vertices = {
{ 0, 0, 0 },
{ 0, 1, 0 },
{ 1, 1, 0 },
{ 1, 0, 0 }
};
gdata.tex_coords_0 = {
{ 0, 0 },
{ 1, 0 },
{ 1, 1 },
{ 0, 1 }
};
gdata.indices = { 0, 1, 2, 0, 2, 3 };
ResourceManager::Ptr resources = GetResourceManager();
GeometryResource::Ptr geometry = resources->MakeGeometry();
geometry->Load(gdata);
StockResources stock(resources);
MaterialResource::Ptr material =
stock.NewMaterial(StockResources::kTextureUniformColorNoLighting);
material->SetParam(sv::kColor, 1.0, 1.0, 1.0, 1.0);
QImage image(400, 400, QImage::Format_RGB888);
image.fill(QColor(255, 0, 0));
QOpenGLTexture* texture = new QOpenGLTexture(image);
material->AddTexture(sv::kTexture, texture);
Scene::Ptr scene = GetScene();
scene->MakeDrawNode(scene->Root(), geometry, material);
|
kTextureUniformColorLighting |
Like kUniformColorLighting with the addition of a texture map. |
GeometryResource::Ptr sv::StockResources::Cone | ( | ) |
Retrieves the stock cone geometry resource.
|
static |
Generate geometry data for a cone.
GeometryResource::Ptr sv::StockResources::Cube | ( | ) |
Retrieves the stock cone geometry resource.
|
static |
Generate geometry data for a unit cube.
GeometryResource::Ptr sv::StockResources::Cylinder | ( | ) |
Retrieve the stock cylinder geometry resource.
|
static |
Generate geometry data for a cylinder that fits in a unit cube centered on the origin.
MaterialResource::Ptr sv::StockResources::NewMaterial | ( | StockShaderId | id | ) |
Convenience method that makes a new material attached to a stock shader.
Calling this method is equivalent to:
For information on how to adjust the material parameters, see the documentation for the specified stock shader id.
GeometryResource::Ptr sv::StockResources::Sphere | ( | ) |
Retrieve the stock sphere geometry resource.
Drawable::Ptr sv::StockResources::UnitAxes | ( | ) |
Stock unit axes, with:
This is returned as a Drawable since the geometry (the axes) is paired with a material (the color properties).
The returned object can be directly added to a DrawNode. e.g.,: