Hi all,

 I search to change dynamically Text3D when picking on screen.
At first I wanted to use the function TextLettre.setString("X")
 but like nothing happened, I talked with java3d-beta and they said me
it was a bug.
(I send my code to let you understand what I intend to do).

Instead of waiting for the new version of java3d, perhaps there is
another way to change live Text3D.
have you a idea ?

Any help will be very useful.
    Thanks a lot,

    Kristell



/*
 * FourByFour.java 13/01/99
 */

import java.applet.Applet;
import java.awt.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.behaviors.picking.*;
import java.util.BitSet;
import com.sun.j3d.utils.applet.MainFrame;

public class FourByFour extends Applet
{
   int width, height;              // Size of the graphics window in
pixels
   Canvas3D canvas3D;              // 3D rendering canvas
   Panel c_container;              // Container to hold the canvas
   private Group group;
   String letter; // holds the key pressed
   private String fontName = "TestFont";
   private String textString = null;
   private Appearance whiteApp;
   private Material whiteMat;
   Lettres lettres;

   public void init()
 {

      width  = 350;
      height = 350;
      setBackground(new Color(200, 200, 200));

 lettres = new Lettres();

      canvas3D = new Canvas3D(null);
      canvas3D.setSize(width, height);
      canvas3D.setLocation(5, 5);

      BranchGroup scene3D = createScene3D();

      SimpleUniverse universe = new SimpleUniverse(canvas3D);
      universe.addBranchGraph(scene3D);

      TransformGroup tg =
universe.getViewingPlatform().getViewPlatformTransform();
      Transform3D transform = new Transform3D();
      transform.set(65.f, new Vector3f(0.0f, 0.0f, 400.0f));
      tg.setTransform(transform);

      c_container = new Panel();
      c_container.setSize(360, 360);
      c_container.setLocation(0, 0);
      c_container.setVisible(true);
      c_container.setLayout(null);
      add(c_container);
      c_container.add(canvas3D);
      setLayout(null);
   }

   public BranchGroup createScene3D()
 {
      Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
      Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
      Color3f specular  = new Color3f(1.0f, 1.0f, 1.0f);

      whiteMat= new Material(white, white, white, specular, 100.f);
      whiteMat.setLightingEnable(true);
      whiteApp = new Appearance();
      whiteApp.setMaterial(whiteMat);

      BranchGroup branchGroup = new BranchGroup();

 TransformGroup objScale = new TransformGroup();
 Transform3D t3d = new Transform3D();
 t3d.setScale(2.5);
 objScale.setTransform(t3d);
 branchGroup.addChild(objScale);

      BoundingSphere bounds = new BoundingSphere(new
Point3d(0.0,0.0,0.0), 1000.0);
      BoundingLeaf boundingLeaf = new BoundingLeaf(bounds);
      objScale.addChild(boundingLeaf);

      Background bg = new Background(bgColor);
      bg.setApplicationBounds(bounds);
      objScale.addChild(bg);

      AmbientLight ambLight = new AmbientLight(white);
      ambLight.setInfluencingBounds(bounds);
      objScale.addChild(ambLight);

      Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f);
      DirectionalLight dirLight = new DirectionalLight(white, dir);
      dirLight.setInfluencingBounds(bounds);
      objScale.addChild(dirLight);

 TransformGroup objTrans = new TransformGroup();
      objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
      objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
 objScale.addChild(objTrans);
 objTrans.addChild(lettres.getChild());
 lettres.setTransformGroup(objTrans);

 MouseRotate behavior3 = new MouseRotate();
 behavior3.setTransformGroup(objTrans);
 objTrans.addChild(behavior3);
 behavior3.setSchedulingBounds(bounds);

 SourisBehavior behavior = new SourisBehavior(canvas3D, branchGroup,
bounds, lettres);

 branchGroup.compile();

      return branchGroup;
    }
public class Lettres extends Object
 {
   private Point3f point[];
   private Switch posSwitch;
   private BitSet posMask;
   private Group group;
   private Material whiteMat;
   private Appearance whiteApp;
   private TransformGroup tgroup;
   private Shape3D sh;
   private String fontName = "TestFont";
   private String tabString[];

   public Lettres()
 {
      // Define colors for lighting
     Color3f white     = new Color3f(1.0f, 1.0f, 1.0f);
      Color3f black     = new Color3f(0.0f, 0.0f, 0.0f);
      Color3f ambWhite  = new Color3f(0.3f, 0.3f, 0.3f);
      Color3f specular  = new Color3f(1.0f, 1.0f, 1.0f);

      // Create the white appearance node
      whiteMat= new Material(ambWhite, black, white, specular, 100.f);
      whiteMat.setLightingEnable(true);
      whiteApp = new Appearance();
      whiteApp.setMaterial(whiteMat);

 point = new Point3f[2];
 tabString = new String[2];

 tabString[0]="A";
 tabString[1]="B";

 point[0]=new Point3f( 16.5f, -23.5f, 25.0f);
 point[1]=new Point3f( -16.5f, 23.5f, 25.0f);

      posSwitch = new Switch(Switch.CHILD_MASK);
      posSwitch.setCapability(Switch.ALLOW_SWITCH_READ);
      posSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

      posMask = new BitSet();

 for (int i=0 ; i<2 ; i++)
 {
  String key = String.valueOf(i);
  Transform3D transform3D = new Transform3D();
  TransformGroup transformGroup = new TransformGroup(transform3D);
  transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
  transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
  transformGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
  Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 30), new
FontExtrusion());
  Text3D txt = new Text3D(f3d, tabString[i], point[i]);
  txt.setCapability(Geometry.ALLOW_INTERSECT);
  txt.setCapability(Text3D.ALLOW_STRING_READ);
  txt.setCapability(Text3D.ALLOW_STRING_WRITE);
  Shape3D sh = new Shape3D();
  sh.setGeometry(txt);
  sh.setAppearance(whiteApp);
  sh.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
  sh.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
  sh.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
  sh.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
  sh.setCapability(Shape3D.ENABLE_PICK_REPORTING);
  transformGroup.addChild(sh);
  posSwitch.addChild(transformGroup);
  posMask.set(i);
 }

      posSwitch.setChildMask(posMask);
      group = new Group();
      group.addChild(posSwitch);
    }


   public void setTransformGroup(TransformGroup transformGroup)
 {
      tgroup = transformGroup;
    }

   public Group getChild()
 {
      return group;
    }
}


public class SourisBehavior extends PickMouseBehavior
{
  Shape3D oldShape = null;
  Lettres lettres;

  public SourisBehavior(Canvas3D canvas, BranchGroup root,Bounds bounds,
Lettres lettres)
 {
      super(canvas, root, bounds);
      this.setSchedulingBounds(bounds);
 this.lettres = lettres;
      root.addChild(this);
   }

    public void updateScene(int xpos, int ypos)
 {
 Shape3D shape;
      shape = (Shape3D) pickScene.pickNode(pickScene.pickClosest(xpos,
ypos,PickObject.USE_GEOMETRY),PickObject.SHAPE3D);

 System.out.println("shape : " + shape);

 if (shape != null)
  {
  Geometry text = shape.getGeometry();
  Text3D TextLettre = (Text3D) text;
  TextLettre.setString("X");
 // text = (Text3D) TextLettre;
 // shape.setGeometry(text);
  }
 }
}


    // The following allows FourByFour to be run as an application
    // as well as an applet
    //
    public static void main(String[] args) {
 new MainFrame(new FourByFour(), 360, 360);
    }

}


=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to