Search in sources :

Example 1 with Appearance

use of javax.media.j3d.Appearance in project ffx by mjschnie.

the class MolecularAssembly method createBox.

/**
 * <p>
 * createBox</p>
 */
public void createBox() {
    int vertices = 8;
    LineArray la = new LineArray(4 * vertices, GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS);
    la.setCapability(LineArray.ALLOW_COORDINATE_WRITE);
    la.setCapability(LineArray.ALLOW_COORDINATE_READ);
    la.setCapability(LineArray.ALLOW_COLOR_WRITE);
    la.setCapability(LineArray.ALLOW_COUNT_READ);
    la.setCapability(LineArray.ALLOW_INTERSECT);
    la.setCapability(LineArray.ALLOW_FORMAT_READ);
    // Create a normal
    // for (ListIterator<MSNode> li = bondlist.listIterator(); li.hasNext(); ){
    // la.setCoordinate(i, a1);
    // la.setColor(i, col);
    // la.setNormal(i++, a1);
    // }
    ColoringAttributes cola = new ColoringAttributes(new Color3f(), ColoringAttributes.SHADE_GOURAUD);
    Appearance app = new Appearance();
    lineAttributes = new LineAttributes();
    lineAttributes.setLineWidth(RendererCache.bondwidth);
    lineAttributes.setCapability(LineAttributes.ALLOW_WIDTH_WRITE);
    lineAttributes.setLineAntialiasingEnable(true);
    app.setLineAttributes(lineAttributes);
    app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);
    app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
    RenderingAttributes ra = new RenderingAttributes();
    ra.setAlphaTestValue(0.1f);
    ra.setAlphaTestFunction(RenderingAttributes.GREATER);
    ra.setDepthBufferEnable(true);
    ra.setDepthBufferWriteEnable(true);
    app.setRenderingAttributes(ra);
    app.setColoringAttributes(cola);
    Shape3D wireframe = new Shape3D(la, app);
    // PickTool.setCapabilities(wire, PickTool.INTERSECT_COORD);
    wireframe.setUserData(this);
    wireframe.setBounds(new BoundingSphere(new Point3d(0, 0, 0), 10.0));
    try {
        wireframe.setBoundsAutoCompute(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
// return wire;
}
Also used : BoundingSphere(javax.media.j3d.BoundingSphere) Point3d(javax.vecmath.Point3d) Color3f(javax.vecmath.Color3f) RenderingAttributes(javax.media.j3d.RenderingAttributes) LineArray(javax.media.j3d.LineArray) ColoringAttributes(javax.media.j3d.ColoringAttributes) Shape3D(javax.media.j3d.Shape3D) Appearance(javax.media.j3d.Appearance) LineAttributes(javax.media.j3d.LineAttributes)

Example 2 with Appearance

use of javax.media.j3d.Appearance in project ffx by mjschnie.

the class RendererCache method initSphereGeom.

private static void initSphereGeom(int res) {
    Appearance ap = new Appearance();
    Sphere sphere;
    sphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_APPEARANCE_MODIFY | Sphere.ENABLE_GEOMETRY_PICKING, 4 + 3 * res, ap);
    sphereGeom[res] = sphere.getShape().getGeometry();
// GeometryArray g = (GeometryArray) sphereGeom[res];
/*
         * if (!g.isLive()) { g.setCapability(g.ALLOW_FORMAT_READ);
         * g.setCapability(g.ALLOW_COUNT_READ);
         * g.setCapability(g.ALLOW_COORDINATE_READ); }
         */
}
Also used : Sphere(com.sun.j3d.utils.geometry.Sphere) ShaderAppearance(javax.media.j3d.ShaderAppearance) Appearance(javax.media.j3d.Appearance)

Example 3 with Appearance

use of javax.media.j3d.Appearance in project ffx by mjschnie.

the class MolecularAssembly method renderWire.

private Shape3D renderWire() {
    ArrayList<ROLS> bonds = getBondList();
    int numbonds = bonds.size();
    if (numbonds < 1) {
        return null;
    }
    Vector3d bondmidpoint = new Vector3d();
    double[] mid = { 0, 0, 0 };
    Vector3d v1 = new Vector3d();
    Vector3d v2 = new Vector3d();
    float[] a1 = { 0, 0, 0 };
    float[] a2 = { 0, 0, 0 };
    float[] col = new float[4];
    Bond bond;
    Atom atom1, atom2;
    LineArray la = new LineArray(4 * numbonds, GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS);
    la.setCapability(LineArray.ALLOW_COORDINATE_WRITE);
    la.setCapability(LineArray.ALLOW_COORDINATE_READ);
    la.setCapability(LineArray.ALLOW_COLOR_WRITE);
    la.setCapability(LineArray.ALLOW_COUNT_READ);
    la.setCapability(LineArray.ALLOW_INTERSECT);
    la.setCapability(LineArray.ALLOW_FORMAT_READ);
    atomLookUp = new Atom[4 * numbonds];
    int i = 0;
    col[3] = 0.9f;
    for (ListIterator<ROLS> li = bonds.listIterator(); li.hasNext(); ) {
        bond = (Bond) li.next();
        bond.setWire(la, i);
        atom1 = bond.getAtom(0);
        atom2 = bond.getAtom(1);
        atom1.getV3D(v1);
        atom2.getV3D(v2);
        a1[0] = (float) v1.x;
        a1[1] = (float) v1.y;
        a1[2] = (float) v1.z;
        a2[0] = (float) v2.x;
        a2[1] = (float) v2.y;
        a2[2] = (float) v2.z;
        // Find the bond center
        bondmidpoint.add(v1, v2);
        bondmidpoint.scale(0.5d);
        bondmidpoint.get(mid);
        // Atom #1
        Atom.AtomColor.get(atom1.getAtomicNumber()).get(col);
        atomLookUp[i] = atom1;
        la.setCoordinate(i, a1);
        la.setColor(i, col);
        la.setNormal(i, a2);
        i++;
        atomLookUp[i] = atom1;
        la.setCoordinate(i, mid);
        la.setColor(i, col);
        la.setNormal(i, a2);
        i++;
        // Atom #2
        Atom.AtomColor.get(atom2.getAtomicNumber()).get(col);
        atomLookUp[i] = atom2;
        la.setCoordinate(i, a2);
        la.setColor(i, col);
        la.setNormal(i, a1);
        i++;
        atomLookUp[i] = atom2;
        la.setCoordinate(i, mid);
        la.setColor(i, col);
        la.setNormal(i, a1);
        i++;
    }
    ColoringAttributes cola = new ColoringAttributes(new Color3f(), ColoringAttributes.SHADE_GOURAUD);
    Appearance app = new Appearance();
    lineAttributes = new LineAttributes();
    lineAttributes.setLineWidth(RendererCache.bondwidth);
    lineAttributes.setCapability(LineAttributes.ALLOW_WIDTH_WRITE);
    lineAttributes.setLineAntialiasingEnable(true);
    app.setLineAttributes(lineAttributes);
    app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);
    app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
    RenderingAttributes ra = new RenderingAttributes();
    ra.setAlphaTestValue(0.1f);
    ra.setAlphaTestFunction(RenderingAttributes.GREATER);
    ra.setDepthBufferEnable(true);
    ra.setDepthBufferWriteEnable(true);
    app.setRenderingAttributes(ra);
    app.setColoringAttributes(cola);
    Shape3D wireframe = new Shape3D(la, app);
    // PickTool.setCapabilities(wire, PickTool.INTERSECT_COORD);
    wireframe.setUserData(this);
    wireframe.setBounds(new BoundingSphere(new Point3d(0, 0, 0), 1000.0));
    try {
        wireframe.setBoundsAutoCompute(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    wireframe.setCapability(Shape3D.ALLOW_LOCAL_TO_VWORLD_READ);
    return wireframe;
}
Also used : ROLS(ffx.potential.bonded.ROLS) BoundingSphere(javax.media.j3d.BoundingSphere) Color3f(javax.vecmath.Color3f) RenderingAttributes(javax.media.j3d.RenderingAttributes) ColoringAttributes(javax.media.j3d.ColoringAttributes) Appearance(javax.media.j3d.Appearance) Atom(ffx.potential.bonded.Atom) LineAttributes(javax.media.j3d.LineAttributes) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d) LineArray(javax.media.j3d.LineArray) Shape3D(javax.media.j3d.Shape3D) Bond(ffx.potential.bonded.Bond)

Example 4 with Appearance

use of javax.media.j3d.Appearance in project ffx by mjschnie.

the class RendererCache method initCylinderGeom.

private static void initCylinderGeom(int res) {
    Appearance ap = new Appearance();
    Cylinder cyl = new Cylinder(1.0f, 1.0f, Cylinder.GENERATE_NORMALS | Cylinder.ENABLE_APPEARANCE_MODIFY | Cylinder.ENABLE_GEOMETRY_PICKING, 2 + res, 1, ap);
    for (int i = 0; i < 3; i++) {
        cylgeom[i][res] = cyl.getShape(i).getGeometry();
        try {
            cylgeom[i][res].setCapability(Geometry.ALLOW_INTERSECT);
            cylgeom[i][res].setCapability(GeometryArray.ALLOW_FORMAT_READ);
            cylgeom[i][res].setCapability(GeometryArray.ALLOW_COUNT_READ);
            cylgeom[i][res].setCapability(GeometryArray.ALLOW_COORDINATE_READ);
        } catch (Exception e) {
            return;
        }
    }
}
Also used : Cylinder(com.sun.j3d.utils.geometry.Cylinder) ShaderAppearance(javax.media.j3d.ShaderAppearance) Appearance(javax.media.j3d.Appearance)

Example 5 with Appearance

use of javax.media.j3d.Appearance in project ffx by mjschnie.

the class RendererCache method createAppearance.

private static Appearance createAppearance(Color3f col, ViewModel polygonType) {
    Appearance ap = null;
    if (shaderProgram != null) {
        ShaderAppearance sap = new ShaderAppearance();
        sap.setShaderProgram(shaderProgram);
        ap = sap;
    }
    if (ap == null) {
        ap = new Appearance();
    }
    Material mat = materialFactory(col);
    ap.setMaterial(mat);
    ap.setRenderingAttributes(renderingAttributes);
    ap.setColoringAttributes(coloringAttributes);
    ap.setLineAttributes(lineAttributes);
    ap.setPointAttributes(pointAttributes);
    if (polygonType == RendererCache.ViewModel.FILL) {
        ap.setPolygonAttributes(fillPolygonAttributes);
        fillAppearances.put(col, ap);
    } else if (polygonType == RendererCache.ViewModel.POINTS) {
        ap.setPolygonAttributes(pointPolygonAttributes);
        pointAppearances.put(col, ap);
    } else {
        ap.setPolygonAttributes(linePolygonAttributes);
        lineAppearances.put(col, ap);
    }
    return ap;
}
Also used : ShaderAppearance(javax.media.j3d.ShaderAppearance) Material(javax.media.j3d.Material) ShaderAppearance(javax.media.j3d.ShaderAppearance) Appearance(javax.media.j3d.Appearance)

Aggregations

Appearance (javax.media.j3d.Appearance)6 ShaderAppearance (javax.media.j3d.ShaderAppearance)3 Color3f (javax.vecmath.Color3f)3 Cylinder (com.sun.j3d.utils.geometry.Cylinder)2 Sphere (com.sun.j3d.utils.geometry.Sphere)2 BoundingSphere (javax.media.j3d.BoundingSphere)2 ColoringAttributes (javax.media.j3d.ColoringAttributes)2 LineArray (javax.media.j3d.LineArray)2 LineAttributes (javax.media.j3d.LineAttributes)2 Material (javax.media.j3d.Material)2 RenderingAttributes (javax.media.j3d.RenderingAttributes)2 Shape3D (javax.media.j3d.Shape3D)2 Point3d (javax.vecmath.Point3d)2 Vector3d (javax.vecmath.Vector3d)2 Cone (com.sun.j3d.utils.geometry.Cone)1 Atom (ffx.potential.bonded.Atom)1 Bond (ffx.potential.bonded.Bond)1 ROLS (ffx.potential.bonded.ROLS)1 Font (java.awt.Font)1 Font3D (javax.media.j3d.Font3D)1