Raytracing a Java3D scene's View

Hi,
I have a simple Java3D modelling app, which I am trying to hook up a basic Raytracer to.
Scene Graph looks something like the following:
                 VirtualUniverse, etc
                          |
                       Locale
                          |
    ContentBranchGroup         ViewsBranchGroup
            |                          |
           ...                 TransformGroup [*]
                                       |
                                 ViewPlatform  -  ViewI have a simple mouse pan behaviour, a mouse zoom behaviour, and a mouse orbit behaviour that all modify the Transform Group marked with a [*] above, thereby changing the "camera" by which the user looks at the scene. The behaviours work very well.
I am trying to hook the raytracer up to "look" through this camera. (I have all the other raytracer stuff working)
The raytracer requires the following:
- The camera eye position
- The camera target (look at) position
- The camera up vector
I am trying to extract this information from the [*] marked TransformGroup's Transform3D object but it is very difficult. I can get the eye position using the transform3D.get(Vector3d) method.
I have tried so many ways to get the target and up vectors. I know the principles to get them but the Transform3D get() methods are to say the least, a nightmare, for me to work with. CAN ANYBODY HELP ME?
If it helps I have managed to get the Euler angles for the camera rotation (converting the rotation Quaternion)...
What next? Please...!
Thanks in advance

Yes, I understand what you are trying to do. Essentially, what it requires is that you do some linear algebra from the position and orientation of the camera object. So, you can get the following:
Camera position:
the actual point location of the camera in the virtual world:
viewTransform3D.get( Vector3f position );
Camera "look at" position:
I assume you don't actually need the point on the X-Y plane (or at least, you shouldn't), but a point along the path in which the camera points (we call the VPN, or view-plane normal). So, in essence, when you take the "look at point" and subtract the "camera position point", you get a vector in 3d space which tells you the direction the camera is pointing. Whichever one you need, you will have to calculate that. More on this in a moment.
Camera "up vector":
This is another one you will have to calculate based on the location of the camera and its current orientation. This one again is a vector based on the original "up" location (also called VUP). More on this one right now...
A good way to resolve this issue is to calculate these vectors based on two points at the beginning of your application, and use them to calcuate the camera's focus point (via VPN) and the camera's up vector. Its pretty simple and easy to implement. Basically, when you set up your camera (view platform), you set the camera position to some default location. When you set this default location, create 2 points which represent the end of the up vector and the end of the VPN, respectively. Then, whenever the transform group which contains the camera's transform is manipulated, simply take that Transform3D and use its matrix to modify the locations of your two initial points, thus giving you the end of the up vector and the end of the vpn transformed by the same transform used to rotate the camera. Then simply subract the camera's location point from each of these and you have the up vector and the vpn, ready for your ray tracer.
I've included some sample code to show you what I'm talking about. Check out the canvas' mouse listener to find the calculations for the VUP and VPN. It sounds like your implementation requires a look at Point3d, so what you could do is just take the camera's location and add some multiple of the VPN to get a look at point.
Anyway, here's the code...
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Group;
import javax.media.j3d.GraphicsConfigTemplate3D;
import javax.media.j3d.Light;
import javax.media.j3d.Material;
import javax.media.j3d.PhysicalBody;
import javax.media.j3d.PhysicalEnvironment;
import javax.media.j3d.PointLight;
import javax.media.j3d.PolygonAttributes;
import javax.media.j3d.Shape3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.View;
import javax.media.j3d.ViewPlatform;
import javax.media.j3d.TransformGroup;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.vecmath.Color3f;
import javax.vecmath.Color4f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;
* The <code>SimpleViewCalculator</code> class calculates the up vector and the
* view plane normal for a camera based on its current position and the
* transformation of two default up vector and VPN reference points.
* @version 1.0
public class SimpleViewCalculator
  extends JFrame
  // CONSTRUCTOR
   * Creates a new <code>SimpleViewCalculator</code> instance.
  public SimpleViewCalculator()
    // Create the canvas and add it to the universe.
    canvas = initializeCanvas();
    universe = new SimpleUniverse( canvas );
    // Create the content for the virtual universe.
    worldRoot = createWorldObjects();
    worldRoot.addChild( createColorCube( 0.0f, 0.0f, 0.0f, 5.0f ) );
    universe.addBranchGraph( worldRoot );
    universe.getViewingPlatform().
      setViewPlatformBehavior( createOrbitBehavior() );
    // Set the clipping distances for the view.
    universe.getViewer().getView( ).setBackClipDistance( 1000.0 );
    universe.getViewer().getView( ).setFrontClipDistance( 0.1 );  
    setCameraPosition( 0.0f,  0.0f, 50.0f );
    upPoint = new Point3d( 0.0, 1.0, 0.0 );
    lookAtPoint = new Point3d( 0.0, 0.0, -1.0 );
       this.getContentPane().setLayout(
      new BoxLayout( this.getContentPane(), BoxLayout.Y_AXIS ) );
    this.getContentPane().add( canvas );
    canvas.addMouseListener(
      new MouseAdapter()
         * The mouseClicked on this mouse listener is where the work for
         * calculating the up vector and the view plane normal.
        public void mouseClicked( MouseEvent event )
          TransformGroup viewPlatformTG =
            universe.getViewingPlatform().getViewPlatformTransform();
          Transform3D cameraT3D = new Transform3D();
          Vector3d cameraPos = new Vector3d();
          viewPlatformTG.getTransform( cameraT3D );
          cameraT3D.get( cameraPos );
          // Calculate the "up" vector.
          Point3d newUpPoint = new Point3d();
          cameraT3D.transform( upPoint, newUpPoint );
          Vector3d upVector = new Vector3d();
          upVector.x = newUpPoint.x - cameraPos.x;
          upVector.y = newUpPoint.y - cameraPos.y;
          upVector.z = newUpPoint.z - cameraPos.z;
          upVector.normalize();
          System.err.println( "new up vector = " + upVector );
          // Calculate the "vpn" or direction the camera is pointing.
          Point3d newLookAtPoint = new Point3d();
          cameraT3D.transform( lookAtPoint, newLookAtPoint );
          Vector3d vpn = new Vector3d();
          vpn.x = newLookAtPoint.x - cameraPos.x;
          vpn.y = newLookAtPoint.y - cameraPos.y;
          vpn.z = newLookAtPoint.z - cameraPos.z;
          vpn.normalize();
          System.err.println( "new view plane normal = " + vpn );
    this.setVisible( true );
    this.setSize( new Dimension( 300, 375 ) );   
  // METHODS
   * Initialize a Canvas3D with default graphics configuration for user's
   * system.
   * @return a <code>Canvas3D</code> value
  private Canvas3D initializeCanvas()
    GraphicsConfigTemplate3D tmpl = new GraphicsConfigTemplate3D( );
    GraphicsEnvironment env =
      GraphicsEnvironment.getLocalGraphicsEnvironment( );
    GraphicsDevice device = env.getDefaultScreenDevice( );
    GraphicsConfiguration config = device.getBestConfiguration( tmpl );
    Canvas3D canvas3D = new Canvas3D( config );
    return canvas3D; 
   * Create a orbit behavior for the canvas and simple universe.
  private OrbitBehavior createOrbitBehavior()
    OrbitBehavior orbit =
      new OrbitBehavior( canvas, OrbitBehavior.REVERSE_ALL );
    BoundingSphere bounds =
      new BoundingSphere( new Point3d( 0.0, 0.0, 0.0 ), 1000000000 );
    orbit.setSchedulingBounds( bounds );
    orbit.setTranslateEnable( true );
    orbit.setZoomEnable( true );
    orbit.setProportionalZoom( true );
    orbit.setReverseZoom( true );
    return orbit;
   * Create the objects that will appear in the virutal world and add them to a
   * branch group which is returned to the calling method.
   * @return a <code>BranchGroup</code> value
  private BranchGroup createWorldObjects()
    BranchGroup root = new BranchGroup();
    root.setCapability( BranchGroup.ALLOW_DETACH );
    root.setCapability( Group.ALLOW_CHILDREN_EXTEND );
    root.setCapability( Group.ALLOW_CHILDREN_READ );
    root.setCapability( Group.ALLOW_CHILDREN_WRITE );
    return root;
   * Create a color cube of <code>scale</code> size, attached to a branch group.
   * This method returns a color cube attached to that branch group.
  private BranchGroup createColorCube( float x, float y, float z, double scale )
       BranchGroup colorCubeRoot = new BranchGroup();
       colorCubeRoot.setCapability( BranchGroup.ALLOW_DETACH );
       TransformGroup colorCubeTG = new TransformGroup();
       Transform3D colorCubeT3D = new Transform3D();
       colorCubeT3D.set( new Vector3f( x, y, z ) );
       colorCubeTG.setTransform( colorCubeT3D );
       colorCubeRoot.addChild( colorCubeTG );
       ColorCube cube = new ColorCube( scale );
       colorCubeTG.addChild( cube );
       return colorCubeRoot;
   * Set the position of the camera.
  private void setCameraPosition( float x, float y, float z )
    Transform3D vt = new Transform3D();
    Point3d eye = new Point3d( x, y , z );
    Point3d  center = new Point3d( 0, 0, 0 );
    Vector3d up = new Vector3d( 0.0, 1.0, 0.0 );   
    vt.lookAt( eye, center, up );
    vt.invert( );
    vt.setTranslation( new Vector3d( eye.x, eye.y, eye.z ) );
    universe.getViewer().getViewingPlatform( ).
      getViewPlatformTransform( ).setTransform( vt );
   * Main method for application.
  public static void main( String[] args )
    new SimpleViewCalculator();     
  // ATTRIBUTES
  /** A Simple 3D virtual world. */
  private SimpleUniverse universe;
  /** Component to paint contents of virtual world. */
  private Canvas3D canvas;
  /** Allows mouse rotations, etc. */
  private OrbitBehavior orbitBehavior;
  /** View object for simple universe. */
  private View view;
  /** Branch group for adding world objects. */
  private BranchGroup worldRoot;
  /** Branch group for attaching lights. */
  private BranchGroup lightRoot;
  /** Point light for illuminating scene. */
  private PointLight pointLight;
  /** A point used to calcuate the up vector. */
  private Point3d upPoint;
  /** A point used to calculate the VPN. */
  private Point3d lookAtPoint;
}Hope that helps. You should check this on your own to make sure no mistakes were made, I didn't have too much time to test it.
Cheers,
Greg

Similar Messages

  • Java3D scenes save in VRML or X3D format

    Hi,
    I would like to know how I can save my Java3D scenes in VRML or X3D format? I have found diferents loaders to get 3D scenes from VRML/X3D to Java3D, but I need the oposite: save my 3D scenes from Java3D to VRML/X3D.
    I don't know if it is better to store the 3D scenes in VRML or X3D.
    Thanks in advance

    Hi, any of you guys able to help me with some VRML/Java I am working on. I have installed and selected the microsoft vm instead of the sun vm but still cannot get an applet connected to a VRML world. When I move the mouse over the applet rectangle I get the error message:
    "load: cannot load MyClass.class". Setting up this thing is a nightmare, any help would be much appreciated.

  • Possible to have multiple views for one scene?

    Away3D allows multiple Views to be created for one Scene, allowing different camera positions for the same geometry.
    Can Proscenium support this? I've been banging my head against a brick wall for a while now...
    Joe

    Hi Kopaacabana,
    (I  feel like I'm in one of those post-apocalyptic scenes where the last two humans left on earth finally meet.....)
    Thanks for answering!
    Yes, I've actually got two cameras quite happily working in the scene, the problem is that I need to re-use the geometry for the scene in two windows, or at least, two separate parts of one window simultaneously. Away3D can do it very easily, where one sets up a 'View', which has a 'Scene' it views. With Proscenium it seems that the whole thing is tied up with an Instance3D, which is fine for one camera, but the scene nodes seem tied up as children of some root scene node. I've tried assigning the scene data as a child of two instances of BasicScene (hacking the stage3ds[number] to be different for each), but that causes an exception.
    Just changing the activeCamera changes the view to the new camera, where I actually need to be able to render to two windows/screen areas from one set of geometry.
    I would have hoped that the paradigm would have been 'here is some geometry, lights, etc., now do with it what you will'
    Adobe, are you there to help us out, like, anyone at all? Are we wasting our time with this?
    Joe

  • Java scene graph

    I'm been trying to find a utility that can parse through my java 3D code and create the scene graph for the code, but I've had no luck in finding such a program. Does anyone know about such program ?
    If the above program doesnt exist, can anyone recommend a editor program for java 3d that contains all the different symbols to make it easier to draw the scene graph myself.
    Thanks for any help.

    You might find a texchnique I am employing for turn X3D into BranchGroups in Java3D. I have it at sourceforge.
    http://cvs.sourceforge.net/viewcvs.py/mathml-x/mathml-x/stylesheets/X3D2Java3D.xsl?rev=1.4&view=markup
    The xsl transforms to source code that is a part of Java3D scene graph and can be hooked into a viewer where the branches come from multiple x3d documents. After it is done once and compiled it doesn't need compiling again until a X3D document changes. Then only the one with the change. This is surprisingly fast and can produce only needed code to go along with for example an applet. The applet doesn't require a big engine.

  • Adding text to java3d canvas

    Hi,
    I have a java3d program running.Now in my running java3d program in the java3d scene i have to draw some lines by dragging the mouse (I am able to do that)....then at any point on some event i should be able to add text (say "these to lines are parallel")..
    Can you explain or give me a working example which has the similar functionality.This will be a great help. As we are new to java3d technology.this is very urgent.Thanks in advance
    shyam

    Try this:
    import java.awt.Font;
    import. javax.vecmath.Color3f;
    int size= 120;
    Text2D textObject = new Text2D("These two lines are parallel", new Color3f(1f, 1f, 1f),
    "Serif", size, Font.BOLD);
    yourTranslationGroup.addChild(textObject);
    Note: you may have to add a rotation, to make sure the text us oriented such that it's perpendicular to the camera.
    Cheers,
    -jeroen

  • How do i add text to the screen in java3d

    I have tried overiding the jpanel, but the paint and paintcomponents are not called.
    Is their a way i can draw directly to the screen, while using java3d in the background.

    That would be correct- if you want text in your Canvas3D it has to be added to the Java3D scene. Have you looked at the Text2D object?

  • Adding Text to Java3d

    HI ,
    In my application i need to add text in my java3d scene at the runtime at any no of places. How
    can i acheive that. Somebody suggested me of Overlays.I dont know what is that actually (I am learning that actually)..but can somebody help me in this problem. Any example or url will be really appriciable.
    Thanks
    Akhil Nagpal

    Hi,
    I tried to add the text using the same piece of code at the place where i used to add straight lines.
    The piece of code is exactly same as urs.
    Shape3D tmpShape3D = new Shape3D();
    PolygonAttributes tmpPolygonAttributes = new PolygonAttributes();
    Appearance tmpAppearance = null;
    Transform3D tmpTransform3D = null;
    tmpShape3D = new Text2D("Hi ABCDEFGHIJKLMNOPQRSTUVWXYZ", new Color3f (Color.red), "Arial", 30, Font.BOLD);
    tmpAppearance = tmpShape3D.getAppearance();
    tmpPolygonAttributes.setCullFace(PolygonAttributes.CULL_NONE);
    tmpAppearance.setPolygonAttributes(tmpPolygonAttributes);
    tmpTransform3D = new Transform3D();
    tmpTransform3D.setScale(0.5f);
    tmpTransform3D.setTranslation(new Vector3f(1.0f, 1.0f, 0.0f));
    TransformGroup tmpSingleComment = new TransformGroup(tmpTransform3D);
    tmpSingleComment.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
    tmpSingleComment.addChild(tmpShape3D);
    bgRed = new BranchGroup();
    bgRed.addChild(tmpSingleComment);
    bgRed.setCapability(BranchGroup.ALLOW_DETACH);
    bgRed.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    bgRed.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
    bgRed.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    transsceneWF.addChild(bgRed);
    Here every time i have to create a new BranchGroup (bgRed) for each Text i add. Earlier in this place i was adding my lines objects depending upon there start and end possition.This was just to test.Also it does not thro any error or exception while adding text nodes.
    But i am not able to see any text. can u telll whats wrong in this.....
    Regards,
    Akhil Nagpal

  • Saving  java3D info

    HI all,
    I have Java3D app runs on applet. i would like to save 3D info into CAD comptaible file. Is there any direct methods supported by 3D API to do this -- GJ

    HI all,
    I have Java3D app runs on applet. i would like to
    save 3D info into CAD comptaible file. Is there any
    direct methods supported by 3D API to do this -- GJNo, unfortunately. But this is because there are almost no standards in the 3D world. That said, if you can write out (or find an exportor) the Java3D scene graph to some common interchange format, you can use a convertor to get it into CAD format.

  • Java3D has different order axis than 3dsMAX

    Hi, I make 3d game. 3D scene I have created in 3d studio MAX and exported to files which I loaded into Java3D scene. Because 3dsMAX has Z a Y axis exchanged instead of Java3D coordinate system I replacementing Y and Z coordinates in 3d mesh. [X,Y,Z] -> [X,Z,-Y]. Problem come in Transform3D when I exchanged translational values. It is not enough. I must exchange some values in rotational components of 3d matrix. And I don't know how.

    There is an easy way to build a new matrix from the old one if you know how to convert individual vectors from one system to the other. A linear transformation (i.e. matrix too) is solely defined by its output on each of the basis vectors, which are (1,0,0,0), (0,1,0,0), (0,0,1,0) and (0,0,0,1) for 4x4. In fact, the vectors it returns for each are the rows (or columns) in your matrix (depending what order you multiply in with vectors). Thus, take (1,0,0,0) in your new coordinate system; convert it to the old system; multiply it by the matrix; then make the resulting vector the first row (or column) in your new matrix. Take (0,1,0,0) and do the same for the second row (or column). Same thing with the other two basis vectors, and you've got it.

  • Java3D has different coordinate system than 3dsMAX

    Hi, I make 3d game. 3D scene I have created in 3d studio MAX and exported to files which I loaded into Java3D scene. Because 3dsMAX has Z a Y axis exchanged instead of Java3D coordinate system I replacementing Y and Z coordinates in 3d mesh. [X,Y,Z] -> [X,Z,-Y]. Problem come in Transform3D when I exchanged translational values. It is not enough. I must exchange some values in rotational components of 3d matrix. And I don't know how.
    Thanks

    It is not really a problem, the model is just rotated the axes are still same place relative to each other. Just put put a rotation in at start of file, I have done that with countless of files from 3d s max.
    And there are noone that are forcing you to define Y as upwards in java3D, you can define it as you like. Thats why there are parameters like 'up' in the method transform3d.lookAt() , Java3d make no presumptions about your worldview.

  • JavaFX & Java3d

    If JavaFX currently will not let me build a 3d scene graph
    Has anyone got an example of building a Java3d scene graph and having it displayed in a JavaFX pane/panel

    >
    Has anyone got an example of building a Java3d scene graph and having it displayed in a JavaFX pane/panel
    >
    The only one I am aware of relied on an older version of JavaFX: www.interactivemesh.org/testspace/j3dmeetsjfx.html
    It would be possible to use the new JavaFX Canvas Node to transfer rendering data from Java3D to JavaFX. I'm afraid I don't have any examples. Keep in mind however that Java3D is a little outdated and in another year and a half or so, JavaFX will eventually supersede Java3D with its own 3D capabilities.

  • Can someone tell me how to change obj file in the applet

    Thanks in advance.
    I have try to use the ObjLoad example in the java3d demo to
    change the obj file.But I fail to do this.
    I had use twe applet,one to change name,and then refresh the other
    frame to try to relod th obj file. but
    java.lang.NullPointerException
    at ObjLoad.init(ObjLoad.java:150)
    at sun.applet.AppletPanel.run(AppletPanel.java:348)
    at java.lang.Thread.run(Thread.java:536)
    can you help me?
    thanks

    Sun's Java3d FlyThrough Demo & Java3d Scenegraph Editor
    allow you to load mutiple 3d files (sequencially) including VRML
    files with the Sun VRML Loaders at run-time
    -- and the Java Source Code is free --- ( see below )
    First, try a Web Demo of the "Appearance Explorer" :
    "Appearance Explorer" Java3d Web Applet, Loads multiple ".obj"
    http://web3dbooks.com/java3d/jumpstart/AppearanceExplorer.html
    - click on "Data"
    - click on "Obj File: Galleon" -- or -- "Obj File: Beethoven"
    - rinse, rather, repeat.
    |
    http://web3dbooks.com/java3d/jumpstart/Java3DExplorer.html
    http://web3dbooks.com/java3d/jumpstart/J3DJumpStart.zip
    | ^-- free source code
    |
    http://www.frontiernet.net/~imaging/games_with_java3d.html
    | Sun's Java3d Scenegraph Editor showing a Nasa VRML model
    | --------------------------------------------------------
    |
    | uses the Sun VRML Loaders, source code available and is free.
    |
    | [ at this url: ] http://java3d.netbeans.org/j3deditor_intro.html
    |
    http://www.frontiernet.net/~imaging/terrain_rendering.html#Scenegraph_Editor
    http://www.frontiernet.net/~imaging/terrain_rendering.html
    Selman wrote a Java3d book that was well received
    and has a Swingtest.java applet and application that
    allows you to load objects dynamically,
    ie. "change" the viewed object when it is running by
    allowing the user to select "sphere" or "cube" from
    menu lists ( in this case it's not just displaying
    Jav3d primative objects, but it has the core functionality
    of deleteing and adding nodes in the scene graph that you
    are seeking, and at that point the rest is left as
    exercise to the student. The ObjLoad.java in Sun's Demos
    directory has the code to load ".obj" files, so you have
    all the tools you need.
    | Picking of VRML objects with your mouse is demonstrated
    | in a new book, Java 3D Programming, by Daniel Selman
    | ( shown on the left ).
    |
    | The source code is avaible for free.
    |
    | [ here: ] http://www.manning.com/selman/selman_source.zip
    |
    | This new book uses the old, reliable Sun VRML Loaders for Java3d.
    |
    | The program reads a 3d scene as a simple VRML text file,
    | and displays the Java3d Scene Graph ( which is interactive,
    | you can expand and collapse the branches of the scenegraph
    | and examine the contents of the nodes ), it renders the
    | 3d scene, and when you click on an object it tells you
    | what you clicked on.
    |
    | You can see ( and download ) the Java Source code of
    | the operative file: VrmlPickingTest.java
    |
    | The publisher's site has more informatation on the book.
    |
    http://www.frontiernet.net/~imaging/games_with_java3d.html
    http://www.frontiernet.net/~imaging/sourcecode/VrmlPickingTest.java
    The Prentice-Hall books by Aaron Walsh are false & fraudulent
    in their claims to present the most current methods, as a part
    of the "Couch-Beiter Flame War" and fraud involving Sandy Ressler
    at the NIST. Prentice-Hall, Yumetech.com and Aaron Walsh have
    misrepresented and disparaged the old & reliable Sun VRML Loaders
    in favor of the "new" Yumetech.com Loader, and the web demo above
    __ DOES NOT __ load Web3d.org's __ VRML __ files, only the less
    capable ".obj" files ... so the "Web3d" series of books from Prentice-Hall
    does not show the loading of ___ Web3d.org 's ___ VRML __ files
    because Sun's VRML Loaders were the best ones, and the Yumetech.com
    folks didn't want anyone using those, and started the "Couch-Beitler Flame War"
    to disparage, falsely & fraudulently misrepresent the facts and knowingly
    published false and misleading "disinformation" in the
    unreliable Prentice-Hall / Pearson Ed books, harming our community.
    The Sun VRML Loaders are used by __ Nasa, __
    the NSF supported Virtual Chemistry Lab ( "Lab3d" ),
    me, and others simply choosing the "what works best",
    and by people using Sun's Java3d FlyThrough & Java Scenegraph Editor.
    symsan wrote:
    |
    | Thanks a lot,but can you give some code
    | about to change the Obj file or vrml file,
    | when the user in the browser to choose
    | the file or input to the textField ?
    |
    I misunderstood the original question ( it was too terse ).
    I interpreted the question has how to change the loaded
    objects --- between successive runs of the program ---
    and not as you intended -- dynamicall while running
    the program program without quiting & restarting.
    In a "Java3d" forum I'm not going to wander into
    how basic ( non-Java3d) 2d commonents such as TextFields
    are programmed.
    The original Vrml97Player.java file that came with
    Sun VRML Loaders also implemented the functionality
    of loading mulitiple files ( sequentically during one run )
    and I have worked with that and similar things with
    the Shout3d.com engine and my own 3d Java engines.
    -- Paul, Java Developer & Web Animator
    Imaging the Imagined: Modeling with Math & a Keyboard

  • An onsceen timer for game???

    Hi,
    I have to make a computer game in java3d and I'm pretty clueless, any help I could get here would be great.
    Current problem : Once the user presses a "Start" button I want a timer counting down from 5 mins. I want to timer to be on screen so the user can see it the whole time he is playing the game and when the timer is up a message appears ie GAME OVER! and the game stops running.
    Does anyone have any ideas or have done this before?? Heres some code on it I've hacked together so far.
    Thanks,
    Sean
    //create start button to start game/timer
    private Buttton go = new Button("Start");
    Panel p = new Panel( );
    p.add(go);
    add("North",p);
    go.addActionListener(this);
    go.addKeyListener(this);
    public void actionPerformed(ActionEvent e ) {
    // start timer when button is pressed
    if (e.getSource()==go){
    //if (time timer is not running) ???
    { //start timer +display timer ???
    //when timer == 0.00 add "game over" message to screen + stop game ???

    That's how you would do it in Java2D, for sure.
    If you want to put some Java2D stuff around your canvas, this kind of thing should work fine.
    If you want to incorporate it into your 3d scene (the way most games work) you will need to find a way to write it into your Java3D scene. There are a few different ways of doing this- I have had some success by writing the text into a graphic and then using the graphic I have just created as a texture on a plane attached to my viewPlatform. I believe there is something clever you can do to write it directly onto the view instead of using geometry in the scene, but I don't recall what...

  • Pre-loading objects and textures

    I have made a java3d applet which starts with swing gui
    then makes a scenegraph, something like this:
    1). I configure/set the
    3DCanvas
    VirtualUniverse,
    Locale
    View BranchGroup ...
    Scene BranchGroup (empty)
    add a behavior to View
    2). The behavior previously added is used to extend the scene and view
    with new BranchGroups, Shape3Ds (some loaded from .obj files) and behaviors (right now, everything gets loaded in the behavior)
    Now my question is, how can I load the .obj files and .jpg texture files
    in the swing part or in part 1.) so that I can put them in the scene from the behavior?
    I was thinking to build another BranchGroup in which I would add all the loaded objects with textures and then give a reference to the behavior which could then just copy the objects in the scene...
    Does this make sense? or is there maybe another way to do it?
    Also is there any easy way to modify the applet loader or make a custom one, so that the user doesn�t see the gray screen with "applet loading"?
    thanks

    If I detach a BranchGroup referenced by a behavior,
    can the behavior still modify or access the BranchGroup????

  • Code compiles, runs but doesn't display anything, not even Exceptions?

    The title just about says it all, but I don't even get a window, why is this? If it's some exception then it's not displaying for me to diagnose. Some pointers in what might be wrong would be really appreciated here - I'm pretty new to Java 3D.
    * Test.java
    * PrTestf of concept - this class draws a 3D wire-frame model of a BattleZone tank
    * @author Mark2
    * Created on 10 September 2006, 18:59
    package BattleZone;
    import java.awt.*;
    import java.awt.event.*;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.geometry.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    public class Test extends CloseableFrame
    public static View myView = new View();
    public static GeometryInfo gi;
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    public Canvas3D canvas3D = new Canvas3D(config);
    public SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
    public void Test()
        CloseableFrame frame = new CloseableFrame("Proof of Concept");
        setVisible(true);
        MakeUniverse();
        constructView();
    public static void main(String args[])
       new Test();
    public SimpleUniverse MakeUniverse()
        ViewPlatform myViewPlatform = new ViewPlatform();
        myView.attachViewPlatform(myViewPlatform);
        BranchGroup contentBranchGroup = new BranchGroup();
        simpleU.addBranchGraph(contentBranchGroup);
        simpleU.getViewingPlatform().setNominalViewingTransform();
        MakeSceneGraph();
        return simpleU;
    public BranchGroup MakeSceneGraph()
        BranchGroup scene = new BranchGroup();
        populateGraph(simpleU, scene);
        return scene;
    private View constructView()
        myView.addCanvas3D(canvas3D);        //NullPointerException
        myView.setPhysicalBody(new PhysicalBody());
        myView.setPhysicalEnvironment(new PhysicalEnvironment());
        return myView;
    public static BranchGroup populateGraph(SimpleUniverse simpleU, BranchGroup scene)
        simpleU.addBranchGraph(scene);
        Read_In_Tank_Data();
        return scene;
        public static void Read_In_Tank_Data()
        float[] data = new float[13*3];
        int [] stripCount = {6,7};
        int i = 0;
        //          X               Y                   Z   for each point in the polygon
                                       //Draw near view first
        data[i++]= -1.0f; data[i++]= -1.0f; data[i++]= 0.0f;    //1     Back right corner of base
        data[i++]= -1.5f; data[i++]= -0.5f; data[i++]= 0.0f;
        data[i++]= -1.0f; data[i++]= 0.0f; data[i++]= 0.0f;
        data[i++]= +2.0f; data[i++]= 0.0f; data[i++]= 0.0f;     //Draws base
        data[i++]= +3.0f; data[i++]= -0.5f; data[i++]= 0.0f;     //Forward most point
        data[i++]= +2.5f; data[i++]= -1.0f; data[i++]= 0.0f;     //6
        data[i++]= -1.0f; data[i++]= 0.0f; data[i++]= 0.0f;     //Draw top and turret
        data[i++]= 0.0f; data[i++]= +1.0f; data[i++]= 0.0f;     //Highest point - Antanae array on top of here
        data[i++]= +0.5f; data[i++]= +0.75f; data[i++]= 0.0f;
        data[i++]= -+2.0f; data[i++]= +0.75f; data[i++]= 0.0f;     //10
        data[i++]= +2.0f; data[i++]= +0.5f; data[i++]= 0.0f;
        data[i++]= +1.0f; data[i++]= +0.5f; data[i++]= 0.0f;
        data[i++]= +2.0f; data[i++]= 0.0f; data[i++]= 0.0f;     //13
                                       //Draws far view same as front but with -1 Z values
        data[i++]= -1.0f; data[i++]= -1.0f; data[i++]= -1.0f;         //Back left corner of base
        data[i++]= -1.5f; data[i++]= -0.5f; data[i++]= -1.0f;     //15
        data[i++]= -1.0f; data[i++]= 0.0f; data[i++]= -1.0f;
        data[i++]= +2.0f; data[i++]= 0.0f; data[i++]= -1.0f;     //Draws base
        data[i++]= +3.0f; data[i++]= -0.5f; data[i++]= -1.0f;     //Forward most point
        data[i++]= +2.5f; data[i++]= -1.0f; data[i++]= -1.0f;
        data[i++]= -1.0f; data[i++]= 0.0f; data[i++]= -1.0f;     //20      Draw top and turret
        data[i++]= 0.0f; data[i++]= +1.0f; data[i++]= -1.0f;     //Highest point - Antanae array on top of here
        data[i++]= +0.5f; data[i++]= +0.75f; data[i++]= -1.0f;
        data[i++]= -+2.0f; data[i++]= +0.75f; data[i++]= -1.0f;
        data[i++]= +2.0f; data[i++]= +0.5f; data[i++]= -1.0f;
        data[i++]= +1.0f; data[i++]= +0.5f; data[i++]= -1.0f;     //25
        data[i++]= +2.0f; data[i++]= 0.0f; data[i++]= -1.0f;     //26
        //Need some connecting lines to make a whole object.
        GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
        gi.setCoordinates(data);
        gi.setStripCounts(stripCount);
        NormalGenerator ng = new NormalGenerator();
        ng.generateNormals(gi);
        gi.recomputeIndices();
        Stripifier st = new Stripifier();
        st.stripify(gi);
        gi.recomputeIndices();
        createWireFrameAppearance();
    public static Appearance createWireFrameAppearance()
        Appearance materialAppear = new Appearance();
        PolygonAttributes polyAttrib = new PolygonAttributes();
        polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE);
        materialAppear.setPolygonAttributes(polyAttrib);
        return materialAppear;
    }

    Its because your public void Test() should be public Test(). Its a constructor, not a method.

Maybe you are looking for

  • Case sensitive statement in the select-statement

    Hi All, i have a table in the abap-dictionary filled with names...when i try to select them with the select-statement with condition: table-name_column like 'some_name' I have encountered some problems...the inquiry is case-sensitive. What i want to

  • How to remove column name in select clause

    Hello Guys, I just want to remove a column name in select clause. Because, I don't want to write all column names. I hope I express myself. In other words, I want the following. Select   * - unwanted_column  from table; instead of this Select col1, c

  • GS-01: Understanding the Flash environment | Learn Flash Professional CS5 & CS5.5 | Adobe TV

    Learn about the basics of the workspace in Flash CS5, including the Stage, the Timeline, panels, and the Tools panel. http://adobe.ly/z4TWsy

  • [svn:fx-trunk] 11286: Small fix to List multiple selection commit.

    Revision: 11286 Author:   [email protected] Date:     2009-10-29 16:59:07 -0700 (Thu, 29 Oct 2009) Log Message: Small fix to List multiple selection commit. Problem: Dispatching programatically mouse_down event to the item renderer would not put it i

  • Information Disbursements workflow

    Hi, I am currently working for a client who is into Financial Services. I need help on CML workflows. Could you kindly tell me if there is a standard SAP workflow (already available) for Loan Disbursements? If there is a standard workflow, could you