osg::ref_ptr<osg::Node> OSGTriangleMeshVisualizer::createTriangleMeshNode(ITriangleMesh* mesh, float red, float green, float blue, float alpha) {
	osg::ref_ptr<osg::Geode> geode = new osg::Geode;
	osg::ref_ptr<osg::TriangleMesh> osgMesh = createTriangleMesh(mesh);
	osg::ref_ptr<osg::ShapeDrawable> drawable = new osg::ShapeDrawable(osgMesh);

	drawable->setColor(osg::Vec4(red, green, blue, alpha)); // TODO: changeable colors...
	geode->addDrawable(drawable);
	geode->setDataVariance(osg::Object::DYNAMIC);

//	osg::Group* group = new osg::Group;
	osg::ref_ptr<osg::Group> group = new osg::Group;
	group->addChild(geode);

	return group;
}
Example #2
0
void TriangleSample::initialize()
{
    // Create the font for drawing the framerate.
    _font = Font::create("res/ui/arial.gpb");

    // Create an orthographic projection matrix.
    float width = getWidth() / (float)getHeight();
    float height = 1.0f;
    Matrix::createOrthographic(width, height, -1.0f, 1.0f, &_worldViewProjectionMatrix);

    // Create the triangle mesh.
    Mesh* mesh = createTriangleMesh();

    // Create a model for the triangle mesh. A model is an instance of a Mesh that can be drawn with a specified material.
    _model = Model::create(mesh);
    SAFE_RELEASE(mesh);

    // Create a material from the built-in "colored-unlit" vertex and fragment shaders.
    // This sample doesn't use lighting so the unlit shader is used.
    // This sample uses vertex color so VERTEX_COLOR is defined. Look at the shader source files to see the supported defines.
    _model->setMaterial("res/shaders/colored.vert", "res/shaders/colored.frag", "VERTEX_COLOR");
}
Example #3
0
PxTriangleMesh* createTriangleMesh( osg::Node& node )
{
    GeometryDataCollector collector;
    node.accept( collector );
    
    std::vector<PxVec3> verts;
    for ( unsigned int i=0; i<collector.vertices.size(); ++i )
    {
        const osg::Vec3& v = collector.vertices[i];
        verts.push_back( PxVec3(v[0], v[1], v[2]) );
    }
    
    std::vector<PxU32> indices;
    for ( unsigned int i=0; i<collector.faces.size(); ++i )
    {
        const GeometryDataCollector::GeometryFace& f = collector.faces[i];
        indices.push_back( f.indices[0] );
        indices.push_back( f.indices[1] );
        indices.push_back( f.indices[2] );
    }
    if ( !verts.size() || !indices.size() ) return NULL;
    return createTriangleMesh(verts, indices);
}
void MeshPrimitiveTest::initialize()
{
    // Create the font for drawing the framerate.
    _font = Font::create("res/common/arial18.gpb");

    // Create an orthographic projection matrix.
    float width = getWidth() / (float)getHeight();
    float height = 1.0f;
    Matrix::createOrthographic(width, height, -1.0f, 1.0f, &_viewProjectionMatrix);

    // Create a model for the triangle mesh. A model is an instance of a Mesh that can be drawn with a specified material.
    Mesh* triangleMesh = createTriangleMesh();
    _triangles = Model::create(triangleMesh);
    SAFE_RELEASE(triangleMesh);

    // Create a material from the built-in "colored-unlit" vertex and fragment shaders.
    // This sample doesn't use lighting so the unlit shader is used.
    // This sample uses vertex color so VERTEX_COLOR is defined. Look at the shader source files to see the supported defines.
    _triangles->setMaterial("res/shaders/colored-unlit.vert", "res/shaders/colored-unlit.frag", "VERTEX_COLOR");
    
    Mesh* triangleStripMesh = createTriangleStripMesh();
    _triangleStrip = Model::create(triangleStripMesh);
    SAFE_RELEASE(triangleStripMesh);
    Material* material = _triangleStrip->setMaterial("res/shaders/colored-unlit.vert", "res/shaders/colored-unlit.frag", "VERTEX_COLOR");
    material->getStateBlock()->setDepthTest(true);
    material->getStateBlock()->setDepthWrite(true);

    Mesh* lineStripMesh = createLineStripMesh();
    _lineStrip = Model::create(lineStripMesh);
    SAFE_RELEASE(lineStripMesh);
    _lineStrip->setMaterial("res/shaders/colored-unlit.vert", "res/shaders/colored-unlit.frag", "VERTEX_COLOR");
    
    Mesh* lineMesh = createLinesMesh();
    _lines = Model::create(lineMesh);
    SAFE_RELEASE(lineMesh);
    _lines->setMaterial("res/shaders/colored-unlit.vert", "res/shaders/colored-unlit.frag", "VERTEX_COLOR");
}