Beispiel #1
0
void WriterNodeVisitor::apply( osg::Geode &node )
{
    pushStateSet(node.getStateSet());
    //_nameStack.push_back(node.getName());
    unsigned int count = node.getNumDrawables();
    ListTriangle listTriangles;
    bool texcoords = false;
    for ( unsigned int i = 0; i < count; i++ )
    {
        osg::Geometry *g = node.getDrawable( i )->asGeometry();
        if ( g != NULL )
        {
            pushStateSet(g->getStateSet());
            createListTriangle(g, listTriangles, texcoords, i);        // May set _succeded to false
            popStateSet(g->getStateSet());
            if (!succeeded()) break;
        }
    }
    if (succeeded() && count > 0)
    {
#if DISABLE_3DS_ANIMATION
        osg::Matrix mat( osg::computeLocalToWorld(getNodePath()) );
        buildFaces(node, mat, listTriangles, texcoords);        // May set _succeded to false
#else
        buildFaces(node, osg::Matrix(), listTriangles, texcoords);        // May set _succeded to false
#endif
    }
    popStateSet(node.getStateSet());
    //_nameStack.pop_back();
    if (succeeded())
        traverse(node);
}
void
CountsVisitor::apply(osg::Transform& node)
{
    pushStateSet(node.getStateSet());

    if (dynamic_cast<osgSim::DOFTransform*>(&node) != NULL)
    {
        _dofTransforms++;
        osg::ref_ptr<osg::Object> rp = (osg::Object*)&node;
        _uDofTransforms.insert(rp);
    }
    else
    {
        _transforms++;
        osg::ref_ptr<osg::Object> rp = (osg::Object*)&node;
        _uTransforms.insert(rp);
    }
    _totalChildren += node.getNumChildren();
    apply(node.getStateSet());

    if (++_depth > _maxDepth)
        _maxDepth = _depth;
    traverse((osg::Node&)node);
    _depth--;

    popStateSet();
}
Beispiel #3
0
void WriterNodeVisitor::apply( osg::Billboard &node )
{
    // TODO Does not handle Billboards' points yet

    pushStateSet(node.getStateSet());
    Lib3dsMeshInstanceNode * parent = _cur3dsNode;

    unsigned int count = node.getNumDrawables();
    ListTriangle listTriangles;
    bool texcoords = false;
    OSG_NOTICE << "Warning: 3DS writer is incomplete for Billboards (rotation not implemented)." << std::endl;
#if DISABLE_3DS_ANIMATION
    osg::Matrix m( osg::computeLocalToWorld(getNodePath()) );
#endif
    for ( unsigned int i = 0; i < count; i++ )
    {
        osg::Geometry *g = node.getDrawable( i )->asGeometry();
        if ( g != NULL )
        {
            listTriangles.clear();
            _cur3dsNode = parent;

            pushStateSet(g->getStateSet());
            createListTriangle(g, listTriangles, texcoords, i);
            popStateSet(g->getStateSet());        // May set _succeded to false
            if (!succeeded()) break;

            osg::Matrix pointLocalMat(osg::Matrix::translate(node.getPosition(i)));        // TODO handle rotation
#if DISABLE_3DS_ANIMATION
            osg::Matrix currentBillboardWorldMat(pointLocalMat * m);
            apply3DSMatrixNode(node, &pointLocalMat, "bil");                            // Add a 3DS matrix node (with local matrix)
            buildFaces(node, currentBillboardWorldMat, listTriangles, texcoords);        // May set _succeded to false
#else
            apply3DSMatrixNode(node, &pointLocalMat, "bil");                            // Add a 3DS matrix node (with local matrix)
            buildFaces(node, osg::Matrix(), listTriangles, texcoords);                    // May set _succeded to false
#endif
            if (!succeeded()) break;
        }
    }

    if (succeeded())
        traverse(node);
    _cur3dsNode = parent;
    popStateSet(node.getStateSet());
}
void OBJWriterNodeVisitor::apply(osg::Geometry& geometry)
{
    osg::Matrix m = osg::computeLocalToWorld(getNodePath());

    pushStateSet(geometry.getStateSet());

    processGeometry(&geometry,m);

    popStateSet(geometry.getStateSet());
}
void DXFWriterNodeVisitor::apply( osg::Geode &node )
{

    pushStateSet(node.getStateSet());
    osg::Matrix m = osg::computeLocalToWorld(getNodePath());
    unsigned int count = node.getNumDrawables();

    for ( unsigned int i = 0; i < count; i++ )
    {
        osg::Geometry *g = node.getDrawable( i )->asGeometry();
        if ( g != NULL )
        {
            pushStateSet(g->getStateSet());
            processGeometry(g,m);
            popStateSet(g->getStateSet());
        }
    }


    popStateSet(node.getStateSet());
}
void OBJWriterNodeVisitor::apply( osg::Geode &node )
{
    pushStateSet(node.getStateSet());
    _nameStack.push_back(node.getName());
    unsigned int count = node.getNumDrawables();
    for ( unsigned int i = 0; i < count; i++ )
    {
        node.getDrawable( i )->accept(*this);
    }

    popStateSet(node.getStateSet());
    _nameStack.pop_back();
}
Beispiel #7
0
void WriterNodeVisitor::apply(osg::MatrixTransform &node)
{
    pushStateSet(node.getStateSet());
    Lib3dsMeshInstanceNode * parent = _cur3dsNode;
#if DISABLE_3DS_ANIMATION
    osg::Matrix mat( osg::computeLocalToWorld(getNodePath()) );
#else
    osg::Matrix mat( node.getMatrix() );
#endif
    apply3DSMatrixNode(node, &mat, "mtx");
    if (succeeded())
        traverse(node);
    _cur3dsNode = parent;
    popStateSet(node.getStateSet());
}
void
CountsVisitor::apply(osg::Node& node)
{
    pushStateSet(node.getStateSet());

    _nodes++;
    osg::ref_ptr<osg::Object> rp = (osg::Object*)&node;
    _uNodes.insert(rp);
    apply(node.getStateSet());

    if (++_depth > _maxDepth)
        _maxDepth = _depth;
    traverse(node);
    _depth--;

    popStateSet();
}
void
CountsVisitor::apply(osg::MatrixTransform& node)
{
    pushStateSet(node.getStateSet());

    _matrixTransforms++;
    osg::ref_ptr<osg::Object> rp = (osg::Object*)&node;
    _uMatrixTransforms.insert(rp);
    _totalChildren += node.getNumChildren();
    apply(node.getStateSet());

    if (++_depth > _maxDepth)
        _maxDepth = _depth;
    traverse((osg::Node&)node);
    _depth--;

    popStateSet();
}
Beispiel #10
0
void
CountsVisitor::apply(osg::PagedLOD& node)
{
    pushStateSet(node.getStateSet());

    osg::Group* grp = node.getParent(0);
    osg::Group* gPar = NULL;
    if (grp)
        gPar = grp->getParent(0);
    apply(node.getStateSet());

    _pagedLods++;
    osg::ref_ptr<osg::Object> rp = (osg::Object*)&node;
    _uPagedLods.insert(rp);
    _totalChildren += node.getNumChildren();

    if (++_depth > _maxDepth)
        _maxDepth = _depth;
    traverse((osg::Node&)node);
    _depth--;

    popStateSet();
}
Beispiel #11
0
void
CountsVisitor::apply(osg::Geode& node)
{
    pushStateSet(node.getStateSet());

    _geodes++;
    osg::ref_ptr<osg::Object> rp = (osg::Object*)&node;
    _uGeodes.insert(rp);
    apply(node.getStateSet());

    unsigned int idx;
    for (idx=0; idx<node.getNumDrawables(); idx++)
    {
        osg::Drawable* draw = node.getDrawable(idx);
        apply(draw);
    }

    if (++_depth > _maxDepth)
        _maxDepth = _depth;
    traverse((osg::Node&)node);
    _depth--;

    popStateSet();
}
Beispiel #12
0
void CountsVisitor::apply(osg::Drawable* draw)
{
    apply(draw->getStateSet());

    pushStateSet(draw->getStateSet());

    if(_countUserMode)
    {
        if(isSet(_userMode, _stateStack.back().get()))
        {
            if(isEnabled(_userMode, _stateStack.back().get()))
                _drawUserModeOn++;
            else
                _drawUserModeOff++;
        }
        else
            _drawUserModeNotSet++;
    }

    _totalDrawables++;
    osg::Geometry* geom;
    if (dynamic_cast<osgText::Text*>(draw) != NULL)
    {
        _texts++;
        osg::ref_ptr<osg::Object> rp = (osg::Object*)draw;
        _uTexts.insert(rp);
    }
    else if ((geom = dynamic_cast<osg::Geometry*>(draw)) != NULL)
    {
        _geometries++;
        osg::ref_ptr<osg::Object> rp = (osg::Object*)geom;
        _uGeometries.insert(rp);

        //if (!geom->areFastPathsUsed())
        //    _slowPathGeometries++;

        if(geom->getNumPrimitiveSets() > 0)
        {
            unsigned int idx;
            for(idx=0; idx < geom->getNumPrimitiveSets(); idx++)
            {
                osg::PrimitiveSet* ps = geom->getPrimitiveSet(idx);
                _vertices += ps->getNumIndices();
            }
        }
        else
            _nullGeometries++;
        osg::ref_ptr<osg::Object> rpv = (osg::Object*)(geom->getVertexArray());
        _uVertices.insert(rpv);

        if(geom->getNumPrimitiveSets() > 0)
        {
            _primitiveSets += geom->getNumPrimitiveSets();
            osg::Geometry::PrimitiveSetList& psl = geom->getPrimitiveSetList();
            osg::Geometry::PrimitiveSetList::const_iterator pslit;
            for(pslit = psl.begin(); pslit != psl.end(); ++pslit)
            {
                osg::ref_ptr<osg::Object> rpps = (osg::Object*)(pslit->get());
                _uPrimitiveSets.insert(rpps);
                const osg::DrawArrays* da = dynamic_cast< const osg::DrawArrays* >(pslit->get());
                if(da)
                {
                    _drawArrays++;
                    osg::ref_ptr<osg::Object> rpda = (osg::Object*)(da);
                    _uDrawArrays.insert(rpda);
                }
            }
        }
    }
    else
    {
        _drawables++;
        osg::ref_ptr<osg::Object> rp = (osg::Object*)draw;
        _uDrawables.insert(rp);
    }

    popStateSet();
}