Пример #1
0
MaterialTransitPtr OctreeVisualization::createMatLine(OctreePtr tree,
                                                      const Octree::OTNodePtr node,
                                                      const Color3f& CoolColor,
                                                      const Color3f& HotColor,
                                                      Real32 Alpha,
                                                      BlendChunk* BaseBlendChunk,
                                                      LineChunk* BaseLineChunk
                                                     )
{
    //Calculate the Color
    Real32 t = static_cast<Real32>(node->getDepth())/static_cast<Real32>(tree->getDepth());
    Color3f NodeColor(t*HotColor + (1.0f-t)*CoolColor);
    Color4f NodeColorWithAlpha(NodeColor.red(),NodeColor.green(),NodeColor.blue(),Alpha);

    MaterialChunkRecPtr    DefaultMatChunk = MaterialChunk::create();
    DefaultMatChunk->setAmbient(NodeColorWithAlpha);
    DefaultMatChunk->setDiffuse(NodeColorWithAlpha);

    ChunkMaterialRecPtr NodeMat = ChunkMaterial::create();
    NodeMat->setSortKey(1);
    NodeMat->addChunk(BaseBlendChunk);
    NodeMat->addChunk(DefaultMatChunk);
    NodeMat->addChunk(BaseLineChunk);

    return MaterialTransitPtr(NodeMat);
}
void ParticleSystemParticleTrailGenerator::onCreate(const ParticleTrailGenerator *Id)
{
    // assemble default material
    PointChunkRecPtr pointChunk = PointChunk::create();
    pointChunk->setSmooth(true);

    BlendChunkRecPtr blendChunk = BlendChunk::create();

    //Particle System Material
    MaterialChunkRecPtr materialChunkChunk = MaterialChunk::create();
    materialChunkChunk->setAmbient(Color4f(0.5f,0.5f,0.5f,1.0f));
    materialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
    materialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
    materialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

    // Assembling materials
    ChunkMaterialRecPtr mat = ChunkMaterial::create();
    mat->addChunk(materialChunkChunk);
    mat->addChunk(pointChunk);
    mat->addChunk(blendChunk);

    PointParticleSystemDrawerRecPtr theDrawer = PointParticleSystemDrawer::create();
    theDrawer->setForcePerParticleSizing(true);

    ParticleSystemRecPtr newPS = ParticleSystem::create();
    newPS->setDynamic(true);
    setParticleSystem(newPS);

    ParticleSystemCoreRecPtr newCore = ParticleSystemCore::create();
    newCore->setSystem(newPS);
    newCore->setMaterial(mat);
    newCore->setDrawer(theDrawer);

    setCore(newCore);
}
Пример #3
0
    void reset() {
        mat = ChunkMaterial::create();
        colChunk = MaterialChunk::create();
        colChunk->setBackMaterial(false);
        mat->addChunk(colChunk);
        twoSidedChunk = TwoSidedLightingChunk::create();
        mat->addChunk(twoSidedChunk);
        blendChunk = 0;
        texChunk = 0;
        genChunk = 0;
        envChunk = 0;
        lineChunk = 0;
        pointChunk = 0;
        polygonChunk = 0;
        texture = 0;
        video = 0;
        shaderChunk = 0;
        clipChunk = 0;
        stencilChunk = 0;
        deffered = false;

        colChunk->setDiffuse( Color4f(1, 1, 1, 1) );
        colChunk->setAmbient( Color4f(0.3, 0.3, 0.3, 1) );
        colChunk->setSpecular( Color4f(1, 1, 1, 1) );
        colChunk->setShininess( 50 );
    }
Пример #4
0
GeometryTransitPtr createPathGeometry(const std::vector<Pnt3f>& Path)
{

    //*******************Create the Geometry for the box
    GeoUInt8PropertyRecPtr type = GeoUInt8Property::create();
    //Volume bound box
    type->push_back(GL_LINE_STRIP);

    GeoUInt32PropertyRefPtr lens = GeoUInt32Property::create();
    //Volume bound box
    lens->push_back(Path.size());

    Color3f CoolColor(0.0f,0.0f,1.0f),
            HotColor(1.0f,0.0f,0.0f);

    GeoUInt32PropertyRefPtr index = GeoUInt32Property::create();
    GeoPnt3fPropertyRefPtr points = GeoPnt3fProperty::create();
    GeoVec3fPropertyRefPtr colors = GeoVec3fProperty::create();

    //Volume bound box
    Color3f Color;
    Real32 t;
    for(UInt32 i(0) ; i<Path.size() ; ++i)
    {
        t = static_cast<Real32>(i)/static_cast<Real32>(Path.size());
        Color = (t*CoolColor) + ((1.0f-t)*HotColor);
        index->push_back(i);
        points->push_back(Path[i]);
        colors->push_back(Color);
    }

    GeometryRecPtr PathGeo = Geometry::create();
    PathGeo->setTypes     (type);
    PathGeo->setLengths   (lens);
    PathGeo->setIndices   (index);
    PathGeo->setPositions (points);
    PathGeo->setColors    (colors);

    //Create the material for the line
    LineChunkRecPtr DefaultLineChunk = LineChunk::create();
    DefaultLineChunk->setWidth(2.0f);

    MaterialChunkRecPtr DefaultMaterialChunk = MaterialChunk::create();
    DefaultMaterialChunk->setLit(false);

    ChunkMaterialRecPtr DefaultChunkMaterial = ChunkMaterial::create();
    DefaultChunkMaterial->addChunk(DefaultMaterialChunk);
    DefaultChunkMaterial->addChunk(DefaultLineChunk);

    PathGeo->setMaterial(DefaultChunkMaterial);

    return GeometryTransitPtr(PathGeo);
}
Пример #5
0
void VRTransform::initTranslator() { // TODO
    if (translator != 0) return;

    translator = makeCoordAxis(0.3, 3, false);
    translator->setTravMask(0);
    addChild(translator);
    GeometryRecPtr geo = dynamic_cast<Geometry*>(translator->getCore());

    string shdr_vp =
    "void main( void ) {"
    "   gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;"
    "   gl_Position.z = -0.1;"
    "   gl_FrontColor = gl_Color;"
    "}";

    /*string shdr_fp =
    "void main( void ) {"
    "   gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;"
    "   gl_Position.z = -0.1;"
    "}";*/

    ChunkMaterialRecPtr mat = ChunkMaterial::create();
    mat->setSortKey(100);// render last
    SimpleSHLChunkRecPtr shader_chunk = SimpleSHLChunk::create();
    shader_chunk->setVertexProgram(shdr_vp.c_str());
    //shader_chunk->setVertexProgram(shdr_fp.c_str());
    mat->addChunk(shader_chunk);

    geo->setMaterial(mat);
}
Пример #6
0
ChunkMaterialTransitPtr createMaterial(const Color4f& TheColor)
{
    MaterialChunkRecPtr BackgroundMaterialChunk = MaterialChunk::create();
    BackgroundMaterialChunk->setAmbient (TheColor);
    BackgroundMaterialChunk->setDiffuse (TheColor);
    BackgroundMaterialChunk->setSpecular(TheColor);

    ChunkMaterialRecPtr BackgroundMaterial = ChunkMaterial::create();
    BackgroundMaterial->addChunk(BackgroundMaterialChunk);

    return ChunkMaterialTransitPtr(BackgroundMaterial);
}
Пример #7
0
VRShader::VRShader(ChunkMaterialRecPtr mat) {
    shader_chunk = ShaderProgramChunk::create();
    mat->addChunk(shader_chunk);

    vProgram = ShaderProgram::createVertexShader  ();
    fProgram = ShaderProgram::createFragmentShader();
    gProgram = ShaderProgram::createGeometryShader();
    shader_chunk->addShader(vProgram);
    shader_chunk->addShader(fProgram);
    shader_chunk->addShader(gProgram);

    vProgram->createDefaulAttribMapping();
    vProgram->addOSGVariable("OSGViewportSize");
}
Пример #8
0
MaterialTransitPtr OctreeVisualization::createMatFilled(OctreePtr tree,
                                                        const Octree::OTNodePtr node,
                                                        const Color3f& CoolColor,
                                                        const Color3f& HotColor,
                                                        Real32 Alpha,
                                                        BlendChunk* BaseBlendChunk,
                                                        PolygonChunk* BasePolygonChunk
                                                       )
{
    //Calculate the Color
    //Real32 t = static_cast<Real32>(node->getDepth())/static_cast<Real32>(tree->getDepth());
    //Color3f NodeColor(t*HotColor + (1.0f-t)*CoolColor);
    Color3f NodeColor;
    Color4f NodeColorWithAlpha;
    if(node->getContainsObstacles())
    {
        NodeColor = HotColor;
        NodeColorWithAlpha.setValuesRGBA(NodeColor.red(),NodeColor.green(),NodeColor.blue(),0.55);
    }
    else
    {
        NodeColor = CoolColor;
        NodeColorWithAlpha.setValuesRGBA(NodeColor.red(),NodeColor.green(),NodeColor.blue(),0.05);
    }

    MaterialChunkRecPtr    DefaultMatChunk = MaterialChunk::create();
    DefaultMatChunk->setAmbient(NodeColorWithAlpha);
    DefaultMatChunk->setDiffuse(NodeColorWithAlpha);

    ChunkMaterialRecPtr NodeMat = ChunkMaterial::create();
    NodeMat->setSortKey(1);
    NodeMat->addChunk(BaseBlendChunk);
    NodeMat->addChunk(BasePolygonChunk);
    NodeMat->addChunk(DefaultMatChunk);

    return MaterialTransitPtr(NodeMat);
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));

        //Particle System Material
        PointChunkRecPtr PSPointChunk = PointChunk::create();
        PSPointChunk->setSize(5.0f);
        PSPointChunk->setSmooth(true);

        BlendChunkRecPtr PSBlendChunk = BlendChunk::create();
        PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
        PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

        MaterialChunkRecPtr PSMaterialChunkChunk = MaterialChunk::create();
        PSMaterialChunkChunk->setAmbient(Color4f(0.5f,0.5f,0.5f,0.3f));
        PSMaterialChunkChunk->setDiffuse(Color4f(0.8f,0.8f,0.8f,0.3f));
        PSMaterialChunkChunk->setSpecular(Color4f(1.0f,1.0f,1.0f,0.3f));
        PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

        ChunkMaterialRecPtr PSMaterial = ChunkMaterial::create();
        PSMaterial->addChunk(PSPointChunk);
        PSMaterial->addChunk(PSMaterialChunkChunk);
        PSMaterial->addChunk(PSBlendChunk);


        //Particle System
        ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
        for(UInt32 i(0) ; i<10 ; ++i)
        {
            ExampleParticleSystem->addParticle(Pnt3f(i,i,i),
                                               Vec3f(0.0,0.0f,1.0f),
                                               Color4f(1.0,0.0,0.0,0.5), 
                                               Vec3f(1.0,1.0,1.0), 
                                               -1.0, 
                                               Vec3f(0.0f,0.0f,0.0f), //Velocity
                                               Vec3f(0.0f,0.0f,0.0f)
                                              );
        }
        ExampleParticleSystem->attachUpdateProducer(TutorialWindow);

        //Particle System Drawer
        //Point
        PointParticleSystemDrawerRecPtr ExamplePointDrawer = PointParticleSystemDrawer::create();
        //ExamplePointParticleSystemDrawer->setForcePerParticleSizing(true);

        //Line
        LineParticleSystemDrawerRecPtr ExampleLineDrawer = LineParticleSystemDrawer::create();
        ExampleLineDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_NORMAL);//DIRECTION_VELOCITY_CHANGE);
        ExampleLineDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X);
        //Quad
        QuadParticleSystemDrawerRecPtr ExampleQuadDrawer = QuadParticleSystemDrawer::create();

        //Disc
        DiscParticleSystemDrawerRecPtr ExampleDiscDrawer = DiscParticleSystemDrawer::create();
        ExampleDiscDrawer->setSegments(16);
        ExampleDiscDrawer->setCenterAlpha(1.0);
        ExampleDiscDrawer->setEdgeAlpha(0.0);

        //Particle System Node
        ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create();
        ParticleNodeCore->setSystem(ExampleParticleSystem);
        ParticleNodeCore->setDrawer(ExampleLineDrawer);
        ParticleNodeCore->setMaterial(PSMaterial);

        NodeRecPtr ParticleNode = Node::create();
        ParticleNode->setCore(ParticleNodeCore);


        // Make Main Scene Node
        NodeRecPtr scene = Node::create();
        scene->setCore(Group::create());
        scene->addChild(ParticleNode);

        sceneManager.setRoot(scene);

        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
                                                    &sceneManager,
                                                    ParticleNodeCore.get(),
                                                    ExamplePointDrawer,
                                                    ExampleLineDrawer,
                                                    ExampleQuadDrawer,
                                                    ExampleDiscDrawer
                                                   ));

        //Create the Documentation
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // Show the whole Scene
        sceneManager.showAll();


        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "01ParticleSystemDrawers");

        commitChanges();

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}