Java3D : Géométrie tronquée par un plan - Programmation
TomsGuide.com : 700 000 inscrits répondent à toutes vos questions high-tech et informatique.
Pour obtenir de l'aide, inscrivez-vous gratuitement !
 

Ajouter une réponse



 Mot :   Pseudo :  
 
Bas de page
Auteur
 Sujet : Java3D : Géométrie tronquée par un plan
 
Graph | H&L | Sex
Profil : QuasiModo
Plus d'informations

Bonjour,

Donc voila, le titre est assez explicite je pense ! Je cherche à tronquer une géométrie avec l'API Java3D !

Exemple : Un cone couper par un plan, on n'affiche que ce qui se trouve d'un coté du plan.

J'espère que l'un d'entre vous connais Java3D ...

:D


Message édité par RedTux le 15-04-2008 à 11:20:49

---------------
N'oubliez pas le [Résolu] dans le titre si vous êtes satisfait.
Les règles du Forum - À lire absolument
Liens spon sorisés

Inscrivez-vous ou connectez-vous pour masquer ceci.

Paranoid Android
Profil : IDNaute
Plus d'informations

Désolé, connais pas.

mais il y a quelques tuto sur le net.


---------------
Don't panic!
mouths91 à dit : "[...]des rageux comme kelnem"
Graph | H&L | Sex
Profil : QuasiModo
Plus d'informations

Ouais ... pas trouvé ce qu'il me faut ... Tous les tutos montrent comment faire une sphère, un cône, etc.
Mais aucun ne montre un objet scindé ! :o

Ça m'énerve !


---------------
N'oubliez pas le [Résolu] dans le titre si vous êtes satisfait.
Les règles du Forum - À lire absolument
Graph | H&L | Sex
Profil : QuasiModo
Plus d'informations

J'ai enfin trouvé !

 

Pas évident :o

 

Donc, pour ceux qui sont intéréssé : ModelClip
Qui s'applique à un : TransformGroup

 

Voila ... si vous voulez un petit exemple :
http://img519.imageshack.us/img519/8541/3dscreenwr6.jpg

Code :
  1. import java.awt.*;
  2. import java.awt.event.WindowAdapter;
  3. import java.awt.event.WindowEvent;
  4. import com.sun.j3d.utils.geometry.*;
  5. import com.sun.j3d.utils.universe.*;
  6. import javax.media.j3d.*;
  7. import javax.vecmath.*;
  8. public class SimpleClip extends Frame {
  9.     /**
  10.         Fonction de création de la scène 3D
  11.     */
  12.     public BranchGroup createSceneGraph(SimpleUniverse u) {
  13.         // Objet Root
  14.         BranchGroup objRoot = new BranchGroup();
  15.         // Paramétrage de l'eclairage
  16.         BoundingSphere bounds;
  17.         bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
  18.         Vector3f ldir = new Vector3f(1.0F,-1.0F,-1.0F);
  19.         Color3f lcouldl = new Color3f(1.0F,1.0F,1.0F);
  20.         DirectionalLight dl = new DirectionalLight(lcouldl,ldir);
  21.         dl.setInfluencingBounds(bounds);
  22.         objRoot.addChild(dl);
  23.         Color3f lColor1 = new Color3f(0.5f,0.0f,0.5f);
  24.         Vector3f lDir1  = new Vector3f(-1.0f,-1.0f,1.0f);
  25.         DirectionalLight lgt1 = new DirectionalLight(lColor1,lDir1);
  26.         lgt1.setInfluencingBounds(bounds);
  27.         objRoot.addChild(lgt1);
  28.         Vector3f lDir2  = new Vector3f(1.0f,1.0f,-1.0f);
  29.         Color3f lColor2 = new Color3f(0.7f,0.7f,0.0f);
  30.         DirectionalLight lgt2 = new DirectionalLight(lColor2,lDir2);
  31.         lgt2.setInfluencingBounds(bounds);
  32.         objRoot.addChild(lgt2);
  33.         // Configuration des géométries
  34.         {    // Un cylindre
  35.             TransformGroup objTrans = new TransformGroup();
  36.             objRoot.addChild(objTrans);
  37.             Transform3D t3D = new Transform3D();
  38.             t3D.setRotation(new AxisAngle4d(-1.0,2.0,-1.0,Math.PI/5.0)) ;
  39.             objTrans.setTransform(t3D);
  40.             Appearance a = new Appearance();
  41.             Material m = new Material();
  42.             m.setDiffuseColor(0.3f,0.7f,1.0f);
  43.             PolygonAttributes attr = new PolygonAttributes();
  44.             attr.setCullFace(PolygonAttributes.CULL_NONE);
  45.             a.setPolygonAttributes(attr);
  46.             a.setMaterial(m);
  47.             objTrans.addChild(new Cylinder(0.4F,0.9F,1,70,70,a));
  48.         }
  49.         {    // Un cube/pavé ...
  50.             TransformGroup objTrans = new TransformGroup();
  51.             objRoot.addChild(objTrans);
  52.             Transform3D t3D = new Transform3D();
  53.             t3D.setRotation(new AxisAngle4d(1.0,2.0,1.0,Math.PI/5.0)) ;
  54.             objTrans.setTransform(t3D);
  55.             Appearance a = new Appearance();
  56.             Material m = new Material();
  57.             m.setDiffuseColor(1.0f,0.6f,0.4f);
  58.             m.setAmbientColor(0.4f,0.2f,0.1f);
  59.             PolygonAttributes attr = new PolygonAttributes();
  60.             attr.setCullFace(PolygonAttributes.CULL_NONE);
  61.             a.setPolygonAttributes(attr);
  62.             a.setMaterial(m);
  63.             objTrans.addChild(new Box(0.25F,0.45F,0.6F,a));
  64.         }
  65.         // Configuration des coupes et de leurs rotations (animations)
  66.         {
  67.             ModelClip mc = new ModelClip();
  68.             boolean enables[] = {false,false,false,false,false,false};
  69.             Vector4d eqn1 = new Vector4d(0.0,1.0,0.0,0.0);
  70.             Vector4d eqn2 = new Vector4d(1.0,1.0,0.0,0.0);
  71.             mc.setEnables(enables);
  72.             mc.setPlane(1,eqn1);
  73.             mc.setPlane(2,eqn2);
  74.             mc.setEnable(1,true);
  75.             mc.setEnable(2,true);
  76.             mc.setInfluencingBounds(bounds);
  77.             TransformGroup objTrans1 = new TransformGroup();
  78.             objRoot.addChild(objTrans1);
  79.             objTrans1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
  80.             Transform3D yAxis = new Transform3D();
  81.             Alpha rotationAlpha;
  82.             rotationAlpha = new Alpha(-1,
  83.                                       Alpha.INCREASING_ENABLE,
  84.                                       0,0,
  85.                                       4000,0,0,
  86.                                       0,0,0);
  87.             RotationInterpolator rotator;
  88.             rotator = new RotationInterpolator( rotationAlpha,
  89.                                                 objTrans1,
  90.                                                 yAxis,
  91.                                                 0.0f,
  92.                                                 (float) Math.PI*2.0f);
  93.             rotator.setSchedulingBounds(bounds);
  94.             objTrans1.addChild(rotator);
  95.             TransformGroup objTrans2 = new TransformGroup();
  96.             objTrans1.addChild(objTrans2);
  97.             Transform3D t3D = new Transform3D();
  98.             t3D.setRotation(new AxisAngle4d(1.0,1.0,0.0,Math.PI/5.0)) ;
  99.             objTrans2.setTransform(t3D);
  100.             objTrans2.addChild(mc);
  101.         }
  102.         // Compilation de la scène
  103.         objRoot.compile();
  104.         return objRoot;
  105.     }
  106.     /**
  107.         Constructeur
  108.     */
  109.     public SimpleClip() {
  110.         setLayout(new BorderLayout());
  111.         // Paramètrage de Java3D, récupération de l'envirronement graphique
  112.         GraphicsConfiguration config;
  113.         config = SimpleUniverse.getPreferredConfiguration();
  114.         // Création du canvas 3D
  115.         Canvas3D c = new Canvas3D(config);
  116.         add("Center",c);
  117.         // Intégration de la scène 3D
  118.         SimpleUniverse u = new SimpleUniverse(c);
  119.         BranchGroup scene = createSceneGraph(u);
  120.         u.getViewingPlatform().setNominalViewingTransform();
  121.         u.addBranchGraph(scene);
  122.     }
  123.     /**
  124.         Procédure d'éxécution.
  125.     */
  126.     public static void main(String[] args) {
  127.         SimpleClip f = new SimpleClip();
  128.         f.addWindowListener(new WindowAdapter(){
  129.             public void windowClosing(WindowEvent e) {
  130.                 System.exit(0);
  131.             }
  132.         });
  133.         f.setSize(300,250);
  134.         f.setVisible(true);
  135.         f.setLocationRelativeTo(null);
  136.     }
  137. }
 

Je l'ai mis en forme et très légèrement commenté ! Bref, c'est ce que je cherchais, me voila heureux "E R E"

 

:D


Message édité par RedTux le 15-04-2008 à 18:27:16

---------------
N'oubliez pas le [Résolu] dans le titre si vous êtes satisfait.
Les règles du Forum - À lire absolument

Aller à :
Ajouter une réponse
  FORUM Infos-du-Net » Programmation » Java3D : Géométrie tronquée par un plan
 

Liens