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

📄 convertfromperformer.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                geom->setNormalArray(osg_norms);                        }        }        else        {            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->setNormalBinding(_gsetBindMap[bind]);            // calc the maximum num of vertex from the index list.            int cc;            if (ilist)            {                cc = 0;                for( i = 0; i < nn; i++ )                    if( ilist[i] > cc ) cc = ilist[i];                cc++;            }            else                cc = nn;            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);                        if(ilist)            {                geom->setNormalIndices(new osg::UShortArray(nn,ilist));            }        }    }    pfVec4 *colors;    geoset->getAttrLists( PFGS_COLOR4,  (void **)&colors, &ilist );    // copy color coords    if(colors)    {        int bind = geoset->getAttrBind( PFGS_COLOR4 );        if (bind==PFGS_PER_VERTEX && flat_shaded_skip_all_primitives!=0)        {            // handle flat shaded skip of colours.            // handle flat shaded skip of normals.            int nn = nv-flat_shaded_skip_all_primitives;            // set the normal binding type.            geom->setColorBinding(_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::Vec4Array* osg_colors = new osg::Vec4Array(cc);                for( i = 0; i < cc; i++ )                {                    (*osg_colors)[i][0] = colors[i][0];                    (*osg_colors)[i][1] = colors[i][1];                    (*osg_colors)[i][2] = colors[i][2];                    (*osg_colors)[i][3] = colors[i][3];                }                geom->setColorArray(osg_colors);                            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->setColorIndices(osg_indices);                                            }            else            {                osg::Vec4Array* osg_colors = new osg::Vec4Array;                osg_colors->reserve(nv);                                int ni=0;                for( i = 0; i < np; ++i)                {                    for(int si=0;si<flat_shaded_skip_per_primitive;++si)                    {                        osg_colors->push_back(osg::Vec4(colors[ni][0],colors[ni][1],colors[ni][2],colors[ni][3]));                    }                    for( int pi=0; pi < plen[i]-flat_shaded_skip_per_primitive; ++pi)                    {                        osg_colors->push_back(osg::Vec4(colors[ni][0],colors[ni][1],colors[ni][2],colors[ni][3]));                        ni++;                    }                }                geom->setColorArray(osg_colors);                        }        }        else        {            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->setColorBinding(_gsetBindMap[bind]);            // calc the maximum num of vertex from the index list.            int cc;            if (ilist)            {                cc = 0;                for( i = 0; i < nn; i++ )                    if( ilist[i] > cc ) cc = ilist[i];                cc++;            }            else                cc = nn;            osg::Vec4Array* osg_colors = new osg::Vec4Array(cc);            for( i = 0; i < cc; i++ )            {                (*osg_colors)[i][0] = colors[i][0];                (*osg_colors)[i][1] = colors[i][1];                (*osg_colors)[i][2] = colors[i][2];                (*osg_colors)[i][3] = colors[i][3];            }            geom->setColorArray(osg_colors);            if(ilist)            {                geom->setColorIndices(new osg::UShortArray(nn,ilist));            }        }    }    else    {    }                    visitGeoState(geom,geoset->getGState());        if (flat_shaded_skip_per_primitive)    {        osg::StateSet* stateset = geom->getOrCreateStateSet();        osg::ShadeModel* shademodel = dynamic_cast<osg::ShadeModel*>(stateset->getAttribute(osg::StateAttribute::SHADEMODEL));        if (!shademodel)        {            shademodel = new osg::ShadeModel;            stateset->setAttribute(shademodel);        }        shademodel->setMode( osg::ShadeModel::FLAT );    }    osgGeode->addDrawable(geom);    registerPfObjectForOsgObject(geoset,geom);    return geom;}osg::StateSet* ConvertFromPerformer::visitGeoState(osg::Drawable* osgDrawable,pfGeoState* geostate){    if (geostate==NULL) return NULL;    osg::StateSet* osgStateSet = dynamic_cast<osg::StateSet*>(getOsgObject(geostate));    if (osgStateSet)    {        if (osgDrawable) osgDrawable->setStateSet(osgStateSet);        return osgStateSet;    }    osgStateSet = new osg::StateSet;    if (osgDrawable) osgDrawable->setStateSet(osgStateSet);    registerPfObjectForOsgObject(geostate,osgStateSet);    // Don could you fill in some of these blanks???    unsigned int inherit = geostate->getInherit();    //     osg::notify(DEBUG) << endl << "Inherit = "<<inherit<<std::endl;    //     if (inherit & PFSTATE_TRANSPARENCY) osg::notify(DEBUG) << "Inherit PFSTATE_TRANSPARENCY"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_TRANSPARENCY"<<std::endl;    //     if (inherit & PFSTATE_ENTEXTURE) osg::notify(DEBUG) << "Inherit PFSTATE_ENTEXTURE"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ENTEXTURE"<<std::endl;    //     if (inherit & PFSTATE_CULLFACE) osg::notify(DEBUG) << "Inherit PFSTATE_CULLFACE"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_CULLFACE"<<std::endl;    //     if (inherit & PFSTATE_ENLIGHTING) osg::notify(DEBUG) << "Inherit PFSTATE_ENLIGHTING"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ENLIGHTING"<<std::endl;    //     if (inherit & PFSTATE_ENFOG) osg::notify(DEBUG) << "Inherit PFSTATE_ENFOG"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ENFOG"<<std::endl;    //     if (inherit & PFSTATE_ENWIREFRAME) osg::notify(DEBUG) << "Inherit PFSTATE_ENWIREFRAME"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ENWIREFRAME"<<std::endl;    //     if (inherit & PFSTATE_ENTEXMAT) osg::notify(DEBUG) << "Inherit PFSTATE_ENTEXMAT"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ENTEXMAT"<<std::endl;    //     if (inherit & PFSTATE_ENTEXGEN) osg::notify(DEBUG) << "Inherit PFSTATE_ENTEXGEN"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ENTEXGEN"<<std::endl;    //    //     if (inherit & PFSTATE_ANTIALIAS) osg::notify(DEBUG) << "Inherit PFSTATE_ANTIALIAS"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ANTIALIAS"<<std::endl;    //     if (inherit & PFSTATE_DECAL) osg::notify(DEBUG) << "Inherit PFSTATE_DECAL"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_DECAL"<<std::endl;    //     if (inherit & PFSTATE_ALPHAFUNC) osg::notify(DEBUG) << "Inherit PFSTATE_ALPHAFUNC"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ALPHAFUNC"<<std::endl;    //     if (inherit & PFSTATE_ENCOLORTABLE) osg::notify(DEBUG) << "Inherit PFSTATE_ENCOLORTABLE"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ENCOLORTABLE"<<std::endl;    //     if (inherit & PFSTATE_ENHIGHLIGHTING) osg::notify(DEBUG) << "Inherit PFSTATE_ENHIGHLIGHTING"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ENHIGHLIGHTING"<<std::endl;    //     if (inherit & PFSTATE_ENLPOINTSTATE) osg::notify(DEBUG) << "Inherit PFSTATE_ENLPOINTSTATE"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ENLPOINTSTATE"<<std::endl;    //     if (inherit & PFSTATE_ENTEXLOD) osg::notify(DEBUG) << "Inherit PFSTATE_ENTEXLOD"<<std::endl;    //     else osg::notify(DEBUG) << "Define PFSTATE_ENTEXLOD"<<std::endl;    if (!(inherit & PFSTATE_ALPHAFUNC)) {        int mode = geostate->getMode(PFSTATE_ALPHAFUNC);        float value = geostate->getVal(PFSTATE_ALPHAREF);        osg::AlphaFunc* aFunc = new osg::AlphaFunc();        switch (mode) {            case PFAF_ALWAYS:                aFunc->setFunction(osg::AlphaFunc::ALWAYS); //==PFAF_OFF in performer 311                break;            case PFAF_EQUAL:                aFunc->setFunction(osg::AlphaFunc::EQUAL);                break;            case PFAF_GEQUAL:                aFunc->setFunction(osg::AlphaFunc::GEQUAL);                break;            case PFAF_GREATER:                aFunc->setFunction(osg::AlphaFunc::GREATER);                break;            case PFAF_LEQUAL:                aFunc->setFunction(osg::AlphaFunc::LEQUAL);                break;            case PFAF_LESS:                aFunc->setFunction(osg::AlphaFunc::LESS);                break;            case PFAF_NEVER:                aFunc->setFunction(osg::AlphaFunc::NEVER);                break;            case PFAF_NOTEQUAL:                aFunc->setFunction(osg::AlphaFunc::NOTEQUAL);                break;//            case PFAF_OFF: //==PFAF_ALWAYS//                break;            default: //warn PFAF not recognized?                break;        }        aFunc->setReferenceValue(value);        if (mode != PFAF_OFF) {            osgStateSet->setAttributeAndModes(aFunc);        } else {            osgStateSet->setAttributeAndModes(aFunc,osg::StateAttribute::OFF);        }    }    if (inherit & PFSTATE_TRANSPARENCY) osgStateSet->setMode(GL_BLEND,osg::StateAttribute::INHERIT);    else    {        int mode = geostate->getMode(PFSTATE_TRANSPARENCY);        if (mode & PFTR_NO_OCCLUDE) {            mode &= ~PFTR_NO_OCCLUDE;//remove NO_OCCLUDE bit            osg::Depth* depth = new osg::Depth(osg::Depth::LESS,0.0f,1.0f,false);            osgStateSet->setAttributeAndModes(depth);        }        switch(mode)        {            case(PFTR_FAST):            case(PFTR_HIGH_QUALITY):            case(PFTR_BLEND_ALPHA):            case(PFTR_MS_ALPHA):            case(PFTR_MS_ALPHA_MASK)://            case(PFTR_NO_OCCLUDE): //this is a bit flag.            case(PFTR_ON):                osgStateSet->setMode(GL_BLEND,osg::StateAttribute::ON);                osgStateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);                break;            case(PFTR_OFF): osgStateSet->setMode(GL_BLEND,osg::StateAttribute::OFF);break;            default:        osgStateSet->setMode(GL_BLEND,osg::StateAttribute::INHERIT);break;        }    }    if (inherit & PFSTATE_ENTEXTURE) osgStateSet->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::INHERIT);    else    {        int mode = geostate->getMode(PFSTATE_ENTEXTURE);        switch(mode)        {            case(PF_ON):    osgStateSet->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::ON);break;            case(PF_OFF):            default:        osgStateSet->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OFF);break;        }    }    if (inherit & PFSTATE_CULLFACE) osgStateSet->setMode(GL_CULL_FACE,osg::StateAttribute::INHERIT);    else    {        int mode = geostate->getMode(PFSTATE_CULLFACE);        switch(mode)        {            case(PFCF_BACK):            {                osgStateSet->setMode(GL_CULL_FACE,osg::StateAttribute::ON);                osg::CullFace *cf = new osg::CullFace;                cf->setMode(osg::CullFace::BACK);                osgStateSet->setAttribute(cf);            }            break;            case(PFCF_FRONT):            {                osgStateSet->setMode(GL_CULL_FACE,osg::StateAttribute::ON);                osg::CullFace *cf = new osg::CullFace;                cf->setMode(osg::CullFace::FRONT);                osgStateSet->setAttribute(cf);            }            break;            case(PFCF_BOTH):            {                osgStateSet->setMode(GL_CULL_FACE,osg::StateAttribute::ON);                osg::CullFace *cf = new osg::CullFace;                cf->setMode(osg::CullFace::FRONT_AND_BACK);                osgStateSet->setAttribute(cf);            }            break;            case(PFCF_OFF):            default:        osgStateSet->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);break;        }    }    if (inherit & PFSTATE_ENLIGHTING) osgStateSet->setMode(GL_LIGHTING,osg::StateAttribute::INHERIT);    else    {        int mode = geostate->getMode(PFSTATE_ENLIGHTING);        switch(mode)        {            case(PF_ON):    osgStateSet->setMode(GL_LIGHTING,osg::StateAttribute::ON);break;            case(PF_OFF):            default:        osgStateSet->setMode(GL_LIGHTING,osg::StateAttribute::OFF);break;        }    }    if (inherit & PFSTATE_ENFOG) osgStateSet->setMode(GL_FOG,osg::StateAttribute::INHERIT);    else    {        int mode = geostate->getMode(PFSTATE_ENFOG);        switch(mode)        {            case(PF_ON):    osgStateSet->setMode(GL_FOG,osg::StateAttribute::ON);break;            case(PF_OFF):            default:        osgStateSet->setMode(GL_FOG,osg::StateAttribute::OFF);break;        }    }    // not currently supported by OSG    //     if (inherit & PFSTATE_ENWIREFRAME)  osgStateSet->setMode(osg::StateSet::WIREFRAME,osg::StateAttribute::INHERIT);    //     else    //     {    //         int mode = geostate->getMode(PFSTATE_ENWIREFRAME);    //         switch(mode)    //         {    //         case(PF_ON):    osgStateSet->setMode(osg::StateSet::WIREFRAME,osg::StateAttribute::ON);break;

⌨️ 快捷键说明

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