rskynet is a small program written in Rust language. Although its name is Skynet, it is indeed a small program with less than a thousand lines of code, and there will be no more code in the future. The reason why I wrote this program is to get familiar with the Rust language and to visualize some of my 3D data. The predecessor of rskynet was a script written in Python 3 called hamal [1]. The functions of the two are basically the same, but it is easier for rskynet to select the observation direction of the 3D scene, because it realizes one of my original ideas [2], that is, on the bounding sphere of the scene, the observation direction is constructed in the way of longitude and latitude.
Source code acquisition and compilation
$ git clone https://gitee.com/garfileo/rskynet.git
$ cd rskynet
$ rustc -O rskynet.rs
usage
In the rskynet/data directory, I provide 5 3D data files as examples, whose types are point set (points.asc), vector set (vectors.asc), line segment set (paths.asc), axial box set ( boxes.asc), surface meshes (mesh.off), to visualize them, just
# 渲染点集
$ rskynet --points points.asc
$ povray +A +P points.pov
# 渲染矢量集
$ rskynet --vectors vectors.asc
$ povray +A +P vectors.pov
# 渲染路径集
$ rskynet --paths paths.asc
$ povray +A +P paths.pov
# 渲染轴向盒集
$ rskynet --boxes boxes.asc
$ povray +A +P boxes.pov
# 曲面网格
$ rskynet --mesh mesh.asc
$ povray +A +P mesh.pov
What does rskynet output?
Taking the point set as an example, input the point set file foo.asc into rskynet, that is
$ rskynet --points foo.asc
rskynet can output the following files in the current directory:
.
├── foo.inc
├── foo.ini
├── foo_object.inc
├── foo.pov
└── foo_view.inc
Among them, foo.pov is used to summarize the contents of other files to form a complete 3D scene.
The content of foo.pov generated by the above example is as follows:
#version 3.7;
#include "colors.inc"
global_settings {assumed_gamma 1.0}
// 相机参数(可根据需要,自行修改)
#declare sky_u = 0;
#declare sky_v = 0;
#declare theta = 0;
#declare odc = 3; // Object distance coefficient.
// 系统参数(不建议自行修改)
#declare bs_center = <-0.278, 4.010, -2.365>; // 包围球中心
#declare bs_r = 156.802; // 包围球半径
#declare sky_r = odc * bs_r; // 天球半径
// 点、矢量、线段的尺寸参数
#declare point_size = 0.0025 * sky_r;
#declare line_width = 0.75 * point_size;
#declare arrow_size = point_size;
#include "foo_view.inc"
#include "foo_object.inc"
Even if you are unfamiliar with the POV Ray scene language, you only need to know that the following parameters determine the viewing orientation of the 3D scene:
// 相机参数(可根据需要,自行修改)
#declare sky_u = 0;
#declare sky_v = 0;
#declare theta = 0;
#declare odc = 3; // Object distance coefficient.
Among them, sky_u
and sky_v
represent the longitude and latitude of the scene surrounding the sphere. If the value is positive, it represents east longitude and north latitude, and negative numbers represent west longitude and south latitude. theta
represents the camera tilt angle, positive numbers tilt to the right, and negative numbers tilt to the left. odc
odc
to determine the size of the scene's bounding sphere. When its value is 1, the scene's bounding sphere is approximately the bounding sphere of all 3D data in the scene. You can control the magnification and Zoom out.
3D observation
The following image is the rendering result based on the default camera parameters:
If the camera's longitude parameter is modified to
#declare sky_u = 90;
Then the rendering result becomes:
Modify the camera tilt angle parameter to
#declare theta = -90;
The rendering result becomes
If sky_u
and theta
are fixed, and the value of sky_v
2036290f3cb731ffdabed1384973761d---is fixed, it is equivalent to viewing the graph in each dimension on the longitude of 90 degrees east.
If the value of odc
is reduced, part of the three-dimensional data can be observed. In order to see the point data at close range, the value of point_size
can also be increased, for example:
#declare odc = 0.3;
... ... ...
#declare point_size = 0.01 * sky_r;
The following results are obtained:
When constructing the observation azimuth through latitude and longitude and camera inclination, it is important to remember that the default initial azimuth is that both latitude and longitude are 0, and the tilt angle of the camera is zero, which is equivalent to the position where the latitude and longitude of the camera is 0 at the equator, and the head is facing due north. , looking down. If the camera is moved to other latitude and longitude coordinates, and its top is tangent to the meridian and points to the north, you need to put yourself in the position and think about how to adjust the camera's inclination to obtain the desired viewing orientation.
Epilogue
If you think rskynet is useful, you'd better learn some basic knowledge of POV Ray, believe me, it's not that difficult, just try it out.
Rust is not easy to use, especially generics. It seems that I hope that everyone should not use generics when writing code... In contrast, I still like C and feel that I am helpless.
addendum
There is a small work implicit in rskynet. When rendering the point set, a texture provided by POV Ray to simulate rust is used, which is named "Rust". It just so happens that rskynet is written in Rust, so the texture's name is fitting.
In the subdirectory data of the rskynet source directory, there is the mesh.off file, which contains the surface mesh data. Process this data using rskynet, i.e.
$ rskynet --mesh mesh.off
In the generated mesh_object.inc file, there is the following code:
#include "textures.inc"
#include "mesh_mesh.inc"
object {
mesh_data
texture {pigment {color Gray50}}
}
#include "mesh_vertices.inc"
object {
mesh_vertices_data
texture {Rust scale 0.3 * sky_r}
}
//#include "mesh_edges.inc"
//object {
// mesh_edges_data
// texture {pigment {color Gray}}
//}
As you can see, the texture for the vertex set of the surface mesh is texture {Rust scale 0.3 * sky_r}
.
I wanted to use Rust textures for surface rendering. After trying, I found that it would make the surface details difficult to distinguish, and sometimes the rendering results would look weird, for example
This kind of rendering effect made me want to change to other textures for a while, but suddenly thought that if the texture is applied to the point set, the discreteness of the point set should help to disintegrate the weirdness of this look and feel. as shown
[1] https://segmentfault.com/a/1190000011922854
[2] https://segmentfault.com/a/1190000037675299
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。