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