本文整理汇总了C++中osg::Node::asGroup方法的典型用法代码示例。如果您正苦于以下问题:C++ Node::asGroup方法的具体用法?C++ Node::asGroup怎么用?C++ Node::asGroup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::Node
的用法示例。
在下文中一共展示了Node::asGroup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isBasicRootNode
/// Returns true if the given node is a basic root group with no special information.
/// Used in conjunction with UseFbxRoot option.
/// Identity transforms are considered as basic root nodes.
bool isBasicRootNode(const osg::Node &node)
{
const osg::Group *osgGroup = node.asGroup();
if (!osgGroup || node.asGeode()) // WriterNodeVisitor handles Geodes the "old way" (= Derived from Node, not Group as for now). Geodes may be considered "basic root nodes" when WriterNodeVisitor will be adapted.
{
// Geodes & such are not basic root nodes
return false;
}
// Test if we've got an empty transform (= a group!)
const osg::Transform *transform = osgGroup->asTransform();
if (transform)
{
if (const osg::MatrixTransform *matrixTransform = transform->asMatrixTransform())
{
if (!matrixTransform->getMatrix().isIdentity())
{
// Non-identity matrix transform
return false;
}
}
else if (const osg::PositionAttitudeTransform *pat = transform->asPositionAttitudeTransform())
{
if (pat->getPosition() != osg::Vec3d() ||
pat->getAttitude() != osg::Quat() ||
pat->getScale() != osg::Vec3d(1.0f, 1.0f, 1.0f) ||
pat->getPivotPoint() != osg::Vec3d())
{
// Non-identity position attribute transform
return false;
}
}
else
{
// Other transform (not identity or not predefined type)
return false;
}
}
// Test the presence of a non-empty stateset
if (node.getStateSet())
{
osg::ref_ptr<osg::StateSet> emptyStateSet = new osg::StateSet;
if (node.getStateSet()->compare(*emptyStateSet, true) != 0)
{
return false;
}
}
return true;
}
示例2: apply
void FindGroupByRecIndex::apply(osg::Node &searchNode)
{
if (searchNode.getUserDataContainer() && searchNode.getUserDataContainer()->getNumUserObjects())
{
NodeUserData* holder = dynamic_cast<NodeUserData*>(searchNode.getUserDataContainer()->getUserObject(0));
if (holder && holder->mIndex == mRecIndex)
{
osg::Group* group = searchNode.asGroup();
if (!group)
group = searchNode.getParent(0);
mFound = group;
mFoundPath = getNodePath();
return;
}
}
traverse(searchNode);
}
示例3: cleanUpFbx
osgDB::ReaderWriter::WriteResult ReaderWriterFBX::writeNode(
const osg::Node& node,
const std::string& filename,
const Options* options) const
{
try
{
std::string ext = osgDB::getLowerCaseFileExtension(filename);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
osg::ref_ptr<Options> localOptions = options ?
static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
localOptions->getDatabasePathList().push_front(osgDB::getFilePath(filename));
KFbxSdkManager* pSdkManager = KFbxSdkManager::Create();
if (!pSdkManager)
{
return WriteResult::ERROR_IN_WRITING_FILE;
}
CleanUpFbx cleanUpFbx(pSdkManager);
pSdkManager->SetIOSettings(KFbxIOSettings::Create(pSdkManager, IOSROOT));
bool useFbxRoot = false;
if (options)
{
std::istringstream iss(options->getOptionString());
std::string opt;
while (iss >> opt)
{
if (opt == "Embedded")
{
pSdkManager->GetIOSettings()->SetBoolProp(EXP_FBX_EMBEDDED, true);
}
else if (opt == "UseFbxRoot")
{
useFbxRoot = true;
}
}
}
KFbxScene* pScene = KFbxScene::Create(pSdkManager, "");
pluginfbx::WriterNodeVisitor writerNodeVisitor(pScene, pSdkManager, filename,
options, osgDB::getFilePath(node.getName().empty() ? filename : node.getName()));
if (useFbxRoot && isBasicRootNode(node))
{
// If root node is a simple group, put all elements under the FBX root
const osg::Group * osgGroup = node.asGroup();
for(unsigned int child=0; child<osgGroup->getNumChildren(); ++child) {
const_cast<osg::Node *>(osgGroup->getChild(child))->accept(writerNodeVisitor);
}
}
else {
// Normal scene
const_cast<osg::Node&>(node).accept(writerNodeVisitor);
}
KFbxExporter* lExporter = KFbxExporter::Create(pSdkManager, "");
pScene->GetGlobalSettings().SetAxisSystem(KFbxAxisSystem::eOpenGL);
// Ensure the directory exists or else the FBX SDK will fail
if (!osgDB::makeDirectoryForFile(filename)) {
OSG_NOTICE << "Can't create directory for file '" << filename << "'. FBX SDK may fail creating the file." << std::endl;
}
// The FBX SDK interprets the filename as UTF-8
#ifdef OSG_USE_UTF8_FILENAME
const std::string& utf8filename(filename);
#else
std::string utf8filename(osgDB::convertStringFromCurrentCodePageToUTF8(filename));
#endif
if (!lExporter->Initialize(utf8filename.c_str()))
{
return std::string(lExporter->GetLastErrorString());
}
if (!lExporter->Export(pScene))
{
return std::string(lExporter->GetLastErrorString());
}
return WriteResult::FILE_SAVED;
}
catch (const std::string& s)
{
return s;
}
catch (const char* s)
{
return std::string(s);
}
catch (...)
{
}
return WriteResult::ERROR_IN_WRITING_FILE;
}
示例4: cleanUpFbx
osgDB::ReaderWriter::WriteResult ReaderWriterFBX::writeNode(
const osg::Node& node,
const std::string& filename,
const Options* options) const
{
try
{
std::string ext = osgDB::getLowerCaseFileExtension(filename);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
osg::ref_ptr<Options> localOptions = options ?
static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
localOptions->getDatabasePathList().push_front(osgDB::getFilePath(filename));
FbxManager* pSdkManager = FbxManager::Create();
if (!pSdkManager)
{
return WriteResult::ERROR_IN_WRITING_FILE;
}
CleanUpFbx cleanUpFbx(pSdkManager);
pSdkManager->SetIOSettings(FbxIOSettings::Create(pSdkManager, IOSROOT));
bool useFbxRoot = false;
bool ascii(false);
std::string exportVersion;
if (options)
{
std::istringstream iss(options->getOptionString());
std::string opt;
while (iss >> opt)
{
if (opt == "Embedded")
{
pSdkManager->GetIOSettings()->SetBoolProp(EXP_FBX_EMBEDDED, true);
}
else if (opt == "UseFbxRoot")
{
useFbxRoot = true;
}
else if (opt == "FBX-ASCII")
{
ascii = true;
}
else if (opt == "FBX-ExportVersion")
{
iss >> exportVersion;
}
}
}
FbxScene* pScene = FbxScene::Create(pSdkManager, "");
if (options)
{
if (options->getPluginData("FBX-AssetUnitMeter"))
{
float unit = *static_cast<const float*>(options->getPluginData("FBX-AssetUnitMeter"));
FbxSystemUnit kFbxSystemUnit(unit*100);
pScene->GetGlobalSettings().SetSystemUnit(kFbxSystemUnit);
}
}
pluginfbx::WriterNodeVisitor writerNodeVisitor(pScene, pSdkManager, filename,
options, osgDB::getFilePath(node.getName().empty() ? filename : node.getName()));
if (useFbxRoot && isBasicRootNode(node))
{
// If root node is a simple group, put all elements under the FBX root
const osg::Group * osgGroup = node.asGroup();
for (unsigned int child = 0; child < osgGroup->getNumChildren(); ++child)
{
const_cast<osg::Node *>(osgGroup->getChild(child))->accept(writerNodeVisitor);
}
}
else {
// Normal scene
const_cast<osg::Node&>(node).accept(writerNodeVisitor);
}
FbxDocumentInfo* pDocInfo = pScene->GetDocumentInfo();
bool needNewDocInfo = pDocInfo != NULL;
if (needNewDocInfo)
{
pDocInfo = FbxDocumentInfo::Create(pSdkManager, "");
}
pDocInfo->LastSaved_ApplicationName.Set(FbxString("OpenSceneGraph"));
pDocInfo->LastSaved_ApplicationVersion.Set(FbxString(osgGetVersion()));
if (needNewDocInfo)
{
pScene->SetDocumentInfo(pDocInfo);
}
FbxExporter* lExporter = FbxExporter::Create(pSdkManager, "");
pScene->GetGlobalSettings().SetAxisSystem(FbxAxisSystem::eOpenGL);
// Ensure the directory exists or else the FBX SDK will fail
if (!osgDB::makeDirectoryForFile(filename)) {
OSG_NOTICE << "Can't create directory for file '" << filename << "'. FBX SDK may fail creating the file." << std::endl;
//.........这里部分代码省略.........