Un texte 3D
RETOUR
import java.awt.*; import java.applet.Applet; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; public class SimpleText3D extends Applet { public BranchGroup createSceneGraph(SimpleUniverse u) { BranchGroup objRoot = new BranchGroup(); BoundingSphere bounds; bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0); Vector3f ldir = new Vector3f(1.0F,1.0F,-1.0F); Color3f lcouldl = new Color3f(1.0F,1.0F,1.0F); DirectionalLight dl = new DirectionalLight(lcouldl,ldir); dl.setInfluencingBounds(bounds); objRoot.addChild(dl); Color3f lcoulal = new Color3f(0.3F,0.3F,0.1F); AmbientLight al = new AmbientLight(lcoulal); al.setInfluencingBounds(bounds); objRoot.addChild(al); Font3D f3d = new Font3D(new Font("TestFont",Font.PLAIN,1), new FontExtrusion()); Text3D txt = new Text3D(f3d,new String("IUP Info"), new Point3f(-1.8f,-0.35f,-3.0f)); Shape3D sph = new Shape3D(); Appearance a = new Appearance(); Material m = new Material(); m.setDiffuseColor(0.1f,0.1f,0.9f); m.setSpecularColor(1.0f,0.0f,0.0f); m.setAmbientColor(0.9f,0.9f,0.9f); m.setShininess(25.0f); a.setMaterial(m); sph.setGeometry(txt); sph.setAppearance(a); objRoot.addChild(sph); objRoot.compile(); return objRoot; } public SimpleText3D() { setLayout(new BorderLayout()); GraphicsConfiguration config; config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center",c); SimpleUniverse u = new SimpleUniverse(c); BranchGroup scene = createSceneGraph(u); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); } public static void main(String[] args) { new MainFrame(new SimpleText3D(),500,160); } }
Remarques,erreurs
janey@lib.univ-fcomte.fr