Hello!

All my objects that I create tend to be very angular and not so smooth that
I would like. Please just take a look at the example code below that are
ready to be lounched.

Especialy the spheres, they tend to be very full of edges.

Is it possible to set any flag to indicate a smoother rendering or is it
impossible to do that with Java3D?

Perhaps the only soulition is to create a sphere in a 3D-program to get a
smoother look for a sphere?

If it is possible to get it smoother in Java3D, will it decrease the
rendering performance?

Hope for some answers.

BTW please look at my previous question about SpotLight.

Best regards
Fredrik

The code:
import java.applet.*;
import java.awt.*;
import java.awt.Frame;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.behaviors.keyboard.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.loaders.*;
import java.io.*;

import java.util.*;

public class TestShape extends Applet
{
       Canvas3D canvas3D;
       SimpleUniverse simpleUniverse;

       public void init()
       {
               long start = System.currentTimeMillis();
               setLayout(new BorderLayout());
               GraphicsConfiguration config = 
SimpleUniverse.getPreferredConfiguration();
               canvas3D = new Canvas3D(config);
               add("Center", canvas3D);
               simpleUniverse = new SimpleUniverse(canvas3D);

               simpleUniverse.addBranchGraph( addLight() );

               //Light middle
               Transform3D transform3D = new Transform3D();
               transform3D.set( new Vector3d( 0.0, -1.25, -10.0 ) );
               GasLight gasLight = new GasLight( transform3D );
               BranchGroup branchGroup = gasLight;

               simpleUniverse.addBranchGraph( branchGroup );

               long end = System.currentTimeMillis();
               System.out.println((end-start)/1000);
       }

       private BranchGroup addLight()
       {
               BranchGroup branchGroup = new BranchGroup();
               BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),
100.0);

               AmbientLight ambientLight = new AmbientLight(new Color3f(1f, 1f, 1f));
               ambientLight.setInfluencingBounds(bounds);

               DirectionalLight directionalLight = new DirectionalLight(new Color3f(1f,
1f, 1f), new Vector3f( 0.0f, 0.0f, -1.0f ));
               directionalLight.setInfluencingBounds(bounds);

               branchGroup.addChild(ambientLight);
               branchGroup.addChild(directionalLight);

               branchGroup.compile();
               return branchGroup;
       }

       public static void main(String[] args)
       {
               Frame frame = new MainFrame(new TestShape(), 400, 400);
       }
}

class GasLight extends BranchGroup
{
       public GasLight(Transform3D transform3D)
       {
               TransformGroup holeTransformGroup = createTransformGroup();
               holeTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
               holeTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
               holeTransformGroup.setTransform(transform3D);
               setCapability(BranchGroup.ALLOW_CHILDREN_READ );

       addChild( holeTransformGroup );

       compile();
       }

       public TransformGroup createTransformGroup()
       {
               TransformGroup holeTransformGroup = new TransformGroup();
               Transform3D transform3D = new Transform3D();

               //LowerCylinder
               TransformGroup lowerCylinder = new TransformGroup();
               transform3D.setTranslation( new Vector3d( 0.0, 0.5, 0.0 ) );
               lowerCylinder.setTransform(transform3D);
               lowerCylinder.addChild(new Cylinder(0.2f, 1.0f));

               //UpperCylinder
               TransformGroup upperCylinder = new TransformGroup();
               transform3D.setTranslation( new Vector3d( 0.0, 2.0, 0.0 ) );
               upperCylinder.setTransform(transform3D);
               upperCylinder.addChild(new Cylinder(0.1f, 2.0f));

               Appearance appearance = new Appearance();
               ColoringAttributes coloringAttributes = new ColoringAttributes(new
Color3f(1.0f, 1.0f, 1.0f), ColoringAttributes.FASTEST);
               appearance.setColoringAttributes(coloringAttributes);

               //LightBulb
               TransformGroup lightBulb = new TransformGroup();
               transform3D.setTranslation( new Vector3d( 0.0, 3.0, 0.0) );
               lightBulb.setTransform(transform3D);
               Sphere lightBulbSphere = new Sphere(0.3f);
               lightBulbSphere.setAppearance(appearance);
               lightBulb.addChild(lightBulbSphere);

               //Top
               TransformGroup top = new TransformGroup();
               transform3D.setTranslation( new Vector3d( 0.0, 3.3, 0.0 ) );
               top.setTransform(transform3D);
               top.addChild(new Cone(0.4f, 0.2f));

               holeTransformGroup.addChild(lowerCylinder);
               holeTransformGroup.addChild(upperCylinder);
               holeTransformGroup.addChild(lightBulb);
               holeTransformGroup.addChild(top);
               holeTransformGroup.addChild(createSpotLight());

               return holeTransformGroup;
       }

       private SpotLight createSpotLight()
       {
               BoundingSphere boundingSphere = new BoundingSphere( new Point3d(0.0, 0.0
,0.0), 0.5);
               Point3f pos = new Point3f(0.0f, 3.0f, 0.0f);
       float spread = 0.5f;
       float concentration = 50.0f;

       SpotLight spotLight = new SpotLight();
       spotLight.setDirection(new Vector3f( 0.0f, -1.0f, 0.0f ));
       spotLight.setInfluencingBounds(boundingSphere);
       spotLight.setPosition(pos);
       spotLight.setSpreadAngle(spread);
       spotLight.setConcentration(concentration);
       return spotLight;
   }

   public Appearance createMatAppear()
   {
       Appearance appear = new Appearance();
       Material material = new Material();
       material.setDiffuseColor(new Color3f(0.5f, 0.5f, 0.5f));
       material.setSpecularColor(new Color3f(0.8f, 0.8f, 0.8f));
       material.setShininess(10.0f);
       appear.setMaterial(material);

       return appear;
   }
}

_________________________________________________________________
Lättare att hitta drömresan med MSN Resor http://www.msn.se/resor/

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to