Structure of my SceneGraph

Have jReality programming problems or questions? Post them here.
Post Reply
tiofredo
Posts: 40
Joined: Mon 2. May 2011, 15:04

Structure of my SceneGraph

Post by tiofredo » Fri 20. May 2011, 17:48

Hi guys.
I'm new to scene graphs and therefore jreality.
I have to modelize a warehouse, with boxes, forklifts and trucks.
I'll also have 1 to 4 cameras displaying the scene.
Considering every component is independant,
Should I do :
root -> boxes -> box1 to box999
-> forklifts -> fl1 to fl999
-> trucks -> t1 to t999
-> camera1
-> camera2

or something like :
root -> box1
-> ...
-> box99
->fl1
etc.
or any other structure ?

Thanks for your help

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Structure of my SceneGraph

Post by gunn » Sat 21. May 2011, 17:44

The scene graph is not only used to construct the transformation hierarchy, it is also used for building up an appearance hierarchy. So even though all objects are independent for the transformation hierarchy, you might still want to group them into sub-graphs (variation 1 of your post), according to the appearance attributes you wish to use. For example, you might want the boxes to have one color; or subsets of the boxes to have particular colors or attributes. See tthe appearance tutorials in the jReality developers tutorial for more on appearance attributes and inheritance.
jReality core developer

tiofredo
Posts: 40
Joined: Mon 2. May 2011, 15:04

Re: Structure of my SceneGraph

Post by tiofredo » Tue 24. May 2011, 15:38

Ok, thanks for the answer.
I'll chose variation 1 then.
It brings me to another question :
each box has say 3 parameters, and we might wanna change the color of every box having parameter 1 set at true.
but we also might want do the same afterwards for every box having parameter 2 at false.
Which means I have overlapping groups, and of course, I can't have my boxes/nodes being child of more than one "category" node.
Is there a quick and not too much time-consuming way to move every box/node I want to a category node, then apply the color change to the category node which will propagate the effect ? I guess browsing every node and change its color would be really time-consuming, so I'm wondering...
Thanks for your help

Andre
Posts: 226
Joined: Fri 18. Sep 2009, 11:30

Re: Structure of my SceneGraph

Post by Andre » Wed 25. May 2011, 01:48

I hope I understood you right and I'll explain way you can act with the following example.

Lets say we have 3 different objects (chairs, tables and lamps) and two different appearances like color and transparency.

Code: Select all

Appearance1:= Color.yellow and transparency 50%
Appearance2:= Color.blue and transparency 100%

SceneGraphComponent chair = new SGC("Chair-Component")
chair.addChilds (List<SGC>chairchilds)
FOR ALL (chairchilds) {
chairchilds[i].setGeometry(indexedFaceSet Chair);
chairchilds[i].setAppearance(Appearance1);
}
...
FOR ALL (tablechilds) {
tablechilds[i].setGeometry(indexedFaceSet table);
tablechilds[i].setAppearance(Appearance1);
}
...
FOR ALL (lampchilds) {
lampchilds[i].setGeometry(indexedFaceSet lamp);
lampchilds[i].setAppearance(Appearance2);
}
...
now you have yellow tables and chairs and blue lamps.
to change the Appearance you just have to change the variables Appearance1 and Appearance2

eg. Appearance1 = Color.orange and transparency 100%
now all tables and chairs are orange.

But if you want to have different appearances for tables and chairs you have to set a new Appearance for each of the childs in the list.
e.g.

Code: Select all

Appearance3 = Color.green and transparency 10%
FOR ALL (tablechilds) {
tablechilds[i].setGeometry(indexedFaceSet table);
tablechilds[i].setAppearance(Appearance3);
}
I'm pretty sure, that a scenegraphcomponent can just have one appearance-child, so it shouldn't be possible to do something like that

Code: Select all

Appearance4 = Color.red
Appearance5 = Color.yellow
Appearance6 = Transparency 100%
Appearance7 = Transparency 50%

FOR ALL (chairchilds) {
chairchilds[i].setGeometry(indexedFaceSet Chair);
chairchilds[i].setAppearance(Appearance4);
chairchilds[i].setAppearance(Appearance6);
}
Can someone please confirm my answer...

best Andre

tiofredo
Posts: 40
Joined: Mon 2. May 2011, 15:04

Re: Structure of my SceneGraph

Post by tiofredo » Wed 1. Jun 2011, 14:59

Hi.
Sorry for the delay, I was working on another project for a few days.
Let me give an example of the situation I can have.
I have boxes, A to F (in fact thousands).
A, B and C have cereals inside.
D, E and F have bottles inside.
But A and D come from ACME, B and E from Big Brother company.
If I have a structure like :
root
|
boxes
|__________
|...................|
cereals bottles
|..................|
A,B,C D,E,F

I can easily highlight all cereal boxes by changing color of cereals node.
But if I then want to highlight only the ACME ones, I have to browse every box and check the owner (step 1), then change (or not) its color (step 2).
When it's about 6 boxes, it's easy.
When it comes to thousands, I'm wondering if doing step1+step2 for each box is more efficient than :
doing step1, moving every ACME box to an ACME node(pre-existing or new), THEN applying to the ACME node the color change.

And by the way, each one of my boxes(sgc) has a unique name, is there an existing way to getChildByName("box 1") on a parent ?

Thanks for all guys.


edit:
it seems I didn't get that a component could have more than one father...
therefore, i could have attribute-nodes being children of boxes-node, and put each box as a child of each of it's attributes.
and I guess it would be faster to apply an appearance to a node than to each concerned box after browsing and testing

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Structure of my SceneGraph

Post by gunn » Wed 1. Jun 2011, 20:06

I think the best approach is to allocate an appearance for every group of objects which share the same properties. That means, in your example, 4 different appearances:
ap1: cereals from ACME
ap2: cereals from Big Brother
ap3: bottles from ACME
ap4: bottles from Big Brother
Then set the appearance of a SceneGraphComponent to the one that matches the content (the geometry) of the SGC.
Then to change the color of the ACME cereals you need only change the appearance ap1.

For your information: assigning an appearance temporarily has no effect. You need to have the appearance attached to the node when it is rendered for it to have an effect.
jReality core developer

tiofredo
Posts: 40
Joined: Mon 2. May 2011, 15:04

Re: Structure of my SceneGraph

Post by tiofredo » Tue 21. Jun 2011, 14:38

Stupid question following the topic :

Code: Select all

		try
		{
			input = Input.getInput("C:\\test\\dc_lisse_20.obj");
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		ReaderOBJ reader = new ReaderOBJ();
		SceneGraphComponent c = null;
		try
		{
			c = reader.read(input);
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Geometry g = SceneGraphUtility.getFirstGeometry(c);
		IndexedFaceSet ifs = null;
		if (g == null)
			return;
		if (g instanceof IndexedFaceSet)
		{
			ifs = (IndexedFaceSet) g;
			IndexedFaceSetUtility.calculateAndSetNormals(ifs);
		}

		geometry = ifs;
//further
sgc.setGeometry(geometry);

Say I want the faces of my shape to be colored, not by loading a texture, just plain color, how do I do that ?
This way, I can make easy tests on my warehouse app.
Thanks

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Structure of my SceneGraph

Post by gunn » Tue 21. Jun 2011, 15:40

There are two ways: setting colors by appearance (then all faces get the same color), or in the IndexedFaceSet (each face can have its own color). For the first way, see this tutorial. To set the current diffuse face color to red in this tutorial use the statement:

Code: Select all

dps.setDiffuseColor(java.awt.Color.RED);
and for the second approach, see this tutorial.
jReality core developer

tiofredo
Posts: 40
Joined: Mon 2. May 2011, 15:04

Re: Structure of my SceneGraph

Post by tiofredo » Fri 24. Jun 2011, 15:10

Thanks for the help!

Post Reply