Skip to main content

setting material properties to appearance makes my object disapear

2 replies [Last post]
Rouben
Offline
Joined: 2006-02-17

Hi Guys,

I am adding a sphere object dynamically (using a BranchGroup) to a live tree, but for some reason whenever I set the Material property of the appearance of the sphere, the sphere disappears (turns black). Below is my function that gets called at runtime...can anyone see what is wrong with it?

thanks a billion in advance,
-Rouben

code ->

public void refreshData(ArrayList listOfPts) {

Sphere sphere = null;
TransformGroup trans = null;
Transform3D t3d = new Transform3D();
Vector3d vec = null;

Iterator iter = listOfPts.iterator();
while (iter.hasNext()) {

Appearance app = new Appearance();
Material material = new Material();
material.setDiffuseColor(new Color3f(0.8f, 0.8f, 0.8f));
material.setSpecularColor(new Color3f(0.3f, 0.4f, 0.5f));
material.setShininess(0.0f);
app.setMaterial(material);

vec = (Vector3d) iter.next();
t3d = new Transform3D();
t3d.setTranslation(vec);
trans = new TransformGroup(t3d);
sphere = new Sphere(.1f, // sphere radius
Primitive.GENERATE_NORMALS,
25, // divisions radially
app); // it's appearance
trans.addChild(sphere);
solution.addChild(trans);
}
flow.addChild(solution);

}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Justin Couch

java3d-interest@javadesktop.org wrote:

> but for some reason whenever I set the Material property of the appearance of the sphere, the sphere disappears (turns black).

Do you have any lights in the scene? Setting material values immediately
make the object subject to lighting equations, meaning you're going to
need to have lights. If you don't have lights, then only emissive colour
values will be seen, which you are not setting in the example code.

--
Justin Couch http://www.vlc.com.au/~justin/
Java Architect & Bit Twiddler http://www.yumetech.com/
Author, Java 3D FAQ Maintainer http://www.j3d.org/
-------------------------------------------------------------------
"Look through the lens, and the light breaks down into many lights.
Turn it or move it, and a new set of arrangements appears... is it
a single light or many lights, lights that one must know how to
distinguish, recognise and appreciate? Is it one light with many
frames or one frame for many lights?" -Subcomandante Marcos
-------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

Rouben
Offline
Joined: 2006-02-17

Thank you soo much Justin, you solved my problem.

-Rouben