Monday, October 26, 2015

Astromech Updates - Speculars & Physics

Time for some more pretty pictures, screenshotted just now from Astromech in the other window:

In Soviet Russia, Caffeine goes inside of you!
Recognize it? It's my second favorite molecule, the one that's powered much of Astromech's development so far. The still shot doesn't entirely do it justice, so I'll have to make a video shortly. Watching the molecule "fold up" from its usual flat schematic is a small revelation.

And yes, that's the "Starship Imagination" lurking in the background. You'll be seeing a lot of it. (You gotta have somewhere comfy to sit, when contemplating the universe.)

The colours? Blue is nitrogen, red is oxygen, grey/white is carbon. Most of what you're looking at are the 'P' orbitals overlapping. Oxygen has two coloured 'lobes' available for bonding, nitrogen has Three, Carbon of course has the full set of four. Things are scaled so a hydrogen atom's 1S orbital would be about a meter across, so the entire molecule is about the 'size' of a small building.

This is not your normal ball-and-stick molecular model, and yes it's harder to see the core structure as a result... but nature isn't as neat and tidy as our schematics would prefer. This is my own small attempt to better show the reality of what a molecule "looks like", if you could shrink yourself to its scale. Ghost-like waves of probability dominate, not little billiard balls.


Sensors are reading Wake-up-juice, Captain! We're saved!
There's been several advances in the code required to make all this happen:

- Scripting System
- Multiple scene models
- Physics Engine
- Specular Shaders (for that 'shiny' look)

In particular, the molecule is a huge "hinge and spring" system built with the cannon.js physics engine, with imported Blender 3D assets for each atom.

In fact, since I like to show the code, here's the part of the script that assembles the molecule:


{"collada":{ "id":"hydrogen", "url":"asset/collada/atomic/hydrogen.dae", "transform":"scale(0.75)" }},
{"collada":{ "id":"oxygen",   "url":"asset/collada/atomic/oxygen.dae",   "transform":"scale(0.75)" }},
{"collada":{ "id":"nitrogen", "url":"asset/collada/atomic/nitrogen.dae", "transform":"scale(0.75)" }},
{"collada":{ "id":"carbon",   "url":"asset/collada/atomic/carbon.dae",   "transform":"scale(0.75)" }},

{"collada":{ "id":"carbon",   "model":"translate(  0 -1 -20)" }}, {"physics":{ "model":"carbon.1", "proxy":{ "type":"sphere", "radius":2 } }},
{"collada":{ "id":"carbon",   "model":"translate(  0  9 -20)" }}, {"physics":{ "model":"carbon.2", "proxy":{ "type":"sphere", "radius":2 } }},
{"collada":{ "id":"carbon",   "model":"translate( 16  4 -20)" }}, {"physics":{ "model":"carbon.3", "proxy":{ "type":"sphere", "radius":2 } }},
{"collada":{ "id":"nitrogen", "model":"translate(  8 12 -20)" }}, {"physics":{ "model":"nitrogen.1", "proxy":{ "type":"sphere", "radius":2 } }},
{"collada":{ "id":"nitrogen", "model":"translate(  8 -4 -20)" }}, {"physics":{ "model":"nitrogen.2", "proxy":{ "type":"sphere", "radius":2 } }},

{"collada":{ "id":"carbon",   "model":"translate( -8 12 -20)" }}, {"physics":{ "model":"carbon.4", "proxy":{ "type":"sphere", "radius":2 } }},
{"collada":{ "id":"carbon",   "model":"translate(-16  0 -20)" }}, {"physics":{ "model":"carbon.5", "proxy":{ "type":"sphere", "radius":2 } }},
{"collada":{ "id":"nitrogen", "model":"translate( -8 -6 -20)" }}, {"physics":{ "model":"nitrogen.3", "proxy":{ "type":"sphere", "radius":2 } }},
{"collada":{ "id":"nitrogen", "model":"translate(-16  8 -20)" }}, {"physics":{ "model":"nitrogen.4", "proxy":{ "type":"sphere", "radius":2 } }},
{"collada":{ "id":"oxygen",   "model":"translate( -8 20 -20)" }}, {"physics":{ "model":"oxygen.1", "proxy":{ "type":"sphere", "radius":2 } }},
{"collada":{ "id":"oxygen",   "model":"translate(-20 -6 -20)" }}, {"physics":{ "model":"oxygen.2", "proxy":{ "type":"sphere", "radius":2 } }},

{"collada":{ "id":"carbon",   "model":"translate(-8 -12 -20)" }}, {"physics":{ "model":"carbon.6", "proxy":{ "type":"sphere", "radius":2 } }},
{"collada":{ "id":"carbon",   "model":"translate(-20 12 -20)" }}, {"physics":{ "model":"carbon.7", "proxy":{ "type":"sphere", "radius":2 } }},
{"collada":{ "id":"carbon",   "model":"translate( 16 18 -20)" }}, {"physics":{ "model":"carbon.8", "proxy":{ "type":"sphere", "radius":2 } }},

{"physics":{ "constraint":[
{"type":"point", "force":0.1, "from":{"model":"carbon.1", "point":[0,4,0]},  "to":{"model":"carbon.2", "point":[0,0,4]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.1", "point":[0,0,4]},  "to":{"model":"carbon.2", "point":[0,4,0]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.1", "point":[4,0,0]},  "to":{"model":"nitrogen.2", "point":[0,0,4]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.1", "point":[-4,0,0]}, "to":{"model":"nitrogen.3", "point":[4,0,0]}},

{"type":"point", "force":0.1, "from":{"model":"carbon.2", "point":[0,4,0]},  "to":{"model":"nitrogen.1", "point":[0,0,4]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.2", "point":[-4,0,0]}, "to":{"model":"carbon.4", "point":[4,0,0]}},

{"type":"point", "force":0.1, "from":{"model":"carbon.3", "point":[0,4,0]},  "to":{"model":"nitrogen.1", "point":[4,0,0]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.3", "point":[0,0,4]},  "to":{"model":"nitrogen.2", "point":[0,4,0]}},

{"type":"point", "force":0.1, "from":{"model":"carbon.4", "point":[0,4,0]},  "to":{"model":"oxygen.1", "point":[0,4,0]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.4", "point":[0,0,4]},  "to":{"model":"oxygen.1", "point":[4,0,0]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.4", "point":[-4,0,0]}, "to":{"model":"nitrogen.4", "point":[4,0,0]}},

{"type":"point", "force":0.1, "from":{"model":"carbon.5", "point":[0,0,4]},  "to":{"model":"nitrogen.3", "point":[0,4,0]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.5", "point":[0,4,0]},  "to":{"model":"nitrogen.4", "point":[0,0,4]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.5", "point":[-4,0,0]}, "to":{"model":"oxygen.2", "point":[4,0,0]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.5", "point":[4,0,0]},  "to":{"model":"oxygen.2", "point":[0,4,0]}},

{"type":"point", "force":0.1, "from":{"model":"carbon.6", "point":[0,4,0]},  "to":{"model":"nitrogen.3", "point":[0,4,0]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.7", "point":[0,0,4]},  "to":{"model":"nitrogen.4", "point":[0,0,4]}},
{"type":"point", "force":0.1, "from":{"model":"carbon.8", "point":[-4,0,0]},  "to":{"model":"nitrogen.1", "point":[0,4,0]}},

{"type":"spring", "length":40, "force":0.001, "from":{"model":"carbon.1"},  "to":{"model":"carbon.3"}},
{"type":"spring", "length":40, "force":0.0001, "from":{"model":"carbon.1"},  "to":{"model":"carbon.4"}},
{"type":"spring", "length":40, "force":0.0001, "from":{"model":"carbon.1"},  "to":{"model":"carbon.5"}},
{"type":"spring", "length":40, "force":0.0001, "from":{"model":"carbon.1"},  "to":{"model":"carbon.6"}},
{"type":"spring", "length":40, "force":0.0001, "from":{"model":"carbon.1"},  "to":{"model":"carbon.7"}},
{"type":"spring", "length":40, "force":0.0001, "from":{"model":"carbon.1"},  "to":{"model":"nitrogen.1"}},
{"type":"spring", "length":40, "force":0.0001, "from":{"model":"carbon.1"},  "to":{"model":"nitrogen.4"}},
{"type":"spring", "length":30, "force":0.001, "from":{"model":"carbon.6"},  "to":{"model":"oxygen.1"}},
{"type":"spring", "length":40, "force":0.001, "from":{"model":"carbon.6"},  "to":{"model":"carbon.3"}},
{"type":"spring", "length":20, "force":0.001, "from":{"model":"carbon.7"},  "to":{"model":"oxygen.1"}},
{"type":"spring", "length":20, "force":0.001, "from":{"model":"carbon.7"},  "to":{"model":"oxygen.2"}},
{"type":"spring", "length":40, "force":0.001, "from":{"model":"carbon.8"},  "to":{"model":"oxygen.2"}}
]}},

A little chunky, but that's it. Really. And yes, this is a rather fake system using springs to 'prop open' the molecule rather than simulating all the interatomic repulsive forces, but hey, you need to have room to improve.

No comments:

Post a Comment