List of usage examples for javax.media.j3d PolygonAttributes CULL_NONE
int CULL_NONE
To view the source code for javax.media.j3d PolygonAttributes CULL_NONE.
Click Source Link
From source file:BooksDemo.java
private Appearance createTexture(String fileName) { Image sourceImage = UIHelper.readImage(fileName); if (sourceImage == null) System.out.println("Image could not be loaded from " + fileName); TextureLoader loader = new TextureLoader(sourceImage, this); ImageComponent2D image = loader.getImage(); if (image == null) System.out.println("Texture could not be loaded from " + fileName); Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image.getWidth(), image.getHeight()); texture.setImage(0, image);// w w w. ja v a 2 s . c om texture.setEnable(true); texture.setMagFilter(Texture.BASE_LEVEL_LINEAR); texture.setMinFilter(Texture.BASE_LEVEL_LINEAR); Appearance appearance = new Appearance(); PolygonAttributes polyAttributes = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0f); appearance.setPolygonAttributes(polyAttributes); appearance.setTexture(texture); TextureAttributes textureAttributes = new TextureAttributes(); appearance.setTextureAttributes(textureAttributes); return appearance; }
From source file:ExBluePrint.java
private Group buildGadget() { if (debug)//from w w w. j a va 2 s. c om System.err.println(" gadget..."); // // Create two appearances: // wireframeApp: draw as blue wireframe // shadedApp: draw as metalic shaded polygons // // Wireframe: // no Material - defaults to coloring attributes color // polygons as lines, with backfaces // thick lines Appearance wireframeApp = new Appearance(); ColoringAttributes wireframeCatt = new ColoringAttributes(); wireframeCatt.setColor(0.0f, 0.2559f, 0.4213f); wireframeCatt.setShadeModel(ColoringAttributes.SHADE_FLAT); wireframeApp.setColoringAttributes(wireframeCatt); PolygonAttributes wireframePatt = new PolygonAttributes(); wireframePatt.setPolygonMode(PolygonAttributes.POLYGON_LINE); wireframePatt.setCullFace(PolygonAttributes.CULL_NONE); wireframeApp.setPolygonAttributes(wireframePatt); LineAttributes wireframeLatt = new LineAttributes(); wireframeLatt.setLineWidth(2.0f); wireframeApp.setLineAttributes(wireframeLatt); // Shaded: // silver material Appearance shadedApp = new Appearance(); Material shadedMat = new Material(); shadedMat.setAmbientColor(0.30f, 0.30f, 0.30f); shadedMat.setDiffuseColor(0.30f, 0.30f, 0.50f); shadedMat.setSpecularColor(0.60f, 0.60f, 0.80f); shadedMat.setShininess(0.10f); shadedApp.setMaterial(shadedMat); ColoringAttributes shadedCatt = new ColoringAttributes(); shadedCatt.setShadeModel(ColoringAttributes.SHADE_GOURAUD); shadedApp.setColoringAttributes(shadedCatt); // // Create a switch group to hold two versions of the // shape: one wireframe, and one shaded // Transform3D tr = new Transform3D(); tr.set(new Vector3f(-1.0f, 0.2f, 0.0f)); TransformGroup gadget = new TransformGroup(tr); shadingSwitch = new Switch(); shadingSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); Group wireframe = new Group(); Group shaded = new Group(); shadingSwitch.addChild(wireframe); shadingSwitch.addChild(shaded); shadingSwitch.setWhichChild(1); // shaded gadget.addChild(shadingSwitch); // // Build a gear (wireframe and shaded) // tr = new Transform3D(); tr.rotY(Math.PI / 2.0); TransformGroup tg = new TransformGroup(tr); SpurGear gear = new SpurGearThinBody(24, // tooth count 1.6f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness wireframeApp);// appearance tg.addChild(gear); wireframe.addChild(tg); tg = new TransformGroup(tr); gear = new SpurGearThinBody(24, // tooth count 1.6f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness shadedApp); // appearance tg.addChild(gear); shaded.addChild(tg); // // Build another gear (wireframe and shaded) // tr.rotY(Math.PI / 2.0); Vector3f trans = new Vector3f(-0.5f, 0.0f, 0.0f); tr.setTranslation(trans); tg = new TransformGroup(tr); gear = new SpurGearThinBody(30, // tooth count 2.0f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness wireframeApp);// appearance tg.addChild(gear); wireframe.addChild(tg); tg = new TransformGroup(tr); gear = new SpurGearThinBody(30, // tooth count 2.0f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness shadedApp); // appearance tg.addChild(gear); shaded.addChild(tg); // // Build a cylindrical shaft (wireframe and shaded) // tr.rotZ(-Math.PI / 2.0); trans = new Vector3f(1.0f, 0.0f, 0.0f); tr.setTranslation(trans); tg = new TransformGroup(tr); Cylinder cyl = new Cylinder(0.3f, // radius 4.0f, // length Primitive.GENERATE_NORMALS, // format 16, // radial resolution 1, // length-wise resolution wireframeApp);// appearance tg.addChild(cyl); wireframe.addChild(tg); tg = new TransformGroup(tr); cyl = new Cylinder(0.3f, // radius 4.0f, // length Primitive.GENERATE_NORMALS, // format 16, // radial resolution 1, // length-wise resolution shadedApp); // appearance tg.addChild(cyl); shaded.addChild(tg); // // Build shaft teeth (wireframe and shaded) // tr.rotY(Math.PI / 2.0); trans = new Vector3f(2.05f, 0.0f, 0.0f); tr.setTranslation(trans); tg = new TransformGroup(tr); gear = new SpurGear(12, // tooth count 0.5f, // pitch circle radius 0.3f, // shaft radius 0.05f, // addendum 0.05f, // dedendum 1.5f, // gear thickness 0.8f, // tooth tip thickness wireframeApp);// appearance tg.addChild(gear); wireframe.addChild(tg); tg = new TransformGroup(tr); gear = new SpurGear(12, // tooth count 0.5f, // pitch circle radius 0.3f, // shaft radius 0.05f, // addendum 0.05f, // dedendum 1.5f, // gear thickness 0.8f, // tooth tip thickness shadedApp); // appearance tg.addChild(gear); shaded.addChild(tg); return gadget; }
From source file:LightScopeApp.java
BranchGroup createScene() { BranchGroup scene = new BranchGroup(); TransformGroup tableTG = new TransformGroup(); TransformGroup lampTG = new TransformGroup(); TransformGroup litBoxTG = new TransformGroup(); TransformGroup unLitBoxTG = new TransformGroup(); scene.addChild(tableTG);/* ww w. j a va2 s . c o m*/ tableTG.addChild(lampTG); tableTG.addChild(litBoxTG); tableTG.addChild(unLitBoxTG); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); Color3f blue = new Color3f(0.0f, 1.0f, 0.0f); Color3f green = new Color3f(0.0f, 0.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Vector3f transVector = new Vector3f(); Transform3D transTransform = new Transform3D(); transVector.set(0.0f, -0.4f, 0.5f); transTransform.setTranslation(transVector); tableTG.setTransform(transTransform); transVector.set(-0.4f, 0.001f, 0.1f); transTransform.setTranslation(transVector); lampTG.setTransform(transTransform); transVector.set(-0.2f, 0.1f, 0.2f); transTransform.setTranslation(transVector); litBoxTG.setTransform(transTransform); transVector.set(0.3f, 0.1f, -0.4f); transTransform.setTranslation(transVector); unLitBoxTG.setTransform(transTransform); Shape3D tablePlane = createXZPlane(new Point3f(-1.0f, 0.0f, -1.0f), new Point3f(-1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, -1.0f)); tablePlane.setAppearance(createMaterialAppearance(white)); tableTG.addChild(tablePlane); litBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, createMaterialAppearance(red))); Shape3D shadowPlane = createXZPlane(new Point3f(0.1f, -0.095f, -0.1f), new Point3f(0.1f, -0.095f, 0.1f), new Point3f(0.2f, -0.095f, 0.15f), new Point3f(0.2f, -0.095f, -0.15f)); shadowPlane.setAppearance(createMaterialAppearance(black)); litBoxTG.addChild(shadowPlane); Appearance redGlowMat = createMaterialAppearance(red); // redGlowMat.getMaterial().setEmissiveColor(0.5f, 0.5f, 0.5f); unLitBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, redGlowMat)); Shape3D lamp = createLampShape(); Appearance lampAppearance = createMaterialAppearance(blue); PolygonAttributes polyAttrib = new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); polyAttrib.setBackFaceNormalFlip(true); lampAppearance.setPolygonAttributes(polyAttrib); lamp.setAppearance(lampAppearance); lampTG.addChild(lamp); PointLight lampLight = new PointLight(); lampLight.setPosition(0.1f, 0.5f, -0.1f); lampLight.setInfluencingBounds(new BoundingSphere()); lampTG.addChild(lampLight); Shape3D litPlane = createXZPlane(new Point3f(-0.4f, 0.0f, -0.4f), new Point3f(-0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, -0.4f)); litPlane.setAppearance(createMaterialAppearance(white)); lampTG.addChild(litPlane); lampLight.addScope(lampTG); lampLight.addScope(litBoxTG); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA); DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere()); lightD1.setColor(new Color3f(0.4f, 0.4f, 0.4f)); Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f); lightDir.normalize(); lightD1.setDirection(lightDir); scene.addChild(lightD1); DirectionalLight lightD2 = new DirectionalLight(); lightD2.setInfluencingBounds(new BoundingSphere()); lightD2.setColor(new Color3f(0.2f, 0.2f, 0.2f)); lightDir.set(1.0f, -1.0f, -1.0f); lightDir.normalize(); lightD2.setDirection(lightDir); scene.addChild(lightD2); Background bg = new Background(); bg.setColor(1.0f, 1.0f, 1.0f); bg.setApplicationBounds(new BoundingSphere()); scene.addChild(bg); return scene; }
From source file:ExDepthCue.java
public Shape3D buildSurface(double freqAlpha, double freqTheta, double radius, float red, float green, float blue) { int nAngles = 64; double amp = radius / 4.0; int nAlpha = nAngles / 2; double theta, alpha; double x, y, z, rprime, r; double deltaTheta, deltaAlpha; int i, j;//from ww w .ja v a 2s . c o m int i1, i2, i3, i4; deltaTheta = 360.0 / (nAngles - 1.0); deltaAlpha = 180.0 / (nAlpha - 1.0); // Build an appearance Appearance app = new Appearance(); LineAttributes latt = new LineAttributes(); latt.setLineWidth(1.0f); app.setLineAttributes(latt); ColoringAttributes catt = new ColoringAttributes(); catt.setColor(red, green, blue); app.setColoringAttributes(catt); PolygonAttributes patt = new PolygonAttributes(); patt.setCullFace(PolygonAttributes.CULL_NONE); patt.setPolygonMode(PolygonAttributes.POLYGON_LINE); app.setPolygonAttributes(patt); // Compute coordinates double[] coordinates = new double[nAlpha * nAngles * 3]; alpha = 90.0; int n = 0; for (i = 0; i < nAlpha; i++) { theta = 0.0; for (j = 0; j < nAngles; j++) { r = radius + amp * Math.sin((freqAlpha * ((double) i / (double) (nAlpha - 1)) + freqTheta * ((double) j / (double) (nAngles - 1))) * 2.0 * Math.PI); y = r * Math.sin(alpha / 180.0 * Math.PI); rprime = y / Math.tan(alpha / 180.0 * Math.PI); x = rprime * Math.cos(theta / 180.0 * Math.PI); z = rprime * Math.sin(theta / 180.0 * Math.PI); coordinates[n + 0] = x; coordinates[n + 1] = y; coordinates[n + 2] = z; n += 3; theta += deltaTheta; } alpha -= deltaAlpha; } // Compute coordinate indexes int[] indexes = new int[(nAlpha - 1) * nAngles * 4]; n = 0; for (i = 0; i < nAlpha - 1; i++) { for (j = 0; j < nAngles; j++) { i1 = i * nAngles + j; if (j == nAngles - 1) { i2 = i1 - j; i3 = (i + 1) * nAngles; } else { i2 = i1 + 1; i3 = (i + 1) * nAngles + j + 1; } i4 = (i + 1) * nAngles + j; indexes[n + 0] = i1; indexes[n + 1] = i2; indexes[n + 2] = i3; indexes[n + 3] = i4; n += 4; } } // Build the shape IndexedQuadArray lines = new IndexedQuadArray(coordinates.length / 3, // Number // of // coordinates GeometryArray.COORDINATES, // coordinates only indexes.length); // Number of indexes lines.setCoordinates(0, coordinates); lines.setCoordinateIndices(0, indexes); Shape3D shape = new Shape3D(lines, app); return shape; }
From source file:KeyNavigateTest.java
public Group createCeiling(Group g) { System.out.println("Creating ceiling"); Group ceilingGroup = new Group(); Land ceilingTile = null;/*from w ww . java 2 s .co m*/ // because we are technically viewing the ceiling from below // we want to switch the normals using a PolygonAttributes. Appearance app = new Appearance(); app.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false)); g.addChild(ceilingGroup); final double kNumTiles = 6; for (double x = -FLOOR_WIDTH + FLOOR_WIDTH / (2 * kNumTiles); x < FLOOR_WIDTH; x = x + FLOOR_WIDTH / kNumTiles) { for (double z = -FLOOR_LENGTH + FLOOR_LENGTH / (2 * kNumTiles); z < FLOOR_LENGTH; z = z + FLOOR_LENGTH / kNumTiles) { ceilingTile = new Land(this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE); ceilingTile.createObject(app, new Vector3d(x, m_kCeilingLevel, z), new Vector3d(FLOOR_WIDTH / (2 * kNumTiles), 1, FLOOR_LENGTH / (2 * kNumTiles)), "ceiling.gif", null, null); } } return ceilingGroup; }
From source file:MouseNavigateTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // note that we are creating a TG *above* the TG // the is being controlled by the mouse behaviors. // The SUN mouse translate behavior would fail in this // instance as all movement would be in the X-Y plane // irrespective of any TG above the object. // The TornadoMouseTranslate behavior always moves an object // parrallel to the image plane TransformGroup objTrans1 = new TransformGroup(); Transform3D t3d = new Transform3D(); objTrans1.getTransform(t3d);/*from ww w.j av a 2s . c om*/ t3d.setEuler(new Vector3d(0.9, 0.8, 0.3)); objTrans1.setTransform(t3d); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create the mouse scale behavior and set limits TornadoMouseScale mouseScale = new TornadoMouseScale(5, 0.1f); mouseScale.setMinScale(new Point3d(0.5, 0.5, 0.5)); mouseScale.setMaxScale(new Point3d(2, 2, 2)); mouseScale.setObject(objTrans); mouseScale.setChangeListener(this); mouseScale.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(mouseScale); // create the mouse rotate behavior TornadoMouseRotate mouseRotate = new TornadoMouseRotate(0.001, 0.001); mouseRotate.setInvert(true); mouseRotate.setObject(objTrans); mouseRotate.setChangeListener(this); mouseRotate.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(mouseRotate); // create the mouse translate behavior and set limits TornadoMouseTranslate mouseTrans = new TornadoMouseTranslate(0.005f); mouseTrans.setObject(objTrans); mouseTrans.setChangeListener(this); mouseTrans.setMinTranslate(new Point3d(-4, -4, -4)); mouseTrans.setMaxTranslate(new Point3d(4, 4, 4)); mouseTrans.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(mouseTrans); objTrans.addChild(new ColorCube(0.5)); // create some axis for the world to show it has been rotated ColorCube axis = new ColorCube(5.0); Appearance app = new Appearance(); app.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0)); axis.setAppearance(app); objTrans1.addChild(axis); objTrans1.addChild(objTrans); objRoot.addChild(objTrans1); return objRoot; }
From source file:GeomInfoApp.java
Appearance createMaterialAppearance() { Appearance materialAppear = new Appearance(); PolygonAttributes polyAttrib = new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); materialAppear.setPolygonAttributes(polyAttrib); Material material = new Material(); material.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f)); materialAppear.setMaterial(material); return materialAppear; }
From source file:BehaviorTest.java
public void addBehaviorToParentGroup(Group nodeParentGroup) { nodeParentGroup.addChild(this); m_TransformGroup = new TransformGroup(); m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); m_BoundsSwitch = new Switch(); m_BoundsSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); Appearance app = new Appearance(); PolygonAttributes polyAttrbutes = new PolygonAttributes(); polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE); app.setPolygonAttributes(polyAttrbutes); m_BoundsSwitch.addChild(new Sphere(1, app)); ColorCube cube = new ColorCube(); cube.setAppearance(app);/*from w w w .j a va 2 s.c o m*/ Group g = new Group(); g.addChild(cube); m_BoundsSwitch.addChild(g); m_BoundsSwitch.setWhichChild(Switch.CHILD_NONE); m_TransformGroup.addChild(m_BoundsSwitch); nodeParentGroup.addChild(m_TransformGroup); }
From source file:J3dSwingFrame.java
/** * Construct the default appearance./*from ww w . j a va 2s . com*/ */ private void constructAppearance() { appearance = new Appearance(); TextureAttributes tex_attr = new TextureAttributes(); tex_attr.setTextureMode(TextureAttributes.DECAL); tex_attr.setPerspectiveCorrectionMode(TextureAttributes.FASTEST); appearance.setTextureAttributes(tex_attr); ColoringAttributes col_attr = new ColoringAttributes(); col_attr.setShadeModel(ColoringAttributes.SHADE_GOURAUD); appearance.setColoringAttributes(col_attr); PolygonAttributes rend_attr = new PolygonAttributes(); rend_attr.setCullFace(PolygonAttributes.CULL_NONE); // uncomment this if you want it to display in line draw mode // rend_attr.setPolygonMode(PolygonAttributes.POLYGON_LINE); appearance.setPolygonAttributes(rend_attr); Material mat = new Material(); // Color3f col = new Color3f(1, 0, 0); // mat.setEmissiveColor(col); appearance.setMaterial(mat); setAppearance(appearance); }
From source file:KeyNavigateTest.java
void createWater(Group mapGroup, int nPixelX, int nPixelY) { Point3d point = convertToWorldCoordinatesPixelCenter(nPixelX, nPixelY); if (m_WaterAppearance == null) { m_WaterAppearance = new Appearance(); m_WaterAppearance.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false)); m_WaterAppearance/*from www.ja va 2s. c o m*/ .setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f)); m_WaterAppearance.setTextureAttributes(new TextureAttributes(TextureAttributes.REPLACE, new Transform3D(), new Color4f(0, 0, 0, 1), TextureAttributes.FASTEST)); } Land water = new Land(this, mapGroup, ComplexObject.GEOMETRY | ComplexObject.TEXTURE); water.createObject(m_WaterAppearance, new Vector3d(point.x, m_kFloorLevel + 0.1, point.z), new Vector3d(40, 1, 40), "water.gif", null, null); }