Ejemplo n.º 1
0
/***************************************************************
* Function: applyColorTexture()
***************************************************************/
void CAVEGeode::applyColorTexture(const Vec3 &diffuse, const Vec3 &specular, const float &alpha, const string &texFilename)
{
    StateSet *stateset = getOrCreateStateSet();

    /* update material parameters */
    Material *material = dynamic_cast <Material*> (stateset->getAttribute(StateAttribute::MATERIAL)); 
    if (!material) 
        material = new Material;
    material->setDiffuse(Material::FRONT_AND_BACK, Vec4(diffuse, 1.f));
    material->setSpecular(Material::FRONT_AND_BACK, Vec4(specular, 1.f));
    material->setAlpha(Material::FRONT_AND_BACK, alpha);
    stateset->setAttributeAndModes(material, StateAttribute::ON);

    /* update texture image */
    Texture2D *texture = dynamic_cast <Texture2D*> (stateset->getAttribute(StateAttribute::TEXTURE));
    if (!texture) 
        texture = new Texture2D;
    Image* texImage = osgDB::readImageFile(texFilename);
    texture->setImage(texImage); 
    texture->setWrap(Texture::WRAP_S,Texture::REPEAT);
    texture->setWrap(Texture::WRAP_T,Texture::REPEAT);
    texture->setDataVariance(Object::DYNAMIC);
    stateset->setTextureAttributeAndModes(0, texture, StateAttribute::ON);
    stateset->setMode(GL_BLEND, StateAttribute::OVERRIDE | osg::StateAttribute::ON );
    stateset->setRenderingHint(StateSet::TRANSPARENT_BIN);

    /* update of color & texture properties */
    mDiffuse = diffuse;
    mSpecular = specular;
    mAlpha = alpha;
    mTexFilename = texFilename;
}
void Object3D::setObjectTextureState(Image *image, bool flipVertically)
{
    // retrieve or create a StateSet
    StateSet* stateTexture = _originalNode->getOrCreateStateSet();
    if(stateTexture && image)
    {
        // create a new two-dimensional texture object
        Texture2D *texCube = new Texture2D;
        texCube->setDataVariance(Object::DYNAMIC);
        // set the texture to the loaded image
        texCube->setImage(image);
        texCube->setResizeNonPowerOfTwoHint(false);
        texCube->setWrap(Texture2D::WRAP_S, Texture2D::REPEAT);
        texCube->setWrap(Texture2D::WRAP_T, Texture2D::REPEAT);

        // set the texture to the state
        stateTexture->setTextureAttributeAndModes(0, texCube, StateAttribute::ON|StateAttribute::OVERRIDE);

        if(flipVertically)
        {
            // apply a vertical (Y component) flip on the texture coordinates
            TexMat *texMat = dynamic_cast<TexMat*>(stateTexture->getAttribute(StateAttribute::TEXMAT,0));
            if(!texMat)
                texMat = new TexMat;
            Matrix M = Matrix::scale(1, -1, 1);
            texMat->setMatrix(M);
            stateTexture->setTextureAttributeAndModes(0, texMat, StateAttribute::ON|StateAttribute::OVERRIDE);
        }
    }
}
Ejemplo n.º 3
0
/***************************************************************
* Function: applyAlpha()
***************************************************************/
void CAVEGeode::applyAlpha(const float &alpha)
{
    StateSet *stateset = getOrCreateStateSet();

    /* update material parameters */
    Material *material = dynamic_cast <Material*> (stateset->getAttribute(StateAttribute::MATERIAL)); 
    if (!material) material = new Material;
    material->setAlpha(Material::FRONT_AND_BACK, alpha);
    stateset->setAttributeAndModes(material, StateAttribute::ON);

    /* update alpha value */
    mAlpha = alpha;
}
/***************************************************************
* Function: setVSParamountPreviewHighlight()
***************************************************************/
void VirtualScenicHandler::setVSParamountPreviewHighlight(bool flag, Geode *paintGeode)
{
    StateSet *stateset = paintGeode->getOrCreateStateSet();
    Material *material = dynamic_cast<Material*> (stateset->getAttribute(StateAttribute::MATERIAL)); 
    if (!material) 
        material = new Material;
    if (flag)
    {
        material->setAlpha(Material::FRONT_AND_BACK, 0.5f);
        material->setDiffuse(Material::FRONT_AND_BACK, Vec4(0.3, 1.0, 0.3, 1.0));
        material->setSpecular(Material::FRONT_AND_BACK, Vec4(0.3, 1.0, 0.3, 1.0));
    }
    else
    {
        material->setAlpha(Material::FRONT_AND_BACK, 1.0f);
        material->setDiffuse(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1));
        material->setSpecular(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1));
    }
    stateset->setAttributeAndModes(material, StateAttribute::OVERRIDE | StateAttribute::ON);
}
/***************************************************************
* Function: switchFloorplan()
***************************************************************/
void VirtualScenicHandler::switchFloorplan(const int &idx, const VisibilityOption &option)
{
    if (idx >= mFloorplanSwitch->getNumChildren()) 
    {
        return;
    }

    if (option == INVISIBLE)
    {
        if (mFloorplanIdx >= 0) 
        {
            mFloorplanSwitch->setSingleChildOn(mFloorplanIdx);
        }
        else 
        {
            mFloorplanSwitch->setAllChildrenOff();
        }
    }
    else 
    {
        Geode *floorplanGeode = dynamic_cast <Geode*> (mFloorplanSwitch->getChild(idx));
        StateSet *stateset = floorplanGeode->getOrCreateStateSet();
        Material *material = dynamic_cast<Material*> (stateset->getAttribute(StateAttribute::MATERIAL)); 

        if (!material) 
        {
            material = new Material;
        }

        if (option == TRANSPARENT)
        {
            material->setAlpha(Material::FRONT_AND_BACK, 0.5f);
        }
        else if (option == SOLID)
        {
            material->setAlpha(Material::FRONT_AND_BACK, 1.0f);
            mFloorplanIdx = idx;
        }
        mFloorplanSwitch->setSingleChildOn(idx);
    }
}
void DisplayRequirementsVisitor::applyStateSet(StateSet& stateset)
{
    if (!_ds) _ds = new osg::DisplaySettings;

   unsigned int min = 0; // assume stencil not needed by this stateset.
   
   if (stateset.getMode(GL_STENCIL_TEST) & StateAttribute::ON)
   {
        min = 1; // number stencil bits we need at least.
   }

   if (stateset.getAttribute(StateAttribute::STENCIL))
   {
        min = 1; // number stencil bits we need at least.
   }
   
   if (min>_ds->getMinimumNumStencilBits())
   {
        // only update if new minimum exceeds previous minimum.
        _ds->setMinimumNumStencilBits(min);
   }    
}
Ejemplo n.º 7
0
   virtual void apply( StateSet &ss )
   {
      inherited::apply( ss );

      // Textures
      int c = ss.getNumTextureAttributeLists();
      for( int i=0; i<c; i++ )
      {
         Texture *t = dynamic_cast< Texture* >( ss.getTextureAttribute( i, StateAttribute::TEXTURE ) );
         if( t )
         {
            ++_numInstancedTextures;
            _textureSet.insert( t );
         }
      }

      // shader programs
      Program *p = dynamic_cast< Program* >( ss.getAttribute( StateAttribute::PROGRAM ) );
      if( p )
      {
         ++_numInstancedShaderPrograms;
         _shaderProgramSet.insert( p );
      }
   }