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

📄 daewgeometry.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        case ArrayNIndices::VEC3:            color->getFloat_array()->setCount( colors.vec3->size() *3 );            color->getTechnique_common()->getAccessor()->setCount( colors.vec3->size() );            for ( unsigned int i = 0; i < colors.vec3->size(); i++ )            {                color->getFloat_array()->getValue().append( (*colors.vec3)[i].x() );                color->getFloat_array()->getValue().append( (*colors.vec3)[i].y() );                color->getFloat_array()->getValue().append( (*colors.vec3)[i].z() );            }            break;        case ArrayNIndices::VEC4:            color->getFloat_array()->setCount( colors.vec4->size() *4 );            color->getTechnique_common()->getAccessor()->setCount( colors.vec4->size() );            for ( unsigned int i = 0; i < colors.vec4->size(); i++ )            {                color->getFloat_array()->getValue().append( (*colors.vec4)[i].r() );                color->getFloat_array()->getValue().append( (*colors.vec4)[i].g() );                color->getFloat_array()->getValue().append( (*colors.vec4)[i].b() );                color->getFloat_array()->getValue().append( (*colors.vec4)[i].a() );            }            break;        default:            osg::notify( osg::WARN ) << "Invalid array type for colors" << std::endl;            break;        }        //if COLOR shares same indices as POSITION put it in the vertices        /*if ( colorInds == vertInds && vertInds != NULL ) {            il = daeSafeCast< domInputLocal >( vertices->createAndPlace( "input" ) );            il->setSemantic( "COLOR" );            url = "#" + std::string(md->color->getId());            il->setSource( url.c_str() );        }*/    }    //process TEXCOORD    //TODO: Do the same as normal and colors for texcoods. But in a loop since you can have many    for ( unsigned int ti = 0; ti < texcoords.size(); ti++ )    {        std::ostringstream intstr;        intstr << std::dec << ti;        sName = name + "-texcoord_" + intstr.str();        domSource *t = createSource( mesh, sName, texcoords[ti].mode, false, true );        switch( texcoords[ti].mode )        {        case ArrayNIndices::VEC2:            t->getFloat_array()->setCount( texcoords[ti].vec2->size() *2 );            t->getTechnique_common()->getAccessor()->setCount( texcoords[ti].vec2->size() );            for ( unsigned int i = 0; i < texcoords[ti].vec2->size(); i++ )            {                t->getFloat_array()->getValue().append( (*texcoords[ti].vec2)[i].x() );                t->getFloat_array()->getValue().append( (*texcoords[ti].vec2)[i].y() );            }            break;        case ArrayNIndices::VEC3:            t->getFloat_array()->setCount( texcoords[ti].vec3->size() *3 );            t->getTechnique_common()->getAccessor()->setCount( texcoords[ti].vec3->size() );            for ( unsigned int i = 0; i < texcoords[ti].vec3->size(); i++ )            {                t->getFloat_array()->getValue().append( (*texcoords[ti].vec3)[i].x() );                t->getFloat_array()->getValue().append( (*texcoords[ti].vec3)[i].y() );                t->getFloat_array()->getValue().append( (*texcoords[ti].vec3)[i].z() );            }            break;        case ArrayNIndices::VEC4:            t->getFloat_array()->setCount( texcoords[ti].vec4->size() *4 );            t->getTechnique_common()->getAccessor()->setCount( texcoords[ti].vec4->size() );            for ( unsigned int i = 0; i < texcoords[ti].vec4->size(); i++ )            {                t->getFloat_array()->getValue().append( (*texcoords[i].vec4)[ti].x() );                t->getFloat_array()->getValue().append( (*texcoords[i].vec4)[ti].y() );                t->getFloat_array()->getValue().append( (*texcoords[i].vec4)[ti].z() );                t->getFloat_array()->getValue().append( (*texcoords[i].vec4)[ti].w() );            }            break;        default:          //##ti and not i            osg::notify( osg::WARN ) << "Invalid array type for texcoord" << ti << std::endl;            break;        }        texcoord.push_back( t );    }    //process each primitive group    unsigned int ncount = 0; //Normal index counter    unsigned int ccount = 0; //Color index counter    if ( geom->getNumPrimitiveSets() == 0 )    {        osg::notify( osg::WARN ) << "NO PRIMITIVE SET!!" << std::endl;        return false;    }    bool valid = false;    //for each primitive group    for ( unsigned int i = 0; i < geom->getNumPrimitiveSets(); i++ )    {        osg::PrimitiveSet *ps = geom->getPrimitiveSet( i );        GLenum mode = ps->getMode();        unsigned int primLength;        //unsigned int offset = 0;        //domInputLocalOffset *ilo = NULL;        //process primitive group        switch( mode )        {            case GL_POINTS:                {                osg::notify( osg::WARN ) << "Geometry contains points rendering. COLLADA does not" << std::endl;                 continue;            }            case GL_LINES:                 {                if ( lines == NULL )                {                    lines = createPrimGroup<domLines>( COLLADA_ELEMENT_LINES, mesh, norm, color, texcoord );                    lines->createAndPlace( COLLADA_ELEMENT_P );                    std::string mat = name + "_material";                    lines->setMaterial( mat.c_str() );                }                primLength = 2;                 valid = true;                break;            }            case GL_TRIANGLES:             {                if ( tris == NULL )                {                    tris = createPrimGroup<domTriangles>( COLLADA_ELEMENT_TRIANGLES, mesh, norm, color, texcoord );                    tris->createAndPlace( COLLADA_ELEMENT_P );                    std::string mat = name + "_material";                    tris->setMaterial( mat.c_str() );                }                primLength = 3;                 valid = true;                break;            }            case GL_QUADS:                 {                if ( polys == NULL )                {                    if (usePolygons)                    {                          polys = createPrimGroup<domPolygons>( COLLADA_ELEMENT_POLYGONS, mesh, norm, color, texcoord );                          polys->createAndPlace( COLLADA_ELEMENT_P );                          std::string mat = name + "_material";                          polys->setMaterial( mat.c_str() );                    }                    else                    {                          polylist = createPrimGroup<domPolylist>( COLLADA_ELEMENT_POLYLIST, mesh, norm, color, texcoord );                                                      polylist->createAndPlace( COLLADA_ELEMENT_VCOUNT );                          polylist->createAndPlace( COLLADA_ELEMENT_P );                          std::string mat = name + "_material";                          polylist->setMaterial( mat.c_str() );                    }                }                primLength = 4;                 valid = true;                break;            }            case GL_LINE_STRIP:            {                if ( linestrips == NULL )                {                    linestrips = createPrimGroup<domLinestrips>( COLLADA_ELEMENT_LINESTRIPS, mesh, norm, color, texcoord );                    std::string mat = name + "_material";                    linestrips->setMaterial( mat.c_str() );                }                primLength = 0;                valid = true;                break;            }            case GL_TRIANGLE_STRIP:            {                if ( tristrips == NULL )                {                    tristrips = createPrimGroup<domTristrips>( COLLADA_ELEMENT_TRISTRIPS, mesh, norm, color, texcoord );                    std::string mat = name + "_material";                    tristrips->setMaterial( mat.c_str() );                }                primLength = 0;                valid = true;                break;            }            case GL_TRIANGLE_FAN:            {                if ( trifans == NULL )                {                    trifans = createPrimGroup<domTrifans>( COLLADA_ELEMENT_TRIFANS, mesh, norm, color, texcoord );                    std::string mat = name + "_material";                    trifans->setMaterial( mat.c_str() );                }                primLength = 0;                valid = true;                break;            }            default:                       {                if ( polys == NULL )                {                    if (usePolygons)                    {                        polys = createPrimGroup<domPolygons>( COLLADA_ELEMENT_POLYGONS, mesh, norm, color, texcoord );                        polys->createAndPlace( COLLADA_ELEMENT_P );                        std::string mat = name + "_material";                        polys->setMaterial( mat.c_str() );                    }                    else                    {                        polylist = createPrimGroup<domPolylist>( COLLADA_ELEMENT_POLYLIST, mesh, norm, color, texcoord );                        polylist->createAndPlace( COLLADA_ELEMENT_VCOUNT );                        polylist->createAndPlace( COLLADA_ELEMENT_P );                        std::string mat = name + "_material";                        polylist->setMaterial( mat.c_str() );                    }                }                primLength = 0;                 valid = true;                break; // compute later when =0.            }        }                //process upon primitive set type                // 1- set data source,accumulate count of primitives and write it to file                // 2- read data source for primitive set and write it to file        switch( ps->getType() )        {                //draw arrays (array of contiguous vertices)                           //(primitive type+begin+end),(primitive type+begin+end)...            case osg::PrimitiveSet::DrawArraysPrimitiveType:            {                //osg::notify( osg::WARN ) << "DrawArrays" << std::endl;                if ( primLength == 0 )                 {                    primLength = ps->getNumIndices();                }                osg::DrawArrays* drawArray = static_cast< osg::DrawArrays* >( ps );                unsigned int vcount = 0;                unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();                std::vector<domP *> p;                switch ( mode )                {                    case GL_LINES:                    {                                                p.push_back(lines->getP());                        lines->setCount( lines->getCount() + drawArray->getCount()/primLength );                        break;                    }                    case GL_TRIANGLES:                    {                                                p.push_back(tris->getP());                        tris->setCount( tris->getCount() + drawArray->getCount()/primLength );                        break;                    }                    case GL_LINE_STRIP:                    {                                                p.push_back(daeSafeCast<domP>( linestrips->createAndPlace( COLLADA_ELEMENT_P ) ));                        linestrips->setCount( linestrips->getCount() + 1 );                        break;                    }                    case GL_TRIANGLE_STRIP:                    {                                                p.push_back(daeSafeCast<domP>( tristrips->createAndPlace( COLLADA_ELEMENT_P ) ));                        tristrips->setCount( tristrips->getCount() + 1 );                        break;                    }                    case GL_TRIANGLE_FAN:                    {                                                p.push_back(daeSafeCast<domP>( trifans->createAndPlace( COLLADA_ELEMENT_P ) ));                        trifans->setCount( trifans->getCount() + 1 );                        break;                    }                    default:                               {                        //TODO : test this case                        unsigned int nbPolygons=drawArray->getCount()/primLength;                        if (usePolygons)                        {                            //for( unsigned int idx = 0; idx < nbPolygons; ++idx )                            p.push_back(polys->getP_array()[0]);                            polys->setCount( polys->getCount() + nbPolygons );                        }                        else                        {                            for( unsigned int idx = 0; idx < nbPolygons; ++idx )                                    polylist->getVcount()->getValue().append( primLength );                            p.push_back(polylist->getP());

⌨️ 快捷键说明

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