opensurgsim
Namespaces | Typedefs | Functions
GraphicsUtilities.h File Reference

The code in here is supposed to help create materials correctly, a lot of it is boilerplate that is repeated over for each material. More...

#include <memory>
#include <unordered_map>
#include <string>
#include "SurgSim/Math/Vector.h"

Go to the source code of this file.

Namespaces

 SurgSim
 Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui needs glew but we need to call glewInit() from a osg callback, using this call we avoid getting warnings about redefinitions.
 

Typedefs

typedef std::unordered_map< std::string, std::shared_ptr< SurgSim::Graphics::OsgMaterial > > SurgSim::Blocks::Materials
 

Functions

void SurgSim::Blocks::enable2DTexture (std::shared_ptr< SurgSim::Graphics::OsgMaterial > material, const std::string &uniform, int unit, const std::string &filename="", bool repeat=false)
 Provide a consistent interface to add texture uniforms on materials, adds the actual texture with a given minimum unit, or provides a placeholder uniform for the unit. More...
 
std::shared_ptr< SurgSim::Graphics::OsgMaterialSurgSim::Blocks::createPlainMaterial (const std::string &name, SurgSim::Math::Vector4f diffuseColor, SurgSim::Math::Vector4f specularColor, float shininess)
 Create a basic material. More...
 
std::shared_ptr< SurgSim::Graphics::OsgMaterialSurgSim::Blocks::createTexturedMaterial (const std::string &name, SurgSim::Math::Vector4f diffuseColor, SurgSim::Math::Vector4f specularColor, float shininess, const std::string &diffuseMap="")
 Create a basic textured material. More...
 
std::shared_ptr< Graphics::OsgMaterial > SurgSim::Blocks::createNormalMappedMaterial (const std::string &name, SurgSim::Math::Vector4f diffuseColor, SurgSim::Math::Vector4f specularColor, float shininess, const std::string &diffuseMap="", const std::string &normalMap="")
 Create a basic textured material. More...
 
void SurgSim::Blocks::applyMaterials (std::shared_ptr< SurgSim::Framework::Scene > scene, std::string materialFilename, const Materials &materials)
 Reads a material file, iterates over the components listed up in the material file and applies the materials and the appropriate material properties (if present) to the component, if the component is not found it will be ignored The material file is a yaml file with the following format. More...
 

Detailed Description

The code in here is supposed to help create materials correctly, a lot of it is boilerplate that is repeated over for each material.

It will have to be changed if the shaders being used change.

Function Documentation

§ applyMaterials()

void SurgSim::Blocks::applyMaterials ( std::shared_ptr< SurgSim::Framework::Scene scene,
std::string  materialFilename,
const Materials &  materials 
)

Reads a material file, iterates over the components listed up in the material file and applies the materials and the appropriate material properties (if present) to the component, if the component is not found it will be ignored The material file is a yaml file with the following format.

  • SceneElementName/ComponentName> Material: MaterialName Properties:
    • [GLSLUniformType, UniformName, YamlEncodedValue]
    • [GLSLUniformType, UniformName, YamlEncodedValue]
  • SceneElementName/ComponentName Material: ...

The name of the SceneElement and the Component addressed need to be be separated by a '/' character. For each of the properties a uniform is created with the given GLSL type, name, and the YAML node will be passed to the uniform setter for conversion. If the type does not match what the appropriate GLSL type is, there will be an error. GLSLUniformType is e.g. vec3, vec4, float, mat4 ...

Parameters
sceneThe scene to traverse for component lookup
materialFilenamethe YAML file that contains the descriptions
materialslookup table for all the materials that are available

§ createNormalMappedMaterial()

std::shared_ptr< SurgSim::Graphics::OsgMaterial > SurgSim::Blocks::createNormalMappedMaterial ( const std::string &  name,
SurgSim::Math::Vector4f  diffuseColor,
SurgSim::Math::Vector4f  specularColor,
float  shininess,
const std::string &  diffuseMap = "",
const std::string &  normalMap = "" 
)

Create a basic textured material.

Parameters
namename of the material
diffuseColorBase diffuse color to use
specularColorBase specular color to use
shininessPhong shininess exponent
diffuseMapDiffuse texture map name to use, if the texture is embedded in the object pass an empty string here, it has to occupy the correct texture unit as defined by
See also
DIFFUSE_TEXTURE_UNIT.
Parameters
normalMapNormal texture map to use, if the texture is embedded in the object pass an empty string here, it has to occupy the correct texture unit as defined by
See also
NORMAL_TEXTURE_UNIT.

§ createPlainMaterial()

std::shared_ptr< SurgSim::Graphics::OsgMaterial > SurgSim::Blocks::createPlainMaterial ( const std::string &  name,
SurgSim::Math::Vector4f  diffuseColor,
SurgSim::Math::Vector4f  specularColor,
float  shininess 
)

Create a basic material.

Parameters
namename of the material
diffuseColorBase diffuse color to use
specularColorBase specular color to use
shininessPhong shininess exponent

§ createTexturedMaterial()

std::shared_ptr< SurgSim::Graphics::OsgMaterial > SurgSim::Blocks::createTexturedMaterial ( const std::string &  name,
SurgSim::Math::Vector4f  diffuseColor,
SurgSim::Math::Vector4f  specularColor,
float  shininess,
const std::string &  diffuseMap = "" 
)

Create a basic textured material.

Parameters
namename of the material
diffuseColorBase diffuse color to use
specularColorBase specular color to use
shininessPhong shininess exponent
diffuseMapDiffuse texture map name to use, if the texture is embedded in the object pass an empty string here, it has to occupy the correct texture unit though.

§ enable2DTexture()

void SurgSim::Blocks::enable2DTexture ( std::shared_ptr< SurgSim::Graphics::OsgMaterial material,
const std::string &  uniform,
int  unit,
const std::string &  filename = "",
bool  repeat = false 
)

Provide a consistent interface to add texture uniforms on materials, adds the actual texture with a given minimum unit, or provides a placeholder uniform for the unit.

Parameters
materialThe material for adding the texture
uniformThe name of the uniform to use
unitThe texture unit to use
filenameThe file to use for the texture,
repeatwhether to create the texture as repeating
Note
if the texture filename is empty a placeholder uniform will be created using the unit as a value this for using objects with textures built in without having to assign the texture to the material on creation