Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | List of all members
sv::StockResources Class Reference

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.
 

Detailed Description

Functions to generate stock resources.

Stock geometry 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.,:

ResourceManager::Ptr resources = GetResourceManager();
StockResources stock(resources);
GeometryResource::Ptr cone1 = stock.Cone();
GeometryResource::Ptr cone2 = stock.Cone();
// At this point, cone1 == cone2.
cone1.reset();
cone2.reset();
// Now that the last reference to the cone geometry has gone out of scope,
// the actual resources used by the cone geometry are released and
// destroyed.

Stock geometry data

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.

Member Enumeration Documentation

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 =
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:

  • sv::kDiffuse : 4 floats
  • sv::kSpecular : 4 floats
  • sv::kShininess : 1 float

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 =
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 =
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:

  • set the uniform color via MaterialResource::SetParam(sv::kColor, r, g, b, a);
  • bind the texture via MaterialResource::AddTexture(sv::kTexture0, texture_);

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 =
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.

Member Function Documentation

GeometryResource::Ptr sv::StockResources::Cone ( )

Retrieves the stock cone geometry resource.

  • Tip is at Z = +0.5
  • Base is at Z = -0.5
  • The cone fits in a unit cube centered on the origin.
static GeometryData sv::StockResources::ConeData ( )
static

Generate geometry data for a cone.

  • Tip is at Z = +0.5
  • Base is at Z = -0.5
  • The cone fits in a unit cube centered on the origin.
GeometryResource::Ptr sv::StockResources::Cube ( )

Retrieves the stock cone geometry resource.

  • Each dimension is unit length.
  • The cube is centered at the origin in model space.
static GeometryData sv::StockResources::CubeData ( )
static

Generate geometry data for a unit cube.

  • Each dimension is unit length.
  • The cube is centered at the origin in model space.
GeometryResource::Ptr sv::StockResources::Cylinder ( )

Retrieve the stock cylinder geometry resource.

  • Diameter 1 and length 1.
  • The axis of revolution is the Z axis.
  • Centered on the origin.
static GeometryData sv::StockResources::CylinderData ( )
static

Generate geometry data for a cylinder that fits in a unit cube centered on the origin.

  • Diameter 1 and length 1.
  • The axis of revolution is the Z axis.
  • 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:

resources->MakeMaterial(stock_resources.Shader(id));

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.

  • Diameter 1
  • Centered on the origin.
Drawable::Ptr sv::StockResources::UnitAxes ( )

Stock unit axes, with:

  • X axis colored red
  • Y axis colored green
  • Z axis colored blue

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.,:

StockResources stock(resources);
DrawNode* draw_node = scene->MakeDrawNode(parent);
draw_node->Add(stock.UnitAxes());

The documentation for this class was generated from the following file: