This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > VRML > December 2006 > [X3D]Color shape at runtime with SAI
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
[X3D]Color shape at runtime with SAI
|
|
| Roberto 2006-12-06, 7:36 pm |
| Hi all.
I need to color a shape created dinamically using SAI APIs. I have a problem
at runtime because the shape remains white :-(
Anyone can help me , please?
Thank you very much
Follows a few statement of my code:
X3DScene mainScene = x3dBrowser.createScene(profile, null);
X3DNode shape = mainScene.createNode("Shape");
mainScene.addRootNode(shape);
SFNode shape_geometry = (SFNode) (shape.getField("geometry"));
SFNode shape_appearance = (SFNode) (shape.getField("appearance"));
X3DNode box = mainScene.createNode("Box");
shape_geometry.setValue(box);
X3DNode appearance = mainScene.createNode("Appearance");
shape_appearance.setValue(appearance);
X3DNode material = mainScene.createNode("Material");
shape_appearance.setValue(material);
SFColor diffuseColor = (SFColor)material.getField("diffuseColor");
float blue[]= {1,0,1};
diffuseColor.setValue(blue);
| |
| Rex Melton 2006-12-06, 7:36 pm |
| Roberto wrote:
> Hi all.
> I need to color a shape created dinamically using SAI APIs. I have a problem
> at runtime because the shape remains white :-(
> Anyone can help me , please?
> Thank you very much
>
> Follows a few statement of my code:
>
> X3DScene mainScene = x3dBrowser.createScene(profile, null);
>
> X3DNode shape = mainScene.createNode("Shape");
> mainScene.addRootNode(shape);
>
> SFNode shape_geometry = (SFNode) (shape.getField("geometry"));
> SFNode shape_appearance = (SFNode) (shape.getField("appearance"));
>
> X3DNode box = mainScene.createNode("Box");
> shape_geometry.setValue(box);
>
> X3DNode appearance = mainScene.createNode("Appearance");
> shape_appearance.setValue(appearance);
>
> X3DNode material = mainScene.createNode("Material");
> shape_appearance.setValue(material);
>
>
Your setting the appearance field of the Shape node with a Material
node. That's wrong.
You need to get the material field from the Appearance node - then set
the material field with the Material node you've created. e.g.
SFNode appearance_material = (SFNode)appearance.getField("material");
appearance_material.setValue( material );
> SFColor diffuseColor = (SFColor)material.getField("diffuseColor");
> float blue[]= {1,0,1};
> diffuseColor.setValue(blue);
>
>
>
>
--
____________________________________________________
Rex Melton
phone: (978) 687-0571
email: rex.melton@comcast.net
| |
| Roberto 2006-12-06, 7:36 pm |
|
"Rex Melton" <NoSpam_rex.melton_NoSpam@comcast.net> ha scritto nel messaggio
> Your setting the appearance field of the Shape node with a Material node.
> That's wrong.
right! I made a mistake in pasting my code.
The correct code that doesn't work the same is:
X3DScene mainScene = x3dBrowser.createScene(profile, null);
X3DNode shape = mainScene.createNode("Shape");
X3DNode box = mainScene.createNode("Box");
X3DNode appearance = mainScene.createNode("Appearance");
X3DNode material = mainScene.createNode("Material");
mainScene.addRootNode(shape);
SFNode shape_geometry = (SFNode) (shape.getField("geometry"));
SFNode shape_appearance = (SFNode) (shape.getField("appearance"));
SFNode shape_material = (SFNode) (appearance.getField("material"));
shape_geometry.setValue(box);
shape_appearance.setValue(appearance);
shape_appearance.setValue(material);
SFColor diffuseColor = (SFColor)material.getField("diffuseColor");
float blue[]= {1,0,1};
diffuseColor.setValue(blue);
| |
| Roberto 2006-12-06, 7:37 pm |
|
"Roberto" <gioeroby@NO_*SPAM*libero.it> ha scritto nel messaggio
SFColor diffuseColor = (SFColor)material.getField("diffuseColor");
float blue[]= {1,0,1};
diffuseColor.setValue(blue);
shape_appearance.setValue(appearance);
shape_material.setValue(material);
Ok! I solved the problem with the statements as above.
Thanks to Rex for his precious counsils :-)
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|