├── icon.png ├── data ├── icons │ ├── icon128.png │ ├── icon16.png │ ├── icon24.png │ ├── icon256.png │ ├── icon32.png │ ├── icon48.png │ └── icon64.png ├── images │ └── icons.png ├── fonts │ ├── Montserrat-Medium.ttf │ └── Montserrat-Medium.min.ttf ├── goxel2.desktop ├── themes │ ├── dark.ini │ └── light.ini ├── progs │ ├── test3.goxcf │ ├── test.goxcf │ ├── test2.goxcf │ ├── tree-small.goxcf │ ├── cherry.goxcf │ ├── planet.goxcf │ ├── tree-big.goxcf │ ├── city.goxcf │ └── intro.goxcf ├── palettes │ ├── db16.gpl │ ├── Pastels.gpl │ ├── Grays.gpl │ ├── db32.gpl │ ├── echo-palette.gpl │ ├── Tango-Palette.gpl │ ├── Ubuntu.gpl │ └── Gold.gpl ├── Info.plist ├── shaders │ ├── background.glsl │ ├── shadow_map.glsl │ ├── pos_data.glsl │ └── model3d.glsl └── other │ └── povray_template.pov ├── screenshots ├── screenshot-dicom.png ├── screenshot-plane.png ├── screenshot-castle.png └── screenshot-procedural-city.png ├── src ├── downloader.h ├── downloader.c ├── exposed_funcs.h ├── utils │ ├── ini.h │ ├── ini.c │ ├── color.h │ ├── b64.h │ ├── mustache.h │ ├── json.h │ ├── img.h │ ├── texture.h │ ├── box.c │ ├── b64.c │ ├── cache.h │ ├── color.c │ └── cache.c ├── assets │ ├── other.inl │ └── themes.inl ├── lua_plugins.h ├── dialogs_osx.m ├── gui │ ├── about.c │ ├── image_panel.c │ ├── quit.c │ ├── topbar.c │ ├── debug_panel.c │ ├── light_panel.c │ ├── palette_panel.c │ ├── lospec.c │ ├── export_panel.c │ ├── view_panel.c │ ├── material_panel.c │ ├── tools_panel.c │ └── cameras_panel.c ├── shape.h ├── assets.h ├── glew-mx.h ├── material.h ├── config.h ├── material.c ├── shader_cache.h ├── gesture3d.h ├── palette.h ├── log.h ├── layer.h ├── file_format.h ├── yocto.cpp ├── tools │ ├── color_picker.c │ └── laser.c ├── pathtracer.h ├── formats │ ├── png_slices.c │ ├── png.c │ └── txt.c ├── assets.c ├── inputs.h ├── actions.h ├── exposed_funcs.c ├── lua_plugins.c ├── file_format.c ├── image.h ├── tools.h ├── shader_cache.c ├── action.c ├── layer.c ├── action.h ├── gesture3d.c └── model3d.h ├── .gitignore ├── Makefile ├── lib └── lua-5.4.4 │ ├── lua.hpp │ ├── lundump.h │ ├── lprefix.h │ ├── lualib.h │ ├── lapi.h │ ├── lzio.c │ ├── lopnames.h │ ├── lzio.h │ ├── lstring.h │ ├── linit.c │ ├── lfunc.h │ ├── ljumptab.h │ ├── ldebug.h │ ├── ltable.h │ ├── lctype.h │ ├── lctype.c │ ├── llex.h │ ├── ldo.h │ └── ltm.h ├── AUTHORS ├── AUTHORS.md ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── tools ├── create_font.py ├── create_icons.py └── create_assets.py ├── INTERNALS.md ├── CHANGELOG.md └── CONTRIBUTING.md /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/icon.png -------------------------------------------------------------------------------- /data/icons/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/data/icons/icon128.png -------------------------------------------------------------------------------- /data/icons/icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/data/icons/icon16.png -------------------------------------------------------------------------------- /data/icons/icon24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/data/icons/icon24.png -------------------------------------------------------------------------------- /data/icons/icon256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/data/icons/icon256.png -------------------------------------------------------------------------------- /data/icons/icon32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/data/icons/icon32.png -------------------------------------------------------------------------------- /data/icons/icon48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/data/icons/icon48.png -------------------------------------------------------------------------------- /data/icons/icon64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/data/icons/icon64.png -------------------------------------------------------------------------------- /data/images/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/data/images/icons.png -------------------------------------------------------------------------------- /data/fonts/Montserrat-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/data/fonts/Montserrat-Medium.ttf -------------------------------------------------------------------------------- /screenshots/screenshot-dicom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/screenshots/screenshot-dicom.png -------------------------------------------------------------------------------- /screenshots/screenshot-plane.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/screenshots/screenshot-plane.png -------------------------------------------------------------------------------- /screenshots/screenshot-castle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/screenshots/screenshot-castle.png -------------------------------------------------------------------------------- /data/fonts/Montserrat-Medium.min.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/data/fonts/Montserrat-Medium.min.ttf -------------------------------------------------------------------------------- /screenshots/screenshot-procedural-city.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frokk/goxel2/HEAD/screenshots/screenshot-procedural-city.png -------------------------------------------------------------------------------- /src/downloader.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int DownloadFileFrom(const char* url, const char* filePath); 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.swp 3 | *~ 4 | *.obj 5 | .sconsign.dblite 6 | /.sconf_temp 7 | /goxel2 8 | /imgui.ini 9 | /config.log 10 | .DS_Store 11 | xcuserdata/ 12 | /todo 13 | /.vimrc 14 | .SRCINFO 15 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL = bash 2 | .ONESHELL: 3 | 4 | all: 5 | scons -j 4 6 | 7 | release: 8 | scons mode=release 9 | 10 | profile: 11 | scons mode=profile 12 | 13 | run: 14 | ./goxel2 15 | 16 | clean: 17 | scons -c 18 | -------------------------------------------------------------------------------- /data/goxel2.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Goxel2 3 | Comment=A cross-platform 3D voxel editor. 4 | GenericName=Voxel graphics editor 5 | TryExec=goxel2 6 | Exec=goxel2 7 | Icon=goxel2 8 | Type=Application 9 | Categories=Graphics;3DGraphics; 10 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Goxel was created by: 2 | Guillaume Chereau 3 | 4 | Other contributors: 5 | Dustin Willis Webber 6 | Pablo Hugo Reda 7 | Othelarian (https://github.com/othelarian) 8 | Michał (https://github.com/YarlBoro) 9 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | # Authors 2 | this file lists people who have contributed in goxel2's code. 3 | 4 | 1. https://github.com/xtreme8000 5 | 2. https://github.com/bztsrc 6 | 7 | Goxel2 uses the Montserrat font licensed under [Open Font License](https://scripts.sil.org/OFL): 8 | 9 | --- 10 | 11 | ## Thanks 12 | -------------------------------------------------------------------------------- /data/themes/dark.ini: -------------------------------------------------------------------------------- 1 | [theme] 2 | name=dark 3 | 4 | [base] 5 | background=#2D2D2DFF 6 | outline=#FF 7 | inner=#595959FF 8 | inner_selected=#0F87FAFF 9 | text=#CCCCCCFF 10 | text_selected=#FFFFFFFF 11 | 12 | [widget] 13 | 14 | [tab] 15 | background=#FF 16 | inner=#444444FF 17 | 18 | [menu] 19 | inner=#353535FF 20 | 21 | [titlebar] 22 | text=#E7E7E7FF 23 | background=#4FA9FFFF 24 | -------------------------------------------------------------------------------- /data/progs/test3.goxcf: -------------------------------------------------------------------------------- 1 | shape main { 2 | [antialiased 1] 3 | loop 8 [rz 45] { 4 | test [s 20 x 2] 5 | } 6 | } 7 | 8 | shape test { 9 | [sat 0.4 light -0.2 hue 240] 10 | sphere[] 11 | cube [z 0.5 sub] 12 | tige (15) [s 0.5 light -0.5] 13 | } 14 | 15 | shape tige ($n) { 16 | cylinder[] 17 | if $n { 18 | tige($n - 1)[z 0.5 ry $n z 0.5 sat -0.1] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /data/progs/test.goxcf: -------------------------------------------------------------------------------- 1 | // Simple Test 2 | 3 | shape branch 4 | rule { 5 | cylinder [sz 0.7] 6 | branch [rz 0 z 0.25 s 0.9 rx 30 z 0.25 7 | light -0.1 hue 10 sat 0.1] 8 | } 9 | rule 0.2 { 10 | branch [rz 180] 11 | } 12 | rule 0.2 { 13 | branch [rz 90] 14 | } 15 | rule 0.1 { 16 | branch [rx -90 s 0.8 z 1] 17 | branch [] 18 | } 19 | 20 | shape main { 21 | [light 1 antialiased 1] 22 | branch [s 32] 23 | } 24 | -------------------------------------------------------------------------------- /data/palettes/db16.gpl: -------------------------------------------------------------------------------- 1 | GIMP Palette 2 | Name: DB16 3 | Columns: 8 4 | # 5 | 20 12 28 Dark1 6 | 68 36 52 Dark2 7 | 48 52 109 Dark3 8 | 78 74 78 Dark4 9 | 133 76 48 Dark5 10 | 52 101 36 Dark6 11 | 208 70 72 Dark7 12 | 117 113 97 Dark8 13 | 89 125 206 Light1 14 | 210 125 44 Light2 15 | 133 149 161 Light3 16 | 109 170 44 Light4 17 | 210 170 153 Light5 18 | 109 194 202 Light6 19 | 218 212 94 Light7 20 | 222 238 214 Light8 21 | -------------------------------------------------------------------------------- /src/downloader.c: -------------------------------------------------------------------------------- 1 | #include "downloader.h" 2 | 3 | // Curl for Windows: https://curl.se/windows/ 4 | 5 | int DownloadFileFrom(const char* url, const char* filePath) { 6 | char* command = NULL; 7 | 8 | // Just Download With Curl, Windows 10 Comes Installed With Curl, if user doesn't have it we can just tell them to install it. 9 | asprintf(&command, "curl -L %s --output %s", url, filePath); 10 | int result = system((const char*)command); 11 | 12 | free(command); 13 | return result; 14 | } -------------------------------------------------------------------------------- /data/progs/test2.goxcf: -------------------------------------------------------------------------------- 1 | shape main { 2 | [antialiased 1] 3 | [light 0.5 sat 0.5 s 100] 4 | loop 5 [s -0.95 light 0.1 sat 0.01 hue 5] { 5 | sphere [light -0.6 hue 30] 6 | } 7 | loop 30 [wait 1] { 8 | sphere [sub rz 0+-180 ry 0+-180 9 | z 0.5 s 0.3] 10 | } 11 | loop 2 [rz 90] { 12 | loop 120 [ry 10 wait 1] { 13 | sphere [hue 30+-30 light -0.5+-0.4 14 | z 0.5 s 0.05+-0.01 z 4+-0.5] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /data/progs/tree-small.goxcf: -------------------------------------------------------------------------------- 1 | shape branch2 { 2 | cube[] 3 | branch2 [z 0.5 s 0.8 rx 20+-4 z 0.5] 4 | } 5 | 6 | shape branch { 7 | [rx 90] 8 | branch2[s 2] 9 | } 10 | 11 | shape tree($s) { 12 | loop $s [z 1] { 13 | cube[s 1 light -0.8+-0.1 sat 0.5] 14 | } 15 | [z $s] 16 | [sat 1 light -0.5 hue 50+-30] 17 | loop 6 [rz 360 / 6 rz 0+-10] { 18 | branch[light 0+-0.3] 19 | } 20 | } 21 | 22 | shape main { 23 | [antialiased 0] 24 | tree(8+-2)[] 25 | } 26 | -------------------------------------------------------------------------------- /data/themes/light.ini: -------------------------------------------------------------------------------- 1 | [theme] 2 | name=light 3 | 4 | [base] 5 | background=#C8C8C8FF 6 | outline=#666666FF 7 | inner=#ABABABFF 8 | inner_selected=#4FA9FFFF 9 | text=#222222FF 10 | text_selected=#444444FF 11 | 12 | [widget] 13 | outline=#777777FF 14 | inner=#E7E7E7FF 15 | inner_selected=#4FA9FFFF 16 | text=#333333FF 17 | text_selected=#444444FF 18 | 19 | [tab] 20 | background=#ABABABFF 21 | inner=#E7E7E7FF 22 | inner_selected=#4FA9FFFF 23 | 24 | [menu] 25 | inner=#E7E7E7FF 26 | 27 | [titlebar] 28 | text=#FFFFFFFF 29 | background=#4FA9FFFF 30 | -------------------------------------------------------------------------------- /data/palettes/Pastels.gpl: -------------------------------------------------------------------------------- 1 | GIMP Palette 2 | Name: Pastels 3 | # Pastels -- GIMP Palette file 4 | 226 145 145 Untitled 5 | 153 221 146 Untitled 6 | 147 216 185 Untitled 7 | 148 196 211 Untitled 8 | 148 154 206 Untitled 9 | 179 148 204 Untitled 10 | 204 150 177 Untitled 11 | 204 164 153 Untitled 12 | 223 229 146 Untitled 13 | 255 165 96 Untitled 14 | 107 255 99 Untitled 15 | 101 255 204 Untitled 16 | 101 196 255 Untitled 17 | 101 107 255 Untitled 18 | 173 101 255 Untitled 19 | 255 101 244 Untitled 20 | 255 101 132 Untitled 21 | 255 101 101 Untitled 22 | -------------------------------------------------------------------------------- /data/progs/cherry.goxcf: -------------------------------------------------------------------------------- 1 | shape main { 2 | [seed 7] 3 | tree(0, 40, 10)[s 10 light -0.9] 4 | } 5 | 6 | shape tree($n, $e, $f) 7 | rule { 8 | cylinder[] 9 | if ($n < $e) { 10 | tree($n + 1)[rz 0+-10 z 0.5 s 0.95 z 0.5 rx 4] 11 | } 12 | if (($n >= $e) || ($n > $f && 0+-1 > 0.5)) { 13 | flower[] 14 | } 15 | } 16 | rule 0.1 { 17 | tree[rz 180] 18 | } 19 | rule 0.08 { 20 | tree[] 21 | tree($n + 1)[rz 0+-180 rx -45] 22 | } 23 | 24 | shape flower { 25 | [light 0.5 sat 0.7 sn 1 s 6 z -0.5 x -1 hue -10] 26 | sphere[x 0+-0.5 0+-0.5 light 0+-0.2] 27 | } -------------------------------------------------------------------------------- /data/progs/planet.goxcf: -------------------------------------------------------------------------------- 1 | // Simple planet 2 | shape main { 3 | [s 50] 4 | sphere [sat 0.5 light -0.75 hue 200] 5 | loop 3 [] { 6 | continent[rz 0+-180 ry 0+-180 7 | hue 1 40+-10 sat 1 0.5 8 | light -0.5+-0.1] 9 | } 10 | loop 16 [wait 1] { 11 | cloud [rz 0+-180 ry 0+-180 12 | hue 200 light -0.1 sat 0.5] 13 | } 14 | } 15 | 16 | shape continent { 17 | loop 30 [rz 10 rx 0+-80 wait 1] { 18 | sphere[x 0.3 s 0.4+-0.05] 19 | } 20 | } 21 | 22 | shape cloud { 23 | loop 5 [rz 2 rx 0+-180 wait 1] { 24 | sphere[x 0.5 s 0.04 +- 0.01] 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /data/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleName 6 | Goxel2 7 | CFBundleIcon 8 | Goxel2 9 | CFBundleExecutable 10 | goxel2 11 | CFBundleIconFile 12 | goxel2.icns 13 | CFBundleShortVersionString 14 | 0.14 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundlePackageType 18 | APPL 19 | 20 | 21 | -------------------------------------------------------------------------------- /data/progs/tree-big.goxcf: -------------------------------------------------------------------------------- 1 | 2 | shape leaf { 3 | cube[] 4 | leaf[x 0.5 s 0.9 0.9 0.8 ry 25 x 0.4] 5 | } 6 | 7 | shape top { 8 | loop 8 [rz 360 / 8] { 9 | [life 8 sy 2 z 0+-5] 10 | leaf[s 5 light -0.4 sat 0.5 hue 60+-20 ry -45] 11 | } 12 | } 13 | 14 | shape part($n) { 15 | loop $i = $n [z 1 rz 30+-10 rx 0+-10 wait 1] { 16 | cylinder[s 4 x 0.1 light 0+-0.1] 17 | if ($i == int($n - 2)) { 18 | top[] 19 | } 20 | } 21 | } 22 | 23 | shape main { 24 | [antialiased 1 hue 40 light -0.5 sat 0.5] 25 | $n = 40+-10 26 | loop 3 [rz 120+-45] { 27 | [y 0.5] 28 | part($n)[light -0.3+-0.05] 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /data/shaders/background.glsl: -------------------------------------------------------------------------------- 1 | varying lowp vec4 v_color; 2 | 3 | #ifdef VERTEX_SHADER 4 | 5 | /************************************************************************/ 6 | attribute highp vec3 a_pos; 7 | attribute lowp vec4 a_color; 8 | 9 | void main() 10 | { 11 | gl_Position = vec4(a_pos, 1.0); 12 | v_color = a_color; 13 | } 14 | /************************************************************************/ 15 | 16 | #endif 17 | 18 | #ifdef FRAGMENT_SHADER 19 | 20 | /************************************************************************/ 21 | void main() 22 | { 23 | gl_FragColor = v_color; 24 | } 25 | /************************************************************************/ 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /data/palettes/Grays.gpl: -------------------------------------------------------------------------------- 1 | GIMP Palette 2 | Name: Grays 3 | # 4 | 0 0 0 gray0 5 | 7 7 7 gray3 6 | 15 15 15 gray6 7 | 23 23 23 gray9 8 | 31 31 31 gray12 9 | 39 39 39 gray15 10 | 47 47 47 gray18 11 | 55 55 55 gray21 12 | 63 63 63 gray25 13 | 71 71 71 gray28 14 | 79 79 79 gray31 15 | 87 87 87 gray34 16 | 95 95 95 gray37 17 | 103 103 103 gray40 18 | 111 111 111 gray43 19 | 119 119 119 gray46 20 | 127 127 127 gray50 21 | 135 135 135 gray53 22 | 143 143 143 gray56 23 | 151 151 151 gray59 24 | 159 159 159 gray62 25 | 167 167 167 gray65 26 | 175 175 175 gray68 27 | 183 183 183 gray71 28 | 191 191 191 gray75 29 | 199 199 199 gray78 30 | 207 207 207 gray81 31 | 215 215 215 gray84 32 | 223 223 223 gray87 33 | 231 231 231 gray90 34 | 239 239 239 gray93 35 | 247 247 247 gray96 36 | -------------------------------------------------------------------------------- /data/shaders/shadow_map.glsl: -------------------------------------------------------------------------------- 1 | #ifdef VERTEX_SHADER 2 | 3 | /************************************************************************/ 4 | attribute highp vec3 a_pos; 5 | uniform highp mat4 u_model; 6 | uniform highp mat4 u_view; 7 | uniform highp mat4 u_proj; 8 | uniform mediump float u_pos_scale; 9 | void main() 10 | { 11 | gl_Position = u_proj * u_view * u_model * vec4(a_pos * u_pos_scale, 1.0); 12 | } 13 | 14 | /************************************************************************/ 15 | 16 | #endif 17 | 18 | #ifdef FRAGMENT_SHADER 19 | 20 | /************************************************************************/ 21 | void main() {} 22 | /************************************************************************/ 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **System information (please complete the following information):** 27 | - OS: [e.g. Windows 10] 28 | - Goxel2 Version [e.g. 0.11.1] 29 | 30 | **Additional context** 31 | Add any other context about the problem here. 32 | -------------------------------------------------------------------------------- /data/palettes/db32.gpl: -------------------------------------------------------------------------------- 1 | GIMP Palette 2 | Name: DB32 3 | Columns: 8 4 | # 5 | 0 0 0 Black 6 | 34 32 52 Valhalla 7 | 69 40 60 Loulou 8 | 102 57 49 Oiled cedar 9 | 143 86 59 Rope 10 | 223 113 38 Tahiti gold 11 | 217 160 102 Twine 12 | 238 195 154 Pancho 13 | 251 242 54 Golden fizz 14 | 153 229 80 Atlantis 15 | 106 190 48 Christi 16 | 55 148 110 Elf green 17 | 75 105 47 Dell 18 | 82 75 36 Verdigris 19 | 50 60 57 Opal 20 | 63 63 116 Deep koamaru 21 | 48 96 130 Venice blue 22 | 91 110 225 Royal blue 23 | 99 155 255 Cornflower 24 | 95 205 228 Viking 25 | 203 219 252 Light steel blue 26 | 255 255 255 White 27 | 155 173 183 Heather 28 | 132 126 135 Topaz 29 | 105 106 106 Dim gray 30 | 89 86 82 Smokey ash 31 | 118 66 138 Clairvoyant 32 | 172 50 50 Brown 33 | 217 87 99 Mandy 34 | 215 123 186 Plum 35 | 143 151 74 Rain forest 36 | 138 111 48 Stinger 37 | -------------------------------------------------------------------------------- /data/palettes/echo-palette.gpl: -------------------------------------------------------------------------------- 1 | GIMP Palette 2 | Name: Echo Icon Theme Palette 3 | Columns: 3 4 | # 5 | 25 174 255 Blue1 6 | 0 132 200 Blue2 7 | 0 92 148 Blue3 8 | 255 65 65 Red1 9 | 220 0 0 Red2 10 | 181 0 0 Red3 11 | 255 255 62 Orange1 12 | 255 153 0 Orange2 13 | 255 102 0 Orange3 14 | 255 192 34 Brown1 15 | 184 129 0 Brown2 16 | 128 77 0 Brown3 17 | 204 255 66 Green1 18 | 154 222 0 Green2 19 | 0 145 0 Green3 20 | 241 202 255 Purple1 21 | 215 108 255 Purple2 22 | 186 0 255 Purple3 23 | 189 205 212 Metalic1 24 | 158 171 176 Metalic2 25 | 54 78 89 Metalic3 26 | 14 35 46 Metalic4 27 | 255 255 255 Grey1 28 | 204 204 204 Grey2 29 | 153 153 153 Grey3 30 | 102 102 102 Grey4 31 | 45 45 45 Grey5 32 | -------------------------------------------------------------------------------- /data/palettes/Tango-Palette.gpl: -------------------------------------------------------------------------------- 1 | GIMP Palette 2 | Name: Tango icons 3 | Columns: 3 4 | # 5 | 252 233 79 Butter 1 6 | 237 212 0 Butter 2 7 | 196 160 0 Butter 3 8 | 138 226 52 Chameleon 1 9 | 115 210 22 Chameleon 2 10 | 78 154 6 Chameleon 3 11 | 252 175 62 Orange 1 12 | 245 121 0 Orange 2 13 | 206 92 0 Orange 3 14 | 114 159 207 Sky Blue 1 15 | 52 101 164 Sky Blue 2 16 | 32 74 135 Sky Blue 3 17 | 173 127 168 Plum 1 18 | 117 80 123 Plum 2 19 | 92 53 102 Plum 3 20 | 233 185 110 Chocolate 1 21 | 193 125 17 Chocolate 2 22 | 143 89 2 Chocolate 3 23 | 239 41 41 Scarlet Red 1 24 | 204 0 0 Scarlet Red 2 25 | 164 0 0 Scarlet Red 3 26 | 255 255 255 Snowy White 27 | 238 238 236 Aluminium 1 28 | 211 215 207 Aluminium 2 29 | 186 189 182 Aluminium 3 30 | 136 138 133 Aluminium 4 31 | 85 87 83 Aluminium 5 32 | 46 52 54 Aluminium 6 33 | 0 0 0 Jet Black 34 | -------------------------------------------------------------------------------- /src/exposed_funcs.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2022 Aditya Mishra 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | int lua_GoxCreateBoxAt(lua_State* L); 22 | int lua_GoxRemoveBoxAt(lua_State* L); 23 | int lua_GoxSetColor(lua_State* L); 24 | -------------------------------------------------------------------------------- /src/utils/ini.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | // Just include ini.h file, with proper defines. 20 | 21 | #define INI_HANDLER_LINENO 1 22 | #include "../../lib/inih/ini.h" 23 | -------------------------------------------------------------------------------- /data/other/povray_template.pov: -------------------------------------------------------------------------------- 1 | // Generated from goxel {{version}} 2 | // https://github.com/guillaumechereau/goxel 3 | 4 | {{#camera}} 5 | camera { 6 | perspective 7 | right x*{{width}}/{{height}} 8 | direction <0, 0, -1> 9 | angle {{angle}} 10 | transform { 11 | matrix {{modelview}} 12 | inverse 13 | } 14 | } 15 | {{/camera}} 16 | 17 | #declare Voxel = box {<-0.5, -0.5, -0.5>, <0.5, 0.5, 0.5>} 18 | #macro Vox(Pos, Color) 19 | object { 20 | Voxel 21 | translate Pos 22 | translate <0.5, 0.5, 0.5> 23 | texture { pigment {color rgb Color / 255} } 24 | } 25 | #end 26 | 27 | {{#light}} 28 | global_settings { ambient_light rgb<1, 1, 1> * {{ambient}} } 29 | light_source { 30 | <0, 0, 1024> color rgb <2, 2, 2> 31 | parallel 32 | point_at {{point_at}} 33 | } 34 | {{/light}} 35 | 36 | union { 37 | {{#voxels}} 38 | Vox({{pos}}, {{color}}) 39 | {{/voxels}} 40 | } 41 | -------------------------------------------------------------------------------- /data/shaders/pos_data.glsl: -------------------------------------------------------------------------------- 1 | varying lowp vec2 v_pos_data; 2 | uniform highp mat4 u_model; 3 | uniform highp mat4 u_view; 4 | uniform highp mat4 u_proj; 5 | uniform lowp vec2 u_block_id; 6 | 7 | #ifdef VERTEX_SHADER 8 | 9 | /************************************************************************/ 10 | attribute highp vec3 a_pos; 11 | attribute lowp vec2 a_pos_data; 12 | 13 | void main() 14 | { 15 | highp vec3 pos = a_pos; 16 | gl_Position = u_proj * u_view * u_model * vec4(pos, 1.0); 17 | v_pos_data = a_pos_data; 18 | } 19 | /************************************************************************/ 20 | 21 | #endif 22 | 23 | #ifdef FRAGMENT_SHADER 24 | 25 | /************************************************************************/ 26 | void main() 27 | { 28 | gl_FragColor.rg = u_block_id; 29 | gl_FragColor.ba = v_pos_data; 30 | } 31 | /************************************************************************/ 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/assets/other.inl: -------------------------------------------------------------------------------- 1 | /* This file is autogenerated by tools/create_assets.py */ 2 | 3 | { 4 | .path = "data/other/povray_template.pov", 5 | .size = 748, 6 | .data = "// Generated from goxel {{version}}\n// https://github.com/guillaumechereau/goxel\n\n{{#camera}}\ncamera {\n perspective\n right x*{{width}}/{{height}}\n direction <0, 0, -1>\n angle {{angle}}\n transform {\n matrix {{modelview}}\n inverse\n }\n}\n{{/camera}}\n\n#declare Voxel = box {<-0.5, -0.5, -0.5>, <0.5, 0.5, 0.5>}\n#macro Vox(Pos, Color)\n object {\n Voxel\n translate Pos\n translate <0.5, 0.5, 0.5>\n texture { pigment {color rgb Color / 255} }\n }\n#end\n\n{{#light}}\nglobal_settings { ambient_light rgb<1, 1, 1> * {{ambient}} }\nlight_source {\n <0, 0, 1024> color rgb <2, 2, 2>\n parallel\n point_at {{point_at}}\n}\n{{/light}}\n\nunion {\n{{#voxels}}\n Vox({{pos}}, {{color}})\n{{/voxels}}\n}\n" 7 | }, 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/assets/themes.inl: -------------------------------------------------------------------------------- 1 | /* This file is autogenerated by tools/create_assets.py */ 2 | 3 | { 4 | .path = "data/themes/dark.ini", 5 | .size = 260, 6 | .data = "[theme]\nname=dark\n\n[base]\nbackground=#2D2D2DFF\noutline=#FF\ninner=#595959FF\ninner_selected=#0F87FAFF\ntext=#CCCCCCFF\ntext_selected=#FFFFFFFF\n\n[widget]\n\n[tab]\nbackground=#FF\ninner=#444444FF\n\n[menu]\ninner=#353535FF\n\n[titlebar]\ntext=#E7E7E7FF\nbackground=#4FA9FFFF\n" 7 | }, 8 | 9 | { 10 | .path = "data/themes/light.ini", 11 | .size = 396, 12 | .data = "[theme]\nname=light\n\n[base]\nbackground=#C8C8C8FF\noutline=#666666FF\ninner=#ABABABFF\ninner_selected=#4FA9FFFF\ntext=#222222FF\ntext_selected=#444444FF\n\n[widget]\noutline=#777777FF\ninner=#E7E7E7FF\ninner_selected=#4FA9FFFF\ntext=#333333FF\ntext_selected=#444444FF\n\n[tab]\nbackground=#ABABABFF\ninner=#E7E7E7FF\ninner_selected=#4FA9FFFF\n\n[menu]\ninner=#E7E7E7FF\n\n[titlebar]\ntext=#FFFFFFFF\nbackground=#4FA9FFFF\n" 13 | }, 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/lua_plugins.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2022 Aditya Mishra 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | // Free All The VMs 22 | void ReleaseAllLuaVMs(); 23 | 24 | // Creates A New Lua VM & Pushes it Into Lua VM's Arrays, if array is full returns -1; 25 | lua_State* NewLuaVM(); 26 | -------------------------------------------------------------------------------- /src/utils/ini.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #pragma GCC diagnostic push 20 | #pragma GCC diagnostic ignored "-Wstringop-truncation" 21 | 22 | #include "ini.h" 23 | #include "../../lib/inih/ini.c" 24 | 25 | #pragma GCC diagnostic pop 26 | -------------------------------------------------------------------------------- /src/dialogs_osx.m: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2015 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | // XXX: if noc_file_dialog didn't use obj c on ios, I could directly include 20 | // this file in system.c 21 | #define NOC_FILE_DIALOG_OSX 22 | #define NOC_FILE_DIALOG_IMPLEMENTATION 23 | #include "noc_file_dialog.h" 24 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | /* 22 | ** Encode major-minor version in one byte, one nibble for each 23 | */ 24 | #define MYINT(s) (s[0]-'0') /* assume one-digit numerals */ 25 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 26 | 27 | #define LUAC_FORMAT 0 /* this is the official format */ 28 | 29 | /* load one chunk; from lundump.c */ 30 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 31 | 32 | /* dump one chunk; from ldump.c */ 33 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 34 | void* data, int strip); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /tools/create_font.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Requires Python Version 3 Interpreter 4 | 5 | # A Simple Script Which Uses FontForge to Read Font Files 6 | # Remove All The Characters Except The Given in "CHARS" Variable 7 | # And Write it To A File 8 | 9 | # Font Forge Module is not Available on Pip 10 | # the module get installed with FontForge Software itself 11 | # Font-Forge: https://fontforge.org/en-US/ 12 | 13 | import fontforge 14 | import unicodedata 15 | 16 | PATH = "./data/fonts/Montserrat-Medium.ttf" 17 | 18 | CHARS = ( 19 | u"abcdefghijklmnopqrstuvwxyz" 20 | u"ABCDEFGHIJKLMNOPQRSTUVWXYZ" 21 | u"0123456789" 22 | u" ?!\"#$%&'()*+,-./°¯[]^:<>{}@_=±" 23 | u"◀▶▲▼▴▾●©" 24 | ) 25 | 26 | font = fontforge.open(PATH) 27 | for g in font: 28 | u = font[g].unicode 29 | if u == -1: continue 30 | u = chr(u) 31 | if u not in CHARS: continue 32 | font.selection[ord(u)] = True 33 | 34 | font.selection.invert() 35 | 36 | for i in font.selection.byGlyphs: 37 | font.removeGlyph(i) 38 | 39 | font.generate("data/fonts/Montserrat-Medium.min.ttf") 40 | -------------------------------------------------------------------------------- /src/gui/about.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019-2022 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | int gui_about_popup(void *data) 22 | { 23 | gui_text("Goxel2 " GOXEL_VERSION_STR); 24 | gui_text("a cross-platform 3D voxel art editor extendable via Lua."); 25 | return gui_button("OK", 0, 0); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/gui/image_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | void gui_image_panel(void) 22 | { 23 | image_t *image = goxel.image; 24 | float (*box)[4][4] = &image->box; 25 | gui_bbox(*box); 26 | gui_action_button(ACTION_img_auto_resize, "Auto resize", 0); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/utils/color.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef COLOR_H 20 | #define COLOR_H 21 | 22 | #include 23 | 24 | void hsl_to_rgb(const uint8_t hsl[3], uint8_t rgb[3]); 25 | void rgb_to_hsl(const uint8_t rgb[3], uint8_t hsl[3]); 26 | 27 | void hsl_to_rgb_f(const float hsl[3], float rgb[3]); 28 | void rgb_to_hsl_f(const float rgb[3], float hsl[3]); 29 | 30 | #endif // COLOR_H 31 | -------------------------------------------------------------------------------- /src/utils/b64.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | /* 20 | * Function: b64_decode 21 | * Decode a base64 string 22 | * 23 | * Parameters: 24 | * src - A base 64 encoded string. 25 | * dest - Buffer that will receive the decoded value or NULL. If set to 26 | * NULL the function just returns the size of the decoded data. 27 | * 28 | * Return: 29 | * The size of the decoded data. 30 | */ 31 | int b64_decode(const char *src, void *dest); 32 | -------------------------------------------------------------------------------- /src/shape.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | /* 20 | * Define the 3d shape we can use for the mesh operations. 21 | * 22 | * TODO: need to explain how that works. 23 | */ 24 | 25 | #ifndef SHAPE_H 26 | #define SHAPE_H 27 | 28 | typedef struct shape { 29 | const char *id; 30 | float (*func)(const float p[3], const float s[3], float smoothness); 31 | } shape_t; 32 | 33 | void shapes_init(void); 34 | extern shape_t shape_sphere; 35 | extern shape_t shape_cube; 36 | extern shape_t shape_cylinder; 37 | 38 | #endif // SHAPE_H 39 | -------------------------------------------------------------------------------- /data/palettes/Ubuntu.gpl: -------------------------------------------------------------------------------- 1 | GIMP Palette 2 | Name: Ubuntu 3 | Columns: 0 4 | # 5 | 238 199 62 Orange Hilight 6 | 240 165 19 Orange 7 | 251 139 0 Orange Base 8 | 244 72 0 Orange Shadow 9 | 255 255 153 Accent Yellow Highlight 10 | 255 255 0 Yellow 11 | 253 202 1 Accent Yellow Base 12 | 152 102 1 Accent Yellow Shadow 13 | 244 72 0 Accent Orange 14 | 253 51 1 Accent Red 15 | 212 0 0 Accent Red Base 16 | 152 1 1 Accent Deep Red 17 | 253 217 155 Human Highlight 18 | 217 187 122 Human 19 | 129 102 71 Human Base 20 | 86 82 72 Environmental Shadow 21 | 170 204 238 Environmental Blue Highlight 22 | 102 153 204 Environmental Blue Medium 23 | 51 102 153 Environmental Blue Base 24 | 0 51 102 Environmental Blue Shadow 25 | 179 222 253 Accent Blue Shadow 26 | 1 151 253 Accent Blue 27 | 1 105 201 Accent Blue Base 28 | 1 51 151 Accent Blue Shadow 29 | 204 255 153 Accent Green Highlight 30 | 152 252 102 Accent Green 31 | 51 153 0 Accent Green Base 32 | 1 90 1 Accent Green Shadow 33 | 0 43 61 Ubuntu Toner 34 | 255 155 255 Accent Magenta Highlight 35 | 255 0 255 Accent Magenta 36 | 102 0 204 Accent Dark Violet 37 | 238 238 238 Grey 1 38 | 204 204 207 Grey 2 39 | 170 170 170 Grey 3 40 | 136 136 136 Grey 4 41 | 102 102 102 Grey 5 42 | 51 51 51 Grey 6 43 | 0 0 0 Black 44 | -------------------------------------------------------------------------------- /src/assets.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2015 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef ASSETS_H 20 | #define ASSETS_H 21 | 22 | // All the assets are saved in binary directly in the code, using 23 | // tool/create_assets.py. 24 | 25 | const void *assets_get(const char *url, int *size); 26 | 27 | // List all the assets in a given asset dir. 28 | // Return the number of assets. 29 | // If f returns not 0, the asset is skipped. 30 | int assets_list(const char *url, void *user, 31 | int (*f)(int i, const char *path, void *user)); 32 | 33 | #endif // ASSETS_H 34 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/utils/mustache.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | // Basic mustache templates support 20 | // Check povray.c for an example of usage. 21 | 22 | #ifndef MUSTACHE_H 23 | #define MUSTACHE_H 24 | 25 | typedef struct mustache mustache_t; 26 | mustache_t *mustache_root(void); 27 | mustache_t *mustache_add_dict(mustache_t *m, const char *key); 28 | mustache_t *mustache_add_list(mustache_t *m, const char *key); 29 | void mustache_add_str(mustache_t *m, const char *key, const char *fmt, ...); 30 | int mustache_render(const mustache_t *m, const char *templ, char *out); 31 | void mustache_free(mustache_t *m); 32 | 33 | #endif // MUSTACHE_H 34 | -------------------------------------------------------------------------------- /src/gui/quit.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2021 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | static int gui_quit_popup(void *data) 22 | { 23 | gui_text("Quit without saving your changes?"); 24 | if (gui_button("Quit", 0, 0)) { 25 | goxel.quit = true; 26 | return 1; 27 | } 28 | gui_same_line(); 29 | if (gui_button("Cancel", 0, 0)) 30 | return 2; 31 | return 0; 32 | } 33 | 34 | void gui_query_quit(void) 35 | { 36 | if (image_get_key(goxel.image) == goxel.image->saved_key) { 37 | goxel.quit = true; 38 | return; 39 | } 40 | gui_open_popup("Unsaved changes", GUI_POPUP_RESIZE, NULL, gui_quit_popup); 41 | } 42 | -------------------------------------------------------------------------------- /INTERNALS.md: -------------------------------------------------------------------------------- 1 | 2 | Small explanation of the internals of goxel code 3 | ================================================ 4 | 5 | The voxels data are stored as blocks of 16^3 voxels (`block_t`). The blocks 6 | implement a copy on write mechanism with references counting, so that it is 7 | very fast to copy blocks, the actual data (`block_data_t`) is copied only when 8 | we make change to a block. 9 | 10 | Several blocks together form a mesh (`mesh_t`), the meshes also use a copy on 11 | write mechanism to make copy basically free. 12 | 13 | An `image_t` contains several `layer_t`, which is basically a mesh plus a few 14 | attributes. The image also keeps snapshots of the layers at every changes for 15 | undo history (since we use copy on write on individual blocks, this does not 16 | require much memory). 17 | 18 | The basic function to operate on a mesh is `mesh_op`, we give it a `painter_t` 19 | pointer that defines the operation: shape, color, mode, etc. 20 | 21 | All the rendering functions are differed. The `render_xxx` calls just build a 22 | list of operations, that is executed when we call `render_render`. 23 | 24 | The assets are stored directly in the C code (`src/assets.inl`), a python 25 | script (`tools/create_assets`) takes care of generating this file. 26 | We can then use `assets_get` to retrieve them. 27 | 28 | The gui is using Ocornut imgui library, with a few custom widgets defined in 29 | `src/imgui_user.inl`. 30 | -------------------------------------------------------------------------------- /tools/create_icons.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Requires Python v3 Interpreter with pillow module installed 4 | 5 | # ************************************************************************ 6 | # Create the icon atlas image from all the icons svg files 7 | 8 | import itertools 9 | import PIL.Image 10 | from shutil import copyfile 11 | import os 12 | import subprocess 13 | import re 14 | 15 | # Use inkscape to convert the svg into one big png file. 16 | subprocess.check_output([ 17 | 'inkscape', './svg/icons.svg', '--export-area-page', 18 | '--export-dpi=192', '--export-png=/tmp/icons.png']) 19 | 20 | src_img = PIL.Image.open('/tmp/icons.png') 21 | ret_img = PIL.Image.new('RGBA', (512, 512)) 22 | 23 | for x, y in itertools.product(range(8), range(8)): 24 | img = src_img.crop((x * 46 + 2, y * 46 + 2, x * 46 + 46, y * 46 + 46)) 25 | # Make the image white in the special range. 26 | if y >= 2 and y < 5: 27 | tmp = PIL.Image.new('RGBA', (44, 44), (255, 255, 255, 255)) 28 | tmp.putalpha(img.split()[3]) 29 | img = tmp 30 | ret_img.paste(img, (64 * x + 10, 64 * y + 10)) 31 | 32 | ret_img.save('data/images/icons.png') 33 | 34 | # Also create the application icons (in data/icons) 35 | if not os.path.exists('data/icons'): os.makedirs('data/icons') 36 | base = PIL.Image.open('icon.png').convert('RGBA') 37 | 38 | for size in [16, 24, 32, 48, 64, 128, 256]: 39 | img = base.resize((size, size), PIL.Image.BILINEAR) 40 | img.save('data/icons/icon%d.png' % size) 41 | -------------------------------------------------------------------------------- /src/glew-mx.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2018 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | /* This file is only here to be included by cycles ! */ 20 | 21 | #define GL_GLEXT_PROTOTYPES 22 | #ifdef WIN32 23 | # include 24 | # include "GL/glew.h" 25 | #endif 26 | #ifdef __APPLE__ 27 | # include "TargetConditionals.h" 28 | # if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR 29 | # define GLES2 1 30 | # include 31 | # include 32 | # else 33 | # include 34 | # endif 35 | #else 36 | # ifdef GLES2 37 | # include 38 | # include 39 | # else 40 | # include 41 | # endif 42 | #endif 43 | 44 | #ifndef GLEW_VERSION_1_5 45 | # define GLEW_VERSION_1_5 0 46 | #endif 47 | -------------------------------------------------------------------------------- /data/progs/city.goxcf: -------------------------------------------------------------------------------- 1 | shape main { 2 | [seed 4] 3 | city[] 4 | } 5 | 6 | shape ground { 7 | [s 128 128 1 8 | light -0.6 sat 0.2 hue 50] 9 | cube[] 10 | loop 16 [] { 11 | cube[x 0+-0.4 0+-0.4 12 | s 0.2+-0.1 0.2+-0.1 3+-1 13 | light -0.3+-0.2] 14 | } 15 | } 16 | 17 | shape city { 18 | ground[] 19 | loop 128 [wait 1] { 20 | building[x 0+-58 0+-58 s 2+-0.5 21 | sat 0.2+-0.1 hue 0+-180] 22 | } 23 | } 24 | 25 | shape building 26 | // Tall building 27 | rule 1 { 28 | [s 3] 29 | $n = int(10+-5) 30 | loop $n [z 1 wait 1] { 31 | $s = 2+-0.2 32 | floor[s $s $s 1 z 0.5] 33 | } 34 | [z $n - 0.5] 35 | loop 1+-2 [] { 36 | antenna[] 37 | } 38 | } 39 | // Low building 40 | rule 1 { 41 | [s 8+-4 8+-4 4+-2 z 0.5] 42 | cube[light -0.3] 43 | windows(8)[] 44 | loop 2+-1 [] {antenna[]} 45 | } 46 | // Tree 47 | rule 10 { 48 | [z 0.5 sn 1 z 0.5] 49 | [sat 1 0.5 light 1 0.2 hue 1 20] 50 | cube[z 0.5 sz 5] 51 | loop 2 [] { 52 | sphere[z 4 s 4+-1 53 | x 0+-0.1 0+-0.1 54 | hue 100+-40] 55 | } 56 | } 57 | 58 | shape windows($n) { 59 | loop $n [rz 90] { 60 | cube[x 0.5 0+-0.4 sn s 1/3 x -0.5 61 | light 1 1 light 0+-0.2] 62 | } 63 | } 64 | 65 | shape floor { 66 | cube[light -0.5+-0.1] 67 | windows(8)[] 68 | } 69 | 70 | shape antenna { 71 | [z 0.5 x 0+-0.4 0+-0.4 72 | sn 1 sz 2+-1 z 0.5 73 | light -0.5] 74 | cube[] 75 | } -------------------------------------------------------------------------------- /src/material.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef MATERIAL_H 20 | #define MATERIAL_H 21 | 22 | #include 23 | 24 | typedef struct material material_t; 25 | struct material { 26 | char name[128]; // 127 chars max. 27 | float metallic; 28 | float roughness; 29 | float base_color[4]; 30 | float emission[3]; 31 | material_t *next, *prev; // List of materials in an image. 32 | }; 33 | 34 | #define MATERIAL_DEFAULT (material_t){ \ 35 | .name = {}, \ 36 | .metallic = 0.2, \ 37 | .roughness = 0.5, \ 38 | .base_color = {1, 1, 1, 1}} 39 | 40 | material_t *material_new(const char *name); 41 | void material_delete(material_t *m); 42 | material_t *material_copy(const material_t *mat); 43 | uint32_t material_get_hash(const material_t *m); 44 | 45 | #endif // MATERIAL_H 46 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | /* 20 | * This file gets included before any compiled file. So we can use it 21 | * to set configuration macros that affect external libraries. 22 | */ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #ifndef _GNU_SOURCE 29 | # define _GNU_SOURCE 30 | #endif 31 | 32 | #pragma GCC diagnostic ignored "-Wpragmas" 33 | 34 | // Define the LOG macros, so that they get available in the utils files. 35 | #include "log.h" 36 | 37 | // Disable yocto with older version of gcc, since it doesn't compile then. 38 | #ifndef YOCTO 39 | # if !defined(__clang__) && __GNUC__ < 6 40 | # define YOCTO 0 41 | # endif 42 | #endif 43 | 44 | // Disable OpenGL deprecation warnings on Mac. 45 | #define GL_SILENCE_DEPRECATION 1 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* Increments 'L->top', checking for stack overflows */ 16 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 17 | "stack overflow");} 18 | 19 | 20 | /* 21 | ** If a call returns too many multiple returns, the callee may not have 22 | ** stack space to accommodate all results. In this case, this macro 23 | ** increases its stack space ('L->ci->top'). 24 | */ 25 | #define adjustresults(L,nres) \ 26 | { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 27 | 28 | 29 | /* Ensure the stack has at least 'n' elements */ 30 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 31 | "not enough elements in the stack") 32 | 33 | 34 | /* 35 | ** To reduce the overhead of returning from C functions, the presence of 36 | ** to-be-closed variables in these functions is coded in the CallInfo's 37 | ** field 'nresults', in a way that functions with no to-be-closed variables 38 | ** with zero, one, or "all" wanted results have no overhead. Functions 39 | ** with other number of wanted results, as well as functions with 40 | ** variables to be closed, have an extra check. 41 | */ 42 | 43 | #define hastocloseCfunc(n) ((n) < LUA_MULTRET) 44 | 45 | /* Map [-1, inf) (range of 'nresults') into (-inf, -2] */ 46 | #define codeNresults(n) (-(n) - 3) 47 | #define decodeNresults(n) (-(n) - 3) 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/gui/topbar.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | #ifndef GUI_CUSTOM_TOPBAR 22 | 23 | static int gui_mode_select(void) 24 | { 25 | 26 | gui_choice_begin("Mode", &goxel.painter.mode, false); 27 | gui_choice("Add", MODE_OVER, ICON_MODE_ADD); 28 | gui_choice("Sub", MODE_SUB, ICON_MODE_SUB); 29 | gui_choice("Paint", MODE_PAINT, ICON_MODE_PAINT); 30 | gui_choice_end(); 31 | return 0; 32 | } 33 | 34 | void gui_top_bar(void) 35 | { 36 | gui_action_button(ACTION_undo, NULL, 0); 37 | gui_same_line(); 38 | gui_action_button(ACTION_redo, NULL, 0); 39 | gui_same_line(); 40 | gui_action_button(ACTION_layer_clear, NULL, 0); 41 | gui_same_line(); 42 | gui_mode_select(); 43 | gui_same_line(); 44 | gui_color("##color", goxel.painter.color); 45 | } 46 | 47 | #endif // GUI_CUSTOM_TOPBAR 48 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/gui/debug_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | void gui_debug_panel(void) 22 | { 23 | mesh_global_stats_t stats; 24 | 25 | gui_text("FPS: %d", (int)round(goxel.fps)); 26 | mesh_get_global_stats(&stats); 27 | gui_text("Nb meshes: %d", stats.nb_meshes); 28 | gui_text("Nb blocks: %d", stats.nb_blocks); 29 | gui_text("Mem: %dM", (int)(stats.mem / (1 << 20))); 30 | 31 | if (!DEFINED(GLES2)) { 32 | gui_checkbox_flag("Show wireframe", &goxel.view_effects, 33 | EFFECT_WIREFRAME, NULL); 34 | } 35 | 36 | if (gui_button("Clear undo history", -1, 0)) { 37 | image_history_resize(goxel.image, 0); 38 | } 39 | if (gui_button("On low memory", -1, 0)) { 40 | goxel_on_low_memory(); 41 | } 42 | if (gui_button("Test release", -1, 0)) { 43 | goxel.request_test_graphic_release = true; 44 | } 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/gui/light_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | void gui_light_panel(void) 22 | { 23 | float v; 24 | 25 | gui_group_begin(NULL); 26 | gui_angle("Pitch", &goxel.rend.light.pitch, -90, +90); 27 | gui_angle("Yaw", &goxel.rend.light.yaw, 0, 360); 28 | gui_input_float("Intensity", &goxel.rend.light.intensity, 29 | 0.1, 0, 10, NULL); 30 | gui_group_end(); 31 | gui_checkbox("Fixed", &goxel.rend.light.fixed, NULL); 32 | 33 | if (!DEFINED(GOXEL_NO_SHADOW)) { 34 | v = goxel.rend.settings.shadow; 35 | if (gui_input_float("Shadow", &v, 0.1, 0, 0, NULL)) { 36 | goxel.rend.settings.shadow = clamp(v, 0, 1); 37 | } 38 | } 39 | 40 | v = goxel.rend.settings.ambient; 41 | if (gui_input_float("Ambient", &v, 0.1, 0, 1, NULL)) { 42 | v = clamp(v, 0, 1); 43 | goxel.rend.settings.ambient = v; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/material.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "material.h" 20 | #include "xxhash.h" 21 | 22 | #include 23 | #include 24 | 25 | 26 | material_t *material_new(const char *name) 27 | { 28 | material_t *m = calloc(1, sizeof(*m)); 29 | *m = MATERIAL_DEFAULT; 30 | if (name) snprintf(m->name, sizeof(m->name), "%s", name); 31 | return m; 32 | } 33 | 34 | void material_delete(material_t *m) 35 | { 36 | free(m); 37 | } 38 | 39 | material_t *material_copy(const material_t *other) 40 | { 41 | material_t *m = malloc(sizeof(*m)); 42 | *m = *other; 43 | m->next = m->prev = NULL; 44 | return m; 45 | } 46 | 47 | uint32_t material_get_hash(const material_t *m) 48 | { 49 | uint32_t ret = 0; 50 | ret = XXH32(&m->metallic, sizeof(m->metallic), ret); 51 | ret = XXH32(&m->roughness, sizeof(m->roughness), ret); 52 | ret = XXH32(&m->base_color, sizeof(m->base_color), ret); 53 | return ret; 54 | } 55 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lopnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopnames.h $ 3 | ** Opcode names 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #if !defined(lopnames_h) 8 | #define lopnames_h 9 | 10 | #include 11 | 12 | 13 | /* ORDER OP */ 14 | 15 | static const char *const opnames[] = { 16 | "MOVE", 17 | "LOADI", 18 | "LOADF", 19 | "LOADK", 20 | "LOADKX", 21 | "LOADFALSE", 22 | "LFALSESKIP", 23 | "LOADTRUE", 24 | "LOADNIL", 25 | "GETUPVAL", 26 | "SETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "GETI", 30 | "GETFIELD", 31 | "SETTABUP", 32 | "SETTABLE", 33 | "SETI", 34 | "SETFIELD", 35 | "NEWTABLE", 36 | "SELF", 37 | "ADDI", 38 | "ADDK", 39 | "SUBK", 40 | "MULK", 41 | "MODK", 42 | "POWK", 43 | "DIVK", 44 | "IDIVK", 45 | "BANDK", 46 | "BORK", 47 | "BXORK", 48 | "SHRI", 49 | "SHLI", 50 | "ADD", 51 | "SUB", 52 | "MUL", 53 | "MOD", 54 | "POW", 55 | "DIV", 56 | "IDIV", 57 | "BAND", 58 | "BOR", 59 | "BXOR", 60 | "SHL", 61 | "SHR", 62 | "MMBIN", 63 | "MMBINI", 64 | "MMBINK", 65 | "UNM", 66 | "BNOT", 67 | "NOT", 68 | "LEN", 69 | "CONCAT", 70 | "CLOSE", 71 | "TBC", 72 | "JMP", 73 | "EQ", 74 | "LT", 75 | "LE", 76 | "EQK", 77 | "EQI", 78 | "LTI", 79 | "LEI", 80 | "GTI", 81 | "GEI", 82 | "TEST", 83 | "TESTSET", 84 | "CALL", 85 | "TAILCALL", 86 | "RETURN", 87 | "RETURN0", 88 | "RETURN1", 89 | "FORLOOP", 90 | "FORPREP", 91 | "TFORPREP", 92 | "TFORCALL", 93 | "TFORLOOP", 94 | "SETLIST", 95 | "CLOSURE", 96 | "VARARG", 97 | "VARARGPREP", 98 | "EXTRAARG", 99 | NULL 100 | }; 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/utils/json.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef JSON_H 20 | #define JSON_H 21 | 22 | #include "../../lib/json/json.h" 23 | #include "../../lib/json/json-builder.h" 24 | 25 | #include 26 | 27 | // Some extra helper functions. 28 | 29 | json_value *json_object_push_int(json_value *obj, const json_char *name, 30 | json_int_t v); 31 | json_value *json_object_push_string(json_value *obj, const json_char *name, 32 | const json_char *v); 33 | json_value *json_object_push_bool(json_value *obj, const json_char *name, 34 | bool v); 35 | json_value *json_object_push_float(json_value *obj, const json_char *name, 36 | double v); 37 | 38 | json_value *json_data_new(const void *data, uint32_t len, const char *mime); 39 | 40 | json_value *json_int_array_new(const int *v, int nb); 41 | json_value *json_float_array_new(const float *v, int nb); 42 | 43 | int json_index(json_value *v); 44 | 45 | #endif // JSON_H 46 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* 16 | ** Memory-allocation error message must be preallocated (it cannot 17 | ** be created after memory is exhausted) 18 | */ 19 | #define MEMERRMSG "not enough memory" 20 | 21 | 22 | /* 23 | ** Size of a TString: Size of the header plus space for the string 24 | ** itself (including final '\0'). 25 | */ 26 | #define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char)) 27 | 28 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 29 | (sizeof(s)/sizeof(char))-1)) 30 | 31 | 32 | /* 33 | ** test whether a string is a reserved word 34 | */ 35 | #define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0) 36 | 37 | 38 | /* 39 | ** equality for short strings, which are always internalized 40 | */ 41 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b)) 42 | 43 | 44 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 45 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 46 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 47 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 48 | LUAI_FUNC void luaS_clearcache (global_State *g); 49 | LUAI_FUNC void luaS_init (lua_State *L); 50 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 51 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue); 52 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 53 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 54 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | the changelog is updated after every release. 3 | 4 | --- 5 | 6 | - [Upcoming Release (v1.0?)] 7 | - Fix Console From Popping-Up With Application 8 | - Add Support For Storing Layers, Materials, Lights, Cameras, Etc. 9 | - Model3d (.m3d) is Now Main Import/Export Format, (Gox can still be used) 10 | - Add 2 New File Format Support by [@bztsrc](https://github.com/bztsrc) 11 | 1. Add Support For Minecraft Schematics (.schematic, .schem, .nbt Files) 12 | 2. Add Support For Minetest's schematic files (.mts) 13 | - Add 3 New Palettes, MineCraft, MineTest & MineClone2 14 | 15 | 16 | - [v0.14.2](https://github.com/pegvin/goxel2/releases/tag/v0.14.2) 17 | - Add i686 (x32) Builds For Windows & Linux 18 | - Add Better Support For Ace Of Spades (.vxl) Format & Similar Games (by [xtreme8000](https://github.com/xtreme8000)) 19 | - Fix UI Glitches 20 | 21 | - [v0.13.2](https://github.com/pegvin/goxel2/releases/tag/v0.13.2) 22 | - Move To Latest ImGui Version - v1.88 23 | - Switch To [Montserrat Font](https://fonts.google.com/specimen/Montserrat) - Medium Version For UI 24 | - Tweak Default Font Size To 15px Times The Scale 25 | 26 | - [v0.12.1](https://github.com/pegvin/goxel2/releases/tag/v0.12.1) 27 | - New Dark Theme 28 | - Performance Fixes (Reduce CPU Usage) 29 | 30 | - [v0.11.1](https://github.com/pegvin/goxel2/releases/tag/v0.11.1) 31 | - Add Hide/Show All Layer Button (Feature Request [#1](https://github.com/pegvin/goxel2/issues/1)) 32 | - Remove Android, IOS & Web Support 33 | - Add Arch Linux Packaging (Available in AUR - [goxel2-git](https://aur.archlinux.org/packages/goxel2-git)) 34 | - Remove Snap Packaging 35 | 36 | - [v0.10.8](https://github.com/pegvin/goxel2/releases/tag/v0.10.8) 37 | - Same as [Goxel's v0.10.8 Release](https://github.com/guillaumechereau/goxel/releases/tag/v0.10.8) 38 | 39 | --- 40 | 41 | # Thanks 42 | -------------------------------------------------------------------------------- /src/gui/palette_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | #ifndef GUI_PALETTE_COLUMNS_NB 22 | # define GUI_PALETTE_COLUMNS_NB 8 23 | #endif 24 | 25 | void gui_palette_panel(void) 26 | { 27 | palette_t *p; 28 | int i, current, nb = 0, nb_col = GUI_PALETTE_COLUMNS_NB; 29 | const char **names; 30 | char id[128]; 31 | 32 | DL_COUNT(goxel.palettes, p, nb); 33 | names = (const char**)calloc(nb, sizeof(*names)); 34 | 35 | i = 0; 36 | DL_FOREACH(goxel.palettes, p) { 37 | if (p == goxel.palette) current = i; 38 | names[i++] = p->name; 39 | } 40 | if (gui_combo("##palettes", ¤t, names, nb)) { 41 | goxel.palette = goxel.palettes; 42 | for (i = 0; i < current; i++) goxel.palette = goxel.palette->next; 43 | } 44 | free(names); 45 | 46 | p = goxel.palette; 47 | 48 | if (p) { 49 | for (i = 0; i < p->size; i++) { 50 | snprintf(id, sizeof(id), "%d", i); 51 | gui_push_id(id); 52 | gui_palette_entry(p->entries[i].color, goxel.painter.color); 53 | if ((i + 1) % nb_col && i != p->size - 1) gui_same_line(); 54 | gui_pop_id(); 55 | } 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/shader_cache.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef SHADER_CACHE_H 20 | #define SHADER_CACHE_H 21 | 22 | #include "goxel.h" 23 | 24 | typedef struct { 25 | const char *name; 26 | bool set; 27 | } shader_define_t; 28 | 29 | /* 30 | * Function: shader_get 31 | * Retreive a cached shader 32 | * 33 | * Probably need to change this api soon. 34 | * 35 | * Properties: 36 | * name - Name of one of the shaders in the resources. 37 | * defines - Array of , terminated by an empty one. 38 | * Can be NULL. 39 | * attr_names - NULL terminated list of attribute names that will be binded. 40 | * on_created - If set, called the first time the shader has been created. 41 | */ 42 | gl_shader_t *shader_get(const char *name, const shader_define_t *defines, 43 | const char **attr_names, 44 | void (*on_created)(gl_shader_t *s)); 45 | 46 | /* 47 | * Function: shaders_release_all 48 | * Remove all the shaders from the cache. 49 | */ 50 | void shaders_release_all(void); 51 | 52 | #endif // SHADER_CACHE 53 | -------------------------------------------------------------------------------- /src/gesture3d.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2020 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef GESTURE3D_H 20 | #define GESTURE3D_H 21 | 22 | typedef struct gesture3d gesture3d_t; 23 | 24 | // Represent a 3d cursor. 25 | // The program keeps track of two cursors, that are then used by the tools. 26 | enum { 27 | // The state flags of the cursor. 28 | CURSOR_PRESSED = 1 << 0, 29 | CURSOR_SHIFT = 1 << 1, 30 | CURSOR_CTRL = 1 << 2, 31 | 32 | CURSOR_OUT = 1 << 3, // Outside of sensing area. 33 | }; 34 | 35 | typedef struct cursor { 36 | float pos[3]; 37 | float normal[3]; 38 | int snap_mask; 39 | int snaped; 40 | int flags; // Union of CURSOR_* values. 41 | float snap_offset; // XXX: fix this. 42 | } cursor_t; 43 | 44 | // #### 3d gestures 45 | struct gesture3d 46 | { 47 | int type; 48 | int state; 49 | int buttons; // CURSOR_SHIFT | CURSOR_CTRL 50 | cursor_t *cursor; 51 | int (*callback)(gesture3d_t *gest, void *user); 52 | }; 53 | 54 | int gesture3d(gesture3d_t *gest, cursor_t *curs, void *user); 55 | 56 | #endif // GESTURE3D_H 57 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {LUA_GNAME, luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | {NULL, NULL} 54 | }; 55 | 56 | 57 | LUALIB_API void luaL_openlibs (lua_State *L) { 58 | const luaL_Reg *lib; 59 | /* "require" functions from 'loadedlibs' and set results to global table */ 60 | for (lib = loadedlibs; lib->func; lib++) { 61 | luaL_requiref(L, lib->name, lib->func, 1); 62 | lua_pop(L, 1); /* remove lib */ 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/utils/img.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | /* 20 | * File: img.h 21 | * A few 2d image manipulation helper functions. 22 | */ 23 | 24 | #ifndef IMG_H 25 | #define IMG_H 26 | 27 | #include 28 | 29 | /* 30 | * Function: img_read 31 | * Read an image from a file. 32 | */ 33 | uint8_t *img_read(const char *path, int *width, int *height, int *bpp); 34 | 35 | /* 36 | * Function: img_read_from_mem 37 | * Read an image from memory. 38 | */ 39 | uint8_t *img_read_from_mem(const char *data, int size, 40 | int *w, int *h, int *bpp); 41 | 42 | /* 43 | * Function: img_write 44 | * Write an image to a file. 45 | */ 46 | void img_write(const uint8_t *img, int w, int h, int bpp, const char *path); 47 | 48 | /* 49 | * Function: img_write_to_mem 50 | * Write an image to memory. 51 | */ 52 | uint8_t *img_write_to_mem(const uint8_t *img, int w, int h, int bpp, 53 | int *size); 54 | 55 | /* 56 | * Function: img_downsample 57 | * Downsample an image by half, using interpolation. 58 | */ 59 | void img_downsample(const uint8_t *img, int w, int h, int bpp, 60 | uint8_t *out); 61 | 62 | #endif // IMG_H 63 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \ 15 | cast_int(sizeof(TValue)) * (n)) 16 | 17 | #define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \ 18 | cast_int(sizeof(TValue *)) * (n)) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | #define upisopen(up) ((up)->v != &(up)->u.value) 33 | 34 | 35 | #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v)) 36 | 37 | 38 | /* 39 | ** maximum number of misses before giving up the cache of closures 40 | ** in prototypes 41 | */ 42 | #define MAXMISS 10 43 | 44 | 45 | 46 | /* special status to close upvalues preserving the top of the stack */ 47 | #define CLOSEKTOP (-1) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); 57 | LUAI_FUNC void luaF_close (lua_State *L, StkId level, int status, int yy); 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); 59 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 60 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 61 | int pc); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/palette.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | // XXX: probably need to redo the code here. 20 | 21 | #include 22 | #include 23 | 24 | typedef struct { 25 | uint8_t color[4]; 26 | char name[512]; 27 | } palette_entry_t; 28 | 29 | typedef struct palette palette_t; 30 | struct palette { 31 | palette_t *next, *prev; // For the global list of palettes. 32 | char name[128]; 33 | int columns; 34 | int size; 35 | int allocated; 36 | palette_entry_t *entries; 37 | }; 38 | 39 | // Load all the available palettes into a list. 40 | void palette_load_all(palette_t **list); 41 | 42 | /* 43 | * Function: palette_search 44 | * Search a given color in a palette 45 | * 46 | * Parameters: 47 | * palette - A palette. 48 | * col - The color we are looking for. 49 | * exact - If set to true, return -1 if no color is found, else 50 | * return the closest color. 51 | * 52 | * Return: 53 | * The index of the color in the palette. 54 | */ 55 | int palette_search(const palette_t *palette, const uint8_t col[4], 56 | bool exact); 57 | 58 | void palette_insert(palette_t *p, const uint8_t col[4], const char *name); 59 | -------------------------------------------------------------------------------- /src/log.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef LOG_H 20 | #define LOG_H 21 | 22 | // #### Logging macros ######### 23 | 24 | enum { 25 | GOX_LOG_VERBOSE = 2, 26 | GOX_LOG_DEBUG = 3, 27 | GOX_LOG_INFO = 4, 28 | GOX_LOG_WARN = 5, 29 | GOX_LOG_ERROR = 6, 30 | }; 31 | 32 | #ifndef DEBUG 33 | # if !defined(NDEBUG) 34 | # define DEBUG 1 35 | # else 36 | # define DEBUG 0 37 | # endif 38 | #endif 39 | 40 | #ifndef LOG_LEVEL 41 | # if DEBUG 42 | # define LOG_LEVEL GOX_LOG_DEBUG 43 | # else 44 | # define LOG_LEVEL GOX_LOG_INFO 45 | # endif 46 | #endif 47 | 48 | #define LOG(level, msg, ...) do { \ 49 | if (level >= LOG_LEVEL) \ 50 | dolog(level, msg, __func__, __FILE__, __LINE__, ##__VA_ARGS__); \ 51 | } while(0) 52 | 53 | #define LOG_V(msg, ...) LOG(GOX_LOG_VERBOSE, msg, ##__VA_ARGS__) 54 | #define LOG_D(msg, ...) LOG(GOX_LOG_DEBUG, msg, ##__VA_ARGS__) 55 | #define LOG_I(msg, ...) LOG(GOX_LOG_INFO, msg, ##__VA_ARGS__) 56 | #define LOG_W(msg, ...) LOG(GOX_LOG_WARN, msg, ##__VA_ARGS__) 57 | #define LOG_E(msg, ...) LOG(GOX_LOG_ERROR, msg, ##__VA_ARGS__) 58 | 59 | void dolog(int level, const char *msg, 60 | const char *func, const char *file, int line, ...); 61 | 62 | #endif // LOG_H 63 | -------------------------------------------------------------------------------- /src/layer.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef LAYER_H 20 | #define LAYER_H 21 | 22 | #include "material.h" 23 | #include "mesh.h" 24 | #include "shape.h" 25 | #include "utils/texture.h" 26 | 27 | typedef struct layer layer_t; 28 | 29 | struct layer { 30 | layer_t *next, *prev; 31 | mesh_t *mesh; 32 | const material_t *material; 33 | int id; // Uniq id in the image (for clones). 34 | bool visible; 35 | char name[256]; // 256 chars max. 36 | float box[4][4]; // Bounding box. 37 | float mat[4][4]; 38 | // For 2d image layers. 39 | texture_t *image; 40 | // For clone layers: 41 | int base_id; 42 | uint64_t base_mesh_key; 43 | // For shape layers. 44 | const shape_t *shape; 45 | uint32_t shape_key; 46 | uint8_t color[4]; 47 | }; 48 | 49 | layer_t *layer_new(const char *name); 50 | void layer_delete(layer_t *layer); 51 | uint32_t layer_get_key(const layer_t *layer); 52 | layer_t *layer_copy(layer_t *other); 53 | 54 | /* 55 | * Function: layer_get_bounding_box 56 | * Return the layer box if set, otherwise the bounding box of the layer 57 | * mesh. 58 | */ 59 | void layer_get_bounding_box(const layer_t *layer, float box[4][4]); 60 | 61 | #endif // LAYER_H 62 | -------------------------------------------------------------------------------- /src/file_format.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2020 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef FILE_FORMAT_H 20 | #define FILE_FORMAT_H 21 | 22 | #include "image.h" 23 | 24 | typedef struct file_format file_format_t; 25 | struct file_format 26 | { 27 | file_format_t *next, *prev; // For the global list of formats. 28 | const char *name; 29 | const char *ext; 30 | void (*export_gui)(void); 31 | int (*export_func)(const image_t *img, const char *path); 32 | int (*import_func)(image_t *img, const char *path); 33 | }; 34 | 35 | void file_format_register(file_format_t *format); 36 | 37 | const file_format_t *file_format_for_path(const char *path, const char *name, 38 | const char *mode); 39 | 40 | void file_format_iter(const char *mode, void *user, 41 | void (*f)(void *user, const file_format_t *f)); 42 | 43 | // The global list of registered file formats. 44 | extern file_format_t *file_formats; 45 | 46 | #define FILE_FORMAT_REGISTER(id_, ...) \ 47 | static file_format_t GOX_format_##id_ = {__VA_ARGS__}; \ 48 | __attribute__((constructor)) \ 49 | static void GOX_register_format_##id_(void) { \ 50 | file_format_register(&GOX_format_##id_); \ 51 | } 52 | 53 | #endif // FILE_FORMAT_H 54 | -------------------------------------------------------------------------------- /src/yocto.cpp: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2018 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | /* 20 | * This file is just there to compile all the needed yocto-gl sources, so 21 | * that we keeps a clean build system. 22 | */ 23 | 24 | #ifndef YOCTO 25 | # define YOCTO 1 26 | #endif 27 | 28 | #if YOCTO 29 | 30 | #pragma GCC diagnostic push 31 | #pragma GCC diagnostic ignored "-Wunused-function" 32 | #pragma GCC diagnostic ignored "-Wcomma" 33 | #pragma GCC diagnostic ignored "-Wunused-but-set-variable" 34 | #ifndef __clang__ 35 | #pragma GCC diagnostic ignored "-Wsign-compare" 36 | #pragma GCC diagnostic ignored "-Wunused-variable" 37 | #pragma GCC diagnostic ignored "-Wparentheses" 38 | #pragma GCC diagnostic ignored "-Wreturn-type" 39 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 40 | #endif 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | #define YOCTO_EMBREE 0 47 | #define STB_IMAGE_STATIC 48 | #define STB_IMAGE_WRITE_STATIC 49 | 50 | // Fix compilation on Windows. 51 | #ifdef NOMINMAX 52 | #undef NOMINMAX 53 | #endif 54 | 55 | 56 | #include "../lib/yocto/yocto_bvh.cpp" 57 | #include "../lib/yocto/yocto_image.cpp" 58 | #include "../lib/yocto/yocto_scene.cpp" 59 | #include "../lib/yocto/yocto_shape.cpp" 60 | #include "../lib/yocto/yocto_trace.cpp" 61 | 62 | #pragma GCC diagnostic pop 63 | 64 | #endif // YOCTO 65 | -------------------------------------------------------------------------------- /src/tools/color_picker.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2017 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | 22 | typedef struct { 23 | tool_t tool; 24 | } tool_pick_color_t; 25 | 26 | 27 | int tool_color_picker_iter(tool_t *tool, const painter_t *painter, 28 | const float viewport[4]) 29 | { 30 | uint8_t color[4]; 31 | const mesh_t *mesh = goxel_get_layers_mesh(goxel.image); 32 | cursor_t *curs = &goxel.cursor; 33 | int pi[3] = {floor(curs->pos[0]), 34 | floor(curs->pos[1]), 35 | floor(curs->pos[2])}; 36 | curs->snap_mask = SNAP_MESH; 37 | curs->snap_offset = -0.5; 38 | 39 | goxel_set_help_text("Click on a voxel to pick the color"); 40 | if (!curs->snaped) return 0; 41 | mesh_get_at(mesh, NULL, pi, color); 42 | color[3] = 255; 43 | goxel_set_help_text("%d %d %d", color[0], color[1], color[2]); 44 | if (curs->flags & CURSOR_PRESSED) vec4_copy(color, goxel.painter.color); 45 | return 0; 46 | } 47 | 48 | static int gui(tool_t *tool) 49 | { 50 | tool_gui_color(); 51 | return 0; 52 | } 53 | 54 | TOOL_REGISTER(TOOL_PICK_COLOR, pick_color, tool_pick_color_t, 55 | .name = "Color Picker", 56 | .iter_fn = tool_color_picker_iter, 57 | .gui_fn = gui, 58 | .default_shortcut = "C", 59 | ) 60 | -------------------------------------------------------------------------------- /src/gui/lospec.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2022 Aditya Mishra 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | /* 20 | Support For Importing Palettes From LoSpec (lospec.com) 21 | */ 22 | 23 | #include "goxel.h" 24 | #include "downloader.h" 25 | #include 26 | 27 | // https://lospec.com/palette-list/.gpl - Length 36 28 | #define PaletteURLSize 40 // Length of the URL without palette Name: 36, using 40 for no reason. 29 | #define PaletteNameSize 2048 // Length of the Name of the palette, too big just to be "safe"? 30 | 31 | char PaletteName[PaletteNameSize] = {0}; 32 | char PaletteURL[PaletteURLSize + PaletteNameSize] = {0}; 33 | 34 | int gui_lospec_importer_popup(void *data) 35 | { 36 | gui_text("Enter a LoSpec Palette Name"); 37 | gui_input_text("", PaletteName, 2048); 38 | gui_text("program might freeze, it's not a crash..."); 39 | 40 | if (gui_button("Ok", 0, 0)) { 41 | char *filePath; 42 | if (sys_get_user_dir()) { 43 | asprintf(&filePath, "%s/lospec/%s.gpl", sys_get_user_dir(), PaletteName); 44 | sys_make_dir(filePath); // Ensure the directory exists 45 | sprintf(PaletteURL, "https://lospec.com/palette-list/%s.gpl", PaletteName); 46 | printf("%s\n%s\n%s\n", PaletteURL, PaletteName, filePath); 47 | DownloadFileFrom(PaletteURL, filePath); 48 | free(filePath); 49 | palette_load_all(&goxel.palettes); 50 | } 51 | return 1; 52 | } 53 | 54 | gui_same_line(); 55 | return gui_button("Cancel", 0, 0); 56 | } 57 | -------------------------------------------------------------------------------- /src/pathtracer.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "utils/texture.h" 20 | 21 | enum { 22 | PT_WORLD_NONE = 0, 23 | PT_WORLD_UNIFORM, 24 | PT_WORLD_SKY, 25 | }; 26 | 27 | enum { 28 | PT_FLOOR_NONE = 0, 29 | PT_FLOOR_PLANE, 30 | }; 31 | 32 | enum { 33 | PT_STOPPED = 0, 34 | PT_RUNNING, 35 | PT_FINISHED, 36 | }; 37 | 38 | typedef struct pathtracer_internal pathtracer_internal_t; 39 | 40 | // Hold info about the cycles rendering task. 41 | typedef struct { 42 | int status; 43 | uint8_t *buf; // RGBA buffer. 44 | int w, h; // Size of the buffer. 45 | float progress; 46 | bool force_restart; 47 | texture_t *texture; 48 | pathtracer_internal_t *p; 49 | int num_samples; 50 | struct { 51 | int type; 52 | float energy; 53 | uint8_t color[4]; 54 | } world; 55 | struct { 56 | int type; 57 | uint8_t color[4]; 58 | int size[2]; 59 | material_t *material; 60 | } floor; 61 | } pathtracer_t; 62 | 63 | /* 64 | * Function: pathtracer_iter 65 | * Iter the rendering process of the current mesh. 66 | * 67 | * Parameters: 68 | * pt - A pathtracer instance. 69 | * viewport - The full view viewport. 70 | */ 71 | void pathtracer_iter(pathtracer_t *pt, const float viewport[4]); 72 | 73 | /* 74 | * Stop the pathtracer thread if it is running. 75 | */ 76 | void pathtracer_stop(pathtracer_t *pt); 77 | -------------------------------------------------------------------------------- /src/formats/png_slices.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2017 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | #include "file_format.h" 21 | 22 | static int export_as_png_slices(const image_t *image, const char *path) 23 | { 24 | float box[4][4]; 25 | const mesh_t *mesh; 26 | int x, y, z, w, h, d, pos[3], start_pos[3]; 27 | uint8_t c[4]; 28 | uint8_t *img; 29 | mesh_iterator_t iter = {0}; 30 | 31 | mesh = goxel_get_layers_mesh(image); 32 | mat4_copy(image->box, box); 33 | if (box_is_null(box)) mesh_get_box(mesh, true, box); 34 | w = box[0][0] * 2; 35 | h = box[1][1] * 2; 36 | d = box[2][2] * 2; 37 | start_pos[0] = box[3][0] - box[0][0]; 38 | start_pos[1] = box[3][1] - box[1][1]; 39 | start_pos[2] = box[3][2] - box[2][2]; 40 | img = calloc(w * h * d, 4); 41 | for (z = 0; z < d; z++) 42 | for (y = 0; y < h; y++) 43 | for (x = 0; x < w; x++) { 44 | pos[0] = x + start_pos[0]; 45 | pos[1] = y + start_pos[1]; 46 | pos[2] = z + start_pos[2]; 47 | mesh_get_at(mesh, &iter, pos, c); 48 | img[(y * w * d + z * w + x) * 4 + 0] = c[0]; 49 | img[(y * w * d + z * w + x) * 4 + 1] = c[1]; 50 | img[(y * w * d + z * w + x) * 4 + 2] = c[2]; 51 | img[(y * w * d + z * w + x) * 4 + 3] = c[3]; 52 | } 53 | img_write(img, w * d, h, 4, path); 54 | free(img); 55 | return 0; 56 | } 57 | 58 | FILE_FORMAT_REGISTER(png_slices, 59 | .name = "png slices", 60 | .ext = "png\0*.png\0", 61 | .export_func = export_as_png_slices, 62 | ) 63 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/ljumptab.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ljumptab.h $ 3 | ** Jump Table for the Lua interpreter 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #undef vmdispatch 9 | #undef vmcase 10 | #undef vmbreak 11 | 12 | #define vmdispatch(x) goto *disptab[x]; 13 | 14 | #define vmcase(l) L_##l: 15 | 16 | #define vmbreak vmfetch(); vmdispatch(GET_OPCODE(i)); 17 | 18 | 19 | static const void *const disptab[NUM_OPCODES] = { 20 | 21 | #if 0 22 | ** you can update the following list with this command: 23 | ** 24 | ** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h 25 | ** 26 | #endif 27 | 28 | &&L_OP_MOVE, 29 | &&L_OP_LOADI, 30 | &&L_OP_LOADF, 31 | &&L_OP_LOADK, 32 | &&L_OP_LOADKX, 33 | &&L_OP_LOADFALSE, 34 | &&L_OP_LFALSESKIP, 35 | &&L_OP_LOADTRUE, 36 | &&L_OP_LOADNIL, 37 | &&L_OP_GETUPVAL, 38 | &&L_OP_SETUPVAL, 39 | &&L_OP_GETTABUP, 40 | &&L_OP_GETTABLE, 41 | &&L_OP_GETI, 42 | &&L_OP_GETFIELD, 43 | &&L_OP_SETTABUP, 44 | &&L_OP_SETTABLE, 45 | &&L_OP_SETI, 46 | &&L_OP_SETFIELD, 47 | &&L_OP_NEWTABLE, 48 | &&L_OP_SELF, 49 | &&L_OP_ADDI, 50 | &&L_OP_ADDK, 51 | &&L_OP_SUBK, 52 | &&L_OP_MULK, 53 | &&L_OP_MODK, 54 | &&L_OP_POWK, 55 | &&L_OP_DIVK, 56 | &&L_OP_IDIVK, 57 | &&L_OP_BANDK, 58 | &&L_OP_BORK, 59 | &&L_OP_BXORK, 60 | &&L_OP_SHRI, 61 | &&L_OP_SHLI, 62 | &&L_OP_ADD, 63 | &&L_OP_SUB, 64 | &&L_OP_MUL, 65 | &&L_OP_MOD, 66 | &&L_OP_POW, 67 | &&L_OP_DIV, 68 | &&L_OP_IDIV, 69 | &&L_OP_BAND, 70 | &&L_OP_BOR, 71 | &&L_OP_BXOR, 72 | &&L_OP_SHL, 73 | &&L_OP_SHR, 74 | &&L_OP_MMBIN, 75 | &&L_OP_MMBINI, 76 | &&L_OP_MMBINK, 77 | &&L_OP_UNM, 78 | &&L_OP_BNOT, 79 | &&L_OP_NOT, 80 | &&L_OP_LEN, 81 | &&L_OP_CONCAT, 82 | &&L_OP_CLOSE, 83 | &&L_OP_TBC, 84 | &&L_OP_JMP, 85 | &&L_OP_EQ, 86 | &&L_OP_LT, 87 | &&L_OP_LE, 88 | &&L_OP_EQK, 89 | &&L_OP_EQI, 90 | &&L_OP_LTI, 91 | &&L_OP_LEI, 92 | &&L_OP_GTI, 93 | &&L_OP_GEI, 94 | &&L_OP_TEST, 95 | &&L_OP_TESTSET, 96 | &&L_OP_CALL, 97 | &&L_OP_TAILCALL, 98 | &&L_OP_RETURN, 99 | &&L_OP_RETURN0, 100 | &&L_OP_RETURN1, 101 | &&L_OP_FORLOOP, 102 | &&L_OP_FORPREP, 103 | &&L_OP_TFORPREP, 104 | &&L_OP_TFORCALL, 105 | &&L_OP_TFORLOOP, 106 | &&L_OP_SETLIST, 107 | &&L_OP_CLOSURE, 108 | &&L_OP_VARARG, 109 | &&L_OP_VARARGPREP, 110 | &&L_OP_EXTRAARG 111 | 112 | }; 113 | -------------------------------------------------------------------------------- /src/assets.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2016 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | typedef struct { 22 | const char *path; 23 | int size; 24 | const void *data __attribute__((aligned(4))); 25 | } asset_t; 26 | 27 | static asset_t ASSETS[]; // Defined in assets.inl 28 | 29 | const void *assets_get(const char *url, int *size) 30 | { 31 | int i; 32 | if (str_startswith(url, "asset://")) url += 8; // Skip asset:// 33 | for (i = 0; ASSETS[i].path; i++) { 34 | if (strcmp(ASSETS[i].path, url) == 0) { 35 | if (size) *size = ASSETS[i].size; 36 | return ASSETS[i].data; 37 | } 38 | } 39 | return NULL; 40 | } 41 | 42 | int assets_list(const char *url, void *user, 43 | int (*f)(int i, const char *path, void *user)) 44 | { 45 | int i, j = 0; 46 | for (i = 0; ASSETS[i].path; i++) { 47 | if (str_startswith(ASSETS[i].path, url)) { 48 | if (!f || f(j, ASSETS[i].path, user) == 0) j++; 49 | } 50 | } 51 | return j; 52 | } 53 | 54 | static asset_t ASSETS[] = { 55 | #include "assets/fonts.inl" 56 | #include "assets/icons.inl" 57 | #include "assets/images.inl" 58 | #include "assets/other.inl" 59 | #include "assets/lua.inl" 60 | #include "assets/palettes.inl" 61 | #include "assets/progs.inl" 62 | #include "assets/shaders.inl" 63 | #include "assets/themes.inl" 64 | #ifdef ASSETS_EXTRA 65 | # include ASSETS_EXTRA // Allow to add custom assets at build time. 66 | #endif 67 | {}, // NULL asset at the end of the list. 68 | }; 69 | -------------------------------------------------------------------------------- /src/utils/texture.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef TEXTURE_H 20 | #define TEXTURE_H 21 | 22 | #include 23 | #include 24 | 25 | enum { 26 | TF_DEPTH = 1 << 0, 27 | TF_STENCIL = 1 << 1, 28 | TF_MIPMAP = 1 << 2, 29 | TF_KEEP = 1 << 3, 30 | TF_RGB = 1 << 4, 31 | TF_RGB_565 = 1 << 5, 32 | TF_HAS_TEX = 1 << 6, 33 | TF_HAS_FB = 1 << 7, 34 | TF_NEAREST = 1 << 8, 35 | }; 36 | 37 | // Type: texture_t 38 | // Reresent a 2d texture. 39 | typedef struct texture texture_t; 40 | struct texture { 41 | int ref; // For reference copy. 42 | char *path; // Only for image textures. 43 | 44 | int format; 45 | uint32_t tex; 46 | int tex_w, tex_h; // The actual OpenGL texture size. 47 | int x, y, w, h; // Position of the sub texture. 48 | int flags; 49 | // This is only used for buffer textures. 50 | uint32_t framebuffer, depth, stencil; 51 | }; 52 | 53 | texture_t *texture_new_from_buf(const uint8_t *data, 54 | int w, int h, int bpp, int flags); 55 | texture_t *texture_new_surface(int w, int h, int flags); 56 | texture_t *texture_new_buffer(int w, int h, int flags); 57 | void texture_get_data(const texture_t *tex, int w, int h, int bpp, 58 | uint8_t *buf); 59 | 60 | texture_t *texture_copy(texture_t *tex); 61 | void texture_delete(texture_t *tex); 62 | 63 | void texture_set_data(texture_t *tex, 64 | const uint8_t *data, int w, int h, int bpp); 65 | 66 | #endif // TEXTURE_H 67 | -------------------------------------------------------------------------------- /src/utils/box.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "utils/box.h" 20 | 21 | static bool box_intersect_box_(const float b1[4][4], const float b2[4][4]) 22 | { 23 | float inv[4][4], box[4][4], vertices[8][3]; 24 | int i, p; 25 | // The six planes equations: 26 | const int P[6][4] = { 27 | {-1, 0, 0, -1}, {1, 0, 0, -1}, 28 | {0, -1, 0, -1}, {0, 1, 0, -1}, 29 | {0, 0, -1, -1}, {0, 0, 1, -1} 30 | }; 31 | if (!mat4_invert(b1, inv)) return false; 32 | mat4_mul(inv, b2, box); 33 | box_get_vertices(box, vertices); 34 | for (p = 0; p < 6; p++) { 35 | for (i = 0; i < 8; i++) { 36 | if ( P[p][0] * vertices[i][0] + 37 | P[p][1] * vertices[i][1] + 38 | P[p][2] * vertices[i][2] + 39 | P[p][3] * 1 < 0) { 40 | break; 41 | } 42 | } 43 | if (i == 8) // All the points are outside a clipping plane. 44 | return false; 45 | } 46 | return true; 47 | } 48 | 49 | bool box_intersect_box(const float b1[4][4], const float b2[4][4]) 50 | { 51 | return box_intersect_box_(b1, b2) || box_intersect_box_(b2, b1); 52 | } 53 | 54 | void box_union(const float a[4][4], const float b[4][4], float out[4][4]) 55 | { 56 | float verts[16][3]; 57 | 58 | if (box_is_null(a)) { 59 | mat4_copy(b, out); 60 | return; 61 | } 62 | if (box_is_null(b)) { 63 | mat4_copy(a, out); 64 | return; 65 | } 66 | 67 | box_get_vertices(a, verts + 0); 68 | box_get_vertices(b, verts + 8); 69 | bbox_from_npoints(out, 16, verts); 70 | } 71 | -------------------------------------------------------------------------------- /src/inputs.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef INPUTS_H 20 | #define INPUTS_H 21 | 22 | #include 23 | #include 24 | 25 | // Key id, same as GLFW for convenience. 26 | enum { 27 | KEY_ESCAPE = 256, 28 | KEY_ENTER = 257, 29 | KEY_TAB = 258, 30 | KEY_BACKSPACE = 259, 31 | KEY_DELETE = 261, 32 | KEY_RIGHT = 262, 33 | KEY_LEFT = 263, 34 | KEY_DOWN = 264, 35 | KEY_UP = 265, 36 | KEY_PAGE_UP = 266, 37 | KEY_PAGE_DOWN = 267, 38 | KEY_HOME = 268, 39 | KEY_END = 269, 40 | KEY_LEFT_SHIFT = 340, 41 | KEY_RIGHT_SHIFT = 344, 42 | KEY_CONTROL = 341, 43 | }; 44 | 45 | 46 | // A finger touch or mouse click state. 47 | // `down` represent each button in the mouse. For touch events only the 48 | // first element is set. 49 | typedef struct { 50 | float pos[2]; 51 | bool down[3]; 52 | } touch_t; 53 | 54 | typedef struct inputs 55 | { 56 | int window_size[2]; 57 | float scale; 58 | bool keys[512]; // Table of all the pressed keys. 59 | uint32_t chars[16]; 60 | touch_t touches[4]; 61 | float mouse_wheel; 62 | int framebuffer; // Screen framebuffer 63 | 64 | // Screen safe margins, used for iOS only. 65 | struct { 66 | int top; 67 | int bottom; 68 | int left; 69 | int right; 70 | } safe_margins; 71 | 72 | } inputs_t; 73 | 74 | // Conveniance function to add a char in the inputs. 75 | void inputs_insert_char(inputs_t *inputs, uint32_t c); 76 | 77 | #endif // INPUTS_H 78 | -------------------------------------------------------------------------------- /src/utils/b64.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "b64.h" 20 | 21 | #include 22 | #include 23 | 24 | /* Function: b64_decode 25 | * Decode a base64 string 26 | * 27 | * Parameters: 28 | * src - A base 64 encoded string. 29 | * dest - Buffer that will receive the decoded value or NULL. If set to 30 | * NULL the function just returns the size of the decoded data. 31 | * 32 | * Return: 33 | * The size of the decoded data. 34 | */ 35 | int b64_decode(const char *src, void *dest) 36 | { 37 | const char TABLE[] = 38 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 39 | int len = strlen(src); 40 | uint8_t *p = dest; 41 | #define b64_value(c) ((strchr(TABLE, c) ?: TABLE) - TABLE) 42 | #define isbase64(c) (c && strchr(TABLE, c)) 43 | 44 | if (*src == 0) return 0; 45 | if (!p) return ((len + 3) / 4) * 3; 46 | do { 47 | char a = b64_value(src[0]); 48 | char b = b64_value(src[1]); 49 | char c = b64_value(src[2]); 50 | char d = b64_value(src[3]); 51 | *p++ = (a << 2) | (b >> 4); 52 | *p++ = (b << 4) | (c >> 2); 53 | *p++ = (c << 6) | d; 54 | if (!isbase64(src[1])) { 55 | p -= 2; 56 | break; 57 | } 58 | else if (!isbase64(src[2])) { 59 | p -= 2; 60 | break; 61 | } 62 | else if (!isbase64(src[3])) { 63 | p--; 64 | break; 65 | } 66 | src += 4; 67 | while (*src && (*src == 13 || *src == 10)) src++; 68 | } while (len -= 4); 69 | return p - (uint8_t*)dest; 70 | } 71 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast_int((pc) - (p)->code) - 1) 15 | 16 | 17 | /* Active Lua function (given call info) */ 18 | #define ci_func(ci) (clLvalue(s2v((ci)->func))) 19 | 20 | 21 | #define resethookcount(L) (L->hookcount = L->basehookcount) 22 | 23 | /* 24 | ** mark for entries in 'lineinfo' array that has absolute information in 25 | ** 'abslineinfo' array 26 | */ 27 | #define ABSLINEINFO (-0x80) 28 | 29 | 30 | /* 31 | ** MAXimum number of successive Instructions WiTHout ABSolute line 32 | ** information. (A power of two allows fast divisions.) 33 | */ 34 | #if !defined(MAXIWTHABS) 35 | #define MAXIWTHABS 128 36 | #endif 37 | 38 | 39 | LUAI_FUNC int luaG_getfuncline (const Proto *f, int pc); 40 | LUAI_FUNC const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, 41 | StkId *pos); 42 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 43 | const char *opname); 44 | LUAI_FUNC l_noret luaG_callerror (lua_State *L, const TValue *o); 45 | LUAI_FUNC l_noret luaG_forerror (lua_State *L, const TValue *o, 46 | const char *what); 47 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 48 | const TValue *p2); 49 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 50 | const TValue *p2, 51 | const char *msg); 52 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 53 | const TValue *p2); 54 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 55 | const TValue *p2); 56 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 57 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 58 | TString *src, int line); 59 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 60 | LUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc); 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/actions.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2020 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | /* 20 | * This file contains the list of all the actions, in the form of an 21 | * enum of values ACTION_. 22 | */ 23 | 24 | #ifndef ACTIONS_H 25 | #define ACTIONS_H 26 | 27 | #define X(name) ACTION_##name 28 | 29 | enum { 30 | ACTION_NULL = 0, 31 | 32 | X(layer_clear), 33 | X(img_new_layer), 34 | X(img_del_layer), 35 | X(img_move_layer_up), 36 | X(img_move_layer_down), 37 | X(img_duplicate_layer), 38 | X(img_clone_layer), 39 | X(img_hide_all_layers), 40 | X(img_show_all_layers), 41 | X(img_unclone_layer), 42 | X(img_select_parent_layer), 43 | X(img_merge_visible_layers), 44 | X(img_new_camera), 45 | X(img_del_camera), 46 | X(img_move_camera_up), 47 | X(img_move_camera_down), 48 | X(img_image_layer_to_mesh), 49 | X(img_new_shape_layer), 50 | X(img_new_material), 51 | X(img_del_material), 52 | X(img_auto_resize), 53 | 54 | X(cut_as_new_layer), 55 | X(reset_selection), 56 | X(fill_selection), 57 | X(add_selection), 58 | X(sub_selection), 59 | X(copy), 60 | X(past), 61 | X(view_left), 62 | X(view_right), 63 | X(view_top), 64 | X(view_default), 65 | X(view_front), 66 | X(quit), 67 | X(undo), 68 | X(redo), 69 | X(toggle_mode), 70 | X(export_render_buf_to_photos), 71 | X(open), 72 | X(save_as), 73 | X(save), 74 | X(reset), 75 | 76 | X(tool_set_brush), 77 | X(tool_set_laser), 78 | X(tool_set_shape), 79 | X(tool_set_pick_color), 80 | X(tool_set_extrude), 81 | X(tool_set_plane), 82 | X(tool_set_selection), 83 | X(tool_set_fuzzy_select), 84 | X(tool_set_line), 85 | X(tool_set_move), 86 | 87 | X(export_to_photos), 88 | X(open_run_lua_plugin), 89 | 90 | ACTION_COUNT 91 | }; 92 | 93 | #undef X 94 | 95 | #endif // ACTIONS_H 96 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Goxel2 2 | 3 | 4 | Thanks alot if you considered to contribute to goxel2, contributing to goxel2 isn't hard just ensure these things: 5 | 6 | - Fake Patches Which Are Intended To Introduce New Bugs Will Not Be Tolerated 7 | - Not Neccessary But If Possible Please Follow The Below Given Coding Style 8 | - Not Neccessary But If Possible Make Sure To Use English in Comments or Anywhere in the Repository 9 | - Make Sure you abide by the [Code of Conduct](CODE_OF_CONDUCT.md) 10 | 11 | Contribution is not always has to be in form of Code, helping people in [Issues](https://github.com/pegvin/goxel2/issues) or in [Discussions](https://github.com/pegvin/goxel2/discussions). 12 | 13 | all the contributors who made contributions in form of code will be list in the [AUTHORS](AUTHORS.md) file. 14 | 15 | ## Coding style 16 | 17 | Try to follow the code style I used for Goxel, as I am unlikely to merge a pull 18 | request that doesn't. The coding style is almost the one used by the linux 19 | kernel, but using four spaces for indentation (I also accept typedef). When in 20 | doubt, just look at other part of the code. The most important rules are: 21 | 22 | - Use tabs characters if possible. 23 | - No trailing white space. 24 | - Please Try to use [Camel Case](https://en.wikipedia.org/wiki/Camel_case) but others are allowed too 25 | - Please Try to define functions and stuff like below given 26 | 27 | ```c 28 | int my_func(void) { 29 | ... 30 | return 0; 31 | } 32 | ``` 33 | 34 | - No space between function and argument parenthesis: 35 | 36 | ```c 37 | func(10, 20) // Good 38 | func (10, 20) // BAD! 39 | ``` 40 | 41 | - One space after keywords, except `sizeof`: 42 | 43 | ```c 44 | if (something) // Good 45 | if(something) // BAD 46 | ``` 47 | 48 | - One space around binary operators, no space after unary operators and 49 | before postfix operators. 50 | 51 | ```c 52 | x = 10 + 20 * 3; // Good 53 | x = 10+20*3; // BAD 54 | x++; // Good 55 | x ++; // BAD 56 | y = &x; // Good 57 | y = & x; // VERY BAD 58 | ``` 59 | 60 | ## Git commit style 61 | 62 | - Keep the summary line under about 50 characters. 63 | 64 | - The rest of the commit message separated by a blank line. Wrap lines at 65 | 72 characters. 66 | 67 | - Try to separate the commits into small logical parts. For example if you 68 | need to add a new public function in order to fix a bug, the first commit 69 | should be about adding the function, and the second one about fixing the 70 | bug. 71 | -------------------------------------------------------------------------------- /src/utils/cache.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef CACHE_H 20 | #define CACHE_H 21 | 22 | // Generic data cache structure. 23 | 24 | // Allow to cache blocks merge operations. 25 | typedef struct cache cache_t; 26 | 27 | /* 28 | * Function: cache_create 29 | * Create a new cache with a given max size (in byte). 30 | */ 31 | cache_t *cache_create(int size); 32 | 33 | /* 34 | * Function: cache_add 35 | * Add an item into the cache. 36 | * 37 | * Parameters: 38 | * cache - A cache_t instance. 39 | * key - Unique key data for the cache item. 40 | * keylen - Size of the key data. 41 | * data - Pointer to the item data. The cache takes ownership. 42 | * cost - Cost of the data used to compute the cache usage. 43 | * It doesn't have to be the size. 44 | * delfunc - Function that the cache can use to free the data. 45 | */ 46 | void cache_add(cache_t *cache, const void *key, int keylen, void *data, 47 | int cost, int (*delfunc)(void *data)); 48 | 49 | /* 50 | * Function: cache_get 51 | * Retreive an item from the cache. 52 | * 53 | * Parameters: 54 | * cache - A cache_t instance. 55 | * key - Unique key data for the item. 56 | * keylen - Sizeo of the key data. 57 | * 58 | * Returns: 59 | * The data owned by the cache, or NULL if no item with this key is in 60 | * the cache. 61 | */ 62 | void *cache_get(cache_t *cache, const void *key, int keylen); 63 | 64 | /* 65 | * Function: cache_clear 66 | * Delete all the cached items. 67 | */ 68 | void cache_clear(cache_t *cache); 69 | 70 | /* 71 | * Function: cache_delete 72 | * Delete a cache. 73 | */ 74 | void cache_delete(cache_t *cache); 75 | 76 | 77 | #endif // CACHE_H 78 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->u.next) 16 | 17 | 18 | /* 19 | ** Clear all bits of fast-access metamethods, which means that the table 20 | ** may have any of these metamethods. (First access that fails after the 21 | ** clearing will set the bit again.) 22 | */ 23 | #define invalidateTMcache(t) ((t)->flags &= ~maskflags) 24 | 25 | 26 | /* true when 't' is using 'dummynode' as its hash part */ 27 | #define isdummy(t) ((t)->lastfree == NULL) 28 | 29 | 30 | /* allocated size for hash nodes */ 31 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 32 | 33 | 34 | /* returns the Node, given the value of a table entry */ 35 | #define nodefromval(v) cast(Node *, (v)) 36 | 37 | 38 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 39 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 40 | TValue *value); 41 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 42 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 43 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 44 | LUAI_FUNC void luaH_newkey (lua_State *L, Table *t, const TValue *key, 45 | TValue *value); 46 | LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key, 47 | TValue *value); 48 | LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key, 49 | const TValue *slot, TValue *value); 50 | LUAI_FUNC Table *luaH_new (lua_State *L); 51 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 52 | unsigned int nhsize); 53 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 54 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 55 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 56 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); 57 | LUAI_FUNC unsigned int luaH_realasize (const Table *t); 58 | 59 | 60 | #if defined(LUA_DEBUG) 61 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 62 | LUAI_FUNC int luaH_isdummy (const Table *t); 63 | #endif 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/exposed_funcs.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2022 Aditya Mishra 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "exposed_funcs.h" 20 | 21 | unsigned char SelectedColor[4] = { 255, 255, 255, 255 }; 22 | 23 | int lua_GoxSetColor(lua_State* L) { 24 | int NewColor[3], isNum; 25 | 26 | for (int i = 0; i < 3; ++i) { 27 | NewColor[i] = (int)lua_tonumberx(L, i+1, &isNum); 28 | if (isNum == false) { 29 | break; 30 | } 31 | } 32 | 33 | if (isNum != false) { 34 | // Clamp The Values Between 0 & 255 35 | for (int i = 0; i < 3; ++i) { 36 | SelectedColor[i] = NewColor[i] <= 0 ? 0 : NewColor[i]; 37 | SelectedColor[i] = NewColor[i] >= 255 ? 255 : NewColor[i]; 38 | } 39 | } 40 | 41 | printf("[C] - GoxSetColor(%d, %d, %d);\n", SelectedColor[0], SelectedColor[1], SelectedColor[2]); 42 | return 3; 43 | } 44 | 45 | int lua_GoxCreateBoxAt(lua_State* L) { 46 | int x, y, z; 47 | x = (int)lua_tonumber(L, 1); 48 | y = (int)lua_tonumber(L, 2); 49 | z = (int)lua_tonumber(L, 3); 50 | 51 | mesh_iterator_t it = mesh_get_iterator(goxel.image->active_layer->mesh, MESH_ITER_VOXELS); 52 | mesh_set_at( 53 | goxel.image->active_layer->mesh, // Mesh To Draw At 54 | &it, // Iterator 55 | (int[3]) { x, y, z }, // Position 56 | SelectedColor // Color 57 | ); 58 | 59 | printf("[C] - GoxCreateBoxAt(%d, %d, %d);\n", x, y, z); 60 | return 3; 61 | } 62 | 63 | int lua_GoxRemoveBoxAt(lua_State* L) { 64 | int x, y, z; 65 | x = (int)lua_tonumber(L, 1); 66 | y = (int)lua_tonumber(L, 2); 67 | z = (int)lua_tonumber(L, 3); 68 | 69 | mesh_iterator_t it = mesh_get_iterator(goxel.image->active_layer->mesh, MESH_ITER_VOXELS); 70 | mesh_clear_block( 71 | goxel.image->active_layer->mesh, // Mesh To Draw At 72 | &it, // Iterator 73 | (int[3]) { x, y, z } // Position 74 | ); 75 | 76 | printf("[C] - GoxRemoveBoxAt(%d, %d, %d);\n", x, y, z); 77 | return 3; 78 | } 79 | -------------------------------------------------------------------------------- /src/gui/export_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | #include "file_format.h" 21 | 22 | #ifndef GUI_CUSTOM_EXPORT_PANEL 23 | 24 | #if 0 25 | 26 | Keep this here as a reference until I fix file format names and order. 27 | 28 | {"glTF (.gltf)", "export_as_gltf"}, 29 | {"Wavefront (.obj)", "export_as_obj"}, 30 | {"Stanford (.pny)", "export_as_ply"}, 31 | {"Png", "export_as_png"}, 32 | {"Magica voxel (.vox)", "export_as_vox"}, 33 | {"Qubicle (.qb)", "export_as_qubicle"}, 34 | {"Slab (.kvx)", "export_as_kvx"}, 35 | {"Spades (.vxl)", "export_as_vxl"}, 36 | {"Png slices (.png)", "export_as_png_slices"}, 37 | {"Plain text (.txt)", "export_as_txt"}, 38 | 39 | #endif 40 | 41 | static const file_format_t *g_current = NULL; 42 | 43 | static const char *make_label(const file_format_t *f, char *buf, int len) 44 | { 45 | const char *ext = f->ext + strlen(f->ext) + 2; 46 | snprintf(buf, len, "%s (%s)", f->name, ext); 47 | return buf; 48 | } 49 | 50 | static void on_format(void *user, const file_format_t *f) 51 | { 52 | char label[128]; 53 | make_label(f, label, sizeof(label)); 54 | if (gui_combo_item(label, f == g_current)) { 55 | g_current = f; 56 | } 57 | } 58 | 59 | void gui_export_panel(void) 60 | { 61 | char label[128]; 62 | gui_text("Export as"); 63 | if (!g_current) g_current = file_formats; // First one. 64 | 65 | make_label(g_current, label, sizeof(label)); 66 | if (gui_combo_begin("Export as", label)) { 67 | file_format_iter("w", NULL, on_format); 68 | gui_combo_end(); 69 | } 70 | 71 | if (g_current->export_gui) 72 | g_current->export_gui(); 73 | if (gui_button("Export", 1, 0)) 74 | goxel_export_to_file(NULL, g_current->name); 75 | } 76 | 77 | #endif // GUI_CUSTOM_EXPORT_PANEL 78 | -------------------------------------------------------------------------------- /src/lua_plugins.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2022 Aditya Mishra 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "lua_plugins.h" 20 | 21 | #define NUM_OF_STATES 100 22 | lua_State* StateArr[NUM_OF_STATES] = { NULL }; 23 | 24 | bool check_lua(lua_State* L, int r) { 25 | if (r != LUA_OK) { 26 | LOG_E("[Lua] - %s\n", lua_tostring(L, -1)); 27 | return false; 28 | } 29 | return true; 30 | } 31 | 32 | void ReleaseAllLuaVMs() { 33 | int releasedVMCount = 0; 34 | for (int i = 0; i < NUM_OF_STATES; ++i) { 35 | if (StateArr[i] != NULL) { 36 | lua_close(StateArr[i]); 37 | StateArr[i] = NULL; 38 | releasedVMCount++; 39 | } 40 | } 41 | 42 | LOG_I("Released Lua VMs"); 43 | } 44 | 45 | lua_State* NewLuaVM() { 46 | lua_State* L = luaL_newstate(); 47 | luaL_openlibs(L); 48 | lua_register(L, "GoxCreateBoxAt", lua_GoxCreateBoxAt); 49 | lua_register(L, "GoxRemoveBoxAt", lua_GoxRemoveBoxAt); 50 | lua_register(L, "GoxSetColor", lua_GoxSetColor); 51 | 52 | // Vector3 Math Library 53 | check_lua(L, luaL_dostring(L, assets_get("asset://data/lua/vector3.lua", NULL))); 54 | 55 | for (int i = 0; i < NUM_OF_STATES; ++i) { 56 | if (StateArr[i] == NULL) { 57 | StateArr[i] = L; 58 | check_lua(L, luaL_dostring(L, "print('Lua Virtual Machine Initialized!')\n")); 59 | return L; 60 | } 61 | } 62 | 63 | // If the function reaches at this point, it means the StateArr is full so we do all the clean up here. 64 | lua_close(L); 65 | LOG_E("Unable to initialize a new LUA VM, States Are Full"); 66 | return NULL; 67 | } 68 | 69 | static void open_run_lua_plugin(void) { 70 | const char *filePath; 71 | filePath = noc_file_dialog_open(NOC_FILE_DIALOG_OPEN, "lua\0*.lua\0", NULL, NULL); 72 | if (!filePath) return; 73 | 74 | lua_State* L = NewLuaVM(); 75 | if (L == NULL) return; 76 | 77 | check_lua(L, luaL_dofile(L, filePath)); 78 | } 79 | 80 | ACTION_REGISTER(open_run_lua_plugin, 81 | .help = "Run Plugin", 82 | .cfunc = open_run_lua_plugin, 83 | ) 84 | -------------------------------------------------------------------------------- /data/palettes/Gold.gpl: -------------------------------------------------------------------------------- 1 | GIMP Palette 2 | Name: Gold 3 | # 4 | 0 0 0 #000000 5 | 128 128 128 #808080 6 | 255 255 255 #FFFFFF 7 | 252 252 128 #FCFC80 8 | 252 248 124 #FCF87C 9 | 252 244 120 #FCF478 10 | 248 244 120 #F8F478 11 | 248 240 116 #F8F074 12 | 248 240 112 #F8F070 13 | 248 236 112 #F8EC70 14 | 244 236 108 #F4EC6C 15 | 244 232 108 #F4E86C 16 | 244 232 104 #F4E868 17 | 244 228 104 #F4E468 18 | 240 228 100 #F0E464 19 | 240 224 96 #F0E060 20 | 240 220 92 #F0DC5C 21 | 236 220 92 #ECDC5C 22 | 236 216 88 #ECD858 23 | 236 216 84 #ECD854 24 | 236 212 84 #ECD454 25 | 236 212 80 #ECD450 26 | 232 208 80 #E8D050 27 | 232 208 76 #E8D04C 28 | 232 204 76 #E8CC4C 29 | 232 204 72 #E8CC48 30 | 228 200 68 #E4C844 31 | 228 196 64 #E4C440 32 | 224 192 60 #E0C03C 33 | 224 192 56 #E0C038 34 | 224 188 56 #E0BC38 35 | 224 188 52 #E0BC34 36 | 220 184 52 #DCB834 37 | 220 184 48 #DCB830 38 | 220 180 48 #DCB430 39 | 220 180 44 #DCB42C 40 | 220 176 40 #DCB028 41 | 216 176 40 #D8B028 42 | 216 172 36 #D8AC24 43 | 216 168 32 #D8A820 44 | 212 168 28 #D4A81C 45 | 212 164 28 #D4A41C 46 | 212 164 24 #D4A418 47 | 212 160 24 #D4A018 48 | 208 160 20 #D0A014 49 | 208 156 20 #D09C14 50 | 208 156 16 #D09C10 51 | 208 152 12 #D0980C 52 | 204 152 12 #CC980C 53 | 204 148 8 #CC9408 54 | 204 144 4 #CC9004 55 | 200 140 0 #C88C00 56 | 196 136 0 #C48800 57 | 192 132 0 #C08400 58 | 188 128 0 #BC8000 59 | 184 124 0 #B87C00 60 | 180 120 0 #B47800 61 | 176 116 0 #B07400 62 | 172 112 0 #AC7000 63 | 168 108 0 #A86C00 64 | 164 104 0 #A46800 65 | 160 100 0 #A06400 66 | 156 96 0 #9C6000 67 | 152 92 0 #985C00 68 | 148 88 0 #945800 69 | 144 84 0 #905400 70 | 140 80 0 #8C5000 71 | 136 76 0 #884C00 72 | 132 72 0 #844800 73 | 128 68 0 #804400 74 | 124 64 0 #7C4000 75 | 120 60 0 #783C00 76 | 116 56 0 #743800 77 | 112 52 0 #703400 78 | 108 48 0 #6C3000 79 | 104 44 0 #682C00 80 | 100 40 0 #642800 81 | 96 36 0 #602400 82 | 92 32 0 #5C2000 83 | 88 28 0 #581C00 84 | 84 24 0 #541800 85 | 80 20 0 #501400 86 | 76 16 0 #4C1000 87 | 72 12 0 #480C00 88 | 68 8 0 #440800 89 | 64 4 0 #400400 90 | 60 0 0 #3C0000 91 | 56 0 0 #380000 92 | 52 0 0 #340000 93 | 48 0 0 #300000 94 | 44 0 0 #2C0000 95 | 40 0 0 #280000 96 | 36 0 0 #240000 97 | 32 0 0 #200000 98 | 28 0 0 #1C0000 99 | 24 0 0 #180000 100 | 20 0 0 #140000 101 | 16 0 0 #100000 102 | 12 0 0 #0C0000 103 | 8 0 0 #080000 104 | 4 0 0 #040000 105 | 0 0 0 #000000 106 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua. 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | 65 | /* 66 | ** In ASCII, this 'ltolower' is correct for alphabetic characters and 67 | ** for '.'. That is enough for Lua needs. ('check_exp' ensures that 68 | ** the character either is an upper-case letter or is unchanged by 69 | ** the transformation, which holds for lower-case letters and '.'.) 70 | */ 71 | #define ltolower(c) \ 72 | check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \ 73 | (c) | ('A' ^ 'a')) 74 | 75 | 76 | /* one entry for each character and for -1 (EOZ) */ 77 | LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];) 78 | 79 | 80 | #else /* }{ */ 81 | 82 | /* 83 | ** use standard C ctypes 84 | */ 85 | 86 | #include 87 | 88 | 89 | #define lislalpha(c) (isalpha(c) || (c) == '_') 90 | #define lislalnum(c) (isalnum(c) || (c) == '_') 91 | #define lisdigit(c) (isdigit(c)) 92 | #define lisspace(c) (isspace(c)) 93 | #define lisprint(c) (isprint(c)) 94 | #define lisxdigit(c) (isxdigit(c)) 95 | 96 | #define ltolower(c) (tolower(c)) 97 | 98 | #endif /* } */ 99 | 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /src/file_format.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2020 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "file_format.h" 20 | #include "utlist.h" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | // The global hash table of file formats. 27 | file_format_t *file_formats = NULL; 28 | 29 | static bool endswith(const char *str, const char *end) 30 | { 31 | const char *start; 32 | if (strlen(str) < strlen(end)) return false; 33 | start = str + strlen(str) - strlen(end); 34 | return strcmp(start, end) == 0; 35 | } 36 | 37 | 38 | void file_format_register(file_format_t *format) 39 | { 40 | DL_APPEND(file_formats, format); 41 | } 42 | 43 | const file_format_t *file_format_for_path(const char *path, const char *name, 44 | const char *mode) 45 | { 46 | const file_format_t *f; 47 | bool need_read = strchr(mode, 'r'); 48 | bool need_write = strchr(mode, 'w'); 49 | const char *ext; 50 | 51 | assert(mode); 52 | assert(path || name); 53 | 54 | DL_FOREACH(file_formats, f) { 55 | if (need_read && !f->import_func) continue; 56 | if (need_write && !f->export_func) continue; 57 | if (name && strcasecmp(f->name, name) != 0) continue; 58 | if (path) { 59 | ext = f->ext + strlen(f->ext) + 2; // Pick the string after '*'. 60 | if (!endswith(path, ext)) continue; 61 | } 62 | return f; 63 | } 64 | return NULL; 65 | } 66 | 67 | void file_format_iter(const char *mode, void *user, 68 | void (*fun)(void *user, const file_format_t *f)) 69 | { 70 | assert(mode); 71 | assert(fun); 72 | const file_format_t *f; 73 | bool need_read = strchr(mode, 'r'); 74 | bool need_write = strchr(mode, 'w'); 75 | DL_FOREACH(file_formats, f) { 76 | if (need_read && !f->import_func) continue; 77 | if (need_write && !f->export_func) continue; 78 | fun(user, f); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | 20 | #if defined (LUA_UCID) /* accept UniCode IDentifiers? */ 21 | /* consider all non-ascii codepoints to be alphabetic */ 22 | #define NONA 0x01 23 | #else 24 | #define NONA 0x00 /* default */ 25 | #endif 26 | 27 | 28 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 29 | 0x00, /* EOZ */ 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 31 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 35 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 36 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 37 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 38 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 39 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 40 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 41 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 42 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 43 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 44 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 45 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 46 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 8. */ 47 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 48 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 9. */ 49 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 50 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* a. */ 51 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 52 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* b. */ 53 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 54 | 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, /* c. */ 55 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 56 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* d. */ 57 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 58 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* e. */ 59 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 60 | NONA, NONA, NONA, NONA, NONA, 0x00, 0x00, 0x00, /* f. */ 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 62 | }; 63 | 64 | #endif /* } */ 65 | -------------------------------------------------------------------------------- /src/gui/view_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | void gui_view_panel(void) 22 | { 23 | // XXX: I don't like to use this array. 24 | const struct { 25 | uint8_t *color; 26 | const char *label; 27 | } COLORS[] = { 28 | {goxel.back_color, "Back color"}, 29 | {goxel.grid_color, "Grid color"}, 30 | {goxel.image_box_color, "Box color"}, 31 | }; 32 | int i; 33 | 34 | for (i = 0; i < (int)ARRAY_SIZE(COLORS); i++) { 35 | gui_color_small(COLORS[i].label, COLORS[i].color); 36 | } 37 | gui_checkbox("Hide box", &goxel.hide_box, NULL); 38 | 39 | gui_text("Effects"); 40 | 41 | if (gui_input_float("occlusion", &goxel.rend.settings.occlusion_strength, 42 | 0.1, 0, 1, NULL)) { 43 | goxel.rend.settings.occlusion_strength = 44 | clamp(goxel.rend.settings.occlusion_strength, 0, 1); 45 | } 46 | if (gui_input_float("Smoothness", &goxel.rend.settings.smoothness, 47 | 0.1, 0, 1, NULL)) { 48 | goxel.rend.settings.smoothness = 49 | clamp(goxel.rend.settings.smoothness, 0, 1); 50 | } 51 | 52 | gui_checkbox_flag("Grid", &goxel.view_effects, EFFECT_GRID, NULL); 53 | gui_checkbox_flag("Edges", &goxel.view_effects, EFFECT_EDGES, NULL); 54 | gui_checkbox_flag("Unlit", 55 | &goxel.rend.settings.effects, EFFECT_UNLIT, NULL); 56 | gui_checkbox_flag("Borders", 57 | &goxel.rend.settings.effects, EFFECT_BORDERS, NULL); 58 | gui_checkbox_flag("See back", 59 | &goxel.rend.settings.effects, EFFECT_SEE_BACK, NULL); 60 | gui_checkbox_flag("Marching Cubes", 61 | &goxel.rend.settings.effects, EFFECT_MARCHING_CUBES, NULL); 62 | 63 | if (goxel.rend.settings.effects & EFFECT_MARCHING_CUBES) { 64 | gui_checkbox_flag("Smooth Colors", &goxel.rend.settings.effects, 65 | EFFECT_MC_SMOOTH, NULL); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/formats/png.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2017 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | #include "file_format.h" 21 | 22 | // XXX: this function has to be rewritten. 23 | static int png_export(const image_t *img, const char *path, int w, int h) 24 | { 25 | uint8_t *buf; 26 | int bpp = img->export_transparent_background ? 4 : 3; 27 | if (!path) return -1; 28 | LOG_I("Exporting to file %s", path); 29 | buf = calloc(w * h, bpp); 30 | goxel_render_to_buf(buf, w, h, bpp); 31 | img_write(buf, w, h, bpp, path); 32 | free(buf); 33 | return 0; 34 | } 35 | 36 | static void export_gui(void) { 37 | int maxsize, i; 38 | 39 | GL(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize)); 40 | maxsize /= 2; // Because png export already double it. 41 | goxel.show_export_viewport = true; 42 | gui_group_begin(NULL); 43 | gui_checkbox("Custom size", &goxel.image->export_custom_size, NULL); 44 | if (!goxel.image->export_custom_size) { 45 | goxel.image->export_width = goxel.gui.viewport[2]; 46 | goxel.image->export_height = goxel.gui.viewport[3]; 47 | } 48 | 49 | gui_enabled_begin(goxel.image->export_custom_size); 50 | i = goxel.image->export_width; 51 | if (gui_input_int("w", &i, 1, maxsize)) 52 | goxel.image->export_width = clamp(i, 1, maxsize); 53 | i = goxel.image->export_height; 54 | if (gui_input_int("h", &i, 1, maxsize)) 55 | goxel.image->export_height = clamp(i, 1, maxsize); 56 | gui_enabled_end(); 57 | gui_group_end(); 58 | 59 | gui_checkbox("Transparent background", 60 | &goxel.image->export_transparent_background, 61 | NULL); 62 | } 63 | 64 | static int export_as_png(const image_t *img, const char *path) 65 | { 66 | png_export(img, path, img->export_width, img->export_height); 67 | return 0; 68 | } 69 | 70 | FILE_FORMAT_REGISTER(png, 71 | .name = "png", 72 | .ext = "png\0*.png\0", 73 | .export_gui = export_gui, 74 | .export_func = export_as_png, 75 | ) 76 | -------------------------------------------------------------------------------- /src/image.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef IMAGE_H 20 | #define IMAGE_H 21 | 22 | #include "camera.h" 23 | #include "layer.h" 24 | #include "material.h" 25 | 26 | #include 27 | #include 28 | 29 | typedef struct history history_t; 30 | 31 | typedef struct image image_t; 32 | struct image { 33 | 34 | layer_t *layers; 35 | layer_t *active_layer; 36 | 37 | camera_t *cameras; 38 | camera_t *active_camera; 39 | 40 | material_t *materials; 41 | material_t *active_material; 42 | 43 | float box[4][4]; 44 | 45 | // For saving. 46 | // XXX: I think those should be persistend data of export code instead. 47 | char *path; 48 | bool export_custom_size; 49 | int export_width; 50 | int export_height; 51 | bool export_transparent_background; 52 | uint32_t saved_key; // image_get_key() value of saved file. 53 | 54 | image_t *history; 55 | image_t *history_next, *history_prev; 56 | }; 57 | 58 | image_t *image_new(void); 59 | void image_delete(image_t *img); 60 | layer_t *image_add_layer(image_t *img, layer_t *layer); 61 | void image_delete_layer(image_t *img, layer_t *layer); 62 | layer_t *image_duplicate_layer(image_t *img, layer_t *layer); 63 | void image_merge_visible_layers(image_t *img); 64 | 65 | void image_history_push(image_t *img); 66 | void image_undo(image_t *img); 67 | void image_redo(image_t *img); 68 | void image_history_resize(image_t *img, int size); 69 | 70 | bool image_layer_can_edit(const image_t *img, const layer_t *layer); 71 | 72 | material_t *image_add_material(image_t *img, material_t *mat); 73 | void image_delete_material(image_t *img, material_t *mat); 74 | 75 | camera_t *image_add_camera(image_t *img, camera_t *cam); 76 | void image_delete_camera(image_t *img, camera_t *cam); 77 | 78 | /* 79 | * Function: image_get_key 80 | * Return a value that is guarantied to change when the image change. 81 | */ 82 | uint32_t image_get_key(const image_t *img); 83 | 84 | #endif // IMAGE_H 85 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include 11 | 12 | #include "lobject.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Single-char tokens (terminal symbols) are represented by their own 18 | ** numeric code. Other tokens start at the following value. 19 | */ 20 | #define FIRST_RESERVED (UCHAR_MAX + 1) 21 | 22 | 23 | #if !defined(LUA_ENV) 24 | #define LUA_ENV "_ENV" 25 | #endif 26 | 27 | 28 | /* 29 | * WARNING: if you change the order of this enumeration, 30 | * grep "ORDER RESERVED" 31 | */ 32 | enum RESERVED { 33 | /* terminal symbols denoted by reserved words */ 34 | TK_AND = FIRST_RESERVED, TK_BREAK, 35 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 36 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 37 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 38 | /* other terminal symbols */ 39 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 40 | TK_SHL, TK_SHR, 41 | TK_DBCOLON, TK_EOS, 42 | TK_FLT, TK_INT, TK_NAME, TK_STRING 43 | }; 44 | 45 | /* number of reserved words */ 46 | #define NUM_RESERVED (cast_int(TK_WHILE-FIRST_RESERVED + 1)) 47 | 48 | 49 | typedef union { 50 | lua_Number r; 51 | lua_Integer i; 52 | TString *ts; 53 | } SemInfo; /* semantics information */ 54 | 55 | 56 | typedef struct Token { 57 | int token; 58 | SemInfo seminfo; 59 | } Token; 60 | 61 | 62 | /* state of the lexer plus state of the parser when shared by all 63 | functions */ 64 | typedef struct LexState { 65 | int current; /* current character (charint) */ 66 | int linenumber; /* input line counter */ 67 | int lastline; /* line of last token 'consumed' */ 68 | Token t; /* current token */ 69 | Token lookahead; /* look ahead token */ 70 | struct FuncState *fs; /* current function (parser) */ 71 | struct lua_State *L; 72 | ZIO *z; /* input stream */ 73 | Mbuffer *buff; /* buffer for tokens */ 74 | Table *h; /* to avoid collection/reuse strings */ 75 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 76 | TString *source; /* current source name */ 77 | TString *envn; /* environment variable name */ 78 | } LexState; 79 | 80 | 81 | LUAI_FUNC void luaX_init (lua_State *L); 82 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 83 | TString *source, int firstchar); 84 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 85 | LUAI_FUNC void luaX_next (LexState *ls); 86 | LUAI_FUNC int luaX_lookahead (LexState *ls); 87 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 88 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 89 | 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /src/gui/material_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | void gui_material_panel(void) 22 | { 23 | material_t *mat = NULL; 24 | int i = 0; 25 | bool is_current; 26 | float base_color_e, emission_e, emission; 27 | 28 | gui_group_begin(NULL); 29 | DL_FOREACH(goxel.image->materials, mat) { 30 | is_current = goxel.image->active_material == mat; 31 | if (gui_layer_item(i, -1, NULL, &is_current, mat->name, 32 | sizeof(mat->name))) { 33 | if (is_current) { 34 | goxel.image->active_material = mat; 35 | } else { 36 | goxel.image->active_material = NULL; 37 | } 38 | } 39 | i++; 40 | } 41 | gui_group_end(); 42 | 43 | gui_action_button(ACTION_img_new_material, NULL, 0); 44 | gui_same_line(); 45 | gui_action_button(ACTION_img_del_material, NULL, 0); 46 | 47 | mat = goxel.image->active_material; 48 | if (!mat) return; 49 | 50 | gui_group_begin(NULL); 51 | gui_input_float("Metallic", &mat->metallic, 0.1, 0, 1, NULL); 52 | gui_input_float("Roughness", &mat->roughness, 0.1, 0, 1, NULL); 53 | gui_group_end(); 54 | 55 | // Internally the material has an emission color independant of the 56 | // base color, but for the moment the gui only allow to set a factor from 57 | // the base color to keep is simple. 58 | base_color_e = max3(mat->base_color[0], 59 | mat->base_color[1], 60 | mat->base_color[2]); 61 | emission_e = max3(mat->emission[0], mat->emission[1], mat->emission[2]); 62 | emission = base_color_e ? emission_e / base_color_e : 0; 63 | 64 | if (gui_color_small_f3("Color", mat->base_color)) { 65 | vec3_mul(mat->base_color, emission, mat->emission); 66 | } 67 | 68 | if (gui_input_float("Emission", &emission, 0.1, 0, 10, NULL)) { 69 | vec3_mul(mat->base_color, emission, mat->emission); 70 | } 71 | 72 | gui_input_float("Opacity", &mat->base_color[3], 0.1, 0, 1, NULL); 73 | } 74 | -------------------------------------------------------------------------------- /src/tools.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef TOOLS_H 20 | #define TOOLS_H 21 | 22 | #include "shape.h" 23 | #include "mesh_utils.h" 24 | 25 | enum { 26 | TOOL_NONE = 0, 27 | TOOL_BRUSH, 28 | TOOL_SHAPE, 29 | TOOL_LINE, 30 | TOOL_LASER, 31 | TOOL_SET_PLANE, 32 | TOOL_MOVE, 33 | TOOL_PICK_COLOR, 34 | TOOL_SELECTION, 35 | TOOL_PROCEDURAL, 36 | TOOL_EXTRUDE, 37 | TOOL_FUZZY_SELECT, 38 | 39 | TOOL_COUNT 40 | }; 41 | 42 | enum { 43 | // Tools flags. 44 | TOOL_REQUIRE_CAN_EDIT = 1 << 0, // Set to tools that can edit the layer. 45 | TOOL_REQUIRE_CAN_MOVE = 1 << 1, // Set to tools that can move the layer. 46 | TOOL_ALLOW_PICK_COLOR = 1 << 2, // Ctrl switches to pick color tool. 47 | TOOL_SHOW_MASK = 1 << 3, 48 | }; 49 | 50 | // Tools 51 | typedef struct tool tool_t; 52 | struct tool { 53 | int id; 54 | const char *action_id; 55 | int action_idx; 56 | int (*iter_fn)(tool_t *tool, const painter_t *painter, 57 | const float viewport[4]); 58 | int (*gui_fn)(tool_t *tool); 59 | const char *default_shortcut; 60 | int state; // XXX: to be removed I guess. 61 | int flags; 62 | const char *name; 63 | }; 64 | 65 | #define TOOL_REGISTER(id_, name_, klass_, ...) \ 66 | static klass_ GOX_tool_##id_ = {\ 67 | .tool = { \ 68 | .action_idx = ACTION_tool_set_##name_, \ 69 | .id = id_, .action_id = "tool_set_" #name_, __VA_ARGS__ \ 70 | } \ 71 | }; \ 72 | static void GOX_register_tool_##tool_(void) __attribute__((constructor)); \ 73 | static void GOX_register_tool_##tool_(void) { \ 74 | tool_register_(&GOX_tool_##id_.tool); \ 75 | } 76 | 77 | void tool_register_(tool_t *tool); 78 | const tool_t *tool_get(int id); 79 | 80 | int tool_iter(tool_t *tool, const painter_t *painter, const float viewport[4]); 81 | int tool_gui(tool_t *tool); 82 | 83 | int tool_gui_snap(void); 84 | int tool_gui_mask_mode(void); 85 | int tool_gui_shape(const shape_t **shape); 86 | int tool_gui_radius(void); 87 | int tool_gui_smoothness(void); 88 | int tool_gui_color(void); 89 | int tool_gui_symmetry(void); 90 | int tool_gui_drag_mode(int *mode); 91 | 92 | #endif // TOOLS_H 93 | -------------------------------------------------------------------------------- /src/shader_cache.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | #include "shader_cache.h" 22 | 23 | typedef struct { 24 | char key[256]; 25 | gl_shader_t *shader; 26 | } shader_t; 27 | 28 | static shader_t g_shaders[16] = {}; 29 | 30 | gl_shader_t *shader_get(const char *name, const shader_define_t *defines, 31 | const char **attr_names, 32 | void (*on_created)(gl_shader_t *s)) 33 | { 34 | int i; 35 | shader_t *s = NULL; 36 | const char *code; 37 | char key[256]; 38 | char path[128]; 39 | char pre[256] = {}; 40 | const shader_define_t *define; 41 | 42 | 43 | // Create the key of the form: 44 | // _define1_define2 45 | strcpy(key, name); 46 | for (define = defines; define && define->name; define++) { 47 | if (define->set) { 48 | strcat(key, "_"); 49 | strcat(key, define->name); 50 | } 51 | } 52 | 53 | for (i = 0; i < ARRAY_SIZE(g_shaders); i++) { 54 | s = &g_shaders[i]; 55 | if (!*s->key) break; 56 | if (strcmp(s->key, key) == 0) 57 | return s->shader; 58 | } 59 | assert(i < ARRAY_SIZE(g_shaders)); 60 | strcpy(s->key, key); 61 | 62 | sprintf(path, "asset://data/shaders/%s.glsl", name); 63 | code = assets_get(path, NULL); 64 | assert(code); 65 | 66 | for (define = defines; define && define->name; define++) { 67 | if (define->set) 68 | sprintf(pre + strlen(pre), "#define %s\n", define->name); 69 | } 70 | s->shader = gl_shader_create(code, code, pre, attr_names); 71 | if (on_created) on_created(s->shader); 72 | return s->shader; 73 | } 74 | 75 | /* 76 | * Function: shaders_release_all 77 | * Remove all the shaders from the cache. 78 | */ 79 | void shaders_release_all(void) 80 | { 81 | int i; 82 | shader_t *s = NULL; 83 | for (i = 0; i < ARRAY_SIZE(g_shaders); i++) { 84 | s = &g_shaders[i]; 85 | if (!*s->key) break; 86 | gl_shader_delete(s->shader); 87 | memset(s, 0, sizeof(*s)); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/gui/tools_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | #ifndef GUI_TOOLS_COLUMNS_NB 22 | # define GUI_TOOLS_COLUMNS_NB 4 23 | #endif 24 | 25 | 26 | // XXX: better replace this by something more automatic. 27 | static void auto_grid(int nb, int i, int col) 28 | { 29 | if ((i + 1) % col != 0) gui_same_line(); 30 | } 31 | 32 | void gui_tools_panel(void) 33 | { 34 | // XXX: cleanup this. 35 | const struct { 36 | int tool; 37 | int action; 38 | int icon; 39 | } values[] = { 40 | {TOOL_BRUSH, ACTION_tool_set_brush, ICON_TOOL_BRUSH}, 41 | {TOOL_SHAPE, ACTION_tool_set_shape, ICON_TOOL_SHAPE}, 42 | {TOOL_LASER, ACTION_tool_set_laser, ICON_TOOL_LASER}, 43 | {TOOL_SET_PLANE, ACTION_tool_set_plane, ICON_TOOL_PLANE}, 44 | {TOOL_MOVE, ACTION_tool_set_move, ICON_TOOL_MOVE}, 45 | {TOOL_PICK_COLOR, ACTION_tool_set_pick_color, ICON_TOOL_PICK}, 46 | {TOOL_SELECTION, ACTION_tool_set_selection, ICON_TOOL_SELECTION}, 47 | {TOOL_FUZZY_SELECT, ACTION_tool_set_fuzzy_select, ICON_TOOL_FUZZY_SELECT}, 48 | {TOOL_EXTRUDE, ACTION_tool_set_extrude, ICON_TOOL_EXTRUDE}, 49 | {TOOL_LINE, ACTION_tool_set_line, ICON_TOOL_LINE}, 50 | }; 51 | 52 | const int nb = ARRAY_SIZE(values); 53 | int i; 54 | bool v; 55 | char label[64]; 56 | const action_t *action = NULL; 57 | const tool_t *tool; 58 | 59 | gui_group_begin(NULL); 60 | for (i = 0; i < nb; i++) { 61 | tool = tool_get(values[i].tool); 62 | v = goxel.tool->id == values[i].tool; 63 | sprintf(label, "%s", tool->name); 64 | action = action_get(values[i].action, true); 65 | assert(action); 66 | if (*action->shortcut) 67 | sprintf(label, "%s (%s)", tool->name, action->shortcut); 68 | if (gui_selectable_icon(label, &v, values[i].icon)) { 69 | action_exec(action); 70 | } 71 | auto_grid(nb, i, GUI_TOOLS_COLUMNS_NB); 72 | } 73 | gui_group_end(); 74 | 75 | if (gui_collapsing_header(goxel.tool->name, true)) 76 | tool_gui(goxel.tool); 77 | } 78 | 79 | -------------------------------------------------------------------------------- /src/action.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2015 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | // Global array of actions. 22 | static action_t *g_actions = NULL; 23 | 24 | void action_register(const action_t *action, int idx) 25 | { 26 | action_t *a; 27 | assert(idx > 0 && idx < ACTION_COUNT); 28 | 29 | if (!g_actions) 30 | g_actions = calloc(ACTION_COUNT, sizeof(*g_actions)); 31 | 32 | a = &g_actions[idx]; 33 | *a = *action; 34 | a->idx = idx; 35 | assert(!a->shortcut[0]); 36 | if (a->default_shortcut) { 37 | assert(strlen(a->default_shortcut) < sizeof(a->shortcut)); 38 | strcpy(a->shortcut, a->default_shortcut); 39 | } 40 | } 41 | 42 | action_t *action_get(int idx, bool assert_exists) 43 | { 44 | action_t *action; 45 | assert(g_actions); 46 | assert(idx > 0 && idx < ACTION_COUNT); 47 | action = &g_actions[idx]; 48 | if (!action->idx && assert_exists) { 49 | LOG_E("Cannot find action %d", idx); 50 | assert(false); 51 | } 52 | return action; 53 | } 54 | 55 | action_t *action_get_by_name(const char *name) 56 | { 57 | int i; 58 | action_t *action; 59 | assert(g_actions); 60 | for (i = 0; i < ACTION_COUNT; i++) { 61 | action = &g_actions[i]; 62 | if (!action->idx) continue; 63 | if (strcmp(name, action->id) == 0) 64 | return action; 65 | } 66 | return NULL; 67 | } 68 | 69 | void actions_iter(int (*f)(action_t *action, void *user), void *user) 70 | { 71 | action_t *action; 72 | int i; 73 | for (i = 0; i < ACTION_COUNT; i++) { 74 | action = &g_actions[i]; 75 | if (!action->idx) continue; 76 | if (f(action, user)) return; 77 | } 78 | } 79 | 80 | int action_exec(const action_t *action) 81 | { 82 | assert(action); 83 | // So that we do not add undo snapshot when an action calls an other one. 84 | static int reentry = 0; 85 | 86 | if (reentry == 0 && (action->flags & ACTION_TOUCH_IMAGE)) { 87 | image_history_push(goxel.image); 88 | } 89 | 90 | reentry++; 91 | 92 | if (action->data) 93 | action->cfunc_data(action->data); 94 | else 95 | action->cfunc(); 96 | 97 | reentry--; 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /data/progs/intro.goxcf: -------------------------------------------------------------------------------- 1 | // The 'main' shape is always the entry point of the program. 2 | shape main { 3 | // Initial random seed of 2. 4 | // Remove this line to use different seed each time. 5 | [seed 2] 6 | // Improves marching cube rendering. 7 | [antialiased 1] 8 | 9 | // Render a single white voxel. 10 | cube [] 11 | 12 | // Put an other cube next to it. 13 | // 'x' applies a translation of 1 along x. 14 | // Those transformation are only applied 15 | // to this cube. 16 | cube [x 1] 17 | 18 | // Now render a bigger grey sphere. 19 | // light -0.5 move the light value to half 20 | // the current value of 1 and the target 21 | sphere [s 10 x 1 light -0.5] 22 | 23 | // We can also render cylinders: 24 | cylinder [s 10 x -1 light -0.9] 25 | 26 | // This time we use a user defined shape. 27 | // And we increase the saturation to give it a color. 28 | my_shape [z 20 light -0.5 sat 0.5] 29 | } 30 | 31 | // A user defined shape 32 | shape my_shape { 33 | // s 8 8 1 scales with different values 34 | // for each axis. 35 | // rx A applies a rotation along z of 36 | // 45 deg. 37 | 38 | // Note that the color is red, because we set the 39 | // Saturation when we called my_shape. 40 | cube [s 8 8 1 z 1 rz 45] 41 | 42 | // Loop 16 time, each time increasing the x 43 | // translation and the hue. 44 | loop 16 [x 2 hue 10] { 45 | cube [] 46 | } 47 | // The loop transformations only affect 48 | // the loop block, after it we return to 49 | // the previous context. 50 | sphere [s 6 z 1] 51 | 52 | // Let's try a recursive shape: 53 | tree [x -10 s 4] 54 | 55 | // And an other one with a bit or randomness: 56 | tree2 [x 10 s 4 rz 180 hue 180] 57 | 58 | // A shape with several rules: 59 | my_other_shape [y 10 rz 90 hue -60 s 3] 60 | } 61 | 62 | // Tree render a cylinder and then call itself. 63 | // Since we scale down the shape at each iteration 64 | // at some point it becomes too small, and is 65 | // then automatically stopped. 66 | shape tree { 67 | cylinder [] 68 | tree [z 1 s 0.99 ry -6] 69 | } 70 | 71 | shape tree2 { 72 | cylinder [] 73 | // 'A +- B' means that we use a random value in the range 74 | // A - B, A + B. this make the second spiral a bit 75 | // messy. 76 | tree2 [z 1 s 0.99 ry -6+-6] 77 | } 78 | 79 | // Here 'my_other_shape' defines several rules. The rule 80 | // used is picked randomly using the weight. 81 | shape my_other_shape 82 | 83 | // Most of the time, just keep growing in z. 84 | rule 15 { 85 | cube [] 86 | my_other_shape [z 1] 87 | } 88 | 89 | // Sometime split into two 90 | rule 1 { 91 | my_other_shape [rx 45 s 0.9] 92 | my_other_shape [rx -45 s 0.9] 93 | } 94 | 95 | // Some other times render a shpere and stop 96 | rule 0.5 { 97 | // 'hue 1 70' means that we immediately set the hue 98 | // to 70 (yellow). 99 | sphere [s 3 hue 1 70] 100 | } 101 | -------------------------------------------------------------------------------- /data/shaders/model3d.glsl: -------------------------------------------------------------------------------- 1 | #if defined(GL_ES) && defined(FRAGMENT_SHADER) 2 | #extension GL_OES_standard_derivatives : enable 3 | #endif 4 | 5 | uniform highp mat4 u_model; 6 | uniform highp mat4 u_view; 7 | uniform highp mat4 u_proj; 8 | uniform highp mat4 u_clip; 9 | uniform lowp vec4 u_color; 10 | uniform mediump vec2 u_uv_scale; 11 | uniform lowp float u_grid_alpha; 12 | uniform mediump vec3 u_l_dir; 13 | uniform mediump float u_l_diff; 14 | uniform mediump float u_l_emit; 15 | 16 | uniform mediump sampler2D u_tex; 17 | uniform mediump float u_strip; 18 | uniform mediump float u_time; 19 | 20 | varying mediump vec3 v_normal; 21 | varying highp vec3 v_pos; 22 | varying lowp vec4 v_color; 23 | varying mediump vec2 v_uv; 24 | varying mediump vec4 v_clip_pos; 25 | 26 | #ifdef VERTEX_SHADER 27 | 28 | /************************************************************************/ 29 | attribute highp vec3 a_pos; 30 | attribute lowp vec4 a_color; 31 | attribute mediump vec3 a_normal; 32 | attribute mediump vec2 a_uv; 33 | 34 | void main() 35 | { 36 | lowp vec4 col = u_color * a_color; 37 | highp vec3 pos = (u_view * u_model * vec4(a_pos, 1.0)).xyz; 38 | if (u_clip[3][3] > 0.0) 39 | v_clip_pos = u_clip * u_model * vec4(a_pos, 1.0); 40 | gl_Position = u_proj * vec4(pos, 1.0); 41 | mediump float diff = max(0.0, dot(u_l_dir, a_normal)); 42 | col.rgb *= (u_l_emit + u_l_diff * diff); 43 | v_color = col; 44 | v_uv = a_uv * u_uv_scale; 45 | v_pos = (u_model * vec4(a_pos, 1.0)).xyz; 46 | v_normal = a_normal; 47 | } 48 | /************************************************************************/ 49 | 50 | #endif 51 | 52 | #ifdef FRAGMENT_SHADER 53 | 54 | /************************************************************************/ 55 | void main() 56 | { 57 | gl_FragColor = v_color * texture2D(u_tex, v_uv); 58 | if (u_strip > 0.0) { 59 | mediump float p = gl_FragCoord.x + gl_FragCoord.y + u_time * 4.0; 60 | if (mod(p, 8.0) < 4.0) gl_FragColor.rgb *= 0.5; 61 | } 62 | if (u_clip[3][3] > 0.0) { 63 | if ( v_clip_pos[0] < -v_clip_pos[3] || 64 | v_clip_pos[1] < -v_clip_pos[3] || 65 | v_clip_pos[2] < -v_clip_pos[3] || 66 | v_clip_pos[0] > +v_clip_pos[3] || 67 | v_clip_pos[1] > +v_clip_pos[3] || 68 | v_clip_pos[2] > +v_clip_pos[3]) discard; 69 | } 70 | 71 | // Grid effect. 72 | #if !defined(GL_ES) || defined(GL_OES_standard_derivatives) 73 | if (u_grid_alpha > 0.0) { 74 | mediump vec2 c; 75 | if (abs((u_model * vec4(v_normal, 0.0)).x) > 0.5) c = v_pos.yz; 76 | if (abs((u_model * vec4(v_normal, 0.0)).y) > 0.5) c = v_pos.zx; 77 | if (abs((u_model * vec4(v_normal, 0.0)).z) > 0.5) c = v_pos.xy; 78 | mediump vec2 grid = abs(fract(c - 0.5) - 0.5) / fwidth(c); 79 | mediump float line = min(grid.x, grid.y); 80 | gl_FragColor.rgb *= mix(1.0 - u_grid_alpha, 1.0, min(line, 1.0)); 81 | } 82 | #endif 83 | 84 | } 85 | /************************************************************************/ 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/layer.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | #include "xxhash.h" 21 | 22 | layer_t *layer_new(const char *name) 23 | { 24 | layer_t *layer; 25 | layer = calloc(1, sizeof(*layer)); 26 | if (name) strncpy(layer->name, name, sizeof(layer->name) - 1); 27 | layer->mesh = mesh_new(); 28 | mat4_set_identity(layer->mat); 29 | return layer; 30 | } 31 | 32 | void layer_delete(layer_t *layer) 33 | { 34 | mesh_delete(layer->mesh); 35 | texture_delete(layer->image); 36 | free(layer); 37 | } 38 | 39 | uint32_t layer_get_key(const layer_t *layer) 40 | { 41 | uint32_t key; 42 | key = mesh_get_key(layer->mesh); 43 | key = XXH32(&layer->visible, sizeof(layer->visible), key); 44 | key = XXH32(&layer->name, sizeof(layer->name), key); 45 | key = XXH32(&layer->box, sizeof(layer->box), key); 46 | key = XXH32(&layer->mat, sizeof(layer->mat), key); 47 | key = XXH32(&layer->shape, sizeof(layer->shape), key); 48 | key = XXH32(&layer->color, sizeof(layer->color), key); 49 | key = XXH32(&layer->material, sizeof(layer->material), key); 50 | return key; 51 | } 52 | 53 | layer_t *layer_copy(layer_t *other) 54 | { 55 | layer_t *layer; 56 | layer = calloc(1, sizeof(*layer)); 57 | memcpy(layer->name, other->name, sizeof(layer->name)); 58 | layer->visible = other->visible; 59 | layer->mesh = mesh_copy(other->mesh); 60 | layer->image = texture_copy(other->image); 61 | layer->material = other->material; 62 | mat4_copy(other->box, layer->box); 63 | mat4_copy(other->mat, layer->mat); 64 | layer->id = other->id; 65 | layer->base_id = other->base_id; 66 | layer->base_mesh_key = other->base_mesh_key; 67 | layer->shape = other->shape; 68 | layer->shape_key = other->shape_key; 69 | memcpy(layer->color, other->color, sizeof(layer->color)); 70 | return layer; 71 | } 72 | 73 | /* 74 | * Function: layer_get_bounding_box 75 | * Return the layer box if set, otherwise the bounding box of the layer 76 | * mesh. 77 | */ 78 | void layer_get_bounding_box(const layer_t *layer, float box[4][4]) 79 | { 80 | int aabb[2][3]; 81 | if (!box_is_null(layer->box)) { 82 | mat4_copy(layer->box, box); 83 | return; 84 | } 85 | mesh_get_bbox(layer->mesh, aabb, true); 86 | if (aabb[0][0] > aabb[1][0]) memset(aabb, 0, sizeof(aabb)); 87 | bbox_from_aabb(box, aabb); 88 | } 89 | -------------------------------------------------------------------------------- /src/formats/txt.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2017 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | #include "file_format.h" 21 | #include 22 | 23 | static int import_as_txt(image_t *image, const char *path) 24 | { 25 | FILE *file; 26 | char line[2048]; 27 | layer_t *layer; 28 | mesh_iterator_t iter = {0}; 29 | int pos[3]; 30 | unsigned int c[4]; 31 | char *token; 32 | 33 | LOG_I("Reading text file. One line per voxel. Format should be: X Y Z RRGGBB"); 34 | file = fopen(path, "r"); 35 | 36 | //Checks if file is empty 37 | if (file == NULL) { 38 | LOG_E("Can not open file for reading: %s", path); 39 | return 1; 40 | } 41 | 42 | layer = image->active_layer; 43 | 44 | while (fgets(line, 2048, file)) { 45 | token = strtok(line, " "); // get first token (X) 46 | if (strcmp(token, "#") == 0) 47 | continue; 48 | pos[0] = atoi(token); 49 | token = strtok(NULL, " "); // get second token (Y) 50 | pos[1] = atoi(token); 51 | token = strtok(NULL, " "); // get third token (Z) 52 | pos[2] = atoi(token); 53 | token = strtok(NULL, " "); // get forth token (RRGGBB) 54 | sscanf(token, "%02x%02x%02x", &c[0], &c[1], &c[2]); 55 | mesh_set_at(layer->mesh, &iter, pos, (uint8_t[]){c[0], c[1], c[2], 255}); 56 | } 57 | 58 | fclose(file); 59 | return 0; 60 | } 61 | 62 | 63 | static int export_as_txt(const image_t *image, const char *path) 64 | { 65 | FILE *out; 66 | const mesh_t *mesh = goxel_get_layers_mesh(image); 67 | int p[3]; 68 | uint8_t v[4]; 69 | mesh_iterator_t iter; 70 | 71 | out = fopen(path, "w"); 72 | if (!out) { 73 | LOG_E("Cannot save to %s: %s", path, strerror(errno)); 74 | return -1; 75 | } 76 | fprintf(out, "# Goxel " GOXEL_VERSION_STR "\n"); 77 | fprintf(out, "# One line per voxel\n"); 78 | fprintf(out, "# X Y Z RRGGBB\n"); 79 | 80 | iter = mesh_get_iterator(mesh, MESH_ITER_VOXELS); 81 | while (mesh_iter(&iter, p)) { 82 | mesh_get_at(mesh, &iter, p, v); 83 | if (v[3] < 127) continue; 84 | fprintf(out, "%d %d %d %02x%02x%02x\n", 85 | p[0], p[1], p[2], v[0], v[1], v[2]); 86 | } 87 | fclose(out); 88 | return 0; 89 | } 90 | 91 | FILE_FORMAT_REGISTER(txt, 92 | .name = "text", 93 | .ext = "text\0*.txt\0", 94 | .import_func = import_as_txt, 95 | .export_func = export_as_txt, 96 | ) 97 | -------------------------------------------------------------------------------- /tools/create_assets.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Requires Python v3 Interpreter 4 | 5 | # Read all the files in 'data', and create assets.inl with all the data. For 6 | # text file, we try to keep the data as a string, for binary files we store it 7 | # into a uint8_t array. 8 | 9 | from collections import namedtuple 10 | import os 11 | import sys 12 | 13 | CWD = os.getcwd() 14 | BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 15 | PROJECT_ROOT = os.path.dirname(BASE_DIR) 16 | 17 | if CWD != PROJECT_ROOT: 18 | print("Error: Run the script from project root, i.e.", PROJECT_ROOT) 19 | sys.exit(-1) 20 | 21 | TYPES = { 22 | "png": { "text": False, }, 23 | "goxcf": { "text": True, }, 24 | "lua": { "text": True, }, 25 | "gpl": { "text": True, }, 26 | "pov": { "text": True, }, 27 | "ttf": { "text": False }, 28 | "wav": { "text": False }, 29 | "ini": { "text": True }, 30 | "glsl": { "text": True }, 31 | "gox": { "text": False }, 32 | "lua": { "text": True }, 33 | } 34 | 35 | GROUPS = [ 36 | 'fonts', 'icons', 'images', 37 | 'other', 'palettes', 'progs', 38 | 'shaders', 'sounds', 'themes', 39 | 'samples', 'mobile', 'lua' 40 | ] 41 | 42 | TEMPLATE = '{{\n\t.path = "{path}",\n\t.size = {size},\n\t.data = {data}\n}},\n\n' 43 | File = namedtuple('File', 'path name data size') 44 | 45 | HEADER = "/* This file is autogenerated by tools/create_assets.py */" 46 | 47 | def list_files(group): 48 | ret = [] 49 | for root, dirs, files in os.walk("data/%s" % group): 50 | for f in files: 51 | if any(f.endswith('.' + x) for x in TYPES): 52 | ret.append(os.path.join(root, f)) 53 | 54 | return sorted(ret, key=lambda x: x.upper()) 55 | 56 | def encode_str(data, f): 57 | data = data.decode() 58 | 59 | # Just Replace Platform Independent New Line Feeds ( Windows = \r\n, Mac = \r, Unix = \n ) To \n 60 | data = data.replace('\r\n', '\n').replace('\r', '\n') 61 | 62 | ret = '"' 63 | for c in data: 64 | if c == '\n': 65 | ret += '\\n' 66 | continue 67 | 68 | if c == '"': c = '\\"' 69 | if c == '\\': c = '\\\\' 70 | ret += c 71 | 72 | ret += '"' 73 | return ret 74 | 75 | def encode_bin(data): 76 | ret = "(const uint8_t[]) {" 77 | line = "" 78 | for i, c in enumerate(data): 79 | line += "{},".format(c) 80 | if len(line) >= 70 or i == len(data) - 1: 81 | ret += line 82 | line = "" 83 | 84 | ret += "}" 85 | return ret; 86 | 87 | def create_file(f): 88 | data = open(f, 'rb').read() 89 | size = len(data) 90 | name = f.replace('/', '_').replace('.', '_').replace('-', '_') 91 | ext = f.split(".")[-1] 92 | 93 | if TYPES[ext]['text']: 94 | size += 1 # So that we NULL terminate the string. 95 | data = encode_str(data, f) 96 | else: 97 | data = encode_bin(data) 98 | 99 | return File(f, name, data, size) 100 | 101 | for group in GROUPS: 102 | files = [] 103 | 104 | for f in list_files(group): 105 | files.append(create_file(f)) 106 | if not files: 107 | continue 108 | 109 | out = open("src/assets/%s.inl" % group, "w") 110 | 111 | out.write(HEADER) 112 | out.write("\n\n") 113 | 114 | for f in files: 115 | out.write(TEMPLATE.format(**f._asdict())) 116 | 117 | out.write("\n\n") 118 | -------------------------------------------------------------------------------- /src/action.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #ifndef ACTION_H 20 | #define ACTION_H 21 | 22 | #include 23 | #include 24 | 25 | #include "actions.h" 26 | #include "image.h" 27 | 28 | // #### Action ################# 29 | 30 | // We support some basic reflexion of functions. We do this by registering the 31 | // functions with the ACTION_REGISTER macro. Once a function has been 32 | // registered, it is possible to query it (action_get) and call it 33 | // (action_exec). 34 | // Check the end of image.c to see some examples. The idea is that this will 35 | // make it much easier to add meta information to functions, like 36 | // documentation, shortcuts. Also in theory this should allow to add a 37 | // scripting engine on top of goxel quite easily. 38 | 39 | // XXX: this is still pretty experimental. This might change in the future. 40 | 41 | enum { 42 | ACTION_TOUCH_IMAGE = 1 << 0, // Push the undo history. 43 | ACTION_CAN_EDIT_SHORTCUT = 1 << 2, 44 | }; 45 | 46 | // Represent an action. 47 | typedef struct action action_t; 48 | struct action { 49 | int idx; 50 | const char *id; // Globally unique id. 51 | const char *help; // Help text. 52 | int flags; 53 | const char *default_shortcut; 54 | char shortcut[8]; // Can be changed at runtime. 55 | int icon; // Optional icon id. 56 | void *data; 57 | 58 | // cfunc and csig can be used to directly call any function. 59 | union { 60 | void (*cfunc)(void); 61 | void (*cfunc_data)(void *data); 62 | }; 63 | }; 64 | 65 | void action_register(const action_t *action, int idx); 66 | 67 | action_t *action_get(int idx, bool assert_exists); 68 | action_t *action_get_by_name(const char *name); 69 | 70 | int action_exec(const action_t *action); 71 | 72 | void actions_iter(int (*f)(action_t *action, void *user), void *user); 73 | 74 | inline void action_exec2(int id) 75 | { 76 | action_exec(action_get(id, true)); 77 | } 78 | 79 | // Convenience macro to register an action from anywere in a c file. 80 | #define ACTION_REGISTER(id_, ...) \ 81 | static const action_t GOX_action_##id_ = {.id = #id_, __VA_ARGS__}; \ 82 | static void GOX_register_action_##id_(void) __attribute__((constructor)); \ 83 | static void GOX_register_action_##id_(void) { \ 84 | action_register(&GOX_action_##id_, ACTION_##id_); \ 85 | } 86 | 87 | #endif // ACTION_H 88 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Macro to check stack size and grow stack if needed. Parameters 18 | ** 'pre'/'pos' allow the macro to preserve a pointer into the 19 | ** stack across reallocations, doing the work only when needed. 20 | ** It also allows the running of one GC step when the stack is 21 | ** reallocated. 22 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 23 | ** at every check. 24 | */ 25 | #define luaD_checkstackaux(L,n,pre,pos) \ 26 | if (l_unlikely(L->stack_last - L->top <= (n))) \ 27 | { pre; luaD_growstack(L, n, 1); pos; } \ 28 | else { condmovestack(L,pre,pos); } 29 | 30 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 31 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 32 | 33 | 34 | 35 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 36 | #define restorestack(L,n) ((StkId)((char *)L->stack + (n))) 37 | 38 | 39 | /* macro to check stack size, preserving 'p' */ 40 | #define checkstackGCp(L,n,p) \ 41 | luaD_checkstackaux(L, n, \ 42 | ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \ 43 | luaC_checkGC(L), /* stack grow uses memory */ \ 44 | p = restorestack(L, t__)) /* 'pos' part: restore 'p' */ 45 | 46 | 47 | /* macro to check stack size and GC */ 48 | #define checkstackGC(L,fsize) \ 49 | luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0) 50 | 51 | 52 | /* type of protected functions, to be ran by 'runprotected' */ 53 | typedef void (*Pfunc) (lua_State *L, void *ud); 54 | 55 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 56 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 57 | const char *mode); 58 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line, 59 | int fTransfer, int nTransfer); 60 | LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci); 61 | LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1, int delta); 62 | LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults); 63 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 64 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 65 | LUAI_FUNC StkId luaD_tryfuncTM (lua_State *L, StkId func); 66 | LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status); 67 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 68 | ptrdiff_t oldtop, ptrdiff_t ef); 69 | LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres); 70 | LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror); 71 | LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror); 72 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 73 | LUAI_FUNC void luaD_inctop (lua_State *L); 74 | 75 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 76 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 77 | 78 | #endif 79 | 80 | -------------------------------------------------------------------------------- /src/utils/color.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2015 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "color.h" 20 | 21 | #include 22 | #include 23 | 24 | static float min3(float x, float y, float z) 25 | { 26 | if (y < x) x = y; 27 | if (z < x) x = z; 28 | return x; 29 | } 30 | 31 | static float max3(float x, float y, float z) 32 | { 33 | if (y > x) x = y; 34 | if (z > x) x = z; 35 | return x; 36 | } 37 | 38 | void hsl_to_rgb_f(const float hsl[3], float rgb[3]) 39 | { 40 | float r = 0, g = 0, b = 0, c, x, m; 41 | const float h = hsl[0] / 60, s = hsl[1], l = hsl[2]; 42 | c = (1 - fabs(2 * l - 1)) * s; 43 | x = c * (1 - fabs(fmod(h, 2) - 1)); 44 | if (h < 1) {r = c; g = x; b = 0;} 45 | else if (h < 2) {r = x; g = c; b = 0;} 46 | else if (h < 3) {r = 0; g = c; b = x;} 47 | else if (h < 4) {r = 0; g = x; b = c;} 48 | else if (h < 5) {r = x; g = 0; b = c;} 49 | else if (h < 6) {r = c; g = 0; b = x;} 50 | m = l - 0.5 * c; 51 | rgb[0] = r + m; 52 | rgb[1] = g + m; 53 | rgb[2] = b + m; 54 | } 55 | 56 | void rgb_to_hsl_f(const float rgb[3], float hsl[3]) 57 | { 58 | float h = 0, s, v, m, c, l; 59 | const float r = rgb[0], g = rgb[1], b = rgb[2]; 60 | v = max3(r, g, b); 61 | m = min3(r, g, b); 62 | l = (v + m) / 2; 63 | c = v - m; 64 | if (c == 0) { 65 | hsl[0] = 0; 66 | hsl[1] = 0; 67 | hsl[2] = l; 68 | return; 69 | } 70 | if (v == r) {h = (g - b) / c + (g < b ? 6 : 0);} 71 | else if (v == g) {h = (b - r) / c + 2;} 72 | else if (v == b) {h = (r - g) / c + 4;} 73 | h *= 60; 74 | s = (l > 0.5) ? c / (2 - v - m) : c / (v + m); 75 | hsl[0] = h; 76 | hsl[1] = s; 77 | hsl[2] = l; 78 | } 79 | 80 | void hsl_to_rgb(const uint8_t hsl[3], uint8_t rgb[3]) 81 | { 82 | // XXX: use an optimized function that use int operations. 83 | float hsl_f[3] = {hsl[0] / 255. * 360, hsl[1] / 255., hsl[2] / 255.}; 84 | float rgb_f[3]; 85 | hsl_to_rgb_f(hsl_f, rgb_f); 86 | rgb[0] = round(rgb_f[0] * 255); 87 | rgb[1] = round(rgb_f[1] * 255); 88 | rgb[2] = round(rgb_f[2] * 255); 89 | } 90 | 91 | void rgb_to_hsl(const uint8_t rgb[3], uint8_t hsl[3]) 92 | { 93 | // XXX: use an optimized function that use int operations. 94 | float rgb_f[3] = {rgb[0] / 255., rgb[1] / 255., rgb[2] / 255.}; 95 | float hsl_f[3]; 96 | rgb_to_hsl_f(rgb_f, hsl_f); 97 | hsl[0] = round(hsl_f[0] * 255 / 360); 98 | hsl[1] = round(hsl_f[1] * 255); 99 | hsl[2] = round(hsl_f[2] * 255); 100 | } 101 | -------------------------------------------------------------------------------- /src/utils/cache.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "cache.h" 20 | #include "uthash.h" 21 | 22 | #include 23 | #include 24 | 25 | typedef struct item item_t; 26 | struct item { 27 | UT_hash_handle hh; 28 | char key[256]; 29 | void *data; 30 | int cost; 31 | uint64_t last_used; 32 | int (*delfunc)(void *data); 33 | }; 34 | 35 | struct cache { 36 | item_t *items; 37 | uint64_t clock; 38 | int size; 39 | int max_size; 40 | }; 41 | 42 | cache_t *cache_create(int size) 43 | { 44 | cache_t *cache = calloc(1, sizeof(*cache)); 45 | cache->max_size = size; 46 | return cache; 47 | } 48 | 49 | static void cleanup(cache_t *cache) 50 | { 51 | item_t *item; 52 | while (cache->size >= cache->max_size) { 53 | assert(cache->items); 54 | item = cache->items; 55 | HASH_DEL(cache->items, item); 56 | assert(item != cache->items); 57 | item->delfunc(item->data); 58 | cache->size -= item->cost; 59 | free(item); 60 | } 61 | } 62 | 63 | void cache_add(cache_t *cache, const void *key, int len, void *data, 64 | int cost, int (*delfunc)(void *data)) 65 | { 66 | item_t *item = calloc(1, sizeof(*item)); 67 | assert(len <= sizeof(item->key)); 68 | memcpy(item->key, key, len); 69 | item->data = data; 70 | item->cost = cost; 71 | item->last_used = cache->clock++; 72 | item->delfunc = delfunc; 73 | HASH_ADD(hh, cache->items, key, len, item); 74 | cache->size += cost; 75 | if (cache->size >= cache->max_size) cleanup(cache); 76 | } 77 | 78 | void *cache_get(cache_t *cache, const void *key, int keylen) 79 | { 80 | item_t *item; 81 | HASH_FIND(hh, cache->items, key, keylen, item); 82 | if (!item) return NULL; 83 | item->last_used = cache->clock++; 84 | // Reinsert item on top of the hash list so that it stays sorted. 85 | HASH_DEL(cache->items, item); 86 | HASH_ADD(hh, cache->items, key, keylen, item); 87 | return item->data; 88 | } 89 | 90 | void cache_clear(cache_t *cache) 91 | { 92 | item_t *item; 93 | while ((item = cache->items)) { 94 | HASH_DEL(cache->items, item); 95 | item->delfunc(item->data); 96 | cache->size -= item->cost; 97 | free(item); 98 | } 99 | assert(cache->size == 0); 100 | } 101 | 102 | /* 103 | * Function: cache_delete 104 | * Delete a cache. 105 | */ 106 | void cache_delete(cache_t *cache) 107 | { 108 | cache_clear(cache); 109 | free(cache); 110 | } 111 | -------------------------------------------------------------------------------- /src/gui/cameras_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | void gui_cameras_panel(void) 22 | { 23 | camera_t *cam; 24 | int i = 0; 25 | bool current; 26 | float rot[3][3], e1[3], e2[3], eul[3], pitch, yaw, v; 27 | 28 | gui_group_begin(NULL); 29 | DL_FOREACH(goxel.image->cameras, cam) { 30 | current = goxel.image->active_camera == cam; 31 | if (gui_layer_item(i, -1, NULL, ¤t, cam->name, sizeof(cam->name))) { 32 | goxel.image->active_camera = cam; 33 | } 34 | i++; 35 | } 36 | gui_group_end(); 37 | gui_action_button(ACTION_img_new_camera, NULL, 0); 38 | gui_same_line(); 39 | gui_action_button(ACTION_img_del_camera, NULL, 0); 40 | gui_same_line(); 41 | gui_action_button(ACTION_img_move_camera_up, NULL, 0); 42 | gui_same_line(); 43 | gui_action_button(ACTION_img_move_camera_down, NULL, 0); 44 | 45 | if (!goxel.image->cameras) image_add_camera(goxel.image, NULL); 46 | 47 | 48 | cam = goxel.image->active_camera; 49 | gui_input_float("dist", &cam->dist, 10.0, 0, 0, NULL); 50 | 51 | /* 52 | gui_group_begin("Offset"); 53 | gui_input_float("x", &cam->ofs[0], 1.0, 0, 0, NULL); 54 | gui_input_float("y", &cam->ofs[1], 1.0, 0, 0, NULL); 55 | gui_input_float("z", &cam->ofs[2], 1.0, 0, 0, NULL); 56 | gui_group_end(); 57 | 58 | gui_quat("Rotation", cam->rot); 59 | */ 60 | gui_checkbox("Ortho", &cam->ortho, NULL); 61 | 62 | gui_group_begin("Set"); 63 | gui_action_button(ACTION_view_left, "left", 0.5); gui_same_line(); 64 | gui_action_button(ACTION_view_right, "right", 1.0); 65 | gui_action_button(ACTION_view_front, "front", 0.5); gui_same_line(); 66 | gui_action_button(ACTION_view_top, "top", 1.0); 67 | gui_action_button(ACTION_view_default, "default", 1.0); 68 | gui_group_end(); 69 | 70 | // Allow to edit euler angles (Should this be a generic widget?) 71 | gui_group_begin(NULL); 72 | mat4_to_mat3(cam->mat, rot); 73 | mat3_to_eul2(rot, EULER_ORDER_XYZ, e1, e2); 74 | if (fabs(e1[1]) < fabs(e2[1])) 75 | vec3_copy(e1, eul); 76 | else 77 | vec3_copy(e2, eul); 78 | 79 | pitch = round(eul[0] * DR2D); 80 | if (pitch < 0) pitch += 360; 81 | v = pitch; 82 | if (gui_input_float("Pitch", &v, 1, -90, 90, "%.0f")) { 83 | v = (v - pitch) * DD2R; 84 | camera_turntable(cam, 0, v); 85 | } 86 | 87 | yaw = round(eul[2] * DR2D); 88 | v = yaw; 89 | if (gui_input_float("Yaw", &v, 1, -180, 180, "%.0f")) { 90 | v = (v - yaw) * DD2R; 91 | camera_turntable(cam, v, 0); 92 | } 93 | gui_group_end(); 94 | } 95 | 96 | -------------------------------------------------------------------------------- /lib/lua-5.4.4/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_CLOSE, 44 | TM_N /* number of elements in the enum */ 45 | } TMS; 46 | 47 | 48 | /* 49 | ** Mask with 1 in all fast-access methods. A 1 in any of these bits 50 | ** in the flag of a (meta)table means the metatable does not have the 51 | ** corresponding metamethod field. (Bit 7 of the flag is used for 52 | ** 'isrealasize'.) 53 | */ 54 | #define maskflags (~(~0u << (TM_EQ + 1))) 55 | 56 | 57 | /* 58 | ** Test whether there is no tagmethod. 59 | ** (Because tagmethods use raw accesses, the result may be an "empty" nil.) 60 | */ 61 | #define notm(tm) ttisnil(tm) 62 | 63 | 64 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 65 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 66 | 67 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 68 | 69 | #define ttypename(x) luaT_typenames_[(x) + 1] 70 | 71 | LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];) 72 | 73 | 74 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 75 | 76 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 77 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 78 | TMS event); 79 | LUAI_FUNC void luaT_init (lua_State *L); 80 | 81 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 82 | const TValue *p2, const TValue *p3); 83 | LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f, 84 | const TValue *p1, const TValue *p2, StkId p3); 85 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 86 | StkId res, TMS event); 87 | LUAI_FUNC void luaT_tryconcatTM (lua_State *L); 88 | LUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1, 89 | const TValue *p2, int inv, StkId res, TMS event); 90 | LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2, 91 | int inv, StkId res, TMS event); 92 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 93 | const TValue *p2, TMS event); 94 | LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, 95 | int inv, int isfloat, TMS event); 96 | 97 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams, 98 | struct CallInfo *ci, const Proto *p); 99 | LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci, 100 | StkId where, int wanted); 101 | 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /src/gesture3d.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2020 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | int gesture3d(gesture3d_t *gest, cursor_t *curs, void *user) 22 | { 23 | bool pressed = curs->flags & CURSOR_PRESSED; 24 | int r, ret = 0; 25 | const int btns_mask = CURSOR_CTRL; 26 | 27 | gest->cursor = curs; 28 | 29 | if (gest->state == GESTURE_FAILED && !pressed) 30 | gest->state = GESTURE_POSSIBLE; 31 | 32 | if (gest->type == GESTURE_DRAG) { 33 | switch (gest->state) { 34 | case GESTURE_POSSIBLE: 35 | if ((gest->buttons & btns_mask) != (curs->flags & btns_mask)) 36 | break; 37 | if (curs->snaped && pressed) gest->state = GESTURE_BEGIN; 38 | break; 39 | case GESTURE_BEGIN: 40 | case GESTURE_UPDATE: 41 | gest->state = GESTURE_UPDATE; 42 | if (!pressed) gest->state = GESTURE_END; 43 | break; 44 | } 45 | } 46 | 47 | if (gest->type == GESTURE_CLICK) { 48 | switch (gest->state) { 49 | case GESTURE_POSSIBLE: 50 | if (curs->snaped && !pressed) gest->state = GESTURE_RECOGNISED; 51 | break; 52 | case GESTURE_RECOGNISED: 53 | if ((gest->buttons & btns_mask) != (curs->flags & btns_mask)) 54 | break; 55 | if (curs->snaped && pressed) gest->state = GESTURE_TRIGGERED; 56 | break; 57 | } 58 | } 59 | 60 | if (!DEFINED(GOXEL_MOBILE) && gest->type == GESTURE_HOVER) { 61 | switch (gest->state) { 62 | case GESTURE_POSSIBLE: 63 | if ((gest->buttons & btns_mask) != (curs->flags & btns_mask)) 64 | break; 65 | if (curs->snaped && !pressed && !(curs->flags & CURSOR_OUT)) 66 | gest->state = GESTURE_BEGIN; 67 | break; 68 | case GESTURE_BEGIN: 69 | case GESTURE_UPDATE: 70 | gest->state = GESTURE_UPDATE; 71 | if ((gest->buttons & btns_mask) != (curs->flags & btns_mask)) 72 | gest->state = GESTURE_END; 73 | if (pressed) gest->state = GESTURE_END; 74 | if (curs->flags & CURSOR_OUT) gest->state = GESTURE_END; 75 | break; 76 | } 77 | } 78 | 79 | if ( gest->state == GESTURE_BEGIN || 80 | gest->state == GESTURE_UPDATE || 81 | gest->state == GESTURE_END || 82 | gest->state == GESTURE_TRIGGERED) 83 | { 84 | r = gest->callback(gest, user); 85 | if (r == GESTURE_FAILED) { 86 | gest->state = GESTURE_FAILED; 87 | ret = 0; 88 | } else { 89 | ret = gest->state; 90 | } 91 | } 92 | if (gest->state == GESTURE_END || gest->state == GESTURE_TRIGGERED) 93 | gest->state = GESTURE_POSSIBLE; 94 | 95 | return ret; 96 | } 97 | -------------------------------------------------------------------------------- /src/tools/laser.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2017 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | 21 | 22 | typedef struct { 23 | tool_t tool; 24 | float box[4][4]; 25 | 26 | struct { 27 | gesture3d_t drag; 28 | gesture3d_t hover; 29 | } gestures; 30 | 31 | } tool_laser_t; 32 | 33 | static int on_drag(gesture3d_t *gest, void *user) 34 | { 35 | tool_laser_t *laser = (tool_laser_t*)USER_GET(user, 0); 36 | painter_t painter = *(painter_t*)USER_GET(user, 1); 37 | 38 | mesh_t *mesh = goxel.image->active_layer->mesh; 39 | painter.mode = MODE_SUB_CLAMP; 40 | painter.shape = &shape_cylinder; 41 | vec4_set(painter.color, 255, 255, 255, 255); 42 | 43 | if (gest->state == GESTURE_BEGIN) 44 | image_history_push(goxel.image); 45 | 46 | mesh_op(mesh, &painter, laser->box); 47 | return 0; 48 | } 49 | 50 | static int iter(tool_t *tool, const painter_t *painter, 51 | const float viewport[4]) 52 | { 53 | tool_laser_t *laser = (tool_laser_t*)tool; 54 | cursor_t *curs = &goxel.cursor; 55 | curs->snap_mask = SNAP_CAMERA; 56 | curs->snap_offset = 0; 57 | float v[4]; 58 | float view_mat_inv[4][4] = {}; 59 | camera_t *camera = goxel.image->active_camera; 60 | 61 | if (!laser->gestures.drag.type) { 62 | laser->gestures.drag = (gesture3d_t) { 63 | .type = GESTURE_DRAG, 64 | .callback = on_drag, 65 | }; 66 | } 67 | 68 | if (curs->snaped & SNAP_CAMERA) { 69 | // Create the tool box from the camera along the visible ray. 70 | mat4_set_identity(laser->box); 71 | mat4_invert(camera->view_mat, view_mat_inv); 72 | mat4_mul_vec4(view_mat_inv, VEC(1, 0, 0, 0), v); 73 | vec3_copy(v, laser->box[0]); 74 | mat4_mul_vec4(view_mat_inv, VEC(0, 1, 0, 0), v); 75 | vec3_copy(v, laser->box[1]); 76 | mat4_mul_vec4(view_mat_inv, VEC(0, 0, 1, 0), v); 77 | vec3_copy(v, laser->box[2]); 78 | vec3_neg(curs->normal, laser->box[2]); 79 | vec3_copy(curs->pos, laser->box[3]); 80 | // Just a large value for the size of the laser box. 81 | mat4_itranslate(laser->box, 0, 0, -1024); 82 | mat4_iscale(laser->box, goxel.tool_radius, goxel.tool_radius, 1024); 83 | render_box(&goxel.rend, laser->box, NULL, EFFECT_WIREFRAME); 84 | } 85 | 86 | gesture3d(&laser->gestures.drag, curs, USER_PASS(laser, painter)); 87 | 88 | return tool->state; 89 | } 90 | 91 | static int gui(tool_t *tool) 92 | { 93 | tool_gui_radius(); 94 | tool_gui_smoothness(); 95 | tool_gui_symmetry(); 96 | return 0; 97 | } 98 | 99 | TOOL_REGISTER(TOOL_LASER, laser, tool_laser_t, 100 | .name = "Laser", 101 | .iter_fn = iter, 102 | .gui_fn = gui, 103 | .flags = TOOL_REQUIRE_CAN_EDIT, 104 | .default_shortcut = "L", 105 | ) 106 | -------------------------------------------------------------------------------- /src/model3d.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2019 Guillaume Chereau 4 | * 5 | * Goxel is free software: you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. 9 | 10 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 | * details. 14 | 15 | * You should have received a copy of the GNU General Public License along with 16 | * goxel. If not, see . 17 | */ 18 | 19 | /* 20 | * Section: Model3d 21 | * 22 | * Functions to render 3d vertex models, like cube, plane, etc. 23 | * not to be confused with .m3d format 24 | */ 25 | 26 | #ifndef MODEL3D_H 27 | #define MODEL3D_H 28 | 29 | #include "utils/texture.h" 30 | 31 | /* 32 | * Type: model_vertex_t 33 | * Container for a single vertex shader data. 34 | */ 35 | typedef struct { 36 | float pos[3] __attribute__((aligned(4))); 37 | float normal[3] __attribute__((aligned(4))); 38 | uint8_t color[4] __attribute__((aligned(4))); 39 | float uv[2] __attribute__((aligned(4))); 40 | } model_vertex_t; 41 | 42 | /* 43 | * Type: model3d_t 44 | * Define a 3d model. 45 | */ 46 | typedef struct { 47 | int nb_vertices; 48 | model_vertex_t *vertices; 49 | bool solid; 50 | bool cull; 51 | 52 | // Rendering buffers. 53 | // XXX: move this into the renderer, like for block_t 54 | uint32_t vertex_buffer; 55 | int nb_lines; 56 | bool dirty; 57 | } model3d_t; 58 | 59 | void model3d_release_graphics(void); 60 | 61 | /* 62 | * Function: model3d_delete 63 | * Delete a 3d model 64 | */ 65 | void model3d_delete(model3d_t *model); 66 | 67 | /* 68 | * Function: model3d_cube 69 | * Create a 3d cube from (0, 0, 0) to (1, 1, 1) 70 | */ 71 | model3d_t *model3d_cube(void); 72 | 73 | /* 74 | * Function: model3d_wire_cube 75 | * Create a 3d wire cube from (0, 0, 0) to (1, 1, 1) 76 | */ 77 | model3d_t *model3d_wire_cube(void); 78 | 79 | /* 80 | * Function: model3d_sphere 81 | * Create a sphere of radius 1, centered at (0, 0). 82 | */ 83 | model3d_t *model3d_sphere(int slices, int stacks); 84 | 85 | /* 86 | * Function: model3d_grid 87 | * Create a grid plane. 88 | */ 89 | model3d_t *model3d_grid(int nx, int ny); 90 | 91 | /* 92 | * Function: model3d_line 93 | * Create a line from (-0.5, 0, 0) to (+0.5, 0, 0). 94 | */ 95 | model3d_t *model3d_line(void); 96 | 97 | /* 98 | * Function: model3d_line 99 | * Create a 2d rect on xy plane, of size 1x1 centered on the origin. 100 | */ 101 | model3d_t *model3d_rect(void); 102 | 103 | /* 104 | * Function: model3d_line 105 | * Create a 2d rect on xy plane, of size 1x1 centered on the origin. 106 | */ 107 | model3d_t *model3d_wire_rect(void); 108 | 109 | /* 110 | * Function: model3d_render 111 | * Render a 3d model using OpenGL calls. 112 | */ 113 | void model3d_render(model3d_t *model3d, 114 | const float model[4][4], 115 | const float view[4][4], 116 | const float proj[4][4], 117 | const uint8_t color[4], 118 | const texture_t *tex, 119 | const float light[3], 120 | const float clip_box[4][4], 121 | int effects); 122 | 123 | #endif // MODEL3D_H 124 | --------------------------------------------------------------------------------