List of usage examples for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ
int ALLOW_TRANSFORM_READ
To view the source code for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ.
Click Source Link
From source file:KeyNavigateTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); createMap(objTrans);/* w w w. j a v a 2s . c o m*/ createFloor(objTrans); createCeiling(objTrans); objRoot.addChild(objTrans); return objRoot; }
From source file:GeometryByReferenceNIOBuffer.java
BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Set up attributes to render lines app = new Appearance(); transp = new TransparencyAttributes(); transp.setTransparency(0.5f);//from w w w .j ava2s . c om transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); transp.setTransparencyMode(TransparencyAttributes.NONE); app.setTransparencyAttributes(transp); //create the direct nio buffer createJ3DBuffers(); tetraRegular = createGeometry(1); tetraStrip = createGeometry(2); tetraIndexed = createGeometry(3); tetraIndexedStrip = createGeometry(4); geoArrays[0] = tetraRegular; geoArrays[1] = tetraStrip; geoArrays[2] = tetraIndexed; geoArrays[3] = tetraIndexedStrip; shape = new Shape3D(tetraRegular, app); shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ); Transform3D t = new Transform3D(); // move the object upwards t.set(new Vector3f(0.0f, 0.3f, 0.0f)); // rotate the shape Transform3D temp = new Transform3D(); temp.rotX(Math.PI / 4.0d); t.mul(temp); temp.rotY(Math.PI / 4.0d); t.mul(temp); // Shrink the object t.setScale(0.6); TransformGroup trans = new TransformGroup(t); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(trans); trans.addChild(shape); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // 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); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:MouseNavigateTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // note that we are creating a TG *above* the TG // the is being controlled by the mouse behaviors. // The SUN mouse translate behavior would fail in this // instance as all movement would be in the X-Y plane // irrespective of any TG above the object. // The TornadoMouseTranslate behavior always moves an object // parrallel to the image plane TransformGroup objTrans1 = new TransformGroup(); Transform3D t3d = new Transform3D(); objTrans1.getTransform(t3d);// ww w . ja va 2s . c o m t3d.setEuler(new Vector3d(0.9, 0.8, 0.3)); objTrans1.setTransform(t3d); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create the mouse scale behavior and set limits TornadoMouseScale mouseScale = new TornadoMouseScale(5, 0.1f); mouseScale.setMinScale(new Point3d(0.5, 0.5, 0.5)); mouseScale.setMaxScale(new Point3d(2, 2, 2)); mouseScale.setObject(objTrans); mouseScale.setChangeListener(this); mouseScale.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(mouseScale); // create the mouse rotate behavior TornadoMouseRotate mouseRotate = new TornadoMouseRotate(0.001, 0.001); mouseRotate.setInvert(true); mouseRotate.setObject(objTrans); mouseRotate.setChangeListener(this); mouseRotate.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(mouseRotate); // create the mouse translate behavior and set limits TornadoMouseTranslate mouseTrans = new TornadoMouseTranslate(0.005f); mouseTrans.setObject(objTrans); mouseTrans.setChangeListener(this); mouseTrans.setMinTranslate(new Point3d(-4, -4, -4)); mouseTrans.setMaxTranslate(new Point3d(4, 4, 4)); mouseTrans.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(mouseTrans); objTrans.addChild(new ColorCube(0.5)); // create some axis for the world to show it has been rotated ColorCube axis = new ColorCube(5.0); Appearance app = new Appearance(); app.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0)); axis.setAppearance(app); objTrans1.addChild(axis); objTrans1.addChild(objTrans); objRoot.addChild(objTrans1); return objRoot; }
From source file:SimpleGame.java
/** * This builds the ball that acts as the bullet for our gun. The ball is * created from a sphere primitive, and a transform group and interpolator * are added so that we can 'fire' the bullet. * //from ww w . j ava 2s .co m * @return BranchGroup that is the root of the ball branch. */ protected BranchGroup buildBall() { BranchGroup theBall = new BranchGroup(); Appearance ballApp = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); float shininess = 20.0f; ballApp.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); Sphere ball = new Sphere(0.2f, ballApp); TransformGroup ballMovXfmGrp = new TransformGroup(); ballMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); ballMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); ballMovXfmGrp.addChild(ball); theBall.addChild(ballMovXfmGrp); ballAlpha = new Alpha(1, 0, 0, 500, 0, 0); Transform3D axis = new Transform3D(); axis.rotY(Math.PI / 2); moveBall = new PositionInterpolator(ballAlpha, ballMovXfmGrp, axis, 0.0f, 50.0f); moveBall.setSchedulingBounds(bounds); theBall.addChild(moveBall); return theBall; }
From source file:InterleavedTest.java
BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Set up attributes to render lines app = new Appearance(); app.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE); transp = new TransparencyAttributes(); transp.setTransparency(0.5f);/*from ww w . ja v a2 s . c o m*/ transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); transp.setTransparencyMode(TransparencyAttributes.NONE); app.setTransparencyAttributes(transp); // load textures TextureAttributes texAttr1 = new TextureAttributes(); texAttr1.setTextureMode(TextureAttributes.DECAL); TextureAttributes texAttr2 = new TextureAttributes(); texAttr2.setTextureMode(TextureAttributes.MODULATE); TextureLoader tex = new TextureLoader(texImage1, new String("RGB"), this); if (tex == null) return null; tex1 = tex.getTexture(); tex = new TextureLoader(texImage2, new String("RGB"), this); if (tex == null) return null; tex2 = tex.getTexture(); textureUnitState[0] = new TextureUnitState(tex1, texAttr1, null); textureUnitState[1] = new TextureUnitState(tex2, texAttr2, null); tetraRegular = createGeometry(1); tetraStrip = createGeometry(2); tetraIndexed = createGeometry(3); tetraIndexedStrip = createGeometry(4); geoArrays[0] = tetraRegular; geoArrays[1] = tetraStrip; geoArrays[2] = tetraIndexed; geoArrays[3] = tetraIndexedStrip; shape = new Shape3D(tetraRegular, app); shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); Transform3D t = new Transform3D(); // move the object upwards t.set(new Vector3f(0.0f, 0.3f, 0.0f)); // rotate the shape Transform3D temp = new Transform3D(); temp.rotX(Math.PI / 4.0d); t.mul(temp); temp.rotY(Math.PI / 4.0d); t.mul(temp); // Shrink the object t.setScale(0.6); TransformGroup trans = new TransformGroup(t); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(trans); trans.addChild(shape); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // 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); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:PickTest.java
private Group createObject(int index, double scale, double xpos, double ypos) { Shape3D shape = null;//from w w w . j av a 2s .c om Geometry geom = null; // 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); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objTrans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); // 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); spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); spinTg.setCapability(TransformGroup.ENABLE_PICK_REPORTING); Appearance appearance = new Appearance(); switch (index) { case 0: geom = new GullCG(); break; case 1: geom = new TetrahedronTA(); break; case 2: geom = new OctahedronTFA(); break; case 3: geom = new IcosahedronTSA(); break; case 4: geom = new CubeIQA(); break; case 5: geom = new TetrahedronITA(); break; case 6: geom = new OctahedronITFA(); break; case 7: geom = new IcosahedronITSA(); break; case 8: geomMorph[0] = new ColorPyramidUp(); geomMorph[1] = new ColorCube(); geomMorph[2] = new ColorPyramidDown(); break; case 9: geom = new TetrahedronLA(); break; case 10: geom = new TetrahedronILA(); break; case 11: geom = new TetrahedronLSA(); break; case 12: geom = new TetrahedronILSA(); break; case 13: geom = new TetrahedronPA(); break; case 14: geom = new TetrahedronIPA(); break; // TODO: other geo types, Text3D? case 15: geom = new TetrahedronTA(); break; } Material m = new Material(); if (index == 8) { m.setLightingEnable(false); appearance.setMaterial(m); morph = new Morph((GeometryArray[]) geomMorph, appearance); morph.setCapability(Morph.ALLOW_WEIGHTS_READ); morph.setCapability(Morph.ALLOW_WEIGHTS_WRITE); PickTool.setCapabilities(morph, PickTool.INTERSECT_FULL); spinTg.addChild(morph); } else { // Geometry picking require this to be set. if (index == 0) m.setLightingEnable(true); else m.setLightingEnable(false); appearance.setMaterial(m); if ((index == 13) || (index == 14)) { PointAttributes pa = new PointAttributes(); pa.setPointSize(4.0f); appearance.setPointAttributes(pa); } shape = new Shape3D(geom, appearance); shape.setCapability(Shape3D.ALLOW_APPEARANCE_READ); shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); shape.setCapability(Shape3D.ENABLE_PICK_REPORTING); PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL); spinTg.addChild(shape); } // add it to the scene graph. objTrans.addChild(spinTg); return objTrans; }
From source file:SwingTest.java
/** * Create the scene side of the scenegraph *//*w w w . j a v a2 s . co m*/ protected BranchGroup createSceneBranchGroup() { // create the root of the scene side scenegraph BranchGroup objRoot = new BranchGroup(); // create a TransformGroup to rotate the objects in the scene // set the capability bits on the TransformGroup so that it // can be modified at runtime TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create a spherical bounding volume BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // create a 4x4 transformation matrix Transform3D yAxis = new Transform3D(); // create an Alpha interpolator to automatically generate // modifications to the rotation component of the transformation matrix Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); // create a RotationInterpolator behavior to effect the TransformGroup rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); // set the scheduling bounds on the behavior rotator.setSchedulingBounds(bounds); // add the behavior to the scenegraph objTrans.addChild(rotator); // create the BranchGroup which contains the objects // we add/remove to and from the scenegraph sceneBranchGroup = new BranchGroup(); // allow the BranchGroup to have children added at runtime sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND); sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_READ); sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_WRITE); // add both the cube and the sphere to the scenegraph sceneBranchGroup.addChild(createCube()); sceneBranchGroup.addChild(createSphere()); // create the colors for the 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); // create the ambient light AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); // create the directional light DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); // add the lights to the scenegraph objRoot.addChild(aLgt); objRoot.addChild(lgt1); // wire the scenegraph together objTrans.addChild(sceneBranchGroup); objRoot.addChild(objTrans); // return the root of the scene side of the scenegraph return objRoot; }
From source file:InterpolatorTest.java
private TransformGroup createSharedGroup(Appearance app) { TransformGroup tg = new TransformGroup(); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); tg.addChild(createGeometry(app, -0.5, -0.5, 0)); tg.addChild(createGeometry(app, -0.5, 0.5, 0)); tg.addChild(createGeometry(app, 0.5, 0.5, 0)); tg.addChild(createGeometry(app, 0.5, -0.5, 0)); return tg;//from w ww . j av a2 s. co m }
From source file:InterleavedNIOBuffer.java
BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Set up attributes to render lines app = new Appearance(); app.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE); transp = new TransparencyAttributes(); transp.setTransparency(0.5f);//from w ww . j a v a2 s . c o m transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); transp.setTransparencyMode(TransparencyAttributes.NONE); app.setTransparencyAttributes(transp); // load textures TextureAttributes texAttr1 = new TextureAttributes(); texAttr1.setTextureMode(TextureAttributes.DECAL); TextureAttributes texAttr2 = new TextureAttributes(); texAttr2.setTextureMode(TextureAttributes.MODULATE); TextureLoader tex = new TextureLoader(texImage1, new String("RGB"), this); if (tex == null) return null; tex1 = tex.getTexture(); tex = new TextureLoader(texImage2, new String("RGB"), this); if (tex == null) return null; tex2 = tex.getTexture(); textureUnitState[0] = new TextureUnitState(tex1, texAttr1, null); textureUnitState[1] = new TextureUnitState(tex2, texAttr2, null); createInterleavedBuffers(); tetraRegular = createGeometry(1); tetraStrip = createGeometry(2); tetraIndexed = createGeometry(3); tetraIndexedStrip = createGeometry(4); geoArrays[0] = tetraRegular; geoArrays[1] = tetraStrip; geoArrays[2] = tetraIndexed; geoArrays[3] = tetraIndexedStrip; shape = new Shape3D(tetraRegular, app); shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); Transform3D t = new Transform3D(); // move the object upwards t.set(new Vector3f(0.0f, 0.3f, 0.0f)); // rotate the shape Transform3D temp = new Transform3D(); temp.rotX(Math.PI / 4.0d); t.mul(temp); temp.rotY(Math.PI / 4.0d); t.mul(temp); // Shrink the object t.setScale(0.6); TransformGroup trans = new TransformGroup(t); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(trans); trans.addChild(shape); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // 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); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:SplineInterpolatorTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // create a root TG in case we need to scale the scene TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Transform3D t3d = new Transform3D(); objTrans.setTransform(t3d);//from ww w . j a v a 2 s. c o m Group hiResGroup = createLodLand(objTrans); createBuildings(objTrans); createHelicopters(objTrans); // connect objRoot.addChild(objTrans); return objRoot; }