3d models with x3dom

I was looking for a way to bring existing 3d models that I’d created in other programs into webpages so that they could be rotated and manipulated without the need for the original software. There are solutions out there but they are not always very helpfully documented, so I thought I’d summarise what I’ve learned so far!

There are two main approaches to 3d graphics for the web, declarative and imperative. Essentially, as far as I understand it, the declarative approach (SVG for 2d, X3Dom for 3d) simply declares the object and lo! it appears, whereas in the imperative approach (canvas for 2d, WebGL for 3d) objects are created via JavaScript functions. Of course the reality and the pros and cons of each approach are clearly more complicated than this, but for a relatively simple model, and where functions are not going to be re-used, the declarative approach is certainly appealing. The crystallographic programs VESTA and KrystalShaper, in which I had created many models, export in the VRML format, which has been superseded by X3D, the language that is used by X3Dom. The 3D modelling program Art of Illusion, in which I had created a small number of models, exports in VRML as well as two other formats, while Blender has a wide variety of import and export formats. The workflow for making the models ready for use in webpages therefore consisted of importing the VRML files in Blender and re-exporting in X3D format, which could be inserted into HTML code with minor modifications. The X3Dom approach involves the use of a JavaScript file and a CSS file. These can either be downloaded and stored in local folders or called directly from the x3dom.org server. There is some sample code on the x3dom.org tutorial page. Documentation for X3Dom exists but there appears to be a pretty steep learning curve between including simple primitives and importing and manipulating complex models built in other programs. Perhaps the expectation is that most of the modelling work will have been done elsewhere. However, from my own experience, the models cannot be used exactly as-imported; instead, they do need some manipulation, and hence some understanding of x3d syntax is necessary. One of the main difficulties I had was finding out which primitives can be used, hence this post! The picture below shows the five primitives: cylinder (yellow), box (red), sphere (blue), plane (green) and cone (magenta). More complex shapes can be specified as “indexed face sets”. The code required to generate the image above is as follows:

<x3d width=”1200px” height=”700px”>
<material diffusecolor=”1 0 0″></material>
<transform translation=”-3 0 0″>
<material diffusecolor=”0 1 0″></material>
<plane solid=”false”></plane>
<transform translation=”3 0 0″>
<material diffusecolor=”0 0 1″></material>
<transform translation=”0 -3 0″>
<material diffusecolor=”1 1 0″></material>
<transform translation=”0 3 0″>
<material diffusecolor=”1 0 1″></material>

Note the similarity to HTML and that the ordering of items (“nodes”) is somewhat counterintuitive – we first have to open a tag declaring where an item will be translated to, then open a second tag declaring that a shape is present, then describe its appearance and only then declare what sort of shape it is!

Many aspects, for example the size of the elements and the position of the viewport, are set by default, allowing us to set up an initial scene with very few lines of code and then subsequently to refine it.

Another aspect of note is that, by default, the plane element, as obtained by simply using <plane></plane>, has the property ‘solid=”true”‘. This means that is we rotate to look at the reverse side of the plane, it will no longer be visible. To make the plane visible from both sides, set its property to <plane solid=”false”></plane>.

A  screenshot of one of the crystallographic models exported from VESTA can be seen below:

Close-packing models (part 2)

As mentioned in Part 1, the Balls and Sticks software can be used to create attractive models to illustrate the two common close-packed structures as well as more complex models based on these. For functionality that is not available in Balls and Sticks, such as plotting lattice planes and crystal faces or exporting vector graphics or three-dimensional data, the .CIF files exported from Balls and Sticks can be imported into VESTA. Note that the colour and atomic radius data used for the elements in Balls and Sticks is not preserved in VESTA, and these must be manually set up if required. Using VESTA you can add lattice planes as shown to illustrate where the close-packed planes are: and you can export data in the 3D format .wrl which can (with some conversion and manipulation) be used to make rotatable 3D models that can be used in other applications (including directly in web pages – more on this in a subsequent post).

Close-packing models (part 1)

Many metals have either a hexagonal or cubic close-packed structure. To illustrate how this structure is made up, I constructed models in which the two or three different close-packed layers, in hexagonal and cubic close-packed structures, respectively, are displayed in different colours. The models are created using “Balls and Sticks” (see this post). In order to obtain these colours, a different, larger unit cell must be used instead of the conventional cell, and two different elements are needed in the case of HCP, or three in the case of CCP. I used Mg, Co and Ti to obtain the colours in these images. The images above are obtained by increasing the values of the “boundaries” in the x, y and z directions so that the unit cell is repeated. Models for the structures above can be obtained in the Balls and Sticks native file format here: http://eutextik.one/resources/CCP_model.BS http://eutextik.one/resources/HCP_model.BS or in the universal CIF file format (which can be opened with other programs) here: http://eutextik.one/resources/CCP_model.CIF http://eutextik.one/resources/HCP_model.CIF You can use the same type of procedure (with a much more complex and larger unit cell in the z-direction!) to produce models of  ccp-hcp martensitic transformation and twinning: Advantages of Balls and Sticks are that it is easy to to learn and produces high-quality, aesthetically pleasing graphics. However, it lacks certain functionality that is provided by other programs such as VESTA (of which more later).

Verbs (an introduction)

Basic structure: 4 forms

  1. Present/infinitive (adding ‘s’ in 3rd person singular)
  2. Simple past (meaning of ‘simple’ analogous to French, meaning ‘single’)
  3. Past participle (in regular verbs, this is same as simple past)
  4. Present participle (-ing form)

Use of auxiliaries

1. tense-forming auxiliaries

to be to have to do will (‘to be going to’) or shall + not

2. modal-type (c.f. German)

want to ought to be able to (can) like to Whereas Japanese, for example, piles things on the end of verbs, English piles them on the beginning: e.g. have not been doing… will have been doing… etc.

Active, passive, interrogative, imperative

Active voice

This is used for a normal statement of fact: The dog bit the man.

Passive voice

The man was bitten (by the dog). This gives a shift of emphasis; the agent – in this case the dog – may be unknown or irrelevant. This form is often used in scientific writing: The liquid was stirred. (For the purposes of a scientific report, it should be irrelevant who stirred it.) There are many other uses including to shift/minimise blame: The vase was broken rather than I broke the vase (!)

Interrogative (question) form

This is the form used in asking a question. It is formed by reversing the personal pronoun and the verb, for certain auxiliary verbs: It is. -> Isn’t it? Otherwise it is formed by adding the corect form of ‘to do’: You do it. -> Do you do it? You like it. -> Do you like it? He likes it. -> Does he like it?

Imperative (command) form

This is the form for giving commands. It is formed by removing the personal pronoun. Have a nice day! Go to bed!

Subjunctive mood

This is somewhat difficult to recognise in English (compared to in French, German and other languages) but it does exist. It is used to represent desires, opinions and purposes rather than objective facts. For most verbs, the form of the subjunctive is the same as that of the indicative (usual) form. However, the second-person singular form loses the ‘s’ or ‘es’. I recommend that you study hard. I recommend that he study hard. The exception is the verb ‘to be’ where the subjunctive for all persons is ‘be’. I recommend that he be awarded the prize. He recommends that I be awarded the prize.


These are sentences describing a condition and a consequence, usually including the word ‘if’. There are different forms depending on how likely the event is. If the MP resigns, there will be an election. (Direct consequence) If the MP resigned, there would be an election. (Possible but less likely) If the MP had resigned, there would have been an election. (Counterfactual – did not happen)    

Tenses (3) The simple present perfect “I have done…”

This tense is formed using the simple present of the verb ‘to have’ + the past participle I, you, we, they have seen, done, been, finished… he, she, it has seen, done, been, finished… It is used to connect the past and the present. It is especially used for finished actions in the past that are important in the present. Because of this, it is often used in news reports.


A. Examples from today’s news (from BBC News, http://news.bbc.co.uk) (Present perfect) 1. “Zimbabwe’s opposition leader has said that his country is facing a bleak future…” 2. “Burma’s military rulers have extended the detention under house arrest of opposition leader Aung San Suu Kyi, government officials have said.” 3. (talking about more distant past events) “Since his election a year ago, the Pope has been to southern Italy and to his native Germany…” (Present perfect + passive) 1. “Colombia’s President Alvaro Uribe has been re-elected in a landslide election victory…” 2. “Former Israeli Prime Minister Ariel Sharon has been moved from hospital to a specialist care centre in Tel Aviv.” B. Examples from daily life: past events with results/consequences in the present 1. Event: I have lost my car keys. Consequence: I can’t get into my car. 2. Event: He has broken his arm. Consequence: He can’t play baseball. 3. Event: You have passed your exams! Consequence: You can go to university. 4. Event: Our visitors have just arrived. Consequence: We must entertain them. 5. Event: He has never studied any foreign languages. Consequence: He can’t speak or read any foreign languages The present perfect is not used when referring to a specific time in the past , such as yesterday, this morning, last week, in January, in 2003, and questions of the form ‘When did …?’ It is used with expressions which refer to a time period starting in the past and continuing up to the moment of speaking, such as ever, never, recently, often, already, yet. Q: Have you ever been abroad? A (negative): No. / No, never. / No, I have never been abroad. A (positive): Yes. / Yes, I have been to Australia. / Yes, I went to Thailand in 2003. Q: Have you finished your work yet? A (negative): No, not yet. A (positive): Yes. / Yes, I have already finished it. / Yes, I finished it this morning.

Tenses (2): The simple past and past progressive (or continuous)

Revision of present tenses

A. Simple present:

Habitual action, permanent or long-term state 1. I go to work by bus. 2. Japan is in Asia.

B. Present continuous or progressive:

Current, short-term action, changing situation 1. I am working hard on my project (short-term continuous action) 2. The weather is getting warmer (changing)

Past tenses: simple and progressive past

There is a similar situation in the past tense. (There are other past tenses than these too, but we’ll look at them another time.)

A. Simple past:

I, he, she, it went, worked, bought, saw, was you, we, they went, worked, bought, saw, were Used to talk about actions in the past; often used with an expression giving information about when the action took place: 1. Mr. Smith lived in Australia from 1999 to 2003. He went back there to visit friends last year. 2. I watched television until 9 p.m. yesterday evening, then I did my homework, had a bath and went to bed. This is also the past tense most often used in stories and other written accounts: * “The Rabbit … TOOK A WATCH OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on.” (Lewis Carroll, “Alice’s Adventures in Wonderland”)

B. Past progressive

This is formed in the same way as the present progressive, except that it takes the simple past form of the verb ‘to be’: I, he, she, it was doing you, we, they were doing Used to talk about an action that was happening: * around a certain time in the past * before another action occurred 1. Policeman: What were you doing at 8 p.m. yesterday? Man: I was at home, watching television with my family. 2. I was dreaming I was on holiday when the alarm clock rang and I had to get up for work. 3. What were they saying about me before I arrived? Can be used for ‘setting the scene’ in a story (often in conjunction with an action in the simple past which interrupts the continuous action): The sun was shining, the birds were singing, and I was walking along the road thinking happily to myself about what I would do that day, when a huge monster suddenly appeared!

Tenses (1) – the present

There are two present tenses in English: the simple present and the present continuous or progressive.

Present continuous

This uses the appropriate form of the verb ‘to be’ followed by the infinitive + –ing. This -ing form is called the present participle (sometimes also the active, imperfect or progressive participle). I am working you, we, they are working he, she, it is working

Negative form

The negative form is made by adding the word ‘not’ between the part of the verb ‘to be’ and the present participle: I am not working you, we they are not working he, she it, is not working

Interrogative (question) form

This is made by reversing the order of the personal pronoun and verb: It is raining? -> Is it raining? You are working -> Are you working?

Simple present

This is formed from the infinitive of the verb, with an ‘s’ added in the third person singular (he, she, it): I, you, we, they work he, she, it works The negative form is made by adding ‘do not’ between the person and the verb. I, you, we, they do not work (this can be shortened to don’t in informal or spoken English) In addition, in the third person singular, we need to modify the endings of the verbs. ‘Do’ is the main verb in this sentence and takes the third-person singular form, ‘does’. ‘Work’ is now an auxiliary verb and loses the ‘s’. he, she, it does not work The imperative (command) form uses the verb without a personal pronoun: Go to bed! Please take a seat. Negative commands are made by inserting ‘do not’ before the verb. (Please) do not walk on the grass. Do not worry! / Don’t worry! Note to Japanese readers in particular: in English, it’s usual to add ‘please’ only when asking people to do something that may be inconvenient to them, or in more official situations. (Note that the ‘please’ is sometimes left off for reasons of space on signs.) Please wait here. Please take a seat. (Please) do not walk on the grass./(Please) keep off the grass. If you are using the imperative form to tell people to do something that they are likely to enjoy or benefit from, particularly in an informal situation, it’s much less common to add the ‘please’: Have a nice time! Have fun! Enjoy yourself! Feel free to ask if you need anything. (Please) help yourself to drinks and cake.

Interrogative (question) form

This is formed by adding the correct form of the verb ‘to do’ before the verb. You like ice-cream. -> Do you like ice-cream? For the third-person singular, ‘to do’ takes the form ‘does’ and what becomes the auxiliary verb loses its ‘s’ or ‘es’: It works. -> Does it work?

What is the difference between the two forms?

The present continuous is used for short-term or temporary states and changing situations: 1. What are you doing? I’m writing a report. 2. My car is making a strange noise. 3. The weather is getting better. 4. The world’s population is increasing. 5. Prices are increasing. The simple present is used for permanent or long-term states and things which occur repeatedly or frequently. 1. The earth revolves around the sun. 2. The JR Tohoku Line runs through Sendai. 3. We are Japanese. 4. I come to work by bus / I usually come to work by bus. 5. I play tennis every Wednesday. 6. Do you smoke? Some verbs are only normally used in the simple present form. Many of these are verbs describing thoughts, memories or feelings (believe, forget, remember, understand, like, love, hate, need, prefer, suppose, want, realise), but there are several others, too: belong, contain, matter, own. 1. Don’t worry – it doesn’t matter. 2. Do you remember your first day at school? 3. Do you realise that it is three years since we came here last? 4. I need some help. 5. I like milk but I hate cheese. 6. This pen belongs to me.

X-rays of flowers – weird, beautiful, weirdly beautiful

I found this set of X-ray photos of flowers by Hugh Turvey on the Telegraph website: http://www.telegraph.co.uk/news/science/picture-galleries/7922343/X-rays-of-flowers-by-Hugh-Turvey.html It turns out that Turvey is not the only person who has taken flower X-rays. Here is a set by Brendan Fitzpatrick:
Floral X-Rays by Brendan Fitzpatrick
and a set by Steven N. Meyers: http://www.xray-art.com/ but people had already thought of taking this sort of photos back in the 1930s:
A Radiologist’s X-Ray Photographs of Flowers from the 1930s
X-Ray Photographs From the 1930s Expose the Delicate Details of Roses and Lilies