Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (727)
Games in Android Showcase (217)
games submitted by our members
Games in WIP (796)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java 3D / Re: adding a branchgroup to a live scene with swing buttons on: 2006-01-04 02:54:00
I've modified the code and I don' t have the exception anymore. But,  when i press the button several times :


action ajout


action ajout

Which seems to be normal.

look at the code hereafter (this is the complete class). The sphere is still not seen, but i've put some attributes to it.

import java.awt.*;
import java.awt.GraphicsConfiguration;
import java.awt.event.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.behaviors.keyboard.*;

import javax.vecmath.*;

import javax.swing.*;

public class Scene3Db extends JFrame implements ActionListener, MouseListener {

   private static final long serialVersionUID = 1L;
   private SimpleUniverse su;
    private BranchGroup sceneBG, mainBG, shapeBG, objRoot;
    private TransformGroup mainTG, shapeTG, cameraTG;
    private BoundingSphere bounds;
    private Material material2;
    private static int mycount = 1;

    //declaration des elements du gui
    private JLabel etiq1;

    private JCheckBox couleur;

    public Scene3Db() {
        Container contentPane = getContentPane();
        //BorderLayout bl = new BorderLayout();

        GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
        Canvas3D c = new Canvas3D(config);
        contentPane.add("Center", c);

        JPanel p1 = new JPanel();
        contentPane.add("North", p1);

        JPanel p2 = new JPanel();
        JButton ajout = new JButton("Ajout");
        addObject addObjBG = new addObject();
        //objRoot.addChild(addObjBG); //pb !
        contentPane.add("South", p2);

        SimpleUniverse su = new SimpleUniverse(c);
        BranchGroup scene = createSceneGraph(su);
        //scene.setCapability( BranchGroup.ALLOW_BOUNDS_READ );

        addWindowListener( new WindowAdapter() {
        public void windowClosing(WindowEvent e) {System.exit(0);}});

        setSize(800,600); //Taille Fenetre

    //création du graphe de scène
    public BranchGroup createSceneGraph(SimpleUniverse su) {

    //création d'un BG racine de l'arbre 3D
    BranchGroup objRoot = new BranchGroup();
    objRoot.setCapability( BranchGroup.ALLOW_PICKABLE_READ );
    objRoot.setCapability( BranchGroup.ALLOW_PICKABLE_WRITE );


        //création d'un bounds pour le fond et la lumière
        BoundingSphere bounds =
        new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
        Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
        Background bg = new Background(bgColor);

        Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
        Vector3f light1Direction  = new Vector3f(4.0f, -7.0f, -12.0f);

        DirectionalLight light1
            = new DirectionalLight(light1Color, light1Direction);

        BranchGroup sceneObj = new BranchGroup();

        //création d'un TG pour la gestion d'échelle
        TransformGroup objScale = new TransformGroup();
        Transform3D t3d = new Transform3D();

        //création d'un TG pour permettre la modification des objets visuels
        TransformGroup objTrans = new TransformGroup();

        MouseRotate myMouseRotate = new MouseRotate();
        myMouseRotate.setSchedulingBounds(new BoundingSphere());

        MouseTranslate myMouseTranslate = new MouseTranslate();
        myMouseTranslate.setSchedulingBounds(new BoundingSphere());

        MouseZoom myMouseZoom = new MouseZoom();
        myMouseZoom.setSchedulingBounds(new BoundingSphere());

        Vector3f translate = new Vector3f();
        Transform3D T3D = new Transform3D();
        TransformGroup TG = null;
        TransformGroup vpTrans = null;
        SharedGroup share = new SharedGroup();

        float[][] position = {{  0.0f, 0.0f,  -3.0f},
                              {  6.0f, 0.0f,   0.0f},
                              {  6.0f, 0.0f,   6.0f},
                              {  3.0f, 0.0f, -10.0f},
                              { 13.0f, 0.0f, -30.0f},
                              {-13.0f, 0.0f,  30.0f},
                              {-13.0f, 0.0f,  23.0f},
                              { 13.0f, 0.0f,   3.0f}};

        for (int i = 0; i < position.length; i++){
               TG = new TransformGroup(T3D);
                TG.addChild(new Link(share));
        vpTrans = su.getViewingPlatform().getViewPlatformTransform();
        translate.set( 0.0f, 0.3f, 0.0f);


        KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans);
        keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(),1000.0));

        //Canvas3D c = new Canvas3D(null);
        //PickHighlightBehavior pickBeh = new
                  //PickHighlightBehavior(c, objRoot, bounds);

        BranchGroup  b2 = new addObject();
        //System.out.println("br "+b2);
        return objRoot;

    public JPanel presentationPanel() {
   JPanel panel1 = new JPanel();
        etiq1 = new JLabel
        ("Modelisation d'un environnement naturel en 3D / © 2005 cnam ubo");

        return panel1;
        //fonction ajout d'objet
        private class addObject extends BranchGroup implements ActionListener {
                private addObject () {
                public void actionPerformed(ActionEvent event){
                      BranchGroup obj = new BranchGroup ();
                      // Création d'une sphère
                      Sphere sphere = new Sphere (0.3f, Sphere.GENERATE_NORMALS, 20);
                      Transform3D sphereRandromTransform = new Transform3D ();
                      sphereRandromTransform.setTranslation(new Vector3d(randomCoord(),randomCoord(),randomCoord()));
                      TransformGroup sphereTG = new TransformGroup (sphereRandromTransform);
                      System.out.println("action ajout");
        private double randomCoord () {
            double coord = Math.random();
            return coord>=0.5?-coord*5:coord*5;
        public void mouseClicked( MouseEvent e ) {
        public void mouseEntered( MouseEvent e ) {
        public void mouseExited( MouseEvent e ) {
        public void mousePressed( MouseEvent e ) {
        // if (e.getSource()==reset) {
        public void mouseReleased( MouseEvent e ) {
        //mode = STILL;
        public void actionPerformed(ActionEvent e) {
        Object target = e.getSource();
          if (target == couleur) {
            if (couleur.isSelected()){
        public static void main(String[] args) {

             try {
                  //Définition du type d'affichage boite de dialogue
      } catch (Exception exc) {
                  System.err.println("Erreur de chargement L&F: " + exc);
                new Scene3Db();

In fact I have this

java.lang.NullPointerException :

   at applet3d.Scene3Db.<init>(

   at applet3d.Scene3Db.main(

when I want to attach the new object to the main branchgroup

any idea ?

2  Java Game APIs & Engines / Java 3D / adding a branchgroup to a live scene with swing buttons on: 2006-01-02 13:21:25

Hi, please have a look on the following code.
I want to add "objects" in a live scene.
I've planned to do this by attaching a new branchgroup
to an existing alive structure.
The code of the new branchgroup is in the action of a swing button.

// method "addObject" called by the button

    private class addObject extends BranchGroup implements ActionListener {
        public void actionPerformed(ActionEvent event){
          BranchGroup obj = new BranchGroup ();
          // Creation of a sphere
          Sphere sphere = new Sphere (0.3f);
          obj.addChild (sphere);
          obj.addChild (this);
          System.out.println("add action");

// definition of the button

   private JButton ajout = new JButton("Ajout");
          JPanel p2 = new JPanel();
        ajout.addActionListener(new addObject());

// code to attach the branchgroup

   BranchGroup  b2 = new addObject();
        System.out.println("br "+b2);
        return objRoot;

But, the Sphere is not seen on the scene
even if the action on the button seems to work.
And if i do twice, i get this error :

Exception occurred during event dispatching: Group.addChild: child already has a parent




   at applet3d.Scene3D$addObject.actionPerformed(

   at javax.swing.AbstractButton.fireActionPerformed(

   at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(

   at javax.swing.DefaultButtonModel.fireActionPerformed(

   at javax.swing.DefaultButtonModel.setPressed(

   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(

   at java.awt.Component.processMouseEvent(

   at java.awt.Component.processEvent(

   at java.awt.Container.processEvent(

   at java.awt.Component.dispatchEventImpl(

   at java.awt.Container.dispatchEventImpl(

   at java.awt.Component.dispatchEvent(

   at java.awt.LightweightDispatcher.retargetMouseEvent(

   at java.awt.LightweightDispatcher.processMouseEvent(

   at java.awt.LightweightDispatcher.dispatchEvent(

   at java.awt.Container.dispatchEventImpl(

   at java.awt.Window.dispatchEventImpl(

   at java.awt.Component.dispatchEvent(

   at java.awt.EventQueue.dispatchEvent(

   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(

   at java.awt.EventDispatchThread.pumpEventsForHierarchy(

   at java.awt.EventDispatchThread.pumpEvents(


Anyone can help ?

3  Java Game APIs & Engines / Java 3D / sharing canvas exception pb on: 2005-12-15 11:53:47 Sharing canvas with multiple views


   at com.sun.j3d.utils.universe.Viewer.<init>(

   at com.sun.j3d.utils.universe.Viewer.<init>(

   at com.sun.j3d.utils.universe.SimpleUniverse.<init>(

   at com.sun.j3d.utils.universe.SimpleUniverse.<init>(

   at com.sun.j3d.utils.universe.SimpleUniverse.<init>(

   at konno.Konno1.<init>(

   at konno.Konno1.main(

Any idea of why getting this exception, and in which type of config  ?

4  Java Game APIs & Engines / Java 3D / changing color on an object with clickbehavior on: 2005-12-04 22:38:45

any idea of finding a peace of code for changing color on an object with
clickbehavior ?

For changing texture also.

5  Java Game APIs & Engines / Java 3D / Attaching a J3D branchgroup to cyberVRML97 scene graph on: 2005-11-29 22:18:15


I would like to know if someone has alredy faced the problem of attaching
let's say a "normal" branchgroup to the specific scene graph structure of

help greatly appreciated.

6  Java Game APIs & Engines / Java 3D / Attaching a scenegraph to a branchgroup ? on: 2005-11-19 13:31:02


I've taken a program to create scenegraph from a wrml file (cybervrml97).
That works fine. But what I want to do now is to "connect" this scenegraph
to a J3D hierarchy that I've created by myself: branchgroup, transformgroups...

Do you think I can make this connection by the mean of a branchgroup or transformgroup ?
The scenegraph I've mentionned is displaved directly through a canvas.

Any Idea ?

7  Java Game APIs & Engines / Java 3D / Re: saving a java3D scene on: 2005-11-19 13:29:07
Hi, gents  Smiley

I've found what I was looking for : a X3D, VRML saver for Java3D.
That Works fine.

Please have a look on N.Konno "VRMLPlayer".
Then download the sources from sourceforge.



8  Java Game APIs & Engines / Java 3D / Fusion, merging of Visual objects in J3D on: 2005-11-09 16:47:25

Does anybody know if it is possible to merge to visual objects in java3D.
i.e. two cube are moved separetely. Wgen they touch (collision), possibility to "regroup" them as one single object.


9  Java Game APIs & Engines / Java 3D / Re: appearance management for loaded objects on: 2005-11-08 21:21:19
Thanks Jeff,
I ve taken the documentation for my loader : vrmlLoader(). It has 75 pages and it is a bit tricky.
So if you remember the name of the utility to traverse the graph ...

many thanks
10  Java Game APIs & Engines / Java 3D / saving a java3D scene on: 2005-11-06 20:20:10
Anyone knows ways and formats supported by java3D in saving and exporting ?

help greatly appreciated.
11  Java Game APIs & Engines / Java 3D / appearance management for loaded objects on: 2005-11-06 19:50:41

Is it a way to manage the appearance for a loaded object (color, texture)?
I have a example with a vrml loaded scene that i woul dlike to modify.
But it is present in my scene as a branchgroup :

BranchGroup b1 = new vrmlLoad("7.wrl");

How is it possible to assign an appearance to this ?
how to link this branchgroup with a shape3D (if shape3D is the solution) ?.
After that, i imagine that to create an appearance for this shape
and modify the capability bits.

Any idea ?
12  Java Game APIs & Engines / Java 3D / splitting feature in J3D on: 2005-11-03 19:42:55

Does anybody knows a way to split a visual object in java3D ?
 ie : a cube : a picking behavior with a mouse and the cube is
splitted in two "half "cubes.

any idea ?
13  Java Game APIs & Engines / Java 3D / group feature in j3d ? regrouping visual objects on: 2005-11-02 22:18:22

Is it possible in Jva3D to regroup visual objects?
I mean two leaves (i.e.geometric form of the same
branchgroup or different branchgroups?) are selected
by the mouse and then become the same object.
For instance , like the group feature in drawing Powerpoint.

Any idea ?


14  Java Game APIs & Engines / Java 3D / assign a texture by clicking on a specific object on: 2005-10-23 21:49:19
Hello there,
I have a certain number of objects in a live scene (cubes,
boxeq, cones...)
I would like to assign a texture on a object by cicking on it.
I assume that a mouse pick feature and the standart
texture assignment.
But how to link to two actions ?

Any idea ?

15  Java Game APIs & Engines / Java 3D / Saving J3D objects in ASE Format ? on: 2005-10-19 18:45:10


I would like to save objects (simple, composed) build in a J3D scene to the ASE format.

Has somedy done this before or know interesting ressources ?


16  Java Game APIs & Engines / Java 3D / Adding a goemetry object in an already started applet, behavior ? on: 2005-10-17 20:56:03

Hello there,

I would like to add a geometric form (cube, box, cone etc..) in an already
started applet. I think creating a specific behavior would be the most

Has anybody done this kind of thing before ?
or Any procedure ?

Many thanks.

17  Java Game APIs & Engines / Java 3D / Re: anyone know of any good beginners tutorials for Java3d? on: 2005-10-17 20:53:37
Take the "Getting started with the java 3D API" from SUN : 7 chapters, organised by topics, very clear, examples to download.
Nothing more to say.

spytox3 Cool
18  Java Game APIs & Engines / Java 3D / vrml97 to J3D : parsing error : pixel texture on: 2005-10-17 20:42:06
I've recently used a vrml97 loader for j3d and it is working fine, with the demo files. But when I load another file coming from another application
(in the same version : 97) I have a parsing error :

Exception: com.sun.j3d.loaders.vrml97.impl.ParseException: Unknown node type: PixelTexture
Last token was "PixelTexture" at line 5187
com.sun.j3d.loaders.vrml97.impl.ParseException: Unknown node type: PixelTexture

Does somedy already met the problem ?
I'm trying to find a parser on the net but that is not easy.
Is it better to create my own parser ?
Somebody can help me ?

Pages: [1]
Archive (294 views)
2017-04-27 17:45:51

buddyBro (483 views)
2017-04-05 03:38:00

CopyableCougar4 (927 views)
2017-03-24 15:39:42

theagentd (941 views)
2017-03-24 15:32:08

Rule (952 views)
2017-03-19 12:43:22

Rule (921 views)
2017-03-19 12:42:17

Rule (922 views)
2017-03-19 12:36:21

theagentd (984 views)
2017-03-16 05:07:07

theagentd (897 views)
2017-03-15 22:37:06

theagentd (693 views)
2017-03-15 22:32:18
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!