List of usage examples for javax.media.j3d DirectionalLight DirectionalLight
public DirectionalLight(Color3f color, Vector3f direction)
From source file:mytrack.SimpleModelView.java
/** * Adds a dramatic blue light... /*from w w w. ja v a 2s. c om*/ */ private void addLightsToUniverse() { Bounds influenceRegion = new BoundingSphere(); Color3f lightColor = new Color3f(Color.RED); Vector3f lightDirection = new Vector3f(-1F, -1F, -1F); DirectionalLight light = new DirectionalLight(lightColor, lightDirection); light.setInfluencingBounds(influenceRegion); root.addChild(light); }
From source file:ConicWorld.java
public BranchGroup createSceneGraph(Canvas3D c) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a bounds for the background and behaviors BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Background bg = new Background(bgColor); bg.setApplicationBounds(bounds);/*from w w w . j av a2 s. co m*/ objRoot.addChild(bg); // 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(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objRoot.addChild(aLgt); objRoot.addChild(lgt1); // Create a bunch of objects with a behavior and add them // into the scene graph. int row, col; int numRows = 3, numCols = 5; Appearance[][] app = new Appearance[numRows][numCols]; for (row = 0; row < numRows; row++) for (col = 0; col < numCols; col++) app[row][col] = createAppearance(row * numCols + col); // Space between each row/column double xspace = 2.0 / ((double) numCols - 1.0); double yspace = 2.0 / ((double) numRows - 1.0); for (int i = 0; i < numRows; i++) { double ypos = ((double) i * yspace - 1.0) * 0.6; for (int j = 0; j < numCols; j++) { double xpos = xpos = ((double) j * xspace - 1.0) * 0.6; objRoot.addChild(createObject(i, j, app[i][j], 0.1, xpos, ypos)); } } // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:Position.java
public Position() { SimpleUniverse universe = new SimpleUniverse(); BranchGroup group = new BranchGroup(); // X axis made of spheres for (float x = -1.0f; x <= 1.0f; x = x + 0.1f) { Sphere sphere = new Sphere(0.05f); TransformGroup tg = new TransformGroup(); Transform3D transform = new Transform3D(); Vector3f vector = new Vector3f(x, .0f, .0f); transform.setTranslation(vector); tg.setTransform(transform);//from w w w . j a va 2s .co m tg.addChild(sphere); group.addChild(tg); } // Y axis made of cones for (float y = -1.0f; y <= 1.0f; y = y + 0.1f) { TransformGroup tg = new TransformGroup(); Transform3D transform = new Transform3D(); Cone cone = new Cone(0.05f, 0.1f); Vector3f vector = new Vector3f(.0f, y, .0f); transform.setTranslation(vector); tg.setTransform(transform); tg.addChild(cone); group.addChild(tg); } // Z axis made of cylinders for (float z = -1.0f; z <= 1.0f; z = z + 0.1f) { TransformGroup tg = new TransformGroup(); Transform3D transform = new Transform3D(); Cylinder cylinder = new Cylinder(0.05f, 0.1f); Vector3f vector = new Vector3f(.0f, .0f, z); transform.setTranslation(vector); tg.setTransform(transform); tg.addChild(cylinder); group.addChild(tg); } Color3f light1Color = new Color3f(.1f, 1.4f, .1f); // green light BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); group.addChild(light1); universe.getViewingPlatform().setNominalViewingTransform(); // add the group of objects to the Universe universe.addBranchGraph(group); }
From source file:PickWorld.java
public BranchGroup createSceneGraph(Canvas3D c) { // 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(1.0);//from w ww. ja v a 2 s . c o m objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and behaviors BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Attach picking behavior utlities to the scene root. // They will wake up when user manipulates a scene node. PickRotateBehavior behavior = new PickRotateBehavior(objRoot, c, bounds); objRoot.addChild(behavior); PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, c, bounds); objRoot.addChild(behavior2); PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, c, bounds); objRoot.addChild(behavior3); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.4f); Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objRoot.addChild(bg); // 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(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objRoot.addChild(aLgt); objRoot.addChild(lgt1); // Create a bunch of objects with a behavior and add them // into the scene graph. int row, col; int numRows = 3, numCols = 5; Appearance[][] app = new Appearance[numRows][numCols]; for (row = 0; row < numRows; row++) for (col = 0; col < numCols; col++) app[row][col] = createAppearance(row * numCols + col); for (int i = 0; i < numRows; i++) { double ypos = (double) (i - numRows / 2) * 0.6; for (int j = 0; j < numCols; j++) { double xpos = (double) (j - numCols / 2) * 0.4; objScale.addChild(createObject(i, j, app[i][j], 0.1, xpos, ypos)); } } // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
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);// ww w . java 2s . co 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:TickTockPicking.java
public BranchGroup createSceneGraph(Canvas3D c) { // 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);/*from ww w. jav a 2 s . c o m*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and behaviors BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // 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(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objScale.addChild(aLgt); objScale.addChild(lgt1); // Create a pair of transform group nodes and initialize them to // identity. Enable the TRANSFORM_WRITE capability so that // our behaviors can modify them at runtime. Add them to the // root of the subgraph. TransformGroup objTrans1 = new TransformGroup(); objTrans1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objScale.addChild(objTrans1); TransformGroup objTrans2 = new TransformGroup(); objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans1.addChild(objTrans2); // Create the positioning and scaling transform group node. Transform3D t = new Transform3D(); t.set(0.3, new Vector3d(0.0, -1.5, 0.0)); TransformGroup objTrans3 = new TransformGroup(t); objTrans2.addChild(objTrans3); // Create a simple shape leaf node, set it's appearance, and // add it to the scene graph. Shape3D shape = new Cube(); Appearance a = new Appearance(); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); a.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); shape.setAppearance(a); shape.setCapability(shape.ALLOW_APPEARANCE_READ); shape.setCapability(shape.ALLOW_APPEARANCE_WRITE); objTrans3.addChild(shape); // Create a new Behavior object that will perform the desired // rotation on the specified transform object and add it into // the scene graph. Transform3D yAxis1 = new Transform3D(); yAxis1.rotX(Math.PI / 2.0); Alpha tickTockAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 2500, 200, 5000, 2500, 200); RotationInterpolator tickTock = new RotationInterpolator(tickTockAlpha, objTrans1, yAxis1, -(float) Math.PI / 2.0f, (float) Math.PI / 2.0f); tickTock.setSchedulingBounds(bounds); objTrans2.addChild(tickTock); // Create a new Behavior object that will perform the desired // rotation on the specified transform object and add it into // the scene graph. Transform3D yAxis2 = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans2, yAxis2, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans2.addChild(rotator); // Now create the simple picking behavior PickHighlightBehavior pickBeh = new PickHighlightBehavior(c, objRoot, bounds); // Create a bunch of objects with a behavior and add them // into the scene graph. int row, col; Appearance[][] app = new Appearance[3][3]; for (row = 0; row < 3; row++) for (col = 0; col < 3; col++) app[row][col] = createAppearance(row * 3 + col); for (int i = 0; i < 3; i++) { double ypos = (double) (i - 1) * 1.5; for (int j = 0; j < 3; j++) { double xpos = (double) (j - 1) * 1.5; objScale.addChild(createObject(app[i][j], 0.3, xpos, ypos)); } } // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:LOD.java
private void createLights(BranchGroup graphRoot) { // Create a bounds for the light source influence BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the global, ambient light Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds);//w w w .j av a 2 s. c om graphRoot.addChild(aLgt); // Set up the directional (infinite) light source Color3f lColor1 = new Color3f(0.9f, 0.9f, 0.9f); Vector3f lDir1 = new Vector3f(1.0f, 1.0f, -1.0f); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); graphRoot.addChild(lgt1); }
From source file:PureImmediateStereo.java
public void run() { // Set up Graphics context gc = canvas.getGraphicsContext3D();/* w ww.ja v a2 s. co m*/ // We always need to set this for PureImmediate // stereo mode gc.setBufferOverride(true); Color3f lightColor = new Color3f(1, 1, 1); Vector3f lightDir = new Vector3f(0, 0, -1); DirectionalLight light = new DirectionalLight(lightColor, lightDir); gc.addLight(light); Appearance redApp = new Appearance(); Appearance greenApp = new Appearance(); Color3f ambientColor = new Color3f(0, 0, 0); Color3f emissiveColor = new Color3f(0, 0, 0); Color3f diffuseColor = new Color3f(1, 0, 0); Color3f specularColor = new Color3f(1, 1, 1); redApp.setMaterial(new Material(ambientColor, emissiveColor, diffuseColor, specularColor, 5)); diffuseColor = new Color3f(0, 1, 0); greenApp.setMaterial(new Material(ambientColor, emissiveColor, diffuseColor, specularColor, 5)); // Set up geometry Cone leftCone = new Cone(0.4f, 0.6f, Primitive.GENERATE_NORMALS, redApp); Cone rightCone = new Cone(0.4f, 0.6f, Primitive.GENERATE_NORMALS, greenApp); leftConeBody = leftCone.getShape(Cone.BODY); leftConeCap = leftCone.getShape(Cone.CAP); rightConeBody = rightCone.getShape(Cone.BODY); rightConeCap = rightCone.getShape(Cone.CAP); leftTrans = new Vector3f(-0.6f, 0, 0); rightTrans = new Vector3f(0.6f, 0, 0); while (true) { // compute data which is can be used // for both left and right eye computeSharedData(); if (stereoSupport) { if (!sharedStereoZbuffer) { gc.setStereoMode(GraphicsContext3D.STEREO_BOTH); // This clear both left and right buffers, we // must set STEREO_BOTH before it. Otherwise // it only clear LEFT or RIGHT buffer unless // this is invoke twice for each buffer. gc.clear(); } gc.setStereoMode(GraphicsContext3D.STEREO_LEFT); renderLeft(); gc.setStereoMode(GraphicsContext3D.STEREO_RIGHT); renderRight(); } else { gc.clear(); renderLeft(); } // This swap both left and right buffers so // there is no need to set STEREO_BOTH before it canvas.swap(); // Be polite to other threads ! Thread.yield(); } }
From source file:ModelClipTest.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // 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);//from w w w .j a v a2 s.c o m objScale.setTransform(t3d); objRoot.addChild(objScale); // This Transformgroup is used by the mouse manipulators to // move the CYlinder. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(objTrans); //Create Model Clip ModelClip mc = new ModelClip(); boolean enables[] = { false, false, false, false, false, false }; Vector4d eqn1 = new Vector4d(0.0, 1.0, 0.0, 0.0); Vector4d eqn2 = new Vector4d(1.0, 1.0, 0.0, 0.0); mc.setEnables(enables); mc.setPlane(1, eqn1); mc.setPlane(2, eqn2); mc.setEnable(1, true); mc.setEnable(2, true); mc.setInfluencingBounds(bounds); objTrans.addChild(mc); //Create a cylinder PolygonAttributes attr = new PolygonAttributes(); attr.setCullFace(PolygonAttributes.CULL_NONE); Appearance ap = new Appearance(); Material mat = new Material(); mat.setLightingEnable(true); ap.setMaterial(mat); ap.setPolygonAttributes(attr); Cylinder CylinderObj = new Cylinder(1.0f, 2.0f, ap); objTrans.addChild(CylinderObj); // Create the rotate behavior node MouseRotate behavior = new MouseRotate(objTrans); objTrans.addChild(behavior); behavior.setSchedulingBounds(bounds); // Create the zoom behavior node MouseZoom behavior2 = new MouseZoom(objTrans); objTrans.addChild(behavior2); behavior2.setSchedulingBounds(bounds); //Shine it with two colored lights. Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f); Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f); Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); objScale.addChild(lgt1); objScale.addChild(lgt2); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:Gouraud.java
/** * Erstellt den Szenegraphen/*from ww w.j a v a 2s . c o m*/ * * @return BranchGroup */ public BranchGroup macheSzene() { BranchGroup objWurzel = new BranchGroup(); // Transformation, 2 Rotationen: Transform3D drehung = new Transform3D(); Transform3D drehung2 = new Transform3D(); drehung.rotX(Math.PI / 4.0d); drehung2.rotY(Math.PI / 5.0d); drehung.mul(drehung2); TransformGroup objDreh = new TransformGroup(drehung); //Loader ObjectFile file = new ObjectFile(ObjectFile.RESIZE); Scene scene = null; try { // Laden der Obj Datei mittels jar scene = file.load(ClassLoader.getSystemResource("teapot.obj")); } catch (Exception e) { System.err.println(e); System.exit(1); } objDreh.addChild(scene.getSceneGroup()); DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f), new Vector3f(-1.0f, -1.0f, -1.0f)); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d)); objDreh.addChild(d_Licht); objWurzel.addChild(objDreh); return objWurzel; }