List of usage examples for javax.media.j3d RotationInterpolator setSchedulingBounds
public void setSchedulingBounds(Bounds region)
From source file:HelloUniverse.java
public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans);/* ww w. j av a2 s . c om*/ objTrans.addChild(new ColorCube(0.2)); 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); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); return objRoot; }
From source file:CuboidTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); 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);/* w w w . j ava2 s . co m*/ // create an appearance Appearance ap = new Appearance(); // render as a wireframe PolygonAttributes polyAttrbutes = new PolygonAttributes(); polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE); ap.setPolygonAttributes(polyAttrbutes); objTrans.addChild(new Cuboid(50, 30, 20, ap)); objTrans.addChild(new Box(25, 15, 10, ap)); objRoot.addChild(objTrans); return objRoot; }
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 a 2s .c o m*/ // 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:LightTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // create the 4 lights - the actual creation // and UI managment is delegated to an object // that "shadows" (no pun intended) the functionality // of the particular light createLight(new AmbientLightObject(), objRoot); createLight(new PointLightObject(), objRoot); createLight(new DirectionalLightObject(), objRoot); createLight(new SpotLightObject(), objRoot); // rotate some of the spheres in the scene TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); 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(getApplicationBounds()); objTrans.addChild(rotator);/*ww w . j a va 2 s .co m*/ // create a large sphere in the center of the // scene and the floor as staionary objects objRoot.addChild(createSphere(0, 0, 0, 2)); objRoot.addChild(createFloor()); // create a smaller sphere at the corners of a cube final int nCubeSize = 3; objTrans.addChild(createSphere(nCubeSize, nCubeSize, nCubeSize, 1)); objTrans.addChild(createSphere(nCubeSize, nCubeSize, -nCubeSize, 1)); objTrans.addChild(createSphere(nCubeSize, -nCubeSize, nCubeSize, 1)); objTrans.addChild(createSphere(nCubeSize, -nCubeSize, -nCubeSize, 1)); objTrans.addChild(createSphere(-nCubeSize, nCubeSize, nCubeSize, 1)); objTrans.addChild(createSphere(-nCubeSize, nCubeSize, -nCubeSize, 1)); objTrans.addChild(createSphere(-nCubeSize, -nCubeSize, nCubeSize, 1)); objTrans.addChild(createSphere(-nCubeSize, -nCubeSize, -nCubeSize, 1)); // add some small spheres here and there to // make things interesting objRoot.addChild(createSphere(-6, -6, 2, 1)); objRoot.addChild(createSphere(8, -5, 3, 1)); objRoot.addChild(createSphere(6, 7, -1, 1)); objRoot.addChild(createSphere(-5, 6, -3.5f, 0.5f)); objRoot.addChild(objTrans); return objRoot; }
From source file:LoaderTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // create a TransformGroup to flip the hand onto its end and enlarge it. TransformGroup objTrans1 = new TransformGroup(); Transform3D tr = new Transform3D(); objTrans1.getTransform(tr);/* w w w.j a va 2s. com*/ tr.rotX(90.0 * Math.PI / 180.0); tr.setScale(10.0); objTrans1.setTransform(tr); // create a TransformGroup to rotate the hand TransformGroup objTrans2 = new TransformGroup(); objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // create a RotationInterpolator behavior to rotate the hand 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, objTrans2, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans2.addChild(rotator); // 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); // load the object file Scene scene = null; Shape3D shape = null; // read in the geometry information from the data file ObjectFile objFileloader = new ObjectFile(ObjectFile.RESIZE); try { scene = objFileloader.load("hand1.obj"); } catch (Exception e) { scene = null; System.err.println(e); } if (scene == null) System.exit(1); // retrieve the Shape3D object from the scene BranchGroup branchGroup = scene.getSceneGroup(); shape = (Shape3D) branchGroup.getChild(0); // create an Appearance and Material 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)); // assign the appearance to the Shape shape.setAppearance(app); // connect the scenegraph objTrans2.addChild(scene.getSceneGroup()); objTrans1.addChild(objTrans2); objRoot.addChild(objTrans1); return objRoot; }
From source file:ViewProj.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // 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); objRoot.addChild(objTrans);/*from ww w . j av a 2 s. c o m*/ // Create a Sphere. We will display this as both wireframe and // solid to make a hidden line display // wireframe Appearance wireApp = new Appearance(); ColoringAttributes ca = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT); wireApp.setColoringAttributes(ca); wirePa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0.0f); wireApp.setPolygonAttributes(wirePa); Sphere outWireSphere = new Sphere(sphereRadius, 0, 10, wireApp); objTrans.addChild(outWireSphere); // solid ColoringAttributes outCa = new ColoringAttributes(red, ColoringAttributes.SHADE_FLAT); Appearance outSolid = new Appearance(); outSolid.setColoringAttributes(outCa); solidPa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_BACK, 0.0f); solidPa.setPolygonOffsetFactor(dynamicOffset); solidPa.setPolygonOffset(staticOffset); solidPa.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE); outSolid.setPolygonAttributes(solidPa); Sphere outSolidSphere = new Sphere(sphereRadius, 0, 10, outSolid); objTrans.addChild(outSolidSphere); innerTG = new TransformGroup(); innerTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); scale = new Transform3D(); updateInnerScale(); objTrans.addChild(innerTG); // Create a smaller sphere to go inside. This sphere has a different // tesselation and color Sphere inWireSphere = new Sphere(sphereRadius, 0, 15, wireApp); innerTG.addChild(inWireSphere); // inside solid ColoringAttributes inCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT); Appearance inSolid = new Appearance(); inSolid.setColoringAttributes(inCa); inSolid.setPolygonAttributes(solidPa); Sphere inSolidSphere = new Sphere(sphereRadius, 0, 15, inSolid); innerTG.addChild(inSolidSphere); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. AxisAngle4f axisAngle = new AxisAngle4f(0.0f, 0.0f, 1.0f, -(float) Math.PI / 2.0f); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 80000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); //objTrans.addChild(rotator); Background bgWhite = new Background(white); bgWhite.setApplicationBounds(bounds); objTrans.addChild(bgWhite); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:GearTest.java
public BranchGroup createSceneGraph(int toothCount) { // 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 . java2 s . c om 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 Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); objScale.addChild(bgNode); // Set up the global 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); Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objScale.addChild(ambientLightNode); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objScale.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objScale.addChild(light2); // 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); objScale.addChild(objTrans); // Create an Appearance. Appearance look = new Appearance(); Color3f objColor = new Color3f(0.5f, 0.5f, 0.6f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); look.setMaterial(new Material(objColor, black, objColor, white, 100.0f)); // Create a gear, add it to the scene graph. // SpurGear gear = new SpurGear(toothCount, 1.0f, 0.2f, SpurGear gear = new SpurGearThinBody(toothCount, 1.0f, 0.2f, 0.05f, 0.05f, 0.3f, 0.28f, look); objTrans.addChild(gear); // Create a new Behavior object that will rotate the object and // add it into the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 8000, 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); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:ExAppearance.java
private Group createObject(Appearance app, double scale, double xpos, double ypos) { // Create a transform group node to scale and position the object. Transform3D t = new Transform3D(); t.set(scale, new Vector3d(xpos, ypos, 0.0)); TransformGroup objTrans = new TransformGroup(t); // Create a second 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); // Create a simple shape leaf node and set the appearance Shape3D shape = new Tetrahedron(); shape.setAppearance(app);//ww w. j av a 2 s . com // add it to the scene graph. spinTg.addChild(shape); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 5000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, spinTg, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); // Add the behavior and the transform group to the object objTrans.addChild(rotator); objTrans.addChild(spinTg); return objTrans; }
From source file:ExSound.java
private Group buildTumblingBox(float width, float height, float depth, Appearance app, int xDur, int yDur, int zDur) { BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Build a box to tumble Shape3D box = buildBox(width, height, depth, app); // Build a set of nested transform groups. Attach // to each one a behavior that rotates around an X, // Y, or Z axis. Use different rotation speeds for // each axis to create a tumbling effect. TransformGroup outerGroup = new TransformGroup(); outerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D yAxis = new Transform3D(); Alpha alpha = new Alpha(-1, // loop count: -1 = forever Alpha.INCREASING_ENABLE, // increasing 0, // trigger time: 0 = now 0, // delay: 0 = none xDur, // increasing duration 0, // increasing ramp duration 0, // at one (sustain) duration 0, // decreasing duration 0, // decreasing ramp duration 0); // at zero duration RotationInterpolator rot = new RotationInterpolator(alpha, // Alpha // control outerGroup, // Target transform group yAxis, // Y axis rotation 0.0f, // Minimum angle 2.0f * (float) Math.PI);// Maximum angle rot.setSchedulingBounds(worldBounds); outerGroup.addChild(rot);/*w w w . j a v a 2 s.c om*/ TransformGroup middleGroup = new TransformGroup(); middleGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D xAxis = new Transform3D(); xAxis.rotZ(-1.571f); alpha = new Alpha(-1, // loop count: -1 = forever Alpha.INCREASING_ENABLE, // increasing 0, // trigger time: 0 = now 0, // delay: 0 = none yDur, // increasing duration 0, // increasing ramp duration 0, // at one (sustain) duration 0, // decreasing duration 0, // decreasing ramp duration 0); // at zero duration rot = new RotationInterpolator(alpha, // Alpha control middleGroup, // Target transform group xAxis, // Y axis rotation 0.0f, // Minimum angle 2.0f * (float) Math.PI);// Maximum angle rot.setSchedulingBounds(worldBounds); middleGroup.addChild(rot); outerGroup.addChild(middleGroup); TransformGroup innerGroup = new TransformGroup(); innerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D zAxis = new Transform3D(); zAxis.rotX(1.571f); alpha = new Alpha(-1, // loop count: -1 = forever Alpha.INCREASING_ENABLE, // increasing 0, // trigger time: 0 = now 0, // delay: 0 = none zDur, // increasing duration 0, // increasing ramp duration 0, // at one (sustain) duration 0, // decreasing duration 0, // decreasing ramp duration 0); // at zero duration rot = new RotationInterpolator(alpha, // Alpha control innerGroup, // Target transform group zAxis, // Y axis rotation 0.0f, // Minimum angle 2.0f * (float) Math.PI);// Maximum angle rot.setSchedulingBounds(worldBounds); innerGroup.addChild(rot); middleGroup.addChild(innerGroup); innerGroup.addChild(box); return outerGroup; }