use of org.scijava.java3d.TransparencyAttributes in project GDSC-SMLM by aherbert.
the class ItemMesh method setTransparency.
@Override
public void setTransparency(final float transparency) {
// We want to use a different transparency from the ij3d default which is FASTEST
// so override this method.
final Appearance appearance = getAppearance();
final TransparencyAttributes ta = appearance.getTransparencyAttributes();
if (transparency <= .01f) {
this.transparency = 0.0f;
// a scene then the transparency cannot be adjusted. So set to FASTEST.
if (ta.isLive()) {
ta.setTransparencyMode(TransparencyAttributes.NONE);
} else {
ta.setTransparencyMode(TransparencyAttributes.FASTEST);
}
} else {
this.transparency = transparency;
ta.setTransparencyMode(transparencyMode);
// ta.setTransparencyMode(TransparencyAttributes.BLENDED);
}
ta.setTransparency(this.transparency);
}
use of org.scijava.java3d.TransparencyAttributes in project GDSC-SMLM by aherbert.
the class ItemMesh method createAppearance.
/**
* Creates the appearance.
*
* @param appearance the appearance
* @param ga the geometry array
* @return the appearance
*/
protected Appearance createAppearance(Appearance appearance, GeometryArray ga) {
// Create a suitable appearance for points or 3D shapes.
if (appearance == null) {
appearance = new Appearance();
}
appearance.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
appearance.setCapability(Appearance.ALLOW_MATERIAL_READ);
appearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
// Ensure we have the ability to colour the object
if (!hasColor()) {
isColorByMaterial = !isPointArray;
}
if (isPointArray) {
shaded = false;
appearance.setPolygonAttributes(null);
appearance.setMaterial(null);
PointAttributes pointAttributes = appearance.getPointAttributes();
if (pointAttributes == null) {
pointAttributes = new PointAttributes();
pointAttributes.setPointAntialiasingEnable(true);
appearance.setPointAttributes(pointAttributes);
}
pointAttributes.setCapability(PointAttributes.ALLOW_ANTIALIASING_WRITE);
pointAttributes.setCapability(PointAttributes.ALLOW_SIZE_WRITE);
if (hasColor()) {
// We use the coordinates for the colour
appearance.setColoringAttributes(null);
} else {
ColoringAttributes ca = appearance.getColoringAttributes();
if (ca == null) {
ca = new ColoringAttributes();
ca.setShadeModel(ColoringAttributes.SHADE_FLAT);
appearance.setColoringAttributes(ca);
}
ca.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
}
} else {
appearance.setPointAttributes(null);
// These are the defaults. We may need them if we want to support mesh
// display when the polygon mode is Line
PolygonAttributes polygonAttributes = appearance.getPolygonAttributes();
if (polygonAttributes == null) {
polygonAttributes = new PolygonAttributes();
polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL);
appearance.setPolygonAttributes(polygonAttributes);
shaded = true;
} else {
shaded = polygonAttributes.getPolygonMode() == PolygonAttributes.POLYGON_FILL;
}
polygonAttributes.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
ColoringAttributes ca = appearance.getColoringAttributes();
if (ca == null) {
ca = new ColoringAttributes();
ca.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
appearance.setColoringAttributes(ca);
}
ca.setCapability(ColoringAttributes.ALLOW_SHADE_MODEL_WRITE);
Material material = appearance.getMaterial();
if (material == null) {
material = new Material();
material.setAmbientColor(0.1f, 0.1f, 0.1f);
material.setSpecularColor(0.1f, 0.1f, 0.1f);
material.setDiffuseColor(DEFAULT_COLOR);
appearance.setMaterial(material);
}
// Ensure per vertex colours replace the diffuse colour
material.setColorTarget(Material.DIFFUSE);
if (isColorByMaterial) {
material.setCapability(Material.ALLOW_COMPONENT_WRITE);
}
}
// We require transparency attributes for global transparency
TransparencyAttributes tr = appearance.getTransparencyAttributes();
if (tr == null) {
tr = new TransparencyAttributes();
tr.setTransparencyMode(TransparencyAttributes.NONE);
tr.setTransparency(0f);
appearance.setTransparencyAttributes(tr);
}
tr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
tr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
return appearance;
}
use of org.scijava.java3d.TransparencyAttributes in project GDSC-SMLM by aherbert.
the class ItemTriangleMesh method createAppearance.
@Override
protected Appearance createAppearance() {
final Appearance appearance = super.createAppearance();
// Update the transparency to the default mode
final TransparencyAttributes ta = appearance.getTransparencyAttributes();
if (ta.getTransparencyMode() != TransparencyAttributes.NONE) {
ta.setTransparencyMode(transparencyMode);
}
return appearance;
}
use of org.scijava.java3d.TransparencyAttributes in project GDSC-SMLM by aherbert.
the class ItemTriangleMesh method setTransparency.
@Override
public void setTransparency(final float transparency) {
// We want to use a different transparency from the ij3d default which is FASTEST
// so override this method.
final Appearance appearance = getAppearance();
final TransparencyAttributes ta = appearance.getTransparencyAttributes();
if (transparency <= .01f) {
this.transparency = 0.0f;
ta.setTransparencyMode(TransparencyAttributes.NONE);
} else {
this.transparency = transparency;
ta.setTransparencyMode(transparencyMode);
}
ta.setTransparency(this.transparency);
}
use of org.scijava.java3d.TransparencyAttributes in project GDSC-SMLM by aherbert.
the class ItemGeometryGroup method createDefaultAppearance.
/**
* Create a default Appearance object. This will have the correct attributes and capability bits
* set to manipulate the material and transparency.
*
* @param appearance the appearance
* @param ga the geometry array
* @return the appearance
*/
private static Appearance createDefaultAppearance(Appearance appearance, GeometryArray ga) {
if (appearance == null) {
appearance = new Appearance();
}
appearance.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
appearance.setCapability(Appearance.ALLOW_MATERIAL_READ);
if (ga instanceof PointArray) {
appearance.setPolygonAttributes(null);
appearance.setMaterial(null);
PointAttributes pointAttributes = appearance.getPointAttributes();
if (pointAttributes == null) {
pointAttributes = new PointAttributes();
pointAttributes.setPointAntialiasingEnable(true);
appearance.setPointAttributes(pointAttributes);
}
pointAttributes.setCapability(PointAttributes.ALLOW_ANTIALIASING_WRITE);
pointAttributes.setCapability(PointAttributes.ALLOW_SIZE_WRITE);
// We use the coordinates for the colour
ga.setCapability(GeometryArray.ALLOW_COLOR_WRITE);
} else {
appearance.setPointAttributes(null);
// These are the defaults. We may need them if we want to support mesh
// display when the polygon mode is Line
PolygonAttributes polygonAttributes = appearance.getPolygonAttributes();
if (polygonAttributes == null) {
polygonAttributes = new PolygonAttributes();
appearance.setPolygonAttributes(polygonAttributes);
}
polygonAttributes.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL);
// We require material attributes for colour
Material material = appearance.getMaterial();
if (material == null) {
material = new Material();
material.setDiffuseColor(DEFAULT_COLOUR);
appearance.setMaterial(material);
}
material.setCapability(Material.ALLOW_COMPONENT_WRITE);
}
// We require transparency attributes for global transparency
TransparencyAttributes tr = appearance.getTransparencyAttributes();
if (tr == null) {
tr = new TransparencyAttributes();
tr.setTransparencyMode(TransparencyAttributes.NONE);
tr.setTransparency(0f);
appearance.setTransparencyAttributes(tr);
}
tr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
tr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
return appearance;
}
Aggregations