instantreality 1.0

Hello world in X3D

tutorial, X3D, world, hello world, XML encoding
Author(s): Peter Eschler
Date: 2005-11-10

Summary: This tutorial shows you how to create a "Hello world!" in X3D

What we need

This tutorial will show you how to write the famous "Hello world!" program in X3D. All you need is a text-editor and a X3D-browser.

How we do it

First start up the text-editor and enter the following code:

Code: The simplest X3D world

<?xml version="1.0" encoding="UTF-8"?>
<X3D profile='Immersive'>

Save the file and call it simple.x3d

Sweet! You just created the most simplest X3D world possible - an empty one. You can check that it is empty by opening it with your favourite X3D browser and watch if the browser gives any warnings. If he does consult the browser documentation if it supports the X3D XML encoding - some browser might only support the X3D Classic VRML encoding.

Understanding the code

Let's have a look at the code:

<?xml version="1.0" encoding="UTF-8"?>

This is the XML file declaration and it's used for easy identification. The file declaration should be present in every valid XML file so just copy-and-paste it there.

The file declaration is followed by the X3D document root element which specifies a profile:

<X3D profile='Immersive'>

A complete overview of the profiles concept can be found in the X3D specification. Simply put it tells the browser which kind of nodes the world uses so that the browser can check if he supports the profile (and the nodes associated to that profile). The Immersive profile used here is targeted at "implementing immersive virtual worlds with complete navigational and environmental sensor control"

Next comes the empty Scene element:


In the following we will put some text into our scene.

Show the words

What is missing in our world is the content. Since we want the two words "Hello world!" in fully blown 3D we add the following Text element to the Scene so that the code now looks like this:

Code: Hello world! in X3D

<?xml version="1.0" encoding="UTF-8"?>
<X3D profile='Immersive'>
      <Text string="Hello world!" />

We added a Shape which contains a Text geometry - and that's it! Save the file to helloworld.x3d and start it up. The words "Hello World" should be shown by your X3D browser.

You could now continue to play around with the Text, e.g. changing the depth or the fontStyle.



This tutorial has no comments.

Add a new comment

Due to excessive spamming we have disabled the comment functionality for tutorials. Please use our forum to post any questions.