This might not be the correct forum, but I’m unsure if there is any better.
I’m about to write a loader for X3D-files (http://www.web3d.org/) that would be independent from JOGL and any scene graph API. Since Java 6 has included JAXB 2 in Java SE, I intend to use that to build the Java objects representing a model. Basically, what I’m doing is:
- Generate the classes using the xjc-tool in Java 6: xjc -d src -p http://www.web3d.org/specifications/x3d-3.0.xsd
- Unmarshall an .x3d file using the JAXB 2 API (see below and javax.xml.bind)
- Read the data from the unmarshalled objects and put it into your favourite Scene Graph API (or however you wish to use it)
The code for unmarshalling an XML document looks like this:
JAXBContext context = JAXBContext.newInstance();
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(null);
unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
model = (X3D) unmarshaller.unmarshal(new FileInputStream(input));
I have some problems getting it to work properly, but overall it seems to be a pretty easy method for loading a .x3d file. I generate the .x3d using Blenders X3D export function and the file seems to validate properly.
Does this sound like a good approach for creating a standalone loader? You still have to parse the values (e.g., vertices) since they are represented as attributes in the XML-document, but that shouldn’t be a problem.