Exemplo n.º 1
0
    virtual void addMorphVertex(Vertex& vertex0, Vertex& /*vertex100*/)
    {
        osg::Vec3Array* vertices = getOrCreateVertexArray(*_geometry);
        vertices->push_back(vertex0._coord);

        if (isGouraud())
        {
            osg::Vec4Array* colors = getOrCreateColorArray(*_geometry);
            if (vertex0.validColor())
            {
                colors->push_back(vertex0._color);
            }
            else
            {
                // Use face color if vertex color is -1 in a gouraud polygon.
                // http://www.multigen-paradigm.com/ubb/Forum1/HTML/000967.html
                colors->push_back(_primaryColor);
            }
        }

        if (vertex0.validNormal())
        {
            osg::Vec3Array* normals = getOrCreateNormalArray(*_geometry);
            normals->push_back(vertex0._normal);
        }

        for (int layer=0; layer<Vertex::MAX_LAYERS; layer++)
        {
            if (vertex0.validUV(layer))
            {
                osg::Vec2Array* UVs = getOrCreateTextureArray(*_geometry,layer);
                UVs->push_back(vertex0._uv[layer]);
            }
        }
    }
Exemplo n.º 2
0
void createFaces(osg::Geometry& geometry, Polyhedron const& polyhedron, unsigned int faceMask = PolyhedronGeometry::All)
{
    osgUtil::Tessellator tessellator;
    tessellator.setTessellationType(osgUtil::Tessellator::TESS_TYPE_POLYGONS);
    tessellator.setWindingType(osgUtil::Tessellator::TESS_WINDING_NONZERO);

    auto _vertices = getOrCreateVertexArray(geometry);
    auto _normals = getOrCreateNormalArray(geometry);
    auto _colors = getOrCreateColorArray(geometry);

    osg::ref_ptr<osg::Vec3Array> vertices = createVertexArray(polyhedron);
    VertexIndexArrays polygons = createVertexIndexArrays(polyhedron);

    for (auto const& polygon: polygons)
    {
        assert(polygon && polygon->size() >= 3);

        if (!(faceMask & PolyhedronGeometry::FaceMaskFromSides(polygon->size()))) continue;

        auto first = _vertices->size();
        auto count = polygon->size();

        auto normal = detail::calculateNormal(vertices, polygon);
        auto color = detail::calculateColor(vertices, polygon);

        for (auto i = 0u; i < polygon->size(); ++i)
        {
            auto vertex = vertices->at(polygon->at(i));
            _vertices->push_back(vertex);
            _normals->push_back(normal);
            _colors->push_back(color);
        }

        geometry.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, first, count));
    }

    tessellator.retessellatePolygons(geometry);
}
Exemplo n.º 3
0
    virtual void addVertex(Vertex& vertex)
    {
        osg::Vec3Array* vertices = getOrCreateVertexArray(*_geometry);
        vertices->push_back(vertex._coord);

        if (isGouraud())
        {
            osg::Vec4Array* colors = getOrCreateColorArray(*_geometry);
            if (vertex.validColor())
            {
                colors->push_back(vertex._color);
            }
            else
            {
                // Use face color if vertex color is -1 in a gouraud polygon.
                // http://www.multigen-paradigm.com/ubb/Forum1/HTML/000967.html
                // Incorporate Face transparency per osg-users thread "Open Flight
                // characteristic not reflected in the current OSG" (Sept/Oct 2011)
                colors->push_back(osg::Vec4(_primaryColor.r(), _primaryColor.g(),
                    _primaryColor.b(), ( 1.0 - getTransparency() ) ));
            }
        }

        bool strict = false; // prepare for "strict" reader option.
        if (strict)
        {
            if (vertex.validNormal())
            {
                osg::Vec3Array* normals = getOrCreateNormalArray(*_geometry);
                normals->push_back(vertex._normal);
            }
        }
        else
        {
            // Add normal only if lit.
            if (isLit())
            {
                osg::Vec3Array* normals = getOrCreateNormalArray(*_geometry);

                if (vertex.validNormal())
                    normals->push_back(vertex._normal);
                else // if lit and no normal in Vertex
                {
                    // Use previous normal if available.
                    if (normals->empty())
                        normals->push_back(osg::Vec3(0,0,1));
                    else
                        normals->push_back(normals->back());
                }
            }
        }

        for (int layer=0; layer<Vertex::MAX_LAYERS; layer++)
        {
            if (vertex.validUV(layer))
            {
                osg::Vec2Array* UVs = getOrCreateTextureArray(*_geometry,layer);
                UVs->push_back(vertex._uv[layer]);
            }
        }
    }