├── .gitignore
├── .vscode
└── .gitignore
├── OpenPolyphorm.ipynb
├── README.md
├── bin
├── .gitignore
├── ShareTechMono-Regular.ttf
├── UbuntuMono-R.ttf
├── capture
│ ├── .gitignore
│ ├── _denoise
│ │ ├── .gitignore
│ │ ├── .ipynb_checkpoints
│ │ │ └── .gitignore
│ │ ├── OpenPhysarumFiles.ipynb
│ │ ├── hdr2pfm.py
│ │ └── tonemap_hdr.ipynb
│ ├── _video_encode.bat
│ └── _videos
│ │ └── .gitignore
├── config.polyp
├── consola.ttf
├── cs_agents_sort.hlsl
├── data
│ ├── .gitignore
│ ├── BP
│ │ └── .gitignore
│ ├── Cathedrals
│ │ ├── .gitignore
│ │ └── pack_data_Cathedral.py
│ ├── Conduits
│ │ └── .gitignore
│ ├── Embeddings
│ │ └── .gitignore
│ ├── FRB
│ │ └── .gitignore
│ ├── MassiveNuS
│ │ ├── .gitignore
│ │ └── pack_MassiveNuS.py
│ ├── Poisson
│ │ ├── pack_data_Poisson.py
│ │ ├── poisson_256_2d.dat
│ │ ├── poisson_256_2d_3d_flattened.bin
│ │ ├── poisson_256_2d_3d_flattened_metadata.txt
│ │ ├── poisson_4096_2d.dat
│ │ ├── poisson_4096_2d_3d.bin
│ │ ├── poisson_4096_2d_3d_bias=3.0.bin
│ │ ├── poisson_4096_2d_3d_bias=3.0_metadata.txt
│ │ ├── poisson_4096_2d_3d_bias=4.0.bin
│ │ ├── poisson_4096_2d_3d_bias=4.0_metadata.txt
│ │ ├── poisson_4096_2d_3d_flattened.bin
│ │ ├── poisson_4096_2d_3d_flattened_metadata.txt
│ │ ├── poisson_4096_2d_3d_metadata.txt
│ │ ├── random_4096_3d.bin
│ │ ├── random_4096_3d_bias=3.0.bin
│ │ ├── random_4096_3d_bias=3.0_metadata.txt
│ │ ├── random_4096_3d_bias=4.0.bin
│ │ ├── random_4096_3d_bias=4.0_metadata.txt
│ │ ├── random_4096_3d_metadata.txt
│ │ ├── regular_4096_3d.bin
│ │ ├── regular_4096_3d_bias=3.0.bin
│ │ ├── regular_4096_3d_bias=3.0_metadata.txt
│ │ ├── regular_4096_3d_bias=4.0.bin
│ │ ├── regular_4096_3d_bias=4.0_metadata.txt
│ │ └── regular_4096_3d_metadata.txt
│ ├── SDSS
│ │ ├── .gitignore
│ │ ├── galaxiesInSdssSlice_viz_bigger_lumdist_t=0.0.bin
│ │ └── galaxiesInSdssSlice_viz_bigger_lumdist_t=0.0_metadata.txt
│ ├── Zoe
│ │ ├── .gitignore
│ │ ├── 64-clean-JT-3Dskan_nobottom.blend
│ │ ├── 64-clean-JT-3Dskan_nobottom_n=38102.bin
│ │ ├── 64-clean-JT-3Dskan_nobottom_n=38102_metadata.txt
│ │ └── pack_data_Zoe.py
│ ├── affect_palettes.png
│ ├── palette_blue.tga
│ ├── palette_cliff3.tga
│ ├── palette_coldhot.tga
│ ├── palette_eagle.tga
│ ├── palette_eagle2.tga
│ ├── palette_gogh_blue.tga
│ ├── palette_gogh_green.tga
│ ├── palette_hot.tga
│ ├── palette_magma.tga
│ ├── palette_magneto2.tga
│ ├── palette_sunset2.tga
│ ├── palette_sunset3.tga
│ ├── palette_tropico.tga
│ ├── palette_vaneyck_green.tga
│ └── palette_vaneyck_red.tga
├── export
│ └── .gitignore
├── freetype271MT.dll
├── obj
│ └── .gitignore
├── ps_volume_halocolor.hlsl
└── renner-book.otf
├── build_and_run.bat
├── builder
├── CMakeLists.txt
├── bin
│ ├── .gitignore
│ ├── build.exe
│ └── obj
│ │ └── main.obj
├── build.bat
├── config.h
├── environment.cpp
├── file_system.cpp
├── hasher.cpp
├── main.cpp
├── memory.cpp
├── microsoft_craziness.h
├── parser.cpp
├── setup.bat
├── string.cpp
├── structs.h
└── sys_utils.cpp
├── cpplib
├── animation.cpp
├── animation.h
├── array.h
├── audio.cpp
├── audio.h
├── export.cpp
├── export.h
├── fbx_loader.cpp
├── fbx_loader.h
├── file_system.cpp
├── file_system.h
├── font.cpp
├── font.h
├── fonts
│ ├── ShareTechMono-Regular.ttf
│ ├── UbuntuMono-R.ttf
│ ├── consola.ttf
│ └── renner-book.otf
├── freetype
│ ├── include
│ │ ├── freetype
│ │ │ ├── config
│ │ │ │ ├── ftconfig.h
│ │ │ │ ├── ftheader.h
│ │ │ │ ├── ftmodule.h
│ │ │ │ ├── ftoption.h
│ │ │ │ └── ftstdlib.h
│ │ │ ├── freetype.h
│ │ │ ├── ftadvanc.h
│ │ │ ├── ftautoh.h
│ │ │ ├── ftbbox.h
│ │ │ ├── ftbdf.h
│ │ │ ├── ftbitmap.h
│ │ │ ├── ftbzip2.h
│ │ │ ├── ftcache.h
│ │ │ ├── ftcffdrv.h
│ │ │ ├── ftchapters.h
│ │ │ ├── ftcid.h
│ │ │ ├── fterrdef.h
│ │ │ ├── fterrors.h
│ │ │ ├── ftfntfmt.h
│ │ │ ├── ftgasp.h
│ │ │ ├── ftglyph.h
│ │ │ ├── ftgxval.h
│ │ │ ├── ftgzip.h
│ │ │ ├── ftimage.h
│ │ │ ├── ftincrem.h
│ │ │ ├── ftlcdfil.h
│ │ │ ├── ftlist.h
│ │ │ ├── ftlzw.h
│ │ │ ├── ftmac.h
│ │ │ ├── ftmm.h
│ │ │ ├── ftmodapi.h
│ │ │ ├── ftmoderr.h
│ │ │ ├── ftotval.h
│ │ │ ├── ftoutln.h
│ │ │ ├── ftpfr.h
│ │ │ ├── ftrender.h
│ │ │ ├── ftsizes.h
│ │ │ ├── ftsnames.h
│ │ │ ├── ftstroke.h
│ │ │ ├── ftsynth.h
│ │ │ ├── ftsystem.h
│ │ │ ├── fttrigon.h
│ │ │ ├── ftttdrv.h
│ │ │ ├── fttypes.h
│ │ │ ├── ftwinfnt.h
│ │ │ ├── t1tables.h
│ │ │ ├── ttnameid.h
│ │ │ ├── tttables.h
│ │ │ ├── tttags.h
│ │ │ └── ttunpat.h
│ │ └── ft2build.h
│ ├── win32
│ │ ├── freetype271.dll
│ │ ├── freetype271.lib
│ │ ├── freetype271MT.dll
│ │ └── freetype271MT.lib
│ └── win64
│ │ ├── freetype271.dll
│ │ ├── freetype271.lib
│ │ ├── freetype271MT.dll
│ │ └── freetype271MT.lib
├── graphics.cpp
├── graphics.h
├── input.cpp
├── input.h
├── logging.cpp
├── logging.h
├── maths.cpp
├── maths.h
├── memory.cpp
├── memory.h
├── oculus
│ ├── Extras
│ │ ├── OVR_CAPI_Util.h
│ │ ├── OVR_Math.h
│ │ └── OVR_StereoProjection.h
│ ├── LibOVR_d.lib
│ ├── LibOVR_r.lib
│ ├── OVR_CAPI.h
│ ├── OVR_CAPI_Audio.h
│ ├── OVR_CAPI_D3D.h
│ ├── OVR_CAPI_GL.h
│ ├── OVR_CAPI_Keys.h
│ ├── OVR_CAPI_Vk.h
│ ├── OVR_ErrorCode.h
│ └── OVR_Version.h
├── ovr.cpp
├── ovr.h
├── parsers.cpp
├── parsers.h
├── platform.cpp
├── platform.h
├── random.cpp
├── random.h
├── resources.cpp
├── resources.h
├── stack.h
├── stb_vorbis.c
├── ui.cpp
└── ui.h
├── docs
├── energy.png
├── mode_combined.png
├── mode_particles.png
├── mode_segmentation.png
├── mode_trace.png
├── proxy_shells.png
├── proxy_sightline.png
├── pt_aniso_red.png
├── pt_cool_blue.png
├── pt_pointlight.png
├── repo_card.png
├── title.png
├── title_vis2020.png
├── title_vis2020_narrow.png
├── title_vis2020_play.png
├── trim_combined.png
├── trim_particles.png
├── trim_segmentation.png
├── trim_trace.png
├── uc1_mapping.png
├── uc2_regions.png
├── uc3_absorption.png
├── uc3_galaxies.png
├── vis_options.png
└── vis_options_small.png
├── main.cpp
├── pack_data_celestial.py
├── polyphorm.build
├── polyphorm.code-workspace
└── shaders
├── cs_agents_propagate.hlsl
├── cs_agents_sort.hlsl
├── cs_density_histo.hlsl
├── cs_field_decay.hlsl
├── cs_particles_blit.hlsl
├── cs_particles_transform.hlsl
├── cs_volpath.hlsl
├── ps_particles_color.hlsl
├── ps_volpath.hlsl
├── ps_volume_halocolor.hlsl
├── ps_volume_highlight.hlsl
├── ps_volume_overdensity.hlsl
├── ps_volume_trace.hlsl
├── ps_volume_velocity.hlsl
├── vs_2d.hlsl
└── vs_3d.hlsl
/.gitignore:
--------------------------------------------------------------------------------
1 | /main_pt.cpp
2 | /data/
3 | *.code-workspace
4 |
--------------------------------------------------------------------------------
/.vscode/.gitignore:
--------------------------------------------------------------------------------
1 | /settings.json
2 |
--------------------------------------------------------------------------------
/OpenPolyphorm.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "view-in-github",
7 | "colab_type": "text"
8 | },
9 | "source": [
10 | "
"
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": null,
16 | "metadata": {
17 | "id": "G3XLl8CHiUJV"
18 | },
19 | "outputs": [],
20 | "source": [
21 | "import numpy as np\n",
22 | "import matplotlib.pyplot as plt\n",
23 | "from ipywidgets import interact # For plotting\n",
24 | "\n",
25 | "# Source and dimensions of the data\n",
26 | "DATA_FILE = 'trace.bin'\n",
27 | "BRICK_SIZE = [1024, 784, 416] # Look up the grid resolution in the metadata file exported by Polyphorm\n",
28 | "N_CHANNELS = 1\n",
29 | "\n",
30 | "# Other settings\n",
31 | "VIS_GAMMA = 0.2\n",
32 | "FIGSIZE = 10.0\n",
33 | "\n",
34 | "# Load raw dataset from HDD\n",
35 | "raw_data = np.fromfile(DATA_FILE, dtype=np.float16)"
36 | ]
37 | },
38 | {
39 | "cell_type": "code",
40 | "source": [
41 | "# Reshape and convert data to suitable format for visualization\n",
42 | "voxels_f16 = raw_data.reshape((BRICK_SIZE[2], BRICK_SIZE[1], BRICK_SIZE[0], N_CHANNELS)) # Mind the order of dimensions\n",
43 | "voxels_u8 = voxels_f16.astype(np.uint8) ** VIS_GAMMA\n",
44 | "\n",
45 | "# Visualize a single slice of the voxel data\n",
46 | "def plot_voxels_slice(slice, channel):\n",
47 | " plt.figure(figsize = (FIGSIZE, FIGSIZE))\n",
48 | " plt.imshow(voxels_u8[:,:,slice,channel])\n",
49 | "interact(plot_voxels_slice, slice=(0, BRICK_SIZE[0]-1, 1), channel=(0, N_CHANNELS-1, 1));"
50 | ],
51 | "metadata": {
52 | "id": "sMNQFl-6i6My"
53 | },
54 | "execution_count": null,
55 | "outputs": []
56 | },
57 | {
58 | "cell_type": "code",
59 | "execution_count": null,
60 | "metadata": {
61 | "id": "ICT9URmmiUJf"
62 | },
63 | "outputs": [],
64 | "source": [
65 | "# Threshold the data from below\n",
66 | "THRESHOLD = 5.0\n",
67 | "voxels_f16_thresholded = np.fmax(voxels_f16 - THRESHOLD, 0.0)\n",
68 | "voxels_u8_thresholded = voxels_f16_thresholded.astype(np.uint8) ** VIS_GAMMA\n",
69 | "\n",
70 | "def plot_voxels_slice_2(slice, channel):\n",
71 | " plt.figure(figsize = (FIGSIZE, FIGSIZE))\n",
72 | " plt.imshow(voxels_u8_thresholded[:,:,slice,channel])\n",
73 | "interact(plot_voxels_slice_2, slice=(0, BRICK_SIZE[0]-1, 1), channel=(0, N_CHANNELS-1, 1));"
74 | ]
75 | }
76 | ],
77 | "metadata": {
78 | "kernelspec": {
79 | "display_name": "Python 3",
80 | "language": "python",
81 | "name": "python3"
82 | },
83 | "language_info": {
84 | "codemirror_mode": {
85 | "name": "ipython",
86 | "version": 3
87 | },
88 | "file_extension": ".py",
89 | "mimetype": "text/x-python",
90 | "name": "python",
91 | "nbconvert_exporter": "python",
92 | "pygments_lexer": "ipython3",
93 | "version": "3.7.0"
94 | },
95 | "colab": {
96 | "name": "OpenPolyphorm.ipynb",
97 | "provenance": [],
98 | "collapsed_sections": [],
99 | "include_colab_link": true
100 | }
101 | },
102 | "nbformat": 4,
103 | "nbformat_minor": 0
104 | }
--------------------------------------------------------------------------------
/bin/.gitignore:
--------------------------------------------------------------------------------
1 | /cs_agents_propagate.hlsl
2 | /cs_density_histo.hlsl
3 | /cs_field_decay.hlsl
4 | /cs_particles_blit.hlsl
5 | /cs_particles_transform.hlsl
6 | /polyphorm.exe
7 | /ps_particles_color.hlsl
8 | /ps_volume_highlight.hlsl
9 | /ps_volume_overdensity.hlsl
10 | /ps_volume_trace.hlsl
11 | /ps_volume_velocity.hlsl
12 | /vs_2d.hlsl
13 | /vs_3d.hlsl
14 | /cs_volpath.hlsl
15 | /ps_volpath.hlsl
16 | *.tmp
17 |
--------------------------------------------------------------------------------
/bin/ShareTechMono-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/ShareTechMono-Regular.ttf
--------------------------------------------------------------------------------
/bin/UbuntuMono-R.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/UbuntuMono-R.ttf
--------------------------------------------------------------------------------
/bin/capture/.gitignore:
--------------------------------------------------------------------------------
1 | *.tga
2 | *.hdr
3 | *.png
4 | /final/
5 | /rotating/
6 | /tng_growth/
7 |
--------------------------------------------------------------------------------
/bin/capture/_denoise/.gitignore:
--------------------------------------------------------------------------------
1 | *.exr
2 | *.pfm
3 |
--------------------------------------------------------------------------------
/bin/capture/_denoise/.ipynb_checkpoints/.gitignore:
--------------------------------------------------------------------------------
1 | /OpenPhysarumFiles-checkpoint.ipynb
2 | /tonemap_hdr-checkpoint.ipynb
3 |
--------------------------------------------------------------------------------
/bin/capture/_denoise/OpenPhysarumFiles.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 4,
6 | "metadata": {},
7 | "outputs": [
8 | {
9 | "data": {
10 | "application/vnd.jupyter.widget-view+json": {
11 | "model_id": "9c3bf707e0af4e59adfe02ce3a4cab7f",
12 | "version_major": 2,
13 | "version_minor": 0
14 | },
15 | "text/plain": [
16 | "interactive(children=(IntSlider(value=327, description='slice', max=655), IntSlider(value=0, description='chan…"
17 | ]
18 | },
19 | "metadata": {},
20 | "output_type": "display_data"
21 | }
22 | ],
23 | "source": [
24 | "import numpy as np\n",
25 | "import matplotlib.pyplot as plt\n",
26 | "from ipywidgets import interact\n",
27 | "\n",
28 | "# Source and the X/Y/Z resolution of the data\n",
29 | "DATA_FILE = 'trace.bin'\n",
30 | "BRICK_SIZE = [656,1200,680]\n",
31 | "N_CHANNELS = 1\n",
32 | "\n",
33 | "# Load raw dataset from HDD\n",
34 | "raw_data = np.fromfile(DATA_FILE, dtype=np.float16)\n",
35 | "\n",
36 | "# Reshape and convert data to suitable formats\n",
37 | "voxels_f16 = raw_data.reshape((BRICK_SIZE[2], BRICK_SIZE[1], BRICK_SIZE[0], N_CHANNELS)) # Mind the order of dimensions\n",
38 | "voxels_u8 = voxels_f16.astype(np.uint8)\n",
39 | "\n",
40 | "# Visualize a single slice of the voxel data\n",
41 | "GAMMA = 0.2\n",
42 | "FIGSIZE = 10.0\n",
43 | "def plot_voxels_slice(slice, channel):\n",
44 | " plt.figure(figsize = (FIGSIZE, FIGSIZE))\n",
45 | " plt.imshow(voxels_u8[:,:,slice,channel] ** GAMMA)\n",
46 | "interact(plot_voxels_slice, slice=(0, BRICK_SIZE[0]-1, 1), channel=(0, N_CHANNELS-1, 1));"
47 | ]
48 | },
49 | {
50 | "cell_type": "code",
51 | "execution_count": null,
52 | "metadata": {},
53 | "outputs": [],
54 | "source": []
55 | }
56 | ],
57 | "metadata": {
58 | "kernelspec": {
59 | "display_name": "Python 3",
60 | "language": "python",
61 | "name": "python3"
62 | },
63 | "language_info": {
64 | "codemirror_mode": {
65 | "name": "ipython",
66 | "version": 3
67 | },
68 | "file_extension": ".py",
69 | "mimetype": "text/x-python",
70 | "name": "python",
71 | "nbconvert_exporter": "python",
72 | "pygments_lexer": "ipython3",
73 | "version": "3.6.12"
74 | }
75 | },
76 | "nbformat": 4,
77 | "nbformat_minor": 2
78 | }
79 |
--------------------------------------------------------------------------------
/bin/capture/_denoise/hdr2pfm.py:
--------------------------------------------------------------------------------
1 | ## needs the freeimage package installed to load/save high dynamic range images
2 | ## read more here: https://imageio.readthedocs.io/en/latest/formats.html
3 |
4 | import sys
5 | import imageio as iio
6 |
7 | for arg in sys.argv[1:]:
8 | hdr_image = iio.imread(arg + '.hdr', format='HDR-FI')
9 | iio.imwrite(arg + '.pfm', hdr_image, format='PFM-FI')
--------------------------------------------------------------------------------
/bin/capture/_video_encode.bat:
--------------------------------------------------------------------------------
1 | ffmpeg -r 30 -f image2 -start_number 18 -i ./frame%%d.tga -vcodec libx264 -f mp4 -pix_fmt yuv420p _videos/xxx.mp4
2 |
3 | REM -b:v 2.0M ...video bitrate
4 | REM -i vis2020_fitting_session.mp3
5 | REM -c copy
6 | REM -i "concat:vis2020_title.ts|vis2020_body.ts"
7 | REM -filter:v "crop=out_w:out_h:x:y"
8 | REM -t 20 (encode X seconds of video)
9 |
10 | REM docu: https://ffmpeg.org/ffmpeg.html
11 | REM combining two mp4s: https://stackoverflow.com/questions/7567713/combining-two-video-from-ffmpeg
12 | REM add audio: https://superuser.com/questions/590201/add-audio-to-video-using-ffmpeg
--------------------------------------------------------------------------------
/bin/capture/_videos/.gitignore:
--------------------------------------------------------------------------------
1 | *.mp4
2 | *.gif
3 |
--------------------------------------------------------------------------------
/bin/config.polyp:
--------------------------------------------------------------------------------
1 | Agents number = 10000000
2 | Grid resolution = 1024
3 | Grid padding = 0.1
4 | Screen X = 1800
5 | Screen Y = 1000
6 | Camera FOV = 30.0
7 | Histogram base = 10.0
8 |
9 | ## Anything below this line is ingored ##
10 |
11 | Screen X = 2000
12 | Screen Y = 1100
13 |
14 | Screen X = 1800
15 | Screen Y = 1000
16 |
17 | Screen X = 1400
18 | Screen Y = 850
--------------------------------------------------------------------------------
/bin/consola.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/consola.ttf
--------------------------------------------------------------------------------
/bin/cs_agents_sort.hlsl:
--------------------------------------------------------------------------------
1 |
2 | RWStructuredBuffer particles_x: register(u2);
3 | RWStructuredBuffer particles_y: register(u3);
4 | RWStructuredBuffer particles_z: register(u4);
5 | RWStructuredBuffer particles_phi: register(u5);
6 | RWStructuredBuffer particles_theta: register(u6);
7 | RWStructuredBuffer particles_weights: register(u7);
8 |
9 | cbuffer ConfigBuffer : register(b0)
10 | {
11 | float sense_spread;
12 | float sense_distance;
13 | float turn_angle;
14 | float move_distance;
15 | float deposit_value;
16 | float decay_factor;
17 | float center_attraction;
18 | int world_width;
19 | int world_height;
20 | int world_depth;
21 | float move_sense_coef;
22 | float normalization_factor;
23 | int n_data_points;
24 | int n_agents;
25 | int n_iteration;
26 | };
27 |
28 | struct RNG {
29 | #define BAD_W 0x464fffffU
30 | #define BAD_Z 0x9068ffffU
31 | uint m_w;
32 | uint m_z;
33 |
34 | void set_seed(uint seed1, uint seed2) {
35 | m_w = seed1;
36 | m_z = seed2;
37 | if (m_w == 0U || m_w == BAD_W) ++m_w;
38 | if (m_w == 0U || m_z == BAD_Z) ++m_z;
39 | }
40 |
41 | void get_seed(out uint seed1, out uint seed2) {
42 | seed1 = m_w;
43 | seed2 = m_z;
44 | }
45 |
46 | uint random_uint() {
47 | m_z = 36969U * (m_z & 65535U) + (m_z >> 16U);
48 | m_w = 18000U * (m_w & 65535U) + (m_w >> 16U);
49 | return uint((m_z << 16U) + m_w);
50 | }
51 |
52 | float random_float() {
53 | return float(random_uint()) / float(0xFFFFFFFFU);
54 | }
55 |
56 | uint wang_hash(uint seed) {
57 | seed = (seed ^ 61) ^ (seed >> 16);
58 | seed *= 9;
59 | seed = seed ^ (seed >> 4);
60 | seed *= 0x27d4eb2d;
61 | seed = seed ^ (seed >> 15);
62 | return seed;
63 | }
64 | };
65 |
66 | void swap_agents(uint idxA, uint idxB) {
67 | float tmp;
68 | tmp = particles_x[idxA]; particles_x[idxA] = particles_x[idxB]; particles_x[idxB] = tmp;
69 | tmp = particles_y[idxA]; particles_y[idxA] = particles_y[idxB]; particles_y[idxB] = tmp;
70 | tmp = particles_z[idxA]; particles_z[idxA] = particles_z[idxB]; particles_z[idxB] = tmp;
71 | tmp = particles_theta[idxA]; particles_theta[idxA] = particles_theta[idxB]; particles_theta[idxB] = tmp;
72 | tmp = particles_phi[idxA]; particles_phi[idxA] = particles_phi[idxB]; particles_phi[idxB] = tmp;
73 | tmp = particles_weights[idxA]; particles_weights[idxA] = particles_weights[idxB]; particles_weights[idxB] = tmp;
74 | }
75 |
76 | // Morton codes: https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/
77 | uint Part1By2(uint x_) {
78 | uint x = x_ & 0x000003ff;
79 | x = (x ^ (x << 16)) & 0xff0000ff;
80 | x = (x ^ (x << 8)) & 0x0300f00f;
81 | x = (x ^ (x << 4)) & 0x030c30c3;
82 | x = (x ^ (x << 2)) & 0x09249249;
83 | return x;
84 | }
85 |
86 | uint EncodeMorton3(uint x, uint y, uint z) {
87 | return (Part1By2(z) << 2) + (Part1By2(y) << 1) + Part1By2(x);
88 | }
89 |
90 | [numthreads(10,10,10)]
91 | void main(uint thread_index : SV_GroupIndex, uint3 group_id : SV_GroupID) {
92 | uint group_idx = group_id.x + group_id.y * 10 + group_id.z * 100;
93 | uint idx = thread_index + 1000 * group_idx;
94 |
95 | // uint idxA = 32 * idx + (n_iteration % 32);
96 | // if (idxA >= n_agents-1)
97 | // return;
98 | // uint idxB = idxA + 1;
99 | // idxA = idxA + (n_data_points-1);
100 | // idxB = idxB + (n_data_points-1);
101 |
102 | // float vA = particles_y[idxA];
103 | // float vB = particles_y[idxB];
104 | // if (vA > vB) {
105 | // swap_agents(idxA, idxB);
106 | // }
107 |
108 | RNG rng;
109 | rng.set_seed(
110 | rng.wang_hash(73*idx),
111 | rng.wang_hash(13*n_iteration)
112 | );
113 | uint idxA = n_data_points + rng.random_uint() % n_agents;
114 | uint idxB = n_data_points + rng.random_uint() % n_agents;
115 | float3 posA = float3(particles_x[idxA], particles_y[idxA], particles_z[idxA]);
116 | float3 posAN = float3(
117 | 0.5 * (particles_x[idxA-1] + particles_x[idxA+1]),
118 | 0.5 * (particles_y[idxA-1] + particles_y[idxA+1]),
119 | 0.5 * (particles_z[idxA-1] + particles_z[idxA+1]));
120 | float3 posB = float3(particles_x[idxB], particles_y[idxB], particles_z[idxB]);
121 | float3 posBN = float3(
122 | 0.5 * (particles_x[idxB-1] + particles_x[idxB+1]),
123 | 0.5 * (particles_y[idxB-1] + particles_y[idxB+1]),
124 | 0.5 * (particles_z[idxB-1] + particles_z[idxB+1]));
125 | float dA = length(posA - posAN);
126 | float dB = length(posB - posBN);
127 | float dApot = length(posA - posBN);
128 | float dBpot = length(posB - posAN);
129 | if ((dApot + dBpot) < (dA + dB)) {
130 | swap_agents(idxA, idxB);
131 | }
132 |
133 | // RNG rng;
134 | // rng.set_seed(
135 | // rng.wang_hash(73*idx),
136 | // rng.wang_hash(13*n_iteration)
137 | // );
138 | // uint idxA = (n_data_points - 1) + rng.random_uint() % n_agents;
139 | // uint idxB = (n_data_points - 1) + rng.random_uint() % n_agents;
140 | // // uint vA = EncodeMorton3(uint(particles_x[idxA]), uint(particles_y[idxA]), uint(particles_z[idxA]));
141 | // // uint vB = EncodeMorton3(uint(particles_x[idxB]), uint(particles_y[idxB]), uint(particles_z[idxB]));
142 | // float vA = particles_y[idxA];
143 | // float vB = particles_y[idxB];
144 | // if (idxA < idxB && vA > vB) {
145 | // swap_agents(idxA, idxB);
146 | // }
147 |
148 | // uint idxA = (n_data_points - 1) + idx;
149 | // uint idxB = idxA + n_agents / 2;
150 | // float vA = particles_z[idxA];
151 | // float vB = particles_z[idxB];
152 | // if (vA > vB) {
153 | // swap_agents(idxA, idxB);
154 | // }
155 | }
156 |
--------------------------------------------------------------------------------
/bin/data/.gitignore:
--------------------------------------------------------------------------------
1 | /TNG/
2 | /palette_electric.tga
3 | /palette_ignite.png
4 | /palette_ignite.tga
5 | /palette_plankton.png
6 | /palette_plankton.tga
7 | /palette_template.svg
8 | /sci_palettes.png
9 | /untitled.blend
10 | /untitled.blend1
11 |
--------------------------------------------------------------------------------
/bin/data/BP/.gitignore:
--------------------------------------------------------------------------------
1 | /bpdat_boxDist_trimDist_trimMass_t=0.05_subrate=1_ROTATED.bin
2 | /bpdat_boxDist_trimDist_trimMass_t=0.05_subrate=1_ROTATED_metadata.txt
3 |
--------------------------------------------------------------------------------
/bin/data/Cathedrals/.gitignore:
--------------------------------------------------------------------------------
1 | /AnkorWat.fbx
2 | /angkor_wat.blend
3 | /angkor_wat.mtl
4 | /angkor_wat.obj
5 | /angkor_wat_n=48207.bin
6 | /angkor_wat_n=48207_metadata.txt
7 | /angkor_wat_n=48259.bin
8 | /angkor_wat_n=48259_metadata.txt
9 | /notre_dame.blend
10 | /notre_dame.blend1
11 | /notre_dame.mtl
12 | /notre_dame.obj
13 | /notre_dame_n=44912.bin
14 | /notre_dame_n=44912_metadata.txt
15 | /pocillopora_eydouxi.blend
16 | /pocillopora_eydouxi.blend1
17 | /pocillopora_eydouxi.mtl
18 | /pocillopora_eydouxi.obj
19 | /pocillopora_eydouxi_n=22158.bin
20 | /pocillopora_eydouxi_n=22158_metadata.txt
21 | /pocillopora_eydouxi_n=222498.bin
22 | /pocillopora_eydouxi_n=222498_metadata.txt
23 | /pocillopora_eydouxi_n=74196.bin
24 | /pocillopora_eydouxi_n=74196_metadata.txt
25 |
--------------------------------------------------------------------------------
/bin/data/Cathedrals/pack_data_Cathedral.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import math as math
3 | import random
4 |
5 | # fileName = 'notre_dame'
6 | # scale_multiplier = 10.0
7 | # fileName = 'pocillopora_eydouxi'
8 | # scale_multiplier = 10.0
9 | fileName = 'angkor_wat'
10 | scale_multiplier = 5.0
11 | subsampling_factor = 5.0
12 |
13 | valid_pt_number = 0
14 | with open(fileName + '.obj') as f:
15 | lines = f.readlines()
16 | data = np.zeros((len(lines)-1, 4), dtype=np.float32)
17 | for i, line in enumerate(lines):
18 | if not (line[0] == 'v' and line[1] == ' '):
19 | continue # not a valid point
20 | if random.uniform(0.0, 1.0) > 1.0/subsampling_factor:
21 | continue # randomly throw out vertices
22 | line = line.split(' ')
23 | x = scale_multiplier * float(line[1])
24 | y = scale_multiplier * float(line[3])
25 | z = -scale_multiplier * float(line[2])
26 | weight = 1.0
27 | data[valid_pt_number, :] = [x, y, z, weight]
28 | valid_pt_number += 1
29 |
30 | if (valid_pt_number == 0):
31 | print('No points found')
32 | exit()
33 |
34 | filtered_data = np.zeros((valid_pt_number, 4), dtype=np.float32)
35 | filtered_data = data[0:valid_pt_number, :]
36 |
37 | print('Min/Max X: ' + str(np.min(filtered_data[:,0])) + ' ' + str(np.max(filtered_data[:,0])))
38 | print('Min/Max Y: ' + str(np.min(filtered_data[:,1])) + ' ' + str(np.max(filtered_data[:,1])))
39 | print('Min/Max Z: ' + str(np.min(filtered_data[:,2])) + ' ' + str(np.max(filtered_data[:,2])))
40 | print('Min/Max/Avg/Med weight: ' + str(np.min(filtered_data[:,3])) + ' ' + str(np.max(filtered_data[:,3])) + ' ' + str(np.mean(filtered_data[:,3])) + ' ' + str(np.median(filtered_data[:,3])))
41 | print('Sample record: ' + str(filtered_data[0,:]))
42 | print('Number of records: ' + str(valid_pt_number))
43 |
44 | output_file_name = fileName + '_n=' + str(valid_pt_number)
45 |
46 | metadata_file = open(output_file_name + "_metadata.txt", "w")
47 | metadata_file.write("Number of points = " + str(valid_pt_number) + "\n")
48 | metadata_file.write("Min X = " + str(np.min(filtered_data[:,0])) + "\n")
49 | metadata_file.write("Max X = " + str(np.max(filtered_data[:,0])) + "\n")
50 | metadata_file.write("Min Y = " + str(np.min(filtered_data[:,1])) + "\n")
51 | metadata_file.write("Max Y = " + str(np.max(filtered_data[:,1])) + "\n")
52 | metadata_file.write("Min Z = " + str(np.min(filtered_data[:,2])) + "\n")
53 | metadata_file.write("Max Z = " + str(np.max(filtered_data[:,2])) + "\n")
54 | metadata_file.write("Mean weight = " + str(np.mean(filtered_data[:,3])) + "\n")
55 | metadata_file.close()
56 |
57 | filtered_data = filtered_data.tofile(output_file_name + '.bin')
58 |
--------------------------------------------------------------------------------
/bin/data/Conduits/.gitignore:
--------------------------------------------------------------------------------
1 | /poisson_256_2d_conduits_n_levels=100_ratio=1.02.bin
2 | /poisson_256_2d_conduits_n_levels=100_ratio=1.02_metadata.txt
3 | /poisson_256_2d_conduits_n_levels=100_ratio=1.03.bin
4 | /poisson_256_2d_conduits_n_levels=100_ratio=1.03_metadata.txt
5 | /poisson_256_2d_conduits_n_levels=100_ratio=1.05.bin
6 | /poisson_256_2d_conduits_n_levels=100_ratio=1.05_metadata.txt
7 | /poisson_256_2d_conduits_n_levels=100_ratio=1.06.bin
8 | /poisson_256_2d_conduits_n_levels=100_ratio=1.06_metadata.txt
9 | /poisson_256_2d_conduits_n_levels=16_ratio=2.0.bin
10 | /poisson_256_2d_conduits_n_levels=16_ratio=2.0_metadata.txt
11 | /poisson_256_2d_conduits_n_levels=20_ratio=1.5.bin
12 | /poisson_256_2d_conduits_n_levels=20_ratio=1.5_metadata.txt
13 | /poisson_256_2d_conduits_n_levels=30_ratio=1.25.bin
14 | /poisson_256_2d_conduits_n_levels=30_ratio=1.25_metadata.txt
15 | /poisson_256_2d_conduits_n_levels=8_ratio=2.0.bin
16 | /poisson_256_2d_conduits_n_levels=8_ratio=2.0_metadata.txt
17 |
--------------------------------------------------------------------------------
/bin/data/Embeddings/.gitignore:
--------------------------------------------------------------------------------
1 | /W2V_UMAP_params_100_n=296630.bin
2 | /W2V_UMAP_params_100_n=296630_metadata.txt
3 | /W2V_UMAP_params_15_n=296630.bin
4 | /W2V_UMAP_params_15_n=296630_metadata.txt
5 | /W2V_UMAP_params_200_n=296630.bin
6 | /W2V_UMAP_params_200_n=296630_metadata.txt
7 | /W2V_UMAP_params_50_n=296630.bin
8 | /W2V_UMAP_params_50_n=296630_metadata.txt
9 | /W2V_UMAP_params_5_n=296630.bin
10 | /W2V_UMAP_params_5_n=296630_metadata.txt
11 | /back_embed_n=18266.bin
12 | /back_embed_n=18266_metadata.txt
13 | /class_embed_n=9369.bin
14 | /class_embed_n=9369_metadata.txt
15 | /research_embed_n=10001.bin
16 | /research_embed_n=10001_metadata.txt
17 | /suit_embed_n=2163.bin
18 | /suit_embed_n=2163_metadata.txt
19 | /wind_embed_n=3834.bin
20 | /wind_embed_n=3834_metadata.txt
21 |
--------------------------------------------------------------------------------
/bin/data/FRB/.gitignore:
--------------------------------------------------------------------------------
1 | /frb_field_cigaleMass_t=0.0_z=0.01-0.1.bin
2 | /frb_field_cigaleMass_t=0.0_z=0.01-0.1_metadata.txt
3 | /frb_field_cigaleMass_t=10.0.bin
4 | /frb_field_cigaleMass_t=10.0_metadata.txt
5 | /frb_field_cigaleMass_t=10.0_z=0.01-0.1.bin
6 | /frb_field_cigaleMass_t=10.0_z=0.01-0.1_metadata.txt
7 | /frb_field_cigaleMass_t=10.0_z=0.02-0.1.bin
8 | /frb_field_cigaleMass_t=10.0_z=0.02-0.1_metadata.txt
9 | /frb_field_cigaleMass_t=10.0_z=0.054-0.1.bin
10 | /frb_field_cigaleMass_t=10.0_z=0.054-0.1_metadata.txt
11 | /frb_field_t=10.3.bin
12 | /frb_field_t=10.3_metadata.txt
13 |
--------------------------------------------------------------------------------
/bin/data/MassiveNuS/.gitignore:
--------------------------------------------------------------------------------
1 | /rockstar_mnv0.00000_om0.30000_As2.1000_out_66t=0.0roi=256.0.bin
2 | /rockstar_mnv0.00000_om0.30000_As2.1000_out_66t=0.0roi=256.0_metadata.txt
3 | /rockstar_mnv0.10000_om0.30000_As2.1000_out_66t=0.0roi=256.0.bin
4 | /rockstar_mnv0.10000_om0.30000_As2.1000_out_66t=0.0roi=256.0_metadata.txt
5 | /rockstar_mnv0.60000_om0.30000_As2.1000_out_66t=0.0roi=256.0.bin
6 | /rockstar_mnv0.60000_om0.30000_As2.1000_out_66t=0.0roi=256.0_metadata.txt
7 |
--------------------------------------------------------------------------------
/bin/data/MassiveNuS/pack_MassiveNuS.py:
--------------------------------------------------------------------------------
1 | #ID DescID Mvir Vmax Vrms Rvir Rs Np X Y Z VX VY VZ JX JY JZ Spin rs_klypin Mvir_all M200b M200c M500c M2500c Xoff Voff spin_bullock b_to_a c_to_a A[x] A[y] A[z] b_to_a(500c) c_to_a(500c) A[x](500c) A[y](500c) A[z](500c) T/|U| M_pe_Behroozi M_pe_Diemer Halfmass_Radius
2 | #a = 1.000000
3 | #Om = 0.300000; Ol = 0.700000; h = 0.700000
4 | #FOF linking length: 0.280000
5 | #Unbound Threshold: 0.500000; FOF Refinement Threshold: 0.700000
6 | #Particle mass: 1.03289e+10 Msun/h
7 | #Box size: 512.000000 Mpc/h
8 | #Force resolution assumed: 0.009 Mpc/h
9 | #Units: Masses in Msun / h
10 | #Units: Positions in Mpc / h (comoving)
11 | #Units: Velocities in km / s (physical, peculiar)
12 | #Units: Halo Distances, Lengths, and Radii in kpc / h (comoving)
13 | #Units: Angular Momenta in (Msun/h) * (Mpc/h) * km/s (physical)
14 | #Units: Spins are dimensionless
15 | #Np is an internal debugging quantity.
16 | #Rockst
17 |
18 | import numpy as np
19 |
20 | # config
21 | dirName = 'rockstar_mnv0.60000_om0.30000_As2.1000'
22 | fileName = 'out_66'
23 | mass_threshold = 0.0
24 | roi = 256.0
25 |
26 | # convert
27 | nonzero_halos = 0
28 | with open(dirName + '/' + fileName + '.list') as f:
29 | lines = f.readlines()
30 | data = np.zeros((len(lines)-1, 4), dtype=np.float32)
31 | for i, line in enumerate(lines[16:]):
32 | line = line.split(' ')
33 | x = float(line[8])
34 | y = float(line[9])
35 | z = float(line[10])
36 | mass = float(line[2]) / 1.0e12
37 |
38 | if ((mass > mass_threshold) & (x < roi) & (y < roi) & (z < roi)):
39 | data[nonzero_halos, :] = [x, y, z, mass]
40 | nonzero_halos += 1
41 |
42 | if (nonzero_halos == 0):
43 | print('No halos in selected ROI')
44 | exit()
45 | n_records = nonzero_halos
46 | filtered_data = np.zeros((n_records, 4), dtype=np.float32)
47 | filtered_data = data[0:n_records, :]
48 |
49 | print('Min/Max X: ' + str(np.min(filtered_data[:,0])) + ' ' + str(np.max(filtered_data[:,0])))
50 | print('Min/Max Y: ' + str(np.min(filtered_data[:,1])) + ' ' + str(np.max(filtered_data[:,1])))
51 | print('Min/Max Z: ' + str(np.min(filtered_data[:,2])) + ' ' + str(np.max(filtered_data[:,2])))
52 | print('Min/Max/Avg/Med Mvir: ' + str(np.min(filtered_data[:,3])) + ' ' + str(np.max(filtered_data[:,3])) + ' ' + str(np.mean(filtered_data[:,3])) + ' ' + str(np.median(filtered_data[:,3])))
53 | print('Sample record: ' + str(filtered_data[0,:]))
54 | print('Number of records: ' + str(n_records))
55 |
56 | output_file_name = dirName + '_' + fileName + 't=' + str(mass_threshold) + 'roi=' + str(roi)
57 |
58 | metadata_file = open(output_file_name + "_metadata.txt", "w")
59 | metadata_file.write("Number of points = " + str(n_records) + "\n")
60 | metadata_file.write("Min X = " + str(np.min(filtered_data[:,0])) + "\n")
61 | metadata_file.write("Max X = " + str(np.max(filtered_data[:,0])) + "\n")
62 | metadata_file.write("Min Y = " + str(np.min(filtered_data[:,1])) + "\n")
63 | metadata_file.write("Max Y = " + str(np.max(filtered_data[:,1])) + "\n")
64 | metadata_file.write("Min Z = " + str(np.min(filtered_data[:,2])) + "\n")
65 | metadata_file.write("Max Z = " + str(np.max(filtered_data[:,2])) + "\n")
66 | metadata_file.write("Mean weight = " + str(np.mean(filtered_data[:,3])) + "\n")
67 | metadata_file.close()
68 |
69 | filtered_data = filtered_data.tofile(output_file_name + '.bin')
--------------------------------------------------------------------------------
/bin/data/Poisson/poisson_256_2d.dat:
--------------------------------------------------------------------------------
1 | 0.08724 0.00700
2 | 0.57183 0.01091
3 | 0.79850 0.00309
4 | 0.02080 0.02068
5 | 0.02471 0.07148
6 | 0.13413 0.06171
7 | 0.19666 0.04608
8 | 0.25919 0.04999
9 | 0.32953 0.04217
10 | 0.39206 0.05390
11 | 0.44678 0.02654
12 | 0.50931 0.01873
13 | 0.54839 0.07344
14 | 0.63046 0.03045
15 | 0.68517 0.05781
16 | 0.74770 0.03827
17 | 0.82195 0.06562
18 | 0.88057 0.02263
19 | 0.93528 0.03436
20 | 0.07942 0.07930
21 | 0.09114 0.13206
22 | 0.17712 0.10470
23 | 0.24356 0.11252
24 | 0.30218 0.10080
25 | 0.36862 0.09689
26 | 0.43114 0.11643
27 | 0.48586 0.07735
28 | 0.56402 0.13597
29 | 0.61873 0.08907
30 | 0.67735 0.12815
31 | 0.73988 0.09298
32 | 0.79069 0.12424
33 | 0.85321 0.12034
34 | 0.90793 0.08516
35 | 0.97436 0.08125
36 | 0.03448 0.15355
37 | 0.14781 0.15942
38 | 0.20643 0.17505
39 | 0.26896 0.17114
40 | 0.32758 0.18286
41 | 0.37839 0.16332
42 | 0.45655 0.18677
43 | 0.49954 0.13988
44 | 0.53862 0.19459
45 | 0.62459 0.15551
46 | 0.68321 0.19068
47 | 0.74183 0.16723
48 | 0.81609 0.17896
49 | 0.87471 0.19850
50 | 0.90988 0.14769
51 | 0.97632 0.15160
52 | 0.04229 0.22390
53 | 0.09701 0.20240
54 | 0.15563 0.22194
55 | 0.22597 0.22976
56 | 0.29632 0.23758
57 | 0.35494 0.24539
58 | 0.41356 0.21804
59 | 0.48781 0.24149
60 | 0.56597 0.24930
61 | 0.61287 0.21413
62 | 0.66758 0.26103
63 | 0.73402 0.23367
64 | 0.79655 0.22585
65 | 0.87080 0.25712
66 | 0.94896 0.21022
67 | 0.01884 0.28252
68 | 0.07356 0.31769
69 | 0.10091 0.26884
70 | 0.18689 0.28057
71 | 0.24551 0.30011
72 | 0.30022 0.30792
73 | 0.36275 0.30401
74 | 0.42528 0.27666
75 | 0.51908 0.28838
76 | 0.58160 0.31574
77 | 0.62850 0.29620
78 | 0.69103 0.31965
79 | 0.75356 0.29229
80 | 0.82000 0.28447
81 | 0.88252 0.31183
82 | 0.93724 0.27275
83 | 0.99977 0.26493
84 | 0.06574 0.38413
85 | 0.11655 0.37045
86 | 0.15172 0.32746
87 | 0.21816 0.34700
88 | 0.31976 0.36263
89 | 0.37057 0.38608
90 | 0.41747 0.33528
91 | 0.48000 0.33919
92 | 0.54252 0.35873
93 | 0.60896 0.37436
94 | 0.67931 0.37827
95 | 0.74574 0.35482
96 | 0.81218 0.34309
97 | 0.89425 0.36654
98 | 0.95678 0.33137
99 | 0.99586 0.38218
100 | 0.02666 0.38804
101 | 0.12827 0.43689
102 | 0.18298 0.39781
103 | 0.25724 0.38999
104 | 0.32367 0.42907
105 | 0.39793 0.44861
106 | 0.43701 0.39390
107 | 0.49172 0.41735
108 | 0.55034 0.42126
109 | 0.60114 0.44080
110 | 0.66367 0.43298
111 | 0.73011 0.42516
112 | 0.79264 0.41344
113 | 0.84735 0.40172
114 | 0.93333 0.40953
115 | 0.97241 0.44470
116 | 0.01494 0.49746
117 | 0.07747 0.45838
118 | 0.14390 0.49551
119 | 0.21034 0.49942
120 | 0.21425 0.45252
121 | 0.27678 0.46424
122 | 0.34321 0.48769
123 | 0.40965 0.51114
124 | 0.46436 0.47206
125 | 0.53080 0.47597
126 | 0.64413 0.49160
127 | 0.71057 0.48378
128 | 0.77310 0.46815
129 | 0.83172 0.47988
130 | 0.88643 0.45643
131 | 0.92551 0.50332
132 | 0.08528 0.52482
133 | 0.13609 0.56195
134 | 0.19471 0.54631
135 | 0.24942 0.56976
136 | 0.28850 0.51896
137 | 0.34712 0.55804
138 | 0.40574 0.57367
139 | 0.47609 0.52677
140 | 0.56988 0.51505
141 | 0.63241 0.53850
142 | 0.69885 0.54241
143 | 0.76528 0.53068
144 | 0.82390 0.55413
145 | 0.87862 0.53459
146 | 0.94505 0.56585
147 | 0.98413 0.52287
148 | 0.00712 0.62643
149 | 0.03838 0.57562
150 | 0.08919 0.60103
151 | 0.16344 0.61666
152 | 0.22206 0.63229
153 | 0.30804 0.59321
154 | 0.36666 0.63620
155 | 0.42919 0.62447
156 | 0.48390 0.58149
157 | 0.54643 0.57758
158 | 0.59333 0.59712
159 | 0.65195 0.60884
160 | 0.73793 0.58930
161 | 0.78092 0.61275
162 | 0.85517 0.60493
163 | 0.92161 0.62057
164 | 0.04620 0.67333
165 | 0.10873 0.65574
166 | 0.17126 0.68700
167 | 0.23770 0.69091
168 | 0.28459 0.64792
169 | 0.38229 0.69873
170 | 0.44091 0.68310
171 | 0.50344 0.64402
172 | 0.55816 0.65965
173 | 0.62069 0.66746
174 | 0.70275 0.65183
175 | 0.75747 0.67528
176 | 0.82781 0.66356
177 | 0.89034 0.67137
178 | 0.95287 0.69482
179 | 0.98804 0.64011
180 | 0.05402 0.73585
181 | 0.11264 0.71436
182 | 0.19862 0.74953
183 | 0.26114 0.74562
184 | 0.31586 0.70264
185 | 0.33931 0.75344
186 | 0.46045 0.73390
187 | 0.51517 0.71045
188 | 0.57770 0.72218
189 | 0.60505 0.76126
190 | 0.65977 0.70654
191 | 0.72229 0.72608
192 | 0.80436 0.71827
193 | 0.86689 0.72999
194 | 0.94115 0.75735
195 | 0.05793 0.79448
196 | 0.12045 0.76907
197 | 0.16735 0.80425
198 | 0.24160 0.81206
199 | 0.30413 0.80034
200 | 0.39402 0.77298
201 | 0.44873 0.78861
202 | 0.49563 0.82379
203 | 0.53471 0.78080
204 | 0.64023 0.81988
205 | 0.67540 0.76516
206 | 0.72620 0.79252
207 | 0.80046 0.77689
208 | 0.86298 0.78471
209 | 0.92942 0.81597
210 | 0.99195 0.80815
211 | 0.03057 0.86091
212 | 0.10482 0.84333
213 | 0.17517 0.85896
214 | 0.22988 0.87850
215 | 0.29241 0.86287
216 | 0.35103 0.83551
217 | 0.42137 0.84723
218 | 0.52298 0.88631
219 | 0.57379 0.83160
220 | 0.59724 0.88241
221 | 0.68712 0.85114
222 | 0.74965 0.87459
223 | 0.77701 0.82769
224 | 0.83954 0.83942
225 | 0.90597 0.86677
226 | 0.98023 0.87068
227 | 0.00321 0.92344
228 | 0.08137 0.89999
229 | 0.13999 0.90195
230 | 0.17907 0.94494
231 | 0.27287 0.92930
232 | 0.33149 0.92149
233 | 0.37448 0.89413
234 | 0.43310 0.92540
235 | 0.47218 0.89022
236 | 0.58551 0.94103
237 | 0.64804 0.91758
238 | 0.70666 0.90976
239 | 0.76919 0.94884
240 | 0.80827 0.89804
241 | 0.85908 0.90585
242 | 0.91379 0.93712
243 | 0.96850 0.93321
244 | 0.01103 0.98597
245 | 0.06965 0.95471
246 | 0.12436 0.97620
247 | 0.23379 0.95666
248 | 0.31195 0.99183
249 | 0.38620 0.96057
250 | 0.45264 0.98402
251 | 0.51126 0.95275
252 | 0.56206 0.98792
253 | 0.63632 0.99965
254 | 0.69494 0.96838
255 | 0.83563 0.96448
256 | 0.89816 0.99574
--------------------------------------------------------------------------------
/bin/data/Poisson/poisson_256_2d_3d_flattened.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/poisson_256_2d_3d_flattened.bin
--------------------------------------------------------------------------------
/bin/data/Poisson/poisson_256_2d_3d_flattened_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 256
2 | Min X = 0.321
3 | Max X = 99.977
4 | Min Y = 0.309
5 | Max Y = 99.965
6 | Min Z = 50.0
7 | Max Z = 50.0
8 | Mean weight = 0.5
9 |
--------------------------------------------------------------------------------
/bin/data/Poisson/poisson_4096_2d_3d.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/poisson_4096_2d_3d.bin
--------------------------------------------------------------------------------
/bin/data/Poisson/poisson_4096_2d_3d_bias=3.0.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/poisson_4096_2d_3d_bias=3.0.bin
--------------------------------------------------------------------------------
/bin/data/Poisson/poisson_4096_2d_3d_bias=3.0_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 4096
2 | Min X = 0.009
3 | Max X = 99.985
4 | Min Y = 0.009
5 | Max Y = 99.985
6 | Min Z = 2.8390361e-11
7 | Max Z = 99.95091
8 | Mean weight = 0.24719092
9 |
--------------------------------------------------------------------------------
/bin/data/Poisson/poisson_4096_2d_3d_bias=4.0.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/poisson_4096_2d_3d_bias=4.0.bin
--------------------------------------------------------------------------------
/bin/data/Poisson/poisson_4096_2d_3d_bias=4.0_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 4096
2 | Min X = 0.009
3 | Max X = 99.985
4 | Min Y = 0.009
5 | Max Y = 99.985
6 | Min Z = 3.0046722e-14
7 | Max Z = 99.89874
8 | Mean weight = 0.19968694
9 |
--------------------------------------------------------------------------------
/bin/data/Poisson/poisson_4096_2d_3d_flattened.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/poisson_4096_2d_3d_flattened.bin
--------------------------------------------------------------------------------
/bin/data/Poisson/poisson_4096_2d_3d_flattened_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 4096
2 | Min X = 0.009
3 | Max X = 99.985
4 | Min Y = 0.009
5 | Max Y = 99.985
6 | Min Z = 50.0
7 | Max Z = 50.0
8 | Mean weight = 0.5
9 |
--------------------------------------------------------------------------------
/bin/data/Poisson/poisson_4096_2d_3d_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 4096
2 | Min X = 0.009
3 | Max X = 99.985
4 | Min Y = 0.009
5 | Max Y = 99.985
6 | Min Z = 0.05045948
7 | Max Z = 99.99182
8 | Mean weight = 1.0
9 |
--------------------------------------------------------------------------------
/bin/data/Poisson/random_4096_3d.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/random_4096_3d.bin
--------------------------------------------------------------------------------
/bin/data/Poisson/random_4096_3d_bias=3.0.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/random_4096_3d_bias=3.0.bin
--------------------------------------------------------------------------------
/bin/data/Poisson/random_4096_3d_bias=3.0_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 4096
2 | Min X = 0.09651001
3 | Max X = 99.92619
4 | Min Y = 0.022577174
5 | Max Y = 99.99224
6 | Min Z = 2.9920244e-12
7 | Max Z = 99.99497
8 | Mean weight = 0.24974537
9 |
--------------------------------------------------------------------------------
/bin/data/Poisson/random_4096_3d_bias=4.0.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/random_4096_3d_bias=4.0.bin
--------------------------------------------------------------------------------
/bin/data/Poisson/random_4096_3d_bias=4.0_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 4096
2 | Min X = 0.0027847835
3 | Max X = 99.973785
4 | Min Y = 0.032550775
5 | Max Y = 99.91945
6 | Min Z = 1.9194192e-13
7 | Max Z = 99.99042
8 | Mean weight = 0.1962329
9 |
--------------------------------------------------------------------------------
/bin/data/Poisson/random_4096_3d_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 4096
2 | Min X = 0.048511274
3 | Max X = 99.985306
4 | Min Y = 0.020293586
5 | Max Y = 99.99692
6 | Min Z = 0.042331498
7 | Max Z = 99.97783
8 | Mean weight = 1.0
9 |
--------------------------------------------------------------------------------
/bin/data/Poisson/regular_4096_3d.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/regular_4096_3d.bin
--------------------------------------------------------------------------------
/bin/data/Poisson/regular_4096_3d_bias=3.0.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/regular_4096_3d_bias=3.0.bin
--------------------------------------------------------------------------------
/bin/data/Poisson/regular_4096_3d_bias=3.0_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 4096
2 | Min X = 0.0
3 | Max X = 100.0
4 | Min Y = 0.0
5 | Max Y = 100.0
6 | Min Z = 0.0
7 | Max Z = 100.0
8 | Mean weight = 0.26666668
9 |
--------------------------------------------------------------------------------
/bin/data/Poisson/regular_4096_3d_bias=4.0.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/regular_4096_3d_bias=4.0.bin
--------------------------------------------------------------------------------
/bin/data/Poisson/regular_4096_3d_bias=4.0_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 4096
2 | Min X = 0.0
3 | Max X = 100.0
4 | Min Y = 0.0
5 | Max Y = 100.0
6 | Min Z = 0.0
7 | Max Z = 100.0
8 | Mean weight = 0.22013828
9 |
--------------------------------------------------------------------------------
/bin/data/Poisson/regular_4096_3d_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 4096
2 | Min X = 0.0
3 | Max X = 100.0
4 | Min Y = 0.0
5 | Max Y = 100.0
6 | Min Z = 0.0
7 | Max Z = 100.0
8 | Mean weight = 1.0
9 |
--------------------------------------------------------------------------------
/bin/data/SDSS/.gitignore:
--------------------------------------------------------------------------------
1 | /sdssGalaxy_rsdCorr_dbscan_e2p0ms3_dz0p001_m10p0_t=10.3.bin
2 | /sdssGalaxy_rsdCorr_dbscan_e2p0ms3_dz0p001_m10p0_t=10.3_metadata.txt
3 |
--------------------------------------------------------------------------------
/bin/data/SDSS/galaxiesInSdssSlice_viz_bigger_lumdist_t=0.0.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/SDSS/galaxiesInSdssSlice_viz_bigger_lumdist_t=0.0.bin
--------------------------------------------------------------------------------
/bin/data/SDSS/galaxiesInSdssSlice_viz_bigger_lumdist_t=0.0_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 37655
2 | Min X = -148.27219
3 | Max X = -7.0655794
4 | Min Y = -143.3676
5 | Max Y = 139.92603
6 | Min Z = -11.804932
7 | Max Z = 136.47922
8 | Mean weight = 0.013950215
9 |
--------------------------------------------------------------------------------
/bin/data/Zoe/.gitignore:
--------------------------------------------------------------------------------
1 | /64-clean-JT-3Dskan.blend
2 | /64-clean-JT-3Dskan.blend1
3 | /64-clean-JT-3Dskan.obj
4 | /64-clean-JT-3Dskan_clean.mtl
5 | /64-clean-JT-3Dskan_clean.obj
6 | /64-clean-JT-3Dskan_clean_n=492891.bin
7 | /64-clean-JT-3Dskan_clean_n=492891_metadata.txt
8 | /64-clean-JT-3Dskan_n=492892.bin
9 | /64-clean-JT-3Dskan_n=492892_metadata.txt
10 | /64-clean-JT-3Dskan_nobottom.mtl
11 | /64-clean-JT-3Dskan_nobottom.obj
12 | /64-clean-JT-3Dskan_nobottom_n=18654.bin
13 | /64-clean-JT-3Dskan_nobottom_n=18654_metadata.txt
14 | /64-clean-JT-3Dskan_nobottom_n=9480.bin
15 | /64-clean-JT-3Dskan_nobottom_n=9480_metadata.txt
16 |
--------------------------------------------------------------------------------
/bin/data/Zoe/64-clean-JT-3Dskan_nobottom.blend:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Zoe/64-clean-JT-3Dskan_nobottom.blend
--------------------------------------------------------------------------------
/bin/data/Zoe/64-clean-JT-3Dskan_nobottom_n=38102.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Zoe/64-clean-JT-3Dskan_nobottom_n=38102.bin
--------------------------------------------------------------------------------
/bin/data/Zoe/64-clean-JT-3Dskan_nobottom_n=38102_metadata.txt:
--------------------------------------------------------------------------------
1 | Number of points = 38102
2 | Min X = -90.60128
3 | Max X = 70.68778
4 | Min Y = -61.6432
5 | Max Y = 56.95748
6 | Min Z = -57.95948
7 | Max Z = -2.43354
8 | Mean weight = 1.0
9 |
--------------------------------------------------------------------------------
/bin/data/Zoe/pack_data_Zoe.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import math as math
3 | import random
4 |
5 | fileName = '64-clean-JT-3Dskan_nobottom'
6 | scale_multiplier = 20.0
7 | subsampling_factor = 5.0
8 |
9 | valid_pt_number = 0
10 | with open(fileName + '.obj') as f:
11 | lines = f.readlines()
12 | data = np.zeros((len(lines)-1, 4), dtype=np.float32)
13 | for i, line in enumerate(lines):
14 | if not (line[0] == 'v' and line[1] == ' '):
15 | continue # not a valid point
16 | if random.uniform(0.0, 1.0) > 1.0/subsampling_factor:
17 | continue # randomly throw out vertices
18 | line = line.split(' ')
19 | x = scale_multiplier * float(line[1])
20 | y = scale_multiplier * float(line[3])
21 | z = -scale_multiplier * float(line[2])
22 | # weight = float(line[4]) + float(line[5]) + float(line[6])
23 | weight = 1.0
24 | data[valid_pt_number, :] = [x, y, z, weight]
25 | valid_pt_number += 1
26 |
27 | if (valid_pt_number == 0):
28 | print('No points found')
29 | exit()
30 |
31 | filtered_data = np.zeros((valid_pt_number, 4), dtype=np.float32)
32 | filtered_data = data[0:valid_pt_number, :]
33 |
34 | print('Min/Max X: ' + str(np.min(filtered_data[:,0])) + ' ' + str(np.max(filtered_data[:,0])))
35 | print('Min/Max Y: ' + str(np.min(filtered_data[:,1])) + ' ' + str(np.max(filtered_data[:,1])))
36 | print('Min/Max Z: ' + str(np.min(filtered_data[:,2])) + ' ' + str(np.max(filtered_data[:,2])))
37 | print('Min/Max/Avg/Med weight: ' + str(np.min(filtered_data[:,3])) + ' ' + str(np.max(filtered_data[:,3])) + ' ' + str(np.mean(filtered_data[:,3])) + ' ' + str(np.median(filtered_data[:,3])))
38 | print('Sample record: ' + str(filtered_data[0,:]))
39 | print('Number of records: ' + str(valid_pt_number))
40 |
41 | output_file_name = fileName + '_n=' + str(valid_pt_number)
42 |
43 | metadata_file = open(output_file_name + "_metadata.txt", "w")
44 | metadata_file.write("Number of points = " + str(valid_pt_number) + "\n")
45 | metadata_file.write("Min X = " + str(np.min(filtered_data[:,0])) + "\n")
46 | metadata_file.write("Max X = " + str(np.max(filtered_data[:,0])) + "\n")
47 | metadata_file.write("Min Y = " + str(np.min(filtered_data[:,1])) + "\n")
48 | metadata_file.write("Max Y = " + str(np.max(filtered_data[:,1])) + "\n")
49 | metadata_file.write("Min Z = " + str(np.min(filtered_data[:,2])) + "\n")
50 | metadata_file.write("Max Z = " + str(np.max(filtered_data[:,2])) + "\n")
51 | metadata_file.write("Mean weight = " + str(np.mean(filtered_data[:,3])) + "\n")
52 | metadata_file.close()
53 |
54 | filtered_data = filtered_data.tofile(output_file_name + '.bin')
55 |
--------------------------------------------------------------------------------
/bin/data/affect_palettes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/affect_palettes.png
--------------------------------------------------------------------------------
/bin/data/palette_blue.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_blue.tga
--------------------------------------------------------------------------------
/bin/data/palette_cliff3.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_cliff3.tga
--------------------------------------------------------------------------------
/bin/data/palette_coldhot.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_coldhot.tga
--------------------------------------------------------------------------------
/bin/data/palette_eagle.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_eagle.tga
--------------------------------------------------------------------------------
/bin/data/palette_eagle2.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_eagle2.tga
--------------------------------------------------------------------------------
/bin/data/palette_gogh_blue.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_gogh_blue.tga
--------------------------------------------------------------------------------
/bin/data/palette_gogh_green.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_gogh_green.tga
--------------------------------------------------------------------------------
/bin/data/palette_hot.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_hot.tga
--------------------------------------------------------------------------------
/bin/data/palette_magma.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_magma.tga
--------------------------------------------------------------------------------
/bin/data/palette_magneto2.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_magneto2.tga
--------------------------------------------------------------------------------
/bin/data/palette_sunset2.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_sunset2.tga
--------------------------------------------------------------------------------
/bin/data/palette_sunset3.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_sunset3.tga
--------------------------------------------------------------------------------
/bin/data/palette_tropico.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_tropico.tga
--------------------------------------------------------------------------------
/bin/data/palette_vaneyck_green.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_vaneyck_green.tga
--------------------------------------------------------------------------------
/bin/data/palette_vaneyck_red.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_vaneyck_red.tga
--------------------------------------------------------------------------------
/bin/export/.gitignore:
--------------------------------------------------------------------------------
1 | /rerouting=0_deposit=linear/
2 | /rerouting=0_deposit=log/
3 | /rerouting=1_deposit=log/
4 | /rerouting=1_deposit=linear/
5 |
--------------------------------------------------------------------------------
/bin/freetype271MT.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/freetype271MT.dll
--------------------------------------------------------------------------------
/bin/obj/.gitignore:
--------------------------------------------------------------------------------
1 | /file_system.obj
2 | /font.obj
3 | /graphics.obj
4 | /input.obj
5 | /logging.obj
6 | /main.obj
7 | /maths.obj
8 | /memory.obj
9 | /platform.obj
10 | /random.obj
11 | /ui.obj
12 |
--------------------------------------------------------------------------------
/bin/ps_volume_halocolor.hlsl:
--------------------------------------------------------------------------------
1 | struct PixelInput
2 | {
3 | float4 position_out: SV_POSITION;
4 | float3 texcoord_out: TEXCOORD;
5 | };
6 |
7 | Texture3D tex_trace : register(t0);
8 | SamplerState tex_trace_sampler : register(s0);
9 | Texture3D tex_deposit : register(t1);
10 | SamplerState tex_deposit_sampler : register(s1);
11 |
12 | cbuffer ConfigBuffer : register(b4)
13 | {
14 | float4x4 projection_matrix;
15 | float4x4 view_matrix;
16 | float4x4 model_matrix;
17 | int texcoord_map;
18 | float trim_x_min;
19 | float trim_x_max;
20 | float trim_y_min;
21 | float trim_y_max;
22 | float trim_z_min;
23 | float trim_z_max;
24 | float trim_density;
25 | float world_width;
26 | float world_height;
27 | float world_depth;
28 | float screen_width;
29 | float screen_height;
30 | float sample_weight;
31 | float optical_thickness;
32 | float highlight_density;
33 | float galaxy_weight;
34 | float histogram_base;
35 | };
36 |
37 | float remap(float val, float slope)
38 | {
39 | return 1.0 - exp(-slope * val);
40 | }
41 |
42 | float4 main(PixelInput input) : SV_TARGET
43 | {
44 | float4 fragment;
45 | if (input.texcoord_out.x < trim_x_min || input.texcoord_out.x > trim_x_max ||
46 | input.texcoord_out.y < trim_y_min || input.texcoord_out.y > trim_y_max ||
47 | input.texcoord_out.z < trim_z_min || input.texcoord_out.z > trim_z_max) {
48 | fragment = 0.0.xxxx;
49 | }
50 | else {
51 | float trace = 2.0 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz);
52 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3( 1./world_width, 0, 0));
53 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(-1./world_width, 0, 0));
54 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0, 1./world_height, 0));
55 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0,-1./world_height, 0));
56 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0, 0, 1./world_depth));
57 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0, 0, -1./world_depth));
58 | float t = sample_weight * (trace - trim_density);
59 | float2 deposit = tex_deposit.Sample(tex_deposit_sampler, input.texcoord_out.xyz).xy;
60 | float2 d = galaxy_weight * deposit;
61 |
62 | fragment.rgb = remap(t, 0.6) * float3(0.5, 0.5, 0.5);
63 | if (d.y > 0.0)
64 | fragment.rgb += remap(d.x, 0.1) * float3(0.0, 0.0, 0.8);
65 | else// if (d.y < 0.0)
66 | fragment.rgb += remap(d.x, 0.1) * float3(0.7, 0.0, 0.0);
67 | // else
68 | // fragment.rgb += remap(d.x, 0.1) * float3(0.0, 0.6, 0.0);
69 |
70 | fragment.a = (0.3*t + 0.15*d.x) * optical_thickness;
71 | }
72 |
73 | fragment.rgb *= 2.0; // Compensate for the drawing 1 stack of meta-quads instead of 3
74 | return fragment;
75 | }
--------------------------------------------------------------------------------
/bin/renner-book.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/renner-book.otf
--------------------------------------------------------------------------------
/build_and_run.bat:
--------------------------------------------------------------------------------
1 | build run polyphorm.build --release
2 | cd bin
3 | polyphorm.exe
4 | cd ..
--------------------------------------------------------------------------------
/builder/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | project (builder)
2 |
3 | add_executable(builder main.cpp)
4 |
5 | target_link_libraries(builder Shlwapi.lib)
--------------------------------------------------------------------------------
/builder/bin/.gitignore:
--------------------------------------------------------------------------------
1 | /build.pdb
2 | /vc140.pdb
3 |
--------------------------------------------------------------------------------
/builder/bin/build.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/builder/bin/build.exe
--------------------------------------------------------------------------------
/builder/bin/obj/main.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/builder/bin/obj/main.obj
--------------------------------------------------------------------------------
/builder/build.bat:
--------------------------------------------------------------------------------
1 | if not exist "bin" mkdir bin
2 | if not exist "bin\\obj" mkdir bin\\obj
3 | call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
4 | call cl.exe main.cpp /nologo /W3 /Od /RTC1 /MTd /EHsc /Zc:inline /Gm- /MP /Fo:bin\\obj\\ /Fd:bin\\ /Zi /DDEBUG /link /INCREMENTAL:NO /subsystem:console /MACHINE:X64 /debug:fastlink /CGTHREADS:4 Shlwapi.lib Advapi32.lib ole32.lib oleaut32.lib /OUT:bin\\build.exe
--------------------------------------------------------------------------------
/builder/config.h:
--------------------------------------------------------------------------------
1 | #include "microsoft_craziness.h"
2 |
3 | namespace config
4 | {
5 | // NEW ENVIRONMENTAL VARS
6 | char *env_var_new_info[3];
7 | const uint32_t env_var_new_info_count = ARRAYSIZE(env_var_new_info);
8 |
9 | char *args_debug = "--debug";
10 | char *args_release = "--release";
11 | char *args_clean = "--clean";
12 | char *args_run = "run";
13 |
14 | #define CONFIG_BIN_DIR_VAR "bin"
15 |
16 | // OPTIMIZATION - /EHsc /fp:fast
17 | // MISC - MTd (static) Zc:inline?
18 | char *compiler_path = NULL;
19 | char *compiler_options_debug = "/nologo /W3 /Od /RTC1 /MDd /EHsc /Zc:inline /Gm- /MP /Fo:" CONFIG_BIN_DIR_VAR "\\obj\\ /Fd" CONFIG_BIN_DIR_VAR "\\ /Zi /DDEBUG /link /INCREMENTAL:NO /subsystem:console /MACHINE:X64 /debug:fastlink /CGTHREADS:4";
20 | char *compiler_options_release = "/nologo /W3 /O2 /MD /EHsc /Zc:inline /Gm- /MP /Fo:" CONFIG_BIN_DIR_VAR "\\obj\\ /link /INCREMENTAL:NO /subsystem:console /MACHINE:X64 /debug:none /CGTHREADS:4";
21 | char *exe_file_prefix = " /OUT:" CONFIG_BIN_DIR_VAR "\\";
22 |
23 | void setup_paths() {
24 | Find_Result result = find_visual_studio_and_windows_sdk();
25 |
26 | // Set CL.exe path.
27 | wchar_t *compiler_path_new = concat(result.vs_exe_path, L"\\cl.exe"); defer {free(compiler_path_new);};
28 | int compiler_path_length = wcslen(compiler_path_new) + 1;
29 | compiler_path = (char *)malloc(compiler_path_length);
30 | wcstombs(compiler_path, compiler_path_new, compiler_path_length);
31 |
32 | // Set LIBPATH variable.
33 | wchar_t *libpath_new = concat(L"LIBPATH=", result.vs_library_path); defer {free(libpath_new);};
34 | int libpath_length = wcslen(libpath_new) + 1;
35 | char *libpath = (char *)malloc(libpath_length);
36 | wcstombs(libpath, libpath_new, libpath_length);
37 |
38 | // Set LIB variable.
39 | wchar_t *lib_new1 = concat(L"LIB=", result.windows_sdk_ucrt_library_path, L";"); defer {free(lib_new1);};
40 | wchar_t *lib_new2 = concat(lib_new1, result.windows_sdk_um_library_path, L";"); defer {free(lib_new2);};
41 | wchar_t *lib_new3 = concat(lib_new2, result.vs_library_path, L";"); defer {free(lib_new3);};
42 | int lib_length = wcslen(lib_new3) + 1;
43 | char *lib = (char *)malloc(lib_length);
44 | wcstombs(lib, lib_new3, lib_length);
45 |
46 | // Set INCLUDE variable.
47 | wchar_t *include_new1 = concat(L"INCLUDE=", result.vs_include_path, L";"); defer {free(include_new1);};
48 | wchar_t *include_new2 = concat(include_new1, result.windows_sdk_um_include_path, L";"); defer {free(include_new2);};
49 | wchar_t *include_new3 = concat(include_new2, result.windows_sdk_ucrt_include_path, L";"); defer {free(include_new3);};
50 | wchar_t *include_new4 = concat(include_new3, result.windows_sdk_shared_include_path, L";"); defer {free(include_new4);};
51 | int include_length = wcslen(include_new4) + 1;
52 | char *include = (char *)malloc(include_length);
53 | wcstombs(include, include_new4, include_length);
54 |
55 | // Update array with new env variables.
56 | env_var_new_info[0] = include;
57 | env_var_new_info[1] = libpath;
58 | env_var_new_info[2] = lib;
59 |
60 | // Clean up.
61 | free_resources(&result);
62 | };
63 | }
64 |
--------------------------------------------------------------------------------
/builder/environment.cpp:
--------------------------------------------------------------------------------
1 | uint32_t get_env_additional_info_length(char **env_additional_info, uint32_t env_additional_info_count)
2 | {
3 | uint32_t env_additional_info_length = 0;
4 |
5 | for(uint32_t i = 0; i < env_additional_info_count; ++i)
6 | {
7 | env_additional_info_length += string::length(env_additional_info[i]);
8 | }
9 |
10 | return env_additional_info_length;
11 | }
12 |
13 | uint32_t get_env_new_info_length(char **env_new_info, uint32_t env_new_info_count)
14 | {
15 | uint32_t env_new_info_length = 0;
16 |
17 | for(uint32_t i = 0; i < env_new_info_count; ++i)
18 | {
19 | env_new_info_length += string::length(env_new_info[i]) + 1;
20 | }
21 |
22 | return env_new_info_length;
23 | }
24 |
25 | uint32_t get_env_block_length(char *env_block)
26 | {
27 | // Counting also the last NULL terminating character (There are two NTCs at the end of the env block)
28 | uint32_t env_block_length = 1;
29 | while(true)
30 | {
31 | uint32_t env_var_length = string::length(env_block) + 1;
32 | env_block_length += env_var_length;
33 | env_block += env_var_length;
34 | if (*env_block == 0) break;
35 | }
36 | return env_block_length;
37 | }
38 |
39 | uint32_t get_var_name_length(char *var)
40 | {
41 | uint32_t length = 0;
42 |
43 | while(true)
44 | {
45 | if(*(var++) == '=') break;
46 | length++;
47 | }
48 |
49 | return length;
50 | }
51 |
52 |
53 |
54 | namespace environment
55 | {
56 | char *update_env_block(char *old_env_block,
57 | char **env_new_info, uint32_t env_new_info_count,
58 | AllocatorType allocator_type = PERSISTENT)
59 | {
60 | // Compute new env block length
61 | uint32_t old_env_block_length = get_env_block_length(old_env_block);
62 | uint32_t new_info_length = get_env_new_info_length(env_new_info, env_new_info_count);
63 | uint32_t new_env_block_length = old_env_block_length + new_info_length;
64 |
65 | // Allocate and prepare pointers
66 | char * new_env_block = memory::allocate(new_env_block_length, PERSISTENT);
67 | char *new_env_block_ptr = new_env_block;
68 | char *old_env_block_ptr = old_env_block;
69 |
70 | while(true)
71 | {
72 | // Get current variable and variable name lengths
73 | uint32_t var_name_length = get_var_name_length(old_env_block_ptr);
74 | uint32_t old_var_length = string::length(old_env_block_ptr);
75 | uint32_t new_var_length = old_var_length;
76 |
77 | // Copy over old content
78 | memcpy(new_env_block_ptr, old_env_block_ptr, old_var_length);
79 |
80 | // Add ntc to the end of the var
81 | new_env_block_ptr[new_var_length] = 0;
82 |
83 | // Move pointers and check for end
84 | new_env_block_ptr += new_var_length + 1;
85 | old_env_block_ptr += old_var_length + 1; // Skip NTC
86 | if (*old_env_block_ptr == 0) break;
87 | }
88 |
89 | // Add new info
90 | for (uint32_t i = 0; i < env_new_info_count; ++i)
91 | {
92 | uint32_t new_info_length = string::length(env_new_info[i]);
93 | memcpy(new_env_block_ptr, env_new_info[i], new_info_length);
94 | new_env_block_ptr[new_info_length] = 0;
95 |
96 | new_env_block_ptr += new_info_length + 1;
97 | }
98 |
99 | // Add final ntc
100 | new_env_block[new_env_block_length - 1] = 0;
101 |
102 | return new_env_block;
103 | }
104 |
105 | char *get_current_env_block()
106 | {
107 | return GetEnvironmentStrings();
108 | }
109 |
110 | void free_env_block(char *env_block)
111 | {
112 | FreeEnvironmentStrings(env_block);
113 | }
114 |
115 | void print_env_block(char *env_block)
116 | {
117 | while(true)
118 | {
119 | printf("%s\n", env_block);
120 | env_block += string::length(env_block) + 1;
121 | if(*env_block == 0) break;
122 | }
123 | }
124 | }
--------------------------------------------------------------------------------
/builder/memory.cpp:
--------------------------------------------------------------------------------
1 | struct Allocator
2 | {
3 | void *data;
4 | uint32_t size;
5 | uint32_t top;
6 | };
7 |
8 | typedef uint32_t AllocatorState;
9 |
10 | enum AllocatorType
11 | {
12 | TEMPORARY,
13 | PERSISTENT
14 | };
15 |
16 | namespace memory
17 | {
18 | static Allocator allocator_temporary;
19 | static Allocator allocator_persistent;
20 |
21 | static const uint32_t init_memory_size = 1000000;
22 | static void init()
23 | {
24 | allocator_temporary.data = malloc(init_memory_size);
25 | allocator_temporary.size = init_memory_size;
26 | allocator_temporary.top = 0;
27 |
28 | allocator_persistent.data = malloc(init_memory_size);
29 | allocator_persistent.size = init_memory_size;
30 | allocator_persistent.top = 0;
31 | }
32 |
33 | template
34 | static T *allocate(uint32_t count, AllocatorType type = TEMPORARY)
35 | {
36 | Allocator *allocator = type == TEMPORARY ? &allocator_temporary : &allocator_persistent;
37 |
38 | if(allocator->top + count > allocator->size)
39 | {
40 | allocator->size *= 2;
41 | allocator->data = realloc(allocator->data, allocator->size);
42 | }
43 |
44 | T *result = (T *)((char *)allocator->data + allocator->top);
45 | allocator->top += sizeof(T) * count;
46 |
47 | return result;
48 | }
49 |
50 | static AllocatorState set(AllocatorType type = TEMPORARY)
51 | {
52 | Allocator *allocator = type == TEMPORARY ? &allocator_temporary : &allocator_persistent;
53 | return allocator->top;
54 | }
55 |
56 | static void reset(AllocatorState state, AllocatorType type = TEMPORARY)
57 | {
58 | Allocator *allocator = type == TEMPORARY ? &allocator_temporary : &allocator_persistent;
59 | allocator->top = state;
60 | }
61 | };
62 |
--------------------------------------------------------------------------------
/builder/setup.bat:
--------------------------------------------------------------------------------
1 | echo off
2 | setx "path=%PATH%;%cd%\bin"
--------------------------------------------------------------------------------
/builder/string.cpp:
--------------------------------------------------------------------------------
1 | namespace string
2 | {
3 | uint32_t length(char *string)
4 | {
5 | return (uint32_t) strlen(string);
6 | }
7 |
8 | char *create_null_terminated(char *string, uint32_t string_length, AllocatorType allocator_type = PERSISTENT)
9 | {
10 | char *nt_string = memory::allocate(string_length + 1, allocator_type);
11 | memcpy(nt_string, string, string_length);
12 | nt_string[string_length] = 0;
13 | return nt_string;
14 | }
15 |
16 | bool equals(char *string1, char *string2, uint32_t max_length)
17 | {
18 | return strncmp(string1, string2, max_length) == 0;
19 | }
20 |
21 | bool equals(char *string1, char *string2)
22 | {
23 | return strcmp(string1, string2) == 0;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/builder/structs.h:
--------------------------------------------------------------------------------
1 | // TODO: Switch to general expandable arrays
2 | struct FileList
3 | {
4 | char *file_path;
5 | FileList *next_file;
6 | };
7 |
8 | struct CopyFileBatch
9 | {
10 | FileList *source_files;
11 | char *target_directory;
12 |
13 | CopyFileBatch *next_batch;
14 | };
15 |
16 | struct BuildSettings
17 | {
18 | FileList *source_files;
19 | FileList *pre_hash_files;
20 | FileList *libraries;
21 | FileList *include_directories;
22 | char *target_exe_name;
23 |
24 | CopyFileBatch *copy_files;
25 | };
26 |
--------------------------------------------------------------------------------
/builder/sys_utils.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | typedef LARGE_INTEGER Ticks;
4 |
5 | namespace sys_utils
6 | {
7 | Ticks get_ticks()
8 | {
9 | LARGE_INTEGER ticks;
10 |
11 | QueryPerformanceCounter(&ticks);
12 |
13 | return (Ticks)ticks;
14 | }
15 |
16 | Ticks get_tick_frequency()
17 | {
18 | LARGE_INTEGER frequency;
19 |
20 | QueryPerformanceFrequency(&frequency);
21 |
22 | return (Ticks)frequency;
23 | }
24 |
25 | float get_dt_from_tick_difference(Ticks t1, Ticks t2, Ticks frequency)
26 | {
27 | float dt = (float)((t2.QuadPart - t1.QuadPart) / (double)frequency.QuadPart);
28 | return dt;
29 | }
30 |
31 | char *get_current_time_and_date_string(char *date_format, char *time_format, bool date_first = true, AllocatorType allocator_type = PERSISTENT)
32 | {
33 | SYSTEMTIME current_time;
34 | GetLocalTime(¤t_time);
35 |
36 | uint32_t bytes_needed_date = GetDateFormat(LOCALE_USER_DEFAULT, NULL, ¤t_time, date_format, NULL, 0);
37 | if (bytes_needed_date == 0)
38 | {
39 | printf("Error obtaining date format string.\n");
40 | return NULL;
41 | }
42 |
43 | uint32_t bytes_needed_time = GetTimeFormat(LOCALE_USER_DEFAULT, NULL, ¤t_time, time_format, NULL, 0);
44 | if (bytes_needed_time == 0)
45 | {
46 | printf("Error obtaining time format string.\n");
47 | return NULL;
48 | }
49 |
50 | uint32_t bytes_needed_total = bytes_needed_date + bytes_needed_time - 1; // Don't count ntc twice
51 | auto mem_state_temp = memory::set(allocator_type);
52 | char *time_date_string_buffer = memory::allocate(bytes_needed_total, allocator_type);
53 | char *date_part = date_first ? time_date_string_buffer : time_date_string_buffer + bytes_needed_time - 1;
54 | char *time_part = date_first ? time_date_string_buffer + bytes_needed_date - 1 : time_date_string_buffer;
55 |
56 | if(date_first)
57 | {
58 | uint32_t bytes_written_date = GetDateFormat(LOCALE_USER_DEFAULT, NULL, ¤t_time, date_format, date_part, bytes_needed_date);
59 | if (bytes_written_date == 0)
60 | {
61 | printf("Error obtaining date format string.\n");
62 | memory::reset(mem_state_temp, allocator_type);
63 | return NULL;
64 | }
65 | }
66 |
67 | uint32_t bytes_written_time = GetTimeFormat(LOCALE_USER_DEFAULT, NULL, ¤t_time, time_format, time_part, bytes_needed_time);
68 | if (bytes_written_time == 0)
69 | {
70 | printf("Error obtaining time format string.\n");
71 | memory::reset(mem_state_temp, allocator_type);
72 | return NULL;
73 | }
74 |
75 | if(!date_first)
76 | {
77 | uint32_t bytes_written_date = GetDateFormat(LOCALE_USER_DEFAULT, NULL, ¤t_time, date_format, date_part, bytes_needed_date);
78 | if (bytes_written_date == 0)
79 | {
80 | printf("Error obtaining date format string.\n");
81 | memory::reset(mem_state_temp, allocator_type);
82 | return NULL;
83 | }
84 | }
85 |
86 | return time_date_string_buffer;
87 | }
88 | }
89 |
90 | struct Timer
91 | {
92 | Ticks frequency;
93 | Ticks start;
94 | };
95 |
96 | namespace timer
97 | {
98 | Timer get()
99 | {
100 | Timer timer = {};
101 | timer.frequency = sys_utils::get_tick_frequency();
102 | return timer;
103 | }
104 |
105 | void start(Timer *timer)
106 | {
107 | timer->start = sys_utils::get_ticks();
108 | }
109 |
110 | float end(Timer *timer)
111 | {
112 | Ticks current = sys_utils::get_ticks();
113 | float dt = sys_utils::get_dt_from_tick_difference(timer->start, current, timer->frequency);
114 | return dt;
115 | }
116 |
117 | float checkpoint(Timer *timer)
118 | {
119 | Ticks current = sys_utils::get_ticks();
120 | float dt = sys_utils::get_dt_from_tick_difference(timer->start, current, timer->frequency);
121 | timer->start = current;
122 |
123 | return dt;
124 | }
125 | }
--------------------------------------------------------------------------------
/cpplib/animation.cpp:
--------------------------------------------------------------------------------
1 | #include "animation.h"
2 | #include "memory.h"
3 |
4 | Matrix4x4 matrix_from_transform(Transform transform)
5 | {
6 | Matrix4x4 scale_matrix = math::get_scale(transform.scale);
7 | Matrix4x4 translation_matrix = math::get_translation(transform.translation);
8 | Matrix4x4 rotation_matrix = math::get_rotation(transform.rotation);
9 |
10 | Matrix4x4 result = translation_matrix * rotation_matrix * scale_matrix;
11 | return result;
12 | }
13 |
14 | Transform interpolate(Transform t1, Transform t2, float t)
15 | {
16 | Transform result = {};
17 | result.scale = math::lerp(t1.scale, t2.scale, t);
18 | result.translation = math::lerp(t1.translation, t2.translation, t);
19 | if (math::dot(t1.rotation, t2.rotation) < 0.0f)
20 | {
21 | result.rotation = math::nlerp(-t1.rotation, t2.rotation, t);
22 | }
23 | else
24 | {
25 | result.rotation = math::nlerp(t1.rotation, t2.rotation, t);
26 | }
27 | return result;
28 | }
29 |
30 | AnimationPlayer animation::get(Skeleton skeleton, Animation *animations, uint32_t animation_count)
31 | {
32 | AnimationPlayer player = {};
33 |
34 | player.skeleton = skeleton;
35 | player.animations = animations;
36 | player.animation_count = animation_count;
37 | player.output_matrices = memory::alloc_heap(skeleton.bones.count);
38 |
39 | return player;
40 | }
41 |
42 | void animation::update(AnimationPlayer *player, float dt)
43 | {
44 | player->current_time += dt;
45 | Animation *current_animation = &player->animations[player->current_animation];
46 | if(player->current_time >= current_animation->duration)
47 | {
48 | player->current_time = 0.0f;
49 | player->current_animation = 1 - player->current_animation;
50 | }
51 | }
52 |
53 | void animation::evaluate(AnimationPlayer *player)
54 | {
55 | Animation *animation = &player->animations[player->current_animation];
56 | Skeleton *skeleton = &player->skeleton;
57 | float current_part = player->current_time / animation->duration * (animation->frame_count - 1);
58 | uint32_t current_frame = (uint32_t)math::floor(current_part);
59 | float fraction = current_part - (float)current_frame;
60 | current_frame = math::clamp(current_frame, (uint32_t)0, animation->frame_count - 1);
61 |
62 | for (uint32_t i = 0; i < skeleton->bones.count; ++i)
63 | {
64 | Transform local_transform_current = animation->key_frames[current_frame].bone_transforms[i];
65 | Transform local_transform_next = animation->key_frames[current_frame + 1].bone_transforms[i];
66 | Transform local_transform = interpolate(local_transform_current, local_transform_next, fraction);
67 | Matrix4x4 local_mat = matrix_from_transform(local_transform);
68 | Matrix4x4 local_mat2 = local_transform.matrix;
69 | int32_t parent_index = skeleton->bones.data[i].parent_idx;
70 | Matrix4x4 parent_mat = math::get_identity();
71 | if(parent_index >= 0)
72 | {
73 | parent_mat = player->output_matrices[parent_index];
74 | }
75 | player->output_matrices[i] = parent_mat * local_mat;
76 | }
77 | for (uint32_t i = 0; i < skeleton->bones.count; ++i)
78 | {
79 | Bone *bone = &skeleton->bones.data[i];
80 | Matrix4x4 mat = bone->world_from_bind_pose;
81 | player->output_matrices[i] = player->output_matrices[i] * bone->bind_pose_from_world;
82 | //player->output_matrices[i] = bone->world_from_bind_pose * bone->bind_pose_from_world;
83 | }
84 | }
--------------------------------------------------------------------------------
/cpplib/animation.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "array.h"
3 | #include "maths.h"
4 |
5 | struct Bone
6 | {
7 | const char *name;
8 | int32_t parent_idx;
9 |
10 | Matrix4x4 world_from_bind_pose;
11 | Matrix4x4 bind_pose_from_world;
12 | };
13 |
14 | struct ControlPoint
15 | {
16 | int32_t bone_indices[4];
17 | float bone_weights[4];
18 |
19 | uint32_t bone_count = 0;
20 | };
21 |
22 | struct Skeleton
23 | {
24 | Array bones;
25 |
26 | ControlPoint *control_points;
27 | uint32_t control_point_count;
28 | int32_t *vertex_to_control_point;
29 | uint32_t vertex_count;
30 | };
31 |
32 | struct Transform
33 | {
34 | Quaternion rotation;
35 | Vector3 scale;
36 | Vector3 translation;
37 | Matrix4x4 matrix;
38 | };
39 |
40 | struct KeyFrame
41 | {
42 | Transform *bone_transforms;
43 | };
44 |
45 | struct Animation
46 | {
47 | KeyFrame *key_frames;
48 | uint32_t frame_count;
49 | uint32_t bone_count;
50 |
51 | char *name;
52 | float duration;
53 | uint32_t fps;
54 | };
55 |
56 | struct AnimationPlayer
57 | {
58 | Skeleton skeleton;
59 | Animation *animations;
60 | uint32_t animation_count;
61 |
62 | uint32_t current_animation = 0;
63 | float current_time = 0;
64 |
65 | Matrix4x4 *output_matrices;
66 | };
67 |
68 | namespace animation
69 | {
70 | AnimationPlayer get(Skeleton skeleton, Animation *animations, uint32_t animation_count);
71 | void update(AnimationPlayer *player, float dt);
72 | void evaluate(AnimationPlayer *player);
73 | }
--------------------------------------------------------------------------------
/cpplib/array.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include "memory.h"
6 |
7 | // Array is a data struct used as a dynamically allocated list.
8 | template
9 | struct Array
10 | {
11 | T *data;
12 | uint32_t count;
13 | uint32_t size;
14 |
15 | T& operator[](uint32_t index)
16 | {
17 | return (this->data[index]);
18 | }
19 | };
20 |
21 |
22 | // `array` namespace handles operations on Array.
23 | namespace array
24 | {
25 | // array_expansion_ratio defines the ratio of new array size to old array size when reallocating.
26 | const uint32_t array_expansion_ratio = 2;
27 |
28 | // Initialize Array
29 | template
30 | void init(Array *array, uint32_t size)
31 | {
32 | array->size = size;
33 | array->count = 0;
34 | array->data = memory::alloc_heap(size);
35 | assert(array->data);
36 | }
37 |
38 | // Returns initialized Array
39 | template
40 | Array get(uint32_t size)
41 | {
42 | Array array;
43 | array::init(&array, size);
44 | return array;
45 | }
46 |
47 | // Reset the array, does not deallocate allocated memory
48 | template
49 | void reset(Array *array)
50 | {
51 | array->count = 0;
52 | }
53 |
54 | // Add an element into array, possibly reallocate and move all the contents
55 | template
56 | void add(Array *array, T item)
57 | {
58 | // In case the array is full, reallocate
59 | if(array->size == array->count)
60 | {
61 | T *new_mem = memory::alloc_heap(array->size * array_expansion_ratio);
62 | assert(new_mem);
63 | memcpy(new_mem, array->data, sizeof(T) * array->size);
64 | memory::free_heap(array->data);
65 | array->data = new_mem;
66 | array->size *= array_expansion_ratio;
67 | }
68 |
69 | array->data[array->count++] = item;
70 | }
71 |
72 | // Completely release the array, freeing all the memory
73 | template
74 | void release(Array *array)
75 | {
76 | memory::free_heap(array->data);
77 | array->size = 0;
78 | array->count = 0;
79 | }
80 | }
--------------------------------------------------------------------------------
/cpplib/audio.cpp:
--------------------------------------------------------------------------------
1 | #define _CRT_SECURE_NO_WARNINGS
2 | #include "audio.h"
3 | #include
4 | #include "stb_vorbis.c"
5 |
6 | #ifdef CPPLIB_DEBUG_PRINTS
7 | #include "logging.h"
8 | #define PRINT_DEBUG(message, ...) logging::print_error(message, ##__VA_ARGS__)
9 | #else
10 | #define PRINT_DEBUG(message, ...)
11 | #endif
12 |
13 | static AudioContext audio_context_;
14 | static AudioContext *audio_context = &audio_context_;
15 |
16 | // NOTE: Audio module releasing facilities aren't tested, so there may be some issues here
17 | bool audio::init()
18 | {
19 | CoInitialize(NULL);
20 |
21 | HRESULT hr = XAudio2Create(&audio_context->engine, 0, XAUDIO2_DEFAULT_PROCESSOR);
22 | if (FAILED(hr)) {
23 | PRINT_DEBUG("Failed to create XAudio2 engine.");
24 | return false;
25 | }
26 | hr = audio_context->engine->CreateMasteringVoice(&audio_context->master_voice);
27 | if (FAILED(hr)) {
28 | PRINT_DEBUG("Failed to create IXAudio2MasteringVoice.");
29 | return false;
30 | }
31 |
32 | #ifdef DEBUG
33 | XAUDIO2_DEBUG_CONFIGURATION debug_config = {};
34 | debug_config.TraceMask = XAUDIO2_LOG_ERRORS | XAUDIO2_LOG_WARNINGS | XAUDIO2_LOG_MEMORY;
35 | audio_context->engine->SetDebugConfiguration(&debug_config, NULL);
36 | #endif
37 |
38 | return true;
39 | }
40 |
41 | Sound audio::get_sound_ogg(void *data, uint32_t data_size)
42 | {
43 | Sound sound = {};
44 | sound.sample_count = stb_vorbis_decode_memory((uint8_t *)data, data_size, &sound.channels, &sound.sample_rate, &sound.samples);
45 |
46 | WAVEFORMATEX wfx = {};
47 | wfx.wFormatTag = WAVE_FORMAT_PCM;
48 | wfx.nChannels = sound.channels;
49 | wfx.nSamplesPerSec = sound.sample_rate;
50 | wfx.nBlockAlign = 4;
51 | wfx.wBitsPerSample = 16;
52 | wfx.nAvgBytesPerSec = sound.sample_rate * 4;
53 |
54 | XAUDIO2_BUFFER buffer = {};
55 | buffer.AudioBytes = sound.sample_count * sound.channels * 2;
56 | buffer.pAudioData = (uint8_t *)sound.samples;
57 | buffer.PlayBegin = 0;
58 | buffer.PlayLength = sound.sample_count;
59 | buffer.LoopBegin = 0;
60 | buffer.LoopLength = sound.sample_count;
61 | buffer.LoopCount = XAUDIO2_LOOP_INFINITE;
62 |
63 | HRESULT hr = audio_context->engine->CreateSourceVoice(&sound.source_voice, &wfx);
64 | if(FAILED(hr)) {
65 | PRINT_DEBUG("Failed to create IXAudio2SourceVoice.");
66 | return Sound{};
67 | }
68 |
69 | hr = sound.source_voice->SubmitSourceBuffer(&buffer);
70 | if(FAILED(hr)) {
71 | sound.source_voice->DestroyVoice();
72 | PRINT_DEBUG("Failed to submit a source buffer.");
73 | return Sound{};
74 | }
75 |
76 | return sound;
77 | }
78 |
79 | bool audio::play_sound(Sound *sound)
80 | {
81 | HRESULT hr = sound->source_voice->Start(0);
82 | if(FAILED(hr)) {
83 | PRINT_DEBUG("Failed to start a source voice.");
84 | return false;
85 | }
86 | return true;
87 | }
88 |
89 | float audio::get_playback_position(Sound *sound)
90 | {
91 | XAUDIO2_VOICE_STATE voice_state;
92 | sound->source_voice->GetState(&voice_state, 0);
93 | double samples_played = (double)voice_state.SamplesPlayed;
94 | double total_samples = (double)sound->sample_count;
95 | double duration = (double)sound->sample_count / (double)sound->sample_rate;
96 | double position = duration * samples_played / total_samples;
97 | return (float)position;
98 | }
99 |
100 | void audio::release(Sound *sound)
101 | {
102 | sound->source_voice->DestroyVoice();
103 | free(sound->samples);
104 | *sound = {};
105 | }
--------------------------------------------------------------------------------
/cpplib/audio.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | struct IXAudio2;
5 | struct IXAudio2MasteringVoice;
6 | struct IXAudio2SourceVoice;
7 |
8 | struct Sound
9 | {
10 | int32_t channels;
11 | int32_t sample_rate;
12 | int32_t sample_count;
13 | int16_t *samples;
14 | IXAudio2SourceVoice *source_voice;
15 | };
16 |
17 | struct AudioContext
18 | {
19 | IXAudio2 *engine;
20 | IXAudio2MasteringVoice *master_voice;
21 | };
22 |
23 | namespace audio
24 | {
25 | bool init();
26 |
27 | Sound get_sound_ogg(void *data, uint32_t data_size);
28 | bool play_sound(Sound *sound);
29 | float get_playback_position(Sound *sound);
30 | void release(Sound *sound);
31 | }
--------------------------------------------------------------------------------
/cpplib/export.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "export.h"
4 | #include "file_system.h"
5 | #include "memory.h"
6 | #ifdef CPPLIB_DEBUG_PRINTS
7 | #include "logging.h"
8 | #define PRINT_DEBUG(message, ...) logging::print_error(message, ##__VA_ARGS__)
9 | #else
10 | #define PRINT_DEBUG(message, ...)
11 | #endif
12 |
13 | #define print_to_string sprintf_s
14 |
15 | bool exports::export_to_obj(char *filename, Vector4 *vertices, uint32_t vertex_count, uint32_t vertex_stride, uint16_t *indices, uint32_t index_count)
16 | {
17 | uint32_t number_of_lines = vertex_count * 2 + index_count / 3;
18 | uint32_t max_line_length = 50; // Should suffice for +-10000
19 |
20 | uint32_t total_file_size = number_of_lines * max_line_length;
21 |
22 | char *file_memory = memory::alloc_heap(total_file_size);
23 | char *file_ptr = file_memory;
24 |
25 | int32_t size_left = total_file_size;
26 | for (uint32_t i = 0; i < vertex_count; ++i)
27 | {
28 | Vector4 vertex_position = vertices[i * 2];
29 | uint32_t bytes_written = print_to_string(file_ptr, size_left, "v %.4f %.4f %.4f %.4f\n", vertex_position.x, vertex_position.y, vertex_position.z, vertex_position.w);
30 | if (bytes_written > max_line_length)
31 | {
32 | PRINT_DEBUG("export_to_obj: expected maximum output line length was %d, actual was %d. This may or may not cause errors.", max_line_length, bytes_written);
33 | }
34 | file_ptr += bytes_written;
35 | size_left -= bytes_written;
36 | if (size_left <= 0)
37 | {
38 | PRINT_DEBUG("Buffer overflow while exporting to OBJ!");
39 | }
40 | }
41 | for (uint32_t i = 0; i < vertex_count; ++i)
42 | {
43 | Vector4 vertex_normal = vertices[i * 2 + 1];
44 | uint32_t bytes_written = print_to_string(file_ptr, size_left, "vn %.4f %.4f %.4f %.4f\n", vertex_normal.x, vertex_normal.y, vertex_normal.z, vertex_normal.w);
45 | file_ptr += bytes_written;
46 | size_left -= bytes_written;
47 | if (size_left <= 0)
48 | {
49 | PRINT_DEBUG("Buffer overflow while exporting to OBJ!");
50 | }
51 | }
52 |
53 | for (uint32_t i = 0; i < index_count; i += 3)
54 | {
55 | uint16_t i1 = indices[i] + 1;
56 | uint16_t i2 = indices[i + 1] + 1;
57 | uint16_t i3 = indices[i + 2] + 1;
58 | uint32_t bytes_written = print_to_string(file_ptr, size_left, "f %d//%d %d//%d %d//%d\n", i1, i1, i2, i2, i3, i3);
59 | file_ptr += bytes_written;
60 | size_left -= bytes_written;
61 | if (size_left <= 0)
62 | {
63 | PRINT_DEBUG("Buffer overflow while exporting to OBJ!");
64 | }
65 | }
66 |
67 | if (!file_system::write_file(filename, file_memory, total_file_size - size_left))
68 | {
69 | PRINT_DEBUG("Could not write mesh to %s.", filename);
70 | return false;
71 | }
72 | memory::free_heap(file_memory);
73 | return true;
74 | }
--------------------------------------------------------------------------------
/cpplib/export.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "maths.h"
3 |
4 | namespace exports
5 | {
6 | bool export_to_obj(char *filename, Vector4 *vertices, uint32_t vertex_count, uint32_t vertex_stride, uint16_t *indices, uint32_t index_count);
7 | }
--------------------------------------------------------------------------------
/cpplib/fbx_loader.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include "array.h"
3 | #include "maths.h"
4 | struct Animation;
5 | struct Skeleton;
6 |
7 | struct MeshData
8 | {
9 | Vector4 *vertices;
10 | uint16_t *indices;
11 | uint32_t vertex_count;
12 | uint32_t index_count;
13 | };
14 |
15 | namespace fbx
16 | {
17 | MeshData get_mesh(char *fbx_filename);
18 | MeshData get_animated_mesh(char *fbx_filename, Skeleton *skeleton, Animation **animations, uint32_t *animation_count);
19 | }
20 |
21 |
22 |
--------------------------------------------------------------------------------
/cpplib/file_system.cpp:
--------------------------------------------------------------------------------
1 | #include "file_system.h"
2 | #include
3 |
4 | #ifdef CPPLIB_DEBUG_PRINTS
5 | #include "logging.h"
6 | #define PRINT_DEBUG(message, ...) logging::print_error(message, ##__VA_ARGS__)
7 | #else
8 | #define PRINT_DEBUG(message, ...)
9 | #endif
10 |
11 |
12 | File file_system::read_file(const char* path)
13 | {
14 | File file = {};
15 |
16 | // Open handle to a file
17 | HANDLE file_handle = CreateFileA(path, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
18 | if (file_handle == INVALID_HANDLE_VALUE)
19 | {
20 | PRINT_DEBUG("Unable to open read handle to file %s.", path);
21 | return file;
22 | }
23 |
24 | // Get file attributes, these are necessary to know how much data to allocate for reading
25 | WIN32_FILE_ATTRIBUTE_DATA file_attributes;
26 | if (!GetFileAttributesExA(path, GetFileExInfoStandard, &file_attributes))
27 | {
28 | PRINT_DEBUG("Unable to get attributes of file %s.", path);
29 | CloseHandle(file_handle);
30 | return File{};
31 | }
32 |
33 | // Allocate memory for reading the file contents
34 | uint32_t file_size = file_attributes.nFileSizeLow;
35 | HANDLE heap = GetProcessHeap();
36 | file.data = HeapAlloc(heap, HEAP_ZERO_MEMORY, file_size);
37 |
38 | // Read the file into allocated memory
39 | DWORD bytes_read_from_file = 0;
40 | if (ReadFile(file_handle, file.data, file_size, &bytes_read_from_file, NULL) &&
41 | bytes_read_from_file == file_size)
42 | {
43 | file.size = bytes_read_from_file;
44 | }
45 | else
46 | {
47 | // In case of read error, deallocate memory and close handle
48 | PRINT_DEBUG("Unable to read opened file %s.", path);
49 | HeapFree(heap, 0, file.data);
50 | CloseHandle(file_handle);
51 | return File{};
52 | }
53 |
54 | // Succesfull file reading, close the handle and return the data
55 | CloseHandle(file_handle);
56 | return file;
57 | }
58 |
59 | void file_system::release_file(File file)
60 | {
61 | // Release allocated memory from the heap
62 | HANDLE heap = GetProcessHeap();
63 | HeapFree(heap, 0, file.data);
64 | }
65 |
66 | uint32_t file_system::write_file(const char* path, void *data, uint32_t size)
67 | {
68 | // Open handle to a file
69 | HANDLE file_handle = 0;
70 | file_handle = CreateFileA(path, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS,
71 | FILE_ATTRIBUTE_NORMAL, NULL);
72 | if (file_handle == INVALID_HANDLE_VALUE)
73 | {
74 | PRINT_DEBUG("Unable to open write handle to file %s.", path);
75 | return 0;
76 | }
77 |
78 | // Write to a file
79 | DWORD bytes_written = 0;
80 | if(!WriteFile(file_handle, data, size, &bytes_written, NULL))
81 | {
82 | PRINT_DEBUG("Unable to write to file %s.", path);
83 | return 0;
84 | }
85 |
86 | // Wrote sucessfully, close the handle
87 | CloseHandle(file_handle);
88 | return bytes_written;
89 | }
90 |
--------------------------------------------------------------------------------
/cpplib/file_system.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | // File encapsulates data loaded from the file and its size.
5 | struct File
6 | {
7 | void *data;
8 | uint32_t size;
9 | };
10 |
11 | // file_system namespace enables interfacing with the Windows file system
12 | namespace file_system
13 | {
14 | // Read file at path
15 | File read_file(const char* path);
16 |
17 | // Release read file
18 | void release_file(File file);
19 |
20 | // Write data to file at path
21 | uint32_t write_file(const char* path, void *data, uint32_t size);
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/cpplib/font.cpp:
--------------------------------------------------------------------------------
1 | #include "font.h"
2 | #include "memory.h"
3 |
4 | #ifdef CPPLIB_DEBUG_PRINTS
5 | #include "logging.h"
6 | #define PRINT_DEBUG(message, ...) logging::print_error(message, ##__VA_ARGS__)
7 | #else
8 | #define PRINT_DEBUG(message, ...)
9 | #endif
10 |
11 | // Globally unique objects
12 | FT_Library ft_library;
13 |
14 | bool font::init()
15 | {
16 | int32_t error = FT_Init_FreeType(&ft_library);
17 | if (error) {
18 | PRINT_DEBUG("Error initializing FreeType library!");
19 | return false;
20 | }
21 | return true;
22 | }
23 |
24 | Font font::get(uint8_t *data, int32_t data_size, int32_t size, int32_t texture_size)
25 | {
26 | Font font = {};
27 |
28 | // Store temp allocator stack state
29 | memory::push_temp_state();
30 |
31 | // Allocate memory for the texture
32 | uint8_t *font_buffer = memory::alloc_temp(texture_size * texture_size);
33 | FT_Face face;
34 | int32_t error = FT_New_Memory_Face(ft_library, data, data_size, 0, &face);
35 | if (error) {
36 | PRINT_DEBUG("Error creating font face!");
37 | return Font{};
38 | }
39 |
40 | int32_t supersampling = 1;
41 | error = FT_Set_Pixel_Sizes(face, 0, size);
42 | if (error)
43 | {
44 | PRINT_DEBUG("Error setting pixel size!");
45 | return Font{};
46 | }
47 |
48 | int32_t row_height = face->size->metrics.height / 64;
49 | int32_t ascender = face->size->metrics.ascender / 64;
50 | int32_t descender = face->size->metrics.descender / 64;
51 | int32_t x = 0, y = 0;
52 |
53 | font.row_height = (float)row_height;
54 | font.top_pad = (float)(row_height - (ascender - descender));
55 | font.scale = 1.0f;
56 | font.face = face;
57 |
58 | for (unsigned char c = 32; c < 128; ++c)
59 | {
60 | // Load character c
61 | error = FT_Load_Char(face, c, FT_LOAD_RENDER | FT_LOAD_TARGET_LIGHT);
62 | if(error)
63 | {
64 | PRINT_DEBUG("Error loading character %c!", c);
65 | return Font{};
66 | }
67 |
68 | // Get glyph specific metrics
69 | int x_offset = face->glyph->bitmap_left;
70 | int y_offset = ascender - face->glyph->bitmap_top;
71 | int advance = face->glyph->advance.x >> 6;
72 |
73 | // Get bitmap parameters
74 | int bitmap_width = face->glyph->bitmap.width, bitmap_height = face->glyph->bitmap.rows;
75 | int pitch = face->glyph->bitmap.pitch;
76 |
77 | // In case we don't fit in the row, let's move to next row
78 | if(x > texture_size - bitmap_width)
79 | {
80 | x = 0;
81 | y += row_height;
82 | }
83 |
84 | // Copy over bitmap
85 | for(int32_t r = 0; r < bitmap_height; ++r)
86 | {
87 | uint8_t *source = face->glyph->bitmap.buffer + pitch * r;
88 | uint8_t *dest = font_buffer + (y + r) * texture_size + x;
89 | memcpy(dest, source, bitmap_width);
90 | }
91 |
92 | // Store glyph settings
93 | font.glyphs[c - 32] = {x, y, bitmap_width, bitmap_height, x_offset, y_offset, advance};
94 |
95 | // Move in the bitmap
96 | x += bitmap_width;
97 | }
98 |
99 | // Initialize D3D texture for the Font
100 | font.texture = graphics::get_texture2D(font_buffer, texture_size, texture_size, DXGI_FORMAT_R8_UNORM, 1);
101 | if(!graphics::is_ready(&font.texture))
102 | {
103 | PRINT_DEBUG("Could not create texture for font.");
104 | return Font{};
105 | }
106 |
107 | // Restore memory state of the temp allocator
108 | memory::pop_temp_state();
109 |
110 | return font;
111 | }
112 |
113 | float font::get_kerning(Font *font, char c1, char c2)
114 | {
115 | FT_Vector kerning;
116 | int32_t left_glyph_index = FT_Get_Char_Index(font->face, c1);
117 | int32_t right_glyph_index = FT_Get_Char_Index(font->face, c2);
118 | FT_Get_Kerning(font->face, left_glyph_index, right_glyph_index, FT_KERNING_DEFAULT, &kerning);
119 | return (float)kerning.x;
120 | }
121 |
122 | float font::get_string_width(const char *string, Font *font)
123 | {
124 | float width = 0;
125 | int i = 0;
126 | while(string[i])
127 | {
128 | // Get a glyph for the current character
129 | char c = string[i];
130 | Glyph glyph = font->glyphs[c - 32];
131 |
132 | // Increment width by character's advance. This should be more precise than taking it's bitmap's width.
133 | width += glyph.advance;
134 |
135 | // Take kerning into consideration
136 | if (string[i+1])
137 | width += font::get_kerning(font, c, string[i+1]);
138 |
139 | // Next letter
140 | i++;
141 | }
142 |
143 | return width;
144 | }
145 |
146 | float font::get_row_height(Font *font)
147 | {
148 | return font->row_height;
149 | }
150 |
151 | void font::release(Font *font)
152 | {
153 | graphics::release(&font->texture);
154 | }
155 |
--------------------------------------------------------------------------------
/cpplib/font.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "graphics.h"
3 | #include "ft2build.h"
4 | #include FT_FREETYPE_H
5 |
6 | // TODO: do floats
7 | // Glyph specifies information aobut a single letter at a single scale
8 | struct Glyph
9 | {
10 | int bitmap_x, bitmap_y;
11 | int bitmap_width, bitmap_height;
12 | int x_offset, y_offset;
13 | int advance;
14 | };
15 |
16 | // Font contains data for rendering text at specific scale
17 | struct Font
18 | {
19 | Glyph glyphs[96];
20 | float row_height;
21 | float top_pad;
22 | float scale;
23 | Texture2D texture;
24 | FT_Face face;
25 | };
26 |
27 | // font namespace handles loading Fonts and extracting information from it
28 | namespace font
29 | {
30 | /*
31 | Return initialized Font object
32 |
33 | Args:
34 | - data: binary data from .ttf/.otf file
35 | - data_size: size of data block in bytes
36 | - size: height of the font in pixels
37 | - texture_size: size of a side of texture that stores font bitmap, in pixels
38 | */
39 | Font get(uint8_t *data, int32_t data_size, int32_t size, int32_t texture_size);
40 |
41 | // Initialize font rasterization code (FreeType2)
42 | bool init();
43 |
44 | // Return height of a single row for a Font
45 | float get_row_height(Font *font);
46 |
47 | // Return width of a string
48 | float get_string_width(const char *string, Font *font);
49 |
50 | // Get kerning between two letters of a Font
51 | float get_kerning(Font *font, char c1, char c2);
52 |
53 | // Release a Font object
54 | void release(Font *font);
55 | }
--------------------------------------------------------------------------------
/cpplib/fonts/ShareTechMono-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/fonts/ShareTechMono-Regular.ttf
--------------------------------------------------------------------------------
/cpplib/fonts/UbuntuMono-R.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/fonts/UbuntuMono-R.ttf
--------------------------------------------------------------------------------
/cpplib/fonts/consola.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/fonts/consola.ttf
--------------------------------------------------------------------------------
/cpplib/fonts/renner-book.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/fonts/renner-book.otf
--------------------------------------------------------------------------------
/cpplib/freetype/include/freetype/config/ftmodule.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file registers the FreeType modules compiled into the library.
3 | *
4 | * If you use GNU make, this file IS NOT USED! Instead, it is created in
5 | * the objects directory (normally `/objs/') based on information
6 | * from `/modules.cfg'.
7 | *
8 | * Please read `docs/INSTALL.ANY' and `docs/CUSTOMIZE' how to compile
9 | * FreeType without GNU make.
10 | *
11 | */
12 |
13 | FT_USE_MODULE( FT_Module_Class, autofit_module_class )
14 | FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class )
15 | FT_USE_MODULE( FT_Driver_ClassRec, t1_driver_class )
16 | FT_USE_MODULE( FT_Driver_ClassRec, cff_driver_class )
17 | FT_USE_MODULE( FT_Driver_ClassRec, t1cid_driver_class )
18 | FT_USE_MODULE( FT_Driver_ClassRec, pfr_driver_class )
19 | FT_USE_MODULE( FT_Driver_ClassRec, t42_driver_class )
20 | FT_USE_MODULE( FT_Driver_ClassRec, winfnt_driver_class )
21 | FT_USE_MODULE( FT_Driver_ClassRec, pcf_driver_class )
22 | FT_USE_MODULE( FT_Module_Class, psaux_module_class )
23 | FT_USE_MODULE( FT_Module_Class, psnames_module_class )
24 | FT_USE_MODULE( FT_Module_Class, pshinter_module_class )
25 | FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class )
26 | FT_USE_MODULE( FT_Module_Class, sfnt_module_class )
27 | FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class )
28 | FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class )
29 | FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcdv_renderer_class )
30 | FT_USE_MODULE( FT_Driver_ClassRec, bdf_driver_class )
31 |
32 | /* EOF */
33 |
--------------------------------------------------------------------------------
/cpplib/freetype/include/freetype/ftbbox.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************/
2 | /* */
3 | /* ftbbox.h */
4 | /* */
5 | /* FreeType exact bbox computation (specification). */
6 | /* */
7 | /* Copyright 1996-2016 by */
8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 | /* */
10 | /* This file is part of the FreeType project, and may only be used, */
11 | /* modified, and distributed under the terms of the FreeType project */
12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 | /* this file you indicate that you have read the license and */
14 | /* understand and accept it fully. */
15 | /* */
16 | /***************************************************************************/
17 |
18 |
19 | /*************************************************************************/
20 | /* */
21 | /* This component has a _single_ role: to compute exact outline bounding */
22 | /* boxes. */
23 | /* */
24 | /* It is separated from the rest of the engine for various technical */
25 | /* reasons. It may well be integrated in `ftoutln' later. */
26 | /* */
27 | /*************************************************************************/
28 |
29 |
30 | #ifndef FTBBOX_H_
31 | #define FTBBOX_H_
32 |
33 |
34 | #include
35 | #include FT_FREETYPE_H
36 |
37 | #ifdef FREETYPE_H
38 | #error "freetype.h of FreeType 1 has been loaded!"
39 | #error "Please fix the directory search order for header files"
40 | #error "so that freetype.h of FreeType 2 is found first."
41 | #endif
42 |
43 |
44 | FT_BEGIN_HEADER
45 |
46 |
47 | /*************************************************************************/
48 | /* */
49 | /* */
50 | /* outline_processing */
51 | /* */
52 | /*************************************************************************/
53 |
54 |
55 | /*************************************************************************/
56 | /* */
57 | /* */
58 | /* FT_Outline_Get_BBox */
59 | /* */
60 | /* */
61 | /* Compute the exact bounding box of an outline. This is slower */
62 | /* than computing the control box. However, it uses an advanced */
63 | /* algorithm that returns _very_ quickly when the two boxes */
64 | /* coincide. Otherwise, the outline Bézier arcs are traversed to */
65 | /* extract their extrema. */
66 | /* */
67 | /* */
68 | /* outline :: A pointer to the source outline. */
69 | /* */
70 | /*