Skip to main content

Problems with Java 3D basics

1 reply [Last post]
Joined: 2011-03-11
Points: 0

I'm trying to use some very basic Java 3D features to generate views on 3D models. My aim is to test some model generation algorithms and all I really need is to make them visible to see what I got. I have no needs for good performance or other such fine tuning. But while I thought Java 3D would have been the easy way to get a model on the screen, I've ran into a couple of puzzling problems and have not been successful in finding answers for them.
I'm using SimpleUniverse with one directional light source. Currently I'm only testing with a simple Shape3D that I have generated using a QuadArray. It is an octagonal cylinder.
1) The first issue is the depth of my field of view. It seems that I'm not able to see any objects farther than ~43.0 unit away from the camera. I understand this is a basic perfomance tweak in 3D, but have not found where to configure it. Since I don't have any world full of objects, but only a lone model in the origin, I'd prefer to not have any restrictions on when I see it. I could propably get a workaround by shrinking my object instead of moving the camera away from, but I'd prefer a proper solution.
2) Another issue is more weird and relates to shading. I have defined an appearance consisting of material with a diffuse color setting for my Shape3D. The QuadArray has been constructed with the COORDINATES and NORMALS flags on and proper normals have been set to it. According to tutorials I have found this should be enough to get basic shading, but it doesn't work. It seems that the diffuse color of my material is assigned exactly on the first vertice of my QuadArray and all other vertices are black. This results in that one of my quads has a blue color fading to black and all the others are completely black. I've not found any clues on what's going on with this one.
Any help would be appreciated, especially with the second problem, since I have no workaround for it and it prevents me from seeing my model properly in 3D.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-12-09
Points: 0

Hey, I'm not so sure I can completely resolve the second problem, but one thing I've ran into before is that I tried color in a GeometryArray in other means than usering the setColor() method.
Using that method wont allow for the lighting/shading to be used ( I think), but it will make you're Octagonal Cylinder visible. (no more black points).
heres what you do:

QuadArray octCylinder = new QuadArray(numIndices, QuadArray.COORDINATES|QuadArray.COLOR_3);
Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);//blue color
//do what you need to set up the coordinates as normal.
//then set up the colors as follows
for(int i = 0; i<numIndices; i++)
octCylinder.setColor(i, blue);