コード例 #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
ファイル: VRMaterial.cpp プロジェクト: uagmw/polyvr
    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
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);
}
コード例 #5
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);
}
コード例 #6
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);
}
コード例 #7
0
ファイル: VRMaterial.cpp プロジェクト: uagmw/polyvr
void VRMaterial::setMaterial(MaterialRecPtr m) {
    if ( dynamic_pointer_cast<MultiPassMaterial>(m) ) {
        MultiPassMaterialRecPtr mm = dynamic_pointer_cast<MultiPassMaterial>(m);
        for (unsigned int i=0; i<mm->getNPasses(); i++) {
            if (i > 0) addPass();
            setMaterial(mm->getMaterials(i));
        }
        setActivePass(0);
        return;
    }

    if ( isSMat(m) ) {
        SimpleMaterialRecPtr sm = dynamic_pointer_cast<SimpleMaterial>(m);
        setDiffuse(sm->getDiffuse());
        setAmbient(sm->getAmbient());
        setSpecular(sm->getSpecular());

        if ( isSTMat(m) ) {
            SimpleTexturedMaterialRecPtr stm = dynamic_pointer_cast<SimpleTexturedMaterial>(m);
            setTexture( VRTexture::create(stm->getImage()), true);
        }

        return;
    }
    if ( isCMat(m) ) {
        MaterialChunkRecPtr mc = 0;
        BlendChunkRecPtr bc = 0;
        TextureEnvChunkRecPtr ec = 0;
        TextureObjChunkRecPtr tc = 0;

        ChunkMaterialRecPtr cmat = dynamic_pointer_cast<ChunkMaterial>(m);
        for (uint i=0; i<cmat->getMFChunks()->size(); i++) {
            StateChunkRecPtr chunk = cmat->getChunk(i);
            if (mc == 0) mc = dynamic_pointer_cast<MaterialChunk>(chunk);
            if (bc == 0) bc = dynamic_pointer_cast<BlendChunk>(chunk);
            if (ec == 0) ec = dynamic_pointer_cast<TextureEnvChunk>(chunk);
            if (tc == 0) tc = dynamic_pointer_cast<TextureObjChunk>(chunk);
        }

        auto md = mats[activePass];
        if (mc) mc->setBackMaterial(false);
        if (mc) {
            if (md->colChunk) md->mat->subChunk(md->colChunk);
            md->colChunk = mc;
            md->mat->addChunk(mc);
        }
        if (bc) {
            if (md->blendChunk) md->mat->subChunk(md->blendChunk);
            md->blendChunk = bc;
            md->mat->addChunk(bc);
        }
        if (ec) {
            if (md->envChunk) md->mat->subChunk(md->envChunk);
            md->envChunk = ec;
            md->mat->addChunk(ec);
        }
        if (tc) {
            if (md->texChunk) md->mat->subChunk(md->texChunk);
            md->texChunk = tc;
            md->mat->addChunk(tc);
        }
        return;
    }

    cout << "Warning: unhandled material type\n";
    if (dynamic_pointer_cast<Material>(m)) cout << " Material" << endl;
    if (dynamic_pointer_cast<PrimeMaterial>(m)) cout << "  PrimeMaterial" << endl;
    if (dynamic_pointer_cast<SimpleMaterial>(m)) cout << "   SimpleMaterial" << endl;
    if (dynamic_pointer_cast<SimpleTexturedMaterial>(m)) cout << "   SimpleTexturedMaterial" << endl;
    if (dynamic_pointer_cast<VariantMaterial>(m)) cout << "   VariantMaterial" << endl;
    if (dynamic_pointer_cast<ChunkMaterial>(m)) cout << "  ChunkMaterial" << endl;
    if (dynamic_pointer_cast<MultiPassMaterial>(m)) cout << "   MultiPassMaterial" << endl;
    if (dynamic_pointer_cast<CompositeMaterial>(m)) cout << "   CompositeMaterial" << endl;
    if (dynamic_pointer_cast<SwitchMaterial>(m)) cout << "   SwitchMaterial" << endl;
}
コード例 #8
0
ファイル: VRMaterial.cpp プロジェクト: uagmw/polyvr
    VRMatData* copy() {
        VRMatData* m = new VRMatData();
        m->mat = ChunkMaterial::create();

        if (colChunk) {
            m->colChunk = dynamic_pointer_cast<MaterialChunk>(colChunk->shallowCopy());
            m->mat->addChunk(m->colChunk);
        }
        if (blendChunk) {
            m->blendChunk = dynamic_pointer_cast<BlendChunk>(blendChunk->shallowCopy());
            m->mat->addChunk(m->blendChunk);
        }
        if (envChunk) {
            m->envChunk = dynamic_pointer_cast<TextureEnvChunk>(envChunk->shallowCopy());
            m->mat->addChunk(m->envChunk);
        }
        if (texChunk) {
            m->texChunk = dynamic_pointer_cast<TextureObjChunk>(texChunk->shallowCopy());
            m->mat->addChunk(m->texChunk);
        }
        if (genChunk) {
            m->genChunk = dynamic_pointer_cast<TexGenChunk>(genChunk->shallowCopy());
            m->mat->addChunk(m->genChunk);
        }
        if (lineChunk) {
            m->lineChunk = dynamic_pointer_cast<LineChunk>(lineChunk->shallowCopy());
            m->mat->addChunk(m->lineChunk);
        }
        if (pointChunk) {
            m->pointChunk = dynamic_pointer_cast<PointChunk>(pointChunk->shallowCopy());
            m->mat->addChunk(m->pointChunk);
        }
        if (polygonChunk) {
            m->polygonChunk = dynamic_pointer_cast<PolygonChunk>(polygonChunk->shallowCopy());
            m->mat->addChunk(m->polygonChunk);
        }
        if (twoSidedChunk) {
            m->twoSidedChunk = dynamic_pointer_cast<TwoSidedLightingChunk>(twoSidedChunk->shallowCopy());
            m->mat->addChunk(m->twoSidedChunk);
        }
        if (clipChunk) {
            m->clipChunk = dynamic_pointer_cast<ClipPlaneChunk>(clipChunk->shallowCopy());
            m->mat->addChunk(m->clipChunk);
        }
        if (stencilChunk) {
            m->stencilChunk = dynamic_pointer_cast<StencilChunk>(stencilChunk->shallowCopy());
            m->mat->addChunk(m->stencilChunk);
        }
        if (shaderChunk) {
            m->shaderChunk = ShaderProgramChunk::create();
            m->mat->addChunk(m->shaderChunk);
        }

        if (texture) {
            ImageRecPtr img = dynamic_pointer_cast<Image>(texture->getImage()->shallowCopy());
            m->texture = VRTexture::create(img);
            m->texChunk->setImage(img);
        }

        if (vProgram) {
            m->vProgram = dynamic_pointer_cast<ShaderProgram>(vProgram->shallowCopy());
            m->shaderChunk->addShader(m->vProgram);
        }
        if (fProgram) {
            m->fProgram = dynamic_pointer_cast<ShaderProgram>(fProgram->shallowCopy());
            m->shaderChunk->addShader(m->fProgram);
        }
        if (gProgram) {
            m->gProgram = dynamic_pointer_cast<ShaderProgram>(gProgram->shallowCopy());
            m->shaderChunk->addShader(m->gProgram);
        }
        if (video) ; // TODO

        m->vertexScript = vertexScript;
        m->fragmentScript = fragmentScript;
        m->geometryScript = geometryScript;

        return m;
    }
コード例 #9
0
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;
}