List of usage examples for javax.media.j3d TransformGroup setTransform
public void setTransform(Transform3D t1)
From source file:Text3DTest.java
TransformGroup createText3D(TornadoRotation rotator, String szText, int nSize, float scale, float trans, int nPath) { TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(scale);/* ww w . ja v a2 s. co m*/ t3d.setTranslation(new Vector3d(0.0, trans, -10.0)); tg.setTransform(t3d); // use a customized FontExtrusion object to control the depth of the // text double X1 = 0; double Y1 = 0; double X2 = 3; double Y2 = 0; Shape extrusionShape = new java.awt.geom.Line2D.Double(X1, Y1, X2, Y2); FontExtrusion fontEx = new FontExtrusion(extrusionShape); Font3D f3d = new Font3D(new Font("TimesRoman", Font.PLAIN, nSize), fontEx); TornadoText3D text3D = new TornadoText3D(f3d, szText, new Point3f(0.0f, 0.0f, 0.0f), Text3D.ALIGN_CENTER, nPath); rotator.addTornadoText3D(text3D); // create an appearance Color3f black = new Color3f(0.1f, 0.1f, 0.1f); Color3f objColor = new Color3f(0.2f, 0.2f, 0.2f); Appearance app = new Appearance(); app.setMaterial(new Material(objColor, black, objColor, black, 90.0f)); // render as a wireframe PolygonAttributes polyAttrbutes = new PolygonAttributes(); polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE); app.setPolygonAttributes(polyAttrbutes); tg.addChild(new Shape3D(text3D, app)); return tg; }
From source file:edu.uci.ics.jung.visualization3d.VisualizationViewer.java
public BranchGroup createSceneGraph(final Canvas3D canvas) { objRoot = new BranchGroup(); objRoot.setCapability(Group.ALLOW_CHILDREN_EXTEND); objRoot.setCapability(Group.ALLOW_CHILDREN_WRITE); TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); // t3d.setScale(0.05); objScale.setTransform(t3d); objRoot.addChild(objScale);/* w ww . ja v a 2s . co m*/ Transform3D tt = new Transform3D(); tt.setScale(.05); tt.setTranslation(new Vector3f(0, 0, -30.f)); objTrans = new TransformGroup(tt); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objTrans.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); objScale.addChild(objTrans); // objRoot.addChild(objTrans); // Create Colors, Materials, and Appearances. Appearance look = new Appearance(); Color3f objColor = new Color3f(0.7f, 0.7f, 0.7f); Color3f black = new Color3f(0.f, 0.f, 0.f); Color3f white = new Color3f(1.0f, 1.0f, 0.6f); Color3f gray = new Color3f(.2f, .2f, .2f); Color3f red = new Color3f(1.0f, 0, 0); Color3f yellow = new Color3f(1, 1, 0); Material objMaterial = new Material(objColor, black, objColor, white, 100.0f); Material blackMaterial = new Material(objColor, black, black, objColor, 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); look.setMaterial(new Material(objColor, black, objColor, white, 100.0f)); 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); // vertexLook = redLook; Appearance objLook = new Appearance(); objLook.setMaterial(objMaterial); grayLook = objLook; final Appearance yellowLook = new Appearance(); yellowLook.setMaterial(yellowMaterial); Bounds bounds = new BoundingSphere(new Point3d(), 300); MouseRotate behavior1 = new MouseRotate(); behavior1.setTransformGroup(objTrans); objTrans.addChild(behavior1); behavior1.setSchedulingBounds(bounds); MouseWheelZoom behavior2 = new MouseWheelZoom(); behavior2.setTransformGroup(objTrans); // behavior2.setFactor(10); objTrans.addChild(behavior2); behavior2.setSchedulingBounds(bounds); MouseTranslate behavior3 = new MouseTranslate(); behavior3.setTransformGroup(objTrans); objTrans.addChild(behavior3); behavior3.setSchedulingBounds(bounds); PickTranslateBehavior ptb = new PickTranslateBehavior(objRoot, canvas, bounds, PickTool.GEOMETRY); ptb.setSchedulingBounds(bounds); // objTrans.addChild(ptb); ptb.setupCallback(new PickingCallback() { public void transformChanged(int type, TransformGroup tg) { if (tg == null) return; Transform3D t3d = new Transform3D(); tg.getTransform(t3d); // System.err.println(tg+" transformChanged \n"+t3d); Point3f p1 = new Point3f(); V v = vertexMap.getKey(tg); // Transform3D lvw = new Transform3D(); // tg.getLocalToVworld(lvw); // System.err.println("lvw = \n"+lvw); // lvw.invert(); // System.err.println("invert lvw = \n"+lvw); Point3f p0 = layout.transform(v); // Transform3D vwip = new Transform3D(); // canvas.getVworldToImagePlate(vwip); // System.err.println("vwip=\n"+vwip); // t3d.mul(lvw); t3d.transform(p1); // scale.transform(p1); System.err.println( "change location for vertex " + v + ", transformGroup " + tg + " from " + p0 + " to " + p1); // p1.set(p1.getX()*2,p1.getY()*2,p1.getZ()*2); // layout.setLocation(v, p1); } }); PickSphereBehavior psb = new PickSphereBehavior(objRoot, canvas, bounds); PickVertexBehavior pvb = new PickVertexBehavior(objRoot, canvas, bounds, renderContext.getPickedVertexState()); objTrans.addChild(pvb); pvb.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { for (V v : graph.getVertices()) { VertexGroup<V> vg = vertexMap.get(v); Appearance look = redLook; if (renderContext.getPickedVertexState().isPicked(v)) { look = yellowLook; } Node node = vg.getShape(); if (node instanceof Primitive) { ((Primitive) node).setAppearance(look); } } } }); //Shine it with two colored lights. Color3f lColor1 = new Color3f(.5f, .5f, .5f); Color3f lColor2 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lDir2 = new Vector3f(-1.0f, 0.0f, -1.0f); DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2); AmbientLight ambient = new AmbientLight(lColor1); lgt2.setInfluencingBounds(bounds); ambient.setInfluencingBounds(bounds); objRoot.addChild(lgt2); objRoot.addChild(ambient); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); // VisRunner runner = new VisRunner((IterativeContext)elayout); // runner.relax(); return objRoot; }
From source file:OrientedTest.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objScale = new TransformGroup(); Transform3D textMat = new Transform3D(); // Assuming uniform size chars, set scale to fit string in view textMat.setScale(1.2 / sl);/*from w ww . ja v a 2 s .co m*/ objScale.setTransform(textMat); // 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); objRoot.addChild(objTrans); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Appearance apText = new Appearance(); Material m = new Material(); m.setLightingEnable(true); apText.setMaterial(m); Appearance apEarth = new Appearance(); Material mm = new Material(); mm.setLightingEnable(true); apEarth.setMaterial(mm); Appearance apStone = new Appearance(); apStone.setMaterial(mm); // create 3D text Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion()); Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, 3.0f, 0.0f)); OrientedShape3D textShape = new OrientedShape3D(); textShape.setGeometry(txt); textShape.setAppearance(apText); textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f); objScale.addChild(textShape); // Create a simple shape leaf node, add it to the scene graph. Transform3D cubeMat = new Transform3D(); TransformGroup cubeTrans = new TransformGroup(cubeMat); cubeMat.set(new Vector3d(0.9, 0.0, -1.0)); cubeTrans.setTransform(cubeMat); cubeTrans.addChild(new ColorCube(0.3)); objTrans.addChild(cubeTrans); TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this); if (stoneTex != null) apStone.setTexture(stoneTex.getTexture()); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); apStone.setTextureAttributes(texAttr); Transform3D coneMat = new Transform3D(); TransformGroup coneTrans = new TransformGroup(coneMat); coneMat.set(new Vector3d(0.0, 0.0, 0.0)); coneTrans.setTransform(coneMat); coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone)); objTrans.addChild(coneTrans); TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this); if (earthTex != null) apEarth.setTexture(earthTex.getTexture()); apEarth.setTextureAttributes(texAttr); Transform3D cylinderMat = new Transform3D(); TransformGroup cylinderTrans = new TransformGroup(cylinderMat); cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0)); cylinderTrans.setTransform(cylinderMat); cylinderTrans.addChild( new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth)); objTrans.addChild(cylinderTrans); objTrans.addChild(objScale); // 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.1f, 0.1f, 0.1f); 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); apText.setMaterial(mm); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); 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);/* ww w .j a v a 2s. 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:TextureTest.java
protected TransformGroup createTextureGroup(String szFile, double x, double y, double z, boolean bWireframe) { TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, y, z)); tg.setTransform(t3d); Shape3D texShape = createTextureGeometry(szFile, bWireframe); if (texShape != null) tg.addChild(texShape);/*from w w w. jav a 2 s .c o m*/ return tg; }
From source file:SimpleGame.java
/** * Creates the duck. This loads the two duck geometries from the files * 'duck.obj' and 'deadduck.obj' and loads these into a switch. The access * rights to the switch are then set so we can write to this switch to swap * between the two duck models. It also creates a transform group and an * interpolator to move the duck.//from ww w . j a v a 2 s .co m * * @return BranchGroup with content attached. */ protected BranchGroup buildDuck() { BranchGroup theDuck = new BranchGroup(); duckSwitch = new Switch(0); duckSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); ObjectFile f1 = new ObjectFile(); ObjectFile f2 = new ObjectFile(); Scene s1 = null; Scene s2 = null; try { s1 = f1.load("duck.obj"); s2 = f2.load("deadduck.obj"); } catch (Exception e) { System.exit(1); } TransformGroup duckRotXfmGrp = new TransformGroup(); Transform3D duckRotXfm = new Transform3D(); Matrix3d duckRotMat = new Matrix3d(); duckRotMat.rotY(Math.PI / 2); duckRotXfm.set(duckRotMat, new Vector3d(0.0, 0.0, -30.0), 1.0); duckRotXfmGrp.setTransform(duckRotXfm); duckRotXfmGrp.addChild(duckSwitch); duckSwitch.addChild(s1.getSceneGroup()); duckSwitch.addChild(s2.getSceneGroup()); TransformGroup duckMovXfmGrp = new TransformGroup(); duckMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); duckMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); duckMovXfmGrp.addChild(duckRotXfmGrp); duckAlpha = new Alpha(-1, 0, 0, 3000, 0, 0); Transform3D axis = new Transform3D(); PositionInterpolator moveDuck = new PositionInterpolator(duckAlpha, duckMovXfmGrp, axis, -30.0f, 30.0f); moveDuck.setSchedulingBounds(bounds); theDuck.addChild(moveDuck); theDuck.addChild(duckMovXfmGrp); return theDuck; }
From source file:Human1.java
BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a TransformGroup to scale the scene down by 3.5x // TODO: move view platform instead of scene using orbit behavior TransformGroup objScale = new TransformGroup(); Transform3D scaleTrans = new Transform3D(); scaleTrans.set(1 / 3.5f); // scale down by 3.5x objScale.setTransform(scaleTrans); objRoot.addChild(objScale);//from ww w . ja v a 2 s . c o m // Create a TransformGroup and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // the mouse behaviors 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); // Add the primitives to the scene createHuman(); // the human objTrans.addChild(Human_body); BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0); Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f)); bg.setApplicationBounds(bounds); objTrans.addChild(bg); // set up the mouse rotation behavior MouseRotate mr = new MouseRotate(); mr.setTransformGroup(objTrans); mr.setSchedulingBounds(bounds); mr.setFactor(0.007); objTrans.addChild(mr); // 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); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 1.0f); Vector3f light1Direction = new Vector3f(0.0f, -0.2f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); return objRoot; }
From source file:PickCollisionTest.java
protected void addSphere(BranchGroup bg, double x, double y, double z, Vector3d incVector, String name) { Appearance app = new Appearance(); TransformGroup sphereTg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, y, z)); sphereTg.setTransform(t3d); sphereTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); sphereTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); sphereTg.addChild(new Sphere(1, app)); bg.addChild(sphereTg);/*from ww w . ja va 2s. c om*/ recursiveSetUserData(sphereTg, name); // create the collision behaviour CollisionBehavior collisionBehavior = new CollisionBehavior(bg, sphereTg, app, new Vector3d(x, y, z), incVector); collisionBehavior.setSchedulingBounds(getApplicationBounds()); bg.addChild(collisionBehavior); }
From source file:PlatformTest.java
ViewerAvatar createViewerAvatar(String szText, Color3f objColor) { ViewerAvatar viewerAvatar = new ViewerAvatar(); // rotate the Cone so that it is lying down and // points sharp-end towards the Viewer's field of view. TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setEuler(new Vector3d(Math.PI / 2.0, Math.PI, 0)); tg.setTransform(t3d); // create appearance and material for the Cone Appearance app = new Appearance(); Color3f black = new Color3f(0.4f, 0.2f, 0.1f); app.setMaterial(new Material(objColor, black, objColor, black, 90.0f)); // create the Primitive and add to the parent BranchGroup tg.addChild(new Cone(1, 3, Primitive.GENERATE_NORMALS, app)); viewerAvatar.addChild(tg);/*from ww w. j a v a2 s . c om*/ return viewerAvatar; }
From source file:PickCollisionTest.java
protected void addCube(BranchGroup bg, double x, double y, double z, double sx, double sy, double sz, String name, boolean wireframe) { // create four ColorCube objects TransformGroup cubeTg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, y, z)); t3d.setScale(new Vector3d(sx, sy, sz)); cubeTg.setTransform(t3d); ColorCube cube = new ColorCube(1.0); // we have to make the front face wireframe // or we can't see inside the box! if (wireframe) { Appearance app = new Appearance(); app.setPolygonAttributes(/*from w w w .j av a 2 s . com*/ new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0)); cube.setAppearance(app); } cubeTg.addChild(cube); recursiveSetUserData(cubeTg, name); bg.addChild(cubeTg); }