Skip to content

Commit 8f2b705

Browse files
committed
ovis: implement setting diffuse color
1 parent 8a8d609 commit 8f2b705

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

modules/ovis/include/opencv2/ovis.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum MaterialProperty
3636
MATERIAL_LINE_WIDTH,
3737
MATERIAL_OPACITY,
3838
MATERIAL_EMISSIVE,
39+
MATERIAL_DIFFUSE,
3940
MATERIAL_TEXTURE0,
4041
MATERIAL_TEXTURE = MATERIAL_TEXTURE0,
4142
MATERIAL_TEXTURE1,

modules/ovis/src/ovis.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ static SceneNode& _getSceneNode(SceneManager* sceneMgr, const String& name)
171171
return *mo->getParentSceneNode();
172172
}
173173

174+
static ColourValue convertColor(const Scalar& val)
175+
{
176+
// BGR 0..255 (uchar) to RGB 0..1
177+
ColourValue ret = ColourValue(val[2], val[1], val[0]) / 255;
178+
ret.saturate();
179+
return ret;
180+
}
181+
174182
struct Application : public OgreBites::ApplicationContext, public OgreBites::InputListener
175183
{
176184
Ptr<LogManager> logMgr;
@@ -508,10 +516,7 @@ class WindowSceneImpl : public WindowScene
508516
{
509517
// hide background plane
510518
bgplane->setVisible(false);
511-
512-
// BGRA as uchar
513-
ColourValue _color = ColourValue(color[2], color[1], color[0], color[3]) / 255;
514-
rWin->getViewport(0)->setBackgroundColour(_color);
519+
rWin->getViewport(0)->setBackgroundColour(convertColor(color));
515520
}
516521

517522
void createEntity(const String& name, const String& meshname, InputArray tvec, InputArray rot) CV_OVERRIDE
@@ -970,8 +975,8 @@ void setMaterialProperty(const String& name, int prop, const Scalar& val)
970975
CV_Assert(mat);
971976

972977
Pass* rpass = mat->getTechniques()[0]->getPasses()[0];
973-
ColourValue col;
974978

979+
ColourValue col;
975980
switch (prop)
976981
{
977982
case MATERIAL_POINT_SIZE:
@@ -984,10 +989,13 @@ void setMaterialProperty(const String& name, int prop, const Scalar& val)
984989
rpass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
985990
rpass->setDepthWriteEnabled(false);
986991
break;
992+
case MATERIAL_DIFFUSE:
993+
col = convertColor(val);
994+
col.a = rpass->getDiffuse().a;
995+
rpass->setDiffuse(col);
996+
break;
987997
case MATERIAL_EMISSIVE:
988-
col = ColourValue(val[2], val[1], val[0]) / 255; // BGR as uchar
989-
col.saturate();
990-
rpass->setEmissive(col);
998+
rpass->setEmissive(convertColor(val));
991999
break;
9921000
case MATERIAL_LINE_WIDTH:
9931001
rpass->setLineWidth(val[0]);

0 commit comments

Comments
 (0)