J3d plusieurs texture
T_Model
Messages postés
3
Statut
Membre
-
T_Model Messages postés 3 Statut Membre -
T_Model Messages postés 3 Statut Membre -
Bonjour,
je voulais ecrire un code qui utilise une image comme arriere plan et qui au meme temps associe une autre texture à un objet 3D (un box dans mon exemple) mais l'application(et l'applet) que j'obtiens lorsque je fais l'execution est completement vide et blanc..j'ai eu le meme probleme en essayant d'utiliser deux textures pour deux objet 3d dans le meme applet..alors je me demande(plutot je vous demande) si il y a un probleme en java3D lorsqu'on utilise plus qu'une texture..
quelqu'un peut m'aidez svp?
ps:je suis sous eclipse
voici mon code
import java.applet.Applet;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.net.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.*;
import javax.media.j3d.*;
import javax.vecmath.Vector3f;
public class Essai extends Applet{
private static boolean isApplet = true ;
private static boolean applet = true ;
public Essai() {
if (!isApplet) {
lanceApplication();
}
if (!applet) {
lanceApplication();
}
}
public void lanceApplication() {
this.setLayout(new BorderLayout());
}
public BranchGroup createSceneTree() {
BranchGroup root = new BranchGroup();
Background background = new Background();
BufferedImage image = null;
if (!applet) {
try {
image = ImageIO.read(new File("C:\\texture\\gazonn.jpg"));
}
catch (IOException ex) {
System.out.println("Impossible de charger le fichier texture \"gazonn.jpg\"");
}
}
if (image != null) {
ImageComponent2D imageComponent2D =
new ImageComponent2D(ImageComponent2D.FORMAT_RGB, image);
background.setImage(imageComponent2D);
background.setApplicationBounds(new BoundingBox());
root.addChild(background);
}
Texture texture = null;
if (!isApplet) {
try {
BufferedImage image1 = ImageIO.read(new File("C:\\texture\\brique.jpg"));
texture = new TextureLoader(image1).getTexture();
}
catch (IOException ex) {
System.out.println("Impossible de charger le fichier texture \"brique.jpg\"");
}
}
Appearance appearance = new Appearance();
appearance.setTexture(texture);
Box box1 = new Box (0.03f, 0.15f, 0.03f, Primitive.GENERATE_TEXTURE_COORDS,
appearance);
Transform3D translation1 = new Transform3D ();
translation1.setTranslation (new Vector3f (0.65f, 0, 0));
TransformGroup translationGroup1 = new TransformGroup (translation1);
translationGroup1.addChild (box1);
Transform3D rotationZAxis1 = new Transform3D ();
rotationZAxis1.rotZ (Math.PI /2);
TransformGroup rotationZAxisGroup1 = new TransformGroup (rotationZAxis1);
rotationZAxisGroup1.addChild (translationGroup1);
root.addChild (rotationZAxisGroup1);
return root;
}
public void init() {
if (isApplet) {
lanceApplication();
}
}
public static void main (String [] args)
{
applet = false ;
isApplet = false ;
new MainFrame (new Essai (), args, 1150, 700);
}
}
je voulais ecrire un code qui utilise une image comme arriere plan et qui au meme temps associe une autre texture à un objet 3D (un box dans mon exemple) mais l'application(et l'applet) que j'obtiens lorsque je fais l'execution est completement vide et blanc..j'ai eu le meme probleme en essayant d'utiliser deux textures pour deux objet 3d dans le meme applet..alors je me demande(plutot je vous demande) si il y a un probleme en java3D lorsqu'on utilise plus qu'une texture..
quelqu'un peut m'aidez svp?
ps:je suis sous eclipse
voici mon code
import java.applet.Applet;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.net.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.*;
import javax.media.j3d.*;
import javax.vecmath.Vector3f;
public class Essai extends Applet{
private static boolean isApplet = true ;
private static boolean applet = true ;
public Essai() {
if (!isApplet) {
lanceApplication();
}
if (!applet) {
lanceApplication();
}
}
public void lanceApplication() {
this.setLayout(new BorderLayout());
}
public BranchGroup createSceneTree() {
BranchGroup root = new BranchGroup();
Background background = new Background();
BufferedImage image = null;
if (!applet) {
try {
image = ImageIO.read(new File("C:\\texture\\gazonn.jpg"));
}
catch (IOException ex) {
System.out.println("Impossible de charger le fichier texture \"gazonn.jpg\"");
}
}
if (image != null) {
ImageComponent2D imageComponent2D =
new ImageComponent2D(ImageComponent2D.FORMAT_RGB, image);
background.setImage(imageComponent2D);
background.setApplicationBounds(new BoundingBox());
root.addChild(background);
}
Texture texture = null;
if (!isApplet) {
try {
BufferedImage image1 = ImageIO.read(new File("C:\\texture\\brique.jpg"));
texture = new TextureLoader(image1).getTexture();
}
catch (IOException ex) {
System.out.println("Impossible de charger le fichier texture \"brique.jpg\"");
}
}
Appearance appearance = new Appearance();
appearance.setTexture(texture);
Box box1 = new Box (0.03f, 0.15f, 0.03f, Primitive.GENERATE_TEXTURE_COORDS,
appearance);
Transform3D translation1 = new Transform3D ();
translation1.setTranslation (new Vector3f (0.65f, 0, 0));
TransformGroup translationGroup1 = new TransformGroup (translation1);
translationGroup1.addChild (box1);
Transform3D rotationZAxis1 = new Transform3D ();
rotationZAxis1.rotZ (Math.PI /2);
TransformGroup rotationZAxisGroup1 = new TransformGroup (rotationZAxis1);
rotationZAxisGroup1.addChild (translationGroup1);
root.addChild (rotationZAxisGroup1);
return root;
}
public void init() {
if (isApplet) {
lanceApplication();
}
}
public static void main (String [] args)
{
applet = false ;
isApplet = false ;
new MainFrame (new Essai (), args, 1150, 700);
}
}