查看: 976|回复: 2

如何将地球模型某个节点挖方一个长方形呀?

[复制链接]

该用户从未签到

发表于 2014-8-29 14:37:41 | 显示全部楼层 |阅读模式


  1.         stencil = new osg::Stencil;
  2.         stencil->setFunction(osg::Stencil::NOTEQUAL, 1, 1);
  3.         m_Earth->getOrCreateStateSet()->setAttributeAndModes(stencil, osg::StateAttribute::ON);        //不行呀
复制代码

该用户从未签到

发表于 2014-8-29 19:08:03 | 显示全部楼层
融合,并调整渲染级别

该用户从未签到

 楼主| 发表于 2014-8-30 10:27:33 | 显示全部楼层
本帖最后由 颂鼎 于 2014-8-30 10:30 编辑
cenfer 发表于 2014-8-29 19:08
融合,并调整渲染级别


下面实现哪里不对呀,咋没效果呢???

  1.         osg::ref_ptr<osg::Geode> m_clipPlane = new osg::Geode;
  2.         (主节点)m_Group->addChild(m_clipPlane);
  3.         osg::ref_ptr<osg::Geometry> top_cap = new osg::Geometry;
  4.         m_clipPlane->addDrawable(top_cap);
  5.         top_cap->setVertexArray(pts);

  6.         osg::Vec4Array* colors = new osg::Vec4Array;
  7.         colors->push_back(osg::Vec4(1,0,0,1));
  8.         top_cap->setColorArray(colors);
  9.         top_cap->setColorBinding(osg::Geometry::BIND_OVERALL);

  10.         top_cap->addPrimitiveSet( new osg::DrawArrays(
  11.                 osg::PrimitiveSet::LINE_LOOP,
  12.                 0,pts->size()));

  13.         osgUtil::Tessellator tess;
  14.         tess.setTessellationType( osgUtil::Tessellator::TESS_TYPE_GEOMETRY );
  15.         tess.setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE );
  16.         tess.retessellatePolygons( *(top_cap.get()) );

  17.         osg::Stencil* stencil = new osg::Stencil;
  18.         stencil->setFunction(osg::Stencil::ALWAYS, 1, ~0u);
  19.         stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::INCR);
  20.         int ref = stencil->getFunctionRef();
  21.         unsigned int mask = stencil->getFunctionMask();
  22.         m_clipPlane->getOrCreateStateSet()->setAttributeAndModes(stencil, osg::StateAttribute::ON);
  23.         m_clipPlane->getOrCreateStateSet()->setAttributeAndModes(new osg::Depth(osg::Depth::LESS, 0, 1, false), osg::StateAttribute::ON);
  24.         m_clipPlane->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
  25.         m_clipPlane->getOrCreateStateSet()->setAttributeAndModes(new osg::ColorMask(false, false, false, false));
  26.         m_clipPlane->setCullingActive(false);
  27.         m_clipPlane->getOrCreateStateSet()->setRenderBinDetails(-9, "RenderBin");


  28.         osg::Geode* clearDepthNode = new osg::Geode;
  29.         clearDepthNode->addDrawable(new osgAPEx::ClearDrawable(GL_DEPTH_BUFFER_BIT));
  30.         clearDepthNode->getOrCreateStateSet()->setRenderBinDetails(-8, "RenderBin");
  31.         (主节点)m_Group->addChild(clearDepthNode);

  32.         stencil = new osg::Stencil;
  33.         stencil->setFunction(osg::Stencil::NOTEQUAL, 1, 1);
  34.         (地球节点)m_Earth->getOrCreateStateSet()->setAttributeAndModes(stencil, osg::StateAttribute::ON);       
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表