ovis: allow manipulating entity material and scale at runtime

pull/1575/head
Pavel Rojtberg 7 years ago
parent 7d1aca38d3
commit 61b03565e6
  1. 17
      modules/ovis/include/opencv2/ovis.hpp
  2. 27
      modules/ovis/src/ovis.cpp

@ -38,6 +38,12 @@ enum MaterialProperty
MATERIAL_TEXTURE
};
enum EntityProperty
{
ENTITY_MATERIAL,
ENTITY_SCALE,
};
/**
* A 3D viewport and the associated scene
*/
@ -76,6 +82,17 @@ public:
*/
CV_WRAP virtual void removeEntity(const String& name) = 0;
/**
* set the property of an entity to the given value
* @param name entity name
* @param prop @ref EntityProperty
* @param value the value
*/
CV_WRAP virtual void setEntityProperty(const String& name, int prop, const Scalar& value) = 0;
/// @overload
CV_WRAP virtual void setEntityProperty(const String& name, int prop, const String& value) = 0;
/**
* convenience method to visualize a camera position
*

@ -427,6 +427,33 @@ public:
node.setPosition(t);
}
void setEntityProperty(const String& name, int prop, const String& value)
{
CV_Assert(prop == ENTITY_MATERIAL);
SceneNode& node = _getSceneNode(sceneMgr, name);
MaterialPtr mat = MaterialManager::getSingleton().getByName(value, RESOURCEGROUP_NAME);
CV_Assert(mat && "material not found");
Camera* cam = dynamic_cast<Camera*>(node.getAttachedObject(name));
if(cam)
{
cam->setMaterial(mat);
return;
}
Entity* ent = dynamic_cast<Entity*>(node.getAttachedObject(name));
CV_Assert(ent && "invalid entity");
ent->setMaterial(mat);
}
void setEntityProperty(const String& name, int prop, const Scalar& value)
{
CV_Assert(prop == ENTITY_SCALE);
SceneNode& node = _getSceneNode(sceneMgr, name);
node.setScale(value[0], value[1], value[2]);
}
void _createBackground()
{
String name = "_" + sceneMgr->getName() + "_DefaultBackground";

Loading…
Cancel
Save