use of org.scijava.java3d.ColoringAttributes in project GDSC-SMLM by aherbert.
the class Shape3DHelper method createShape.
/**
* Creates the shape.
*
* @param rendering the rendering
* @param colorDepth the color depth
* @return the shape
*/
public static Shape3D createShape(Rendering rendering, int colorDepth) {
GeometryArray ga;
final Appearance appearance = new Appearance();
int vertexFormat = GeometryArray.COORDINATES;
if (colorDepth == 3) {
vertexFormat |= GeometryArray.COLOR_3;
} else if (colorDepth == 4) {
vertexFormat |= GeometryArray.COLOR_4;
}
// Support drawing as points ...
if (rendering == Rendering.POINT) {
ga = new PointArray(1, vertexFormat);
final PointAttributes pa = new PointAttributes();
pa.setPointAntialiasingEnable(true);
appearance.setPointAttributes(pa);
} else {
ga = createGeometryArray(rendering, colorDepth);
// // Test using the geometry from a sphere primitive
// switch (r)
// {
// case HIGH_RES_SPHERE:
// ga = ItemGeometryGroup.createSphere(50);
// break;
// case LOW_RES_SPHERE:
// ga = ItemGeometryGroup.createSphere(16);
// break;
// }
final PolygonAttributes pa = new PolygonAttributes();
pa.setPolygonMode(PolygonAttributes.POLYGON_FILL);
if (rendering.is2D()) {
pa.setCullFace(PolygonAttributes.CULL_NONE);
pa.setBackFaceNormalFlip(true);
} else {
pa.setCullFace(PolygonAttributes.CULL_BACK);
pa.setBackFaceNormalFlip(false);
}
appearance.setPolygonAttributes(pa);
final ColoringAttributes ca = new ColoringAttributes();
// if (rendering.isHighResolution() || rendering.is2D())
// // Smooth across vertices. Required to show 2D surfaces smoothly
// ca.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
// else
// // Faster polygon rendering with flat shading
// ca.setShadeModel(ColoringAttributes.SHADE_FLAT);
// For indexed models (with 1 normal per vertex) always use smooth shading
ca.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
appearance.setColoringAttributes(ca);
final Material m = new Material();
m.setShininess(128f);
m.setAmbientColor(0.1f, 0.1f, 0.1f);
if (rendering.isHighResolution()) {
// Allow shiny highlights on balls
m.setSpecularColor(0.1f, 0.1f, 0.1f);
} else {
// For flat appearance
m.setSpecularColor(0, 0, 0);
}
appearance.setMaterial(m);
}
return new Shape3D(ga, appearance);
}
use of org.scijava.java3d.ColoringAttributes 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.ColoringAttributes in project GDSC-SMLM by aherbert.
the class ImageJ3DResultsViewer method updateAppearance.
private static void updateAppearance(CustomMesh mesh, final ImageJ3DResultsViewerSettingsOrBuilder settings) {
mesh.setShaded(settings.getShaded());
final Appearance appearance = mesh.getAppearance();
final PolygonAttributes pa = appearance.getPolygonAttributes();
// For all 3D polygons we want to support a true face orientation so transparency works
final Rendering r = Rendering.forNumber(settings.getRendering());
if (r.is2D()) {
pa.setCullFace(PolygonAttributes.CULL_NONE);
pa.setBackFaceNormalFlip(true);
} else {
pa.setCullFace(PolygonAttributes.CULL_BACK);
pa.setBackFaceNormalFlip(false);
}
// TransparencyAttributes ta = appearance.getTransparencyAttributes();
// ta.setSrcBlendFunction(TransparencyAttributes.BLEND_SRC_ALPHA);
// ta.setDstBlendFunction(TransparencyAttributes.BLEND_ONE);
// ta.setDstBlendFunction(TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA); // Default
ItemTriangleMesh.setTransparencyMode(TransparencyAttributes.FASTEST);
// ItemTriangleMesh.setTransparencyMode(TransparencyAttributes.SCREEN_DOOR);
// ItemTriangleMesh.setTransparencyMode(TransparencyAttributes.BLENDED);
final ColoringAttributes ca = appearance.getColoringAttributes();
if (r.isHighResolution() || r.is2D()) {
// Smooth across vertices. Required to show 2D surfaces smoothly
ca.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
} else {
// Faster polygon rendering with flat shading
ca.setShadeModel(ColoringAttributes.SHADE_FLAT);
}
}
Aggregations