void LinkPointActor::setLinkPointState(int state) { _state = state; switch (_state) { case 1: { osg::ref_ptr<osg::StateSet> ss = g_SystemContext._resourceLoader->getPublicStateSetByDrawableName(POINT_STATE_IDLE); setStateSet(ss); break; } case 2: { osg::ref_ptr<osg::StateSet> ss = g_SystemContext._resourceLoader->getPublicStateSetByDrawableName(POINT_STATE_NOTIDLE); setStateSet(ss); break; } case 3: { osg::ref_ptr<osg::StateSet> ss = g_SystemContext._resourceLoader->getPublicStateSetByDrawableName(POINT_STATE_NOTUSE); setStateSet(ss); break; } default: break; } }
SymbolNode::SymbolNode(std::string _id, std::string _stype) : osg::Group() { id = _id; stype = _stype; vel = osg::Vec3(0,0,0); pos = osg::Vec3(0,0,0); billboard = new osg::Billboard(); addChild(billboard); billboard->setMode(osg::Billboard::POINT_ROT_EYE); osg::StateSet* stateset = new osg::StateSet(); osg::Image* image = osgDB::readImageFile("texture.png"); if (image) { osg::Texture2D* texture = new osg::Texture2D; texture->setImage(image); texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); } stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON); setStateSet(stateset); osg::TessellationHints* hints = new osg::TessellationHints; hints->setDetailRatio(0.6f); sphere = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f), RADIUS), hints); billboard->addDrawable(sphere); osgText::Font *font = osgText::readFontFile("fonts/arial.ttf"); osg::Vec4 fontSizeColor(0.6f, 0.0f, 0.0f, 100.0f); osg::Vec3 cursor; cursor = osg::Vec3(0, -RADIUS, 0.52*RADIUS); textId = new osgText::Text; textId->setFont(font); textId->setCharacterSize(120); textId->setAxisAlignment(osgText::TextBase::XZ_PLANE); textId->setPosition(cursor); textId->setColor(fontSizeColor); textId->setAlignment(osgText::Text::CENTER_CENTER); textId->setFontResolution(1000, 1000); textId->setText(id); billboard->addDrawable(textId); cursor = osg::Vec3(0, -RADIUS, -0.35*RADIUS); textType = new osgText::Text; textType->setFont(font); textType->setCharacterSize(120); textType->setAxisAlignment(osgText::TextBase::XZ_PLANE); textType->setPosition(cursor); textType->setColor(fontSizeColor); textType->setAlignment(osgText::Text::CENTER_CENTER); textType->setFontResolution(10,10); textType->setText(stype); billboard->addDrawable(textType); }
LightPointNode::LightPointNode(): _minPixelSize(0.0f), _maxPixelSize(30.0f), _maxVisibleDistance2(FLT_MAX), _lightSystem(0), _pointSprites(false) { setStateSet(getSingletonLightPointSystemSet()); }
void SkyDome::setupStateSet( osg::TextureCubeMap* cubemap ) { osg::StateSet* ss = new osg::StateSet; ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF); ss->setTextureAttributeAndModes( 0, cubemap, osg::StateAttribute::ON ); ss->setAttributeAndModes( createShader().get(), osg::StateAttribute::ON ); ss->addUniform( new osg::Uniform("uEnvironmentMap", 0) ); setStateSet(ss); }
std::shared_ptr<LabelVectorShape> VectorLayerEditor::_getLabel(const std::string &key, bool &newLabel) { auto label_it = _labels.find(key); if(label_it==_labels.end()) { auto label = std::make_shared<LabelVectorShape>(); auto bufferData = std::make_shared<BufferDataCollection>(); label->setBuffers( bufferData ); label->setStateSet( _labelStateSet ); _labels[key] = label; newLabel = true; return label; } newLabel = false; return (*label_it).second; }
void osgParticle::ParticleSystem::setDefaultAttributes(const std::string& texturefile, bool emissive_particles, bool lighting, int texture_unit) { osg::StateSet *stateset = new osg::StateSet; stateset->setMode(GL_LIGHTING, lighting? osg::StateAttribute::ON: osg::StateAttribute::OFF); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); osg::Material *material = new osg::Material; material->setSpecular(osg::Material::FRONT, osg::Vec4(0, 0, 0, 1)); material->setEmission(osg::Material::FRONT, osg::Vec4(0, 0, 0, 1)); material->setColorMode(lighting? osg::Material::AMBIENT_AND_DIFFUSE : osg::Material::OFF); stateset->setAttributeAndModes(material, osg::StateAttribute::ON); if (!texturefile.empty()) { osg::Texture2D *texture = new osg::Texture2D; texture->setImage(osgDB::readRefImageFile(texturefile)); texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR); texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR); stateset->setTextureAttributeAndModes(texture_unit, texture, osg::StateAttribute::ON); osg::TexEnv *texenv = new osg::TexEnv; texenv->setMode(osg::TexEnv::MODULATE); stateset->setTextureAttribute(texture_unit, texenv); } osg::BlendFunc *blend = new osg::BlendFunc; if (emissive_particles) { blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE); } else { blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); } stateset->setAttributeAndModes(blend, osg::StateAttribute::ON); setStateSet(stateset); setUseVertexArray(false); setUseShaders(false); }
/*! Constructor */ xDefaultSelectionDecorator::xDefaultSelectionDecorator() : xSelectionDecorator() { // create highlighting state m_pStateSet = new osg::StateSet; m_polygonOffset = new osg::PolygonOffset; m_polygonOffset->setFactor(-1.0f); m_polygonOffset->setUnits(-1.0f); m_polygonMode = new osg::PolygonMode; m_polygonMode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE); m_pStateSet->setAttributeAndModes(m_polygonOffset.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); m_pStateSet->setAttributeAndModes(m_polygonMode.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); m_lineWidth = new osg::LineWidth; m_lineWidth->setWidth(4.0f); m_pStateSet->setAttributeAndModes(m_lineWidth.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); m_material = new osg::Material; m_material->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0, 0.0, 0.0, 1.0)); m_material->setColorMode(osg::Material::DIFFUSE); m_pStateSet->setAttributeAndModes(m_material.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); m_pStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF); m_pStateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF); setStateSet(m_pStateSet.get()); setEnable(true); }
Cuboid::Cuboid(const osg::Vec3 &from, const osg::Vec3 &size) : _from(from), _size(size) { _drawable = new osg::Geometry(); osg::Vec3Array *pyramidVertices = new osg::Vec3Array(); { pyramidVertices->push_back( from + osg::Vec3(0, 0, size.z())); pyramidVertices->push_back( from + osg::Vec3(size.x(), 0, size.z())); pyramidVertices->push_back( from + osg::Vec3(size.x(), 0, 0)); pyramidVertices->push_back( from ); pyramidVertices->push_back( from + osg::Vec3(0, size.y(), size.z())); pyramidVertices->push_back( from + osg::Vec3(size.x(), size.y(), size.z())); pyramidVertices->push_back( from + osg::Vec3(size.x(), size.y(), 0)); pyramidVertices->push_back( from + osg::Vec3(0, size.y(), 0) ); } _drawable->setVertexArray( pyramidVertices ); // front { osg::DrawElementsUInt *face = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); face->push_back(0); face->push_back(1); face->push_back(2); face->push_back(3); _drawable->addPrimitiveSet(face); } // back { osg::DrawElementsUInt *face = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); face->push_back(4); face->push_back(5); face->push_back(6); face->push_back(7); _drawable->addPrimitiveSet(face); } // left { osg::DrawElementsUInt *face = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); face->push_back(0); face->push_back(4); face->push_back(7); face->push_back(3); _drawable->addPrimitiveSet(face); } // right { osg::DrawElementsUInt *face = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); face->push_back(1); face->push_back(5); face->push_back(6); face->push_back(2); _drawable->addPrimitiveSet(face); } // bottom { osg::DrawElementsUInt *face = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); face->push_back(3); face->push_back(2); face->push_back(6); face->push_back(7); _drawable->addPrimitiveSet(face); } osg::Vec4Array* colors = new osg::Vec4Array; { colors->push_back(osg::Vec4(0.0f, 1.0f, 1.0f, 0.8f)); colors->push_back(osg::Vec4(0.0f, 1.0f, 1.0f, 0.8f)); colors->push_back(osg::Vec4(1.0f, 1.0f, 0.0f, 0.8f)); colors->push_back(osg::Vec4(1.0f, 1.0f, 0.0f, 0.8f)); colors->push_back(osg::Vec4(1.0f, 0.0f, 1.0f, 0.8f)); colors->push_back(osg::Vec4(1.0f, 0.0f, 1.0f, 0.8f)); colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 0.8f)); colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 0.8f)); _drawable->setColorArray(colors); _drawable->setColorBinding(osg::Geometry::BIND_PER_VERTEX); } addDrawable(_drawable); osg::StateSet* stateSet = new osg::StateSet(); stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON); stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); setStateSet(stateSet); }
GraphModelEdge::GraphModelEdge(std::string _src, std::string _dst, std::string _label, std::map<std::string, SymbolNode *> *_nodeMapId) : osg::Group() { src = _src; dst = _dst; label = _label; geode = new osg::Geode; addChild(geode); nodeMapId = _nodeMapId; SymbolNode *s1 = (*nodeMapId)[src]; osg::Vec3 p1 = s1->pos; SymbolNode *s2 = (*nodeMapId)[dst]; osg::Vec3 p2 = s2->pos; osg::StateSet* stateset = new osg::StateSet(); stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON); setStateSet(stateset); osg::Vec3 pInc = p2-p1; osg::Vec3 pIncNorm = pInc; pIncNorm.normalize(); p1 = p1 + pIncNorm*RADIUS; p2 = p2 - pIncNorm*RADIUS; pInc = p2 - p1; float length = pInc.length(); osg::Vec3 ii = p2-p1; ii.normalize(); osg::Quat quat = quaternionFromInitFinalVector(osg::Vec3(0, 0, 1), ii); if (length <= 0.000001) { printf("hiuhwhuhhuwfqw\n"); exit(1); } float effectiveLength = length-TIPSIZE; osg::Vec3 position(((p1+p2)/2.f)-(pIncNorm*TIPSIZE)); line = new osg::Cylinder(position, RADIUS*0.2, effectiveLength); line->setRotation(quat); lineDrawable = new osg::ShapeDrawable(line); lineDrawable->setColor(osg::Vec4(0.7, 0.7, 0.7, 1)); geode->addDrawable(lineDrawable); tip = new osg::Cone(p2-pIncNorm*(TIPSIZE+4), 2.*RADIUS/3., 3 *TIPSIZE); tip->setRotation(quat); tipDrawable = new osg::ShapeDrawable(tip); lineDrawable->setColor(osg::Vec4(0.7, 0.7, 0.7, 1)); geode->addDrawable(tipDrawable); billboard = new osg::Billboard(); addChild(billboard); billboard->setMode(osg::Billboard::POINT_ROT_EYE); osg::Vec3 cursor = osg::Vec3(0, -RADIUS, 0.52*RADIUS); labelText = new osgText::Text; osgText::Font *font = osgText::readFontFile("fonts/arial.ttf"); osg::Vec4 fontSizeColor(0.2f, 0.0f, 0.0f, 100.0f); labelText->setFont(font); labelText->setCharacterSize(120); labelText->setAxisAlignment(osgText::TextBase::XZ_PLANE); labelText->setPosition(cursor); labelText->setColor(fontSizeColor); labelText->setAlignment(osgText::Text::CENTER_CENTER); labelText->setFontResolution(1000, 1000); labelText->setText(label); billboard->addDrawable(labelText); }
void osgParticle::ParticleSystem::setDefaultAttributesUsingShaders(const std::string& texturefile, bool emissive_particles, int texture_unit) { osg::StateSet *stateset = new osg::StateSet; stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); osg::PointSprite *sprite = new osg::PointSprite; stateset->setTextureAttributeAndModes(texture_unit, sprite, osg::StateAttribute::ON); #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) stateset->setMode(GL_VERTEX_PROGRAM_POINT_SIZE, osg::StateAttribute::ON); #else OSG_NOTICE<<"Warning: ParticleSystem::setDefaultAttributesUsingShaders(..) not fully implemented."<<std::endl; #endif if (!texturefile.empty()) { osg::Texture2D *texture = new osg::Texture2D; texture->setImage(osgDB::readRefImageFile(texturefile)); texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR); texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR); stateset->setTextureAttributeAndModes(texture_unit, texture, osg::StateAttribute::ON); } osg::BlendFunc *blend = new osg::BlendFunc; if (emissive_particles) { blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE); } else { blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); } stateset->setAttributeAndModes(blend, osg::StateAttribute::ON); osg::Program *program = new osg::Program; #ifdef USE_LOCAL_SHADERS char vertexShaderSource[] = "uniform float visibilityDistance;\n" "varying vec3 basic_prop;\n" "\n" "void main(void)\n" "{\n" " basic_prop = gl_MultiTexCoord0.xyz;\n" " \n" " vec4 ecPos = gl_ModelViewMatrix * gl_Vertex;\n" " float ecDepth = -ecPos.z;\n" " \n" " if (visibilityDistance > 0.0)\n" " {\n" " if (ecDepth <= 0.0 || ecDepth >= visibilityDistance)\n" " basic_prop.x = -1.0;\n" " }\n" " \n" " gl_Position = ftransform();\n" " gl_ClipVertex = ecPos;\n" " \n" " vec4 color = gl_Color;\n" " color.a *= basic_prop.z;\n" " gl_FrontColor = color;\n" " gl_BackColor = gl_FrontColor;\n" "}\n"; char fragmentShaderSource[] = "uniform sampler2D baseTexture;\n" "varying vec3 basic_prop;\n" "\n" "void main(void)\n" "{\n" " if (basic_prop.x < 0.0) discard;\n" " gl_FragColor = gl_Color * texture2D(baseTexture, gl_TexCoord[0].xy);\n" "}\n"; program->addShader(new osg::Shader(osg::Shader::VERTEX, vertexShaderSource)); program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource)); #else program->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX, osgDB::findDataFile("shaders/particle.vert"))); program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, osgDB::findDataFile("shaders/particle.frag"))); #endif stateset->setAttributeAndModes(program, osg::StateAttribute::ON); stateset->addUniform(new osg::Uniform("visibilityDistance", (float)_visibilityDistance)); stateset->addUniform(new osg::Uniform("baseTexture", texture_unit)); setStateSet(stateset); setUseVertexArray(true); setUseShaders(true); }