Osg显示bool运算图形
利用Array的OsgModling中Boolean进行图形的bool运算
创建基本图形
osg::ref_ptr<osg::Geometry> CreateBox(const osg::Vec3& center,float lengthX,float lengthY, float lengthZ)//创建方体
{
float halflengthX = lengthX*0.5 ,halflengthY = lengthY*0.5 ,halflengthZ = lengthZ*0.5 ;
osg::ref_ptr<osg::Vec3Array> mPtTempArray = new osg::Vec3Array ;//顶点数组;
mPtTempArray->push_back(osg::Vec3(center.x() - halflengthX, center.y() - halflengthY, center.z() + halflengthZ));
mPtTempArray->push_back(osg::Vec3(center.x() + halflengthX, center.y() - halflengthY, center.z() + halflengthZ));
mPtTempArray->push_back(osg::Vec3(center.x() + halflengthX, center.y() + halflengthY, center.z() + halflengthZ));
mPtTempArray->push_back(osg::Vec3(center.x() - halflengthX, center.y() + halflengthY, center.z() + halflengthZ));
mPtTempArray->push_back(osg::Vec3(center.x() - halflengthX, center.y() - halflengthY, center.z() - halflengthZ));
mPtTempArray->push_back(osg::Vec3(center.x() + halflengthX, center.y() - halflengthY, center.z() - halflengthZ));
mPtTempArray->push_back(osg::Vec3(center.x() + halflengthX, center.y() + halflengthY, center.z() - halflengthZ));
mPtTempArray->push_back(osg::Vec3(center.x() - halflengthX, center.y() + halflengthY, center.z() - halflengthZ));
return CreatePolyMesh(mPtTempArray,2);
}
创建bool图形
osg::ref_ptr<osg::Geometry> Createboolean(osgModeling::BoolOperator::Method mMethod,osg::ref_ptr<osg::Geometry> mGeometry1,osg::ref_ptr<osg::Geometry> mGeometry2)
{
osg::ref_ptr<osgModeling::BoolOperator> mBoolOperator = new osgModeling::BoolOperator(mMethod);
osg::ref_ptr<osgModeling::Model> mModel1 = new osgModeling::Model(*mGeometry1);
osg::ref_ptr<osgModeling::Model> mModel2 = new osgModeling::Model(*mGeometry2);
mBoolOperator->setOperands(mModel1,mModel2);
osg::ref_ptr<osg::Geometry> mGeom = new osg::Geometry;
mBoolOperator->output(mGeom);
// A triangle strip generator should be used here, otherwise too many independent triangles may cause the graphics system crash.
osgUtil::TriStripVisitor tsv;
tsv.stripify( *mGeom );
return mGeom;
}
做1w次bool realese图形运算需时间50s
版权声明:本文为qq_31577553原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。