List of usage examples for javax.media.j3d Material Material
public Material(Color3f ambientColor, Color3f emissiveColor, Color3f diffuseColor, Color3f specularColor, float shininess)
From source file:SwingTest.java
/** * Create a BranchGroup that contains a Sphere. The user data for the * BranchGroup is set so the BranchGroup can be identified. *///from w ww . ja v a2 s . co m protected BranchGroup createSphere() { BranchGroup bg = new BranchGroup(); bg.setCapability(BranchGroup.ALLOW_DETACH); Appearance app = new Appearance(); Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); bg.addChild(new com.sun.j3d.utils.geometry.Sphere(1, app)); bg.setUserData("Sphere"); return bg; }
From source file:SplineAnim.java
public BranchGroup createSceneGraph() { // Colors for lights and objects Color3f aColor = new Color3f(0.2f, 0.2f, 0.2f); Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f coneColor = new Color3f(0.9f, 0.1f, 0.1f); Color3f sphereColor = new Color3f(0.1f, 0.7f, 0.9f); Color3f bgColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f lightColor = new Color3f(1.0f, 1.0f, 1.0f); // Root of the branch grsph BranchGroup root = new BranchGroup(); // Create transforms such that all objects appears in the scene sceneTransform = new Transform3D(); sceneTransform.setScale(0.14f);/*from w w w. j av a 2 s .c om*/ Transform3D yrot = new Transform3D(); yrot.rotY(-Math.PI / 5.0d); sceneTransform.mul(yrot); sceneTransformGroup = new TransformGroup(sceneTransform); sceneTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); sceneTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); root.addChild(sceneTransformGroup); // Create bounds for the background and lights bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0f); // Set up the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); sceneTransformGroup.addChild(bg); // Create the transform group node for the lights lightTransform1 = new Transform3D(); lightTransform2 = new Transform3D(); Vector3d lightPos1 = new Vector3d(0.0, 0.0, 2.0); Vector3d lightPos2 = new Vector3d(1.0, 0.0, -2.0); lightTransform1.set(lightPos1); lightTransform2.set(lightPos2); light1TransformGroup = new TransformGroup(lightTransform1); light2TransformGroup = new TransformGroup(lightTransform2); sceneTransformGroup.addChild(light1TransformGroup); sceneTransformGroup.addChild(light2TransformGroup); // Create lights AmbientLight ambLight = new AmbientLight(aColor); Light dirLight1; Light dirLight2; Vector3f lightDir1 = new Vector3f(lightPos1); Vector3f lightDir2 = new Vector3f(lightPos2); lightDir1.negate(); lightDir2.negate(); dirLight1 = new DirectionalLight(lightColor, lightDir1); dirLight2 = new DirectionalLight(lightColor, lightDir2); // Set the influencing bounds ambLight.setInfluencingBounds(bounds); dirLight1.setInfluencingBounds(bounds); dirLight2.setInfluencingBounds(bounds); // Add the lights into the scene graph sceneTransformGroup.addChild(ambLight); sceneTransformGroup.addChild(dirLight1); sceneTransformGroup.addChild(dirLight2); // Create a cone and add it to the scene graph. objTransform = new Transform3D(); objTransformGroup = new TransformGroup(objTransform); objTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); sceneTransformGroup.addChild(objTransformGroup); Material m = new Material(coneColor, eColor, coneColor, sColor, 100.0f); Appearance a = new Appearance(); m.setLightingEnable(true); a.setMaterial(m); Cone cone = new Cone(0.4f, 1.0f); cone.setAppearance(a); objTransformGroup.addChild(cone); // Create transform groups for each knot point // knot point 0 Transform3D t3dKnot = new Transform3D(); t3dKnot.set(pos0); TransformGroup k0TransformGroup = new TransformGroup(t3dKnot); sceneTransformGroup.addChild(k0TransformGroup); // knot point 1 t3dKnot = new Transform3D(); t3dKnot.set(pos1); TransformGroup k1TransformGroup = new TransformGroup(t3dKnot); sceneTransformGroup.addChild(k1TransformGroup); // knot point 2 t3dKnot = new Transform3D(); t3dKnot.set(pos2); TransformGroup k2TransformGroup = new TransformGroup(t3dKnot); sceneTransformGroup.addChild(k2TransformGroup); // knot point 3 t3dKnot = new Transform3D(); t3dKnot.set(pos3); TransformGroup k3TransformGroup = new TransformGroup(t3dKnot); sceneTransformGroup.addChild(k3TransformGroup); // knot point 4 t3dKnot = new Transform3D(); t3dKnot.set(pos4); TransformGroup k4TransformGroup = new TransformGroup(t3dKnot); sceneTransformGroup.addChild(k4TransformGroup); // knot point 5 t3dKnot = new Transform3D(); t3dKnot.set(pos5); TransformGroup k5TransformGroup = new TransformGroup(t3dKnot); sceneTransformGroup.addChild(k5TransformGroup); // Create spheres for each knot point's transform group ColoringAttributes sphereColorAttr = new ColoringAttributes(); sphereColorAttr.setColor(sphereColor); Appearance sphereAppearance = new Appearance(); sphereAppearance.setColoringAttributes(sphereColorAttr); k0TransformGroup.addChild(new Sphere(0.10f, sphereAppearance)); k1TransformGroup.addChild(new Sphere(0.10f, sphereAppearance)); k2TransformGroup.addChild(new Sphere(0.10f, sphereAppearance)); k3TransformGroup.addChild(new Sphere(0.10f, sphereAppearance)); k4TransformGroup.addChild(new Sphere(0.10f, sphereAppearance)); k5TransformGroup.addChild(new Sphere(0.10f, sphereAppearance)); return root; }
From source file:PlatformTest.java
ViewerAvatar createViewerAvatar(String szText, Color3f objColor) { ViewerAvatar viewerAvatar = new ViewerAvatar(); // rotate the Cone so that it is lying down and // points sharp-end towards the Viewer's field of view. TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setEuler(new Vector3d(Math.PI / 2.0, Math.PI, 0)); tg.setTransform(t3d);/*from w w w . ja va 2s. c o m*/ // create appearance and material for the Cone Appearance app = new Appearance(); Color3f black = new Color3f(0.4f, 0.2f, 0.1f); app.setMaterial(new Material(objColor, black, objColor, black, 90.0f)); // create the Primitive and add to the parent BranchGroup tg.addChild(new Cone(1, 3, Primitive.GENERATE_NORMALS, app)); viewerAvatar.addChild(tg); return viewerAvatar; }
From source file:EnvironmentExplorer.java
void setupSpheres() { // create a Switch for the spheres, allow switch changes spheresSwitch = new Switch(Switch.CHILD_ALL); spheresSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); // Set up an appearance to make the Sphere with objColor ambient, // black emmissive, objColor diffuse and white specular coloring Material material = new Material(objColor, black, objColor, white, 32); Appearance appearance = new Appearance(); appearance.setMaterial(material);// w ww .j ava2s.c om // create a sphere and put it into a shared group Sphere sphere = new Sphere(0.5f, appearance); SharedGroup sphereSG = new SharedGroup(); sphereSG.addChild(sphere); // create a grid of spheres in the z=0 plane // each has a TransformGroup to position the sphere which contains // a link to the shared group for the sphere for (int y = -2; y <= 2; y++) { for (int x = -2; x <= 2; x++) { TransformGroup tg = new TransformGroup(); tmpVector.set(x * 1.2f, y * 1.2f, -0.1f); tmpTrans.set(tmpVector); tg.setTransform(tmpTrans); tg.addChild(new Link(sphereSG)); spheresSwitch.addChild(tg); } } }
From source file:AppearanceExplorer.java
void setupAppearance() { appearance = new Appearance(); // ColoringAttributes coloringColor = new Color3f(red); coloringAttr = new ColoringAttributes(coloringColor, coloringShadeModel); coloringAttr.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE); coloringAttr.setCapability(ColoringAttributes.ALLOW_SHADE_MODEL_WRITE); appearance.setColoringAttributes(coloringAttr); // set up the editor coloringAttrEditor = new ColoringAttributesEditor(coloringAttr); // PointAttributes pointAttr = new PointAttributes(pointSize, pointAAEnable); pointAttr.setCapability(PointAttributes.ALLOW_SIZE_WRITE); pointAttr.setCapability(PointAttributes.ALLOW_ANTIALIASING_WRITE); appearance.setPointAttributes(pointAttr); // set up the editor pointAttrEditor = new PointAttributesEditor(pointAttr); // LineAttributes lineAttr = new LineAttributes(lineWidth, linePattern, lineAAEnable); lineAttr.setCapability(LineAttributes.ALLOW_WIDTH_WRITE); lineAttr.setCapability(LineAttributes.ALLOW_PATTERN_WRITE); lineAttr.setCapability(LineAttributes.ALLOW_ANTIALIASING_WRITE); appearance.setLineAttributes(lineAttr); // set up the editor lineAttrEditor = new LineAttributesEditor(lineAttr); // PolygonAttributes polygonAttr = new PolygonAttributes(polygonMode, polygonCull, 0.0f); polygonAttr.setPolygonOffset(polygonOffsetBias); polygonAttr.setPolygonOffsetFactor(polygonOffsetFactor); polygonAttr.setCapability(PolygonAttributes.ALLOW_MODE_WRITE); polygonAttr.setCapability(PolygonAttributes.ALLOW_CULL_FACE_WRITE); polygonAttr.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE); appearance.setPolygonAttributes(polygonAttr); // set up the editor polygonAttrEditor = new PolygonAttributesEditor(polygonAttr); // Rendering attributes renderAttr = new RenderingAttributes(renderDepthBuffer, renderDepthBufferWrite, 0.0f, RenderingAttributes.ALWAYS, renderVisible, renderIgnoreVertexColor, renderRasterOpEnable, renderRasterOp);/* ww w.ja va2s .co m*/ renderAttr.setCapability(RenderingAttributes.ALLOW_IGNORE_VERTEX_COLORS_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_RASTER_OP_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_FUNCTION_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_VALUE_WRITE); appearance.setRenderingAttributes(renderAttr); appearance.setCapability(Appearance.ALLOW_RENDERING_ATTRIBUTES_WRITE); // set up the editor renderAttrEditor = new RenderingAttributesEditor(renderAttr); // TransparencyAttributes transpAttr = new TransparencyAttributes(transpMode, transpValue); transpAttr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); transpAttr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE); transpAttr.setCapability(TransparencyAttributes.ALLOW_BLEND_FUNCTION_WRITE); appearance.setTransparencyAttributes(transpAttr); // set up the editor transpAttrEditor = new TransparencyAttributesEditor(transpAttr); // Material material = new Material(red, black, red, white, 20.f); material.setLightingEnable(false); material.setCapability(Material.ALLOW_COMPONENT_WRITE); appearance.setMaterial(material); // material presets String[] materialNames = { "Red", "White", "Red Ambient", "Red Diffuse", "Grey Emissive", "White Specular", "Aluminium", "Blue Plastic", "Copper", "Gold", "Red Alloy", "Black Onyx" }; Material[] materialPresets = new Material[materialNames.length]; materialPresets[0] = new Material(red, black, red, white, 20.0f); materialPresets[1] = new Material(white, black, white, white, 20.0f); materialPresets[2] = new Material(red, black, black, black, 20.0f); materialPresets[3] = new Material(black, black, red, black, 20.0f); materialPresets[4] = new Material(black, grey, black, black, 20.0f); materialPresets[5] = new Material(black, black, black, white, 20.0f); Color3f alum = new Color3f(0.37f, 0.37f, 0.37f); Color3f alumSpec = new Color3f(0.89f, 0.89f, 0.89f); materialPresets[6] = new Material(alum, black, alum, alumSpec, 17); Color3f bluePlastic = new Color3f(0.20f, 0.20f, 0.70f); Color3f bluePlasticSpec = new Color3f(0.85f, 0.85f, 0.85f); materialPresets[7] = new Material(bluePlastic, black, bluePlastic, bluePlasticSpec, 22); Color3f copper = new Color3f(0.30f, 0.10f, 0.00f); ; Color3f copperSpec = new Color3f(0.75f, 0.30f, 0.00f); materialPresets[8] = new Material(copper, black, copper, copperSpec, 10); Color3f gold = new Color3f(0.49f, 0.34f, 0.00f); Color3f goldSpec = new Color3f(0.89f, 0.79f, 0.00f); materialPresets[9] = new Material(gold, black, gold, goldSpec, 15); Color3f redAlloy = new Color3f(0.34f, 0.00f, 0.34f); Color3f redAlloySpec = new Color3f(0.84f, 0.00f, 0.00f); materialPresets[10] = new Material(redAlloy, black, redAlloy, redAlloySpec, 15); Color3f blackOnyxSpec = new Color3f(0.72f, 0.72f, 0.72f); materialPresets[11] = new Material(black, black, black, blackOnyxSpec, 23); // set up the editor materialEditor = new MaterialPresetEditor(material, materialNames, materialPresets); // Texture2D // set the values to the defaults texEnable = false; texMipMapMode = Texture.BASE_LEVEL; texBoundaryModeS = Texture.WRAP; texBoundaryModeT = Texture.WRAP; texMinFilter = Texture.BASE_LEVEL_POINT; texMagFilter = Texture.BASE_LEVEL_POINT; texBoundaryColor = new Color4f(0.0f, 0.0f, 0.0f, 0.0f); // set up the image choices String[] texImageNames = { "Earth", "Fish", }; String[] texImageFileNames = { "earth.jpg", "fish1.gif", }; int texImageFileIndex = 0; // set up the appearance to allow the texture to be changed appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE); // set up the editor (this will create the initial Texture2D and // assign it to the appearance) texture2DEditor = new Texture2DEditor(appearance, codeBaseString, texImageNames, texImageFileNames, texImageFileIndex, texEnable, texBoundaryModeS, texBoundaryModeT, texMinFilter, texMagFilter, texMipMapMode, texBoundaryColor); // TextureAttributes texMode = TextureAttributes.REPLACE; texBlendColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f); texTransform = new Transform3D(); texPerspCorrect = TextureAttributes.NICEST; textureAttr = new TextureAttributes(texMode, texTransform, texBlendColor, texPerspCorrect); // set the capabilities to allow run time changes textureAttr.setCapability(TextureAttributes.ALLOW_MODE_WRITE); textureAttr.setCapability(TextureAttributes.ALLOW_BLEND_COLOR_WRITE); textureAttr.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE); // connect it to the appearance appearance.setTextureAttributes(textureAttr); // setup the editor textureAttrEditor = new TextureAttributesEditor(textureAttr); // set up the tex coordinate generation texGenEnable = false; texGenMode = TexCoordGeneration.OBJECT_LINEAR; texGenPlaneS = new Vector4f(1.0f, 0.0f, 0.0f, 0.0f); texGenPlaneT = new Vector4f(0.0f, 1.0f, 0.0f, 0.0f); // set the appearance so that we can replace the tex gen when live appearance.setCapability(Appearance.ALLOW_TEXGEN_WRITE); // setup the editor texGenEditor = new TexCoordGenerationEditor(appearance, texGenEnable, texGenMode, texGenPlaneS, texGenPlaneT); }
From source file:IntersectTest.java
public IntersectInfoBehavior(Canvas3D canvas3D, BranchGroup branchGroup, float size) { pickCanvas = new PickCanvas(canvas3D, branchGroup); pickCanvas.setTolerance(5.0f);/*from ww w .ja v a 2 s. com*/ 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:EnvironmentExplorer.java
void setupGrid() { // create a Switch for the spheres, allow switch changes gridSwitch = new Switch(Switch.CHILD_NONE); gridSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); // Set up an appearance to make the square3s with red ambient, // black emmissive, red diffuse and black specular coloring Material material = new Material(red, black, red, black, 64); Appearance appearance = new Appearance(); appearance.setMaterial(material);//from www . j a v a 2 s . co m // create a grid of quads int gridSize = 20; // grid is gridSize quads along each side int numQuads = gridSize * gridSize; int numVerts = numQuads * 4; // 4 verts per quad // there will be 3 floats per coord and 4 coords per quad float[] coords = new float[3 * numVerts]; // All the quads will use the same normal at each vertex, so // allocate an array to hold references to the same normal Vector3f[] normals = new Vector3f[numVerts]; Vector3f vertNormal = new Vector3f(0.0f, 0.0f, 1.0f); float edgeLength = 5.0f; // length of each edge of the grid float gridGap = 0.03f; // the gap between each quad // length of each quad is (total length - sum of the gaps) / gridSize float quadLength = (edgeLength - gridGap * (gridSize - 1)) / gridSize; // create a grid of quads in the z=0 plane // each has a TransformGroup to position the sphere which contains // a link to the shared group for the sphere float curX, curY; for (int y = 0; y < gridSize; y++) { curY = y * (quadLength + gridGap); // offset to lower left corner curY -= edgeLength / 2; // center on 0,0 for (int x = 0; x < gridSize; x++) { // this is the offset into the vertex array for the first // vertex of the quad int vertexOffset = (y * gridSize + x) * 4; // this is the offset into the coord array for the first // vertex of the quad, where there are 3 floats per vertex int coordOffset = vertexOffset * 3; curX = x * (quadLength + gridGap); // offset to ll corner curX -= edgeLength / 2; // center on 0,0 // lower left corner coords[coordOffset + 0] = curX; coords[coordOffset + 1] = curY; coords[coordOffset + 2] = 0.0f; // z // lower right corner coords[coordOffset + 3] = curX + quadLength; coords[coordOffset + 4] = curY; coords[coordOffset + 5] = 0.0f; // z // upper right corner coords[coordOffset + 6] = curX + quadLength; coords[coordOffset + 7] = curY + quadLength; coords[coordOffset + 8] = 0.0f; // z // upper left corner coords[coordOffset + 9] = curX; coords[coordOffset + 10] = curY + quadLength; coords[coordOffset + 11] = 0.0f; // z for (int i = 0; i < 4; i++) { normals[vertexOffset + i] = vertNormal; } } } // now that we have the data, create the QuadArray QuadArray quads = new QuadArray(numVerts, QuadArray.COORDINATES | QuadArray.NORMALS); quads.setCoordinates(0, coords); quads.setNormals(0, normals); // create the shape Shape3D shape = new Shape3D(quads, appearance); // add it to the switch gridSwitch.addChild(shape); }
From source file:TextureByReference.java
public BranchGroup createSceneGraph() { // create the root of the branch group BranchGroup objRoot = new BranchGroup(); // create the transform group node and initialize it // enable the TRANSFORM_WRITE capability so that it can be modified // at runtime. Add it to the root of the subgraph Transform3D rotate = new Transform3D(); TransformGroup objTrans = new TransformGroup(rotate); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans);// ww w . j av a2s .c om // bounds BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // set up some light Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -0.5f, -1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objRoot.addChild(aLgt); objRoot.addChild(lgt1); Appearance appearance = new Appearance(); // enable the TEXTURE_WRITE so we can modify it at runtime appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE); // load the first texture TextureLoader loader = new TextureLoader(urls[0], TextureLoader.BY_REFERENCE | TextureLoader.Y_UP, this); // get the texture from the loader Texture2D tex = (Texture2D) loader.getTexture(); // get the BufferedImage to convert to TYPE_4BYTE_ABGR and flip // get the ImageComponent because we need it anyway ImageComponent2D imageComp = (ImageComponent2D) tex.getImage(0); BufferedImage bImage = imageComp.getImage(); // convert the image bImage = ImageOps.convertImage(bImage, BufferedImage.TYPE_4BYTE_ABGR); // flip the image ImageOps.flipImage(bImage); imageComp.set(bImage); tex.setCapability(Texture.ALLOW_IMAGE_WRITE); tex.setBoundaryModeS(Texture.CLAMP); tex.setBoundaryModeT(Texture.CLAMP); tex.setBoundaryColor(1.0f, 1.0f, 1.0f, 1.0f); // set the image of the texture tex.setImage(0, imageComp); // set the texture on the appearance appearance.setTexture(tex); // set texture attributes TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); appearance.setTextureAttributes(texAttr); // set material properties Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); appearance.setMaterial(new Material(white, black, white, black, 1.0f)); // create a scale transform Transform3D scale = new Transform3D(); scale.set(.6); TransformGroup objScale = new TransformGroup(scale); objTrans.addChild(objScale); tetra = new Tetrahedron(true); tetra.setAppearance(appearance); objScale.addChild(tetra); // create the behavior animate = new AnimateTexturesBehavior(tex, urls, appearance, this); animate.setSchedulingBounds(bounds); objTrans.addChild(animate); // add a rotation behavior so we can see all sides of the tetrahedron Transform3D yAxis = new Transform3D(); Alpha rotorAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotorAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); // have java3d perform optimizations on this scene graph objRoot.compile(); return objRoot; }
From source file:TickTockPicking.java
public PickHighlightBehavior(Canvas3D canvas, BranchGroup root, Bounds bounds) { super(canvas, root, bounds); this.setSchedulingBounds(bounds); root.addChild(this); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f highlightColor = new Color3f(0.0f, 1.0f, 0.0f); Material highlightMaterial = new Material(highlightColor, black, highlightColor, white, 80.0f); highlightAppearance = new Appearance(); highlightAppearance.setMaterial(new Material(highlightColor, black, highlightColor, white, 80.0f)); pickCanvas.setMode(PickTool.BOUNDS); }
From source file:LightTest.java
public void synchLightToUi() { super.synchLightToUi(); // set some defaults if things go wrong... double x = 0; double y = 0; double z = 0; double constant = 0.01; double linear = 0; double quadratic = 0; try {//from w w w. ja v a 2 s . c o m x = Double.valueOf(m_XPositionTextField.getText()).doubleValue(); y = Double.valueOf(m_YPositionTextField.getText()).doubleValue(); z = Double.valueOf(m_ZPositionTextField.getText()).doubleValue(); constant = Double.valueOf(m_ConstantAttenuationTextField.getText()).doubleValue(); linear = Double.valueOf(m_LinearAttenuationTextField.getText()).doubleValue(); quadratic = Double.valueOf(m_QuadraticAttenuationTextField.getText()).doubleValue(); } catch (java.lang.NumberFormatException e) { // invalid numeric input - just ignore. } ((PointLight) m_Light).setPosition((float) x, (float) y, (float) z); ((PointLight) m_Light).setAttenuation((float) constant, (float) linear, (float) quadratic); if (m_TransformGroup != null) { Transform3D t3d = new Transform3D(); m_TransformGroup.getTransform(t3d); t3d.setTranslation(new Vector3d(x, y, z)); m_TransformGroup.setTransform(t3d); } if (m_Sphere != null) { Appearance app = new Appearance(); Color3f objColor = new Color3f(); m_Light.getColor(objColor); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); m_Sphere.getShape(Sphere.BODY).setAppearance(app); } }