Package javax.media.j3d

Examples of javax.media.j3d.Shape3D


        float[] coords = GeodeMaker.createGeode(10);
      TriangleArray ta = new TriangleArray(coords.length / 3, GeometryArray.COORDINATES | GeometryArray.NORMALS);
      ta.setCoordinates(0,coords);
      ta.setNormals(0,coords);
     
      Shape3D s = new Shape3D(ta);
        anonymousNodeNumber++;
        name = NodeResourcesManager.getNodeName("Sphere") + ((anonymousNodeNumber == 1) ? "" : String.valueOf(anonymousNodeNumber));
        return s;
    }
View Full Code Here


    // Setup color buffer
    ta.setColorRefBuffer(new J3DBuffer(nioColors));
      ta.setCapability(TriangleArray.ALLOW_COLOR_WRITE);
      ta.setCapabilityIsFrequent(TriangleArray.ALLOW_COLOR_WRITE);
     
      Shape3D shape3d = new Shape3D(ta);
     
    // The appearance of a shape has many interesting features.
      // In particular, in case one wants to display lines (edges) over the shape,
      // it is possible to set a polygon offset to the triangles. This offset is in fact
      // a distance in the Z-buffer => an offset of 1 for example on the triangles,
      // will place them behind the edges. @see PolygonAttributes.setPolygonOffset,
      // and the code in syn3d.nodes.java3d.Shape3DJava3D
      // Here the shape is created without an appearance and it is managed
      // by ShapeNodeJava3D. See this class for more information
        shape3d.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
        shape3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

        // The shape will be pickable, which means the user can click on the shape in 3D
        // space from the 2D window
        PickTool.setCapabilities(shape3d,PickTool.INTERSECT_FULL);
        shape3d.setCapability(Shape3D.ALLOW_PICKABLE_READ);
        shape3d.setCapability(Shape3D.ALLOW_PICKABLE_WRITE);
    shape3d.setPickable(true);

        // Create a node in the JTree for this shape
    new ShapeNodeJava3D(this, shape3d);

    // Syn3D picking code uses the user data of a Java3D object to find back a node
        // that handles the picking. Let's declare this object as the handler instead of
    // ShapeNodeJava3D
    shape3d.setUserData(this);
   
    // scale the shape to have a reasonable size
    // and translate it to the origin
    Bounds bounds = transformGroup.getBounds();
    if (bounds instanceof BoundingSphere) {
View Full Code Here

  // This method is called directly by the plugin on key press, as an example how to do it
  public void showResult(int num) {

    // Get the shape back from the children list. Ignore case when there is no file loaded
    if (children.size()<1) return;
    Shape3D shape3d = (Shape3D)((ShapeNodeJava3D)children.get(0)).get3DObject();
   
    // Find the color buffer
    FloatBuffer colors = (FloatBuffer)(((TriangleArray)shape3d.getGeometry()).getColorRefBuffer().getBuffer());
   
    // helper variables
    int d = num+3;
    if (d>=names.length) return; // ignore keypressed events for unknown variables
    currentVariable = d;
View Full Code Here

        return super.canRemoveSceneGraphObject(obj,oldObj);
    }
   
    @Override
    public void removeSceneGraphObject(SceneGraphObject obj, SceneGraphObject oldObj){
        Shape3D s=(Shape3D)getGraphObject();
        if(obj instanceof Geometry){
            boolean forced=forceCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
            s.removeGeometry((Geometry)obj);
            if(forced) restoreCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
            return;
        }
        else if (obj instanceof Appearance){
            if(oldObj==null || !(oldObj instanceof Appearance)){
                throw new RuntimeException("removeSceneGraphObject invalid argument old="+oldObj.getClass());
            }
            boolean forced=forceCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
            s.setAppearance((Appearance)oldObj);
            if(forced) restoreCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
            return;
        }
        throw new RuntimeException("removeSceneGraphObject invalid argument ="+obj.getClass());
    }
View Full Code Here

    public static void makeSolidAxis(Group group, float length, float arrowLength,
            float radius, float arrowRadius, Color color, Color arrowColor, int divisions) {
       
        float l=length-arrowLength;
       
        Shape3D cy= new Shape3D(Geometries.cylinder(radius, l-arrowLength, divisions));
        group.addChild(cy);
        Shape3D bcy= new Shape3D(Geometries.disc(radius, divisions,false,0.));
        group.addChild(bcy);
        Shape3D co= new Shape3D(Geometries.cone(arrowRadius, arrowLength, divisions,true,l-arrowLength));
        group.addChild(co);
        Shape3D bco= new Shape3D(Geometries.disc(arrowRadius, divisions,false,l-arrowLength));
        group.addChild(bco);

        Color3f aColor  = new Color3f(0.1f, 0.1f, 0.1f);
        Color3f eColor  = new Color3f(0.0f, 0.0f, 0.0f);
        Color3f sColor  = new Color3f(1.0f, 1.0f, 1.0f);

        Appearance cya=new Appearance();
        cya.setColoringAttributes(new ColoringAttributes(new Color3f(color),ColoringAttributes.SHADE_GOURAUD));
        Material cym = new Material(aColor, eColor, new Color3f(color), sColor, 100.0f);
        cym.setLightingEnable(true);
        cya.setMaterial(cym);
        cy.setAppearance(cya);
        bcy.setAppearance(cya);

        Appearance coa=new Appearance();
        coa.setColoringAttributes(new ColoringAttributes(new Color3f(arrowColor),ColoringAttributes.SHADE_GOURAUD));
        Material com = new Material(aColor, eColor, new Color3f(arrowColor), sColor, 100.0f);
        com.setLightingEnable(true);
        coa.setMaterial(com);
        co.setAppearance(coa);
        bco.setAppearance(coa);
    }
View Full Code Here

            Appearance a = new Appearance();
            a.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0));
            ColoringAttributes ca = new ColoringAttributes();
            ca.setColor(0.0f,0.0f,1.0f);
            a.setColoringAttributes(ca);
            Shape3D saxis = new Shape3D(la, a);
            saxis.setName("X");
            g.addChild(saxis);
           
            // Y axis in green
            axis = makeAxis(1);
            la = new LineArray(axis.length/3, LineArray.COORDINATES);
            la.setCoordinates(0,axis);
            a = new Appearance();
            a.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0));
            ca = new ColoringAttributes();
            ca.setColor(0.0f,1.0f,0.0f);
            a.setColoringAttributes(ca);
            saxis = new Shape3D(la, a);
            saxis.setName("Y");
            g.addChild(saxis);
           
            // Z axis in purple
            axis = makeAxis(2);
            la = new LineArray(axis.length/3, LineArray.COORDINATES);
            la.setCoordinates(0,axis);
            a = new Appearance();
            a.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0));
            ca = new ColoringAttributes();
            ca.setColor(1.0f,0.0f,1.0f);
            a.setColoringAttributes(ca);
            saxis = new Shape3D(la, a);
            saxis.setName("Z");
            g.addChild(saxis);
           
            gn.addChild(g);
           
            AddEdit ae=new AddEdit(gn, g, null);
View Full Code Here

                    getLocation(),"Disc"); // TODO i18n
            DiscDialog.Result n=d.getResult();
            if(n!=null){
                GroupNode gn=(GroupNode)getNode();
       
                Shape3D sd= new Shape3D(Geometries.disc(n.radius, n.divisions,n.up,0.));
                Color3f aColor  = new Color3f(0.1f, 0.1f, 0.1f);
                Color3f eColor  = new Color3f(0.0f, 0.0f, 0.0f);
                Color3f sColor  = new Color3f(1.0f, 1.0f, 1.0f);

                Appearance cya=new Appearance();
                cya.setColoringAttributes(new ColoringAttributes(new Color3f(Color.WHITE),ColoringAttributes.SHADE_GOURAUD));
                cya.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0));
                Material cym = new Material(aColor, eColor, new Color3f(Color.WHITE), sColor, 100.0f);
                cym.setLightingEnable(true);
                cya.setMaterial(cym);
                sd.setAppearance(cya);

                gn.addChild(sd);
       
                AddEdit ae=new AddEdit(gn, sd, null);
                getNode().getTree().getUndoableEditListener().undoableEditHappened(
View Full Code Here

                Appearance a = new Appearance();
                a.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0));
                ColoringAttributes ca = new ColoringAttributes();
                ca.setColor(1.0f,1.0f,1.0f);
                a.setColoringAttributes(ca);
                Shape3D sd = new Shape3D(la, a);

                gn.addChild(sd);
       
                AddEdit ae=new AddEdit(gn, sd, null);
                getNode().getTree().getUndoableEditListener().undoableEditHappened(
View Full Code Here

        }
       
        void apply(double[] v){
            GroupNode gn=(GroupNode)getNode();
           
            Shape3D sd= new Shape3D(Geometries.polygon(v));
            Color3f aColor  = new Color3f(0.1f, 0.1f, 0.1f);
            Color3f eColor  = new Color3f(0.0f, 0.0f, 0.0f);
            Color3f sColor  = new Color3f(1.0f, 1.0f, 1.0f);

            Appearance cya=new Appearance();
            cya.setColoringAttributes(new ColoringAttributes(new Color3f(Color.WHITE),ColoringAttributes.SHADE_GOURAUD));
            cya.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0));
            Material cym = new Material(aColor, eColor, new Color3f(Color.WHITE), sColor, 100.0f);
            cym.setLightingEnable(true);
            cya.setMaterial(cym);
            sd.setAppearance(cya);

            gn.addChild(sd);
   
            AddEdit ae=new AddEdit(gn, sd, null);
            getNode().getTree().getUndoableEditListener().undoableEditHappened(
View Full Code Here

        super(tree, graphObject, getChildren);
    }

    @Override
    protected void getSceneGraphChildren(ArrayList<Object> list) {
        Shape3D s=(Shape3D)getGraphObject();
        Enumeration<?> e=s.getAllGeometries();
        while(e.hasMoreElements()){
            list.add(e.nextElement());
        }
        list.add(s.getAppearance());
    }
View Full Code Here

TOP

Related Classes of javax.media.j3d.Shape3D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.