本文整理汇总了C++中osg::Geometry::getOrCreateStateSet方法的典型用法代码示例。如果您正苦于以下问题:C++ Geometry::getOrCreateStateSet方法的具体用法?C++ Geometry::getOrCreateStateSet怎么用?C++ Geometry::getOrCreateStateSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::Geometry
的用法示例。
在下文中一共展示了Geometry::getOrCreateStateSet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _initSkinning
bool InstancesManagerImpl::_initSkinning(osg::Geometry& geom, const image_data& id )
{
osg::Geometry& source = geom;
osg::Vec3Array* positionSrc = dynamic_cast<osg::Vec3Array*>(source.getVertexArray());
if (!positionSrc)
{
OSG_WARN << "InstancedAnimationManager no vertex array in the geometry " << geom.getName() << std::endl;
return false;
}
osg::ref_ptr<osg::Program> cSkinningProg = creators::createProgram("skininst2").program;
cSkinningProg->setName("SkinningShader");
const int attribIndex = cAttribSkinningBaseIndex;
int nbAttribs = id.bonesWeights.size();
for (int i = 0; i < nbAttribs; i++)
{
osg::ref_ptr<osg::Vec4Array> array = new osg::Vec4Array(osg::Array::BIND_PER_VERTEX);
const image_data::weights_t& w = id.bonesWeights[i];
for (unsigned j = 0; j < w.size(); j+=id.divisor)
{
array->push_back(osg::Vec4(w.at(j),w.at(j+1),w.at(j+2),w.at(j+3)));
}
std::stringstream ss;
ss << "boneWeight" << i;
cSkinningProg->addBindAttribLocation(ss.str(), attribIndex + i);
geom.setVertexAttribArray(attribIndex + i, array);
OSG_INFO << "set vertex attrib " << ss.str() << std::endl;
}
osg::ref_ptr<osg::StateSet> ss = geom.getOrCreateStateSet();
ss->addUniform(new osg::Uniform("nbBonesPerVertex", id.bonesPerVertex));
ss->setAttributeAndModes(cSkinningProg.get());
return true;
}