Hi,
Try this. You may see the rendering of face not correct
since Java3D v1.2.1 don't do depth sort transparency.
However next version will have API to address this.
- Kelvin
------------
Java 3D Team
Sun Microsystems Inc.
>X-Unix-From: [EMAIL PROTECTED] Wed Apr 11 00:14:45 2001
>MIME-Version: 1.0
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
>Date: Tue, 11 Apr 2000 11:02:34 +0400
>From: PLUG <[EMAIL PROTECTED]>
>Subject: [JAVA3D] [java3d] transparency
>To: [EMAIL PROTECTED]
>
>Hi!
>
>I have problems with objects transparency with textures. Already 5 days. Below
Uma Sabada has written working (like) program. But, again, I have failled. Here
is piece of code, can somebody will prompt in than problem.
>
>app = new Appearance();
>Texture tex = new TextureLoader(texImage, this).getTexture();
>app.setTexture(tex);
>TextureAttributes texAttr = new TextureAttributes();
>texAttr.setTextureMode(TextureAttributes.MODULATE);
>app.setTextureAttributes(texAttr);
>
>transparency = new TransparencyAttributes(
>
>TransparencyAttributes.NICEST, .3f);
>
>May be somebody post a working code, please
>
>Thank you for attention.
>
>
>
>-------------------------------------------------------------------------------
-------------
>[EMAIL PROTECTED]
>
>ICQ: #75190013
>
/*
* @(#)BoxExample.java 1.12 99/05/19 14:30:05
*
* Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.behaviors.mouse.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class BoxExample extends Applet {
public BranchGroup createSceneGraph(String[] args) {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
// Create a Transformgroup to scale all objects so they
// appear in the scene.
TransformGroup objScale = new TransformGroup();
Transform3D t3d = new Transform3D();
t3d.setScale(0.4);
objScale.setTransform(t3d);
objRoot.addChild(objScale);
TransformGroup objTrans = new TransformGroup();
//write-enable for behaviors
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTrans.setCapability( TransformGroup.ALLOW_TRANSFORM_READ );
objTrans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
objScale.addChild(objTrans);
Appearance ap = new Appearance();
Color3f aColor = new Color3f(0.1f, 0.1f, 0.1f);
Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
Color3f dColor = new Color3f(1.0f, 0.8f, 0f);
Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
Material m = new Material(aColor, eColor, dColor, sColor, 80.0f);
m.setLightingEnable(true);
ap.setMaterial(m);
TransparencyAttributes ta = new TransparencyAttributes(
TransparencyAttributes.BLENDED, 0.9f);
// TransparencyAttributes ta = new TransparencyAttributes();
PolygonAttributes pa = new PolygonAttributes();
pa.setCullFace(PolygonAttributes.CULL_NONE);
// ta.setTransparency(0.9f);
// ta.setTransparencyMode(TransparencyAttributes.NICEST);
ap.setTransparencyAttributes(ta);
ap.setPolygonAttributes(pa);
//Create a Box
Box BoxObj = new Box(1.5f, 1.5f, 0.8f, Box.GENERATE_NORMALS |
Box.GENERATE_TEXTURE_COORDS, ap);
// add it to the scene graph.
objTrans.addChild(BoxObj);
TextureLoader tex = new TextureLoader(new String("fight.gif"), new String("RGBA"),
this);
if (tex != null) {
ap.setTexture(tex.getTexture());
}
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
texAttr.setTextureMode(TextureAttributes.REPLACE);
ap.setTextureAttributes(texAttr);
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
// Create the rotate behavior node
MouseRotate behavior = new MouseRotate(objTrans);
objTrans.addChild(behavior);
behavior.setSchedulingBounds(bounds);
// Create the zoom behavior node
MouseZoom behavior2 = new MouseZoom(objTrans);
objTrans.addChild(behavior2);
behavior2.setSchedulingBounds(bounds);
//Shine it with two lights.
Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
Color3f lColor2 = new Color3f(0.2f, 0.2f, 0.1f);
Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
Vector3f lDir2 = new Vector3f(1.0f, 1.0f, -1.0f);
DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
lgt1.setInfluencingBounds(bounds);
lgt2.setInfluencingBounds(bounds);
objScale.addChild(lgt1);
objScale.addChild(lgt2);
// Let Java 3D perform optimizations on this scene graph.
objRoot.compile();
return objRoot;
}
public BoxExample (String argv[]){
setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
add("Center", c);
BranchGroup scene = createSceneGraph(argv);
SimpleUniverse u = new SimpleUniverse(c);
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
public static void main(String argv[])
{
new MainFrame(new BoxExample(argv), 750, 750);
}
}
fight.gif