Ejemplo n.º 1
0
NodeTransitPtr OctreeVisualization::createNodeGeo(OctreePtr,
                                                  const Octree::OTNodePtr node,
                                                  Material* GeoMaterial,
                                                  const Node* BaseGeo)
{
    //Make the Geoemtry
    NodeRecPtr box = deepCloneTree(BaseGeo);

    dynamic_cast<Geometry*>(box->getCore())->setMaterial(GeoMaterial);

    Matrix m;
    TransformRecPtr box_trans;
    NodeRecPtr trans_node = makeCoredNode<Transform>(&box_trans);
    Pnt3f Center;
    node->getVolume().getCenter(Center);
    m.setTranslate( Center.x(), Center.y(), Center.z());

    const Real32 Offset(0.0f);
    Vec3f Size;
    node->getVolume().getSize(Size);
    m.setScale(Size.x()-(Size.x()*Offset), Size.y()-(Size.y()*Offset), Size.z()-(Size.z()*Offset));
    box_trans->setMatrix(m);
    trans_node->addChild(box);

    return NodeTransitPtr(trans_node);
}
Ejemplo n.º 2
0
void PasteCommand::execute(void)
{
	NodeRefPtr ClonedNodeInCopyClipboard = _ApplicationPlayer->getClonedNodeInCopyClipboard();

    if(_DeepClone)
    {
        _PastedNode = deepCloneTree(_ApplicationPlayer->getClonedNodeInCopyClipboard());
    }
    else
    {
        _PastedNode = cloneTree(_ApplicationPlayer->getClonedNodeInCopyClipboard());
    }

    const Char8* NameChar = getName(_ApplicationPlayer->getClonedNodeInCopyClipboard());
    std::string _Name= (NameChar == NULL ? "UNNAMED NODE" : NameChar);
	_Name+=" copy";
	setName(_PastedNode,_Name);

    if(_PastedNode!=NULL)
	{
		_HierarchyPanel->getSceneGraphTreeModel()->addNode(_ParentNode,_PastedNode);
	}

	_HasBeenDone = true;
}
Ejemplo n.º 3
0
NodeTransitPtr deepCloneTree(const OSG::Node                *rootNode,
                             const std::vector<OSG::UInt16> &shareGroupIds,
                             const std::vector<OSG::UInt16> &ignoreGroupIds)
{
    std::vector<const ReflexiveContainerType *> shareTypes;
    std::vector<const ReflexiveContainerType *> ignoreTypes;

    return deepCloneTree(rootNode, shareTypes,    ignoreTypes,
                                   shareGroupIds, ignoreGroupIds);
}
Ejemplo n.º 4
0
NodeTransitPtr deepCloneTree(const Node            *rootNode,
                             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 deepCloneTree(rootNode, shareTypes,    ignoreTypes,
                                   shareGroupIds, ignoreGroupIds);
}
Ejemplo n.º 5
0
NodeTransitPtr deepCloneTree(const OSG::Node                *rootNode,
                             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 deepCloneTree(rootNode, shareTypes,    ignoreTypes,
                                   shareGroupIds, ignoreGroupIds);
}
Ejemplo n.º 6
0
NodeTransitPtr OctreeVisualization::createNodeDistanceLOD(OctreePtr,
                                                          const Octree::OTNodePtr node,
                                                          Material* GeoMaterial,
                                                          const Node* BaseGeo,
                                                          Real32 Range
                                                         )
{
    NodeRecPtr box = deepCloneTree(BaseGeo);
    dynamic_cast<Geometry*>(box->getCore())->setMaterial(GeoMaterial);

    //DistanceLOD node
    DistanceLODRecPtr LOD = DistanceLOD::create();
    LOD->editMFRange()->push_back(10.0);

    NodeRecPtr LODNode = makeNodeFor(LOD);
    LODNode->addChild(box);
    LODNode->addChild(makeCoredNode<Group>());

    Matrix m;
    TransformRecPtr box_trans;
    NodeRecPtr trans_node = makeCoredNode<Transform>(&box_trans);
    Pnt3f Center;
    node->getVolume().getCenter(Center);
    m.setTranslate(Center.x(),
                   Center.y(),
                   Center.z());

    const Real32 Offset(0.0f);
    Vec3f Size;
    node->getVolume().getSize(Size);
    m.setScale(Size.x()-(Size.x()*Offset),
               Size.y()-(Size.y()*Offset),
               Size.z()-(Size.z()*Offset));
    box_trans->setMatrix(m);
    trans_node->addChild(LODNode);

    return NodeTransitPtr(trans_node);
}
Ejemplo n.º 7
0
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);
}
Ejemplo n.º 8
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->init();

    // load the scene
    NodePtr scene = NullFC;
    
    if(argc < 2)
    {
        FWARNING(("No file given!\n"));
        FWARNING(("Supported file formats:\n"));
        
        std::list<const char*> suffixes;
        SceneFileHandler::the().getSuffixList(suffixes, SceneFileType::OSG_READ_SUPPORTED);
        
        for(std::list<const char*>::iterator it  = suffixes.begin();
                                             it != suffixes.end();
                                           ++it)
        {
            FWARNING(("%s\n", *it));
        }

        scene = makeTorus(.5, 2, 16, 16);
    }
    else
    {
        /*
            All scene file loading is handled via the SceneFileHandler.
        */
        scene = SceneFileHandler::the().read(argv[1]);
    }
    
    // calc size of the scene
    Vec3f min, max;
#ifndef OSG_2_PREP
    DynamicVolume vol;
#else
    BoxVolume     vol;
#endif
    scene->getWorldVolume(vol);
    vol.getBounds(min, max);

    Vec3f d = max - min;
    Real32 offset = d.length() / 2.0f;
    
    // now create a deep clone
    // we share the GenericAtt from the wrl loader without it crashes in deepClone setAbstrValue ...
    NodePtr sceneClone = deepCloneTree(scene, "GenericAtt");
    // this clones all nodes but the cores of type Material and Transform are shared.
    //NodePtr sceneClone = deepCloneTree(scene, "Material, Transform");
    
    // now change all geometries from the cloned scene just to show
    // that it is a real deep copy.
    traverse(sceneClone, 
             osgTypedFunctionFunctor1CPtrRef<Action::ResultE,
                                             NodePtr        >(changeGeo));
    
    // create a small scene graph with two transformation nodes.
    NodePtr root = makeCoredNode<Group>();
    ComponentTransformPtr t1;
    NodePtr tn1 = makeCoredNode<ComponentTransform>(&t1);
    ComponentTransformPtr t2;
    NodePtr tn2 = makeCoredNode<ComponentTransform>(&t2);
    
    beginEditCP(t1);
        t1->setTranslation(Vec3f(- offset, 0.0f, 0.0f));
    endEditCP(t1);
    beginEditCP(t2);
        t2->setTranslation(Vec3f(offset, 0.0f, 0.0f));
    endEditCP(t2);
    
    beginEditCP(tn1);
        tn1->addChild(scene);
    endEditCP(tn1);
    
    beginEditCP(tn2);
        tn2->addChild(sceneClone);
    endEditCP(tn2);
    
    beginEditCP(root);
        root->addChild(tn1);
        root->addChild(tn2);
    endEditCP(root);
    
    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(gwin );
    mgr->setRoot  (root);

    // show the whole scene
    mgr->showAll();
    
    // GLUT main loop
    glutMainLoop();

    return 0;
}