The first step is to create a Plug-in Project, this is: File -> New -> Project where you can find Plug-in Project select it and go to Next, give the project a name for Example: java3dPlugin and go to Next. The next window will ask you for a template unselect the checkbox "Create a plug-in using one of the templates" and click Finish.
By now the project should looks like this:
Next go to the File Editor and in the Extensions tab (bottom of the editor) click on the Add button, it will show you a list of all possible Extension Points you can use, so as we want to create a Eclipse View select the org.eclipse.ui.views extension and click Finish.
Now in the Extensions tab should appear an entry with the name org.eclipse.ui.views, right click on it and go to New->View, now under the first entry should be another with the name name (view).
Go to the package explorer and add a new class inside the package in the src folder, name it Java3DView and it must extend from org.eclipse.ui.part.ViewPart, the class you create must override two methods createPartControl and setFocus, we will just write our code inside createPartControl which is the responsible of drawing inside the view.
Before we can begin with the writing of our code we must tell the view which class will handle with these, so open the file plugin.xml and in the File Editor go to the Extensions tab (yes the same as before) and select the entry called name(view), you can see in the right of this editor a column with the title Extension Element Details where you can find where to write a name for the view and a class associated with the view, in the name field write Java3d and in the class name field write java3dplugin.Java3DView (the class we created before) and save the work we have done until now.
The next step is tell the Eclipse plugin where to find the Java3d libraries, so first download them from https://java3d.dev.java.net/ if you haven’t done it before, inside the project create a Folder called lib and put the java libraries (*.jar) inside of it, next create another folder called native and put the native libraries (*.dll or *.so) inside of it.
Now go to the build path configuration (right click on the project -> build path -> configure build path) and add the jars to the project libraries so it can “see” them. After that open once more the plugin.xml file and go to the Runtime tab and click the Add button from the Classpath section and select the libraries from the lib folder (i.e. the jars from Java3d).
Ok, now let’s go back to the Java3DView class and use the code from here.
Now select Run Configurations from the Run menu in Eclipse it will pop up a window with a list of possible run configurations, double click on Eclipse Application and it will create a configuration to run the plug-in, go to the Arguments tab and in the text-area VM Arguments write: -Djava.library.path="${project_loc}/native", this will include the native libraries in the path so they can be loaded from the plug-in. Finally click on the Run button. Once the new instance of Eclipse is running go to the window menu and select Show View, from the list find Java3d and voila!, the nice cube from the Hello Universe example of Java3d should be happily turning in the view.
Final image:
I've followed your example all the way through but you then say "add the code in this file". What file. Also, I don't see any use of the AWT_SWT bridge is that in the code that I am unable to see?
ReplyDeleteThanks for your comment, right now I'm unable to check what's going on with the file, but as soon as I can, It will be available to download.
ReplyDeleteI have updated the missing links in this post, sorry about the problems it caused
ReplyDelete