List of usage examples for javax.media.j3d Switch Switch
public Switch()
From source file:BehaviorTest.java
public void addBehaviorToParentGroup(Group nodeParentGroup) { nodeParentGroup.addChild(this); m_TransformGroup = new TransformGroup(); m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); m_BoundsSwitch = new Switch(); m_BoundsSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); Appearance app = new Appearance(); PolygonAttributes polyAttrbutes = new PolygonAttributes(); polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE); app.setPolygonAttributes(polyAttrbutes); m_BoundsSwitch.addChild(new Sphere(1, app)); ColorCube cube = new ColorCube(); cube.setAppearance(app);/*from ww w.j a v a 2 s . c o m*/ Group g = new Group(); g.addChild(cube); m_BoundsSwitch.addChild(g); m_BoundsSwitch.setWhichChild(Switch.CHILD_NONE); m_TransformGroup.addChild(m_BoundsSwitch); nodeParentGroup.addChild(m_TransformGroup); }
From source file:SplineInterpolatorTest.java
public Group createLodLand(Group g) { Switch switchNode = new Switch(); switchNode.setCapability(Switch.ALLOW_SWITCH_WRITE); Group hiResGroup = createLand(switchNode); createEnvirons(switchNode);// w w w. j a va 2s . c om // create a DistanceLOD that will select the child of // the Switch node based on distance. Here we are selecting // child 0 (high res) if we are closer than 180 units to // 0,0,0 and child 1 (low res) otherwise. float[] distanceArray = { 180 }; DistanceLOD distanceLod = new DistanceLOD(distanceArray); distanceLod.setSchedulingBounds(getApplicationBounds()); distanceLod.addSwitch(switchNode); g.addChild(distanceLod); g.addChild(switchNode); return hiResGroup; }
From source file:Demo3D.java
/** * Create the subgraph #32/* w ww . jav a 2 s. c o m*/ * * @return javax.media.j3d.TransformGroup trGr32_3 - the root of the * subgraph #32 */ public BranchGroup mySubGraph32() { // A BoundingSphere instance as general bounding region. boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Create the first TransformGroup node trGr32_1 to: // 1) attach the Switch node with the five different earth's // representations to the subgraph32 // 2) attach a coordinate system to each earth's representation // 3) rotate each earth about its own y-axis. trGr32_1 = new TransformGroup(); // With the ALLOW_TRANSFORM_WRITE capability, we allow the // modification of the TransformGroup's code by the behavior's // code at run time. trGr32_1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // SwitchBehavior is the class which controls the fonctioning of // the switchEarths node. switchBehavior = new SwitchBehavior(this); switchBehavior.setSchedulingBounds(boundsGen); trGr32_1.addChild(switchBehavior); // The Switch which allows the rendering of the five different // earth's representations. switchEarths = new Switch(); // With the ALLOW_TRANSFORM_WRITE, ALLOW_SWITCH_WRITE and // ALLOW_CHILDREN_READ // capabilities we allow to get or set new capabilities. switchEarths.setCapability(Switch.ALLOW_SWITCH_READ); switchEarths.setCapability(Switch.ALLOW_SWITCH_WRITE); switchEarths.setCapability(Switch.ALLOW_CHILDREN_READ); // Attach the different earth's representations to the Switch node. // Increasing earth_Points = new Earth("points", 0.4f); switchEarths.addChild(earth_Points.myEarth()); // # 0 earth_Lines = new Earth("lines", 0.4f); switchEarths.addChild(earth_Lines.myEarth()); // # 1 earth_Polygons = new Earth("polygons", 0.4f); switchEarths.addChild(earth_Polygons.myEarth()); // # 2 earth_Gouraud = new Earth("gouraud", 0.4f); switchEarths.addChild(earth_Gouraud.myEarth()); // # 3 earth_Texture = new Earth("texture", 0.4f); switchEarths.addChild(earth_Texture.myEarth()); // # 4 // Decreasing switchEarths.addChild(earth_Texture.myEarth()); // # 4 switchEarths.addChild(earth_Gouraud.myEarth()); // # 3 switchEarths.addChild(earth_Polygons.myEarth()); // # 2 switchEarths.addChild(earth_Lines.myEarth()); // # 1 switchEarths.addChild(earth_Points.myEarth()); // # 0 // Attach the Switch node with the five different earth's // representations to the TransformGroup node trGr32_1. trGr32_1.addChild(switchEarths); // Create and attach a coordinate system to the TransformGroup node // trGr32_1, that is to each earth's representation. coordSyst = new CoordSyst(1.0f, 1.0f, 0.0f, // Color of the x-axis 0.0f, 0.0f, 1.0f, // Color of the y-axis 1.0f, 0.0f, 0.0f, // Color of the z-axis 0.6f); // Lenght of the 3 axes trGr32_1.addChild(coordSyst); // Create the alpha(t) function for the earth's rotation about // its own y-axis. rotationAlpha_1 = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 10000, 0, 0, 0, 0, 0); // Create the earth's rotation about its own y-axis. rotator_1 = new RotationInterpolator(rotationAlpha_1, trGr32_1, new Transform3D(), 0.0f, (float) Math.PI * 2.0f); rotator_1.setSchedulingBounds(boundsGen); trGr32_1.addChild(rotator_1); // Create a Transform3D instance to execute the desired "static // translation" of the earth, that is the rotation radius around // the sun. transl = new Transform3D(); vectTransl = new Vector3d(2.5, 0.0, 0.0); transl.set(vectTransl); // Create the second TransformGroup node trGr32_2 and attach the // "static translation" transl to it. trGr32_2 = new TransformGroup(transl); // Attach the trGr32_1 node to the trGr32_2 node. trGr32_2.addChild(trGr32_1); // Create the third TransformGroup node trGr32_3 for the earth's // rotation around the sun. trGr32_3 = new TransformGroup(); // With the ALLOW_TRANSFORM_WRITE capability, we allow the // modification of the TransformGroup's code by the behavior's // code at run time. trGr32_3.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // Attach the trGr32_2 node to the trGr32_3 node. trGr32_3.addChild(trGr32_2); // Create the alpha(t) function for the earth's rotation around the sun. rotationAlpha_2 = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 20000, 0, 0, 0, 0, 0); // To restart correctly the rotation of the earth around the // sun after a detach/add process of the subgraph32 from the // BranchGroup node brGr3. rotationAlpha_2.setStartTime(System.currentTimeMillis()); // Create the earth's rotation around the sun. rotator_2 = new RotationInterpolator(rotationAlpha_2, trGr32_3, new Transform3D(), 0.0f, (float) Math.PI * 2.0f); rotator_2.setSchedulingBounds(boundsGen); trGr32_3.addChild(rotator_2); // To allow the detaching of this subgraph32 from the // BranchGroup node brGr3. brGr32 = new BranchGroup(); brGr32.setCapability(BranchGroup.ALLOW_DETACH); brGr32.addChild(trGr32_3); // Return the final version of the BranchGroup node brGr32. return brGr32; }
From source file:AppearanceExplorer.java
void setupSceneSwitch() { // create a Switch for the scene, allow switch changes sceneSwitch = new Switch(); sceneSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); sceneSwitch.setCapability(Switch.ALLOW_CHILDREN_READ); sceneSwitch.setCapability(Switch.ALLOW_CHILDREN_WRITE); sceneSwitch.setCapability(Switch.ALLOW_CHILDREN_EXTEND); Shape3D pointArray = createPointArray(); sceneSwitch.addChild(pointArray);/*from ww w.j a v a2 s .c o m*/ Shape3D lineArray = createLineArray(); sceneSwitch.addChild(lineArray); Shape3D triangleArray = createTriangleArray(); sceneSwitch.addChild(triangleArray); Shape3D lineStripArray = createLineStripArray(); sceneSwitch.addChild(lineStripArray); Shape3D triangleStripArray = createTriangleStripArray(); sceneSwitch.addChild(triangleStripArray); Shape3D triangleFanArray = createTriangleFanArray(); sceneSwitch.addChild(triangleFanArray); Shape3D texTris = createTexTris(); sceneSwitch.addChild(texTris); Shape3D texSquare = createTexSquare(); sceneSwitch.addChild(texSquare); Shape3D largeTexSquare = createLargeTexSquare(); sceneSwitch.addChild(largeTexSquare); Shape3D colorCube = createColorCube(); sceneSwitch.addChild(colorCube); Shape3D ngCreaseCube = createNGCube(45); sceneSwitch.addChild(ngCreaseCube); Shape3D ngSmoothCube = createNGCube(100); sceneSwitch.addChild(ngSmoothCube); Shape3D triWithHole = createTriWithHole(); sceneSwitch.addChild(triWithHole); // create a sphere with the shared appearance Sphere sphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, appearance); sceneSwitch.addChild(sphere); // create a sphere with the shared appearance Sphere lrSphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, 10, appearance); sceneSwitch.addChild(lrSphere); // create a sphere with the shared appearance Sphere hrSphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, 45, appearance); sceneSwitch.addChild(hrSphere); // Text3D Shape3D text3D = createText3D(); sceneSwitch.addChild(text3D); // galleon -- use a placeholder to indicate it hasn't been loaded yet // then load it the first time it gets asked for //was: //Group galleon = createGalleon(); //sceneSwitch.addChild(galleon); galleonIndex = sceneSwitch.numChildren(); galleonPlaceholder = new BranchGroup(); galleonPlaceholder.setCapability(BranchGroup.ALLOW_DETACH); sceneSwitch.addChild(galleonPlaceholder); // beethoven -- use a placeholder to indicate it hasn't been loaded yet // then load it the first time it gets asked for //was: //Group beethoven = createBeethoven(); //sceneSwitch.addChild(beethoven); beethovenIndex = sceneSwitch.numChildren(); beethovenPlaceholder = new BranchGroup(); beethovenPlaceholder.setCapability(BranchGroup.ALLOW_DETACH); sceneSwitch.addChild(beethovenPlaceholder); }
From source file:AppearanceExplorer.java
Group setupLights() { Group group = new Group(); // set up the BoundingSphere for all the lights BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0); // Set up the ambient light AmbientLight lightAmbient = new AmbientLight(medGrey); lightAmbient.setInfluencingBounds(bounds); lightAmbient.setCapability(Light.ALLOW_STATE_WRITE); group.addChild(lightAmbient);/* w w w .j av a2 s. com*/ lightSwitch = new Switch(); lightSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); group.addChild(lightSwitch); // Set up the directional light Vector3f lightDirection1 = new Vector3f(0.0f, 0.0f, -1.0f); DirectionalLight lightDirectional1 = new DirectionalLight(white, lightDirection1); lightDirectional1.setInfluencingBounds(bounds); lightDirectional1.setCapability(Light.ALLOW_STATE_WRITE); lightSwitch.addChild(lightDirectional1); Point3f lightPos1 = new Point3f(-4.0f, 8.0f, 16.0f); Point3f lightAttenuation1 = new Point3f(1.0f, 0.0f, 0.0f); PointLight pointLight1 = new PointLight(brightWhite, lightPos1, lightAttenuation1); pointLight1.setInfluencingBounds(bounds); lightSwitch.addChild(pointLight1); Point3f lightPos2 = new Point3f(-16.0f, 8.0f, 4.0f); //Point3f lightPos = new Point3f(-4.0f, 2.0f, 1.0f); Point3f lightAttenuation2 = new Point3f(1.0f, 0.0f, 0.0f); PointLight pointLight2 = new PointLight(white, lightPos2, lightAttenuation2); pointLight2.setInfluencingBounds(bounds); lightSwitch.addChild(pointLight2); return group; }