⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convertfromperformer.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    if (name) osgTransform->setName(name);    pfMatrix matrix;    scs->getMat(matrix);    osg::Matrix osgMatrix(matrix[0][0],matrix[0][1],matrix[0][2],matrix[0][3],        matrix[1][0],matrix[1][1],matrix[1][2],matrix[1][3],        matrix[2][0],matrix[2][1],matrix[2][2],matrix[2][3],        matrix[3][0],matrix[3][1],matrix[3][2],matrix[3][3]);    osgTransform->setMatrix(osgMatrix);    for(int i=0;i<scs->getNumChildren();++i)    {        visitNode(osgTransform,scs->getChild(i));    }    return (osg::Node*)osgTransform;}osg::Node* ConvertFromPerformer::visitGeode(osg::Group* osgParent,pfGeode* geode){    osg::Geode* osgGeode = dynamic_cast<osg::Geode*>(getOsgObject(geode));    if (osgGeode)    {        if (osgParent) osgParent->addChild(osgGeode);        return osgGeode;    }    osgGeode = new osg::Geode;    if (osgParent) osgParent->addChild(osgGeode);    registerPfObjectForOsgObject(geode,osgGeode);    const char* name = geode->getName();    if (name) osgGeode->setName(name);    for(int i=0;i<geode->getNumGSets();++i)    {        visitGeoSet(osgGeode,geode->getGSet(i));    }    return (osg::Node*)osgGeode;}osg::Node* ConvertFromPerformer::visitBillboard(osg::Group* osgParent,pfBillboard* billboard){    //    return NULL;    osg::Billboard* osgBillboard = dynamic_cast<osg::Billboard*>(getOsgObject(billboard));    if (osgBillboard)    {        if (osgParent) osgParent->addChild(osgBillboard);        return osgBillboard;    }    osgBillboard = new osg::Billboard;    if (osgParent) osgParent->addChild(osgBillboard);    registerPfObjectForOsgObject(billboard,osgBillboard);    const char* name = billboard->getName();    if (name) osgBillboard->setName(name);    pfVec3 axis;    billboard->getAxis(axis);    osgBillboard->setAxis(osg::Vec3(axis[0],axis[1],axis[2]));    switch( billboard->getMode( PFBB_ROT ) )    {    case PFBB_AXIAL_ROT:       osgBillboard->setMode( osg::Billboard::AXIAL_ROT );       break;    case PFBB_POINT_ROT_EYE:       osgBillboard->setMode( osg::Billboard::POINT_ROT_EYE );       break;    case PFBB_POINT_ROT_WORLD:       osgBillboard->setMode( osg::Billboard::POINT_ROT_WORLD );       break;    }    for(int i=0;i<billboard->getNumGSets();++i)    {                                 /* osg::GeoSet* osggset = */        visitGeoSet(osgBillboard,billboard->getGSet(i));        pfVec3 pos;        billboard->getPos(i,pos);        osgBillboard->setPosition(i,osg::Vec3(pos[0],pos[1],pos[2]));    }    return (osg::Node*)osgBillboard;}int ConvertFromPerformer::getNumVerts(pfGeoSet *gset){    int nv;    int np;    int *lens;    int i;    np = gset->getNumPrims();    nv = 0;    switch( gset->getPrimType() )    {        case PFGS_POINTS :            nv = np;            break;        case PFGS_LINES :            nv = 2 * np;            break;        case PFGS_TRIS :            nv = 3 * np;            break;        case PFGS_QUADS :            nv = 4 * np;            break;        case PFGS_TRISTRIPS :        case PFGS_TRIFANS :        case PFGS_FLAT_TRISTRIPS :        case PFGS_POLYS :        case PFGS_LINESTRIPS :        case PFGS_FLAT_LINESTRIPS :            lens = gset->getPrimLengths();            for( i = 0; i < np; i++ )                nv += lens[i];            break;    }    return nv;}osg::Drawable* ConvertFromPerformer::visitGeoSet(osg::Geode* osgGeode,pfGeoSet* geoset){    if (geoset==NULL) return NULL;    osg::Drawable* osgDrawable = dynamic_cast<osg::Drawable*>(getOsgObject(geoset));    if (osgDrawable)    {        if (osgGeode) osgGeode->addDrawable(osgDrawable);        return osgDrawable;    }    // we'll make it easy to convert by using the Performer style osg::GeoSet,    // and then convert back to a osg::Geometry afterwards.    //osg::ref_ptr<osg::GeoSet> geom = new osg::GeoSet;    osg::Geometry* geom = new osg::Geometry;    int i;    // number of prims    int np = geoset->getNumPrims();    int *plen = geoset->getPrimLengths();    // Number of verticies (may be different than number of coords)    int nv = getNumVerts( geoset );    int prim = geoset->getPrimType();    int flat_shaded_skip_per_primitive=0;    if (prim == PFGS_FLAT_LINESTRIPS)       flat_shaded_skip_per_primitive=1;    else if (prim == PFGS_FLAT_TRISTRIPS)   flat_shaded_skip_per_primitive=2;    else if (prim == PFGS_FLAT_TRIFANS)     flat_shaded_skip_per_primitive=2;    int flat_shaded_skip_all_primitives=flat_shaded_skip_per_primitive*np;    // create the primitive sets.    switch( geoset->getPrimType() )    {        case PFGS_POINTS :            geom->addPrimitiveSet(new osg::DrawArrays(GL_POINTS,0,np));            break;        case PFGS_LINES :            geom->addPrimitiveSet(new osg::DrawArrays(GL_LINES,0,2*np));            break;        case PFGS_TRIS :            geom->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLES,0,3*np));            break;        case PFGS_QUADS :            geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4*np));            break;        case PFGS_TRISTRIPS :            geom->addPrimitiveSet(new osg::DrawArrayLengths(GL_TRIANGLE_STRIP,0,np,plen));            break;                    case PFGS_TRIFANS :            geom->addPrimitiveSet(new osg::DrawArrayLengths(GL_TRIANGLE_FAN,0,np,plen));            break;        case PFGS_FLAT_TRISTRIPS :            geom->addPrimitiveSet(new osg::DrawArrayLengths(GL_TRIANGLE_STRIP,0,np,plen));            break;                    case PFGS_POLYS :            geom->addPrimitiveSet(new osg::DrawArrayLengths(GL_POLYGON,0,np,plen));            break;                    case PFGS_LINESTRIPS :            geom->addPrimitiveSet(new osg::DrawArrayLengths(GL_LINE_STRIP,0,np,plen));            break;        case PFGS_FLAT_LINESTRIPS :            geom->addPrimitiveSet(new osg::DrawArrayLengths(GL_LINE_STRIP,0,np,plen));            break;        default:           osg::notify(osg::INFO) << "ConvertFromPerformer::visitGeoSet: Osg can't convert primitive "                     << geoset->getPrimType()                     << std::endl;            break;    }    pfVec3 *coords;    ushort *ilist;    geoset->getAttrLists( PFGS_COORD3,  (void **)&coords, &ilist );    // copy the vertex coordinates across.    if( coords )    {        // calc the maximum num of vertex from the index list.        int cc;        if (ilist)        {            cc = 0;            for( i = 0; i < nv; i++ )                if( ilist[i] > cc ) cc = ilist[i];            cc++;        }        else            cc = nv;        osg::Vec3Array* osg_coords = new osg::Vec3Array(cc);        for( i = 0; i < cc; i++ )        {            (*osg_coords)[i][0] = coords[i][0];            (*osg_coords)[i][1] = coords[i][1];            (*osg_coords)[i][2] = coords[i][2];        }                geom->setVertexArray(osg_coords);        if(ilist)        {            geom->setVertexIndices(new osg::UShortArray(nv,ilist));        }    }    pfVec2 *tcoords;    geoset->getAttrLists( PFGS_TEXCOORD2,  (void **)&tcoords, &ilist );    // copy texture coords    if(tcoords)    {        int bind = geoset->getAttrBind( PFGS_TEXCOORD2 );                        if (bind==PFGS_PER_VERTEX && bind != PFGS_OFF)        {            int nn = bind == PFGS_OFF ? 0 :                     bind == PFGS_OVERALL ? 1 :                     bind == PFGS_PER_PRIM ? geoset->getNumPrims() :                     bind == PFGS_PER_VERTEX ? nv : 0;            // set the normal binding type.            //geom->setTextureBinding(_gsetBindMap[bind]);            // calc the maximum num of vertex from the index list.            int cc;            if (ilist)            {                cc = 0;                for( i = 0; i < nv; i++ )                    if( ilist[i] > cc ) cc = ilist[i];                cc++;            }            else                cc = nn;            osg::Vec2Array* osg_tcoords = new osg::Vec2Array(cc);            for( i = 0; i < cc; i++ )            {                (*osg_tcoords)[i][0] = tcoords[i][0];                (*osg_tcoords)[i][1] = tcoords[i][1];            }            geom->setTexCoordArray(0,osg_tcoords);            if(ilist)            {                geom->setTexCoordIndices(0,new osg::UShortArray(nn,ilist));            }        }        else        {            osg::notify(osg::INFO)<<"OSG can't handle non PER_VERTEX tex coord binding at present"<<std::endl;        }    }    pfVec3 *norms;    geoset->getAttrLists( PFGS_NORMAL3,  (void **)&norms, &ilist );    // copy normals    if(norms)    {        int bind = geoset->getAttrBind( PFGS_NORMAL3 );        if (bind==PFGS_PER_VERTEX && flat_shaded_skip_all_primitives!=0)        {            // handle flat shaded skip of normals.            int nn = nv-flat_shaded_skip_all_primitives;            // set the normal binding type.            geom->setNormalBinding(_gsetBindMap[bind]);            if (ilist)            {                // calc the maximum num of vertex from the index list.                int cc = 0;                for( i = 0; i < nn; i++ )                    if( ilist[i] > cc ) cc = ilist[i];                cc++;                // straight forward mapping of normals across.                                osg::Vec3Array* osg_norms = new osg::Vec3Array(cc);                for( i = 0; i < cc; i++ )                {                    (*osg_norms)[i][0] = norms[i][0];                    (*osg_norms)[i][1] = norms[i][1];                    (*osg_norms)[i][2] = norms[i][2];                }                geom->setNormalArray(osg_norms);                            osg::UShortArray* osg_indices = new osg::UShortArray;                osg_indices->reserve(nv);                                int ni=0;                for( i = 0; i < np; ++i)                {                    for(int si=0;si<flat_shaded_skip_per_primitive;++si)                    {                        osg_indices->push_back(ilist[ni]);                    }                    for( int pi=0; pi < plen[i]-flat_shaded_skip_per_primitive; ++pi)                    {                        osg_indices->push_back(ilist[ni++]);                    }                }                                if (ni!=nn)                 {                    osg::notify(osg::INFO) << "1 ni!=nn"<<std::endl;                }                                geom->setNormalIndices(osg_indices);                                            }            else            {                osg::Vec3Array* osg_norms = new osg::Vec3Array;                osg_norms->reserve(nv);                                int ni=0;                for( i = 0; i < np; ++i)                {                    for(int si=0;si<flat_shaded_skip_per_primitive;++si)                    {                        osg_norms->push_back(osg::Vec3(norms[ni][0],norms[ni][1],norms[ni][2]));                    }                    for( int pi=0; pi < plen[i]-flat_shaded_skip_per_primitive; ++pi)                    {                        osg_norms->push_back(osg::Vec3(norms[ni][0],norms[ni][1],norms[ni][2]));                        ni++;                    }                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -