Copyright © 2010 The G String. All Rights Reserved. Snowblind by Themes by bavotasan.com. Powered by WordPress.
Archive for January, 2009
When delivering on-line content, it is always desirable to ensure that the content is accessible to the widest possible audience. This objective is well-documented in most areas of web development, but when it comes to dealing with 3D scenes and worlds on-line, things are far from straightforward. A variety of formats, proprietary plug-ins and target platforms make delivering 3D content on the web a challenge.
The simplest method of publishing 3D is probably to link straight to a scene file, and rely on a browser plug-in capable of reading it. This approach is limited in that it depends on end-users having such a plug-in installed; and these plug-ins are normally platform-dependant. They also pose problems when trying to fit the object within the webpage; all too often frames are used to compensate, with ugly results.
The best fit to this solution takes the form of the X3D format. X3D specifies a clean XML syntax for 3D worlds, compatible with existing languages and tools, and comes with its own Java implementation, called Xj3D. This open-source codebase contains the code for the scenegraph nodes and also for a browser, allowing 3D objects to be embedded in webpages using Java applets; hence delivering a platform-independent solution as well using a plug-in that is widely supported. I wanted to embed a 3D scene into a webpage for a client, so I found out how to employ Xj3D as an applet.
The Xj3D browser uses OpenGL as the default renderer, which introduces platform-dependent requirements on end-users. The Jogl and Joal libraries depend on native extensions that wouldn’t be known until runtime. Fortunately, there is a mechanism using Java Web Start to embed an applet within Web Start, which determines the user’s platform and downloads the relevant libraries, called applet launcher. Using this mechanism, it is possible to run native code, while coding the applet in a platform-independent way.
First of all, some straightforward Java is used to define the applet which we intend to embed, which has the task of setting up the Xj3D browser. This code was based on the example from xj3d.org.
package com.yourserver.applet;
import java.applet.Applet;
import java.awt.*;
import java.util.HashMap;
import org.web3d.x3d.sai.*;
import org.xj3d.sai.*;
import org.web3d.vrml.scripting.external.sai.*;
public class XJ3DApplet extends Applet {
ExternalBrowser browser;
public XJ3DApplet() {
}
public void init() {
setLayout(new BorderLayout());
browser = getBrowser();
loadScene();
}
// Generate the browser
private ExternalBrowser getBrowser() {
HashMap requestedParameters = new HashMap();
requestedParameters.put(“Xj3D_ConsoleShown”, Boolean.TRUE);
requestedParameters.put(“Xj3D_LocationShown”, Boolean.FALSE);
X3DComponent comp = BrowserFactory.createX3DComponent(requestedParameters);
Xj3DBrowser browser = (Xj3DBrowser) comp.getBrowser();
setBackground(Color.blue);
add((Component) comp, BorderLayout.CENTER);
setVisible(true);
return browser;
}
// Create the scene implementation and add it to the world
private void loadScene() {
X3DScene mainScene = browser.createX3DFromURL(new String[] {getParameter(“modelURL”)});
browser.replaceWorld(mainScene);
}
}
This class can then be packaged up into a jar, ready to be deployed. This class would also be the place to hook into the browser for any SAI-scripting, or to pass other parameters to the browser, such changing cursors or the taskbar look + feel.
The next stage was to obtain the Xj3D libraries to deploy alongside the applet. These can be found on xj3d.org. Xj3D provides a jar file to contain the runtime used with applets, packaging a jar for each X3D profile seperately. You will need to choose which jar file is appropriate for your scene; I was using an immersive scene with touch sensors, so I needed xj3d-immersive-applet-av3d_2.0.0.jar.
Before any of the jars could be used however, it is necessary to sign them using the jarsigner command. If you haven’t already got a keystore, then in order to make jarsigner work you must create a key using the keytool command:
keytool -genkey
Which will prompt you for information necessary to create a self-signed certificate and a key, which defaults to ‘mykey’. I used the domain of the server I would be running off as the common name (it prompts you as ‘Your Name’). Once I had a key, I could sign my applet’s jar and each of the Xj3D jars so that I could host them from my server.
jarsigner -storepass changeit soandso.jar mykey
Once I had signed copies of the latest jar files from xj3d.org, I was ready to define the applet tag. The remaining code resides within inside the applet tag within the HTML itself:
<applet code=”org.jdesktop.applet.util.JNLPAppletLauncher”
width=600
height=400
archive=”http://download.java.net/media/applet-launcher/applet-launcher.jar,
http://www.yourserver.com/jogl.jar,
http://www.yourserver.com/gluegen-rt.jar,
http://www.yourserver.com/joal.jar,
http://www.yourserver.com/uri.jar,
http://www.yourserver.com/vecmath.jar,
http://www.yourserver.com/j3d-org-all_0.9.0.jar,
http://www.yourserver.com/xj3d-immersive-applet-av3d_2.0.0.jar,
http://www.yourserver.com/js.jar,
http://www.yourserver.com/xj3d-sai_2.0.0.jar,
http://www.yourserver.com/xj3d-external-sai_2.0.0.jar,
http://www.yourserver.com/httpclient.jar,
http://www.yourserver.com/aviatrix3d-all_2.0.0.jar,
http://www.yourserver.com/xj3d-script-base_2.0.0.jar,
http://www.yourserver.com/yourbrowserapplet.jar”>
<param name=”codebase_lookup” value=”false”/>
<param name=”subapplet.classname” value=”com.yourserver.applet.XJ3DApplet”/>
<param name=”subapplet.displayname” value=”Your Applet”/>
<param name=”subapplet.image” value=”http://www.yourserver.com/splash.jpg”/>
<param name=”noddraw.check” value=”true”/>
<param name=”progressbar” value=”true”/>
<param name=”jnlpNumExtensions” value=”2″/>
<param name=”jnlpExtension1″
value=”http://download.java.net/media/jogl/builds/archive/jsr-231-webstart-current/jogl.jnlp”/>
<param name=”jnlpExtension2″
value=”http://download.java.net/media/joal/webstart/joal.jnlp”/>
<param name=”modelURL” value=”http://www.yourserver.com/bellsnew.x3d”/>
</applet>
Notice that you can host all the jars yourself. I found that I ran into trouble when I was hosting the applet-launcher jar file; this is related to the necessity of having the native extensions signed by the same source as the applet launcher. I’m sure this is fixable but I didn’t discover how.
One difficulty that I found when using this approach was that the link between Web Start and the applet runtime suppressed errors stemming from the Xj3D browser, making debugging very difficult. I found that it was far more efficient to get my scene working perfectly in the stand-alone browser, which reported errors immediately, before trying to get the applet running. Whenever I had trouble getting the scene to load, it was usually because of a jar file that was missing or not signed correctly.
Now when users visit the HTML page, a Java applet appears that downloads all the necessary software, and runs the Xj3D browser, displaying the 3D content in the most accessible way.
Continue Reading »Today is a milestone in my ambitions as a freelance web developer. I have installed and deployed my own server in a datacenter, running Debian linux. This development now allows me to offer full-cycle web development, from concept, through design, implementation and testing, and I can even host your website when its done.
Contact me for a quote for your freelance development or hosting needs.
Continue Reading »A long-standing interest of mine in the field of computer graphics is the progress of the X3D standard for virtual reality, established as an ISO standard in 2004. I was first taken in as a student, working on a project to develop my own network protocol for X3D environments, impressed by the intuitive XML-syntax and standards-driven approach. An open-source Java-implementation exists, although sadly their documentation / user-guide page hasn’t moved on at all since I was at University. Ultimately, I found working with a draft specification, no documentation and a severe lack of tools too much for X3D to remain compelling, although when I was recently approached to develop an on-line model of a musical instrument that has recently been invented, my first inclination was to catch up with X3D and see if it had become any more mature or easier to work with.
My first stop was checking out what tools were available. The Web3D consoritum keep a list of players and editors that is currently more useful than a Google search, mainly because so many tools are propreitary and only run on Windows. I was running on Mac OSX, and it took a while to find any editors that were helpful at all. But before I nearly gave in to running parallels and WinXP, I found that X3D-Edit has become much more useful and featured. A Java-based Netbeans mod, it comprises a built-in Xj3D browser for easy preview (just hit right-mouse and its the first option) as well as tight integration with any other players; I was checking my scene in the excellent FreeWRL. I found that the navigation tree and code-snapping features took a great deal of complexity out of the complex model I was supplied with, and the import from VRML 2.0 worked like a charm. Despite the more powerful features, I found that the packaging of X3DEdit is rather awkward and un-mac like; the executable is a shell command to kick-start the Java VM, and the memory-hungry app forced me to quit and restart the editor many, many times.
However, to suddenly have found a tool that I could put up with for X3D development renewed those questions buzzing around in my head since discovering virtual reality: could we all easily develop 3D-environments, as easy as we’re writing blogs today? Will we all be wondering around with HUDs and building social networks in 3D-psychedelic tripped-out universes?
And then I get amongst the code, and I see that X3D is still very much back in the 90s. While 3D has come from Wolfenstein3D to Ice Age in the last ten or so years, its hard to see how I could sit in front of this computer for more than that long and achieve nothing more than a cone with X3D; and even a cone would be a bit 99 (pardon the pun). Thankfully, for this job I was supplied with a model; but even the user-interface of the browsers with their unusual viewing paradigms seem designed for little more than tracking a spherical object in a scene. My little brother uses Wii-motes to make music in a little 3D world; and yet even with a degree in computer science I don’t feel confident that I could take this technology anywhere near that, as cool as would be.
Nonetheless the ideals of the standard and the potential applications are too vital to ignore. Perhaps hope will come in the form of more open-source technology. I haven’t had the chance to check out blender, but it seems to be a fully-fledged graphics package like Maya, without the several thousand pound price tag. The flux player has found an application and become Vivaty, which looks promising as a standards-based second-life styled network. So for now, I’ll continue the trial-and-error with X3D.
Continue Reading »