Hi Georg,
I usually make my appearance this way :
//--------------------------------------------------
public Appearance buildAppearance( )
{
Appearance appear = new Appearance( );
ColoringAttributes colorAttrib =
new ColoringAttributes(0.0f, 0.0f, 0.0f, 3);
Color3f matAmbient = new Color3f(0.2f, 0.2f, 0.2f)
,
matEmissive = new Color3f(0.0f, 0.0f, 0.0f)
,
matDiffuse = new Color3f(1.0f, 1.0f, 1.0f)
,
matSpecular = new Color3f(1.0f, 1.0f, 1.0f);
float matShininess= 50.0f ;
Material material =
new Material ( matAmbient, matEmissive,
matDiffuse, matSpecular, matShininess);
TextureUnitState textureUnitState[] =
new TextureUnitState[2];
TextureAttributes texAttr1 = new
TextureAttributes();
texAttr1.setTextureMode(2);
TextureLoader tex;
try{
tex = new TextureLoader("earth.gif" , this);
Texture texture1 = tex.getTexture();
textureUnitState[0] = new TextureUnitState();
textureUnitState[0].setTexture(texture1);
textureUnitState[0].setTextureAttributes(texAttr1);
appear.setTextureUnitState(textureUnitState);
}
catch(Exception ex)
{
System.out.println("imgeURL1 - texture null
!");
ex.printStackTrace();
}
TransparencyAttributes transparencyAttributes =
new TransparencyAttributes(4, 0.0f);
PolygonAttributes polyAttributes =
new PolygonAttributes();
polyAttributes.setPolygonMode( 2 );
polyAttributes.setCullFace( 1 );
appear.setPolygonAttributes(polyAttributes);
appear.setTransparencyAttributes(transparencyAttributes);
appear.setMaterial(material);
appear.setColoringAttributes(colorAttrib);
return appear;
}
//---------------------------------
Works fine.
--- Georg Rehfeld <[EMAIL PROTECTED]> escreveu: >
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.java: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".
_______________________________________________________________________
Yahoo! Encontros
O lugar certo para voc� encontrar aquela pessoa que falta na sua vida. Cadastre-se
hoje mesmo!
http://br.encontros.yahoo.com/
===========================================================================
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".