Beispiel #1
0
void TexturePlaneNode::traverse( osg::NodeVisitor& nv )
{
    if ( nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR )
    {
	if ( needsUpdate() )
	    updateGeometry();
    }
    else if ( nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR )
    {
	osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);

	if ( getStateSet() )
	    cv->pushStateSet( getStateSet() );

	if ( _texture && _texture->getSetupStateSet() )
	    cv->pushStateSet( _texture->getSetupStateSet() );

	for ( unsigned int idx=0; idx<_geometries.size(); idx++ )
	{
	    cv->pushStateSet( _statesets[idx] );
	    cv->addDrawable( _geometries[idx], cv->getModelViewMatrix() );
	    cv->popStateSet();
	}

	if ( _texture && _texture->getSetupStateSet() )
	    cv->popStateSet();

	if ( getStateSet() )
	    cv->popStateSet();
    }
}
Beispiel #2
0
void ShapeNode::setStateSetFromFile(const char* filename)
{
	osg::ref_ptr<ReferencedStateSet> ss = sceneManager->createStateSet(filename);
	if (ss.valid())
	{
		if (ss->id == stateset) return; // we're already using that stateset
		stateset = ss->id;
		updateStateSet();
		BROADCAST(this, "ss", "setStateSet", getStateSet());
	}
}
Beispiel #3
0
CSulShadow::CSulShadow( osg::Group* pSceneRoot ) :
osg::TexGenNode(),
m_posLight( 100.0f, 100.0f, 100.0f ),
m_fileShaderFrag(""),
m_fileShaderVert(""),
m_size_squared( 1024 )
{
//	setStateSet( osg::StateAttribute::ON | osg::StateAttribute::PROTECTED );
	getStateSet()->setAttribute( 
		getStateSet()->getAttribute( osg::StateAttribute::TEXGEN ),
		osg::StateAttribute::ON | osg::StateAttribute::PROTECTED );
	
	

	m_rSceneRoot = pSceneRoot;

	m_rCasters = new osg::Group;

	setTextureUnit( 3 );
}
Beispiel #4
0
void ShapeNode::setStateSet (const char* s)
{
	if (gensym(s)==stateset) return;

	osg::ref_ptr<ReferencedStateSet> ss = sceneManager->getStateSet(s);
	if (ss.valid())
	{
		stateset = ss->id;
		updateStateSet();
		BROADCAST(this, "ss", "setStateSet", getStateSet());
	}
}
Beispiel #5
0
void PlaneWellLog::buildLineGeometry()
{
    _lineGeometry = new osg::Geometry();
    _geode->addDrawable(_lineGeometry);
    _lineGeometry->setVertexArray(_logLinedPoints.get());
    _lineGeometry->setColorArray(_lineColor.get());
    _lineGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back( osg::Vec3 (0.0f,-1.0f,0.0f ));
    _lineGeometry->setNormalArray(normals.get());
    _lineGeometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
    _linePrimitiveSet = new osg::DrawArrays(
	osg::PrimitiveSet::LINE_STRIP, 0, 0);
    _lineGeometry->addPrimitiveSet(_linePrimitiveSet);

    osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
    polyoffset->setFactor(1.0f);
    polyoffset->setUnits(1.0f);
    getOrCreateStateSet()->setAttributeAndModes(_lineWidth);
    getStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
    getStateSet()->setAttributeAndModes( 
	polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
}
Beispiel #6
0
std::vector<lo_message> ShapeNode::getState () const
{
	// inherit state from base class
	std::vector<lo_message> ret = GroupNode::getState();

	lo_message msg;
	osg::Vec3 v;
	osg::Vec4 v4;

	//std::cout << "in getState. shape=" << shape << ", textureName=" << textureName << std::endl;

	msg = lo_message_new();
	lo_message_add(msg, "si", "setBillboard", getBillboard());
	ret.push_back(msg);
	
	msg = lo_message_new();
	v4 = this->getColor();
	lo_message_add(msg, "sffff", "setColor", v4.x(), v4.y(), v4.z(), v4.w());
	ret.push_back(msg);

	msg = lo_message_new();
	lo_message_add(msg,  "ss", "setTextureFromFile", texturePath.c_str());
	ret.push_back(msg);

	msg = lo_message_new();
	lo_message_add(msg,  "ss", "setStateSet", getStateSet());
	ret.push_back(msg);

	msg = lo_message_new();
	lo_message_add(msg, "si", "setRenderBin", getRenderBin());
	ret.push_back(msg);

	msg = lo_message_new();
	lo_message_add(msg, "si", "setLighting", getLighting());
	ret.push_back(msg);

	// put this one last:	
	msg = lo_message_new();
	lo_message_add(msg, "si", "setShape", getShape());
	ret.push_back(msg);

	return ret;
}
Beispiel #7
0
void PlaneWellLog::traverse(osg::NodeVisitor& nv)
{
    WellLog::traverse( nv );

    if( !_logPath->size() )
	return;

    if ( nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR )
    {
	if ( _forceReBuild )
	{
	    calcFactors();
	    _colorTableChanged = true;
	    _forceCoordReCalculation = true;
	}

	if ( _colorTableChanged )
	    updateFilledLogColor();
    }
    else if ( nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR )
    {
	osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
	const osg::Vec3 projdir = getPrjDirection(cv);
	const osg::Vec3 normal = calcNormal(projdir);
	
	if ( _forceCoordReCalculation || eyeChanged(projdir) || 
	    _logWidthChanged )
	{
	    calcCoordinates(normal); 
	    _preProjDir = projdir;
	    _logWidthChanged = false;

	    if ( _lineWidth->getWidth() == 0 )
		getStateSet()->removeAttribute(_lineWidth);
	    else
		getStateSet()->setAttributeAndModes(_lineWidth);
	    
	    dirtyBound();
	}

	osg::ref_ptr<osg::MatrixTransform> tr = new osg::MatrixTransform;
	osg::ref_ptr<osg::RefMatrix> modelViewMatrix = 
	    const_cast<osgUtil::CullVisitor*>(cv)->getModelViewMatrix();
	
	if ( getStateSet() ) cv->pushStateSet( getStateSet() );

	osg::Matrix repeatTransform;
	osg::BoundingBox bbox;
	for ( int idx=0; idx<(int)_repeatNumber; idx++ )
	{
	    repeatTransform.setTrans( normal*idx*getRepeatStep() );
	    osg::Matrix RMV = repeatTransform * (*modelViewMatrix);
	    osg::ref_ptr<osg::RefMatrix> rfMx = new osg::RefMatrix(RMV);

	    const osg::BoundingBox bbtri = _triangleGeometry->getBound() ;
	    const osg::BoundingBox bbline = _lineGeometry->getBound();
	    bbox.expandBy( bbtri );
	    bbox.expandBy( bbline );

	    if ( bbox.radius() == 0 )
		return;

	    const float depth = cv->getDistanceFromEyePoint(bbox.center(),false);
	    cv->addDrawableAndDepth( _lineGeometry, rfMx, depth );
	    cv->addDrawableAndDepth( _triangleGeometry, rfMx, depth );
	}

	if ( _bbox._min != bbox._min || _bbox._max != bbox._max )
	{
	    dirtyBound();
	    _bbox = bbox;
	}

	if ( getStateSet() ) cv->popStateSet();
    }
    else
    {
	osgUtil::IntersectionVisitor* iv =
			dynamic_cast<osgUtil::IntersectionVisitor*>(&nv);

	if ( iv && iv->getModelMatrix() )
	{
	    const osg::Vec3 normal = calcNormal( _preProjDir );

	    osg::Matrix repeatTransform;
	    for ( int idx=0; idx<(int)_repeatNumber; idx++ )
	    {
		repeatTransform.setTrans(normal*idx*getRepeatStep());

		osg::Matrix mat = repeatTransform * (*iv->getModelMatrix());
		osg::ref_ptr<osg::RefMatrix> rfMx = new osg::RefMatrix(mat);

		iv->pushModelMatrix( rfMx );

		osg::ref_ptr<osgUtil::Intersector> intersec = 
		    iv->getIntersector()->clone(*iv);
		if ( intersec.valid() )
		{
		    intersec->intersect(*iv, _lineGeometry);
		    intersec->intersect(*iv, _triangleGeometry);
		}

		iv->popModelMatrix();
	    }
	}

	osgGeo::ComputeBoundsVisitor* cbv =
	    dynamic_cast<osgGeo::ComputeBoundsVisitor*>(&nv);
	if ( cbv )
	    cbv->applyBoundingBox(_bbox);
    }

}