Example #1
0
void PhongMaterial::prepareLocalChunks(void)
{
    if(_materialChunk != NullFC)
        return;

    _materialChunk = MaterialChunk::create();
    addRefCP(_materialChunk);

    _blendChunk = BlendChunk::create();
    addRefCP(_blendChunk);
    beginEditCP(_blendChunk);
    _blendChunk->setSrcFactor (GL_SRC_ALPHA);
    _blendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
    endEditCP  (_blendChunk);

    // phong shading without a fragment shader looks quite black ;-)
    // all cards with a fragment shader should also have a vertex shader.
    // calling hasCommonExtension() here is not a good idea as this works
    // only for a initialized window, I added a check to hasCommonExtension()
    // so this won't crash anymore.
    if(Window::hasCommonExtension(_arbFragmentProgram))
    {
        _vpChunk = VertexProgramChunk::create();
        addRefCP(_vpChunk);
        beginEditCP(_vpChunk);
        _vpChunk->setProgram(_phong_vp_prg);
        endEditCP(_vpChunk);

        _fpChunk = FragmentProgramChunk::create();
        addRefCP(_fpChunk);
        createFragmentProgram();
    }
}
void SceneBasicEditor::createInterface(ApplicationBuilderPtr TheApplicationBuilder)
{
	//Scene Name Label
    _SceneNameLabel = osg::Label::create();
	beginEditCP(_SceneNameLabel, Label::TextFieldMask);
		_SceneNameLabel->setText("Scene Name:");
	endEditCP(_SceneNameLabel, Label::TextFieldMask);

	//Scene Name Text Field
    _SceneNameTextField = osg::TextField::create();
	beginEditCP(_SceneNameTextField, TextField::TextFieldMask);
		_SceneNameTextField->setText("NOT NAMED");
	endEditCP(_SceneNameTextField, TextField::TextFieldMask);

	//Layout
	FlowLayoutPtr SceneBasicEditorLayout = FlowLayout::create();
	

	//Basic Scene Editor
	beginEditCP(SceneBasicEditorPtr(this), SceneBasicEditor::ChildrenFieldMask | SceneBasicEditor::LayoutFieldMask);
		getChildren().clear();
		getChildren().push_back(_SceneNameLabel);
		getChildren().push_back(_SceneNameTextField);
		setLayout(SceneBasicEditorLayout);
	endEditCP(SceneBasicEditorPtr(this), SceneBasicEditor::ChildrenFieldMask | SceneBasicEditor::LayoutFieldMask);
}
Example #3
0
void Particles::setScale(gmtl::Vec3f scale)
{
	float maxScale;
	Vec3f position, osgScale;
	Quaternion orientation, scaleOrientation;

	beginEditCP(particleTrans);
		Matrix mOrig = particleTrans->getMatrix();
	endEditCP(particleTrans);

	Matrix mNew = mOrig;
	mNew.getTransform(position, orientation, osgScale, scaleOrientation);
	osgScale = Vec3f(scale[0], scale[1], scale[2]);
	mNew.setTransform(position, orientation, osgScale, scaleOrientation);
	beginEditCP(particleTrans, Transform::MatrixFieldMask);
		particleTrans->setMatrix(mNew);
	endEditCP(particleTrans, Transform::MatrixFieldMask);
	
	mOrig.invert();
//	mNew.multLeft(mOrig);
	mNew.mult(mOrig);
	beginEditCP(particleTransNode);
		DynamicVolume &v = particleTransNode->getVolume(false);
		v.transform(mNew);
	endEditCP(particleTransNode);

} // setScale
Example #4
0
OSG_USING_NAMESPACE

Particles::Particles(std::string fileName, bool makeClone)
{
	int i;

	particleSystemInfo.pConfigFile = new char[512];
  	sprintf( (char *)particleSystemInfo.pConfigFile, "%s/effect.xml", fileName.c_str());
	particleSystemInfo.rUpdatesPerSecond = 30;
	particleSystemInfo.iRandomSeed = time( NULL );
	particleSystemInfo.rSynchronisationInterval = 1.0f;
	particleSystemInfo.iForwardThreshold = 50;
	pParticles = pCreateParticleSystem( particleSystemInfo );
//	delete particleSystemInfo.pConfigFile;

	particleNode = Node::create();
	particleModelNode = pParticles != 0 ? pParticles->pGetNodePtr() : Node::create();
// 	particleNode = pParticles != 0 ? pParticles->pGetNodePtr() : Node::create();

	Vec3f boundingBoxSize = pParticles->GetSize();
	
	particleTransNode = Node::create();
	particleTrans = Transform::create();

	particleModelTrans = Transform::create();
	
	Matrix m;
	m.setIdentity();
	beginEditCP(particleTrans, Transform::MatrixFieldMask);
		particleTrans->setMatrix(m);
	endEditCP(particleTrans, Transform::MatrixFieldMask);

	beginEditCP(particleModelTrans, Transform::MatrixFieldMask);
		particleModelTrans->setMatrix(m);
	endEditCP(particleModelTrans, Transform::MatrixFieldMask);

	beginEditCP(particleNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
		particleNode->setCore(particleModelTrans);
		particleNode->addChild(particleModelNode);
	endEditCP(particleNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
	
	beginEditCP(particleTransNode);
		particleTransNode->setCore(particleTrans);
		if (makeClone)
			particleTransNode->addChild(cloneTree(particleNode));
		else
			particleTransNode->addChild(particleNode);

		// set volume static to prevent constant update
		Volume &v = particleTransNode->getVolume( false ).getInstance();
		v.setEmpty();
		v.extendBy( Pnt3f( -boundingBoxSize[0], -boundingBoxSize[1], -boundingBoxSize[2] ) );
		v.extendBy( Pnt3f( boundingBoxSize[0], boundingBoxSize[1], boundingBoxSize[2] ) );
		v.setStatic();
		((DynamicVolume&)particleTransNode->getVolume()).instanceChanged();

	endEditCP(particleTransNode);

	cloned = false;
} // Particles
Example #5
0
void PCSSShadowMap::initTextures(Window *win)
{
    _initTexturesDone = true;

    Int32   width = _shadowVP->getPixelWidth();
    Int32   height = _shadowVP->getPixelHeight();

    //if no NPOTTextures supported, resize images
    if(!_useNPOTTextures)
    {
        if(width > height)
            _widthHeightPOT = osgnextpower2(width - 1);
        else
            _widthHeightPOT = osgnextpower2(height - 1);

        beginEditCP(_colorMap);
        beginEditCP(_colorMapImage);
        _colorMapImage->set(COLORMAP_FORMAT, _widthHeightPOT, _widthHeightPOT);
        endEditCP(_colorMapImage);
        endEditCP(_colorMap);

        beginEditCP(_shadowFactorMap);
        beginEditCP(_shadowFactorMapImage);
        _shadowFactorMapImage->set(GL_RGB, _widthHeightPOT, _widthHeightPOT);
        endEditCP(_shadowFactorMapImage);
        endEditCP(_shadowFactorMap);
    }
}
// Create a volume rendering node with all desired attachments
NodePtr makeVolume(ImagePtr datImage)
{  
    vol         = DVRVolume::create();
    DVRAppearancePtr     app         = DVRAppearance::create(); 
    DVRVolumeTexturePtr  tex         = DVRVolumeTexture::create();

    beginEditCP(tex);
    tex->setImage(datImage);
    endEditCP(tex);

    // Attach the volume texture to the appearance
    beginEditCP(app, Node::AttachmentsFieldMask);
    app->addAttachment(tex);
    endEditCP  (app, Node::AttachmentsFieldMask);

    // Assign the appearance to the volume core
    beginEditCP(vol);
    vol->setAppearance(app);
    vol->setShader(DVRSimpleShader::create());
    endEditCP(vol);

    // Create a node for the volume core
    NodePtr newGeom = Node::create();
    beginEditCP(newGeom);
    newGeom->setCore(vol);
    endEditCP(newGeom);
    
    return newGeom;
}
static NodePtr makePerturbedUniform (UInt16 numSubdiv, 
				     Real32 radius,
				     Real32 rate = 0.1f)
{
   static Real32 factor = 1.1f;

   NodePtr         sphereNode = makeSphere(numSubdiv, radius);
   GeometryPtr     sphere = GeometryPtr::dcast(sphereNode->getCore());
   GeoPositionsPtr points = sphere->getPositions();
   beginEditCP(points);
   for (UInt32 i=0; i<points->size(); ++i) {
      Real32 random = (rand()/Real32(RAND_MAX));
      if (random <= rate) {
	 points->setValue(factor*points->getValue(i), i);
      }
   }
   endEditCP(points);

   NodePtr node = Node::create();
   beginEditCP(node);
   node->setCore(Transform::create());
   node->addChild(sphereNode);
   endEditCP(node);

   return node;
}
// redraw the window
void display(void)
{
   Profiler::the().StartProfile("Frame");
   unsigned i;
   for (i=0; i<numFirst; ++i) {
     TransformPtr trf = TransformPtr::dcast(first->getChild(i)->getCore());
     beginEditCP(trf);
     trf->getMatrix()[3] += Vec4f((rand()/Real32(RAND_MAX)-0.5f),
				  (rand()/Real32(RAND_MAX)-0.5f),
				  (rand()/Real32(RAND_MAX)-0.5f), 0.0f);
     endEditCP(trf);
   }
   for (i=0; i<numSecond; ++i) {
     TransformPtr trf = TransformPtr::dcast(second->getChild(i)->getCore());
     beginEditCP(trf);
     trf->getMatrix()[3] += Vec4f((rand()/Real32(RAND_MAX)-0.5f),
				  (rand()/Real32(RAND_MAX)-0.5f),
				  (rand()/Real32(RAND_MAX)-0.5f), 0.0f);
     endEditCP(trf);
   }

   bool result = all->apply(first, second);

   OSGRAPIDCollision& col = (OSGRAPIDCollision&)all->getData();     
   SLOG << col.getNumContacts() << " contacts with " 
	<< col.getNumBVolTests() << " BVolTests/"
	<< col.getNumMixedTests() << " MixedTests/"
	<< col.getNumPrimTests() << " TriTests  " 
	<< std::endl;
   
   Profiler::the().EndProfile("Frame");
   mgr->redraw();
}
NodePtr makeTransformedCube (Real32 xsize,
			     Real32 ysize,
			     Real32 zsize,
			     UInt16 hor,
			     UInt16 vert,
			     UInt16 depth,
			     const Color3f& c)
{
   GeoColors3fPtr color = GeoColors3f::create();
   beginEditCP(color);
   color->addValue(c);
   endEditCP(color);
   GeometryPtr box = makeBoxGeo(xsize, ysize, zsize, hor, vert, depth);
   beginEditCP(box);
   box->setColors(color);
   endEditCP(box);
   NodePtr boxNode = Node::create();
   beginEditCP(boxNode);
   boxNode->setCore(box);
   endEditCP(boxNode);
   NodePtr node = Node::create();
   beginEditCP(node);
   node->setCore(Transform::create());
   node->addChild(boxNode);
   endEditCP(node);
   return node;
}
Example #10
0
// react to keys
void keyboard(unsigned char k, int, int)
{
    switch(k)
    {
    case 27:    exit(1);
    case 'a':   zpp /= 1.1;
                break;
    case 's':   zpp *= 1.1;
                break;
    case 'z':   ed /= 1.1;
                break;
    case 'x':   ed *= 1.1;
                break;         
    }
    
    std::cout << "ZPP:" << zpp << " ED:" << ed << std::endl;
    
    beginEditCP(decoleft);
    decoleft->setEyeSeparation(ed);
    decoleft->setZeroParallaxDistance(zpp);
    endEditCP  (decoleft);
    
    beginEditCP(decoright);
    decoright->setEyeSeparation(ed);
    decoright->setZeroParallaxDistance(zpp);
    endEditCP  (decoright);
}
Example #11
0
void VRMLSwitchBinder::init(VRMLToOSGAction *)
{
    if(_pNode == NULL)
        return;

    VRMLSwitch *pNode = dynamic_cast<VRMLSwitch *>(_pNode);

    if(pNode == NULL)
        return;

    NodePtr   pSwNode = Node  ::create();
    SwitchPtr pSwitch = Switch::create();

    beginEditCP(pSwitch, Switch::ChoiceFieldMask);
    {
        pSwitch->setChoice(pNode->getSFWhichChoice()->getValue());
    }
    endEditCP  (pSwitch, Switch::ChoiceFieldMask);

    beginEditCP(pSwNode, Node::CoreFieldMask);
    {
        pSwNode->setCore(pSwitch);
    }
    endEditCP  (pSwNode, Node::CoreFieldMask);

    _pFieldContainer = pSwNode;
}
DialogPtr DialogHierarchy::addDialog(std::string response, Real32 delayResponses, SoundPtr dialogSound, bool interactive, DialogPtr parentDialog)
{
    DialogPtr d = osg::Dialog::create();
    beginEditCP(d, Dialog::ResponseFieldMask | Dialog::ResponsePresentationDelayFieldMask | Dialog::DialogSoundFieldMask | Dialog::InteractiveFieldMask | Dialog::ParentDialogHierarchyFieldMask);
        d->setResponse(response);
        d->setResponsePresentationDelay(delayResponses);
        d->setDialogSound(dialogSound);
        d->setInteractive(interactive);
        d->setParentDialogHierarchy(DialogHierarchyPtr(this));
    endEditCP(d, Dialog::ResponseFieldMask | Dialog::ResponsePresentationDelayFieldMask | Dialog::DialogSoundFieldMask | Dialog::InteractiveFieldMask | Dialog::ParentDialogHierarchyFieldMask);

    d->addDialogListener(&_DialogHierarchyListener);

    if(parentDialog != NullFC)
    {
        beginEditCP(parentDialog, Dialog::ResponsesFieldMask);
            parentDialog->getResponses().push_back(d);
        endEditCP(parentDialog, Dialog::ResponsesFieldMask);
    }

    if(getRootDialog() == NullFC)
    {
        setRootDialog(d);
    }
    return d;
}
typename FaceSpatialize<BasicTraits>::ResultT  
FaceSpatialize<BasicTraits>::InnerEnter (GroupType*)
{
  if (m_level <= m_depth) {
     if (m_flat) {
       if (m_level == 0) {
	  m_root = Node::create();
	  m_rootLevel = m_root;
	  beginEditCP(m_root);
	  m_root->setCore(getGroupCore());
       } else {
	  beginEditCP(m_root);
       }
       m_ifs = new Category(m_root);
     } else {
       NodePtr root = Node::create();
       if (m_level > 0) {
	 m_rootLevel->addChild(root);
       } else {
	 m_root = root;
       }
       m_rootLevel = root;
       beginEditCP(root);
       root->setCore(getGroupCore());
       m_ifs = new Category(root);
     }
     m_ifsStack.push_back(m_ifs);
  }
  ++m_level;
  return SingleTraverserBase<BasicTraits>::CONTINUE;
}
Example #14
0
void SceneEditor::changed(BitVector whichField, ::osg::UInt32 origin)
{
    Inherited::changed(whichField, origin);

	if(whichField & EditingSceneFieldMask)
	{
		for(::osg::UInt32 i(0) ; i<getEditors().size() ; ++i)
		{
			beginEditCP(getEditors(i), SceneComponentEditor::EditingSceneFieldMask);
				getEditors(i)->setEditingScene(getEditingScene());
			endEditCP(getEditors(i), SceneComponentEditor::EditingSceneFieldMask);
		}
		
		if(_SceneNameLabel != NullFC)
		{
			beginEditCP(_SceneNameLabel, Label::TextFieldMask);
			if(getEditingScene() != NullFC
               && getName(getEditingScene()))
			{
				_SceneNameLabel->setText(getName(getEditingScene()));
			}
			else
			{
				_SceneNameLabel->setText("");
			}
			endEditCP(_SceneNameLabel, Label::TextFieldMask);
		}
	}
}
	virtual void  setRoot          ( NodePtr root )
	{
		if(_internalRoot == NullFC)
		{
			initialize();
		}

		if(_root != root)
		{
			if(_root != NullFC)
			{
				beginEditCP(_internalRoot, Node::ChildrenFieldMask);
				_internalRoot->subChild(_root);
				endEditCP(_internalRoot, Node::ChildrenFieldMask);
			}

			_root = root;
			if(_root != NullFC)
			{
				beginEditCP(_internalRoot, Node::ChildrenFieldMask);
				_internalRoot->addChild(_root);
				endEditCP(_internalRoot, Node::ChildrenFieldMask);
			}
		}
	}
Example #16
0
void display(void)
{
    Real32 time = glutGet(GLUT_ELAPSED_TIME );
    
    //create the Quaternion the describes the rotation of
    //the planet around the sun
    Quaternion planetRot = Quaternion(Vec3f(0,1,0), time/float(1000));
    
    //now the rotation of the moon around the planet
    //the division by 12 speeds up the rotation by 12 compared to the
    //planet rotation
    Quaternion moonRot = Quaternion(Vec3f(0,1,0), time/float(1000/12));
    
    //generate the Matrices
    Matrix p,m;
    
    p.setIdentity();
    m.setIdentity();
    
    p.setRotate(planetRot);
    m.setRotate(moonRot);
    
    p.setTranslate(20,0,0);
    m.setTranslate(8,0,0);

    beginEditCP(planetTransform, Transform::MatrixFieldMask);
        planetTransform->setMatrix(p);
    endEditCP(planetTransform, Transform::MatrixFieldMask);
    
    beginEditCP(moonTransform, Transform::MatrixFieldMask);
        moonTransform->setMatrix(m);
    endEditCP(moonTransform, Transform::MatrixFieldMask);
    
    mgr->redraw();
}
Example #17
0
// redraw the window
void display( void )
{
    // create the matrix
    Matrix m;
    Real32 t = glutGet(GLUT_ELAPSED_TIME );
    
    m.setTransform(Quaternion( Vec3f(0,1,0), 
                               t / 1000.f));
    
    // set the transform's matrix
    beginEditCP(trans, Transform::MatrixFieldMask);
    {
        trans->setMatrix(m);
    }   
    endEditCP  (trans, Transform::MatrixFieldMask);
   
    /*
        Manipulate the geometry.
        
        The OpenSG geometry structure is pretty flexible.
        
        The disadvantage of all this flexibility is that it can be hard to
        write generic tools, as pretty much all the used types can be one of a
        number of variants.
        
        To simplify that, every kind of GeoProperty has a generic type, e.g.
        the generic type for positions is Pnt3f, for colors it's Color3f.
        
        No matter the internal data representation looks like, all
        GeoProperties have the generic interface. As does the abstract parent
        class of every kind of property. Thus it's possible to access the data
        of an arbitrary geometry using the generic interface.
    */
    
    // note that this is the abstract parent class, it doesn't have a specific
    // type
    GeoPositionsPtr pos = geo->getPositions();
    
    beginEditCP(pos);
    for(UInt32 i = 0; i < pos->getSize(); i++)
    {
        Pnt3f p;      
        pos->getValue(p, i);
        
        p[0] += osgsin(t / 300) * p[1] / 100;
        p[1] += osgsin(t / 300) * p[2] / 100;
        p[2] += osgsin(t / 300) * p[0] / 100;
        
        pos->setValue(p, i);
    }
    endEditCP  (pos);
    
    // right now the geometry doesn't notice changes to the properties, it has
    // to be notified explicitly
    beginEditCP(geo, Geometry::PositionsFieldMask);
    endEditCP  (geo, Geometry::PositionsFieldMask);
    
    mgr->redraw();
}
void SimpleTexturedMaterial::changed(BitVector whichField, UInt32 origin)
{
    prepareLocalChunks();

    // these two are very expensive, as they need to regenerate the
    // texture object, do only if really needed

    if(whichField & ImageFieldMask)
    {
        beginEditCP(_textureChunk, TextureChunk::ImageFieldMask);

        _textureChunk->setImage(getImage());

        endEditCP(_textureChunk, TextureChunk::ImageFieldMask);
    }
    if(whichField & MinFilterFieldMask || whichField & MagFilterFieldMask)
    {
        beginEditCP(_textureChunk, TextureChunk::MinFilterFieldMask |
                                   TextureChunk::MagFilterFieldMask);

        _textureChunk->setMinFilter(getMinFilter());
        _textureChunk->setMagFilter(getMagFilter());

        endEditCP(_textureChunk, TextureChunk::MinFilterFieldMask |
                                 TextureChunk::MagFilterFieldMask);
    }
    // this is not as expensive, but why do it more often then needed?
    if(whichField & EnvModeFieldMask)
    {
        beginEditCP(_textureChunk, TextureChunk::EnvModeFieldMask);

        _textureChunk->setEnvMode(getEnvMode());

        endEditCP(_textureChunk, TextureChunk::EnvModeFieldMask);
    }
    if(whichField & EnvMapFieldMask)
    {
        beginEditCP(_texGenChunk, TexGenChunk::GenFuncSFieldMask |
                                  TexGenChunk::GenFuncTFieldMask);
        
        if (getEnvMap())
        {
            _texGenChunk->setGenFuncS(GL_SPHERE_MAP);
            _texGenChunk->setGenFuncT(GL_SPHERE_MAP);
        }
        else
        {
            _texGenChunk->setGenFuncS(GL_NONE);
            _texGenChunk->setGenFuncT(GL_NONE);
        }

        endEditCP(_texGenChunk, TexGenChunk::GenFuncSFieldMask |
                                TexGenChunk::GenFuncTFieldMask);
    }

    Inherited::changed(whichField, origin);
}
OSG::NodePtr makePolygon(double pntData[][3], int numPoints) {

  OSG::GeometryPtr geoPtr  = OSG::Geometry::create();
  OSG::NodePtr     nodePtr = OSG::Node::create();

  GeoPositions3fPtr    pnts    = GeoPositions3f::create();
  GeoNormals3fPtr      norms   = GeoNormals3f::create();
  GeoTexCoords2fPtr    tex     = GeoTexCoords2f::create();
  GeoIndicesUI32Ptr    indices = GeoIndicesUI32::create();   
  GeoPLengthsUI32Ptr   lens    = GeoPLengthsUI32::create();  
  GeoPTypesUI8Ptr      types   = GeoPTypesUI8::create();     

  //Set up the properties according to the geometry defined above
  beginEditCP(pnts);
  beginEditCP(norms);
  
  for(int i = 0; i < numPoints; i++) 
    {
      pnts->push_back(Pnt3f(pntData[i][0],
                            pntData[i][1], 
                            pntData[i][2]));

      indices->push_back(2*i);

      norms->push_back(Vec3f(0.0, 0.0, pntData[i][2]));
      indices->push_back(2*i + 1);
    }

  endEditCP(pnts);
  endEditCP(norms);

  beginEditCP(types);
  beginEditCP(lens);
  types->push_back(GL_POLYGON);
  lens->push_back(numPoints);
  endEditCP(types);
  endEditCP(lens);

  beginEditCP(geoPtr);
  
  geoPtr->setMaterial(getDefaultMaterial());
  geoPtr->setPositions(pnts);
  geoPtr->setNormals(norms);
  geoPtr->setIndices(indices);
  
  geoPtr->editMFIndexMapping()->push_back(Geometry::MapPosition | 
                                          Geometry::MapNormal);
  
  geoPtr->setTypes(types);
  geoPtr->setLengths(lens);
  
  endEditCP(geoPtr);

  nodePtr->setCore(geoPtr);
  return nodePtr;
}
Example #20
0
PanelPtr SceneEditor::createEditorTab(SceneComponentEditorPtr Editor, IconManagerPtr TheIconManager) const
{
	//Editor Icon
	ImageComponentPtr EditorIcon = TheIconManager->createIconImageComponent(Editor->getPresentationIconName());
    if(EditorIcon == NullFC)
    {
        EditorIcon = ImageComponent::create();
    }

	beginEditCP(EditorIcon, ImageComponent::ScaleFieldMask | ImageComponent::AlignmentFieldMask);
		EditorIcon->setAlignment(Vec2f(0.5f,0.5f));
		EditorIcon->setScale(ImageComponent::SCALE_MIN_AXIS);
	endEditCP(EditorIcon, ImageComponent::ScaleFieldMask | ImageComponent::AlignmentFieldMask);
	
	//Editor Label
	LabelPtr TabLabel = Label::create();
	beginEditCP(TabLabel, Label::TextFieldMask | Label::BordersFieldMask | Label::BackgroundsFieldMask | Label::AlignmentFieldMask);
		TabLabel->setBorders(NullFC);
		TabLabel->setBackgrounds(NullFC);
		TabLabel->setText(Editor->getPresentationName());
		TabLabel->setAlignment(Vec2f(0.5f,0.5f));
	endEditCP(TabLabel, Label::TextFieldMask | Label::BordersFieldMask | Label::BackgroundsFieldMask | Label::AlignmentFieldMask);

	//Tab
	PanelPtr Tab = Panel::createEmpty();

	//Layout
	SpringLayoutPtr TabLayout = SpringLayout::create();

	//Editor Icon
    TabLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, EditorIcon, 0, SpringLayoutConstraints::WEST_EDGE, Tab);
    TabLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, EditorIcon, 0, SpringLayoutConstraints::EAST_EDGE, Tab);
	TabLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, EditorIcon, 0, SpringLayoutConstraints::NORTH_EDGE, Tab);
	TabLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, EditorIcon, -1, SpringLayoutConstraints::NORTH_EDGE, TabLabel);
	
	//Editor Label
    TabLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, TabLabel, 0, SpringLayoutConstraints::WEST_EDGE, Tab);
    TabLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, TabLabel, 0, SpringLayoutConstraints::EAST_EDGE, Tab);
	TabLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, TabLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, Tab);
	TabLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, TabLabel, LayoutSpring::height(TabLabel));
    
    //Tab Layout
    //TabLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, Tab, LayoutSpring::max(TabLayout->getConstraint(SpringLayoutConstraints::WIDTH_EDGE,TabLabel),TabLayout->getConstraint(SpringLayoutConstraints::WIDTH_EDGE,EditorIcon)));
    //TabLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, Tab, LayoutSpring::sum(TabLayout->getConstraint(SpringLayoutConstraints::HEIGHT_EDGE,TabLabel),TabLayout->getConstraint(SpringLayoutConstraints::HEIGHT_EDGE,EditorIcon)));
    TabLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, Tab, LayoutSpring::width(Tab));
    TabLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, Tab, LayoutSpring::height(Tab));

	beginEditCP(Tab, Panel::ChildrenFieldMask | Panel::LayoutFieldMask | Panel::PreferredSizeFieldMask);
		Tab->getChildren().push_back(EditorIcon);
		Tab->getChildren().push_back(TabLabel);
		Tab->setLayout(TabLayout);
		Tab->setPreferredSize(Vec2f(70.0f,50.0f));
	endEditCP(Tab, Panel::ChildrenFieldMask | Panel::LayoutFieldMask | Panel::PreferredSizeFieldMask);

	return Tab;
}
void FaceSpatialize<BasicTraits>::CategoryGeneral::begin (const FaceIterator&)
{
   if (m_hasTex) {
      m_texCoord = GeoTexCoords2f::create();

      beginEditCP(m_geom);
      m_geom->setTexCoords(m_texCoord);
      endEditCP(m_geom);
      beginEditCP(m_texCoord);
   }
}
void FaceSpatialize<BasicTraits>::CategoryColor::begin (const FaceIterator&)
{
   if (m_hasColor) {
      m_color = GeoColors3f::create();

      beginEditCP(m_geom);
      m_geom->setColors(m_color);
      endEditCP(m_geom);
      beginEditCP(m_color);
   }
}
// TODO: 
void ManipulatorManager::changeManipulator(ManipulatorType type)
{
    if (type != _currentType)
    {
        MFNodePtr parents;
        NodePtr   maniN;
        
        parents = _maniC->getParents();        
        if ( !parents.isEmpty() )
        {
            maniN = parents[0];
            
            beginEditCP( maniN );
            {    
                maniN->setCore( NullFC ); // TODO: delete ok?
            }
            endEditCP(   maniN );
            
            _maniC = NullFC;

            switch (type)
            {
                case TRANSLATE:
                    _maniC = MoveManipulator::create();
                    break;
                case ROTATE:
                    _maniC = RotateManipulator::create();
                    break;
                case SCALE:
                    _maniC = ScaleManipulator::create();
                    break;
            }
            
            _currentType = type;

            beginEditCP(maniN);
            {
                maniN->setCore( _maniC );
             }
            endEditCP(maniN);    

            beginEditCP(_maniC);
            {
                _maniC->setTarget(   _target );
                _maniC->setViewport( _viewport );
            }
            endEditCP(_maniC);
        }
        else
        {
            maniN = NullFC;
        }
    }
}
Example #24
0
void key(unsigned char key, int , int)
{
    switch ( key )
    {
    case 27:    exit(0);
    case 'a':   UChar8 imgdata[32];
                for ( int i = 0; i < 32; i++ )
                    imgdata[i] = static_cast<UChar8>(rand());
                pImage->set( Image::OSG_RGB_PF, 2, 2, 2, 1, 1, 0, imgdata );
                xchunk1->imageContentChanged();
                break;
    case 'b':   {
                UChar8 imgdata[16];
                for ( int i = 0; i < 16; i++ )
                    imgdata[i] = static_cast<UChar8>(rand());
                pImage->set( Image::OSG_RGBA_PF, 2, 2, 1, 1, 1, 0, imgdata );
                beginEditCP( xchunk1 );
                xchunk1->setImage( pImage );
                endEditCP( xchunk1 );
                }
                break;
    case 'c':   {
                beginEditCP( xchunk1 );
                xchunk1->setMinFilter( GL_LINEAR_MIPMAP_LINEAR );
                xchunk1->setMagFilter( GL_LINEAR );
                endEditCP( xchunk1 );
                }
                break;
    case 'd':   {
                beginEditCP( xchunk1 );
                xchunk1->setMinFilter( GL_NEAREST );
                xchunk1->setMagFilter( GL_NEAREST );
                endEditCP( xchunk1 );
                }
                break;
    case 'e':   {
                UChar8 imgdata[16];
                for ( int i = 0; i < 16; i++ )
                    imgdata[i] = static_cast<UChar8>(rand());
                pImage->set( Image::OSG_RGBA_PF, 2, 2, 1, 1, 1, 0, imgdata );
                xchunk1->imageContentChanged(1,1,1,1);
                }
                break;
    case 'f':   {
                UChar8 imgdata[16];
                for ( int i = 0; i < 16; i++ )
                    imgdata[i] = static_cast<UChar8>(rand());
                pImage->set( Image::OSG_RGBA_PF, 2, 2, 1, 1, 1, 0, imgdata );
                xchunk1->imageContentChanged(0,1,0,0);
                }
                break;
    }
}
Example #25
0
Action::ResultE changeGeo(NodePtr& node)
{   
    GeometryPtr geo = GeometryPtr::dcast(node->getCore());
    
    if(geo == NullFC)
        return Action::Continue;


    GeoColors3fPtr colors = GeoColors3fPtr::dcast(geo->getColors());
    if(colors == NullFC)
    {
        colors = GeoColors3f::create();

        colors->resize(geo->getPositions()->getSize());
        
        // Change the geometry to use the new colors
        beginEditCP(geo, Geometry::ColorsFieldMask);
            geo->setColors(colors);
            // If multi-indexed, make the colors use the same index as
            // the geometry
            if(geo->getMFIndexMapping()->size() > 0)
            {
                Int16 pind = geo->calcMappingIndex(Geometry::MapPosition);
                
                if(pind < 0)
                {
                    FFATAL(("Multi-indexed, but no positions index???\n"));
                    return Action::Continue; 
                }
                
                // This makes the colors use the same indices as the positions
                geo->editIndexMapping(pind) |= Geometry::MapColor;
            }
        endEditCP  (geo, Geometry::ColorsFieldMask);
    }
    

    beginEditCP(geo, Geometry::ColorsFieldMask);
    beginEditCP(colors);
    Real32 size = colors->getSize();
    for(UInt32 i=0;i<size;++i)
    {
        Color3f c;
        c[0] = ((Real32) i) / size;
        c[1] = 0.0f;
        c[2] = 0.0f;
        colors->setValue(c, i);
    }
    endEditCP(colors);
    endEditCP(geo, Geometry::ColorsFieldMask);
    
    return Action::Continue; 
}
/**
 * If not done so far, this function sets up the vtk pipeline for looking at at a
 * section perpendicularl to the x-axis, adds the generated geometry to the
 * internal OpenSG root and sets the m_bNewOsgObjectsCreated flag to true
 */
bool CScalarUnstructuredGrid::InitXCutPlanePipeline(){
	// No grid has been loaded so far
	if (m_pvtkDataSet == NULL) return false;

	// The pipeline has already been set up
	if (m_pvtkXCutPlane != NULL) return true;
	
	// setting up the cut plane along x
	m_pvtkXCutPlane = vtkPlane::New();
	m_pvtkXCutPlane->SetOrigin(0.5 * (m_state.m_dXMin + m_state.m_dXMax), 0.5 * (m_state.m_dYMin + m_state.m_dYMax), 0.5 * (m_state.m_dZMin +  m_state.m_dZMax));
	m_pvtkXCutPlane->SetNormal(1.0, 0.0, 0.0);
	vtkCutter *xCut = vtkCutter::New();
	xCut->SetInput(m_pvtkDataSet);
	xCut->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS,
		m_state.m_stdstrAttributeName.c_str());
	xCut->SetCutFunction(m_pvtkXCutPlane);
	vtkCleanPolyData *xCutCleaner = vtkCleanPolyData::New();
	xCutCleaner->SetInput(xCut->GetOutput());
	vtkPolyDataNormals *polyDataNormals = vtkPolyDataNormals::New();
	polyDataNormals->SetInput(xCutCleaner->GetOutput());
	
	vtkPolyDataMapper *xCutMapper = vtkPolyDataMapper::New();
	m_pvtkXSectionLookupTable->SetActiveMapper(xCutMapper);
	xCutMapper->SetLookupTable(m_pvtkXSectionLookupTable);
	//xCutMapper->SetInput(xCutCleaner->GetOutput());
	xCutMapper->SetInput(polyDataNormals->GetOutput());
	xCutMapper->SetScalarModeToUsePointFieldData();
	xCutMapper->ScalarVisibilityOn();
	xCutMapper->SetUseLookupTableScalarRange(0);
	xCutMapper->SetColorModeToMapScalars();
	xCutMapper->SelectColorArray(m_state.m_stdstrAttributeName.c_str());
	xCutMapper->SetScalarRange(m_state.m_dValMin, m_state.m_dValMax);
	//xCutMapper->SetScalarRange(m_pvtkDataSet->GetPointData()->GetScalars()->GetRange());
	m_pXCutActor->SetMapper(xCutMapper);
	
	NodePtr xSectionRoot = m_pXCutActor->GetOsgRoot();
	if (! m_state.m_bShowXSection){
		beginEditCP(xSectionRoot);{
			xSectionRoot->setTravMask(0);
		};endEditCP(xSectionRoot);
	}
	
	m_pXCutActor->UpdateOsg();
	
	beginEditCP(m_posgRoot, Node::ChildrenFieldMask);{
		m_posgRoot->addChild(xSectionRoot);
	};endEditCP(m_posgRoot, Node::ChildrenFieldMask);
	
	m_bNewOsgObjectsCreated = true;
	
	return true;
}
Example #27
0
void VRMLLODBinder::finish(VRMLToOSGAction *)
{
    if(_pNode == NULL)
        return;

    VRMLLOD *pNode = dynamic_cast<VRMLLOD *>(_pNode);

    if(pNode == NULL)
        return;
    
    NodePtr pLODNode    = NodePtr::dcast(_pFieldContainer);

    if(pLODNode == NullFC)
        return;

    DistanceLODPtr pLOD = 
        DistanceLODPtr::dcast(pLODNode->getCore());
    
    if(pLOD == NullFC)
        return;

    UInt32    uiNumRanges;

    beginEditCP(pLOD, DistanceLOD::RangeFieldMask);
    {
        if(pNode->getMFRange()->empty() == false)
        {
            uiNumRanges = pNode->getMFRange()->size();
            
            pLOD->getMFRange()->resize(uiNumRanges);
            
            memcpy(&(pLOD ->getMFRange()->front()),
                   &(pNode->getMFRange()->front()),
                   sizeof(Real32) * uiNumRanges);
        }
    }
    endEditCP  (pLOD, DistanceLOD::RangeFieldMask);

    Vec3f v;

    beginEditCP(pLOD, DistanceLOD::CenterFieldMask);
    {
        v.setValues(pNode->getSFCenter()->getValue()[0],
                    pNode->getSFCenter()->getValue()[1],
                    pNode->getSFCenter()->getValue()[2]);

        pLOD->setCenter(v);
    }
    beginEditCP(pLOD, DistanceLOD::CenterFieldMask);
}
Example #28
0
Particles::Particles(Particles* src)
{
	int i;

	particleSystemInfo = src->particleSystemInfo;
	pParticles = src->pParticles;

// 	particleNode = pParticles != 0 ? pParticles->pGetNodePtr() : Node::create();
	particleNode = Node::create();
	particleModelNode = pParticles->pGetNodePtr();
	assert(particleModelNode != NullFC);

	Vec3f boundingBoxSize = pParticles->GetSize();
	
	particleTransNode = Node::create();
	particleTrans = Transform::create();

	particleModelTrans = Transform::create();

	Matrix m;
	m.setIdentity();
	beginEditCP(particleTrans, Transform::MatrixFieldMask);
		particleTrans->setMatrix(m);
	endEditCP(particleTrans, Transform::MatrixFieldMask);

	beginEditCP(particleModelTrans, Transform::MatrixFieldMask);
		particleModelTrans->setMatrix(m);
	endEditCP(particleModelTrans, Transform::MatrixFieldMask);

	beginEditCP(particleNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
		particleNode->setCore(particleModelTrans);
		particleNode->addChild(particleModelNode);
	endEditCP(particleNode, Node::CoreFieldMask | Node::ChildrenFieldMask);

	beginEditCP(particleTransNode);
		particleTransNode->setCore(particleTrans);
		particleTransNode->addChild(cloneTree(particleNode));

		// set volume static to prevent constant update
		Volume &v = particleTransNode->getVolume( false ).getInstance();
		v.setEmpty();
		v.extendBy( Pnt3f( -boundingBoxSize[0], -boundingBoxSize[1], -boundingBoxSize[2] ) );
		v.extendBy( Pnt3f( boundingBoxSize[0], boundingBoxSize[1], boundingBoxSize[2] ) );
		v.setStatic();
		((DynamicVolume&)particleTransNode->getVolume()).instanceChanged();

	endEditCP(particleTransNode);
	cloned = true;
} // Particles
void FBOSourceTextureFilter::internalUpdate(RenderActionBase *action, const Vec2f& DrawnSize)
{
    Vec2f NewFBOSize(getFBOSize());
    ImagePtr TheImage(getFBO()->getTextures(0)->getImage());
    if(getFBOSize().x() < 0.0f)
    {
        NewFBOSize[0] = DrawnSize.x();
    }
    if(getFBOSize().y() < 0.0f)
    {
        NewFBOSize[1] = DrawnSize.y();
    }
    if(Vec2f(TheImage->getWidth(), TheImage->getHeight()) != NewFBOSize)
    {
        //If the size of the FBO Texture has changed then update it
        for( unsigned int nt = 0; nt < getFBO()->getTextures().getSize(); ++ nt )
        {
            osg::TextureChunkPtr tex = getFBO()->getTextures()[nt];
            beginEditCP (tex);
                beginEditCP(tex->getImage());
                    tex->getImage()->set(tex->getImage()->getPixelFormat(),NewFBOSize.x(), NewFBOSize.y(),
                                         tex->getImage()->getDepth(), tex->getImage()->getMipMapCount(),
                                         tex->getImage()->getFrameCount(),tex->getImage()->getFrameDelay(),
                                         NULL,tex->getImage()->getDataType());
                endEditCP(tex->getImage());
            endEditCP (tex);
        }

        beginEditCP(getFBO(), FBOViewport::DirtyFieldMask | FBOViewport::LeftFieldMask | FBOViewport::RightFieldMask | FBOViewport::BottomFieldMask | FBOViewport::TopFieldMask | FBOViewport::StorageHeightFieldMask | FBOViewport::StorageWidthFieldMask);
            getFBO()->setSize(0,0,NewFBOSize.x()-1, NewFBOSize.y()-1);
            
            getFBO()->setStorageWidth(NewFBOSize.x());
            getFBO()->setStorageHeight(NewFBOSize.y());
            getFBO()->setDirty(true);

        endEditCP(getFBO(), FBOViewport::DirtyFieldMask | FBOViewport::LeftFieldMask | FBOViewport::RightFieldMask | FBOViewport::BottomFieldMask | FBOViewport::TopFieldMask | FBOViewport::StorageHeightFieldMask | FBOViewport::StorageWidthFieldMask);
    }

    //Update the parent wintow of the FBO
    WindowPtr ParentWin(action->getWindow());
    if(getFBO()->getParent() != ParentWin)
    {
        beginEditCP(getFBO(), FBOViewport::ParentFieldMask);
            getFBO()->setParent(ParentWin);
        endEditCP(getFBO(), FBOViewport::ParentFieldMask);
    }

    getFBO()->render(action);
}
Example #30
0
void VRMLAppearanceBinder::finish(VRMLToOSGAction *)
{
    ChunkMaterialPtr pChunkMat = 
        ChunkMaterialPtr::dcast(_pFieldContainer);

    TextureChunkPtr pTexChunk = 
        TextureChunkPtr::dcast(pChunkMat->find(TextureChunk::getClassType()));
    
    MaterialChunkPtr pMatChunk = 
        MaterialChunkPtr::dcast(
            pChunkMat->find(MaterialChunk::getClassType()));
    
    if(pTexChunk != NullFC)
    {    
        beginEditCP(pTexChunk, TextureChunk::EnvModeFieldMask);
        {
            if(pMatChunk == NullFC)
            {
                pTexChunk->setEnvMode(GL_REPLACE);
            }
            else
            {
                pTexChunk->setEnvMode(GL_MODULATE);
            }
        }
        endEditCP  (pTexChunk, TextureChunk::EnvModeFieldMask);
    }
    
    if(pChunkMat != NullFC && (pChunkMat->isTransparent() == true || 
                               _has_alpha))
    {
        BlendChunkPtr pBlendChunk = OSG::BlendChunk::create();

        beginEditCP(pBlendChunk, BlendChunk::SrcFactorFieldMask | 
                                 BlendChunk::DestFactorFieldMask);
        {
            pBlendChunk->setSrcFactor (GL_SRC_ALPHA);
            pBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
        }
        endEditCP  (pBlendChunk, BlendChunk::SrcFactorFieldMask | 
                                 BlendChunk::DestFactorFieldMask);

        beginEditCP(pChunkMat, ChunkMaterial::ChunksFieldMask);
        {
            pChunkMat->addChunk(pBlendChunk);
        }
        endEditCP  (pChunkMat, ChunkMaterial::ChunksFieldMask);
    }
}