Three JS and Physics Behavior Testing
Lab1 - Some shadow testing.
Lab1 experiments with shadow effects and keyboard control. The
small cube is the "test subject". There is a small octahedron on the
forward facing face so that you can keep track of your orientation. This
lab is not "mobile device friendly" except for when using Orbital Controls
because I have not incorportated any kind of pointer select with grab/drag
features (future lab). The following keys control the small cube's behavior:
Key |
Behavior |
w |
Move 1 unit forward. |
s |
Move 1 unit backward. |
a |
Move 1 unit left. |
d |
Move 1 unit right. |
q |
Roll 1 unit left. |
e |
Roll 1 unit right. |
r |
Yaw 1 unit left. |
f |
Yaw 1 unit right. |
z |
Pitch 1 unit down. |
x |
Pitch 1 unit up. |
space |
Move 1 unit up. |
c |
Move 1 unit down |
o |
Switch to Orbital Controls mode: hold left button down to rotate, hold right button down to move camera, use wheel to zoom in and out. |
p |
Switch to Object Perspective mode (3D first-person for small cube). There is no Zoom while in this mode. |
Lab2 - Our solar system to scale.
This lab begins to setup our solar system to scale. For now I have
placed both the sun and the earth into the scene, together with a ship.
- Added dat.UI, which is a simple UI component. I've added movement and view controls, which will be handy for non-keyboard use case.
- Added a reticle for the forward view.
- Added highlighting for when acceleration or rotation in a particular direction is active.
- All units are metric. Distance is measured in km.
- The acceleration slider configures how much acceleration will be applied when one of the movement controls is activated. Acceleration ranges from .1 G to 80 G.
- Added Targets. Currently there are two targets: Earth, Sun. Selecting a target rotates the forward view in that direction; subsequent acceleration in forward
direction will accelerate toward target.
- Fixed bug when using target option.
- Increased Acceleration maxiumum from 8 to 80.
- A big source of confusion for me was the difference in the coordinate system convention used by Blender and Three. Both are right handed, but in Blender, the "y" axis
points into the screen, the z axis is vertical, and the x axis is horizontal; whereas in Three, the x axis is horizontal, the y axis is vertical, and the z axis points out
of the screen. Also, in Three, the "get world direction" method returns the direction coordinates for the local z component of an object. I used Thing children cameras to
fix orientation of the object that I created in Blender, but originally I did not compensate for the differences in the coordinate systems (this is what caused problems with
the target option). If defining "forward" for a Blender object by using a camera, it's important for the forward direction of the object to be aligned with the "y" axis,
in the negative direction, so that when it is ported into Three, the forward direction will be pointing in the positive "z" direction (which is what Three will use when
computing the global direction vector for an object). Alternatively, I could rotate the object after importing it into Three so that I don't need to worry about orientation
within Blender.
Key |
Behavior |
g |
Translate ship to Sun location. |
b |
Translate ship to Earth location. |
p |
Change view to ship perspective. |
l |
Change view to closeup of sun. |
t |
Change view to earth. |
o |
Change view to sun at distance. |
1 |
Forward Ship View |
2 |
Backward Ship View |
3 |
Left Ship View |
4 |
Right Ship View |
5 |
Top Ship View |
6 |
Bottom Ship View |
Lab3 - Our solar system to scale with gravity.
This one is fun! Put yourself in LEO and enjoy the view as you whip around the Earth at 7 km/s.
Fun factoid: humans can only handle approximately 2 G for any sustained period of time. Anything over 2 G starts to get very uncomfortable. Something like 80 G -- which is what the acceleration
slider will allow you to use for the shp -- would kill a human. So, if you want a "realistic" experience, keep acceleration below 2 G. It will give you an appreciation for the distances and object sizes
in this simulation. Also, when you can only accelerate at 2 G, or maybe 3 G, mistakes in your navigation will become apparent when you try to postion the ship into an orbit :) 80 G is for wusses unless you
are travelling to the sun (which would be masochistic at anything slower than 80 G :))!
As a reminder, for now there is no managed session state, so a page refresh or any navigation from simulation page, will reset everything.
-
Added "Align To Target" option to align to currently selected target.
-
Added gravity. Both the sun and earth gravity are accounted for in the motion mechanics.
-
Added a crude collision mechanic: if the ship collides with either the Earth or Sun, its
position and velocity are set back to initial conditions (i.e. earth view). It is possible to "cheat" collision at extremely high velocities :p
-
Added "Target Distance" to Target Control. This is distance from ship to center of target. TODO change so that distance is measured from ship to SURFACE of target.
-
Added "Radial Speed" to Target Control.
-
Added "TVOR - Speed" to Target Control. TVOR is my acronym for Transverse Velocity Orbital Requirements. The TVOR values help to manually enter a stable orbit. TVOR Speed is the transverse Speed
needed for a stable circular orbit at the current target radius. Because of interpolation errors, it turns out the actual simulation speed at LEO (Low Earth Orbit) is about 0.7 km/s less than TVOR Speed,
something to keep in mind if you are trying to get into a stable orbit. In one of my test runs, I got into a fairly stable orbit at 9,666 km (atual distance from earth center), with a Forward Speed of 6.42 km/s
(TVOR Speed indicated 7.1 km/s, but that is a little too fast because of simulation errors).
At that speed, I had a slow positive radial speed (tending toward negative) of 0.0098 km/s.
-
Added "TVOR - Alignment" to Target Control. TVOR Alignment is 1.0 when the Up direction vector is exactly parallel to the radial direction vector. This is the most important value to look at when managing
orbital entry. The procedure I used goes like this when starting a new session:
(1) Pitch up until the earth is centered in the "down" (key 6) view. Get TVOR Alignement as close to "1" as you can. The closer to "1" the more aligned your up direction vector is with the vector
directed from earth to your ship. To make small pitch/yaw/roll adjustments, use the key commands (z, x, q, e, r, f).
(2) Max out the acceleration to 80.
(3) Accelerate down, "Move Down", until you get within a few thousand km of LEO. LEO is any oribt 2000 km or less, which means a radial distance of 8400 km or less. I fudged a little and aimed for an orbit
of 9600 km. Make sure to "Move Up" well before you reach your desired altitude :)
(4) Every time you want to apply thrust in any direction, first get TVOR Alignment as close to 1 as you can (this will likely mean periodically doing a "pitch up/down").
(5) Move Forward until the forward speed matches TVOR Speed. What you want is Forward Speed = Speed = TVOR Speed, with Radial Speed as close to zero as you can get. In reality though, Forward Speed will need
to be less than TVOR Speed to reach a stable orbit (one where the radial speed is changing very slowly).
(6) Periodically dampen any small velocity in the "Left" direction axis (i.e. keep value as near to zero as possible).
(7) If all goes well and yo are in a stable orbit, all you need to do is periodically pitch down to bring TVOR Alignment near to 1 and then perform small adjustments to forward speed if necessary. When I have
placed the ship in LEO, once I got the initaial orbit stable, I did not have to make any adjustements (other than pitching down for the correct orientation). My radial distance fluctuated between 9666 km
and 9832 km, which I think is pretty damn good! On the second orbit, minimun distance was 9535 km, so the oribit is not perfectly circular, which is not a surprise. Not sure how stable the orbit is either.
-
Added "TVOR - Yaw" to Target Control. "Yaw" is a litle misleading, but I use it because if the up vector is aligned with the target radial vector, yaw changes are what most likely will cause your forward
direction to be pointing differently than the forward veloctity vector (TVOR Yaw is simply the DOT product of your ship forward direction vector with the ship velocity direction vector, and since
you are keeping Up normal to your desired velocity, it will be yaw motion or Left acceleration that make TVOR Yaw vary from 1.0). If you have applied any Move Left in this procedure, chances are you will
need to correct your yaw or roll if TVOR Yaw is not close to 1. In general though, you should not need to make adjustments for yaw/roll if you kept your ship Up direction vector perfectly aligned with the
earth radial vector (i.e. you kept TVOR Alignement as close to 1 as possible when applying any movment controls). Don't use TVOR Yaw to make any corrections until after stabalizing TVOR Alignment (usually
by making adjustments to pitch); you will find that when TVOR Alignment is near 1, so is TVOR Yaw, unless you have velocity that is not transverse to rotational plane.
-
Added Info section.
Moved global position vector and velocity vector of ship to here. Use "show" to refresh values. TODO Add gravitational acceleration values (earth and sun).
-
TODO Add moon.
-
TODO Define your standard for object orientation and use it to apply rotations when using gltf.
-
TODO Add a camera to view ship.
Lab4 WIP attempt to stop with ESC
This lab is also the index reference.
Lab5 An axample from ThreeJS that I'm using to test with go templates...
Lab6 Javascript testing
A place to sample snippets of javascript to test compatibility.
Also a place to view icons.
Lab7 Galaxy testing
Lab8 Lab7, but using particle shader... Standard Galaxy
Lab9 Lab7, but using particle shader... Large Galaxy
Lab10 Lab7, but using particle shader... Standard Galaxy with particle size effect
Lab8 is a decent representation of a spiral galaxy with modest memory requirements (about 4mb).
There are around 10,000 stars in the galaxy.
Lab9 is a large galaxy with over 136000 stars with large memory requirement of 12mb.
Lab 10 shows particle effect using shader to continuously alter the size of a star.
Test galaxy generation.
I use a Fermat Spiral to model a galaxy. In particular, see "The golden ratio and the golden angle."
The other types to be added later: logarithmic spiral, Archimedean spiral, an x cubed shape, and a spherical shape distribution.
Variables for procedural generation will include galactic ecliptic inclination, stellar ecliptic inclination, stellar type, planetary and asteroid density, and much more.
The next step is to create a procedural generator on the backend that will (1) generate the galaxy list, (2) generate and persist stelar information, (3) generate planets and moons.
This next work will include API REST endpoints for retrieving a galaxy star list.
Interaction starts with Galaxy map. User then can drill in on a particular galaxy to view stars, then click on stars to view planetary systems.
Left clicking on an element will select it. Right clicking on element will generate an option menu object.
Improve the Fermat Spiral by introducing pseudo random offsets to the star locations to give a more natural look.