Skip to content

Commit b160c11

Browse files
author
Daniel Wickeroth
committed
colorAnim Plugin shows all vertex colors
1 parent bbbe5c7 commit b160c11

3 files changed

Lines changed: 49 additions & 15 deletions

File tree

config/config.daniel.xml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,17 @@
2727
<FileType name="fits" plugin="Volume" />
2828
</FileManager>
2929

30-
31-
30+
31+
3232
<WelcomeMessage value="Welcome to Daniel" />
3333

3434
<Plugin>
35-
<MADIconnect value="on">
36-
<DataPath value="/home/daniel/data/KeiIto/3neurons" />
37-
</MADIconnect>
38-
39-
<ANARI>
40-
<PointCloud radius="0.025" />
41-
</ANARI>
35+
<ColorAnim value="on">
36+
<FirstModel value="/home/daniel/data/Horn/surfaces/dynamic/cortex_sample/cortex_001.ply" />
37+
<SecondModel value="/home/daniel/data/Horn/surfaces/static/anatomy.ply" />
38+
<ThirdModel value="/home/daniel/data/Horn/surfaces/static/left_electrode.ply" />
39+
</ColorAnim>
4240

43-
<Vrml97>
44-
<TransparencyMode value="sorted_blended_alphatest" />
45-
<Headlight value="ON" />
46-
<Lights value="ON" />
47-
</Vrml97>
48-
4941
<OrientationIndicator value="off">
5042
<Position x="-700.0" y="0.0" z="-400.0" />
5143
<InvertX value="true" />

src/OpenCOVER/plugins/ukoeln/colorAnim/ColorAnimPlugin.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ bool ColorAnimPlugin::init()
185185
secondModel = osgDB::readNodeFile(secondModelPath);
186186
if (secondModel.valid())
187187
{
188+
setupVertexColorMaterial(secondModel.get());
188189
cover->getObjectsRoot()->addChild(secondModel.get());
189190
fprintf(stderr, "ColorAnimPlugin: Second model loaded successfully\n");
190191
}
@@ -202,6 +203,7 @@ bool ColorAnimPlugin::init()
202203
thirdModel = osgDB::readNodeFile(thirdModelPath);
203204
if (thirdModel.valid())
204205
{
206+
setupVertexColorMaterial(thirdModel.get());
205207
cover->getObjectsRoot()->addChild(thirdModel.get());
206208
fprintf(stderr, "ColorAnimPlugin: Third model loaded successfully\n");
207209
}
@@ -568,4 +570,43 @@ void ColorAnimPlugin::flipNormals()
568570
}
569571
}
570572

573+
void ColorAnimPlugin::setupVertexColorMaterial(osg::Node *node)
574+
{
575+
if (!node)
576+
return;
577+
578+
// Set up material to use vertex colors
579+
osg::StateSet *stateSet = node->getOrCreateStateSet();
580+
osg::Material *material = new osg::Material();
581+
material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
582+
stateSet->setAttributeAndModes(material, osg::StateAttribute::ON);
583+
584+
// If this is a geode, also set the material on each drawable
585+
osg::Geode *geode = dynamic_cast<osg::Geode*>(node);
586+
if (geode)
587+
{
588+
for (unsigned int i = 0; i < geode->getNumDrawables(); ++i)
589+
{
590+
osg::Drawable *drawable = geode->getDrawable(i);
591+
if (drawable)
592+
{
593+
osg::StateSet *drawableStateSet = drawable->getOrCreateStateSet();
594+
osg::Material *drawableMaterial = new osg::Material();
595+
drawableMaterial->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
596+
drawableStateSet->setAttributeAndModes(drawableMaterial, osg::StateAttribute::ON);
597+
}
598+
}
599+
}
600+
601+
// Recursively process child nodes
602+
osg::Group *group = node->asGroup();
603+
if (group)
604+
{
605+
for (unsigned int i = 0; i < group->getNumChildren(); ++i)
606+
{
607+
setupVertexColorMaterial(group->getChild(i));
608+
}
609+
}
610+
}
611+
571612
COVERPLUGIN(ColorAnimPlugin)

src/OpenCOVER/plugins/ukoeln/colorAnim/ColorAnimPlugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class ColorAnimPlugin : public coVRPlugin, public ui::Owner
9191
void flipNormals();
9292
float applyInterpolationCurve(float t);
9393
void setInterpolationMode(InterpolationMode mode);
94+
void setupVertexColorMaterial(osg::Node *node);
9495
};
9596

9697
#endif

0 commit comments

Comments
 (0)