Sunday 27 May 2012

Getting / Downloading Java3D

Java3D is free! You can download the correct version for your operating system here at https://java3d.dev.java.net/binary-builds.html

Since I am running on a Windows machine I downloaded the i586 windows installer version.

Once that is downloaded, open it and you should get a pane pop up to ask if you really want to run it. Click run.

Once that is installed, you will have all the necessary packages for java3d software installed on your machine.

Getting ‘javac’ command to work in Windows Vista


One of the main issues with using java is if you want to do anything complex and are using Windows instead of Linux, you may need to set windows to allow you to use the javac command in the command line window.

Doing this is really easy if you know what to do, and a pain in the butt if your doing it for the first time.

Instructions

In windows press start->run.

Type in "explorer"



Right click on the 'Computer' and click 'properties'.



Click Advanced System Settings.



In the window that pops up, navigate to the 'advanced tab' and click the 'environment variables' button at the bottom.



In the 'System variables' section at the bottom, scroll down untill you see the 'Path' variable, then click it.



Now that the 'Path' variable is highlighted, click the 'edit' button at the bottom.

  • Important: Whatever you do, DONT delete the text that is already the section that pops up.


The first step to do is make sure there is a semicolon ( ; ) at the very end of the text, which there probably isn't, so add one in. This is to separate the rest of the text from what you are about to put in.

  • Note: A semicolon is used to separate all paths, so if you were to add another path in later, you would need another semicolon at the end of the text you are about to put in.


Copy and paste the path to your java jdk 'bin' directory here. It must be the java 'jdk' bin folder and not 'jre' or anything else. The java bin directory should contain the javac.exe file. For example, my java directory containing the 'javac' command that I want to use is located at: 'C:\Program Files\Java\jdk1.6.0_11\bin'

You will most probably have to change the part after 'Java\' and before '\bin' to match your jdk.

After you have done this click the 'ok' button, and then the ok button at the bottom of the Environment Variables pane.

You are finished!



Troubleshooting
  • Note: An easy way to find what you should put in as the address is to open up another explorer pane,
    (start->run->'explorer') and navigate to c:/program files/java and then click the folder with ' jdk ' in the name. Then click the bin directory and click the address bar at the top to highlight the address and click copy. Then you can just paste the entire address directly into the path file.






  • Make sure your address does not end in '\' or ';' since mine doesnt and it works. You will have to add a ';' to the end later if you want to add another path.
  • Make sure to close any command panes and open up a new one before you try and use the javac command, as the variable may not be set correctly in ones that were already open before you made the changes.

If you are still having problems, please comment.

Blend2Java - Exporting 3D Objects from Blender for Java

Aim

The aim of this tutorial is to allow a complete beginner, who has absolutely no previous knowledge of Blend2Java, Python, or Blender scripting, to export a 3D object that they have created in Blender, into a form that can be later used by Java3D and my other tutorials.



Step 1 - Get Blend2Java

Go here and download it. It's free, just like all things that I cover in my tutorials.





Once you have downloaded it. Open the Zip file.





You should get the following screen.





Extract the files to the desktop





Once you've extracted the files and opened the folder you should see the following:







Step 2 - Editing the export.py script for use in blender.

Open the export.py file in notepad and you should see the following:





Insert the following code into the top of the file and then save it.

#!BPY
"""
Name: 'Blend2Java'
Blender: 248
Group: 'Export'
"""

Note that the 248 stands for version 2.48, change this number for your blender version. (It says when you start blender up)







Step 3 - Using the export.py script to export your 3D object.

Now we need to load the export.py script into blender. Open up blender.





press shift+f11 to open the scripting window, as shown below.





Open the python script by clicking the button shown below:





You should then get the following menu.





Select your exporg.py file that you edited earlier and saved. Then open it.







Run the python script



You should get the following menu asking you for the output directory and the start export button.





Enter the directory you wish the files to be exported to. I put it as C:/test as shown. Then press the stat export button.





Your files wil now be in the folder you specified, as shown. This file can be used by Java3D later.



Well done your finished!





  • Note: If you have any problems please comment about the issues and I will try to solve them in a troubleshooting section of this post. Please do not comment about any spelling/grammar mistakes. Thank you.

Getting Started with WiiRemoteJ



What You Need
  • A bluetooth dongle. This is a USB stick that will plug into your computer to work with the Wii Remotes.

  • Avetana Bluetooth needs to be installed on your machine and configured correctly. If it is not you can easily follow my tutorial here

  • I highly suggest you use a computer with a Linux operating system that has a graphical user interface, such as Xubuntu (ie. you can see pretty icons and a desktop rather than just a black screen with text). This is because Avetana is free with Linux and so that is what I used.


Downloading WiiRemoteJ

To download WiiRemoteJ, go here, and click the little orange download box as shown.


Once you have downloaded WiiRemoteJ, we need to extract it. Place the zip folder in an empty directory that you create, and name it something like WiiRemoteJ so you remember it.




Extracting WiiRemoteJ


Double click the file to open up the zip.



Drag the wiiremotej folder to the file manager to extract it.



Installing WiiRemoteJ

Go into the extracted directory and copy the Wiiremotej.jar file



Open up the terminal and type 'sudo thunar' in order to open up the file browser as the root user. You may need to enter the root user password (whatever you type to log in). This will allow us to paste the file where we need it.

The thunar file manager will open. Navigate to your Java extensions folder. Mine is located at '/usr/lib/jvm/java-6-openjdk/jre/lib/ext' and yours will be somewhere similar (probably just something different after the ' /jvm/ ' bit).



Paste the file into this directory.



It is very important that after doing this close that file manager immediately, due to the reason in red stated at the top of the file manager.

Testing/Playing with WiiRemoteJ

Now that you have installed WiiRemoteJ we should be able to run the WRLImpl.java file within the WiiRemoteJ folder that we extracted. Navigate to the WiiRemoteJ file within the command line in linux and type 'javac WRLImpl.java', press enter, then type 'java WRLImpl'. The following should pop up once you have connected the Wii remote by pressing both the 1 and 2 buttons on it after the program has started up. (note that the screen capture didnt work too well in this case so there is the white rectangle.)




Troubleshooting
If you don't have Avetana or WiiremoteJ installed correctly, when you try to compile the WRLImpl.java file provided by WiiRemoteJ, it will not compile properly and you will get a screen like this:



If you have WiiRemoteJ installed correctly but have not set up Avetana then the WRLImpl.java file will compile but will not run correctly and you will get an error like this:

Lesson 2 - Primitives and Conditional Loops

1) Java has several 'primitives' or basic data types
  1. byte - minimum value of -128 and a maximum value of 127
  2. short - minimum value of -32,768 and a maximum value of 32,767 (inclusive)
  3. int - minimum value of -2,147,483,648 and a maximum value of 2,147,483,647
  4. long - minimum -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807
  5. float - 1.1234f
  6. double - 1.127
  7. char - a single character such as 'a' or 'b'
  8. boolean - TRUE/FALSE
2) Java also supports another special type called the 'String' which is a set of characters within quotation marks. e.g. "Hello World"

2) The main ones most commonly used are String, int, and float.

3) There is a significant difference between a float and a double but this is beyond the scope of this entry tutorial. You can think of them both as types that will take a decimal point value. If you REALLY want to know the difference, look here.

4) Boolean values a

Starting With Java3D Made Easy

Aim
The aim of this post is not to give you a detailed insight into java3d, but to explain things very easily (with pictures!) on how to start off so that a complete newbie to Java could make their first Java3d scene. This is mainly due to the fact that I had quite a few issues when I did it for the first time, and that many people are experiencing problems, even after following the Sun tutorials at http://java.sun.com/developer/onlineTraining/java3d/. I also noticed that some crucial information was missing on-line, such as one of the import statements that you will need to use.


What you need
You will need to have Java3D installed on your computer. This is very easy and quick in my other tutorial. If you are running Windows Vista you may want to follow my other tutorial on how to get Javac to work in Windows Vista, first.

Programming your first Program with Java3D
  • * Important Note!This tutorial will tell you how to make a Java3D program even if you haven't got Java3d installed correctly, and will tell you where to skip if you have got Java3D installed correctly. This is due to the fact that when I originally wrote this article, my Java3D was not installed correctly. I have since fixed this problem.
This can be done in a simple text editor such as notepad, or be performed in a programming IDE of your choice. My personal preference is the Netbeans IDE but for training purposes I am going to do it in notepad.

Go to http://java.sun.com/developer/onlineTraining/java3d/ and click on 'chapeter 1' .

Navigate to page 20 and copy the code shown there.


Paste the code into notepad (or your IDE), and remove all the line numbers.


Navigate to the next code section in chapter 1 on the same page and do the same, making sure to paste the code BELOW the code you pasted in before.




Navigate to page 21 in chapter 1 and copy the first section of code.


Paste the code into your notepad file after the class declaration but before the first method declaration, as shown below. Make sure to remove all the line numbers once again.


Navigate to the bottom of page 21 and copy the section of code as shown below:


Paste it into your notepad file at the TOP before everything else. (make sure to remove all line numbers)


Paste the followig code in the section that you just pasted:
import java.awt.GraphicsConfiguration;
This is an important package that will be needed to compile the program.





Now save the file as 'HelloJava3Da.java'. The name has to be exactly correct otherwise the tutorial wont work. The name of the file is the same as the class name within the file, and it has to have the '.java' extension.





Create a new folder and move the file into an that folder. Make sure the folder is somewhere you will remember. It will make it easier later if you put the folder in your c: directory and name it something easy to type/remember.


  • * Amendment! - The steps below untill the next ' * Amendment! ' note are unnecessary if you installed Java3d correctly. This is section is kept for troubleshooting purposes.
Navigate to your Java3D bin folder and copy the .dll files. Mine is at
C:\Program Files\Java\Java3D\1.5.2\bin


Paste the files into your freshly made folder that you placed 'HelloJava3Da.java'.


Navigate to your Java 3d lib ext folder and copy the .jar files. Mine is at
C:\Program Files\Java\Java3D\1.5.2\lib\ext


Paste the files into your freshly made folder that you placed 'HelloJava3Da.java'.


  • *Amendment! - The above steps may have been unnecessary but the next few are needed in order to run the program.
Press start->run and type 'cmd' in order to open up your command pane.


You should now have your command pane open. Type in 'cd' and then the full path to the folder that you put your java file in. My command was ' cd c:\tutorial ' as shown below.


Now that you are in your folder, you can compile your program. Type 'javac HelloJava3Da.java '. You can do this easily by typing javac then spacebar and then pressing tab untill the right file name pops up.


After you hit enter/return, it should appear that nothing happened, as shown below. If you recieved a load of text, then your program did not compile correctly and you should look at the troubleshooting section at the bottom of this post.


Now that you have compiled your program successfully, type into the command pane (making sure that you are currently located in the folder containing all the jar files and the .java file you wrote earlier) :

  • For users without Java3D installed properly but have the packages moved to the folder type :
    java -classpath .;\.;j3dcore.jar;j3dutils.jar;vecmath.jar; HelloJava3Da

  • For users that have Java3D installed correctly and did not need to move the files type:
    java HelloJava3Da

This declaration tells the java machine to run the program HelloJava3Da that you wrote and to check the jar files for all the necessary classes specified in your imports in the program you wrote. The ruesult should be a pane that pops up and shows you a red square.


Well done you're finished!



Troubleshooting
If your having trouble compiling and your on a Windows computer and haven't set up 'javac' to work correctly yet, you should get a 'javac' unrecognized error of some sort. If you are using Windows Vista please follow my 'Javac to work in Windows Vista' tutorial.

If you get the error like below when trying to compile with 'javac', then you forgot my instructions just before saving the java file.
Paste the following code in the section that you just pasted:
import java.awt.GraphicsConfiguration;
This is an important package that will be needed to compile the program.