Posted by
mmcrosb on
Apr 08, 2015; 9:55pm
URL: https://forum.jogamp.org/j3d-problem-transparent-texture-light-tp4034240p4034249.html
here is my full source
.
.
.
.
.
.
.
.
public final class Atmosphere {
//<editor-fold defaultstate="collapsed" desc="Constructors">
Atmosphere(... core) {
this.core = core;
setCeilingTexture(core.getResourceManager().getTexture("local", "cielo.png"));
this.core.getUniverse().addBranchGraph(getComponent3D());
this.ceilingTimer.schedule(ceilingTimerTask, 10, 10);
}
@Override
protected void finalize() {
ceilingTimer.cancel();
ceilingTimer.purge();
try {
super.finalize();
} catch (Throwable ex) {
Logger.getLogger(Atmosphere.class.getName()).log(Level.SEVERE, null, ex);
}
}
private final ... core;
private final ... getCore() { return core; }
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Background">
//<editor-fold defaultstate="collapsed" desc="Ceiling">
//<editor-fold defaultstate="collapsed" desc="Geometry">
//<editor-fold defaultstate="collapsed" desc="Coordinates">
private Point3d[] ceilingCoordinates = null;
private Point3d[] getCeilingCoordinates() {
if (ceilingCoordinates == null) {
this.ceilingCoordinates = new Point3d[]{
new Point3d(1,0.06,1), new Point3d(-1,0.06,1),
new Point3d(-1,0.06,-1), new Point3d(1,0.06,-1)
};
}
return ceilingCoordinates;
}
//</editor-fold>
private QuadArray ceilingGeometry = null;
private QuadArray getCeilingGeometry() {
if (ceilingGeometry == null) {
ceilingGeometry = new QuadArray(getCeilingCoordinates().length, GeometryArray.COLOR_4|GeometryArray.COORDINATES|GeometryArray.NORMALS|GeometryArray.TEXTURE_COORDINATE_2);
ceilingGeometry.setCoordinates(0, getCeilingCoordinates());
setNormals(ceilingGeometry);
}
return ceilingGeometry;
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Appearance">
//<editor-fold defaultstate="collapsed" desc="Material">
private Material ceilingMaterial = null;
private Material getCeilingMaterial() {
if (ceilingMaterial == null) {
ceilingMaterial = new Material();
ceilingMaterial.setAmbientColor(1,1,1);
ceilingMaterial.setEmissiveColor(0,0,0);
ceilingMaterial.setDiffuseColor(0,0,0);
ceilingMaterial.setSpecularColor(0, 0, 0);
ceilingMaterial.setShininess(1);
ceilingMaterial.setLightingEnable(true);
}
return ceilingMaterial;
}
//</editor-fold>
private ColoringAttributes ceilingColoringAttributes = null;
private ColoringAttributes getCeilingColoringAttributes() {
if (ceilingColoringAttributes == null) {
ceilingColoringAttributes = new ColoringAttributes();
ceilingColoringAttributes.setColor(0,1,0);
}
return ceilingColoringAttributes;
}
//<editor-fold defaultstate="collapsed" desc="Texture">
private Texture ceilingTexture = null;
public Texture getCeilingTexture() {
if (ceilingTexture == null) return getCore().getResourceManager().TEXTURE_NULL;
return ceilingTexture;
}
public Atmosphere setCeilingTexture(String packId, String name) { return setCeilingTexture(getCore().getResourceManager().getTexture(packId, name)); }
public Atmosphere setCeilingTexture(Texture texture) {
java.lang.System.out.println("Texture: "+texture);
if (texture == null) texture = getCore().getResourceManager().TEXTURE_NULL;
if (ceilingAppearance != null) getCeilingAppearance().setTexture(texture);
this.ceilingTexture = texture;
return this;
}
private TexCoordGeneration ceilingTexCoordGeneration = null;
private TexCoordGeneration getCeilingTexCoordGeneration() {
if (ceilingTexCoordGeneration == null) {
ceilingTexCoordGeneration = new TexCoordGeneration(
TexCoordGeneration.OBJECT_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_2,
new Vector4f(1,0,0,0), new Vector4f(0,0,1,0)
);
}
return ceilingTexCoordGeneration;
}
private TextureAttributes ceilingTextureAttributes = null;
private TextureAttributes getCeilingTextureAttributes() {
if (ceilingTextureAttributes == null) {
ceilingTextureAttributes = new TextureAttributes();
ceilingTextureAttributes.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE);
ceilingTextureAttributes.setPerspectiveCorrectionMode(TextureAttributes.FASTEST);
ceilingTextureAttributes.setTextureMode(TextureAttributes.REPLACE);
}
return ceilingTextureAttributes;
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Transparency">
private TransparencyAttributes ceilingTransparencyAttributes = null;
private TransparencyAttributes getCeilingTransparencyAttributes() {
if (ceilingTransparencyAttributes == null) {
ceilingTransparencyAttributes = new TransparencyAttributes();
ceilingTransparencyAttributes.setTransparency(1f);
ceilingTransparencyAttributes.setTransparencyMode(TransparencyAttributes.NICEST);
}
return ceilingTransparencyAttributes;
}
//</editor-fold>
private Appearance ceilingAppearance = null;
private Appearance getCeilingAppearance() {
if (ceilingAppearance == null) {
ceilingAppearance = new Appearance();
ceilingAppearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
ceilingAppearance.setMaterial(getCeilingMaterial());
ceilingAppearance.setColoringAttributes(getCeilingColoringAttributes()); //not working, like lighting
ceilingAppearance.setTexture(getCeilingTexture());
ceilingAppearance.setTextureAttributes(getCeilingTextureAttributes());
ceilingAppearance.setTexCoordGeneration(getCeilingTexCoordGeneration());
ceilingAppearance.setTransparencyAttributes(getCeilingTransparencyAttributes());
ceilingAppearance.setUserData(this);
}
return ceilingAppearance;
}
//</editor-fold>
private Shape3D ceiling = null;
private Shape3D getCeiling() {
if (ceiling == null) ceiling = new Shape3D(getCeilingGeometry(), getCeilingAppearance());
return ceiling;
}
private Timer ceilingTimer = new Timer();
private TimerTask ceilingTimerTask = new TimerTask() {
double x = 0, z = 0;
@Override
public void run() {
if (ceiling == null) return;
x = (x+0.0001f)%100;
z = (z+0.0001f)%100;
Transform3D t = new Transform3D();
t.setTranslation(new Vector3d(x,z,0));
getCeilingTextureAttributes().setTextureTransform(t);
}
};
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Dome">
private Color domeColor = new Color(100,150,200);
public Color getDomeColor() { return domeColor; }
public Atmosphere setDomeColor(Color c) {
if (c == null) c = Color.DARK_GRAY;
this.domeColor = c;
if (dome != null) dome.getAppearance().getColoringAttributes().setColor(
((float)c.getRed())/255f,
((float)c.getGreen())/255f,
((float)c.getBlue())/255f
);
return this;
}
private Sphere dome = null;
private Sphere getDome() {
if (dome == null) {
dome = new Sphere(1, Sphere.GENERATE_NORMALS|Sphere.GENERATE_NORMALS_INWARD|Sphere.GENERATE_TEXTURE_COORDS_Y_UP, 90);
ColoringAttributes coloring = new ColoringAttributes();
coloring.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
coloring.setColor(
((float)getDomeColor().getRed())/255f,
((float)getDomeColor().getGreen())/255f,
((float)getDomeColor().getBlue())/255f
);
dome.getAppearance().setColoringAttributes(coloring);
dome.getAppearance().getMaterial().setLightingEnable(false);
}
return dome;
}
//</editor-fold>
private BranchGroup backGeom = null;
private BranchGroup getBackGeom() {
if (backGeom == null) {
backGeom = new BranchGroup();
backGeom.addChild(getCeiling());
backGeom.addChild(getDome());
backGeom.compile();
}
return backGeom;
}
private Background background = null;
private Background getBackground() {
if (background == null) {
background = new Background();
background.setApplicationBounds(new BoundingSphere(new Point3d(0,0,0), Float.MAX_VALUE));
background.setGeometry(getBackGeom());
}
return background;
}
//</editor-fold>
private BranchGroup component3d = null;
private BranchGroup getComponent3D() {
if (component3d == null) {
component3d = new BranchGroup();
component3d.addChild(getBackground());
component3d.compile();
}
return component3d;
}
}
.
.
.
.
.
.
here are some images


note the terrain was affected by red light
but my problem is i can not get clouds (ceiling) affected by light AND OR colors
i want to know how to make my ceiling affected by coloringattributes and or by an external light
here is my clouds texture png file