List of usage examples for javax.media.j3d Appearance Appearance
public Appearance()
From source file:TextureImage.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 w ww . j a va 2 s . co m // Create appearance object for textured cube Appearance app = new Appearance(); Texture tex = new TextureLoader(texImage, this).getTexture(); app.setTexture(tex); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); app.setTextureAttributes(texAttr); // Create textured cube and add it to the scene graph. Box textureCube = new Box(0.4f, 0.4f, 0.4f, Box.GENERATE_TEXTURE_COORDS, app); objTrans.addChild(textureCube); // 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, 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); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:SimpleCone.java
/** * This simply builds the shape using the Cone utility class. * /*from w ww. j ava 2 s .c om*/ * @param Node * that the is the Cone created */ protected Node buildShape() { return new Cone(1.0f, 2.0f, Cone.GENERATE_NORMALS, new Appearance()); }
From source file:LightScopeApp.java
Appearance createMaterialAppearance(Color3f color) { Appearance appear = new Appearance(); Material material = new Material(); material.setDiffuseColor(color);/*from www . jav a2 s. c o m*/ material.setShininess(50.0f); appear.setMaterial(material); return appear; }
From source file:Text3DApp.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); Transform3D t3D = new Transform3D(); t3D.setTranslation(new Vector3f(0.0f, 0.0f, -3.0f)); TransformGroup objMove = new TransformGroup(t3D); objRoot.addChild(objMove);// ww w .j a v a 2s .c om // Create the transform group node and initialize it to the // identity. Add it to the root of the subgraph. TransformGroup objSpin = new TransformGroup(); objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objMove.addChild(objSpin); Appearance textAppear = new Appearance(); ColoringAttributes textColor = new ColoringAttributes(); textColor.setColor(1.0f, 0.0f, 0.0f); textAppear.setColoringAttributes(textColor); textAppear.setMaterial(new Material()); // Create a simple shape leaf node, add it to the scene graph. Font3D font3D = new Font3D(new Font("Helvetica", Font.PLAIN, 1), new FontExtrusion()); Text3D textGeom = new Text3D(font3D, new String("3DText")); textGeom.setAlignment(Text3D.ALIGN_CENTER); Shape3D textShape = new Shape3D(); textShape.setGeometry(textGeom); textShape.setAppearance(textAppear); objSpin.addChild(textShape); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Alpha rotationAlpha = new Alpha(-1, 10000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin); // a bounding sphere specifies a region a behavior is active // create a sphere centered at the origin with radius of 100 BoundingSphere bounds = new BoundingSphere(); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); DirectionalLight lightD = new DirectionalLight(); lightD.setInfluencingBounds(bounds); lightD.setDirection(new Vector3f(0.0f, 0.0f, -1.0f)); lightD.setColor(new Color3f(1.0f, 0.0f, 1.0f)); objMove.addChild(lightD); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(bounds); objMove.addChild(lightA); return objRoot; }
From source file:SimpleWire.java
/** * This constructs a cube using the Box utility class. The attributes are * set so that the lines are drawn and not the faces. * /* w w w . j a v a2 s . co m*/ * @return Node that is the cube */ protected Node buildShape() { Appearance app = new Appearance(); //Create the polygon attributes PolygonAttributes polyAttr = new PolygonAttributes(); //Set them so that the draw mode is polygon line polyAttr.setPolygonMode(PolygonAttributes.POLYGON_LINE); //Use these in the appearance app.setPolygonAttributes(polyAttr); return new Box(1.0f, 1.0f, 1.0f, app); }
From source file:SimpleMouse.java
/** * Build the content branch for the scene graph * /*from w w w. j a va2 s. c o m*/ * @return BranchGroup that is the root of the content */ protected BranchGroup buildContentBranch() { Appearance app = 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; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); Box cube = new Box(2.0f, 2.0f, 2.0f, app); BranchGroup contentBranch = new BranchGroup(); addLights(contentBranch); //Create the transform groups that will be //affected by the mouse utiltities TransformGroup spinGroup = new TransformGroup(); TransformGroup zoomGroup = new TransformGroup(); TransformGroup moveGroup = new TransformGroup(); //Set the capabilities of the groups so that we can //manipulate them spinGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); spinGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); zoomGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); zoomGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); //Create and use the rotation utility MouseRotate mouseSpin = new MouseRotate(); mouseSpin.setTransformGroup(spinGroup); contentBranch.addChild(mouseSpin); mouseSpin.setSchedulingBounds(bounds); //Create and use the zoom utility MouseZoom mouseSize = new MouseZoom(); mouseSize.setTransformGroup(zoomGroup); contentBranch.addChild(mouseSize); mouseSize.setSchedulingBounds(bounds); //Create and use the translation utility MouseTranslate mouseMove = new MouseTranslate(); mouseMove.setTransformGroup(moveGroup); contentBranch.addChild(mouseMove); mouseMove.setSchedulingBounds(bounds); //Put it all together spinGroup.addChild(cube); moveGroup.addChild(spinGroup); zoomGroup.addChild(moveGroup); contentBranch.addChild(zoomGroup); return contentBranch; }
From source file:PickText3DBounds.java
public BranchGroup createSceneGraph(Canvas3D canvas) { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Transform3D t;/* w ww. ja v a 2s . co m*/ // 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); 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 Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); Material m = new Material(objColor, eColor, objColor, sColor, 100.0f); Appearance a = new Appearance(); m.setLightingEnable(true); a.setMaterial(m); Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 1), new FontExtrusion()); Text3D txt = new Text3D(f3d, new String("TEXT3D"), new Point3f(-2.0f, 0.0f, 0.0f)); // txt.setCapability(Geometry.ALLOW_INTERSECT); Shape3D s3D = new Shape3D(); s3D.setGeometry(txt); s3D.setAppearance(a); // Create a 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); spinTg.addChild(s3D); objScale.addChild(spinTg); // Create the transform group node for the each light and initialize // it to the identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add them to the root // of the subgraph. // Create transformations for the positional lights t = new Transform3D(); Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0); t.set(lPos1); TransformGroup l1Trans = new TransformGroup(t); l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); l1Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objScale.addChild(l1Trans); t = new Transform3D(); Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0); t.set(lPos2); TransformGroup l2Trans = new TransformGroup(t); l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); l2Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objScale.addChild(l2Trans); // Create Geometry for point lights ColoringAttributes caL1 = new ColoringAttributes(); ColoringAttributes caL2 = new ColoringAttributes(); caL1.setColor(lColor1); caL2.setColor(lColor2); Appearance appL1 = new Appearance(); Appearance appL2 = new Appearance(); appL1.setColoringAttributes(caL1); appL2.setColoringAttributes(caL2); l1Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS, 15, appL1)); l2Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS, 15, appL2)); // Create lights AmbientLight aLgt = new AmbientLight(alColor); Light lgt1; Light lgt2; Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f); Point3f atten = new Point3f(1.0f, 0.0f, 0.0f); lgt1 = new PointLight(lColor1, lPoint, atten); lgt2 = new PointLight(lColor2, lPoint, atten); // Set the influencing bounds aLgt.setInfluencingBounds(bounds); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); // Add the lights into the scene graph objScale.addChild(aLgt); l1Trans.addChild(lgt1); l2Trans.addChild(lgt2); PickRotateBehavior behavior1 = new PickRotateBehavior(objRoot, canvas, bounds); behavior1.setMode(PickTool.BOUNDS); objRoot.addChild(behavior1); PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, canvas, bounds); behavior2.setMode(PickTool.BOUNDS); objRoot.addChild(behavior2); PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds); behavior3.setMode(PickTool.BOUNDS); objRoot.addChild(behavior3); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:BasicConstruct.java
/** * Adds a box to the universe/* w w w . j av a2s . co m*/ * * @param x * The x dimension of the box * @param y * The y dimension of the box * @param z * The z dimension of the box */ public void addBox(float x, float y, float z, Color3f diffuse, Color3f spec) { // Add a box with the given dimension // First setup an appearance for the box Appearance app = new Appearance(); Material mat = new Material(); mat.setDiffuseColor(diffuse); mat.setSpecularColor(spec); mat.setShininess(5.0f); app.setMaterial(mat); Box box = new Box(x, y, z, app); // Create a TransformGroup and make it the parent of the box TransformGroup tg = new TransformGroup(); tg.addChild(box); // Then add it to the rootBranchGroup rootBranchGroup.addChild(tg); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); MouseRotate myMouseRotate = new MouseRotate(); myMouseRotate.setTransformGroup(tg); myMouseRotate.setSchedulingBounds(new BoundingSphere()); rootBranchGroup.addChild(myMouseRotate); MouseTranslate myMouseTranslate = new MouseTranslate(); myMouseTranslate.setTransformGroup(tg); myMouseTranslate.setSchedulingBounds(new BoundingSphere()); rootBranchGroup.addChild(myMouseTranslate); MouseZoom myMouseZoom = new MouseZoom(); myMouseZoom.setTransformGroup(tg); myMouseZoom.setSchedulingBounds(new BoundingSphere()); rootBranchGroup.addChild(myMouseZoom); }
From source file:SimpleSphere.java
protected BranchGroup buildContentBranch() { BranchGroup contentBranch = new BranchGroup(); Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); // rotateCube.set(new AxisAngle4d(1.0,0.0,0.0,Math.PI/2.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); rotationGroup.addChild(new Sphere(2.0f, Sphere.GENERATE_NORMALS, 120, app)); addLights(contentBranch);//from www .j a v a 2 s .c o m return contentBranch; }
From source file:SimpleDirLight.java
/** * This build the content branch of our scene graph. It creates a transform * group so that the shape is slightly tilted to reveal its 3D shape. * //from w ww.jav a2 s.c o m * @param shape * Node that represents the geometry for the content * @return BranchGroup that is the root of the content branch */ protected BranchGroup buildContentBranch() { BranchGroup contentBranch = new BranchGroup(); Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); //Create a new appearance Appearance app = new Appearance(); //Create the colours for the material Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); //Define the shininess float shininess = 20.0f; //Set the material of the appearance app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Create and add a new sphere using the appearance rotationGroup.addChild(new Sphere(2.0f, Sphere.GENERATE_NORMALS, 120, app)); //Use the addLights function to add the lights to the branch addLights(contentBranch); //Return the root of the content branch return contentBranch; }