win10&osg3.6.4
Why is the following function deep copy the same data?
*class SCENETOOL_API NodeDeepCopy : public osg::CopyOp*
* {*
* public:*
* inline NodeDeepCopy(CopyFlags flags = SHALLOW_COPY) :*
* osg::CopyOp(flags) { _nodeCopyMap.clear(); }*
* virtual osg::Node* operator() (const osg::Node* node) const*
* {*
* if (node && _flags&DEEP_COPY_NODES)*
* {*
* if (node->getNumParents() > 1)*
* {*
* if (_nodeCopyMap.find(node) != _nodeCopyMap.end())*
* {*
* std::cout << "Copy of node " << node << " " << node->getName() << ", "*
* << _nodeCopyMap[node] << ", will be reused" << std::endl;*
* return (osg::Node*)(_nodeCopyMap[node]);*
* }*
* else*
* {*
* osg::Node* newNode = dynamic_cast<osg::Node*>(node->clone(*this));*
* _nodeCopyMap[node] = newNode;*
* return newNode;*
* }*
* }*
* else*
* return dynamic_cast<osg::Node*>(node->clone(*this));*
* }*
* else*
* return const_cast<osg::Node*>(node);*
* }*
* protected:*
* // must be mutable since CopyOp is passed around as const to*
* // the various clone/copy constructors.*
* mutable std::map<const osg::Node*, osg::Node*> _nodeCopyMap;*
* };*
osg::Node* ModelFileLoad::addModelFormFile(std::string modelPath)
{
osg::Node* resNode = nullptr;
std::map<std::string, osg::Node*>::iterator itFind =
_mapNodePath.find(modelPath);
if (itFind == _mapNodePath.end())
{
resNode = osgDB::readNodeFile(modelPath);
if (resNode)
{
_mapNodePath.insert(std::pair<std::string, osg::Node*>(modelPath, pNode));
return resNode;
}
}
else
{
osg::Node* pFindNode = itFind->second;
if (pFindNode)
{
resNode =
dynamic_cast<osg::Node*>(pFindNode->clone(NodeDeepCopy(DEEP_COPY_NODES));
}
}
return resNode;
}
--
You received this message because you are subscribed to the Google Groups
"OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/osg-users/cfc89e13-037f-4d68-a848-224fdf4a637fn%40googlegroups.com.