Bonjour.

Après de nombreux efforts infructueux, je pense avoir trouvé la solution qui permet de réactualiser l'écran 3D, sans devoir reconstruire l'univers tout entier.
Je vous livre le code test:

Le principe consiste à créer un BranchGroup pour chaque objet à afficher.
Ce BranchGroup étant le parent du TransformGroup de l'objet.

Ici, on construit un univers avec 2 sphères, puis, après effacement des sphères, on en affiche une 3è.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
 
// Etape 1 :
// Importation des packages Java 2
import java.applet.Applet;
import java.awt.*;
 
// Etape 2 :
// Importation des packages Java 3D
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
 
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.media.j3d.Material;
import javax.vecmath.*;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.geometry.*;
 
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.Text2D;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.vecmath.Color3f;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.picking.behaviors.*;
import com.sun.j3d.utils.behaviors.keyboard.*;
import com.sun.j3d.utils.picking.*;
 
public class test_sphere extends Applet {
 
  BranchGroup BG_etoiles;
  TransformGroup TG, TG_global, tg1, tg2;
 
  public test_sphere() {
    this.setLayout(new BorderLayout());
 
    // Etape 3 :
    // Creation du Canvas 3D
    Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
 
    this.add(canvas3D, BorderLayout.CENTER);
 
    // Etape 4 :
    // Creation d'un objet SimpleUniverse
    SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
 
    // Etape 5 :
    // Positionnement du point d'observation pour avoir une vue correcte de la
    // scene 3D
    simpleU.getViewingPlatform().setNominalViewingTransform();
 
    // Etape 6 :
    // Creation de la scene 3D qui contient tous les objets 3D que l'on veut visualiser
    BranchGroup scene = createSceneGraph();
 
    // Etape 7 :
    // Compilation de la scene 3D
    scene.compile();
 
    // Etape 8:
    // Attachement de la scene 3D a l'objet SimpleUniverse
    simpleU.addBranchGraph(scene);
 
    actualiser();
  }
 
  /**
   * Creation de la scene 3D qui contient tous les objets 3D
   * @return scene 3D
   */
  public BranchGroup createSceneGraph() {
    // Creation de l'objet parent qui contiendra tous les autres objets 3D
    BranchGroup parent = new BranchGroup();
 
    /************ Partie de code concernant l'animation *************/
    /* Elle sera expliquee en details dans les chapitres relatifs aux
     transformations geometriques et aux animations */
    TG_global = new TransformGroup();
    TG_global.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    TG_global.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    TG_global.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
    TG_global.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
 
    TG = new TransformGroup();
    TG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    TG.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    TG.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
 
    // Arriere plan en blanc
    Background background = new Background(1, 1, 1);
    background.setApplicationBounds(new BoundingBox());
    parent.addChild(background);
 
    parent.addChild(TG_global);
 
    BG_etoiles=new BranchGroup();
    BG_etoiles.setCapability(BranchGroup.ALLOW_DETACH);
    BG_etoiles.setUserData("etoile");
 
    Transform3D t3d;
    (t3d = new Transform3D()).setTranslation(new Vector3f(-0.50f,-0.25f,0.0f));
    tg1 = new TransformGroup(t3d);
    tg1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tg1.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    tg1.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
 
    Sphere s=new Sphere(0.25f);
    tg1.addChild(s);
    BG_etoiles.addChild(tg1);
 
    Transform3D t3d2;
    (t3d2 = new Transform3D()).setTranslation(new Vector3f(0.50f,0.25f,0.0f));
    tg2 = new TransformGroup(t3d2);
    tg2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tg2.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    tg2.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
 
    Sphere s2=new Sphere(0.25f);
    tg2.addChild(s2);
    BG_etoiles.addChild(tg2);
 
    TG_global.addChild(BG_etoiles);
 
    return parent;
  }
 
 void actualiser()
      {
      // On enlève le BranchGroup contenant la sphère.  
 
      for (int kk=0;kk<TG_global.numChildren();kk++)
           {
           String s=(String) TG_global.getChild(kk).getUserData();
 
           System.out.println(kk+" "+s+" "+TG_global.getChild(0).toString());
 
           if (s.equals("etoile")) TG_global.removeChild(kk);
           }
 
       // On reconstruit le BranchGroup contenant la sphère.
 
    BG_etoiles=new BranchGroup();
    BG_etoiles.setCapability(BranchGroup.ALLOW_DETACH);
    BG_etoiles.setUserData("etoile");
 
    Transform3D t3d;
    (t3d = new Transform3D()).setTranslation(new Vector3f(0.0f,0.0f,0.0f));
    tg1 = new TransformGroup(t3d);
    tg1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tg1.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    tg1.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
 
    Sphere s=new Sphere(0.05f);
    tg1.addChild(s);
    BG_etoiles.addChild(tg1);
    TG_global.addChild(BG_etoiles);
    }
 
  /**
   * Etape 9 :
   * Methode main() nous permettant d'utiliser cette classe comme une applet
   * ou une application.
   * @param args
   */
  public static void main(String[] args) {
    Frame frame = new MainFrame(new test_sphere(), 1440, 900);
  }
}