예제 #1
0
OSG_USING_NAMESPACE

#if 1
int main (int argc, char **argv)
{
    NodePtr  node;

    const char *fileName = (argc > 1) ? argv[1] : "tie.wrl";

    osgInit(argc, argv);

    NodePtr  pScene      = Node::create();
    GroupPtr pSceneGroup = Group::create();

    pScene->setCore(pSceneGroup);

    node = SceneFileHandler::the().read(fileName);

    node->updateVolume();

    Vec3f center;
    node->getVolume().getCenter(center);

    std::cerr << "Volume: center " << center << ", volume "
              << node->getVolume().getScalarVolume() << std::endl;


    pScene->addChild(node);

    VRMLWriteAction *pWriter = VRMLWriteAction::create();

//    pWriter->addOptions(VRMLWriteAction::OSGNoNormals);

//VRMLWriteAction::OSGNoIndent |

    pWriter->open((argc > 2) ? argv[2] : "test.wrl");

    pWriter->write(pScene);

    pWriter->close();

    return 0;
}
bool VRMLSceneFileType::write(Node         * const  node, 
                              std::ostream         &os,
                              Char8          const *fileNameOrExtension) const
{
    // This is a hack but should be safer.

    std::ofstream *osf = dynamic_cast<std::ofstream *>(&os);

    if(osf != NULL)
        osf->close();
    
    VRMLWriteAction *pWriter = VRMLWriteAction::create();

    // parse options
    bool inlineTex = false;
    if(getOptionAs<bool>("inlineTextures", inlineTex))
    {
        if(inlineTex)
            pWriter->addOptions(VRMLWriteAction::OSGPixelTextures);
        else
            pWriter->subOptions(VRMLWriteAction::OSGPixelTextures);
    }
    
    pWriter->open(fileNameOrExtension);

    pWriter->write(node);

    pWriter->close();

    delete pWriter;

    return true;
}
예제 #3
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
	cout << "Testing screen aligned text generation and file-IO." << endl;
	
    if(argc == 1)
    {
        FFATAL(("Need *.txf or *.ttf font file\n"));
        return -1;
    }

    // OSG init
    osgInit(argc, argv);

    // GLUT init
    int             winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr   gwin = GLUTWindow::create();
    gwin->setId(winid);
    gwin->init();

    PathHandler paths;

    paths.push_backPath(".");

    //paths.push_backPath("/home/elmi/wrk/development/texFont");
    // create the scene
    FontStyle   *fontStyle = FontStyleFactory::the().create( paths, argv[1], 
															 0.25);
	cout << fontStyle->getFontName() << endl;

    // create the scene
    NodePtr pTorus = makeTorus( 0.02, 0.55, 16, 16);
	ChunkMaterialPtr mat = ChunkMaterial::create();

    MaterialChunkPtr pmc = MaterialChunk::create();
    pmc->setDiffuse( Color4f( 1,0,0,0.5 ) );
    pmc->setAmbient( Color4f( 0,1,0,0.5 ) );
    pmc->setSpecular( Color4f( 0,0,1,0.5 ) );
	pmc->setLit( true );
    pmc->setShininess( 20 );

	beginEditCP(mat);
	{
	mat->addChunk( pmc );
	}
	endEditCP(mat);

    scene = Node::create();
	GroupPtr group = Group::create();
    beginEditCP( scene );
    {
        scene->setCore( group );
	}
    endEditCP( scene );

	SharedFontStylePtr sfs = SharedFontStyle::create(); 
	sfs->setContainedFontStyle( fontStyle );

	for( int x=0; x<100; x += 20 )
	{
		for( int y=0; y<100; y += 20 )
		{
			for( int z=0; z<100; z += 20 )
			{
				ScreenAlignedTextPtr scaText = ScreenAlignedText::create();
				if( scaText == NullFC )
				{
					exit (2);
				}
				SharedFontStyleWrapperPtr pFSWrapper = SharedFontStyleWrapper::create();
				pFSWrapper->setFStyleContainer( sfs );
				ostringstream cString;
				cString << '(' 
						<< x 
						<< ',' 
						<< y
						<< ','
						<< z
						<< ')'
						<< endl;

				beginEditCP(scaText);
				{
					scaText->setPosition( Vec3f ( x, y, z ) );
					scaText->setFont( pFSWrapper );
					scaText->setVerticalLineDistance( 0.20 );
					scaText->setAlignment( 0 );
					scaText->editMFText()->push_back( cString.str() );
					scaText->setMaterial( mat );
				}
				endEditCP(scaText);
				NodePtr pTextNode = Node::create();
				beginEditCP( pTextNode );
				{
					pTextNode->setCore( scaText );
				}
				beginEditCP( scene );
				{
					scene->addChild( pTextNode );
				}
				endEditCP( scene );	
				cout << "Erzeugt : " 
					 << cString.str() 
					 << endl;
			}
		}
    }

	//NodePtr pCopied = scene;

#if 1
	{
		ofstream outFileStream( "/tmp/text.osg" );

		if( !outFileStream )
		{
			cerr << "cannot open file" << endl;
			exit(2);
		}
		//FILE *pFile = fopen( "isolinien.osg","w" );
		//BINWriter writer( pFile );
		OSGWriter writer( outFileStream );
		writer.write( scene );
	}
#endif

#if 0
	VRMLWriteAction *pWriter = VRMLWriteAction::create();
	scene->dump();
	pWriter->open("allesscheisse.wrl");
	pWriter->write( scene);
	pWriter->close();
	delete pWriter;
#endif

    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(gwin);
    mgr->setRoot( scene );

    // show the whole scene
    mgr->showAll();

    // GLUT main loop
    glutMainLoop();

    return 0;
}
예제 #4
0
int main (int argc, char **argv)
{
    NodePtr  node;

    osgInit(argc, argv);

    NodePtr  pScene      = Node::create();
    GroupPtr pSceneGroup = Group::create();

    pScene->setCore(pSceneGroup);

    setName(pScene,      "foo");
    setName(pSceneGroup, "bar");

    NodePtr     pSceneChild     = Node::create();
//    NodeCorePtr pSceneChildCore = Group::create();
    NodeCorePtr pSceneChildCore = makeSphereGeo(3, 1);

    pSceneChild->setCore(pSceneChildCore);

    setName(pSceneChild,     "foo1");
//    setName(pSceneChildCore, "bar1");

    pScene->addChild(pSceneChild);


    pSceneChild     = Node::create();
//    pSceneChildCore = Group::create();
//    pSceneChildCore = makeSphereGeo(3, 1);

    pSceneChild->setCore(pSceneChildCore);

//    setName(pSceneChild,     "foo2");
    setName(pSceneChildCore, "bar2");

    pScene->addChild(pSceneChild);


    pSceneChild     = Node::create();
    pSceneChildCore = Group::create();

    pSceneChild->setCore(pSceneChildCore);

    setName(pSceneChild,     "foo3");
    setName(pSceneChildCore, "bar3");

    pScene->addChild(pSceneChild);


    pSceneChild     = Node::create();
    pSceneChildCore = Group::create();

    pSceneChild->setCore(pSceneChildCore);

    setName(pSceneChild,     "foo4");
    setName(pSceneChildCore, "bar4");

    pScene->addChild(pSceneChild);


    pSceneChild     = Node::create();
//    pSceneChildCore = Group::create();

    pSceneChild->setCore(pSceneChildCore);

   setName(pSceneChild,     "foo4");
//    setName(pSceneChildCore, "bar4");

    pScene->addChild(pSceneChild);



    VRMLWriteAction *pWriter = VRMLWriteAction::create();

    pWriter->addOptions(VRMLWriteAction::OSGNoNormals);
//VRMLWriteAction::OSGNoIndent |

    pWriter->open((argc > 2) ? argv[2] : "test.wrl");

    pWriter->write(pScene);

    pWriter->close();

    return 0;
}