📄 daewgeometry.cpp
字号:
polylist->getVcount()->getValue().append( primLength ); p.push_back(polylist->getP()); polylist->setCount( polylist->getCount() + nbPolygons ); } break; } } unsigned int primCount = 0; osg::DrawElementsUShort::iterator primItrBegin = drawElements->begin(); unsigned int nbVerticesPerPoly= drawElements->size()/p.size(); osg::DrawElementsUShort::iterator primItrEnd=primItrBegin+nbVerticesPerPoly; for( unsigned int iPoly = 0; iPoly < p.size(); ++iPoly ) { for( osg::DrawElementsUShort::iterator primItr = primItrBegin;primItr != primItrEnd; ++primCount, ++primItr ) { unsigned int vindex = *primItr; appendGeometryIndices(geom,p[iPoly],vindex, norm,color, verts,normals,colors,texcoords, ncount,ccount); if ( primCount % primLength == 0 ) { if ( geom->getNormalBinding() == osg::Geometry::BIND_PER_PRIMITIVE ) { ncount++; } if ( geom->getColorBinding() == osg::Geometry::BIND_PER_PRIMITIVE ) { ccount++; } } } primItrBegin+=nbVerticesPerPoly;#if ( _SECURE_SCL == 1 ) if (primItrBegin != drawElements->end())#endif primItrEnd+=nbVerticesPerPoly; } break; } case osg::PrimitiveSet::DrawElementsUIntPrimitiveType: { //osg::notify( osg::WARN ) << "DrawElementsUInt" << std::endl; if ( primLength == 0 ) primLength = ps->getNumIndices(); osg::DrawElementsUInt* drawElements = static_cast<osg::DrawElementsUInt*>( ps ); std::vector<domP *> p; switch ( mode ) { case GL_LINES: { p.push_back(lines->getP()); lines->setCount( lines->getCount() + drawElements->size()/primLength ); break; } case GL_TRIANGLES: { p.push_back(tris->getP()); tris->setCount( tris->getCount() + drawElements->size()/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: { unsigned int nbPolygons=drawElements->size()/primLength; if (usePolygons) { //for( unsigned int idx = 0; idx < nbPolygons; ++idx ) /*idx*/ //huh ? why only one ? p.push_back(polys->getP_array()[0]); polys->setCount( polys->getCount() + nbPolygons ); } else { polylist->getVcount()->getValue().append( primLength ); p.push_back(polylist->getP()); polylist->setCount( polylist->getCount() + nbPolygons ); } break; } } unsigned int primCount = 0; osg::DrawElementsUInt::iterator primItrBegin = drawElements->begin(); unsigned int nbVerticesPerPoly= drawElements->size()/p.size(); osg::DrawElementsUInt::iterator primItrEnd=primItrBegin+nbVerticesPerPoly; for( unsigned int iPoly = 0; iPoly < p.size(); ++iPoly ) { for( osg::DrawElementsUInt::iterator primItr = primItrBegin;primItr != primItrEnd; ++primCount, ++primItr ) { unsigned int vindex = *primItr; appendGeometryIndices(geom,p[iPoly],vindex, norm,color, verts,normals,colors,texcoords, ncount,ccount); if ( primCount % primLength == 0 ) { if ( geom->getNormalBinding() == osg::Geometry::BIND_PER_PRIMITIVE ) { ncount++; } if ( geom->getColorBinding() == osg::Geometry::BIND_PER_PRIMITIVE ) { ccount++; } } } primItrBegin+=nbVerticesPerPoly;#if ( _SECURE_SCL == 1 ) if (primItrBegin != drawElements->end())#endif primItrEnd+=nbVerticesPerPoly; } break; } default: osg::notify( osg::WARN ) << "Unsupported primitiveSet" << std::endl; break; } if ( geom->getNormalBinding() == osg::Geometry::BIND_PER_PRIMITIVE_SET ) { ncount++; } if ( geom->getColorBinding() == osg::Geometry::BIND_PER_PRIMITIVE_SET ) { ccount++; } } return valid;}domSource *daeWriter::createSource( daeElement *parent, const std::string &baseName, int size, bool color, bool uv ){ domSource *src = daeSafeCast< domSource >( parent->createAndPlace( COLLADA_ELEMENT_SOURCE ) ); if ( src == NULL ) { return NULL; } src->setId( baseName.c_str() ); domFloat_array *fa = daeSafeCast< domFloat_array >( src->createAndPlace( COLLADA_ELEMENT_FLOAT_ARRAY ) ); std::string fName = baseName + "-array"; fa->setId( fName.c_str() ); domSource::domTechnique_common *teq = daeSafeCast< domSource::domTechnique_common >( src->createAndPlace( "technique_common" ) ); domAccessor *acc = daeSafeCast< domAccessor >( teq->createAndPlace( COLLADA_ELEMENT_ACCESSOR ) ); std::string url = "#" + fName; acc->setSource( url.c_str() ); domParam *param; if ( color ) { acc->setStride( size ); param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); param->setName( "R" ); param->setType( "float" ); param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); param->setName( "G" ); param->setType( "float" ); param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); param->setName( "B" ); param->setType( "float" ); if ( size == 4 ) { param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); param->setName( "A" ); param->setType( "float" ); } } else if ( uv ) { acc->setStride( size ); param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); param->setName( "S" ); param->setType( "float" ); param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); param->setName( "T" ); param->setType( "float" ); if ( size >=3 ) { param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); param->setName( "P" ); param->setType( "float" ); } } else { acc->setStride( size ); param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); param->setName( "X" ); param->setType( "float" ); param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); param->setName( "Y" ); param->setType( "float" ); if ( size >=3 ) { param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); param->setName( "Z" ); param->setType( "float" ); if ( size == 4 ) { param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); param->setName( "W" ); param->setType( "float" ); } } } return src;}template < typename Ty >Ty *daeWriter::createPrimGroup( daeString type, domMesh *mesh, domSource *norm, domSource *color, const std::vector< domSource* > &texcoord ){ unsigned int offset = 0; Ty *retVal = daeSafeCast< Ty >( mesh->createAndPlace( type ) ); domInputLocalOffset *ilo = daeSafeCast< domInputLocalOffset >( retVal->createAndPlace( "input" ) ); ilo->setOffset( offset++ ); ilo->setSemantic( "VERTEX" ); std::string url = "#" + std::string(mesh->getVertices()->getId()); ilo->setSource( url.c_str() ); if ( norm != NULL ) { ilo = daeSafeCast< domInputLocalOffset >( retVal->createAndPlace( "input" ) ); ilo->setOffset( offset++ ); ilo->setSemantic( "NORMAL" ); url = "#" + std::string( norm->getId() ); ilo->setSource( url.c_str() ); } if ( color != NULL ) { ilo = daeSafeCast< domInputLocalOffset >( retVal->createAndPlace( "input" ) ); ilo->setOffset( offset++ ); ilo->setSemantic( "COLOR" ); url = "#" + std::string( color->getId() ); ilo->setSource( url.c_str() ); } for ( unsigned int i = 0; i < texcoord.size(); i++ ) { ilo = daeSafeCast< domInputLocalOffset >( retVal->createAndPlace( "input" ) ); ilo->setOffset( offset++ ); ilo->setSemantic( "TEXCOORD" ); ilo->setSet( i ); url = "#" + std::string( texcoord[i]->getId() ); ilo->setSource( url.c_str() ); } return retVal;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -