# [OT]: Has anyone done this ? Recursive Scene graphs

I just wanted to share a new idea I have been working on for a while. It now works.

Can you see the implementation of the recursive algo in the scene graph ?

It builds trees that are the same on each x,y position where they are instantiated

gzRealXY xyfunk1(gzReal in)
{
return gzRealXY(in*(1-in)sin(inGZ_PI3)2,in(1-in)sin(3inGZ_PI)*2);
}

gzRealXY xyfunk2(gzReal in)
{
return gzRealXY(in*(1-in)sin(inGZ_PI)2,in(1-in)sin(inGZ_PI));
}

// A test sample of a geometry
gzNode *buildTree()
{
gzGeometry *base_1=new gzGeometryTube(20,1,10,6,GZ_TUBE_CONE,xyfunk1,10,10);

//base_1->useDisplayList(TRUE);

gzGeometry *base_2=new gzGeometryTube(20,1,3,6,GZ_TUBE_CONE,xyfunk2,10,10);

//base_2->useDisplayList(TRUE);

// Base branch

gzSeedSwitch *base=new gzSeedSwitch;

// Build tree

gzRecursive *tree=new gzRecursive;

tree->setMaxDepth(4);

// tree=(base+T1R1S1tree+T2R2S2tree+SW*(T3R3S3*tree…))

// tree=base

// TRS1 - top striving high
gzSeedTransform *pSeedTransform_1=new gzSeedTransform();
pSeedTransform_1->setTranslation(0,19.8,0);
pSeedTransform_1->setScale(0.5,0.6,0.5);
pSeedTransform_1->setHPRSeedValue(TRUE,gzVec3(0,-10,-10),gzVec3(0,10,10));

// tree=base+T1R1S1*tree

// TRS2 - side winder
gzSeedTransform *pSeedTransform_2=new gzSeedTransform();
pSeedTransform_2->setTranslation(0,19.7,0);
pSeedTransform_2->setScale(0.4,0.5,0.4);
pSeedTransform_2->setHPRSeedValue(TRUE,gzVec3(0,20,20),gzVec3(360,30,30));

// TRS3 - optional branch
gzSeedTransform *pSeedTransform_3=new gzSeedTransform();
pSeedTransform_3->setTranslation(0,17,0);
pSeedTransform_3->setScale(0.3,0.4,0.3);
pSeedTransform_3->setHPRSeedValue(TRUE,gzVec3(0,-120,-120),gzVec3(180,120,120));

// TRS4 - optional branch
gzSeedTransform *pSeedTransform_4=new gzSeedTransform;
pSeedTransform_4->setTranslation(0,17,0);
pSeedTransform_4->setScale(0.3,0.6,0.3);
pSeedTransform_4->setHPRSeedValue(TRUE,gzVec3(180,30,-60),gzVec3(270,60,60));

// TRS5 - optional branch
gzSeedTransform *pSeedTransform_5=new gzSeedTransform;
pSeedTransform_5->setTranslation(0,15,0);
pSeedTransform_5->setScale(0.4,0.6,0.4);
pSeedTransform_5->setHPRSeedValue(TRUE,gzVec3(270,30,-60),gzVec3(360,60,60));

// Optional braches
gzSeedSwitch *pSeedSwitch_O=new gzSeedSwitch;
pSeedSwitch_O->useExclusive(FALSE);

pSeedSwitch_O->setSeedProbability(0,1);

pSeedSwitch_O->setSeedProbability(1,1);

pSeedSwitch_O->setSeedProbability(2,1);

// Add optional to tree

// Fix state on overall tree

gzMaterial *material=new gzMaterial;
gzState *state=new gzState;

state->setMaterial(material);
state->setMode(GZ_STATE_MATERIAL,GZ_STATE_ON);

gzTexture *tex=new gzTexture;

tex->setWrapS(GZ_REPEAT);
tex->setWrapT(GZ_REPEAT);
tex->useMipMaps(TRUE);
tex->setMagFilter(GZ_LINEAR);
tex->setMinFilter(GZ_LINEAR_MIPMAP_LINEAR);

state->setTexture(tex);
state->setMode(GZ_STATE_TEXTURE,GZ_STATE_ON);

// Seed starter
gzSeedControl *topNode=new gzSeedControl;
//topNode->setSeedControlType(GZ_SEED_FROM_TIME);

topNode->setState(state);

// Add recursive tree

}

I haven’t tried it myself with the OpenSceneGraph, but your enthusiasn makes me tempted to try out a little traversal callback on a osg::Group node to implement a recursive subgraph.

I guess the fun part comes when the amount of recursion you do is implemented so its adaptive - so once a subgraph gets small enough w.r.t screen size you stop traversing.

Robert.

exactly…

// ---------- Recursive ---------------------------------------------

GZ_GRAPH_EXPORT gzVoid setMaxDepth( gzULong depth );
GZ_GRAPH_EXPORT gzVoid setTransform(const gzMatrix4 &transform);
GZ_GRAPH_EXPORT gzVoid setMaxDepthNode(gzNode *node);
GZ_GRAPH_EXPORT gzVoid useDistanceDepth(gzBool on);
GZ_GRAPH_EXPORT gzVoid setDistanceDepthEquation(gzReal farDistance=100,gzReal speed=1);

Works just like LOD levels