You cannot have two texture unit states set for one shape and apply
different ones to different parts of the same geometry.  In other words, you
are always applying all the texture units specified in the tex coord set map
to all the triangles in a geometry array in a shape.

The closest you could come is to use a different tex coord set map for
different geometries inside a single shape, but you would still in effect be
applying different textures to different geometries. I am pretty sure the
texture untis were not designed to be a support for applying wholly
different textures to different geometry arrays.  In other words I am not
sure you could make 10 texture units and then have 10 geometries each of
which uses a tex coord set map referencing only one unit.  If this would
work then this could be a good optimization for certain things.

Multi texturing is when you overlay multiple texture units on one geometry,
so basically your tex coord set count for a geometry is greator than 1.  In
that case the textures are applied one on top of each other according to
their texture mode and the defined texture attributes.

Dave Yazel



-----Original Message-----
From: Georg Rehfeld [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 14, 2002 12:30 AM
To: [EMAIL PROTECTED]
Subject: [JAVA3D] Problem with TextureUnitState


Hi group,

I'm trying to use TextureUnitState in an Appearance to apply
different Textures to different parts of the Geometry contained
in only one Shape3D.

My code is as follows:

    /**
     * Returns the Appearance for a house containing 2 Textures,
     * one for the 4 walls, the other for the roof.
     */
    protected Appearance getHouseAppearance() {
        if (houseAppearance == null) {
            houseAppearance = new Appearance();
            TextureUnitState tus = new TextureUnitState();
            tus.setTexture(getTexture("facade.gif"));
            // the texture IS returned, definitely
            houseAppearance.setTextureUnitState(0, tus); // <=====
            tus = new TextureUnitState();
            tus.setTexture(getTexture("roof.gif"));
            houseAppearance.setTextureUnitState(1, tus);
        }
        return houseAppearance;
    }

However, at the marked line of code, I get this exception:

java.lang.NullPointerException
 at
javax.media.j3d.AppearanceRetained.setTextureUnitState(AppearanceRetained.ja
va:665)
 at javax.media.j3d.Appearance.setTextureUnitState(Appearance.java:687)
 at Zoom.getHouseAppearance(Zoom.java:310)
 at Zoom.createHouse(Zoom.java:298)
 at Zoom.createCity(Zoom.java:144)
 at Zoom.createSceneGraph(Zoom.java:118)
 at Zoom.init(Zoom.java:435)
 at com.sun.j3d.utils.applet.JMainFrame.run(JMainFrame.java:180)
 at java.lang.Thread.run(Thread.java:536)

What am I doing wrong?

Or might this be a bug in J3D 1.3 beta2?

regards

Georg
 ___   ___
| + | |__    Georg Rehfeld      Woltmanstr. 12     20097 Hamburg
|_|_\ |___   [EMAIL PROTECTED]           +49 (40) 23 53 27 10

===========================================================================
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".

===========================================================================
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