本文整理汇总了C++中osg::Node::getOrCreateStateSet方法的典型用法代码示例。如果您正苦于以下问题:C++ Node::getOrCreateStateSet方法的具体用法?C++ Node::getOrCreateStateSet怎么用?C++ Node::getOrCreateStateSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::Node
的用法示例。
在下文中一共展示了Node::getOrCreateStateSet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setMaterialColor
void osgManipulator::setMaterialColor(const osg::Vec4& color, osg::Node& node)
{
osg::Material* mat = dynamic_cast<osg::Material*>(node.getOrCreateStateSet()->getAttribute(osg::StateAttribute::MATERIAL));
if (! mat)
{
mat = new osg::Material;
node.getOrCreateStateSet()->setAttribute(mat);
}
mat->setDiffuse(osg::Material::FRONT_AND_BACK, color);
}
示例2: apply
void TextureResizeNonPowerOfTwoHintVisitor::apply(osg::Node & node)
{
osg::StateSet * stateset = node.getOrCreateStateSet();
if(stateset)
{
setHint(stateset);
}
traverse(node);
}
示例3: createProgram
void ShaderVisitor::createProgram(const ShaderRequirements &reqs, osg::Node& node)
{
osg::StateSet* writableStateSet = NULL;
if (mAllowedToModifyStateSets)
writableStateSet = node.getOrCreateStateSet();
else
writableStateSet = getWritableStateSet(node);
ShaderManager::DefineMap defineMap;
for (unsigned int i=0; i<sizeof(defaultTextures)/sizeof(defaultTextures[0]); ++i)
{
defineMap[defaultTextures[i]] = "0";
defineMap[std::string(defaultTextures[i]) + std::string("UV")] = "0";
}
for (std::map<int, std::string>::const_iterator texIt = reqs.mTextures.begin(); texIt != reqs.mTextures.end(); ++texIt)
{
defineMap[texIt->second] = "1";
defineMap[texIt->second + std::string("UV")] = boost::lexical_cast<std::string>(texIt->first);
}
if (!reqs.mColorMaterial)
defineMap["colorMode"] = "0";
else
{
switch (reqs.mVertexColorMode)
{
default:
case GL_AMBIENT_AND_DIFFUSE:
defineMap["colorMode"] = "2";
break;
case GL_EMISSION:
defineMap["colorMode"] = "1";
break;
}
}
defineMap["forcePPL"] = mForcePerPixelLighting ? "1" : "0";
defineMap["clamp"] = mClampLighting ? "1" : "0";
osg::ref_ptr<osg::Shader> vertexShader (mShaderManager.getShader(mDefaultVsTemplate, defineMap, osg::Shader::VERTEX));
osg::ref_ptr<osg::Shader> fragmentShader (mShaderManager.getShader(mDefaultFsTemplate, defineMap, osg::Shader::FRAGMENT));
if (vertexShader && fragmentShader)
{
writableStateSet->setAttributeAndModes(mShaderManager.getProgram(vertexShader, fragmentShader), osg::StateAttribute::ON);
for (std::map<int, std::string>::const_iterator texIt = reqs.mTextures.begin(); texIt != reqs.mTextures.end(); ++texIt)
{
writableStateSet->addUniform(new osg::Uniform(texIt->second.c_str(), texIt->first), osg::StateAttribute::ON);
}
}
}
示例4: entityAdded
virtual void entityAdded(igplugincore::PluginContext&, unsigned int, osg::Node& node, const std::string& fileName)
{
if (!osgDB::fileExists(fileName+".xml")) return;
osgDB::XmlNode* root = osgDB::readXmlFile(fileName+".xml");
if (!root) return;
if (!root->children.size()) return;
if (root->children.at(0)->name != "OpenIg-Model-Definition") return;
osgDB::XmlNode::Children::iterator itr = root->children.at(0)->children.begin();
for ( ; itr != root->children.at(0)->children.end(); ++itr )
{
if ((**itr).name == "Material")
{
osgDB::XmlNode* materialNode = *itr;
osgDB::XmlNode::Children::iterator citr = materialNode->children.begin();
osg::ref_ptr<osg::Material> material;
for ( ; citr != materialNode->children.end(); ++citr )
{
if ((**citr).name == "Name")
{
if ((**citr).contents == "Day")
_dayMaterial = material = new osg::Material;
else
if ((**citr).contents == "Night")
_nightMaterial = material = new osg::Material;
}
if ((**citr).name == "Ambient")
{
if (material.valid())
{
igcore::StringUtils::Tokens tokens = igcore::StringUtils::instance()->tokenize((**citr).contents);
if (tokens.size() == 4)
{
float r = atof(tokens.at(0).c_str());
float g = atof(tokens.at(1).c_str());
float b = atof(tokens.at(2).c_str());
float a = atof(tokens.at(3).c_str());
material->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(r,g,b,a));
}
}
}
if ((**citr).name == "Diffuse")
{
if (material.valid())
{
igcore::StringUtils::Tokens tokens = igcore::StringUtils::instance()->tokenize((**citr).contents);
if (tokens.size() == 4)
{
float r = atof(tokens.at(0).c_str());
float g = atof(tokens.at(1).c_str());
float b = atof(tokens.at(2).c_str());
float a = atof(tokens.at(3).c_str());
material->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(r,g,b,a));
}
}
}
if ((**citr).name == "Specular")
{
if (material.valid())
{
igcore::StringUtils::Tokens tokens = igcore::StringUtils::instance()->tokenize((**citr).contents);
if (tokens.size() == 4)
{
float r = atof(tokens.at(0).c_str());
float g = atof(tokens.at(1).c_str());
float b = atof(tokens.at(2).c_str());
float a = atof(tokens.at(3).c_str());
material->setSpecular(osg::Material::FRONT_AND_BACK,osg::Vec4(r,g,b,a));
}
}
}
if ((**citr).name == "Shininess")
{
if (material.valid())
{
float shininess = atof((**citr).contents.c_str());
material->setShininess(osg::Material::FRONT_AND_BACK,shininess);
}
}
}
}
}
if (_dayMaterial.valid() && _nightMaterial.valid())
{
_runtimeMaterial = new osg::Material(*_dayMaterial);
node.getOrCreateStateSet()->setAttributeAndModes(_runtimeMaterial,osg::StateAttribute::ON|osg::StateAttribute::PROTECTED|osg::StateAttribute::OVERRIDE);
}
}