FieldContainerTransitPtr deepClone( FieldContainer const *src, const std::vector<OSG::UInt16> &shareGroupIds, const std::vector<OSG::UInt16> &ignoreGroupIds) { std::vector<const ReflexiveContainerType *> shareTypes; std::vector<const ReflexiveContainerType *> ignoreTypes; return deepClone(src, shareTypes, ignoreTypes, shareGroupIds, ignoreGroupIds); }
void testNode(void) { #if 0 OSG::SFNodePtr sfNode; OSG::MFNodePtr mfNode; OSG::NodePtr pNode = OSG::Node::create(); sfNode.setValue(pNode); mfNode.push_back(pNode); /* fprintf(stderr, "%p %p %p | %d %d\n", pNode, sfNode.getValue(), mfNode[0], OSG::Node::VolumeFieldId, OSG::Node::TravMaskFieldId); */ OSG::NodePtr pNode1 = OSG::Node::create(); sfNode.setValue(pNode1); mfNode.resize(2); mfNode.replace(1, pNode1); const OSG::Field *pF1 = pNode->getSFVolume(); OSG::Field *pF2 = pNode->editSFVolume(); OSG::GetFieldHandlePtr pRF1 = pNode->getField("volume"); OSG::EditFieldHandlePtr pRF2 = pNode->editField("volume"); fprintf(stderr, "#### Field %p %p | %p %p\n", pF1, pF2, pRF1.get(), pRF2.get()); // fprintf(stderr, "%p %p %p\n", pNode1, sfNode.getValue(), mfNode[1]); const OSG::SFNodePtr constSFNode; // fprintf(stderr, "%p %p\n", pNode1, constSFNode.getValue()); OSG::FieldContainerPtr pNodeClone = deepClone(pNode); OSG::FieldContainerPtr pFC = OSG::FieldContainerFactory::the()->createContainer("Billboard"); fprintf(stderr, "### FOO %p\n", getCPtr(pFC)); #endif }
FieldContainerTransitPtr deepClone( OSG::FieldContainer const *src, const std::string &shareTypesString, const std::string &ignoreTypesString) { std::vector<const ReflexiveContainerType *> shareTypes; std::vector<const ReflexiveContainerType *> ignoreTypes; std::vector<UInt16> shareGroupIds; std::vector<UInt16> ignoreGroupIds; appendTypesString(shareTypesString, shareTypes); appendTypesString(ignoreTypesString, ignoreTypes); return deepClone(src, shareTypes, ignoreTypes, shareGroupIds, ignoreGroupIds); }
CCSprite* UIDragLayer::deepClone(CCSprite* target) { if(!target) { return NULL; } CCSprite* sprite = NULL; CCTexture2D* texture = target->getTexture(); if(texture) { sprite = CCSprite::createWithTexture(texture); } else { sprite = CCSprite::create(); } bool isFlipX = target->isFlipX(); bool isFlipY = target->isFlipY(); sprite->setFlipX(isFlipX); sprite->setFlipY(isFlipY); sprite->setTextureRect(target->getTextureRect()); sprite->setRotation(target->getRotation()); sprite->setAnchorPoint(target->getAnchorPoint()); sprite->setContentSize(target->getContentSize()); sprite->setPosition(target->getPosition()); sprite->setDirty(target->isDirty()); sprite->setScale(target->getScale()); int count = target->getChildrenCount(); if(count > 0) { CCArray* array = target->getChildren(); CCObject* obj; CCARRAY_FOREACH(array,obj) { CCSprite* targetChild = dynamic_cast<CCSprite*>(obj); if(targetChild) { CCSprite* child = deepClone(targetChild); sprite->addChild(child); child->setPosition(targetChild->getPosition()); } }
FieldContainerTransitPtr deepClone( FieldContainer const *src, const std::vector<std::string> &shareTypeNames, const std::vector<std::string> &ignoreTypeNames, const std::vector<std::string> &shareGroupNames, const std::vector<std::string> &ignoreGroupNames) { std::vector<const ReflexiveContainerType *> shareTypes; std::vector<const ReflexiveContainerType *> ignoreTypes; std::vector<UInt16> shareGroupIds; std::vector<UInt16> ignoreGroupIds; appendTypesVector (shareTypeNames, shareTypes ); appendTypesVector (ignoreTypeNames, ignoreTypes ); appendGroupsVector(shareGroupNames, shareGroupIds ); appendGroupsVector(ignoreGroupNames, ignoreGroupIds); return deepClone(src, shareTypes, ignoreTypes, shareGroupIds, ignoreGroupIds); }
NodeTransitPtr deepCloneTree( const OSG::Node *rootNode, const std::vector<const OSG::ReflexiveContainerType *> &shareTypes, const std::vector<const OSG::ReflexiveContainerType *> &ignoreTypes, const std::vector<OSG::UInt16> &shareGroupIds, const std::vector<OSG::UInt16> &ignoreGroupIds) { NodeUnrecPtr rootClone(NULL); if(rootNode != NULL) { NodeUnrecPtr childClone; NodeCore *core = rootNode->getCore(); rootClone = Node::create(); rootClone->setTravMask(rootNode->getTravMask()); deepCloneAttachments(rootNode, rootClone, shareTypes, ignoreTypes, shareGroupIds, ignoreGroupIds); if(core != NULL) { NodeCoreUnrecPtr coreClone(NULL); const FieldContainerType &coreType = core->getType(); // test if core type should NOT be ignored if(!TypePredicates::typeInGroupIds ( ignoreGroupIds.begin(), ignoreGroupIds.end(), coreType) && !TypePredicates::typeDerivedFrom( ignoreTypes.begin(), ignoreTypes.end(), coreType) ) { // test if core should be shared if(TypePredicates::typeInGroupIds ( shareGroupIds.begin(), shareGroupIds.end(), coreType) || TypePredicates::typeDerivedFrom( shareTypes.begin(), shareTypes.end(), coreType) ) { // share core coreClone = core; } else { // clone core coreClone = dynamic_pointer_cast<NodeCore>( deepClone(core, shareTypes, ignoreTypes, shareGroupIds, ignoreGroupIds)); } } rootClone->setCore(coreClone); } for(UInt32 i = 0; i < rootNode->getNChildren(); ++i) { childClone = deepCloneTree(rootNode->getChild(i), shareTypes, ignoreTypes, shareGroupIds, ignoreGroupIds); rootClone->addChild(childClone); } } return NodeTransitPtr(rootClone); }