Example usage for javax.media.j3d Appearance ALLOW_MATERIAL_WRITE

List of usage examples for javax.media.j3d Appearance ALLOW_MATERIAL_WRITE

Introduction

In this page you can find the example usage for javax.media.j3d Appearance ALLOW_MATERIAL_WRITE.

Prototype

int ALLOW_MATERIAL_WRITE

To view the source code for javax.media.j3d Appearance ALLOW_MATERIAL_WRITE.

Click Source Link

Document

Specifies that this Appearance object allows writing its material component information.

Usage

From source file:edu.uci.ics.jung.visualization3d.VisualizationViewer.java

public BranchGroup createSceneGraph(final Canvas3D canvas) {

    objRoot = new BranchGroup();
    objRoot.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    objRoot.setCapability(Group.ALLOW_CHILDREN_WRITE);

    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    //      t3d.setScale(0.05);
    objScale.setTransform(t3d);/*from www.  j  a va 2s  .  c o m*/
    objRoot.addChild(objScale);

    Transform3D tt = new Transform3D();
    tt.setScale(.05);
    tt.setTranslation(new Vector3f(0, 0, -30.f));
    objTrans = new TransformGroup(tt);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objTrans.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
    objScale.addChild(objTrans);
    //      objRoot.addChild(objTrans);

    // Create Colors, Materials,  and Appearances.
    Appearance look = new Appearance();
    Color3f objColor = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f black = new Color3f(0.f, 0.f, 0.f);
    Color3f white = new Color3f(1.0f, 1.0f, 0.6f);
    Color3f gray = new Color3f(.2f, .2f, .2f);
    Color3f red = new Color3f(1.0f, 0, 0);
    Color3f yellow = new Color3f(1, 1, 0);

    Material objMaterial = new Material(objColor, black, objColor, white, 100.0f);
    Material blackMaterial = new Material(objColor, black, black, objColor, 10.0f);
    Material whiteMaterial = new Material(white, white, white, white, 100.0f);
    Material grayMaterial = new Material(gray, black, gray, gray, 100.0f);

    Material redMaterial = new Material(red, black, red, red, 100.0f);
    Material yellowMaterial = new Material(yellow, black, yellow, yellow, 100);

    look.setMaterial(new Material(objColor, black, objColor, white, 100.0f));
    Appearance blackLook = new Appearance();
    blackLook.setMaterial(blackMaterial);

    Appearance whiteLook = new Appearance();
    whiteLook.setMaterial(whiteMaterial);

    Appearance grayLook = new Appearance();
    grayLook.setMaterial(grayMaterial);
    grayLook.setCapability(Appearance.ALLOW_MATERIAL_READ);
    grayLook.setCapability(Appearance.ALLOW_MATERIAL_WRITE);

    final Appearance redLook = new Appearance();
    redLook.setMaterial(redMaterial);
    //      vertexLook = redLook;

    Appearance objLook = new Appearance();
    objLook.setMaterial(objMaterial);
    grayLook = objLook;
    final Appearance yellowLook = new Appearance();
    yellowLook.setMaterial(yellowMaterial);
    Bounds bounds = new BoundingSphere(new Point3d(), 300);

    MouseRotate behavior1 = new MouseRotate();
    behavior1.setTransformGroup(objTrans);
    objTrans.addChild(behavior1);
    behavior1.setSchedulingBounds(bounds);

    MouseWheelZoom behavior2 = new MouseWheelZoom();
    behavior2.setTransformGroup(objTrans);
    //      behavior2.setFactor(10);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    MouseTranslate behavior3 = new MouseTranslate();
    behavior3.setTransformGroup(objTrans);
    objTrans.addChild(behavior3);
    behavior3.setSchedulingBounds(bounds);

    PickTranslateBehavior ptb = new PickTranslateBehavior(objRoot, canvas, bounds, PickTool.GEOMETRY);
    ptb.setSchedulingBounds(bounds);
    //      objTrans.addChild(ptb);
    ptb.setupCallback(new PickingCallback() {

        public void transformChanged(int type, TransformGroup tg) {
            if (tg == null)
                return;
            Transform3D t3d = new Transform3D();
            tg.getTransform(t3d);
            //            System.err.println(tg+" transformChanged \n"+t3d);
            Point3f p1 = new Point3f();
            V v = vertexMap.getKey(tg);
            //            Transform3D lvw = new Transform3D();
            //            tg.getLocalToVworld(lvw);
            //            System.err.println("lvw = \n"+lvw);
            //            lvw.invert();
            //            System.err.println("invert lvw = \n"+lvw);
            Point3f p0 = layout.transform(v);
            //            Transform3D vwip = new Transform3D();
            //            canvas.getVworldToImagePlate(vwip);
            //            System.err.println("vwip=\n"+vwip);
            //            t3d.mul(lvw);
            t3d.transform(p1);
            //            scale.transform(p1);
            System.err.println(
                    "change location for vertex " + v + ", transformGroup " + tg + " from " + p0 + " to " + p1);
            //            p1.set(p1.getX()*2,p1.getY()*2,p1.getZ()*2);
            //            layout.setLocation(v, p1);

        }
    });

    PickSphereBehavior psb = new PickSphereBehavior(objRoot, canvas, bounds);

    PickVertexBehavior pvb = new PickVertexBehavior(objRoot, canvas, bounds,
            renderContext.getPickedVertexState());
    objTrans.addChild(pvb);
    pvb.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            for (V v : graph.getVertices()) {
                VertexGroup<V> vg = vertexMap.get(v);
                Appearance look = redLook;
                if (renderContext.getPickedVertexState().isPicked(v)) {
                    look = yellowLook;
                }
                Node node = vg.getShape();
                if (node instanceof Primitive) {
                    ((Primitive) node).setAppearance(look);
                }
            }

        }
    });

    //Shine it with two colored lights.
    Color3f lColor1 = new Color3f(.5f, .5f, .5f);
    Color3f lColor2 = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lDir2 = new Vector3f(-1.0f, 0.0f, -1.0f);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    AmbientLight ambient = new AmbientLight(lColor1);
    lgt2.setInfluencingBounds(bounds);
    ambient.setInfluencingBounds(bounds);
    objRoot.addChild(lgt2);
    objRoot.addChild(ambient);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    //      VisRunner runner = new VisRunner((IterativeContext)elayout);
    //      runner.relax();

    return objRoot;
}

From source file:NodesTest.java

public CollisionBehavior(BranchGroup pickRoot, TransformGroup collisionObject, Appearance app,
        Vector3d posVector, Vector3d incVector) {
    // save references to the objects
    this.pickRoot = pickRoot;
    this.collisionObject = collisionObject;
    this.objectAppearance = app;

    incrementVector = incVector;//  w w  w  .j  a va 2  s. c  o  m
    positionVector = posVector;

    // create the WakeupCriterion for the behavior
    WakeupCriterion criterionArray[] = new WakeupCriterion[1];
    criterionArray[0] = new WakeupOnElapsedFrames(ELAPSED_FRAME_COUNT);

    objectAppearance.setCapability(Appearance.ALLOW_MATERIAL_WRITE);

    collisionObject.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    collisionObject.setCapability(Node.ALLOW_BOUNDS_READ);

    // save the WakeupCriterion for the behavior
    m_WakeupCondition = new WakeupOr(criterionArray);
}

From source file:IntersectTest.java

public IntersectInfoBehavior(Canvas3D canvas3D, BranchGroup branchGroup, float size) {
    pickCanvas = new PickCanvas(canvas3D, branchGroup);
    pickCanvas.setTolerance(5.0f);/*w  ww .  j  a  v  a2s  .  c o m*/
    pickCanvas.setMode(PickCanvas.GEOMETRY_INTERSECT_INFO);
    this.size = size;
    // Create an Appearance.
    redlook = new Appearance();
    Color3f objColor = new Color3f(0.5f, 0.0f, 0.0f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    redlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    redlook.setCapability(Appearance.ALLOW_MATERIAL_WRITE);

    redlookwf = new Appearance();
    redlookwf.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    PolygonAttributes pa = new PolygonAttributes();
    pa.setPolygonMode(pa.POLYGON_LINE);
    pa.setCullFace(pa.CULL_NONE);
    redlookwf.setPolygonAttributes(pa);

    oldlook = new Appearance();
    objColor = new Color3f(1.0f, 1.0f, 1.0f);
    oldlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));

    greenlook = new Appearance();
    objColor = new Color3f(0.0f, 0.8f, 0.0f);
    greenlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    bluelook = new Appearance();
    objColor = new Color3f(0.0f, 0.0f, 0.8f);
    bluelook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    for (int i = 0; i < 6; i++) {
        switch (i) {
        case 0:
            sph[i] = new Sphere(size * 1.15f, redlook);
            break;
        case 1:
            sph[i] = new Sphere(size * 1.1f, greenlook);
            break;
        default:
            sph[i] = new Sphere(size, bluelook);
            break;
        }
        sph[i].setPickable(false);
        sphTrans[i] = new TransformGroup();
        sphTrans[i].setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        sphTrans[i].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        // Add sphere, transform
        branchGroup.addChild(sphTrans[i]);
        sphTrans[i].addChild(sph[i]);
    }
}

From source file:AppearanceTest.java

protected void setAppearanceCapability() {
    m_Appearance.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
}