[PYTHON] Story of making a virtual planetarium [Until a beginner makes a model with a script and manages to put it together]

What was made

2019121421085379.png

Items to do

  1. Before starting to make: About the concept
  2. Preparation to make a starry sky
  3. Make a starry sky
  4. Adjust the brightness
  5. Create a meteor effect ep. Footnote

0: Concept

I'd like to decline first because it's often misunderstood, but I don't want to create a beautiful starry sky. ** **

What I want to do here is ** "I want to reproduce outer space using a very flexible medium called VR" **. (Since it will be a little long, I will supplement this area with footnote 1.) After all, it may be clean as a result, but it is not the real purpose to clean it. (Footnote 2)

Catalog type

When making a planetarium, some information such as star position, brightness (magnitude), and in some cases color must be referred to. I'll leave the details to the footnote, but no matter how much you wear it sideways, you have to put thousands or more stars in the planetarium. Therefore, you have to bring those data from somewhere. If you want to make it by hand, you can make a copy of a star map such as Uranometria and make a hole, but it is preferable that the numbers are organized as shown in the table for computer use. This collection of data is called a star catalog, but these must be selected because there are many depending on the age and criteria of their creation. To give an example

There are various other catalogs. The above is the observation result with visible light, but there are also data with radio waves, infrared rays, and X-rays. In addition, there are really many catalogs from various viewpoints, such as the Gliese catalog created from the viewpoint of whether or not it is near the earth, and the Messier catalog that collects only galaxies and nebulae.

Examination of realization method

Since the number of stars that must be created as described above is enormous, it is extremely difficult to simply describe each star (and there are many more difficulties ...). Therefore, it was necessary to first consider and examine the realization method. Some of them are introduced below.

Catalog to use

Creating a planetarium doesn't start without deciding on a catalog. There are three things I can't give up this time,

  1. Insert more than enough stars to express the Milky Way (more than 1 million)
  2. In the future, stars can be operated interactively
  3. Touch the stars and look up at hand

I absolutely wanted to protect them. Therefore, the following specifications naturally became a must item.

  1. The basic catalog is tycho or gaia
  2. Catalogs of other wavelengths will be added later (SDSS, etc.)
  3. The celestial body to touch is Grise
  4. Additional extragalactic catalogs (such as galaxies and nebulae)

However, since it is difficult to combine exoplanets into one as a background VCI due to the capacity, we decided to make it as an add-on, and for the time being, 2 and 3 and 4 were postponed.

How to create a model

It turns out that we have to draw at least one million stars, but definitely ** first of all it can't be done manually. ** Therefore, I had no choice but to create a star with the help of a computer, but several methods were considered.

  1. Paste a texture on a simple model
  2. Represent with particles
  3. Make a star shape with a model

First, from the necessary requirements, 1 is out of the question (footnote 3). It seems that the number of polygons in 2 is small, so I thought it would be promising at first, but I gave up hearing that the processing of particles seems to be unexpectedly heavy (the calculation formula has already been created based on theory). Inevitably 3 was selected. Then, the question is how to create model data, but previous article becomes important. In the linked article, I used python with built-in blender to create geometric figures, which is an application of this. ** Catalog data is preprocessed a little with awk, read by blender built-in python, and based on that data, blender draws with bpy module. ** **

How to express brightness

** From the conclusion, it is expressed by the size of the model. ** ** You might be wondering why you would take such a roundabout way, but I'll explain it below.

You may think that brightness is easy if you play with the colors. However, there are circumstances where this is not the case. The brightness of a star is generally expressed in "magnitude", and the smaller the number, the brighter it looks. Excluding the celestial bodies in the solar system, the visible stars are said to be -1.5 for bright and +6 for dark at the limit of the human eye. You might think it's only about 8 steps, but by WH's law, human senses follow an exponential function. (The sound is the same, and the functions that appear in Nyafu-san's article are also included) The magnitude of a star (relative magnitude) is expressed as follows, with Vega in Lyra as a reference and Vega as a standard, or Polaris as 2.0 mag. (Footnote 5)

m_1 - m_2 = -\frac{5}{2} log_{10}\frac{b_1}{b_2}

There is a difference of 2.51 times by 1 arithmetic progression, and 994 times, that is, about 1000 times difference between -1.5 mag and +6.0 mag. There are 13 mag dark stars on tycho, so it's 1000 times more than 1 million times ...

On the other hand, HMD displays, like most displays, have gradations of only 8 bits, perhaps up to 255. Also, even if the gradation can be expressed only by color, the number of materials will die. Also, the number of models will increase, so don't do it. I think this can't change the brightness ...

In a general planetarium, this is expressed by the size of a star. The (physical) planetarium projects the light of the light bulb in the center of the equipment through the hole, but since the brightness of the light source is constant, if the size increases 2.51 times on an area basis, there is a difference of one grade. Can be expressed.

This method is very convenient because it does not increase the number of meshes, but it has one drawback: too bright objects become too large to be seen as stars anymore. Therefore, it is necessary to determine an appropriate celestial body (for example, the brightest star: Sirius, Venus, etc.) as the upper limit, and narrow down the size of that object to the limit where it looks like a star. And as we will see later, this will later set the limits for the VR planetarium.

python code

Based on the above, I made a star formation python code, so I will write about that code and the wall that I bumped into when I made it.

Code content

import bpy
from math import sqrt,pi,sin,cos,acos,asin,atan2
import csv

scale = 0.1*2.51*2.51
distance =30
nloop = 9
with open('D:\\Blender\\hipparcos_nolimit_DirectionCosine.dat') as f:
    reader = csv.reader(f)
    j = 1
    for i,row in enumerate(reader):
        l = [float(row[0]),float(row[1]),float(row[2]),float(row[3])]
        if(i<13000*nloop):
            continue
        
        if(l[0]<1.5):
            continue
            #ittousei dake mensekiha naositenai
            ngon = 12
 
        elif(l[0]<3.5):
            continue
            ngon = 6
   
        elif(l[0]<4.5):  
            continue
            ngon = 4
            
        else:
            ngon = 4
             

        bpy.ops.mesh.primitive_circle_add(vertices=ngon,fill_type='NGON',radius=scale*sqrt(10**((1-l[0])/2.5))/(sin(pi/ngon)*cos(pi/ngon)/2*ngon),
                                            location=(l[1]*distance,l[2]*distance,l[3]*distance),
                                            rotation=(0,-asin(l[3])-pi/2,atan2(l[2],l[1])))        

        
        if(i>100*j):
            bpy.ops.object.select_by_type(type = 'MESH')
            bpy.ops.object.join()
            j += 1
        if(i>13000*(nloop+1)):
            break
        
        
bpy.ops.object.select_by_type(type = 'MESH')
bpy.ops.object.join()    
    
#bpy.ops.view3d.snap_cursor_to_center()
#bpy.ops.object.origin_set(type='ORIGIN_CURSOR')           
    

Actually, this code alone is not a one-button. First, there is more than one model to generate. The model is divided into five parts, named first-class star, brighter, darker, darkest, and darkest2. Each is divided by brightness, but the reason is written in the phrase "Screen flicker" below. At that time, I am messing with variables and uncommenting them. The variable to be tampered with is scale, which is multiplied by 2.51 for each step when creating a dark star. Commenting out, as we'll see later, tweaks the look of the shape.

Also, for nloop, this is too slow to draw, so I partially draw the model halfway, save it, restart blender and increment nloop by +1 to go from 0 to 10. This is because blender does not free the memory, and at the end of drawing, even 48G of memory overflows. If you do not divide the drawing time, it will take several hours, and even if you divide it, it will take 20 minutes, so please be patient.

diet

At first, I was thinking of round points, but since 3D modeling is expressed by polygons, if you make a beautiful circle, the capacity will jump up. However, bright stars are fairly large, so if you make them into triangles, you will feel a great deal of discomfort. I struggled with this point because it was difficult to find in an actual planetarium. ** The solution was to model large stars close to circles such as hexagons and octagons, and lightly model small stars such as quadrangles and triangles **. I comment it out because it looks different depending on the brightness, so I am modifying it as appropriate. However, this method is not enough to simply change the vertex, you have to save the area. The coefficient a of the conversion formula is as follows when it is an n-sided polygon. l is the coefficient by brightness (in this case, the magnitude).

a=\frac{\sqrt{10^{((1-l)/2.5)}}}{(\sin(\pi/n)*\cos(\pi/n)/2*n)}

If you want to make fine adjustments, play with the scale.

It's too heavy!

In the early stages, I wanted to summon each star, so I made all the star objects separately. But it was too heavy. If you put in 800 pieces, it will be heavy and the screen will be messy, and in some cases the room will fall the moment you put it out, making it a vicious item. If it's too much, it seems that even uploading to TSO will be rejected, and ** it's surprisingly lighter if you use the combination of objects to combine them into one **. I realized that the weight of the operation is determined by the number of child objects, not the capacity.

Screen flicker

The above script initially generated for all grades, but a problem occurred. It seems that there is no problem with taking a video or an image, but when I look through the HMD, the screen flickers. It's difficult to explain because I've only experienced # Raito-san, but in short, it's ** unpleasant **. It's not such a universe! That's why I needed to cure it.

Apparently, I thought that the cause of this phenomenon was the processing when an object smaller than the pixel size of the HMD appeared on the screen. If there is an object A that is the same size as a pixel and has a surface brightness (brightness) S, and an object B that is half the size (area) of a pixel and has the same surface brightness S, it will look like The amount of light coming from that pixel should be Object A: S Object B: 0.5S respectively. In other words, it should be halved, but ** Apparently both are S in the virtual cast **. Moreover, because the grid between pixels is an invisible area, one of the causes is that any star may or may not be drawn when it appears in the adjacent pixel. The other is that the brightness is expressed by the size, so the brightness per unit area is constant, so all the stars that I wanted to darken are drawn with the maximum brightness, and originally the eyes are one grain. The number was too large because even the invisible stars could be seen as a single grain.

To be honest, I think this process is not good, and the relationship between "object A: S object B: 0.5S" above is ** to put it plainly, it's antialiasing. The point is that ** there is a high frequency of jaggedness with insufficient pixel count **, and I wonder what this is, of course, the calculation is heavy, but I think there are some aspects in the future. It's a problem that I want you to solve.

After all, it's a problem that can be solved without permission if the technology advances, so I'm not motivated to deal with it, but it's strange, so I decided to cure it. Since the cause is mainly when the model looks smaller than the pixel size, ** I adjusted the lower limit of the model size "to span at least 4 pixels" **. However, since I do not know the pixel size of each HMD, I did not calculate it and checked it with my own eyes while outputting stars many times. (Therefore, flicker may still remain on models with a resolution of oculus rift S or lower.) And ** The missing gradation of the grade expression depends on the bloom for the brighter one while maintaining the size. The upper limit of the adjustment was raised, and the lower one was solved by making multiple material colors so that dark stars could be expressed even with the same size. ** Because of this, the model is divided into first-class stars, bright, darker, darkest, and darkest2.

Linking emission and grade

2019112021513265.png

Because of the above brightness processing, I had to use the emissions properly, so I used MToon to investigate the emissions that I thought only as an aid at first. The stars made by the method examined in "Brightness expression method" were arranged side by side in a sensory test by playing with the emission value little by little. In short, I tested one by one to see if there was any discomfort that seemed to be different. It looks like the image above.

The result of the experiment is as follows.

emit +1 +2 +3 +4 +5 +6 +7 +8 +9 +10
grade -1 -2 -3 -4 -5 -6 -7

☓ is too bright to be used because it doesn't look like a starry sky. is what it means. It looks like the grade goes down by +1. It is difficult to put it out scientifically here, so I decided to believe it as I felt it.

Meteor effect: effekseer

I thought it would be easier to make if there was some kind of astronomical event, so I targeted the Gemini meteor shower. Then I had to do something about the meteor, but I decided to make the meteor with particles. To be honest, I'm not confident because I've been playing with particles for the first time, and I can't do much, but the composition is as follows.

image.png

I finally finished it

Since it is made as a background add-on, it can be adapted to any ** background VCI that is not surrounded by a dome. It feels good to put in a mountain (the photo is combined with Pio's VCI)![2019121520195342.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0 / 494837/6983ec94-5448-73e2-385f-9c8969f01725.png)

I have to put in 1 million in the future, but I have to solve it because the problem of the lower limit of brightness comes out ...

footnote

Footnote 1

In the first place, the planetarium was created for the purpose of educating the operation of planets that move differently from ordinary starry sky as the name suggests. ** After all, the first planetarium didn't have a starry sky **, for example, [Aise Aisinga Planetarium](https://ja.wikipedia.org/wiki/%E3%82%A8%E3%82%A4%E3%82] % BB% E3% 83% BB% E3% 82% A8% E3% 82% A4% E3% 82% B7% E3% 83% B3% E3% 82% AC% E3% 83% BB% E3% 83% 97 % E3% 83% A9% E3% 83% 8D% E3% 82% BF% E3% 83% AA% E3% 82% A6% E3% 83% A0) is a good example. To show it more realistically, the Deutsches Museum has installed a machine that projects it together with the starry sky that is the space around it.

It is this "flow" that I am thinking of doing, Planetarium without a starry sky → Planetarium with a starry sky As the jump-up was made by the Deutsches Museum, ** Planetarium where you can see the starry sky → I want to create an experience of a space where you can go back and forth between stars and do various things. ** ** In other words, in a word You said you would make a planetarium, that's a lie. Cosmorium is the one to make. ** I want to create outer space with stars **

Footnote 2

There are already many people who have pasted "space-like patterns" in the background to make them beautiful, so I don't want to make such things.

Footnote 3

I'm often asked the question, "Why don't you put a texture on it?" I talked about the lowest number of stars being 1 million, which is why. How much do you think the area ratio of the area with stars to the area without stars is? The stars are tremendously far apart, 10,000? Let's say that it is 100 times as much as it is. Then, at least 1 million x 100 = 100 million pixels will be required. ** Can you prepare such an image? ** And considering that the stars are relatively irregular and biased, 100 million pixels is not enough at all.

Footnote 4

I am often surprised by the number of stars in it, so I would like to add that the number of stars that humans can see is up to 6th magnitude, and it is said that it is about 6000 or 8000. Then what do you do with 100,000 or 2 million? I think there are some people who have questions like this. But it's not in vain at all. ** Invisible means that it cannot be recognized as an individual grain, and if many stars are close to each other, it will look vague, and the Milky Way can be seen **. (Extremely speaking, it is known that the intensity of light emitted by a single molecule or atom by thermal motion is high energy, but even the light of Ohisama is a collection of them. You can see the sun, right? You can see it if you gather a lot. Then, the limit that really affects the human vision that makes up the Milky Way is about a dozen magnitudes, and the number of stars is about 1 million (actually there is night sky light, and even darker ones are at night. It contributes to the light, but it is omitted because the story becomes too detailed). Was it difficult to understand? It's no wonder that, since the planetarium was born in its current form, it has been tied to the "6th grade limit theory" for about 100 years anywhere in the world, but only around 2000, Japan has it. Will be overcome by college students in Japan. His name is Takayuki Ohira. You may have heard of the word Megastar. The planetarium that projects up to a dozen grades created by him created a breathtakingly beautiful night sky and was very well received. It shook the industry and changed common sense. And now, the state-of-the-art planetariums of major manufacturers, which used to project at most 8,000 stars until a while ago, are now projecting more than 100 million stars at most.

Footnote 5

Strictly different. There was a time when it was a method like the notation, but since it has become clear that the brightness of most stars fluctuates, the brightness of multiple stars, which is the standard, is now measured and averaged by a fixed standard metering method. The way to do it is taken.

Recommended Posts

Story of making a virtual planetarium [Until a beginner makes a model with a script and manages to put it together]
The story of making a sound camera with Touch Designer and ReSpeaker
The story of making a tool to load an image with Python ⇒ save it as another name
Easy to try! A story about making a deep learning Othello and strengthening it until you beat yourself (Part 1)
How to put a lot of pipelines together and put them away at once
Script to tweet with multiples of 3 and numbers with 3 !!
From installing Flask on CentOS to making it a service with Nginx and uWSGI
I don't like to be frustrated with the release of Pokemon Go, so I made a script to detect the release and tweet it
Unzip a lot of ZIP-compressed files with Linux commands to UTF8 and stick them together
A story that makes it easy to estimate the living area using Elasticsearch and Python
A script that makes it easy to create rich menus with the LINE Messaging API
A story that makes it easier to see Model debugging in the Django + SQLAlchemy environment
Create a deploy script with fabric and cuisine and reuse it
The story of making a question box bot with discord.py
Overview of Python virtual environment and how to create it
Find the white Christmas rate by prefecture with Python and map it to a map of Japan
The story of making a standard driver for db with python.
I wrote a script to help goodnotes5 and Anki work together
The story of making a module that skips mail with python
Is it possible to enter a venture before listing and make a lot of money with stock options?
Upload data to s3 of aws with a command and update it, and delete the used data (on the way)