Hi,
I'm from Italy so please forgive my English.
I'm new at Java3D... in these days I was trying to create an applet that
displays a polygon with LineStripArray... I think I've created the
polygon, but it won't appear on the panel in the browser (I get a black
surface with no line)... I can't locate the problem.... I put here the
code, hoping that someone could tell me how to view what I've created!
thank you very much!
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import java.applet.*;
import java.awt.*;
public class GraficaComp extends Applet {
private Geometry poligono(){
LineStripArray pol;
Point3f punti[] = new Point3f[3];
Color3f colors[] = new Color3f[3];
int stripCounts[] = {3};
Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
Color3f yellow = new Color3f(0.7f, 0.5f, 0.0f);
punti[0] = new Point3f(1.0f, 1.5f, 1.7f);
punti[1] = new Point3f(4.2f, 1.7f, 6.2f);
punti[2] = new Point3f(2.9f, 5.8f, 3.4f);
colors[0] = red;
colors[1] = yellow;
colors[2] = red;
pol = new LineStripArray(3, LineStripArray.COORDINATES,
stripCounts);
pol.setCoordinates(0, punti);
return pol;
}
public GraficaComp() {
setLayout(new BorderLayout());
Canvas3D superficie = new Canvas3D(null);
add("Center", superficie);
BranchGroup scena = createSceneGraph();
scena.compile();
SimpleUniverse simpleU = new SimpleUniverse(superficie);
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scena);
}
public BranchGroup createSceneGraph(){
BranchGroup objRoot = new BranchGroup();
objRoot.addChild(new Shape3D(poligono()));
return objRoot;
}
public static void main(String[] args){
Frame frame = new MainFrame(new GraficaComp(), 256, 256);
}
}
--
BADBOY - 29 Aug 2004 20:03 GMT
Try ading a ColorCube to the Branchgroup if this is viewable then add line
array to a TransformGroup
and change z coordinates (it might be too far away too see or too near -
behind front clip plane)
or simply call setNominalViewingTransform() after adding the branchgroup
as the view is being set at a nominal position to nothing.
> Hi,
> I'm from Italy so please forgive my English.
[quoted text clipped - 66 lines]
> }
> }
stoosh - 30 Aug 2004 09:37 GMT
> Try ading a ColorCube to the Branchgroup if this is viewable then add line
> array to a TransformGroup
> and change z coordinates (it might be too far away too see or too near -
> behind front clip plane)
> or simply call setNominalViewingTransform() after adding the branchgroup
> as the view is being set at a nominal position to nothing.
Thank you for your help.
I've tried, but I always get the black screen... if I use a ColorCube,
everything works fine.
I really don't know what to do...
--
BADBOY - 31 Aug 2004 11:42 GMT
A polygon is only viewable from 1 side so (its invisible from the other)
try creating it with points in reverse order.
> > Try ading a ColorCube to the Branchgroup if this is viewable then add line
> > array to a TransformGroup
[quoted text clipped - 7 lines]
> everything works fine.
> I really don't know what to do...
stoosh - 31 Aug 2004 16:04 GMT
I wanted to ask another thing... is it possible to modify a BranchGroup
and recompile the scene that I'm already viewing in the applet at
runtime, in order to dinamically add an object? I don't mean adding a
new branchgroup, but modify one already created in the simpleuniverse
(in
order to keep all the information about the viewer's position).
--
BADBOY - 01 Sep 2004 02:28 GMT
I dont beleive its possible to decompile a branchgroup after compiling it
(Some1 please correct me if i`m wrong)
I find its best to make your own universe class and subclass
VirtualUniverse
this gives you alot more control and enables you to have more than 1
ViewingPlatform
Keep views in their own Branchs separate from "content".
Personally i only compile branches that contain content that never changes
or only needs
Transform operations such as translate / rotate or scale.
If u search the web there are several papers relating to performance
regarding the compile method.
Have 1 content Branch that never gets removed and add all other content
branches to this.
Only BranchGroups maybe detach()ed from a live scenegraph so keep anything
that will be removed
from the scene in its own branch,
eg:- You have an car object made up of 5 different Shapes each with its own
Transformgroup. The car body and four wheels , the wheels added to the body
group and the body group added to a branchgroup. Say the car gets a punchure
and u need to change the geometry for a wheel:-
You would detach() the car's BranchGroup and iterate thru wheels to find the
punchured wheel(s),
Now the car's BranchGroup has been removed from the scene it is no longer
live so you can remove and add things to your hearts content. Then add the
BranchGroup back to the Node you detached it from.
Thats a little more than You asked for (Hey i waz bored! lol )
Keep at it !
Jonney
> I wanted to ask another thing... is it possible to modify a BranchGroup
> and recompile the scene that I'm already viewing in the applet at
> runtime, in order to dinamically add an object? I don't mean adding a
> new branchgroup, but modify one already created in the simpleuniverse
> (in
> order to keep all the information about the viewer's position).
Olivier - 31 Aug 2004 17:41 GMT
> A polygon is only viewable from 1 side so (its invisible from the other)
> try creating it with points in reverse order.
Or try using a PolygonAttributes and change the cull face to none.