Thanks for your reaction!
But I don't see how I can use it.
Maybe my question was a bit confusing.
But I have an actual instance of the Image2D class.
And I want to create an instance of a subclass of Texture, using that
Image2D-object.
The code you sent, creates a BufferedImage-object (and with that, a
Texture), using an image-file.

But what is JAI? (yeah, sorry, I'm new to this mailinglist...)
And has PlanarImage something to do with JAI? Because I can't find a
PlanarImage class.
Can I use PlanarImage (or JAI) to create a BufferedImage using an =
instance
of Image2D?

all help is welcome!
Thanks.
Pieter Van Raemdonck
Katholieke Universiteit Leuven, Belgium.



----- Original Message -----
From: Jacob Nikom <[EMAIL PROTECTED]>
To: Discussion list for Java 3D API <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Friday, March 17, 2000 1:09 AM
Subject: Re: [JAVA3D] [java3d] make Texture from Image


> Look at
> http://java.sun.com/products/java-media/3D/collateral/
>
> Here is the code. I used JAI for downloading .png images
>
> Jacob Nikom
>
> file://=3D=3D=3D=3D=3Dbeginning of the file SphereTextureApp =
=3D=3D=3D=3D=3D=3D=3D=3D=3D
> import javax.media.jai.*;
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
>
> import javax.media.j3d.*;
> import javax.vecmath.*;
> import java.awt.image.*;
>
> import com.sun.j3d.utils.universe.*;
>
> import com.sun.j3d.utils.geometry.*;
> import com.sun.j3d.utils.image.TextureLoader;
>
> import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
> import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
> import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
>
> // SphereTextureApp creates a single plane with texture mapping.
> public class SphereTextureApp extends JPanel
> {
>   public SphereTextureApp (BufferedImage bufferedImage)
>   {
>     Canvas3D canvas =3D new Canvas3D(null);
>
>     setLayout(new BorderLayout());
>     add("Center", canvas);
>
>     BranchGroup scene =3D createSceneGraph(bufferedImage);
>
>     SimpleUniverse su =3D new SimpleUniverse(canvas);
>
>     // This will move the ViewPlatform back a bit so the
>     // objects in the scene can be viewed.
>     su.getViewingPlatform().setNominalViewingTransform();
>
>     su.addBranchGraph(scene);
>   }
>
>   public BranchGroup createSceneGraph(BufferedImage bufferedImage)
>   {
>     BranchGroup objRoot =3D new BranchGroup();
>     Transform3D transform =3D new Transform3D();
>     Appearance appear =3D new Appearance();
>
>     //  Create 3D transformation variables(internally a matrix)
>     Transform3D revXY =3D new Transform3D();
>     Transform3D revY  =3D new Transform3D();
>     Transform3D movX  =3D new Transform3D();
>
>     //  Set Transformations
>     movX.set(new Vector3d(-0.5d, 0.0d, 0.0d));
>     revXY.rotX(Math.PI/6.0);
>     revY.rotY(Math.PI/6.0);
>
>     // Put the final result into the same matrix movX
>     revXY.mul(revY);
>     movX.mul(revXY);
>
>     //  Create a Transform Group object
> //  TransformGroup objTrans =3D new TransformGroup(movX);
>     TransformGroup objTrans =3D new TransformGroup();
>     objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
>     objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
>
>     TextureLoader loader =3D new TextureLoader(bufferedImage);
>     ImageComponent2D imageTexture =3D loader.getImage();
>
>     // can't use parameterless constuctor
>     Texture2D texture =3D new Texture2D(
>                                       Texture.BASE_LEVEL,
>                                       Texture.RGBA,
>                                       imageTexture.getWidth(),
>                                       imageTexture.getHeight()
>                                      );
>
>     texture.setImage(0, imageTexture);
>
>     appear.setTexture(texture);
>
>     appear.setTransparencyAttributes(
>          new TransparencyAttributes(TransparencyAttributes.FASTEST,
> 0.1f));
>
>     // Create Geometry
>     Sphere sphere =3D new Sphere(1.0f, =
Primitive.GENERATE_TEXTURE_COORDS,
> appear);
>     QuadArray plane =3D createPlane();  // initialize QuadArray object
>
> //  Shape3D planeObj =3D new Shape3D(plane, appear);
> //  Shape3D sphereObj =3D new Shape3D(sphere, appear);
>
>     // Key point - add the geometry not to the scene
>     // but to the transformation object!
>     objTrans.addChild(sphere);
>
>     //  add Transform group object to the Branch group
>     objRoot.addChild(objTrans);
>
>     BoundingSphere bounds =3D
>       new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
>
>     // Create the rotate behavior node
>     MouseRotate behavior1 =3D new MouseRotate(objTrans);
>     objTrans.addChild(behavior1);
>     behavior1.setSchedulingBounds(bounds);
>
>     // Create the zoom behavior node
>     MouseZoom behavior2 =3D new MouseZoom(objTrans);
>     objTrans.addChild(behavior2);
>     behavior2.setSchedulingBounds(bounds);
>
>     // Create the translate behavior node
>     MouseTranslate behavior3 =3D new MouseTranslate(objTrans);
>     objTrans.addChild(behavior3);
>     behavior3.setSchedulingBounds(bounds);
>
>     Background background =3D new Background();
>     background.setColor(0.0f, 0.0f, 0.5f);
>     background.setApplicationBounds(new BoundingSphere());
>     objRoot.addChild(background);
>
>     return objRoot;
>   }
>
>   public QuadArray createPlane()
>   {
>     QuadArray plane =3D
>       new QuadArray(4, GeometryArray.COORDINATES |
> GeometryArray.TEXTURE_COORDINATE_2);
>
>     Point3f p =3D new Point3f(-1.0f,  1.0f,  0.0f);
>     plane.setCoordinate(0, p);
>     p.set(-1.0f, -1.0f,  0.0f);
>     plane.setCoordinate(1, p);
>     p.set(1.0f, -1.0f,  0.0f);
>     plane.setCoordinate(2, p);
>     p.set(1.0f,  1.0f,  0.0f);
>     plane.setCoordinate(3, p);
>
>     Point2f q =3D new Point2f( 0.0f,  1.0f);
>     plane.setTextureCoordinate(0, q);
>     q.set(0.0f, 0.0f);
>     plane.setTextureCoordinate(1, q);
>     q.set(1.0f, 0.0f);
>     plane.setTextureCoordinate(2, q);
>     q.set(1.0f, 1.0f);
>     plane.setTextureCoordinate(3, q);
>
>     return plane;
>   }
>
>   public static void main(String args[])
>   {
>     JFrame jFrame =3D new JFrame("Swing3D Primitive Texture");
>     jFrame.setBounds(100, 100, 300, 300);
>
>     jFrame.addWindowListener(new WindowAdapter()
>     {
>       public void windowClosing(WindowEvent event)
>       {
>         System.exit(0);
>       }
>     });
>
>     Container jFrameContainer =3D jFrame.getContentPane();
>     jFrameContainer.setLayout(null);
>     jFrameContainer.setBounds(0, 0, 300, 300);
>     jFrameContainer.setBackground(Color.pink);
>
>     if (args.length !=3D 1)
>     {
>       System.out.println ("usage: java SphereTextureApp
> <image_file.ext>");
>       System.exit (1);
>     }
>
>     PlanarImage planarImage =3D JAI.create("fileload", args[0]);
>     BufferedImage buffImage =3D planarImage.getAsBufferedImage();
>
>     SphereTextureApp sphereTextureApp =3D new =
SphereTextureApp(buffImage);
>     sphereTextureApp.setBounds(0, 0, 256, 256);
>     sphereTextureApp.setVisible(true);
>
>     jFrameContainer.add(sphereTextureApp);
>     jFrame.setVisible(true);
>     jFrame.validate();
>
>   }
> }
>
>
> > pieter wrote:
> >
> > hello all.
> >
> > I would like to make a Texture-object from the information in an =
Image
> > object. I got the Image via the getImage() method in an AWT =
Component.
> > Texture-classes (Texture2D in particular) seem to want an
> > ImageComponent-object. And an ImageComponent-object seems to want a
> > BufferedImage-object. And to use a BufferedImage-object, I need a =
kind
> > of
> > Raster.
> > But I can't seem to convert the Image2D-object that I have to any of
> > those
> > required classes.
> >
> > So if anybody knows how to make a Texture from an Image2D, I'd be =
very
> > gratefull if you could tell me!
> >
> > P.S. Are there any good books that address such issues (or that
> > explain the
> > exact working of the util-package classes) ?
> >
> > Thanx.
> > Pieter.

Reply via email to