loading
If you're a Java programmer you probably have wanted to program in 3D at some point. But how? Well you could use Java3D and slowly type in each point in a 3D polygon (tried it trust me its a bad idea), or you could use Blender (http://blender.org) a free and open source 3D modeling program along with a script called Blend2Java (http://sourceforge.net/projects/blend2java/). However the documentation on Blend2Java is almost nonexistant so thats why I sit here writing this.

Step 1: Download the Programs

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).

Step 3: Import the Object to Java

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!
This is a great Instructable, but you need to add a main image of the final project to the intro step. Please do that and leave me a message when you have so that we can publish your work. Thanks!
Ok I put the final picture on the intro.
<p>I still dont get it , could you now explain how to use the 3d object?</p>
Yi]ou said that you just learned java a week ago... Where did you learn it/ how did you learn it? I cant find anything at all on how to program in java.
If you want to learn a bit of java:<br><br>1.Get Minecraft, if you haven't done so already.<br>2.Get MCP (Minecraft Coder Pack)<br>3.Get ModLoader<br>4.Look up on YouTube how to set it up, as well as various tutorials on how to mod certain aspects of the game.<br>5.Make a mod.<br><br>Follow these steps, and you will have learned some Java!
This could come in handy for making Minecraft mods. Thanks!

About This Instructable

39,145views

7favorites

License:

More by ghostbust555:How to make an expandable, professional, pc controlled fireworks launcher Using Java to Rotate an Object to Face the Mouse Using Blender To Create Java3D Models 
Add instructable to: