List of usage examples for javax.media.j3d Shape3D setGeometry
public void setGeometry(Geometry geometry)
From source file:Text3DApp.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); Transform3D t3D = new Transform3D(); t3D.setTranslation(new Vector3f(0.0f, 0.0f, -3.0f)); TransformGroup objMove = new TransformGroup(t3D); objRoot.addChild(objMove);//from www .j a v a 2 s . c o m // 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); objMove.addChild(objSpin); Appearance textAppear = new Appearance(); ColoringAttributes textColor = new ColoringAttributes(); textColor.setColor(1.0f, 0.0f, 0.0f); textAppear.setColoringAttributes(textColor); textAppear.setMaterial(new Material()); // Create a simple shape leaf node, add it to the scene graph. Font3D font3D = new Font3D(new Font("Helvetica", Font.PLAIN, 1), new FontExtrusion()); Text3D textGeom = new Text3D(font3D, new String("3DText")); textGeom.setAlignment(Text3D.ALIGN_CENTER); Shape3D textShape = new Shape3D(); textShape.setGeometry(textGeom); textShape.setAppearance(textAppear); objSpin.addChild(textShape); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Alpha rotationAlpha = new Alpha(-1, 10000); 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 100 BoundingSphere bounds = new BoundingSphere(); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); DirectionalLight lightD = new DirectionalLight(); lightD.setInfluencingBounds(bounds); lightD.setDirection(new Vector3f(0.0f, 0.0f, -1.0f)); lightD.setColor(new Color3f(1.0f, 0.0f, 1.0f)); objMove.addChild(lightD); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(bounds); objMove.addChild(lightA); return objRoot; }
From source file:edu.uci.ics.jung.visualization3d.PluggableRenderContext.java
public PluggableRenderContext() { super();/*w w w . j a v a 2 s. co m*/ Color3f lightGray = new Color3f(0.7f, 0.7f, 0.7f); Color3f black = new Color3f(0, 0, 0); Color3f white = new Color3f(1, 1, 1); Color3f gray = new Color3f(.2f, .2f, .2f); Color3f red = new Color3f(1, 0, 0); Color3f yellow = new Color3f(0, 1, 1); Material lightGrayMaterial = new Material(lightGray, black, lightGray, white, 100.0f); Material blackMaterial = new Material(lightGray, black, black, lightGray, 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.0f); final Appearance lightGrayLook = new Appearance(); lightGrayLook.setMaterial(lightGrayMaterial); 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); final Appearance yellowLook = new Appearance(); yellowLook.setMaterial(yellowMaterial); final Cylinder cylinder = new Cylinder(1, 1, Cylinder.GENERATE_NORMALS | Cylinder.ENABLE_GEOMETRY_PICKING, 26, 26, lightGrayLook); final Sphere sphere = new Sphere(10, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, redLook); final Box box = new Box(10, 10, 10, Box.GENERATE_NORMALS | Box.ENABLE_GEOMETRY_PICKING, redLook); this.edgeAppearanceTransformer = new ConstantTransformer(lightGrayLook); this.edgeShapeTransformer = new Transformer<Context<Graph<V, E>, E>, Node>() { public Node transform(Context<Graph<V, E>, E> ec) { LineArray lineArray = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3); lineArray.setCoordinates(0, new Point3f[] { new Point3f(0, -.5f, 0), new Point3f(0, .5f, 0) }); lineArray.setColor(0, new Color3f(1, 1, 1)); lineArray.setColor(1, new Color3f(1, 1, 1)); Shape3D shape = new Shape3D(); shape.setGeometry(lineArray); return shape; // return new Cylinder(1, 1, // Cylinder.GENERATE_NORMALS | // Cylinder.ENABLE_GEOMETRY_PICKING, // 26, 26, lightGrayLook); } }; this.vertexAppearanceTransformer = new ConstantTransformer(redLook); this.vertexShapeTransformer = new Transformer<V, Node>() { public Node transform(V arg0) { return new Sphere(10, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING | Sphere.ENABLE_APPEARANCE_MODIFY, redLook); } }; }
From source file:PickText3DBounds.java
public BranchGroup createSceneGraph(Canvas3D canvas) { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Transform3D t;//www.j a v a 2 s . c o m // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4); objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); Material m = new Material(objColor, eColor, objColor, sColor, 100.0f); Appearance a = new Appearance(); m.setLightingEnable(true); a.setMaterial(m); Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 1), new FontExtrusion()); Text3D txt = new Text3D(f3d, new String("TEXT3D"), new Point3f(-2.0f, 0.0f, 0.0f)); // txt.setCapability(Geometry.ALLOW_INTERSECT); Shape3D s3D = new Shape3D(); s3D.setGeometry(txt); s3D.setAppearance(a); // Create a transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. TransformGroup spinTg = new TransformGroup(); spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); spinTg.setCapability(TransformGroup.ENABLE_PICK_REPORTING); spinTg.addChild(s3D); objScale.addChild(spinTg); // Create the transform group node for the each light and initialize // it to the identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add them to the root // of the subgraph. // Create transformations for the positional lights t = new Transform3D(); Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0); t.set(lPos1); TransformGroup l1Trans = new TransformGroup(t); l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); l1Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objScale.addChild(l1Trans); t = new Transform3D(); Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0); t.set(lPos2); TransformGroup l2Trans = new TransformGroup(t); l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); l2Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objScale.addChild(l2Trans); // Create Geometry for point lights ColoringAttributes caL1 = new ColoringAttributes(); ColoringAttributes caL2 = new ColoringAttributes(); caL1.setColor(lColor1); caL2.setColor(lColor2); Appearance appL1 = new Appearance(); Appearance appL2 = new Appearance(); appL1.setColoringAttributes(caL1); appL2.setColoringAttributes(caL2); l1Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS, 15, appL1)); l2Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS, 15, appL2)); // Create lights AmbientLight aLgt = new AmbientLight(alColor); Light lgt1; Light lgt2; Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f); Point3f atten = new Point3f(1.0f, 0.0f, 0.0f); lgt1 = new PointLight(lColor1, lPoint, atten); lgt2 = new PointLight(lColor2, lPoint, atten); // Set the influencing bounds aLgt.setInfluencingBounds(bounds); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); // Add the lights into the scene graph objScale.addChild(aLgt); l1Trans.addChild(lgt1); l2Trans.addChild(lgt2); PickRotateBehavior behavior1 = new PickRotateBehavior(objRoot, canvas, bounds); behavior1.setMode(PickTool.BOUNDS); objRoot.addChild(behavior1); PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, canvas, bounds); behavior2.setMode(PickTool.BOUNDS); objRoot.addChild(behavior2); PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds); behavior3.setMode(PickTool.BOUNDS); objRoot.addChild(behavior3); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:PickText3DGeometry.java
public BranchGroup createSceneGraph(Canvas3D canvas) { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Transform3D t;/*from ww w. j av a 2 s . co m*/ // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4); objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); Material m = new Material(objColor, eColor, objColor, sColor, 100.0f); Appearance a = new Appearance(); m.setLightingEnable(true); a.setMaterial(m); Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 1), new FontExtrusion()); Text3D text3D = new Text3D(f3d, new String("TEXT3D"), new Point3f(-2.0f, 0.7f, 0.0f)); text3D.setCapability(Geometry.ALLOW_INTERSECT); Shape3D s3D1 = new Shape3D(); s3D1.setGeometry(text3D); s3D1.setAppearance(a); // Create a transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. TransformGroup spinTg1 = new TransformGroup(); spinTg1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); spinTg1.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); spinTg1.setCapability(TransformGroup.ENABLE_PICK_REPORTING); spinTg1.addChild(s3D1); objScale.addChild(spinTg1); Text3D pick = new Text3D(f3d, new String("Pick me"), new Point3f(-2.0f, -0.7f, 0.0f)); pick.setCapability(Geometry.ALLOW_INTERSECT); Shape3D s3D2 = new Shape3D(); s3D2.setGeometry(pick); s3D2.setAppearance(a); // Create a transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. TransformGroup spinTg2 = new TransformGroup(); spinTg2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); spinTg2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); spinTg2.setCapability(TransformGroup.ENABLE_PICK_REPORTING); spinTg2.addChild(s3D2); objScale.addChild(spinTg2); // Create the transform group node for the each light and initialize // it to the identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add them to the root // of the subgraph. // Create transformations for the positional lights t = new Transform3D(); Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0); t.set(lPos1); TransformGroup l1Trans = new TransformGroup(t); l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); l1Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objScale.addChild(l1Trans); t = new Transform3D(); Vector3d lPos2 = new Vector3d(0.5, 1.2, 2.0); t.set(lPos2); TransformGroup l2Trans = new TransformGroup(t); l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); l2Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objScale.addChild(l2Trans); // Create Geometry for point lights ColoringAttributes caL1 = new ColoringAttributes(); ColoringAttributes caL2 = new ColoringAttributes(); caL1.setColor(lColor1); caL2.setColor(lColor2); Appearance appL1 = new Appearance(); Appearance appL2 = new Appearance(); appL1.setColoringAttributes(caL1); appL2.setColoringAttributes(caL2); l1Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, 15, appL1)); l2Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, 15, appL2)); // Create lights AmbientLight aLgt = new AmbientLight(alColor); Light lgt1; Light lgt2; Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f); Point3f atten = new Point3f(1.0f, 0.0f, 0.0f); lgt1 = new PointLight(lColor1, lPoint, atten); lgt2 = new PointLight(lColor2, lPoint, atten); // Set the influencing bounds aLgt.setInfluencingBounds(bounds); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); // Add the lights into the scene graph objScale.addChild(aLgt); l1Trans.addChild(lgt1); l2Trans.addChild(lgt2); PickRotateBehavior behavior1 = new PickRotateBehavior(objRoot, canvas, bounds); behavior1.setMode(PickTool.GEOMETRY); behavior1.setTolerance(0.0f); objRoot.addChild(behavior1); PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, canvas, bounds); behavior2.setMode(PickTool.GEOMETRY); behavior2.setTolerance(0.0f); objRoot.addChild(behavior2); PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds); behavior3.setMode(PickTool.GEOMETRY); behavior3.setTolerance(0.0f); objRoot.addChild(behavior3); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:Text3DLoad.java
public BranchGroup createSceneGraph() { float sl = textString.length(); // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); // Assuming uniform size chars, set scale to fit string in view t3d.setScale(1.2 / sl);/*from www. j av a 2 s.c om*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(objTrans); Font3D f3d; if (tessellation > 0.0) { f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), tessellation, new FontExtrusion()); } else { f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion()); } Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, -1.f, -1.f)); Shape3D sh = new Shape3D(); Appearance app = new Appearance(); Material mm = new Material(); mm.setLightingEnable(true); app.setMaterial(mm); sh.setGeometry(txt); sh.setAppearance(app); objTrans.addChild(sh); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); if (false) { Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); } // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); objRoot.addChild(bgNode); // Set up the ambient light Color3f ambientColor = new Color3f(0.3f, 0.3f, 0.3f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objRoot.addChild(light2); return objRoot; }
From source file:LightScopeApp.java
Shape3D createXZPlane(Point3f p0, Point3f p1, Point3f p2, Point3f p3) { Shape3D plane = new Shape3D(); QuadArray planeGeom = new QuadArray(4, QuadArray.COORDINATES | QuadArray.NORMALS); planeGeom.setCoordinate(0, p0);//from www.j a v a 2 s.c o m planeGeom.setCoordinate(1, p1); planeGeom.setCoordinate(2, p2); planeGeom.setCoordinate(3, p3); Vector3f norm = new Vector3f(0.0f, 1.0f, 0.0f); planeGeom.setNormal(0, norm); planeGeom.setNormal(1, norm); planeGeom.setNormal(2, norm); planeGeom.setNormal(3, norm); plane.setGeometry(planeGeom); return plane; }
From source file:GeomInfoApp.java
public BranchGroup createSceneGraph(boolean wireFrame) { int total = 0; System.out.println("\n --- geometry debug information --- \n"); float[] coordinateData = null; coordinateData = createCoordinateData(); int[] stripCount = { 17, 17, 5, 5, 5, 5, 5, 5, 5 }; // ****** // int[] stripCount = {17,17,17}; // ****** for (int i = 0; i < stripCount.length; i++) { System.out.println("stripCount[" + i + "] = " + stripCount[i]); total += stripCount[i];/*from w ww .j a v a 2 s . co m*/ } if (total != coordinateData.length / 3) { System.out.println(" coordinateData vertex count: " + coordinateData.length / 3); System.out.println("stripCount total vertex count: " + total); } GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); gi.setCoordinates(coordinateData); gi.setStripCounts(stripCount); Triangulator tr = new Triangulator(); // Triangulator tr = new Triangulator(1); System.out.println("begin triangulation"); tr.triangulate(gi); System.out.println(" END triangulation"); gi.recomputeIndices(); NormalGenerator ng = new NormalGenerator(); ng.generateNormals(gi); gi.recomputeIndices(); Stripifier st = new Stripifier(); st.stripify(gi); gi.recomputeIndices(); Shape3D part = new Shape3D(); if (wireFrame == true) part.setAppearance(createWireFrameAppearance()); else part.setAppearance(createMaterialAppearance()); part.setGeometry(gi.getGeometryArray()); ///////////////////////////// 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); objSpin.addChild(part); //////////////////////// LineStripArray lineArray = new LineStripArray(69, LineArray.COORDINATES, stripCount); //***** // LineStripArray lineArray = new LineStripArray(51, // LineArray.COORDINATES, stripCount); //***** lineArray.setCoordinates(0, coordinateData); Appearance blueColorAppearance = new Appearance(); ColoringAttributes blueColoring = new ColoringAttributes(); blueColoring.setColor(0.0f, 0.0f, 1.0f); blueColorAppearance.setColoringAttributes(blueColoring); LineAttributes lineAttrib = new LineAttributes(); lineAttrib.setLineWidth(2.0f); blueColorAppearance.setLineAttributes(lineAttrib); objSpin.addChild(new Shape3D(lineArray, blueColorAppearance)); 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); DirectionalLight lightD = new DirectionalLight(); lightD.setDirection(new Vector3f(0.0f, -0.7f, -0.7f)); lightD.setInfluencingBounds(bounds); contentRoot.addChild(lightD); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(bounds); contentRoot.addChild(lightA); Background background = new Background(); background.setColor(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:IntersectTest.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode);// w w w .jav a2 s .c o m // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f); Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objRoot.addChild(light2); Transform3D t3 = new Transform3D(); // Shapes for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { t3.setTranslation(new Vector3d(-4 + x * 4.0, -4 + y * 4.0, -20 - z * 4.0)); TransformGroup objTrans = new TransformGroup(t3); objRoot.addChild(objTrans); // Create a simple shape leaf node, add it to the scene // graph. GeometryArray geom = null; if (((x + y + z) % 2) == 0) { geom = new RandomColorCube(); } else { geom = new RandomColorTetrahedron(); } Shape3D shape = new Shape3D(geom); // use the utility method to set the capabilities PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL); objTrans.addChild(shape); } } } // Lines Point3f[] verts = { new Point3f(-2.0f, 0.0f, 0.0f), new Point3f(2.0f, 0.0f, 0.0f) }; Color3f grey = new Color3f(0.7f, 0.7f, 0.7f); Color3f[] colors = { grey, grey }; for (int y = 0; y < 5; y++) { for (int z = 0; z < 5; z++) { t3.setTranslation(new Vector3d(7.0, -4 + y * 2.0, -20.0 - z * 2.0)); TransformGroup objTrans = new TransformGroup(t3); objRoot.addChild(objTrans); LineArray la = new LineArray(verts.length, LineArray.COORDINATES | LineArray.COLOR_3); la.setCoordinates(0, verts); la.setColors(0, colors); Shape3D shape = new Shape3D(); shape.setGeometry(la); // use the utility method to set the capabilities PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL); objTrans.addChild(shape); } } // Points for (double x = -2.0; x <= 2.0; x += 1.0) { for (double y = -2.0; y <= 2.0; y += 1.0) { for (double z = -2.0; z <= 2.0; z += 1.0) { t3.setTranslation(new Vector3d(-10.0 + 2.0 * x, 0.0 + 2.0 * y, -20.0 + 2.0 * z)); TransformGroup objTrans = new TransformGroup(t3); objRoot.addChild(objTrans); PointArray pa = new PointArray(1, PointArray.COORDINATES | PointArray.COLOR_3); pa.setCoordinate(0, new Point3d(0.0, 0.0, 0.0)); pa.setColor(0, grey); Shape3D shape = new Shape3D(); shape.setGeometry(pa); // use the utility method to set the capabilities PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL); objTrans.addChild(shape); } } } return objRoot; }
From source file:LightScopeApp.java
Shape3D createLampShape() { Shape3D lamp = new Shape3D(); int stripCounts[] = { 10, 10 }; TriangleStripArray lampGeom = new TriangleStripArray(20, GeometryArray.COORDINATES | GeometryArray.NORMALS, stripCounts);/* w w w. j a va2s. c om*/ lampGeom.setCoordinate(0, new Point3f(-0.01f, 0.9f, 0.01f)); lampGeom.setCoordinate(1, new Point3f(-0.01f, 0.0f, 0.01f)); lampGeom.setCoordinate(2, new Point3f(0.01f, 0.9f, 0.01f)); lampGeom.setCoordinate(3, new Point3f(0.01f, 0.0f, 0.01f)); lampGeom.setCoordinate(4, new Point3f(0.01f, 0.9f, -0.01f)); lampGeom.setCoordinate(5, new Point3f(0.01f, 0.0f, -0.01f)); lampGeom.setCoordinate(6, new Point3f(-0.01f, 0.9f, -0.01f)); lampGeom.setCoordinate(7, new Point3f(-0.01f, 0.0f, -0.01f)); lampGeom.setCoordinate(8, new Point3f(-0.01f, 0.9f, 0.01f)); lampGeom.setCoordinate(9, new Point3f(-0.01f, 0.0f, 0.01f)); lampGeom.setCoordinate(10, new Point3f(-0.1f, 0.9f, 0.1f)); lampGeom.setCoordinate(11, new Point3f(-0.2f, 0.5f, 0.2f)); lampGeom.setCoordinate(12, new Point3f(0.1f, 0.9f, 0.1f)); lampGeom.setCoordinate(13, new Point3f(0.2f, 0.5f, 0.2f)); lampGeom.setCoordinate(14, new Point3f(0.1f, 0.9f, -0.1f)); lampGeom.setCoordinate(15, new Point3f(0.2f, 0.5f, -0.2f)); lampGeom.setCoordinate(16, new Point3f(-0.1f, 0.9f, -0.1f)); lampGeom.setCoordinate(17, new Point3f(-0.2f, 0.5f, -0.2f)); lampGeom.setCoordinate(18, new Point3f(-0.1f, 0.9f, 0.1f)); lampGeom.setCoordinate(19, new Point3f(-0.2f, 0.5f, 0.2f)); Vector3f norm = new Vector3f(-0.7f, 0.0f, 0.7f); lampGeom.setNormal(0, norm); lampGeom.setNormal(1, norm); norm.set(0.7f, 0.0f, 0.7f); lampGeom.setNormal(2, norm); lampGeom.setNormal(3, norm); norm.set(0.7f, 0.0f, -0.7f); lampGeom.setNormal(4, norm); lampGeom.setNormal(5, norm); norm.set(-0.7f, 0.0f, -0.7f); lampGeom.setNormal(6, norm); lampGeom.setNormal(7, norm); norm.set(-0.7f, 0.0f, 0.7f); lampGeom.setNormal(8, norm); lampGeom.setNormal(9, norm); norm.set(-0.7f, 0.0f, 0.7f); lampGeom.setNormal(10, norm); lampGeom.setNormal(11, norm); norm.set(0.7f, 0.0f, 0.7f); lampGeom.setNormal(12, norm); lampGeom.setNormal(13, norm); norm.set(0.7f, 0.0f, -0.7f); lampGeom.setNormal(14, norm); lampGeom.setNormal(15, norm); norm.set(-0.7f, 0.0f, -0.7f); lampGeom.setNormal(16, norm); lampGeom.setNormal(17, norm); norm.set(-0.7f, 0.0f, 0.7f); lampGeom.setNormal(18, norm); lampGeom.setNormal(19, norm); lamp.setGeometry(lampGeom); return lamp; }
From source file:AppearanceTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup zoomTg = new TransformGroup(); zoomTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); zoomTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // attach a navigation behavior to the position of the viewer KeyNavigatorBehavior key = new KeyNavigatorBehavior(zoomTg); key.setSchedulingBounds(createApplicationBounds()); key.setEnable(true);/*from w w w . ja v a 2s.co m*/ objRoot.addChild(key); // create a TransformGroup to flip the hand onto its end and enlarge it. TransformGroup objTrans1 = new TransformGroup(); Transform3D tr = new Transform3D(); objTrans1.getTransform(tr); tr.setEuler(new Vector3d(0.5 * Math.PI, 0.6, 0)); objTrans1.setTransform(tr); // Set up the global lights Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(getApplicationBounds()); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(getApplicationBounds()); objRoot.addChild(aLgt); objRoot.addChild(lgt1); int nScale = 50; Box box = new Box(nScale, nScale, nScale, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, m_Appearance); Shape3D frontFace = box.getShape(Box.LEFT); // create a new left face so we can // assign per-vertex colors GeometryArray geometry = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.COLOR_4 | GeometryArray.TEXTURE_COORDINATE_2); nScale = 40; final float[] verts = { // left face -1.0f * nScale, -1.0f * nScale, 1.0f * nScale, -1.0f * nScale, 1.0f * nScale, 1.0f * nScale, -1.0f * nScale, 1.0f * nScale, -1.0f * nScale, -1.0f * nScale, -1.0f * nScale, -1.0f * nScale }; final float[] colors = { // left face 1, 0, 0, 0, 0, 1, 0, 0.2f, 0, 0, 1, 0.8f, 0, 0, 0, 1, }; float[] tcoords = { // left 1, 0, 1, 1, 0, 1, 0, 0 }; Vector3f normalVector = new Vector3f(-1.0f, 0.0f, 0.0f); geometry.setColors(0, colors, 0, 4); for (int n = 0; n < 4; n++) geometry.setNormal(n, normalVector); geometry.setTextureCoordinates(0, tcoords, 0, 4); geometry.setCoordinates(0, verts); frontFace.setGeometry(geometry); // connect the scenegraph objTrans1.addChild(box); zoomTg.addChild(objTrans1); objRoot.addChild(zoomTg); return objRoot; }