... thank you Ricardo,

your code example runs - so it's a real proof, that it works and how to
interpret your advice.

Well, I think I can restrict to a single appearance.

So I will try to implement according your example.

This was really the fastest and most convincing way to answer my question

Horst

----- Original Message -----
From: "Ricardo Nakamura" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 09, 2003 4:13 PM
Subject: Re: [JAVA3D] adding objects to a life scene


> Hi,
>
>          If your objects can share the same appearance, you might try to
> use a single Shape3D and the addGeometry() / removeGeometry() methods. In
> this case, you can pre-transform your geometry to put it in the right
> position. (Some time ago, Florin Herinean wrote to this list about this
> technique.)
>          I see two drawbacks of this method: (1) it might take up more
> memory than sharing the spheres geometry (and using individual
branchgroups
> and transformgroups); (2) Java 3D probably will not be able to perform
> culling on that single Shape3D.
>
>          I am sending a small demo of this, attached to the message.
>
>
> Ricardo Nakamura
>
>
> At 10:05 9/7/2003, you wrote:
>
> >SiG Software Integration GmbHHi all,
> >
> >simple question: how can I add objects, e.g. simple spheres, to a life
> >graph?
> >
> >Background is: I like to dynamically add 3d-datapoints read from a
external
> >data feeding device each minute to even the same transformation group.
> >Depending on the users choice on the limit the oldest data points should
> >disappear then, while he still is able to rotate, translate an zoom it
> >manually.
> >
> >I have already learned from a posting of Nathalie (Nov 8, 2000), that I
have
> >to set for "each Group node in which I want to add or modify children I
must
> >set the capabilities ALLOW_CHILDREN_READ, ALLOW_CHILDREN_WRITE and/or
> >ALLOW_CHILDREN_EXTEND.
> >
> >Adding a new node results in the error message "only a BranchGroup node
may
> >be added".
> >
> >Does it mean, that I have to reconstruct my BranchGroup and compile it
every
> >time (every minute in my case) for all that hundreds or (depending on the
> >users choice) thousands of data points?
> >
> >If so - is there now workaround? Are there no "not so obvious features"
> >hidden somewhere in the deep j3d-structure, which could enable a more
> >flexible near life behaviour?
> >
> >I would be thankful for any hints, comments and of course a MiRCE
(minimal
> >running code example).
> >
> >thanks
> >
> >Horst
> >
> >
> >------------------------------------------------
> >
> >Dr. Horst Walther
> >SiG Software Integration GmbH
> >Chilehaus A * Fischertwiete 2
> >D-20095 Hamburg
> >phone: +49 40 32005 439
> >Fax & Voice-Mail: +49 40 8708306 8
> >Mobil & Voice box: +49 171 2145502
> >e-Mail:  [EMAIL PROTECTED]
> >WWW: http://www.si-G.com
> >
>
>===========================================================================
> >To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> >of the message "signoff JAVA3D-INTEREST".  For general help, send email
to
> >[EMAIL PROTECTED] and include in the body of the message "help".
> >
> >
> >
> >---
> >Incoming mail is certified Virus Free.
> >Checked by AVG anti-virus system (http://www.grisoft.com).
> >Version: 6.0.486 / Virus Database: 284 - Release Date: 29/5/2003
>
>


----------------------------------------------------------------------------
----


> import com.sun.j3d.utils.universe.*;
> import com.sun.j3d.utils.geometry.*;
> import javax.media.j3d.*;
> import javax.vecmath.*;
>
> import javax.swing.*;
> import java.awt.*;
> import java.awt.event.ActionListener;
> import java.awt.event.ActionEvent;
>
> import java.util.Enumeration;
>
> /**
>  * NewGeometryDemo
>  * a simple demo showing how to add geometry to a live scene
>  * using a single Shape3D
>  *
>  * @author  Ricardo Nakamura
>  * @version 1.0
>  *
> **/
>
> public class NewGeometryDemo implements ActionListener {
>   private Shape3D spheres;
>   private Transform3D t3d;
>   private Vector3d vec;
>   private Point3d coord;
>
>   public NewGeometryDemo() {
>     coord = new Point3d(0, 0, 0);
>
>     GraphicsConfiguration gc = SimpleUniverse.getPreferredConfiguration();
>     Canvas3D canvas = new Canvas3D(gc);
>     SimpleUniverse universe = new SimpleUniverse(canvas);
>
>     // move camera back
>     TransformGroup viewTG =
universe.getViewingPlatform().getViewPlatformTransform();
>     t3d = new Transform3D();
>     vec = new Vector3d(0, 0, 20);
>     t3d.setTranslation(vec);
>     viewTG.setTransform(t3d);
>
>     // create our empty Shape3D
>     spheres = new Shape3D();
>     Appearance app = new Appearance();
>     Material mat = new Material();
>     mat.setDiffuseColor(0.0f, 0.0f, 0.8f);
>     app.setMaterial(mat);
>     spheres.setAppearance(app);
>     // THIS IS ESSENTIAL -- SO WE CAN ADD MORE GEOMETRIES LATER
>     spheres.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
>
>     // add the Shape3D to the scene
>     BranchGroup spheresGroup = new BranchGroup();
>     spheresGroup.addChild(spheres);
>     universe.addBranchGraph(spheresGroup);
>
>     // create a lightsource
>     DirectionalLight dl = new DirectionalLight();
>     BoundingSphere bs = new BoundingSphere();
>     bs.setRadius(Double.POSITIVE_INFINITY);
>     dl.setInfluencingBounds(bs);
>     BranchGroup lightGroup = new BranchGroup();
>     lightGroup.addChild(dl);
>     universe.addBranchGraph(lightGroup);
>
>     // create a window
>     JFrame win = new JFrame("Geometry Addition Demo");
>     win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>     Container cp = win.getContentPane();
>     cp.setLayout(new BorderLayout());
>     cp.add(canvas, BorderLayout.CENTER);
>
>     // ... and a button to add new spheres
>     JButton addButton = new JButton("ADD");
>     addButton.addActionListener(this);
>     cp.add(addButton, BorderLayout.SOUTH);
>
>     win.setSize(400, 400);
>     win.show();
>   }
>
>   public void actionPerformed(ActionEvent e) {
>     // CHOOSE A RANDOM POSITION TO THE NEW SPHERE
>     vec.x = 10.0*Math.random() - 5.0;
>     vec.y = 10.0*Math.random() - 5.0;
>     vec.z = 10.0*Math.random() - 5.0;
>     t3d.set(vec);
>
>     // CREATE THE SPHERE GEOMETRY
>     int flags = Primitive.GENERATE_NORMALS |
Primitive.GEOMETRY_NOT_SHARED;
>     Sphere s = new Sphere(0.2f, flags, null);
>     Shape3D sphereShape = s.getShape();
>     // OBTAIN ALL SPHERE GEOMETRY ARRAYS - NOT SURE IF THERE IS MORE THAN
ONE
>     // BUT ANYWAY, IT CAN BE REUSED FOR OTHER SHAPES
>     Enumeration en = sphereShape.getAllGeometries();
>     while (en.hasMoreElements()) {
>       GeometryArray ga = (GeometryArray)en.nextElement();
>       int start = ga.getInitialVertexIndex();
>       int end = start + ga.getValidVertexCount();
>       // PRE-TRANSFORM ALL VERTICES
>       for (int i = start; i < end; i++) {
>         ga.getCoordinate(i, coord);
>         t3d.transform(coord);
>         ga.setCoordinate(i, coord);
>       }
>       // ADD EACH NEW GEOMETRY ARRAY TO THE EXISTING SHAPE3D
>       spheres.addGeometry(ga);
>     }
>   }
>
>   public static void main(String[] args) {
>     new NewGeometryDemo();
>   }
> }
>
>


----------------------------------------------------------------------------
----


>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.486 / Virus Database: 284 - Release Date: 29/5/2003
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to