Using Blender To Create Java3D Models
You will need Blender (http://blender.org) and Blend2Java (http://sourceforge.net/projects/blend2java/). Ok then once you have them both start off by making a simple model (or just using the standard cube) in Blender.
Step 2: Export Your Model To XML
Once you have a model you would like to use in Blender open Edit Mode
and hit the "a" key to select all points. In the bottom panel select text editor.
Open a new file in the text editor. Open the blend2java.py file that you downloaded. Run.
Ok
your object should now be in .XML wherever you saved it (if you have
and error message make shure you only have 1 material for the object).
Rename the object (it will have a weird name).
Shape3D fred = null;
try {
XMLDecoder e = new
XMLDecoder(new BufferedInputStream(new
FileInputStream("c:/HandShape3D.xml"))); //your file name here
fred = (Shape3D) e.readObject();
e.close();
} catch(Exception e) {
e.printStackTrace();
}
ColoringAttributes at=new ColoringAttributes();
Appearance ap = new Appearance();
Color3f col = new Color3f(1.0f, 0.0f, 1.0f);
ColoringAttributes ca = new ColoringAttributes(col, ColoringAttributes.NICEST);
ap.setColoringAttributes(ca);
fred.setAppearance(ap);
obj.addChild(fred);
insert this into any 3d code or use the whole code here
import java.io.*;
import java.beans.XMLDecoder;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.event.*;
import java.util.Enumeration;
public class MouseBehaviorApp extends Applet {
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
TransformGroup objTransform = new TransformGroup();
objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objRoot.addChild(objTransform);
Shape3D fred = null;
try {
XMLDecoder e = new XMLDecoder(new BufferedInputStream(new FileInputStream("c:/HandShape3D.xml")));
fred = (Shape3D) e.readObject();
e.close();
} catch(Exception e) {
e.printStackTrace();
}
ColoringAttributes at=new ColoringAttributes();
Appearance ap = new Appearance();
Color3f col = new Color3f(1.0f, 0.0f, 1.0f);
ColoringAttributes ca = new ColoringAttributes(col, ColoringAttributes.NICEST);
ap.setColoringAttributes(ca);
fred.setAppearance(ap);
objTransform.addChild(fred);
MouseRotate myMouseRotate = new MouseRotate();
myMouseRotate.setTransformGroup(objTransform);
myMouseRotate.setSchedulingBounds(new BoundingSphere());
objRoot.addChild(myMouseRotate);
MouseTranslate myMouseTranslate = new MouseTranslate();
myMouseTranslate.setTransformGroup(objTransform);
myMouseTranslate.setSchedulingBounds(new BoundingSphere());
objRoot.addChild(myMouseTranslate);
MouseZoom myMouseZoom = new MouseZoom();
myMouseZoom.setTransformGroup(objTransform);
myMouseZoom.setSchedulingBounds(new BoundingSphere());
objRoot.addChild(myMouseZoom);
objRoot.compile();
return objRoot;
}
public MouseBehaviorApp() {
setLayout(new BorderLayout());
Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
add("Center", canvas3D);
BranchGroup scene = createSceneGraph();
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scene);
}
public static void main(String[] args) {
Frame frame = new MainFrame(new MouseBehaviorApp(), 256, 256);
}
}
use this for a complete program
tada! you are done!
and then you say "now what"?
I have no idea! I just learned Java a month ago lol!
No comments:
Post a Comment