Examine, Edit, and Validate .x3d Files


The .x3d file format is an ISO/IEC xml-based standard for representing 3d images. Also known as X3D, .x3d files originated as a way to represent 3D images for computer graphics. Over time applications grew from virtual reality (VRML), to CAD design, architectural rendering, 3D printing, medical and anatomical imaging, representation of molecular chemical structures, human animation, and more.

The Web3D Consortium maintains the X3D standard, with XML Schemas documented here. Current versions include definitions of more than 250 XML elements, over 100 simple types, 70 complex types, and more than 40 defined node groups.

It takes that much complexity to accurately describe anything from a precisely manufactured machine part to a richly textured virtual environment, especially considering lighting, texture, and point of view! XMLSpy, the world’s most popular tool for modeling, editing, transforming, and debugging XML and JSON related technologies, supports .x3d files. XMLSpy offers standards-based tools for anyone who may need to examine, exchange, consume, or validate .x3d files. Let’s look at some examples.

First, we can customize the XMLSpy Tools menu to create a new menu selection to conveniently render 3D images from .x3d files. We installed two X3D players listed on the web3d.org X3D resources page so we can compare results in each. This creates the user-defined menu options here:

Now we need a .x3d file. Many examples are available online. The National Institute of Health (NIH) maintains a library of .x3d files at their Web site. These files include a range of X3D applications, including chemical structure models, 3D-printable objects, and actual renderings of cell tissues and organisms.

Let’s start with a 3D-printable shape. In the screenshot below we opened a file and used the Tools menu to also open it in the H3DViewer app:

XMLSpy will automatically validate .x3d files when they are opened

Note the message window below the main Text display. XMLSpy will automatically validate .x3d files when you open them. In the H3D viewer we can grab the image and rotate to see it better:

This object is an ear saver for face masks that can be printed on a 3D printer. It’s intended to prevent irritation behind the ears for mask wearers.

As we saw in the first screenshot, most of the file contains coordinate definitions starting on line 14. If we wanted to edit the file, say to change the object color, we might want to switch to XMLSpy Grid Editor view. Grid Editor view shows the hierarchical structure of XML documents and DTDs through a set of nested containers that can be easily expanded and collapsed. We’ll leave the container holding all the shape coordinates collapsed to focus on other document features and avoid accidentally changing any shape values.

The screenshot below shows what happens in the Grid Editor if we double-click the Shape element:

XMLSpy opens a pop-up entry helper that lists all the other schema-defined elements that are valid children of the Group element at this location in the file. This would be good to know if you are assigned to create or modify a prototype .x3d file for a CAD workspace or a scene in a first-person immersive game.

Let’s change the color of the object defined in this file. When we click to edit the values for the diffuseColor attribute of the Material element, XMLSpy offers the default value based on the XML Schema. We can either accept the default value or type in a new entry.

Editing the .x3d file in XMLSpy Grid View

XMLSpy includes an option to validate .x3d files during editing. If we type 3 3 3 and try to save the file, XMLSpy immediately detects an error:

Validate .x3d files with detailed error explanation messages

The values for this attribute must each be less than 1. We can enter 0.3 0.2 0.1 and reload the image in the H3D Viewer:

The object is now a bronze shade instead of blue.

Other files on the NIH site and elsewhere demonstrate other X3D applications. Shown below is the chemical model for remdesivir, a possible treatment for Ebola and Covid-19. This shape is defined very differently from the ear saver:

An .x3d file describing the chemical structure of remdesivir

If you’re brave enough you can even confront the enemy of all mankind:

.x3d to JSON

The Web3D Consortium is nearing completion of a standard for storing X3D in JSON format and has released an XSL stylesheet to convert .x3d files to JSON. XMLSpy includes the very fast RaptorXML XSLT 3.0 processor, which you can use with the Web3D XSL stylesheet to try out file conversion.

First, we can change the default file extension in the XMLSpy Options dialog for XSLT processing:

XMLSpy Options dialog for XSL processing

We also deselected the Validate XML files option, since we’ve been continuously validating during edit.

Then, with an .x3d file open, either press the F10 key or choose XSL transformation under the XSL/XQuery menu.

The transformation occurs and the resulting JSON file opens in a new window. The image below shows the JSON document generated from the NIH  face mask ear saver, in XMLSpy Text view and in JSON Grid Editor view:

If you need to examine, edit, or validate .x3d files, check out the XMLSpy demos page for more videos and in-depth tutorials on the Grid Editor and many other XMLSpy features. When you’re ready to immerse yourself in a 3D environment defined by an .x3d file, download an XMLSpy free, 30-day trial.

Tags: , , , ,
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *