IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

3D Java Discussion :

Intégrer un objet 3D dans un JPanel


Sujet :

3D Java

  1. #1
    Invité
    Invité(e)
    Par défaut Intégrer un objet 3D dans un JPanel
    Bonjour,

    J'ai modélisé un objet 3D avec blender que j'ai exporté en .obj, j'arrive à l'afficher correctement à partir d'une MainFrame et d'un Applet.

    Mais je voudrais l'afficher dans un JPanel que j'intégrerai ensuite à une JFrame, comment faire ?

    Sinon est-il possible d'intégrer un Appel à un JPanel ?

    Merci d'avance
    Simon.

  2. #2
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    quelle API veux tu utiliser?

    Normalement tu peux intégrer n'importe quel composant AWT dans une application Swing, en respectant quelques contraintes.

    cf http://docs.oracle.com/javase/7/docs...wt.html#gdaduc
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2010
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Avril 2010
    Messages : 22
    Points : 34
    Points
    34
    Par défaut
    Bonsoir,
    On peut exporter l'objet 3D sous forme d'un fichier ".x" et récupérer les cordonnées de l'objet (Cela est faisable en webGL (javascript) et je ne sais pas si c'est possible dans un application Swing)

  4. #4
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Merci de vos réponses

    En fait suite à ma question j'ai pas mal cherché et j'ai finis par arriver à afficher mon objet 3D dans un JPanel, et ensuite l'intégrer à une JInternalframe ou une JFrame.

    Mais mon problème est que je n'arrive à l'affiche seulement en faisant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
            this.getContentPane().removeAll();
            this.setContentPane(totem);
            totem.setVisible(true);
            totem.repaint();
    Avec this une JIF et totem un objet d'une classe héritant JPanel. Cette classe contient différente méthodes qui permettent l'affichage d'un objet 3D à partir d'un fichier .obj.
    Là, l'objet s'affiche, mais moi je ne voudrais pas afficher que ça dans ma JIF, je veux afficher d'autres éléments, ainsi j'ai voulus utiliser le GridBagLayout en faisant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
            this.setLayout(new GridBagLayout());
            contraintes = new GridBagConstraints();  
     
            contraintes.gridx = 0;
            contraintes.gridy = 0;
            this.add(totem, contraintes);    
            totem.repaint();
    Et là rien de s'affiche du tout ..

    Alors que avec une autre classe qui étend aussi JPanel, mais qui ne contient que des boutons, labels etc ça marche.

    Si vous aviez des idées
    Merci,
    Simon.

  5. #5
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Il faudra placer d'autres contraintes telles que le fill, le poids horizontal et vertical.

    Et il faut aussi que ton composant calcule correctement sa preferredSize, autant que possible.
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  6. #6
    Invité
    Invité(e)
    Par défaut
    Il faudra placer d'autres contraintes telles que le fill, le poids horizontal et vertical.
    Quelles fonctions faut-il utiliser pour définir les poids ?


    Et il faut aussi que ton composant calcule correctement sa preferredSize, autant que possible.
    Donc il faut que je fasse un setPreferedSize() sur totem ?

    Je vais essayer tout ça et je vous tiens au courant.

    Merci

    Simon

  7. #7
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  8. #8
    Invité
    Invité(e)
    Par défaut
    Bonjour

    J'ai ajouté comme tu me la dit, un setPreferedSize() à totem et il s'affiche.

    Mais en fait je voudrais améliorer mon application :

    Je voudrais via la palette netBeans positionner mes différents JPanel dans ma JInternalfrme et ensuite ajouter à mon JPanel central mon objet 3D,

    Hors je n'y arrive pas ...

    Voici le code de ma classe qui importe le .obj :

    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
     
    package projet_tutore_simon;
     
     
    import com.sun.j3d.loaders.IncorrectFormatException;
    import com.sun.j3d.loaders.ParsingErrorException;
    import com.sun.j3d.loaders.Scene;
    import com.sun.j3d.loaders.objectfile.ObjectFile;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
    import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
    import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
    import com.sun.j3d.utils.universe.SimpleUniverse;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Frame;
    import java.io.FileNotFoundException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.media.j3d.AmbientLight;
    import javax.media.j3d.BoundingSphere;
    import javax.media.j3d.BranchGroup;
    import javax.media.j3d.Canvas3D;
    import javax.media.j3d.DirectionalLight;
    import javax.media.j3d.Light;
    import javax.media.j3d.TransformGroup;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.vecmath.Color3f;
    import javax.vecmath.Point3d;
    import javax.vecmath.Vector3f;
     
     
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author Sayce
     */
    public class Objet3D extends JPanel {
     
     
        private static boolean panel = true;
     
        public Objet3D()
        {
            if(!panel)
            {
                lanceApplication();
            }
        }
     
     
        public void lanceApplication()
        {
     
            this.setLayout(new BorderLayout());
     
            Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
     
            this.add(canvas3D, BorderLayout.CENTER);
     
            SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
     
            simpleU.getViewingPlatform().setNominalViewingTransform();
     
            BranchGroup scene = createSceneGraph();
     
            scene.compile();
     
            simpleU.addBranchGraph(scene);  
     
        }
     
     
        public BranchGroup createSceneGraph() {
     
        BranchGroup parent = new BranchGroup();
     
        BoundingSphere bounds = new BoundingSphere(new Point3d(), 100);
        Light ambientLight = new AmbientLight(new Color3f(Color.white));    // Modifis couleur lumiere
        ambientLight.setInfluencingBounds(bounds);
        parent.addChild(ambientLight);
     
        Light directionalLight = new DirectionalLight(
          new Color3f(Color.white),
          new Vector3f(1, -1, -1));
        directionalLight.setInfluencingBounds(bounds);
        parent.addChild(directionalLight);
     
        TransformGroup mouseTransform = new TransformGroup();
     
        // Le groupe de transformation sera modifie par le comportement de la
        // souris
        mouseTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        mouseTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
     
        // Creation comportement rotation a la souris
        MouseRotate rotate = new MouseRotate(mouseTransform);
        rotate.setSchedulingBounds(new BoundingSphere());
        parent.addChild(rotate);
     
        // Creation comportement deplacement a la souris
        MouseTranslate translate = new MouseTranslate(mouseTransform);
        translate.setSchedulingBounds(new BoundingSphere());
        parent.addChild(translate);
     
        // Creation comportement zoom a la souris
        MouseZoom zoom = new MouseZoom(mouseTransform);
        zoom.setSchedulingBounds(new BoundingSphere());
        parent.addChild(zoom);
     
        // Chargement de l'objet Wavefront et ajout au graphe de la scene
        mouseTransform.addChild(loadWavefrontObject());
        parent.addChild(mouseTransform);
     
        return parent;    
        }
     
     
        private BranchGroup loadWavefrontObject() {
     
        String filename = "Totem_Simon_1.obj";
        ObjectFile waveFrontObject = new ObjectFile(ObjectFile.RESIZE);
        Scene scene = null;
        int error = 0;
     
        try {
          if (!panel) {
            scene = waveFrontObject.load(filename);
          }
        }  // fin try
        catch (ParsingErrorException ex) {
          System.out.println("Fichier defectueux : "+ex.getMessage());
          error = -1;
        }
        catch (IncorrectFormatException ex) {
          System.out.println("Mauvais format de fichier");
          error = -1;
        }
        catch (FileNotFoundException ex) {
          System.out.println("Fichier " + filename + " non trouve");
          error = -1;
        }
     
        if (error != 0) {
                System.exit(error);
            }
     
        return scene.getSceneGroup();    
     
        }    
     
        public static boolean isPanel() {
            return panel;
        }
     
        public static void setPanel(boolean panel) {
            Objet3D.panel = panel;
        }
    }
    Comme vous le voyez ma classe étends JPanel, ainsi je ne peux pas l'ajouter à un autre JPanel que j'aurais placé via la palette netBeans.

    Avez vous des idées ?

    Merci
    Simon

  9. #9
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Intégrer un objet select dans une form
    Par jpwitz dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 06/02/2013, 10h07
  2. Réponses: 11
    Dernier message: 08/08/2006, 23h11
  3. Insérer un tableau d'objet dans un Jpanel
    Par Flophx dans le forum AWT/Swing
    Réponses: 6
    Dernier message: 25/04/2006, 20h37
  4. Déplacer des objets dans un JPanel
    Par hammag dans le forum AWT/Swing
    Réponses: 6
    Dernier message: 23/03/2006, 11h13
  5. [JPanel] parcours d'objets dans un JPanel
    Par fleur1234 dans le forum Agents de placement/Fenêtres
    Réponses: 3
    Dernier message: 17/01/2005, 13h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo