forked from Gepetto/gepetto-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-drawable.cpp
56 lines (49 loc) · 1.61 KB
/
node-drawable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2018, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
#include <gepetto/viewer/node-drawable.h>
#include <osg/Texture2D>
#include <osg/Version>
#include <osgDB/ReadFile>
namespace gepetto {
namespace viewer {
void NodeDrawable::init() {
addProperty(Vector4Property::create(
"Color",
Vector4Property::getterFromMemberFunction(this, &NodeDrawable::getColor),
Vector4Property::setterFromMemberFunction(this,
&NodeDrawable::setColor)));
}
void NodeDrawable::setColor(const osgVector4& color) {
shape_drawable_ptr_->setColor(color);
redrawShape();
setTransparentRenderingBin(color[3] <
Node::TransparencyRenderingBinThreshold);
}
void NodeDrawable::redrawShape() {
#if OSG_VERSION_GREATER_OR_EQUAL(3, 5, 6)
shape_drawable_ptr_->build();
#else
shape_drawable_ptr_->dirtyDisplayList();
shape_drawable_ptr_->dirtyBound();
#endif
setDirty();
}
osgVector4 NodeDrawable::getColor() const {
return shape_drawable_ptr_->getColor();
}
void NodeDrawable::setTexture(const std::string& image_path) {
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC);
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(image_path);
if (!image) {
std::cerr << " couldn't find texture " << image_path << ", quiting."
<< std::endl;
return;
}
texture->setImage(image);
geode_ptr_->getStateSet()->setTextureAttributeAndModes(
0, texture, osg::StateAttribute::ON);
setDirty();
}
} /* namespace viewer */
} // namespace gepetto