How to use and create 3D objects using java View3D:

  Lesson1: how to create a View3DComponent (without a dev. environment)

The View3D component inherit from the object java.awt.component, so just use it this way.
Example:
 
import java.awt.*: 
import tom.graphic.ThreeD.*; 

public class MyApplet extends Applet{ 
    View3DCanvas myView; 
    public void init(){ 
        setLayout(new BorderLayout()); 
        myView=new View3DCanvas();    // Create the new canvas 
        add("Center",myView); 
    } 
}

That's all.....

the problem is that the object is created with the default object, which is a dirigable. Maybe you want to add your own object.
So, if you're program is executed from an applet, just replace the View3D canvas creation with the following lines:
 
      myView=new View3DCanvas(false);  // the false value is here to prevent 
                                     // the creation of the default obj 
  
    try {  
      String name="avion.m3d"; 
      myView.setObj(new URL(getDocumentBase(), name ).openStream(),name); 
    } catch(Exception e) {  
      System.out.println(e);  
    }  
 
 
Now, you have an applet with a 3D object.
Note that there is such an applet included in the View3D package: the View3DApplet object. This object does all the job of retreiving parameters from the html, display object, etc...

Now you can move your object. Play with the setAngleX/setAngleY/setAngleY values of the View3DCanvas, or the setPosX/setPosY/setPosZ to change the user point of View.
 

 
 Lesson2: How to create a more complex object.

The basic object used in our 3D worlds are Ojbect3D instances. Each object is made of Points and several Elements ( see class Elem3D). An element can be a line, face, sphere (or something else if you want to extends View3D).
So, using our previous applet, we will create a new object ( a pyramide) and add this object in our world.
 
    Object3D myObj=new Object3D(); 

    myObj.addVert(-1,-1,0);  // this is point number 0 
    myObj.addVert( 1,-1,0);  // point number 1 
    myObj.addVert( 1, 1,0);  // etc... 
    myObj.addVert(-1,-1,0); 
    myObj.addVert( 0, 0,2); 

    Face  f=new Face(0,1,4,4,Color.red); //if you use 3 points for your face 
                                         //instead of four, just put twice the  
                                         // last point index 
    myObj.addElem(f); 
    f=new Face(1,2,4,4,Color.green); 
    myObj.addElem(f); 
    f=new Face(2,3,4,4,Color.green); 
    myObj.addElem(f); 
    f=new Face(3,0,4,4,Color.green); 
    myObj.addElem(f); 
    f=new Face(0,3,2,1,Color.yellow); 
    myObj.addElem(f); 

    // now, we add your new object in the whole world 
    myView.view().world().addObj(myObj); 
 

 

that's all....

Lesson3: Add new readers...

It's easy to add new reader. Just implement the ObjReaderInterface, and register your reader using the static method: Object3D.addReader(). Check the next tutorial: Create your own object Reader.

 
View3D Main page