gunjannigam 28 Junior Poster

I have a code in Java 3D through which I can draw a static(all verticies are known before hand) 3D curve.
But I want to draw a dynamic(vertices specified at they at run time) curve, and the number of vertices keeps on adding up.

This is the code for static curve.

public Shape3D createCurve(){

    int steps = 200;
    
    Point3d[] coords = new Point3d[steps];
    for (int i = 0; i < coords.length; i++) {
        coords[i] = new Point3d(x,Math.sin(x*10),Math.cos(x*10));
        x += 0.01;
    }
    int[] strip = {steps};
    LineStripArray lsa = new LineStripArray(steps, LineStripArray.COORDINATES|LineStripArray.COLOR_3, strip);
    Color3f colors[] = new Color3f[steps];        //array of colors
      for(int v = 0; v < steps; v++)
      {            //set the remaining colors
          colors[v] = new Color3f(Color.ORANGE);
      }
    lsa.setColors(0, colors);
    lsa.setCoordinates(0, coords);
    Appearance app = new Appearance();
    app.setLineAttributes(new LineAttributes(1.5f, LineAttributes.PATTERN_SOLID, true));

        return new Shape3D(lsa, app);
    }

This curve is added to a BranchGroup() and then the group is compiled. For dynamic curve, I thought of increasing the no of steps using Timer and than generating new curve and then remove old from the TransformGroup and adding the new one.But that gives an exception

Exception in thread "AWT-EventQueue-0" javax.media.j3d.RestrictedAccessException: Group: only a BranchGroup node may be removed
        at javax.media.j3d.Group.removeChild(Group.java:350)

Please explain how to draw dynamic curve in Java 3D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.