List of usage examples for javax.media.j3d Shape3D Shape3D
public Shape3D()
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);/*ww w .j a va 2s.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: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 ww w .j a va 2 s . com // 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: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;/*w w w.j ava2s.c om*/ // 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:edu.uci.ics.jung.visualization3d.PluggableRenderContext.java
public PluggableRenderContext() { super();//from w w w . j a v a 2s.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:LightScopeApp.java
Shape3D createLampShape() { Shape3D lamp = new Shape3D(); int stripCounts[] = { 10, 10 }; TriangleStripArray lampGeom = new TriangleStripArray(20, GeometryArray.COORDINATES | GeometryArray.NORMALS, stripCounts);/*from ww w.j a v a2 s. com*/ 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: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 w w w. j a v a 2s . 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: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;// w ww. ja v 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: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 w w . ja v a 2s . c o 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:ExBackgroundImage.java
public Arch(double startPhi, double endPhi, int nPhi, double startTheta, double endTheta, int nTheta, double startPhiRadius, double endPhiRadius, double startPhiThickness, double endPhiThickness, Appearance app) {// ww w . j av a 2 s. c o m double theta, phi, radius, radius2, thickness; double x, y, z; double[] xyz = new double[3]; float[] norm = new float[3]; float[] tex = new float[3]; // Compute some values for our looping double deltaTheta = (endTheta - startTheta) / (double) (nTheta - 1); double deltaPhi = (endPhi - startPhi) / (double) (nPhi - 1); double deltaTexX = 1.0 / (double) (nTheta - 1); double deltaTexY = 1.0 / (double) (nPhi - 1); double deltaPhiRadius = (endPhiRadius - startPhiRadius) / (double) (nPhi - 1); double deltaPhiThickness = (endPhiThickness - startPhiThickness) / (double) (nPhi - 1); boolean doThickness = true; if (startPhiThickness == 0.0 && endPhiThickness == 0.0) doThickness = false; // Create geometry int vertexCount = nTheta * nPhi; if (doThickness) vertexCount *= 2; int indexCount = (nTheta - 1) * (nPhi - 1) * 4; // Outer surface if (doThickness) { indexCount *= 2; // plus inner surface indexCount += (nPhi - 1) * 4 * 2; // plus left & right edges } IndexedQuadArray polys = new IndexedQuadArray(vertexCount, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2, indexCount); // // Compute coordinates, normals, and texture coordinates // theta = startTheta; tex[0] = 0.0f; int index = 0; for (int i = 0; i < nTheta; i++) { phi = startPhi; radius = startPhiRadius; thickness = startPhiThickness; tex[1] = 0.0f; for (int j = 0; j < nPhi; j++) { norm[0] = (float) (Math.cos(phi) * Math.cos(theta)); norm[1] = (float) (Math.sin(phi)); norm[2] = (float) (-Math.cos(phi) * Math.sin(theta)); xyz[0] = radius * norm[0]; xyz[1] = radius * norm[1]; xyz[2] = radius * norm[2]; polys.setCoordinate(index, xyz); polys.setNormal(index, norm); polys.setTextureCoordinate(index, tex); index++; if (doThickness) { radius2 = radius - thickness; xyz[0] = radius2 * norm[0]; xyz[1] = radius2 * norm[1]; xyz[2] = radius2 * norm[2]; norm[0] *= -1.0f; norm[1] *= -1.0f; norm[2] *= -1.0f; polys.setCoordinate(index, xyz); polys.setNormal(index, norm); polys.setTextureCoordinate(index, tex); index++; } phi += deltaPhi; radius += deltaPhiRadius; thickness += deltaPhiThickness; tex[1] += deltaTexY; } theta += deltaTheta; tex[0] += deltaTexX; } // // Compute coordinate indexes // (also used as normal and texture indexes) // index = 0; int phiRow = nPhi; int phiCol = 1; if (doThickness) { phiRow += nPhi; phiCol += 1; } int[] indices = new int[indexCount]; // Outer surface int n; for (int i = 0; i < nTheta - 1; i++) { for (int j = 0; j < nPhi - 1; j++) { n = i * phiRow + j * phiCol; indices[index + 0] = n; indices[index + 1] = n + phiRow; indices[index + 2] = n + phiRow + phiCol; indices[index + 3] = n + phiCol; index += 4; } } // Inner surface if (doThickness) { for (int i = 0; i < nTheta - 1; i++) { for (int j = 0; j < nPhi - 1; j++) { n = i * phiRow + j * phiCol; indices[index + 0] = n + 1; indices[index + 1] = n + phiCol + 1; indices[index + 2] = n + phiRow + phiCol + 1; indices[index + 3] = n + phiRow + 1; index += 4; } } } // Edges if (doThickness) { for (int j = 0; j < nPhi - 1; j++) { n = j * phiCol; indices[index + 0] = n; indices[index + 1] = n + phiCol; indices[index + 2] = n + phiCol + 1; indices[index + 3] = n + 1; index += 4; } for (int j = 0; j < nPhi - 1; j++) { n = (nTheta - 1) * phiRow + j * phiCol; indices[index + 0] = n; indices[index + 1] = n + 1; indices[index + 2] = n + phiCol + 1; indices[index + 3] = n + phiCol; index += 4; } } polys.setCoordinateIndices(0, indices); polys.setNormalIndices(0, indices); polys.setTextureCoordinateIndices(0, indices); // // Build a shape // arch = new Shape3D(); arch.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); arch.setGeometry(polys); arch.setAppearance(app); addChild(arch); }
From source file:ExBackgroundImage.java
private void rebuild() { // Build a shape if (shape == null) { shape = new Shape3D(); shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); shape.setAppearance(mainAppearance); addChild(shape);//from w ww . j a va 2s.c o m } else { shape.setAppearance(mainAppearance); } if (xDimension < 2 || zDimension < 2 || heights == null || heights.length < 4) { tristrip = null; shape.setGeometry(null); return; } // Create a list of coordinates, one per grid row/column double[] coordinates = new double[xDimension * zDimension * 3]; double x, z; int n = 0, k = 0; z = ((double) (zDimension - 1)) * zSpacing / 2.0; // start at front edge for (int i = 0; i < zDimension; i++) { x = -((double) (xDimension - 1)) * xSpacing / 2.0;// start at left // edge for (int j = 0; j < xDimension; j++) { coordinates[n++] = x; coordinates[n++] = heights[k++]; coordinates[n++] = z; x += xSpacing; } z -= zSpacing; } // Create a list of normals, one per grid row/column float[] normals = new float[xDimension * zDimension * 3]; Vector3f one = new Vector3f(0.0f, 0.0f, 0.0f); Vector3f two = new Vector3f(0.0f, 0.0f, 0.0f); Vector3f norm = new Vector3f(0.0f, 0.0f, 0.0f); n = 0; k = 0; for (int i = 0; i < zDimension - 1; i++) { for (int j = 0; j < xDimension - 1; j++) { // Vector to right in X one.set((float) xSpacing, (float) (heights[k + 1] - heights[k]), 0.0f); // Vector back in Z two.set(0.0f, (float) (heights[k + xDimension] - heights[k]), (float) -zSpacing); // Cross them to get the normal norm.cross(one, two); normals[n++] = norm.x; normals[n++] = norm.y; normals[n++] = norm.z; k++; } // Last normal in row is a copy of the previous one normals[n] = normals[n - 3]; // X normals[n + 1] = normals[n - 2]; // Y normals[n + 2] = normals[n - 1]; // Z n += 3; k++; } // Last row of normals is a copy of the previous row for (int j = 0; j < xDimension; j++) { normals[n] = normals[n - xDimension * 3]; // X normals[n + 1] = normals[n - xDimension * 3 + 1]; // Y normals[n + 2] = normals[n - xDimension * 3 + 2]; // Z n += 3; } // Create a list of texture coordinates, one per grid row/column float[] texcoordinates = new float[xDimension * zDimension * 2]; float deltaS = 1.0f / (float) (xDimension - 1); float deltaT = 1.0f / (float) (zDimension - 1); float s = 0.0f; float t = 0.0f; n = 0; for (int i = 0; i < zDimension; i++) { s = 0.0f; for (int j = 0; j < xDimension; j++) { texcoordinates[n++] = s; texcoordinates[n++] = t; s += deltaS; } t += deltaT; } // Create a list of triangle strip indexes. Each strip goes // down one row (X direction) of the elevation grid. int[] indexes = new int[xDimension * (zDimension - 1) * 2]; int[] stripCounts = new int[zDimension - 1]; n = 0; k = 0; for (int i = 0; i < zDimension - 1; i++) { stripCounts[i] = xDimension * 2; for (int j = 0; j < xDimension; j++) { indexes[n++] = k + xDimension; indexes[n++] = k; k++; } } // Create geometry for collection of triangle strips, one // strip per row of the elevation grid tristrip = new IndexedTriangleStripArray(coordinates.length, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2, indexes.length, stripCounts); tristrip.setCoordinates(0, coordinates); tristrip.setNormals(0, normals); tristrip.setTextureCoordinates(0, texcoordinates); tristrip.setCoordinateIndices(0, indexes); tristrip.setNormalIndices(0, indexes); tristrip.setTextureCoordinateIndices(0, indexes); // Set the geometry for the shape shape.setGeometry(tristrip); }