Example usage for javax.media.j3d Shape3D getGeometry

List of usage examples for javax.media.j3d Shape3D getGeometry

Introduction

In this page you can find the example usage for javax.media.j3d Shape3D getGeometry.

Prototype

public Geometry getGeometry() 

Source Link

Document

Retrieves the geometry component at index 0 from this Shape3D node's list of geometry components.

Usage

From source file:TwistStripApp.java

public BranchGroup createSceneGraph() {

    BranchGroup contentRoot = new BranchGroup();

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    contentRoot.addChild(objSpin);/* w w  w . j  a v a  2s.  c o  m*/

    Shape3D twist = new Twist();
    objSpin.addChild(twist);

    // Duplicate the twist strip geometry and set the
    // appearance of the new Shape3D object to line mode
    // without culling.
    // Add the POLYGON_FILLED and POLYGON_LINE strips
    // in the scene graph at the same point.
    // This will show the triangles of the original Mobius strip that
    // are clipped. The PolygonOffset is set to prevent stitching.
    PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
    polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrib.setPolygonOffset(0.001f);
    Appearance polyAppear = new Appearance();
    polyAppear.setPolygonAttributes(polyAttrib);
    objSpin.addChild(new Shape3D(twist.getGeometry(), polyAppear));

    Alpha rotationAlpha = new Alpha(-1, 16000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 1
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    // make background white
    Background background = new Background(1.0f, 1.0f, 1.0f);
    background.setApplicationBounds(bounds);
    contentRoot.addChild(background);

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

    return contentRoot;
}

From source file:ShadowApp.java

public ShadowApp() {
    setLayout(new BorderLayout());
    Canvas3D c = new Canvas3D(null);
    add("Center", c);

    BranchGroup scene = new BranchGroup();

    Shape3D plane = new LitQuad(new Point3f(-0.3f, 0.6f, 0.2f), new Point3f(-0.3f, -0.3f, 0.2f),
            new Point3f(0.6f, -0.3f, -0.3f), new Point3f(0.6f, 0.6f, -0.3f));
    scene.addChild(plane);// w  w  w.jav  a  2  s  .  c  om

    Shape3D floor = new LitQuad(new Point3f(-1.0f, -0.5f, -1.0f), new Point3f(-1.0f, -0.5f, 1.0f),
            new Point3f(1.0f, -0.5f, 1.0f), new Point3f(1.0f, -0.5f, -1.0f));
    scene.addChild(floor);

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);

    DirectionalLight lightD1 = new DirectionalLight();
    lightD1.setInfluencingBounds(new BoundingSphere());
    Vector3f direction = new Vector3f(-1.0f, -1.0f, -1.0f);
    direction.normalize();
    lightD1.setDirection(direction);
    scene.addChild(lightD1);

    Shape3D shadow = new SimpleShadow((GeometryArray) plane.getGeometry(), direction,
            new Color3f(0.2f, 0.2f, 0.2f), -0.5f);
    scene.addChild(shadow);

    SimpleUniverse u = new SimpleUniverse(c);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();

    u.addBranchGraph(scene);
}

From source file:RedGreenGriffin.java

public BranchGroup createSceneGraph(int i) {
    System.out.println("Creating scene for: " + URLString);
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    try {// w  w  w.j  ava2s . co  m
        Transform3D myTransform3D = new Transform3D();
        myTransform3D.setTranslation(new Vector3f(+0.0f, -0.15f, -3.6f));
        TransformGroup objTrans = new TransformGroup(myTransform3D);
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        Transform3D t = new Transform3D();
        TransformGroup tg = new TransformGroup(t);
        tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objTrans.addChild(tg);
        URL url = new URL(URLString);
        ObjectFile f = new ObjectFile();
        f.setFlags(ObjectFile.RESIZE | ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY);
        System.out.println("About to load");

        Scene s = f.load(url);
        Transform3D myTrans = new Transform3D();
        myTrans.setTranslation(new Vector3f(eyeOffset, -eyeOffset, 0F));
        TransformGroup mytg = new TransformGroup(myTrans);
        //mytg.addChild(s.getSceneGroup());
        tg.addChild(mytg);
        Transform3D myTrans2 = new Transform3D();
        myTrans2.setTranslation(new Vector3f(-eyeOffset, +eyeOffset, 0F));
        TransformGroup mytg2 = new TransformGroup(myTrans2);
        //mytg2.addChild(s.getSceneGroup());
        Hashtable table = s.getNamedObjects();
        for (Enumeration e = table.keys(); e.hasMoreElements();) {
            Object key = e.nextElement();
            System.out.println(key);
            Object obj = table.get(key);
            System.out.println(obj.getClass().getName());
            Shape3D shape = (Shape3D) obj;
            //shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
            Appearance ap = new Appearance();
            Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
            Color3f red = new Color3f(0.7f, .0f, .15f);
            Color3f green = new Color3f(0f, .7f, .15f);
            ap.setMaterial(new Material(green, black, green, black, 1.0f));
            Appearance ap2 = new Appearance();
            ap2.setMaterial(new Material(red, black, red, black, 1.0f));
            float transparencyValue = 0.5f;
            TransparencyAttributes t_attr = new TransparencyAttributes(TransparencyAttributes.BLENDED,
                    transparencyValue, TransparencyAttributes.BLEND_SRC_ALPHA,
                    TransparencyAttributes.BLEND_ONE);
            ap2.setTransparencyAttributes(t_attr);
            ap2.setRenderingAttributes(new RenderingAttributes());
            ap.setTransparencyAttributes(t_attr);
            ap.setRenderingAttributes(new RenderingAttributes());
            // bg.addChild(ap);
            shape.setAppearance(ap);
            mytg2.addChild(new Shape3D(shape.getGeometry(), ap2));
            mytg.addChild(new Shape3D(shape.getGeometry(), ap));
        }
        tg.addChild(mytg2);
        System.out.println("Finished Loading");
        BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
        Color3f light1Color = new Color3f(.9f, 0.9f, 0.9f);
        Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
        DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
        light1.setInfluencingBounds(bounds);
        objTrans.addChild(light1);
        // Set up the ambient light
        Color3f ambientColor = new Color3f(1.0f, .4f, 0.3f);
        AmbientLight ambientLightNode = new AmbientLight(ambientColor);
        ambientLightNode.setInfluencingBounds(bounds);
        objTrans.addChild(ambientLightNode);

        MouseRotate behavior = new MouseRotate();
        behavior.setTransformGroup(tg);
        objTrans.addChild(behavior);
        // Create the translate behavior node
        MouseTranslate behavior3 = new MouseTranslate();
        behavior3.setTransformGroup(tg);
        objTrans.addChild(behavior3);
        behavior3.setSchedulingBounds(bounds);

        KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(tg);
        keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0));
        objTrans.addChild(keyNavBeh);

        behavior.setSchedulingBounds(bounds);
        objRoot.addChild(objTrans);
    } catch (Throwable t) {
        System.out.println("Error: " + t);
    }
    return objRoot;
}

From source file:MyJava3D.java

public MyJava3D() {
    // load the object file
    Scene scene = null;/*from   ww  w.  j av a2s .com*/
    Shape3D shape = null;

    // read in the geometry information from the data file
    ObjectFile objFileloader = new ObjectFile(ObjectFile.RESIZE);

    try {
        scene = objFileloader.load("hand1.obj");
    } catch (Exception e) {
        scene = null;
        System.err.println(e);
    }

    if (scene == null)
        System.exit(1);

    // retrieve the Shape3D object from the scene
    BranchGroup branchGroup = scene.getSceneGroup();
    shape = (Shape3D) branchGroup.getChild(0);

    GeometryArray geometryArray = (GeometryArray) shape.getGeometry();

    // add the geometry to the rendering engine...
    renderingEngine.addGeometry(geometryArray);

    // create a rendering surface and bind the rendering engine
    renderingSurface = new RenderingSurface(renderingEngine, geometryUpdater);

    // start the rendering surface and add it to the content panel
    renderingSurface.start();
    getContentPane().add(renderingSurface);

    // disable automatic close support for Swing frame.
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

    // adds the window listener
    addWindowListener(new WindowAdapter() {
        // handles the system exit window message
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
}