Here's one FAQ that I'd like to get properly answered, not only for
myself, but for eveeryone else that seems to ask it. (Trust me, the
first thing I'm going to do when this all works is write up a section
for the FAQ !!!!!)

I'm using our custom image loaders that generate BufferedImages.
Everything works correct wrt setting image transparency because they
render quite nicely in 2D. Put it on a 3D object and it's all lost (ie
white object appears in the background). Now I've checked that the image
being used for the texture has transparency in the colour model so that
is all fine. Also, I've tried every combination of the texture attribute
mode, boundary colour etc but I'm still doing something wrong. :(

I've attached the code below so if someone would be kind enough to see
what the stupid thing is that I've done....

--
Justin Couch                                   Author, Java Hacker
Snr Software Engineer                     [EMAIL PROTECTED]
ADI Ltd, Systems Group              http://www.vlc.com.au/~justin/
Java3D FAQ:       http://tintoy.ncsa.uiuc.edu/~srp/java3d/faq.html
-------------------------------------------------------------------
"Look through the lens, and the light breaks down into many lights.
 Turn it or move it, and a new set of arrangements appears... is it
 a single light or many lights, lights that one must know how to
 distinguish, recognise and appreciate? Is it one light with many
 frames or one frame for many lights?"      -Subcomandante Marcos
-------------------------------------------------------------------

-----------------
Creating Geometry
-----------------
  private void constructBasicGeometry()
  {
    int flags =
      GeometryArray.COORDINATES |
      GeometryArray.TEXTURE_COORDINATE_2 |
      GeometryArray.NORMALS;

    IndexedQuadArray geom = new IndexedQuadArray(4, flags, 4);

    // Create the geometry first
    double[] coordinates = {
      0.5, 1, 0,
      0.5, 0, 0,
      -0.5, 0, 0,
      -0.5, 1, 0
    };

    int[] indices = { 0, 1, 2, 3 };

    geom.setCoordinates(0, coordinates);
    geom.setCoordinateIndices(0, indices);

    // Next the texture coordinates
    float[] tex_coords = {
      1, 1,
      1, 0,
      0, 0,
      0, 1
    };

    geom.setTextureCoordinates(0, tex_coords);
    geom.setTextureCoordinateIndices(0, indices);

    // Finally the normal information
    float[] normal = { 0, 0, 1 };

    geom.setNormal(0, normal);
    geom.setNormal(1, normal);
    geom.setNormal(2, normal);
    geom.setNormal(3, normal);

    base_shape.setGeometry(geom);
  }

-----------------
Creating Appearance
-----------------

  private void createAppearance(BufferedImage img)
  {
    appearance = new Appearance();

    PolygonAttributes rend_attr = new PolygonAttributes();
    rend_attr.setCullFace(PolygonAttributes.CULL_NONE);
    rend_attr.setBackFaceNormalFlip(true);

    appearance.setPolygonAttributes(rend_attr);

    // Construct the texture from the basic image This needs to be
scaled
    // so that the image is a factor of 2 in dimensions. At the moment,
this
    // is a square scale. Probably should take into account non-square
sizes.
    BufferedImage tex_img =
      MasterUtilities.createScaledImage(img,
                                        TEXTURE_IMAGE_SIZE,
                                        TEXTURE_IMAGE_SIZE);

    ImageComponent2D ic2d =
      new ImageComponent2D(ImageComponent.FORMAT_RGBA, tex_img);

    Texture2D texture = new Texture2D(Texture.BASE_LEVEL,
                                      Texture.RGBA,
                                      TEXTURE_IMAGE_SIZE,
                                      TEXTURE_IMAGE_SIZE);
    texture.setImage(0, ic2d);
    texture.setBoundaryColor(0, 0, 0, 0);
    texture.setBoundaryModeS(Texture.CLAMP);   // just in case!
    texture.setBoundaryModeT(Texture.CLAMP);
    texture.setEnable(true);

    appearance.setTexture(texture);

    TextureAttributes tex_attr = new TextureAttributes();
    tex_attr.setTextureMode(TextureAttributes.DECAL);
    tex_attr.setPerspectiveCorrectionMode(TextureAttributes.FASTEST);

    appearance.setTextureAttributes(tex_attr);

    base_shape.setAppearance(appearance);
  }

-----------------
Creating scaled image
-----------------

  public static BufferedImage createScaledImage(Image img, int w, int h)
  {
    BufferedImage input = createBufferedImage(img);

    float height = img.getHeight(null);
    float width = img.getWidth(null);

    float x_scale = w / width;
    float y_scale = h / height;

    AffineTransform at = AffineTransform.getScaleInstance(x_scale,
                                                          y_scale);
    AffineTransformOp atop =
      new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);

    BufferedImage output  = atop.filter(input, null);

    return output;
  }

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to