Tutorials on Various 3D Programming
General Tips
Creating an orbit for a planet and place the planet on it
To create a planetary orbit and place a planet on it so that one can calculate precise position of the planet at a given time can be done by using Orbital Elements. You can read detailed information about them from this wikipedia page. In this guide, I will show detailed steps on how to do the calculation and implement it in Blender or Unity.
There are six parameters in orbital elements that are closely related to the 3-D positions and 3-D velocity of a planet.
- semi-major axis ($a$): determines the size of an orbit. For a given mass of the central object (e.g., Sun), $a$ is directly related to an orbital period ($P$) through Kepler's 3rd law.
- eccentricity ($e$): shape of the ellipse. In an elliptical orbit, Sun is located at one of two foci.
- inclination ($i$): the tilt angle of the orbital plane with respect to observer's line of sight.
- longitude of the ascending node ($\Omega$): In an inclined orbit (i.e., non-zero $i$), there are two points where a planetary orbit crosses the plane of reference. We choose one of these points as $\Omega$ where a planet moves from below the reference planet to above the plane.
- argument of periapsis ($\omega$): determines the orientation of the ellipse in the orbital plane. From the focus where the Sun is located at, the direction toward the periapsis can be anywhere on the plane. An angle measured from the ascending node to the periapsis can fix the orientation of the ellipse.
- true anomaly ($\nu$): the position of the planet measured in angle from the periapsis for a given time (or epoch).
Calculation
Check the Wikipedia for “Orbit Modeling” for useful information.
From a given set of orbital elements, let's see how we can calculate the planet's position at a given time $T$. At any arbitrary epoch (say $T=0$), orbital elements can be expressed as $(a_0,e_0,i_0,\Omega_0,\omega_0,\nu_0)$. Since the first five parameters do not change over time (without a perturbation like additional object), at a later time ($T+\delta T$), we only need to find the new $\nu$; i.e., at $T=T+\delta T \equiv new$, we have $(a_0,e_0,i_0,\Omega_0,\omega_0,\nu_{new})$ where $\nu_{new}=\nu_0 + \delta\nu$.
In this calculation, the reference plane is denoted as $(\hat{I},\hat J,\hat K)$ where $\hat I$ is the direction toward the vernal equinox and the orbital plane is denoted as $(\hat x,\hat y,\hat z)$ where $\hat x$ is toward the periapsis and $\hat z$ is toward the north pole. In the Solar System, we choose the ecliptic plane as the reference plane.
Then, the transformation between the reference plane and the orbital plane is defined by three Euler rotations.
where the new $xyz$ values are
There is a Python package called pyorb that can calculate Keplerian (i.e., $xyz$) from reference ($IJK$) or vice versa.
A good introduction on the whole calculation step (and the visualization of the orbital elements) is available from this YouTube video.
Check this YouTube video for Keplerian orbital elements and Euler Angles: https://www.youtube.com/watch?v=bgFaDDt0Rn4
Blender Tips
This introduction to blender documentation prepared by Michael Cai will be useful for students new to 3D programming.
Here is the link to the shared document. And here is the link to all shared Blender files.
Use this link to convert the Google Doc tutorial shown above to a dw content. https://cgcookie.com/ offers many Blender tutorials. </panel>
Useful tips for creating objects in the Blender night sky
- You need to download relevant NASA star maps and link them in the node editor to see the starry background.
- In Blender rendering, because we are rendering only the changes of the background pixelated images (and no 3-D object), we can turn off ray tracing (Render → Light Paths → max bounce = 1) and set the cycles render's sampling to be 1 (Sampling → Render → Max Samples = 1). Then, it should take less than 10 sec per scene (~20 min rendering for 240 frame animation).
See these examples for creating a virtual, realistic, night sky in Blender:
- Horizon + Mountain + Real nightsky from NASA: here (watch from 19m:10s)
- Create bright Sun“ Sun
- Check this GitHub page which provides “Blender-CelestialSimulator” with Python: https://github.com/Yuxiza/Blender-CelestialSimulator
- https://www.youtube.com/watch?v=RY2_Lhfy53M This simulates 1000 nearby stars. However, this is a collection of 1000 objects (i.e., stars) not a real simulation of the Celestial Sphere.
- There was a relevant question but answers to the question are not helpful.https://blender.stackexchange.com/questions/179119/guidance-on-creating-a-celestial-sphere
- https://blenderartists.org/t/using-blender-to-make-a-real-life-celestial-globe/683089 Not the same one we are trying to build. This attempt is trying to project onto the outer surface area contrary to out case of projection to the interior surface of the Celestial sphere. Again, no helpful info in the answer.
- https://blendermarket.com/products/real-world-starsky-generator This one is listed in the Blender market (for $12). This is close to what we intend to create. ⇒ Can we purchase this one and modify it to fit our need? What's the license term?
- Check this 3D Star Map Add-on in Blender which uses a dataset of real nearby ~3,000 stars. This also shows how to simulate a night sky (i.e., celestial sphere). A free demo version has 299 stars without constellation markings. ⇒ This shows a good tip on how to display texts on the scene (text fixed with respect to a camera)
- NASA image as the HDRI background with constellation lines: Blender-Night-Sky ⇒ This demo also provides a Blender file that shows tips on how to use dynamic camera control (i.e., dynamically changing camera position, origin [i.e., camera field-of-view], etc.)
- Blender 3.? and later versions provide a Geometry Node which can be used in simulating a planet in a orbit around its central star. Check this tutorial: https://www.youtube.com/watch?v=9haf_JsqKlY. Using orbital elements from JPL (https://ssd.jpl.nasa.gov/planets/approx_pos.html), one can do a decent planetary orbit simulation.
- Check this GitHub page https://github.com/markus-ebke/SolarSystemSimulator showing a Blender package for simulating Solar System from orbital elements.
- This package can simulate an orbit of a planet around a central star with all user-configurable physical parameters (mass, rotation rate, rotation axis tilt angle, orbital elements, etc.).
- This package also display animated orbital elements annotations in the 3D render.
Simulate/Visualize Orbital Motions
- Solar System Simulator has a good tool to create and visualize a Keplerian orbiting system from orbital elements: https://github.com/markus-ebke/SolarSystemSimulator
- https://github.com/japhir/visualise-orbitN uses the output of orbitN (A symplectic integrator for planetary systems dominated by a central mass; 2024 AJ) and visualize in Blender. Positions of planets are likely accurate.
Blender Add-ons for Space Scene
- Check this YouTube video introducing 6 add-ons (https://www.youtube.com/watch?v=We6xdvd-7u8). None of these are free though.
Python in Blender
Good tutorials from YouTube on Python in Blender
- Watch this first if you are new to Blender: https://www.youtube.com/watch?v=Rqhtw7dg6Wk:Blender in 20min
- Watch this first if you are new to Python scripting in Blender: Getting Started with Scripting in Python
- Good intro in general and how to make an addon with Python: Python Crash Course for Blender
- Cool animation, collections, and context: Animation with Python in Blender
Unity Tips
There is a free asset called, SimplerKeplerOrbits, in the Unity asset store. It has three sample scenes and we can use this package to create a nice Solar System simulation. Especially, check Example 3 in the included scenes which allows users' tilting and zooming actions in the rendered window (i.e. in the GamePlay mode), and it also allows to set the observing date (set to “now” automatically). There is a UI slider that can speed up and go backward in time as well. Nice! We can recycle most of these in our 3-D model.
We can create a realistic Solar System model with three free Unity assets (Simple Kepler Orbits, Planets of the Solar System, and MilkyWay). Follow the sequence of operations below to create one.
- Start a new 3D Unity project
- Set project setting (Edit → Project Settings; pay attention to Graphics [Rendering], Quality etc.)
- Import necessary assets (Package Manager: Install assets from My Assets)
- In the main camera setting, choose the right Renderer and select “Post Processing”. Choose the MilkyWay skybox (drag one on the main camera).
- Create three objects (two spheres and one object). You can drag and drop Sun and Earth from “Planets of the Solar System”. One sphere is an attractor (i.e., the central star), the other sphere is an orbiting object (e.g., Earth), and the 3rd object is a velocity indicator.
- Drag and drop “KeplerOrbitMover” script on the orbiting object. Drop “KeplerOrbitLineDisplay” on the orbiting object as well if orbits need to be displayed with curves.
- Then, select the central object as the attractor and set the right mass value.
- Set velocity handle, length scale, and time scale.
- Render and you can see an animation.
- For faster script load, check “Fast Script Reload” asset.
Procedural (Script-based) Sun-Earth-Moon Model Creation
Sample WebGL model of the Sun-Earth-Moon System
This embedded WebGL rendering of the Sun-Earth-Moon system created with Unity can be played in any modern web browser. The right mouse button can tilt/rotate the scene, the middle mouse button scroll adjusts a zoom level. Click the image below to access the model.
Setup VR with a Quest Headset
Steps:
- Create a Meta account
- Enable Developer mode
- Enable Quest Link
- Meta Quest Developer Hub (MQDH)
MicroSoft also has this tutorial: MS + Quest
Creating AR
Render 2+ camera views
Create cameras as you need. Then, change the “Viewport Rect” (Width and Height and X & Y) to set the desired location and size you need. In the render view then, you will have more than one camera views.
Display UI info and tools
You can add many UI components in three different ways in Unity by changing the “Render Mode”: (1) screen overlay (always displayed on screen), (2) camera space (displayed over camera view), and (3) world space (as if they are regular objects).
Unreal Engine Tips
Space scene in Unreal Engine 5.x
Check these tutorials for UE5
- Various tutorials for UE5 (asteroid belt, Solar System, Nebular, Neutron Stars, Blackhole, etc.): https://www.youtube.com/playlist?list=PL3h9_2VztKEFm-WauCP9n_m3fNBqRruAR
- Step-by-step tutorial for creating Solar System in UE5: https://www.youtube.com/playlist?list=PL6jMdZzbgqlCumwccHDRHyW_5m6fOluom
- Create User Interface in UE5: https://www.youtube.com/watch?v=kM27HYbpvc0