├── .clang-format ├── .clang-tidy ├── .editorconfig ├── .gitattributes ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── AUTHORS ├── CHANGELOG.md ├── CONTRIBUTING.md ├── COPYING ├── INTERNALS.md ├── Makefile ├── README.md ├── SConstruct ├── data ├── fonts │ ├── DejaVuSans.ttf │ └── goxel-font.ttf ├── icons │ ├── icon128.png │ ├── icon16.png │ ├── icon24.png │ ├── icon256.png │ ├── icon32.png │ ├── icon48.png │ └── icon64.png ├── images │ └── icons.png ├── locale │ └── fr.mo ├── other │ └── povray_template.pov ├── palettes │ ├── Blues.gpl │ ├── Caramel.gpl │ ├── Gold.gpl │ ├── Gray.gpl │ ├── Grays.gpl │ ├── Greens.gpl │ ├── Hilite.gpl │ ├── Khaki.gpl │ ├── MagicaVoxel.gpl │ ├── Minetest.gpl │ ├── Pastels.gpl │ ├── Pico8.gpl │ ├── Plasma.gpl │ ├── Reds.gpl │ ├── Royal.gpl │ ├── Tango-Palette.gpl │ ├── Ubuntu.gpl │ ├── db16.gpl │ ├── db32.gpl │ ├── echo-palette.gpl │ ├── inkscape.gpl │ └── webhex.gpl ├── progs │ ├── cherry.goxcf │ ├── city.goxcf │ ├── intro.goxcf │ ├── planet.goxcf │ ├── test.goxcf │ ├── test2.goxcf │ ├── test3.goxcf │ ├── tree-big.goxcf │ └── tree-small.goxcf ├── scripts │ └── test.js ├── shaders │ ├── background.glsl │ ├── model3d.glsl │ ├── pos_data.glsl │ ├── shadow_map.glsl │ └── volume.glsl ├── sounds │ ├── build.wav │ └── click.wav └── themes │ ├── dark.ini │ └── light.ini ├── doc └── cla │ ├── ccla-1.0.md │ ├── ccla-1.0.pdf │ ├── icla-1.0.md │ ├── icla-1.0.pdf │ ├── individual │ ├── black-cat.md │ ├── calebh.md │ ├── danieldownes.md │ ├── dsunshi.md │ ├── latorredev.md │ ├── madd-games.md │ ├── mailaender.md │ ├── newage99.md │ ├── ntfwc.md │ ├── podsvirov.md │ ├── randomairborne.md │ ├── ravencgg.md │ ├── sariug.md │ ├── template.md │ └── vvbalashoff.md │ └── sign-cla.md ├── ext_src ├── cgltf │ ├── cgltf.h │ └── cgltf_write.h ├── glew │ ├── GL │ │ ├── glew.h │ │ └── wglew.h │ └── glew.c ├── imgui │ ├── ImGuizmo.cpp │ ├── ImGuizmo.h │ ├── imconfig.h │ ├── imgui.cpp │ ├── imgui.h │ ├── imgui_draw.cpp │ ├── imgui_internal.h │ ├── imgui_tables.cpp │ ├── imgui_widgets.cpp │ ├── imstb_rectpack.h │ ├── imstb_textedit.h │ └── imstb_truetype.h ├── inih │ ├── ini.c │ └── ini.h ├── json │ ├── json-builder.c │ ├── json-builder.h │ ├── json.c │ └── json.h ├── meshoptimizer │ ├── allocator.cpp │ ├── clusterizer.cpp │ ├── indexcodec.cpp │ ├── indexgenerator.cpp │ ├── meshoptimizer.h │ ├── overdrawanalyzer.cpp │ ├── overdrawoptimizer.cpp │ ├── simplifier.cpp │ ├── spatialorder.cpp │ ├── stripifier.cpp │ ├── vcacheanalyzer.cpp │ ├── vcacheoptimizer.cpp │ ├── vertexcodec.cpp │ ├── vertexfilter.cpp │ ├── vfetchanalyzer.cpp │ └── vfetchoptimizer.cpp ├── nfd │ ├── nfd.h │ ├── nfd_cocoa.m │ ├── nfd_glfw3.h │ ├── nfd_gtk.cpp │ ├── nfd_portal.cpp │ └── nfd_win.cpp ├── quickjs │ ├── cutils.c │ ├── cutils.h │ ├── hello.c │ ├── libbf.c │ ├── libbf.h │ ├── libregexp-opcode.h │ ├── libregexp.c │ ├── libregexp.h │ ├── libunicode-table.h │ ├── libunicode.c │ ├── libunicode.h │ ├── list.h │ ├── quickjs-atom.h │ ├── quickjs-libc.c │ ├── quickjs-libc.h │ ├── quickjs-opcode.h │ ├── quickjs.c │ ├── quickjs.h │ └── repl.c ├── stb │ ├── stb_ds.h │ ├── stb_image.h │ ├── stb_image_resize.h │ ├── stb_image_write.h │ ├── stb_rect_pack.h │ ├── stb_textedit.h │ └── stb_truetype.h ├── tinyobjloader │ └── tinyobj_loader_c.h ├── uthash │ ├── utarray.h │ ├── uthash.h │ └── utlist.h ├── voxelizer │ └── voxelizer.h ├── xxhash │ ├── xxhash.c │ └── xxhash.h └── yocto │ ├── yocto_bvh.cpp │ ├── yocto_bvh.h │ ├── yocto_color.h │ ├── yocto_geometry.h │ ├── yocto_image.cpp │ ├── yocto_image.h │ ├── yocto_math.h │ ├── yocto_modelio.cpp │ ├── yocto_modelio.h │ ├── yocto_noise.h │ ├── yocto_parallel.h │ ├── yocto_sampling.h │ ├── yocto_scene.cpp │ ├── yocto_scene.h │ ├── yocto_shading.h │ ├── yocto_shape.cpp │ ├── yocto_shape.h │ ├── yocto_trace.cpp │ └── yocto_trace.h ├── flake.nix ├── icon.png ├── osx └── goxel │ ├── .gitignore │ ├── goxel.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── goxel │ ├── AppDelegate.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ ├── 1024.png │ │ ├── 128.png │ │ ├── 16.png │ │ ├── 256.png │ │ ├── 32.png │ │ ├── 512.png │ │ ├── 64.png │ │ └── Contents.json │ ├── Base.lproj │ └── MainMenu.xib │ ├── Info.plist │ ├── goxel-Bridging-Header.h │ ├── goxel.entitlements │ └── goxel.pch ├── po └── fr.po ├── screenshots ├── screenshot-castle.png ├── screenshot-dicom.png ├── screenshot-plane.png └── screenshot-procedural-city.png ├── snap ├── gui │ ├── goxel.desktop │ └── io.github.guillaumechereau.Goxel.metainfo.xml └── snapcraft.yaml ├── src ├── action.c ├── action.h ├── actions.h ├── assets.c ├── assets.h ├── assets │ ├── fonts.inl │ ├── icons.inl │ ├── images.inl │ ├── locale.inl │ ├── other.inl │ ├── palettes.inl │ ├── progs.inl │ ├── scripts.inl │ ├── shaders.inl │ ├── sounds.inl │ └── themes.inl ├── block_def.h ├── camera.c ├── camera.h ├── config.h ├── file_format.c ├── file_format.h ├── filters.c ├── filters.h ├── filters │ ├── colors.c │ ├── mirror.c │ └── wrap.c ├── formats │ ├── gltf.c │ ├── gox.c │ ├── luanti.c │ ├── png.c │ ├── png_slices.c │ ├── povray.c │ ├── qubicle.c │ ├── qubicle2.c │ ├── txt.c │ ├── vox.c │ ├── voxlap.c │ ├── vxl.c │ └── wavefront.c ├── gesture.c ├── gesture.h ├── gesture3d.c ├── gesture3d.h ├── gizmos.c ├── gizmos.h ├── glew-mx.h ├── goxel.c ├── goxel.h ├── gui.cpp ├── gui.h ├── gui │ ├── about.c │ ├── app.c │ ├── cameras_panel.c │ ├── debug_panel.c │ ├── edit_panel.c │ ├── export_panel.c │ ├── image_panel.c │ ├── layers_panel.c │ ├── light_panel.c │ ├── material_panel.c │ ├── menu.c │ ├── palette_panel.c │ ├── quit.c │ ├── render_panel.c │ ├── settings.c │ ├── snap_panel.c │ ├── symmetry_panel.c │ ├── tools_panel.c │ ├── topbar.c │ └── view_panel.c ├── i18n.c ├── i18n.h ├── image.c ├── image.h ├── imgui.cpp ├── inputs.h ├── layer.c ├── layer.h ├── log.h ├── main.c ├── marchingcube.c ├── material.c ├── material.h ├── meshoptimizer.cpp ├── model3d.c ├── model3d.h ├── palette.c ├── palette.h ├── pathtracer.cpp ├── pathtracer.h ├── quantization.c ├── quickjs.c ├── render.c ├── render.h ├── script.c ├── script.h ├── shader_cache.c ├── shader_cache.h ├── shape.c ├── shape.h ├── system.c ├── system.h ├── tests.c ├── theme.c ├── theme.h ├── tools.c ├── tools.h ├── tools │ ├── brush.c │ ├── color_picker.c │ ├── extrude.c │ ├── fuzzy_select.c │ ├── laser.c │ ├── line.c │ ├── move.c │ ├── plane.c │ ├── rect_select.c │ ├── selection.c │ └── shape.c ├── utils.c ├── utils │ ├── b64.c │ ├── b64.h │ ├── box.c │ ├── box.h │ ├── cache.c │ ├── cache.h │ ├── color.c │ ├── color.h │ ├── geometry.c │ ├── geometry.h │ ├── gl.c │ ├── gl.h │ ├── img.c │ ├── img.h │ ├── ini.c │ ├── ini.h │ ├── json.c │ ├── json.h │ ├── mo_reader.c │ ├── mo_reader.h │ ├── mustache.c │ ├── mustache.h │ ├── path.c │ ├── path.h │ ├── plane.h │ ├── sound.c │ ├── sound.h │ ├── sound_openal.inl │ ├── texture.c │ ├── texture.h │ ├── vec.c │ └── vec.h ├── volume.c ├── volume.h ├── volume_to_vertices.c ├── volume_utils.c ├── volume_utils.h ├── xxhash.c └── yocto.cpp ├── svg ├── glyphs │ ├── mouse_lmb.svg │ ├── mouse_mmb.svg │ └── mouse_rmb.svg └── icons.svg └── tools ├── create_assets.py ├── create_font.py ├── create_icons.py └── update-i18n.py /.clang-format: -------------------------------------------------------------------------------- 1 | # Style for Goxel. 2 | # 3 | # This is still a work in progress, and shouldn't be used systematically yet. 4 | # Unfortunately I couldn't make it work with the style I like, so for the 5 | # moment I disable all alignments. 6 | 7 | BasedOnStyle: LLVM 8 | 9 | AllowShortFunctionsOnASingleLine: Empty 10 | AllowShortIfStatementsOnASingleLine: WithoutElse 11 | 12 | Cpp11BracedListStyle: false 13 | 14 | SpacesInContainerLiterals: false 15 | 16 | ColumnLimit: 79 17 | PenaltyExcessCharacter: 1000 18 | 19 | # Never use tabs for indentation. 20 | UseTab: Never 21 | TabWidth: 4 22 | IndentWidth: 4 23 | 24 | ContinuationIndentWidth: 8 25 | BracedInitializerIndentWidth: 4 26 | 27 | BreakBeforeBraces: Custom 28 | BraceWrapping: 29 | AfterClass: false 30 | AfterControlStatement: MultiLine 31 | AfterEnum: false 32 | AfterFunction: true 33 | AfterNamespace: false 34 | AfterStruct: false 35 | AfterUnion: false 36 | BeforeCatch: true 37 | BeforeElse: true 38 | IndentBraces: false 39 | 40 | BinPackParameters: false 41 | AllowAllArgumentsOnNextLine: true 42 | 43 | SortIncludes: true 44 | 45 | PenaltyReturnTypeOnItsOwnLine: 10000 46 | PenaltyBreakAssignment: 100 47 | PenaltyIndentedWhitespace: 2 48 | 49 | ForEachMacros: 50 | - DL_FOREACH 51 | - DL_FOREACH 52 | - DL_FOREACH2 53 | - DL_FOREACH_SAFE 54 | - DL_FOREACH_SAFE2 55 | - DL_FOREACH_REVERSE 56 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | 2 | Checks: > 3 | readability-*, 4 | -readability-identifier-length, 5 | -readability-braces-around-statements, 6 | -readability-magic-numbers, 7 | -readability-isolate-declaration, 8 | -readability-function-cognitive-complexity, 9 | -readability-uppercase-literal-suffix, 10 | -readability-avoid-unconditional-preprocessor-if, 11 | -readability-suspicious-call-argument, 12 | -readability-math-missing-parentheses, 13 | 14 | bugprone-*, 15 | -bugprone-narrowing-conversions, 16 | -bugprone-easily-swappable-parameters, 17 | -bugprone-implicit-widening-of-multiplication-result, 18 | -bugprone-suspicious-include, 19 | -bugprone-sizeof-expression, 20 | -bugprone-casting-through-void, 21 | -bugprone-suspicious-realloc-usage, 22 | -bugprone-multi-level-implicit-pointer-conversion, 23 | 24 | modernize-*, 25 | -modernize-macro-to-enum, 26 | 27 | clang-analyzer-*, 28 | llvm-*, 29 | portability-*, 30 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # C/C++ 2 | [*.{c,cpp,h,inl,glsl}] 3 | charset = utf-8 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | indent_style = space 7 | indent_size = 4 8 | max_line_length = 79 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | src/assets/sounds.inl binary 2 | src/assets/samples.inl binary 3 | src/assets/images.inl binary 4 | src/assets/icons.inl binary 5 | src/assets/fonts.inl binary 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.swp 3 | *~ 4 | *.obj 5 | .sconsign.dblite 6 | /.sconf_temp 7 | /goxel 8 | /imgui.ini 9 | /config.log 10 | .DS_Store 11 | xcuserdata/ 12 | /todo 13 | /.vimrc 14 | /compile_commands.json 15 | /TAGS 16 | /.cache 17 | -------------------------------------------------------------------------------- /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 | Daniel Downes (https://github.com/danieldownes) 10 | 11 | Goxel uses the font DejaVu (GPL-2+ licence): 12 | Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. 13 | Bitstream Vera is a trademark of Bitstream, Inc. 14 | DejaVu changes are in public domain. 15 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Goxel 2 | 3 | Please read this file first before making a pull request to Goxel. 4 | 5 | 6 | ## CLA 7 | 8 | In your first pull request, you must add your name in a CLA file in 9 | 'doc/cla/individual'. This gives me the right to release special version of 10 | Goxel under a commercial licence. It doesn't change the license of the current 11 | code. See: 12 | https://github.com/guillaumechereau/goxel/blob/master/doc/cla/sign-cla.md 13 | For more information about that. 14 | 15 | 16 | ## Coding style 17 | 18 | Try to follow the code style I used for Goxel, as I am unlikely to merge a pull 19 | request that doesn't. The coding style is almost the one used by the linux 20 | kernel, but using four spaces for indentation, and I also accept typedef. When 21 | in doubt, just look at other part of the code. The most important rules are: 22 | 23 | - Use 4 spaces indentations. No tabs characters anywhere in the code. 24 | 25 | - 80 columns max line width. 26 | 27 | - No trailing white space. 28 | 29 | - function and variable names all in lowercase, with underscore to separate 30 | parts if needed: 31 | 32 | int nb_block; // Good 33 | int nbBlock; // Bad 34 | 35 | - K&R style braces (opening brace on same line): 36 | 37 | if (something) { 38 | ... 39 | } else { 40 | ... 41 | } 42 | 43 | - Except for functions, where we put the opening brace on the next line: 44 | 45 | int my_func(void) 46 | { 47 | ... 48 | return 0; 49 | } 50 | 51 | - I also accept exceptions to the K&R braces for multi line conditions 52 | (but that should be avoided if possible by making the condition shorter): 53 | 54 | if (a_very_long_condition || 55 | that_uses_several_lines) 56 | { 57 | ... 58 | } 59 | 60 | - No space between function and argument parenthesis: 61 | 62 | func(10, 20) // Good 63 | func (10, 20) // BAD! 64 | 65 | 66 | - One space after keywords, except `sizeof`: 67 | 68 | if (something) // Good 69 | if(something) // BAD 70 | 71 | - One space around binary operators, no space after unary operators and 72 | before postfix operators. 73 | 74 | x = 10 + 20 * 3; // Good 75 | x = 10+20*3; // BAD 76 | x++; // Good 77 | x ++; // BAD 78 | y = &x; // Good 79 | y = & x; // VERY BAD 80 | 81 | - Use 'C' style variable declarations: 82 | 83 | int *x; // Good 84 | int* x; // BAD 85 | 86 | - Put all the variable declarations on top of the function, so that we can 87 | see them all at the same place. 88 | 89 | 90 | ## Git commit style 91 | 92 | - Keep the summary line under about 50 characters. 93 | 94 | - The rest of the commit message separated by a blank line. Wrap lines at 95 | 72 characters. 96 | 97 | - Try to separate the commits into smaller logical parts, so it is easier to 98 | review them independently. 99 | -------------------------------------------------------------------------------- /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 volume (`volume_t`), the volumes also use a copy 11 | on write mechanism to make copy basically free. 12 | 13 | An `image_t` contains several `layer_t`, which is basically a volume 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 volume is `volume_op`, we give it a 19 | `painter_t` 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 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL = bash 2 | ifeq ($(OS),Linux) 3 | JOBS := "-j $(shell nproc)" 4 | else 5 | JOBS := "-j $(shell getconf _NPROCESSORS_ONLN)" 6 | endif 7 | 8 | .ONESHELL: 9 | 10 | all: .FORCE 11 | scons $(JOBS) 12 | 13 | release: 14 | scons $(JOBS) mode=release 15 | 16 | profile: 17 | scons $(JOBS) mode=profile 18 | 19 | run: 20 | ./goxel 21 | 22 | clean: .FORCE 23 | scons -c 24 | 25 | analyze: 26 | scan-build scons mode=analyze 27 | 28 | # For the moment only apply the format to uncommited changes. 29 | format: .FORCE 30 | git clang-format -f 31 | 32 | 33 | # Generate an AppImage. Used by github CI. 34 | appimage: .FORCE 35 | scons mode=release nfd_backend=portal 36 | rm -rf AppDir 37 | mkdir AppDir 38 | DESTDIR=AppDir PREFIX=/usr make install 39 | curl https://github.com/linuxdeploy/linuxdeploy/releases/download/1-alpha-20231206-1/linuxdeploy-x86_64.AppImage \ 40 | --output linuxdeploy.AppImage -L -f 41 | chmod +x linuxdeploy.AppImage 42 | ./linuxdeploy.AppImage --output=appimage --appdir=AppDir 43 | 44 | # Targets to install/uninstall goxel and its data files on unix system. 45 | PREFIX ?= /usr/local 46 | 47 | .PHONY: install 48 | install: 49 | install -Dm755 goxel $(DESTDIR)$(PREFIX)/bin/goxel 50 | for size in 16 24 32 48 64 128 256; do 51 | install -Dm644 data/icons/icon$${size}.png \ 52 | $$(printf '%s%s' $(DESTDIR)$(PREFIX)/share/icons/hicolor/ \ 53 | $${size}x$${size}/apps/goxel.png) 54 | done 55 | install -Dm644 snap/gui/goxel.desktop \ 56 | $(DESTDIR)$(PREFIX)/share/applications/goxel.desktop 57 | install -Dm644 \ 58 | snap/gui/io.github.guillaumechereau.Goxel.metainfo.xml \ 59 | $$(printf '%s%s' $(DESTDIR)$(PREFIX)/share/metainfo/ \ 60 | io.github.guillaumechereau.Goxel.metainfo.xml) 61 | 62 | .PHONY: uninstall 63 | uninstall: 64 | rm -f $(DESTDIR)$(PREFIX)/bin/goxel 65 | for size in 16 24 32 48 64 128 256; do \ 66 | rm -f $$(printf '%s%s' $(DESTDIR)$(PREFIX)/share/icons/hicolor/ \ 67 | $${size}x$${size}/apps/goxel.png) 68 | done 69 | rm -f $(DESTDIR)$(PREFIX)/share/applications/goxel.desktop 70 | rm -f $$(printf '%s%s' $(DESTDIR)$(PREFIX)/share/metainfo/ \ 71 | io.github.guillaumechereau.Goxel.metainfo.xml) 72 | 73 | .PHONY: all 74 | 75 | .FORCE: 76 | -------------------------------------------------------------------------------- /data/fonts/DejaVuSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/fonts/DejaVuSans.ttf -------------------------------------------------------------------------------- /data/fonts/goxel-font.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/fonts/goxel-font.ttf -------------------------------------------------------------------------------- /data/icons/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/icons/icon128.png -------------------------------------------------------------------------------- /data/icons/icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/icons/icon16.png -------------------------------------------------------------------------------- /data/icons/icon24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/icons/icon24.png -------------------------------------------------------------------------------- /data/icons/icon256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/icons/icon256.png -------------------------------------------------------------------------------- /data/icons/icon32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/icons/icon32.png -------------------------------------------------------------------------------- /data/icons/icon48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/icons/icon48.png -------------------------------------------------------------------------------- /data/icons/icon64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/icons/icon64.png -------------------------------------------------------------------------------- /data/images/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/images/icons.png -------------------------------------------------------------------------------- /data/locale/fr.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/locale/fr.mo -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/palettes/Pico8.gpl: -------------------------------------------------------------------------------- 1 | GIMP Palette 2 | Name: Pico8 3 | Columns: 8 4 | # 5 | 0 0 0 #000000 6 | 29 43 83 #1D2B53 7 | 126 37 83 #7E2553 8 | 0 135 81 #008751 9 | 171 82 54 #AB5236 10 | 95 87 79 #5F574F 11 | 194 195 199 #C2C3C7 12 | 255 241 232 #FFF1E8 13 | 255 0 77 #FF004D 14 | 255 163 0 #FFA300 15 | 255 236 39 #FFEC27 16 | 0 228 54 #00E436 17 | 41 173 255 #29ADFF 18 | 131 118 156 #83769C 19 | 255 119 168 #FF77A8 20 | 255 204 170 #FFCCAA -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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 | } -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/scripts/test.js: -------------------------------------------------------------------------------- 1 | 2 | import * as std from 'std' 3 | 4 | /* 5 | * Example of file format support in js: 6 | */ 7 | /* 8 | goxel.registerFormat({ 9 | name: 'Test', 10 | exts: ['*.test'], 11 | exts_desc: 'test', 12 | import: function(img, path) { 13 | let layer = img.addLayer() 14 | let volume = layer.volume 15 | volume.setAt([0, 0, 0], [255, 0, 0, 255]) 16 | }, 17 | export: function(img, path) { 18 | try { 19 | console.log(`Save ${path}`) 20 | let out = std.open(path, 'w') 21 | let volume = img.getLayersVolume() 22 | volume.iter(function(p, c) { 23 | out.printf(`${p.x} ${p.y}, ${p.z} => ${c.r}, ${c.g}, ${c.b}\n`) 24 | }) 25 | out.close() 26 | console.log('done') 27 | } catch(e) { 28 | console.log('error', e) 29 | } 30 | }, 31 | }) 32 | */ 33 | 34 | function getRandomColor() { 35 | return [ 36 | Math.floor(Math.random() * 256), 37 | Math.floor(Math.random() * 256), 38 | Math.floor(Math.random() * 256), 39 | 255 40 | ] 41 | } 42 | 43 | goxel.registerScript({ 44 | name: 'FillRandom', 45 | description: 'Fill selection with random voxels', 46 | onExecute: function() { 47 | let box = goxel.image.selectionBox 48 | let volume = goxel.image.activeLayer.volume 49 | box.iterVoxels(function(pos) { 50 | volume.setAt(pos, getRandomColor()) 51 | }) 52 | } 53 | }) 54 | 55 | goxel.registerScript({ 56 | name: 'Dilate', 57 | onExecute: function() { 58 | let volume = goxel.image.activeLayer.volume 59 | volume.copy().iter(function(pos, color) { 60 | for (let z = -1; z < 2; z++) { 61 | for (let y = -1; y < 2; y++) { 62 | for (let x = -1; x < 2; x++) { 63 | volume.setAt([pos.x + x, pos.y + y, pos.z + z], color) 64 | } 65 | } 66 | } 67 | }) 68 | } 69 | }) 70 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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_tile_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_tile_id; 29 | gl_FragColor.ba = v_pos_data; 30 | } 31 | /************************************************************************/ 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /data/sounds/build.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/sounds/build.wav -------------------------------------------------------------------------------- /data/sounds/click.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/data/sounds/click.wav -------------------------------------------------------------------------------- /data/themes/dark.ini: -------------------------------------------------------------------------------- 1 | [theme] 2 | name=dark 3 | 4 | [base] 5 | background=#303030FF 6 | inner=#545454FF 7 | item=#1975BEFF 8 | selected=#1975BEFF 9 | text=#CCCCCCFF 10 | text_selected=#FFFFFFFF 11 | 12 | [section] 13 | background=#3D3D3DFF 14 | 15 | [widget] 16 | 17 | [menu] 18 | background=#181818FF 19 | 20 | [icon] 21 | inner=#00000000 22 | item=#FFFFFFFF 23 | 24 | [icon_edit] 25 | item=#CCCCCCFF 26 | 27 | [icon_view] 28 | item=#E19658FF 29 | 30 | [icon_render] 31 | item=#74A2FFFF 32 | 33 | [icon_other] 34 | item=#CC6670FF 35 | -------------------------------------------------------------------------------- /data/themes/light.ini: -------------------------------------------------------------------------------- 1 | [theme] 2 | name=light 3 | 4 | [base] 5 | background=#B3B3B3FF 6 | inner=#D4D4D4FF 7 | item=#557FC1FF 8 | selected=#557FC1FF 9 | text=#1D1D1DFF 10 | text_selected=#FFFFFFFF 11 | 12 | [window] 13 | background=#B3B3B3FF 14 | 15 | [section] 16 | background=#CCCCCCFF 17 | 18 | [widget] 19 | 20 | [icon] 21 | inner=#00000000 22 | item=#000000FF 23 | 24 | [icon_edit] 25 | item=#575757FF 26 | 27 | [icon_view] 28 | item=#B03D00FF 29 | 30 | [icon_render] 31 | item=#5149EFFF 32 | 33 | [icon_other] 34 | item=#DF4F4DFF 35 | -------------------------------------------------------------------------------- /doc/cla/ccla-1.0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/doc/cla/ccla-1.0.pdf -------------------------------------------------------------------------------- /doc/cla/icla-1.0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/doc/cla/icla-1.0.pdf -------------------------------------------------------------------------------- /doc/cla/individual/black-cat.md: -------------------------------------------------------------------------------- 1 | Russia, 2020-01-24 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | Artem Buryachenko iblackcatw@gmail.com https://github.com/Black-Cat 12 | -------------------------------------------------------------------------------- /doc/cla/individual/calebh.md: -------------------------------------------------------------------------------- 1 | United States, 2024-12-22 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | Caleb Helbling caleb.helbling@yahoo.com https://github.com/calebh 12 | -------------------------------------------------------------------------------- /doc/cla/individual/danieldownes.md: -------------------------------------------------------------------------------- 1 | Japan, 2025-05-20 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | Daniel Downes dd@danieldownes.co.uk https://github.com/danieldownes 12 | -------------------------------------------------------------------------------- /doc/cla/individual/dsunshi.md: -------------------------------------------------------------------------------- 1 | United States, 2025-05-22 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | David Sunshine david@sunshines.org https://github.com/dsunshi 12 | -------------------------------------------------------------------------------- /doc/cla/individual/latorredev.md: -------------------------------------------------------------------------------- 1 | Colombia, 2022-08-28 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | David Latorre david@latorredev.com https://github.com/latorredev -------------------------------------------------------------------------------- /doc/cla/individual/madd-games.md: -------------------------------------------------------------------------------- 1 | UK, 2024-03-18 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | Mariusz Pilipczuk projekt.darma@gmail.com https://github.com/madd-games -------------------------------------------------------------------------------- /doc/cla/individual/mailaender.md: -------------------------------------------------------------------------------- 1 | Germany, 2021-02-21 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | Matthias Mailänder matthias@mailaender.name https://github.com/Mailaender 12 | -------------------------------------------------------------------------------- /doc/cla/individual/newage99.md: -------------------------------------------------------------------------------- 1 | Spain, 2025-02-25 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | Roger Solis rooger99@gmail.com https://github.com/newage99 12 | -------------------------------------------------------------------------------- /doc/cla/individual/ntfwc.md: -------------------------------------------------------------------------------- 1 | United States, 2019-07-09 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | ntfwc ntfwc@yahoo.com https://github.com/ntfwc 12 | -------------------------------------------------------------------------------- /doc/cla/individual/podsvirov.md: -------------------------------------------------------------------------------- 1 | Russia, 2021-04-26 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | Konstantin Podsvirov konstantin@podsvirov.pro https://github.com/podsvirov 12 | -------------------------------------------------------------------------------- /doc/cla/individual/randomairborne.md: -------------------------------------------------------------------------------- 1 | United States of America, 2022-10-2 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | valyrie_pilot valk@randomairborne.dev https://github.com/randomairborne 12 | -------------------------------------------------------------------------------- /doc/cla/individual/ravencgg.md: -------------------------------------------------------------------------------- 1 | United States, 2021-06-04 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | Chris Genova raven.cgg@gmail.com https://github.com/ravencgg 12 | -------------------------------------------------------------------------------- /doc/cla/individual/sariug.md: -------------------------------------------------------------------------------- 1 | Turkey, 2020-03-02 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | sariug ugurcansari93@gmail.com https://github.com/sariug -------------------------------------------------------------------------------- /doc/cla/individual/template.md: -------------------------------------------------------------------------------- 1 | , 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | John Doe jd@example.com https://github.com/johndoe 12 | -------------------------------------------------------------------------------- /doc/cla/individual/vvbalashoff.md: -------------------------------------------------------------------------------- 1 | Russia, 2020-12-01 2 | 3 | I hereby agree to the terms of the Goxel Individual Contributor License 4 | Agreement v1.0. 5 | 6 | I declare that I am authorized and able to make this agreement and sign this 7 | declaration. 8 | 9 | Signed, 10 | 11 | vadim v. balashoff vvb.backup@rambler.ru https://github.com/vvbalashoff 12 | -------------------------------------------------------------------------------- /ext_src/meshoptimizer/allocator.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of meshoptimizer library; see meshoptimizer.h for version/license details 2 | #include "meshoptimizer.h" 3 | 4 | void meshopt_setAllocator(void* (MESHOPTIMIZER_ALLOC_CALLCONV *allocate)(size_t), void (MESHOPTIMIZER_ALLOC_CALLCONV *deallocate)(void*)) 5 | { 6 | meshopt_Allocator::Storage::allocate = allocate; 7 | meshopt_Allocator::Storage::deallocate = deallocate; 8 | } 9 | -------------------------------------------------------------------------------- /ext_src/meshoptimizer/vcacheanalyzer.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of meshoptimizer library; see meshoptimizer.h for version/license details 2 | #include "meshoptimizer.h" 3 | 4 | #include 5 | #include 6 | 7 | meshopt_VertexCacheStatistics meshopt_analyzeVertexCache(const unsigned int* indices, size_t index_count, size_t vertex_count, unsigned int cache_size, unsigned int warp_size, unsigned int primgroup_size) 8 | { 9 | assert(index_count % 3 == 0); 10 | assert(cache_size >= 3); 11 | assert(warp_size == 0 || warp_size >= 3); 12 | 13 | meshopt_Allocator allocator; 14 | 15 | meshopt_VertexCacheStatistics result = {}; 16 | 17 | unsigned int warp_offset = 0; 18 | unsigned int primgroup_offset = 0; 19 | 20 | unsigned int* cache_timestamps = allocator.allocate(vertex_count); 21 | memset(cache_timestamps, 0, vertex_count * sizeof(unsigned int)); 22 | 23 | unsigned int timestamp = cache_size + 1; 24 | 25 | for (size_t i = 0; i < index_count; i += 3) 26 | { 27 | unsigned int a = indices[i + 0], b = indices[i + 1], c = indices[i + 2]; 28 | assert(a < vertex_count && b < vertex_count && c < vertex_count); 29 | 30 | bool ac = (timestamp - cache_timestamps[a]) > cache_size; 31 | bool bc = (timestamp - cache_timestamps[b]) > cache_size; 32 | bool cc = (timestamp - cache_timestamps[c]) > cache_size; 33 | 34 | // flush cache if triangle doesn't fit into warp or into the primitive buffer 35 | if ((primgroup_size && primgroup_offset == primgroup_size) || (warp_size && warp_offset + ac + bc + cc > warp_size)) 36 | { 37 | result.warps_executed += warp_offset > 0; 38 | 39 | warp_offset = 0; 40 | primgroup_offset = 0; 41 | 42 | // reset cache 43 | timestamp += cache_size + 1; 44 | } 45 | 46 | // update cache and add vertices to warp 47 | for (int j = 0; j < 3; ++j) 48 | { 49 | unsigned int index = indices[i + j]; 50 | 51 | if (timestamp - cache_timestamps[index] > cache_size) 52 | { 53 | cache_timestamps[index] = timestamp++; 54 | result.vertices_transformed++; 55 | warp_offset++; 56 | } 57 | } 58 | 59 | primgroup_offset++; 60 | } 61 | 62 | size_t unique_vertex_count = 0; 63 | 64 | for (size_t i = 0; i < vertex_count; ++i) 65 | unique_vertex_count += cache_timestamps[i] > 0; 66 | 67 | result.warps_executed += warp_offset > 0; 68 | 69 | result.acmr = index_count == 0 ? 0 : float(result.vertices_transformed) / float(index_count / 3); 70 | result.atvr = unique_vertex_count == 0 ? 0 : float(result.vertices_transformed) / float(unique_vertex_count); 71 | 72 | return result; 73 | } 74 | -------------------------------------------------------------------------------- /ext_src/meshoptimizer/vfetchanalyzer.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of meshoptimizer library; see meshoptimizer.h for version/license details 2 | #include "meshoptimizer.h" 3 | 4 | #include 5 | #include 6 | 7 | meshopt_VertexFetchStatistics meshopt_analyzeVertexFetch(const unsigned int* indices, size_t index_count, size_t vertex_count, size_t vertex_size) 8 | { 9 | assert(index_count % 3 == 0); 10 | assert(vertex_size > 0 && vertex_size <= 256); 11 | 12 | meshopt_Allocator allocator; 13 | 14 | meshopt_VertexFetchStatistics result = {}; 15 | 16 | unsigned char* vertex_visited = allocator.allocate(vertex_count); 17 | memset(vertex_visited, 0, vertex_count); 18 | 19 | const size_t kCacheLine = 64; 20 | const size_t kCacheSize = 128 * 1024; 21 | 22 | // simple direct mapped cache; on typical mesh data this is close to 4-way cache, and this model is a gross approximation anyway 23 | size_t cache[kCacheSize / kCacheLine] = {}; 24 | 25 | for (size_t i = 0; i < index_count; ++i) 26 | { 27 | unsigned int index = indices[i]; 28 | assert(index < vertex_count); 29 | 30 | vertex_visited[index] = 1; 31 | 32 | size_t start_address = index * vertex_size; 33 | size_t end_address = start_address + vertex_size; 34 | 35 | size_t start_tag = start_address / kCacheLine; 36 | size_t end_tag = (end_address + kCacheLine - 1) / kCacheLine; 37 | 38 | assert(start_tag < end_tag); 39 | 40 | for (size_t tag = start_tag; tag < end_tag; ++tag) 41 | { 42 | size_t line = tag % (sizeof(cache) / sizeof(cache[0])); 43 | 44 | // we store +1 since cache is filled with 0 by default 45 | result.bytes_fetched += (cache[line] != tag + 1) * kCacheLine; 46 | cache[line] = tag + 1; 47 | } 48 | } 49 | 50 | size_t unique_vertex_count = 0; 51 | 52 | for (size_t i = 0; i < vertex_count; ++i) 53 | unique_vertex_count += vertex_visited[i]; 54 | 55 | result.overfetch = unique_vertex_count == 0 ? 0 : float(result.bytes_fetched) / float(unique_vertex_count * vertex_size); 56 | 57 | return result; 58 | } 59 | -------------------------------------------------------------------------------- /ext_src/meshoptimizer/vfetchoptimizer.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of meshoptimizer library; see meshoptimizer.h for version/license details 2 | #include "meshoptimizer.h" 3 | 4 | #include 5 | #include 6 | 7 | size_t meshopt_optimizeVertexFetchRemap(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count) 8 | { 9 | assert(index_count % 3 == 0); 10 | 11 | memset(destination, -1, vertex_count * sizeof(unsigned int)); 12 | 13 | unsigned int next_vertex = 0; 14 | 15 | for (size_t i = 0; i < index_count; ++i) 16 | { 17 | unsigned int index = indices[i]; 18 | assert(index < vertex_count); 19 | 20 | if (destination[index] == ~0u) 21 | { 22 | destination[index] = next_vertex++; 23 | } 24 | } 25 | 26 | assert(next_vertex <= vertex_count); 27 | 28 | return next_vertex; 29 | } 30 | 31 | size_t meshopt_optimizeVertexFetch(void* destination, unsigned int* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size) 32 | { 33 | assert(index_count % 3 == 0); 34 | assert(vertex_size > 0 && vertex_size <= 256); 35 | 36 | meshopt_Allocator allocator; 37 | 38 | // support in-place optimization 39 | if (destination == vertices) 40 | { 41 | unsigned char* vertices_copy = allocator.allocate(vertex_count * vertex_size); 42 | memcpy(vertices_copy, vertices, vertex_count * vertex_size); 43 | vertices = vertices_copy; 44 | } 45 | 46 | // build vertex remap table 47 | unsigned int* vertex_remap = allocator.allocate(vertex_count); 48 | memset(vertex_remap, -1, vertex_count * sizeof(unsigned int)); 49 | 50 | unsigned int next_vertex = 0; 51 | 52 | for (size_t i = 0; i < index_count; ++i) 53 | { 54 | unsigned int index = indices[i]; 55 | assert(index < vertex_count); 56 | 57 | unsigned int& remap = vertex_remap[index]; 58 | 59 | if (remap == ~0u) // vertex was not added to destination VB 60 | { 61 | // add vertex 62 | memcpy(static_cast(destination) + next_vertex * vertex_size, static_cast(vertices) + index * vertex_size, vertex_size); 63 | 64 | remap = next_vertex++; 65 | } 66 | 67 | // modify indices in place 68 | indices[i] = remap; 69 | } 70 | 71 | assert(next_vertex <= vertex_count); 72 | 73 | return next_vertex; 74 | } 75 | -------------------------------------------------------------------------------- /ext_src/nfd/nfd_glfw3.h: -------------------------------------------------------------------------------- 1 | /* 2 | Native File Dialog Extended 3 | Repository: https://github.com/btzy/nativefiledialog-extended 4 | License: Zlib 5 | Authors: Bernard Teo 6 | 7 | This header contains a function to convert a GLFW window handle to a native window handle for 8 | passing to NFDe. 9 | */ 10 | 11 | #ifndef _NFD_GLFW3_H 12 | #define _NFD_GLFW3_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #define NFD_INLINE inline 22 | #else 23 | #define NFD_INLINE static inline 24 | #endif // __cplusplus 25 | 26 | /** 27 | * Converts a GLFW window handle to a native window handle that can be passed to NFDe. 28 | * @param sdlWindow The GLFW window handle. 29 | * @param[out] nativeWindow The output native window handle, populated if and only if this function 30 | * returns true. 31 | * @return Either true to indicate success, or false to indicate failure. It is intended that 32 | * users ignore the error and simply pass a value-initialized nfdwindowhandle_t to NFDe if this 33 | * function fails. */ 34 | NFD_INLINE bool NFD_GetNativeWindowFromGLFWWindow(GLFWwindow* glfwWindow, 35 | nfdwindowhandle_t* nativeWindow) { 36 | GLFWerrorfun oldCallback = glfwSetErrorCallback(NULL); 37 | bool success = false; 38 | #if defined(GLFW_EXPOSE_NATIVE_WIN32) 39 | if (!success) { 40 | const HWND hwnd = glfwGetWin32Window(glfwWindow); 41 | if (hwnd) { 42 | nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_WINDOWS; 43 | nativeWindow->handle = (void*)hwnd; 44 | success = true; 45 | } 46 | } 47 | #endif 48 | #if defined(GLFW_EXPOSE_NATIVE_COCOA) 49 | if (!success) { 50 | const id cocoa_window = glfwGetCocoaWindow(glfwWindow); 51 | if (cocoa_window) { 52 | nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_COCOA; 53 | nativeWindow->handle = (void*)cocoa_window; 54 | success = true; 55 | } 56 | } 57 | #endif 58 | #if defined(GLFW_EXPOSE_NATIVE_X11) 59 | if (!success) { 60 | const Window x11_window = glfwGetX11Window(glfwWindow); 61 | if (x11_window != None) { 62 | nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_X11; 63 | nativeWindow->handle = (void*)x11_window; 64 | success = true; 65 | } 66 | } 67 | #endif 68 | #if defined(GLFW_EXPOSE_NATIVE_WAYLAND) 69 | // For now we don't support Wayland, but we intend to support it eventually. 70 | // Silence the warnings. 71 | { 72 | (void)glfwWindow; 73 | (void)nativeWindow; 74 | } 75 | #endif 76 | glfwSetErrorCallback(oldCallback); 77 | return success; 78 | } 79 | 80 | #undef NFD_INLINE 81 | #ifdef __cplusplus 82 | } 83 | #endif // __cplusplus 84 | 85 | #endif // _NFD_GLFW3_H 86 | -------------------------------------------------------------------------------- /ext_src/quickjs/hello.c: -------------------------------------------------------------------------------- 1 | /* File generated automatically by the QuickJS compiler. */ 2 | 3 | #include "quickjs-libc.h" 4 | 5 | const uint32_t qjsc_hello_size = 87; 6 | 7 | const uint8_t qjsc_hello[87] = { 8 | 0x02, 0x04, 0x0e, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 9 | 0x6c, 0x65, 0x06, 0x6c, 0x6f, 0x67, 0x16, 0x48, 10 | 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 11 | 0x6c, 0x64, 0x22, 0x65, 0x78, 0x61, 0x6d, 0x70, 12 | 0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 13 | 0x6f, 0x2e, 0x6a, 0x73, 0x0e, 0x00, 0x06, 0x00, 14 | 0xa0, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 15 | 0x14, 0x01, 0xa2, 0x01, 0x00, 0x00, 0x00, 0x38, 16 | 0xe1, 0x00, 0x00, 0x00, 0x42, 0xe2, 0x00, 0x00, 17 | 0x00, 0x04, 0xe3, 0x00, 0x00, 0x00, 0x24, 0x01, 18 | 0x00, 0xcd, 0x28, 0xc8, 0x03, 0x01, 0x00, 19 | }; 20 | 21 | static JSContext *JS_NewCustomContext(JSRuntime *rt) 22 | { 23 | JSContext *ctx = JS_NewContextRaw(rt); 24 | if (!ctx) 25 | return NULL; 26 | JS_AddIntrinsicBaseObjects(ctx); 27 | return ctx; 28 | } 29 | 30 | int main(int argc, char **argv) 31 | { 32 | JSRuntime *rt; 33 | JSContext *ctx; 34 | rt = JS_NewRuntime(); 35 | js_std_set_worker_new_context_func(JS_NewCustomContext); 36 | js_std_init_handlers(rt); 37 | ctx = JS_NewCustomContext(rt); 38 | js_std_add_helpers(ctx, argc, argv); 39 | js_std_eval_binary(ctx, qjsc_hello, qjsc_hello_size, 0); 40 | js_std_loop(ctx); 41 | JS_FreeContext(ctx); 42 | JS_FreeRuntime(rt); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /ext_src/quickjs/libregexp-opcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Regular Expression Engine 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | #ifdef DEF 26 | 27 | DEF(invalid, 1) /* never used */ 28 | DEF(char, 3) 29 | DEF(char32, 5) 30 | DEF(dot, 1) 31 | DEF(any, 1) /* same as dot but match any character including line terminator */ 32 | DEF(line_start, 1) 33 | DEF(line_end, 1) 34 | DEF(goto, 5) 35 | DEF(split_goto_first, 5) 36 | DEF(split_next_first, 5) 37 | DEF(match, 1) 38 | DEF(save_start, 2) /* save start position */ 39 | DEF(save_end, 2) /* save end position, must come after saved_start */ 40 | DEF(save_reset, 3) /* reset save positions */ 41 | DEF(loop, 5) /* decrement the top the stack and goto if != 0 */ 42 | DEF(push_i32, 5) /* push integer on the stack */ 43 | DEF(drop, 1) 44 | DEF(word_boundary, 1) 45 | DEF(not_word_boundary, 1) 46 | DEF(back_reference, 2) 47 | DEF(backward_back_reference, 2) /* must come after back_reference */ 48 | DEF(range, 3) /* variable length */ 49 | DEF(range32, 3) /* variable length */ 50 | DEF(lookahead, 5) 51 | DEF(negative_lookahead, 5) 52 | DEF(push_char_pos, 1) /* push the character position on the stack */ 53 | DEF(bne_char_pos, 5) /* pop one stack element and jump if equal to the character 54 | position */ 55 | DEF(prev, 1) /* go to the previous char */ 56 | DEF(simple_greedy_quant, 17) 57 | 58 | #endif /* DEF */ 59 | -------------------------------------------------------------------------------- /ext_src/quickjs/quickjs-libc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * QuickJS C library 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef QUICKJS_LIBC_H 25 | #define QUICKJS_LIBC_H 26 | 27 | #include 28 | #include 29 | 30 | #include "quickjs.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | JSModuleDef *js_init_module_std(JSContext *ctx, const char *module_name); 37 | JSModuleDef *js_init_module_os(JSContext *ctx, const char *module_name); 38 | void js_std_add_helpers(JSContext *ctx, int argc, char **argv); 39 | void js_std_loop(JSContext *ctx); 40 | void js_std_init_handlers(JSRuntime *rt); 41 | void js_std_free_handlers(JSRuntime *rt); 42 | void js_std_dump_error(JSContext *ctx); 43 | uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename); 44 | int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val, 45 | JS_BOOL use_realpath, JS_BOOL is_main); 46 | JSModuleDef *js_module_loader(JSContext *ctx, 47 | const char *module_name, void *opaque); 48 | void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len, 49 | int flags); 50 | void js_std_promise_rejection_tracker(JSContext *ctx, JSValueConst promise, 51 | JSValueConst reason, 52 | JS_BOOL is_handled, void *opaque); 53 | void js_std_set_worker_new_context_func(JSContext *(*func)(JSRuntime *rt)); 54 | 55 | #ifdef __cplusplus 56 | } /* extern "C" { */ 57 | #endif 58 | 59 | #endif /* QUICKJS_LIBC_H */ 60 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; 4 | utils.url = "github:numtide/flake-utils"; 5 | }; 6 | 7 | outputs = { self, nixpkgs, utils }: 8 | utils.lib.eachDefaultSystem (system: 9 | let pkgs = import nixpkgs { inherit system; }; 10 | in { 11 | devShell = with pkgs; 12 | mkShell { buildInputs = [ scons pkg-config gtk3 glfw ]; }; 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/icon.png -------------------------------------------------------------------------------- /osx/goxel/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /osx/goxel/goxel.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/1024.png -------------------------------------------------------------------------------- /osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/128.png -------------------------------------------------------------------------------- /osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/16.png -------------------------------------------------------------------------------- /osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/256.png -------------------------------------------------------------------------------- /osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/32.png -------------------------------------------------------------------------------- /osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/512.png -------------------------------------------------------------------------------- /osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/64.png -------------------------------------------------------------------------------- /osx/goxel/goxel/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /osx/goxel/goxel/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 0.15.1 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 10 25 | LSApplicationCategoryType 26 | public.app-category.productivity 27 | LSMinimumSystemVersion 28 | $(MACOSX_DEPLOYMENT_TARGET) 29 | NSHumanReadableCopyright 30 | Copyright © 2022 Noctua Software Limited. All rights reserved. 31 | NSMainNibFile 32 | MainMenu 33 | NSPrincipalClass 34 | GoxNSApplication 35 | 36 | 37 | -------------------------------------------------------------------------------- /osx/goxel/goxel/goxel-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // goxel-Bridging-Header.h 3 | // goxel 4 | // 5 | // Created by Guillaume Chereau on 10/16/15. 6 | // Copyright © 2015 Noctua Software Limited. All rights reserved. 7 | // 8 | 9 | #ifndef goxel_Bridging_Header_h 10 | #define goxel_Bridging_Header_h 11 | 12 | #ifndef DEBUG 13 | # define DEBUG 0 14 | #endif 15 | 16 | #include "config.h" 17 | #include "goxel.h" 18 | 19 | #endif /* goxel_Bridging_Header_h */ 20 | -------------------------------------------------------------------------------- /osx/goxel/goxel/goxel.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-write 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /osx/goxel/goxel/goxel.pch: -------------------------------------------------------------------------------- 1 | // 2 | // goxel.pch 3 | // goxel 4 | // 5 | // Created by Guillaume Chereau on 10/16/15. 6 | // Copyright © 2015 Noctua Software Limited. All rights reserved. 7 | // 8 | 9 | #ifndef goxel_pch 10 | #define goxel_pch 11 | 12 | // Include any system framework and library headers here that should be included in all compilation units. 13 | // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file. 14 | #define INI_HANDLER_LINENO 1 15 | 16 | #ifndef DEBUG 17 | # define DEBUG 0 18 | #endif 19 | 20 | #pragma clang diagnostic ignored "-Wconversion" 21 | 22 | #include "config.h" 23 | 24 | #endif /* goxel_pch */ 25 | -------------------------------------------------------------------------------- /screenshots/screenshot-castle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/screenshots/screenshot-castle.png -------------------------------------------------------------------------------- /screenshots/screenshot-dicom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/screenshots/screenshot-dicom.png -------------------------------------------------------------------------------- /screenshots/screenshot-plane.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/screenshots/screenshot-plane.png -------------------------------------------------------------------------------- /screenshots/screenshot-procedural-city.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumechereau/goxel/66d36e0c3511479ceaac8cbf9f5c7c3e619b30d3/screenshots/screenshot-procedural-city.png -------------------------------------------------------------------------------- /snap/gui/goxel.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Version=1.0 3 | Encoding=UTF-8 4 | Name=Goxel 5 | GenericName=Voxel graphics editor 6 | Comment=3D Voxel Editor 7 | Exec=goxel 8 | Icon=goxel 9 | Type=Application 10 | Categories=Graphics;3DGraphics; 11 | -------------------------------------------------------------------------------- /snap/gui/io.github.guillaumechereau.Goxel.metainfo.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | io.github.guillaumechereau.Goxel 4 | Goxel 5 | GPL-3.0-only 6 | CC0-1.0 7 | Open Source 3D voxel editor 8 | Guillaume Chereau 9 | 10 |

11 | Goxel is a 3D program that lets you create voxel volumes, a bit similar to minecraft. The code is Open Source and fully available on Github. 12 |

13 |

Features:

14 |
    15 |
  • Unlimited scene size: You can create voxel images as big as you want.
  • 16 |
  • Layers support: Decompose your image into several layers for easy editing.
  • 17 |
  • Many export formats: Goxel can export to obj, pyl, magica voxel, png, qubicle, povray, and more.
  • 18 |
19 |
20 | goxel.desktop 21 | 22 | 23 | Fisherman house, made with Goxel by Thibault Simar 24 | https://goxel.xyz/gallery/thibault-fisherman-house.jpg 25 | 26 | 27 | 28 | goxel 29 | 30 | 31 | 32 | 33 | https://goxel.xyz/ 34 | https://github.com/guillaumechereau/goxel/issues 35 | https://github.com/guillaumechereau/goxel#donations 36 | https://github.com/guillaumechereau/goxel 37 | https://github.com/guillaumechereau/goxel/blob/master/CONTRIBUTING.md 38 | 39 |
40 | -------------------------------------------------------------------------------- /snap/snapcraft.yaml: -------------------------------------------------------------------------------- 1 | name: goxel 2 | version: git 3 | summary: Goxel. Free and Open Source 3D Voxel Editor 4 | description: | 5 | You can use goxel to create voxel graphics (3D images formed of cubes). 6 | It works on Linux, BSD, Windows and macOS. 7 | 8 | confinement: strict 9 | 10 | apps: 11 | goxel: 12 | command: desktop-launch $SNAP/goxel 13 | plugs: 14 | - x11 15 | - opengl 16 | - home 17 | 18 | parts: 19 | goxel: 20 | after: [desktop-gtk3] 21 | source: . 22 | plugin: make 23 | build: | 24 | make release 25 | install: | 26 | cp goxel $SNAPCRAFT_PART_INSTALL 27 | cp icon.png $SNAPCRAFT_PART_INSTALL 28 | build-packages: 29 | - scons 30 | - pkg-config 31 | - libglfw3-dev 32 | - libgtk-3-dev 33 | - libpng12-dev 34 | -------------------------------------------------------------------------------- /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 | enum { 28 | ACTION_NULL = 0, 29 | 30 | ACTION_layer_clear, 31 | ACTION_img_new_layer, 32 | ACTION_img_del_layer, 33 | ACTION_img_move_layer_up, 34 | ACTION_img_move_layer_down, 35 | ACTION_img_duplicate_layer, 36 | ACTION_img_clone_layer, 37 | ACTION_img_unclone_layer, 38 | ACTION_img_select_parent_layer, 39 | ACTION_img_merge_visible_layers, 40 | ACTION_img_merge_layer_down, 41 | ACTION_img_new_camera, 42 | ACTION_img_del_camera, 43 | ACTION_img_move_camera_up, 44 | ACTION_img_move_camera_down, 45 | ACTION_img_image_layer_to_volume, 46 | ACTION_img_new_shape_layer, 47 | ACTION_img_new_material, 48 | ACTION_img_del_material, 49 | ACTION_img_auto_resize, 50 | 51 | ACTION_cut_as_new_layer, 52 | ACTION_reset_selection, 53 | ACTION_fill_selection_box, 54 | ACTION_paint_selection, 55 | ACTION_add_selection, 56 | ACTION_sub_selection, 57 | ACTION_copy, 58 | ACTION_paste, 59 | ACTION_view_left, 60 | ACTION_view_right, 61 | ACTION_view_top, 62 | ACTION_view_toggle_ortho, 63 | ACTION_view_default, 64 | ACTION_view_front, 65 | ACTION_quit, 66 | ACTION_undo, 67 | ACTION_redo, 68 | ACTION_toggle_mode, 69 | ACTION_set_mode_add, 70 | ACTION_set_mode_sub, 71 | ACTION_set_mode_paint, 72 | ACTION_export_render_buf_to_photos, 73 | ACTION_open, 74 | ACTION_save_as, 75 | ACTION_save, 76 | ACTION_overwrite_export, 77 | ACTION_reset, 78 | 79 | ACTION_tool_set_brush, 80 | ACTION_tool_set_laser, 81 | ACTION_tool_set_shape, 82 | ACTION_tool_set_pick_color, 83 | ACTION_tool_set_extrude, 84 | ACTION_tool_set_plane, 85 | ACTION_tool_set_selection, 86 | ACTION_tool_set_fuzzy_select, 87 | ACTION_tool_set_rect_select, 88 | ACTION_tool_set_line, 89 | ACTION_tool_set_move, 90 | 91 | ACTION_export_to_photos, 92 | 93 | ACTION_COUNT 94 | }; 95 | 96 | #undef X 97 | 98 | #endif // ACTIONS_H 99 | -------------------------------------------------------------------------------- /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/locale.inl" 59 | #include "assets/other.inl" 60 | #include "assets/palettes.inl" 61 | #include "assets/progs.inl" 62 | #include "assets/shaders.inl" 63 | #include "assets/scripts.inl" 64 | #include "assets/sounds.inl" 65 | #include "assets/themes.inl" 66 | #ifdef ASSETS_EXTRA 67 | # include ASSETS_EXTRA // Allow to add custom assets at build time. 68 | #endif 69 | {}, // NULL asset at the end of the list. 70 | }; 71 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/assets/other.inl: -------------------------------------------------------------------------------- 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 autogenerated by tools/create_assets.py */ 20 | 21 | {.path = "data/other/povray_template.pov", .size = 748, .data = 22 | "// Generated from goxel {{version}}\n" 23 | "// https://github.com/guillaumechereau/goxel\n" 24 | "\n" 25 | "{{#camera}}\n" 26 | "camera {\n" 27 | " perspective\n" 28 | " right x*{{width}}/{{height}}\n" 29 | " direction <0, 0, -1>\n" 30 | " angle {{angle}}\n" 31 | " transform {\n" 32 | " matrix {{modelview}}\n" 33 | " inverse\n" 34 | " }\n" 35 | "}\n" 36 | "{{/camera}}\n" 37 | "\n" 38 | "#declare Voxel = box {<-0.5, -0.5, -0.5>, <0.5, 0.5, 0.5>}\n" 39 | "#macro Vox(Pos, Color)\n" 40 | " object {\n" 41 | " Voxel\n" 42 | " translate Pos\n" 43 | " translate <0.5, 0.5, 0.5>\n" 44 | " texture { pigment {color rgb Color / 255} }\n" 45 | " }\n" 46 | "#end\n" 47 | "\n" 48 | "{{#light}}\n" 49 | "global_settings { ambient_light rgb<1, 1, 1> * {{ambient}} }\n" 50 | "light_source {\n" 51 | " <0, 0, 1024> color rgb <2, 2, 2>\n" 52 | " parallel\n" 53 | " point_at {{point_at}}\n" 54 | "}\n" 55 | "{{/light}}\n" 56 | "\n" 57 | "union {\n" 58 | "{{#voxels}}\n" 59 | " Vox({{pos}}, {{color}})\n" 60 | "{{/voxels}}\n" 61 | "}\n" 62 | "" 63 | }, 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/assets/themes.inl: -------------------------------------------------------------------------------- 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 autogenerated by tools/create_assets.py */ 20 | 21 | {.path = "data/themes/dark.ini", .size = 362, .data = 22 | "[theme]\n" 23 | "name=dark\n" 24 | "\n" 25 | "[base]\n" 26 | "background=#303030FF\n" 27 | "inner=#545454FF\n" 28 | "item=#1975BEFF\n" 29 | "selected=#1975BEFF\n" 30 | "text=#CCCCCCFF\n" 31 | "text_selected=#FFFFFFFF\n" 32 | "\n" 33 | "[section]\n" 34 | "background=#3D3D3DFF\n" 35 | "\n" 36 | "[widget]\n" 37 | "\n" 38 | "[menu]\n" 39 | "background=#181818FF\n" 40 | "\n" 41 | "[icon]\n" 42 | "inner=#00000000\n" 43 | "item=#FFFFFFFF\n" 44 | "\n" 45 | "[icon_edit]\n" 46 | "item=#CCCCCCFF\n" 47 | "\n" 48 | "[icon_view]\n" 49 | "item=#E19658FF\n" 50 | "\n" 51 | "[icon_render]\n" 52 | "item=#74A2FFFF\n" 53 | "\n" 54 | "[icon_other]\n" 55 | "item=#CC6670FF\n" 56 | "" 57 | }, 58 | {.path = "data/themes/light.ini", .size = 365, .data = 59 | "[theme]\n" 60 | "name=light\n" 61 | "\n" 62 | "[base]\n" 63 | "background=#B3B3B3FF\n" 64 | "inner=#D4D4D4FF\n" 65 | "item=#557FC1FF\n" 66 | "selected=#557FC1FF\n" 67 | "text=#1D1D1DFF\n" 68 | "text_selected=#FFFFFFFF\n" 69 | "\n" 70 | "[window]\n" 71 | "background=#B3B3B3FF\n" 72 | "\n" 73 | "[section]\n" 74 | "background=#CCCCCCFF\n" 75 | "\n" 76 | "[widget]\n" 77 | "\n" 78 | "[icon]\n" 79 | "inner=#00000000\n" 80 | "item=#000000FF\n" 81 | "\n" 82 | "[icon_edit]\n" 83 | "item=#575757FF\n" 84 | "\n" 85 | "[icon_view]\n" 86 | "item=#B03D00FF\n" 87 | "\n" 88 | "[icon_render]\n" 89 | "item=#5149EFFF\n" 90 | "\n" 91 | "[icon_other]\n" 92 | "item=#DF4F4DFF\n" 93 | "" 94 | }, 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | static int file_format_cmp(const file_format_t *a, const file_format_t *b) 38 | { 39 | if (b->priority != a->priority) { 40 | return b->priority - a->priority; 41 | } 42 | return strcmp(a->name, b->name); 43 | } 44 | 45 | void file_format_register(file_format_t *format) 46 | { 47 | DL_APPEND(file_formats, format); 48 | DL_SORT(file_formats, file_format_cmp); 49 | } 50 | 51 | const file_format_t *file_format_get( 52 | const char *path, const char *name, const char *mode) 53 | { 54 | const file_format_t *f; 55 | bool need_read = strchr(mode, 'r'); 56 | bool need_write = strchr(mode, 'w'); 57 | const char *ext; 58 | 59 | assert(mode); 60 | assert(path || name); 61 | 62 | DL_FOREACH(file_formats, f) { 63 | if (need_read && !f->import_func) continue; 64 | if (need_write && !f->export_func) continue; 65 | if (name && strcasecmp(f->name, name) != 0) continue; 66 | if (!name && path) { 67 | ext = f->exts[0] + 1; // Pick the string after '*'. 68 | if (!endswith(path, ext)) continue; 69 | } 70 | return f; 71 | } 72 | return NULL; 73 | } 74 | 75 | void file_format_iter(const char *mode, void *user, 76 | void (*fun)(void *user, file_format_t *f)) 77 | { 78 | assert(mode); 79 | assert(fun); 80 | file_format_t *f; 81 | bool need_read = strchr(mode, 'r'); 82 | bool need_write = strchr(mode, 'w'); 83 | DL_FOREACH(file_formats, f) { 84 | if (need_read && !f->import_func) continue; 85 | if (need_write && !f->export_func) continue; 86 | fun(user, f); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /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 *exts[8]; 30 | const char *exts_desc; 31 | void (*export_gui)(file_format_t *format); 32 | int (*export_func)(const file_format_t *format, 33 | const image_t *img, const char *path); 34 | int (*import_func)(const file_format_t *format, image_t *img, 35 | const char *path); 36 | void (*import_gui)(file_format_t *format); 37 | int priority; // Specifies the order of file_format_iter. 38 | }; 39 | 40 | void file_format_register(file_format_t *format); 41 | 42 | /** 43 | * Return the recomended file format for a path or by explicit name. 44 | * 45 | * path - Optional file path. 46 | * format_name - Optional explicit format name. 47 | * mode - String that can contain 'r' and or 'w'. 48 | */ 49 | const file_format_t *file_format_get( 50 | const char *path, const char *format_name, const char *mode); 51 | 52 | void file_format_iter(const char *mode, void *user, 53 | void (*f)(void *user, file_format_t *f)); 54 | 55 | // The global list of registered file formats. 56 | extern file_format_t *file_formats; 57 | 58 | #define FILE_FORMAT_REGISTER(id_, ...) \ 59 | static file_format_t GOX_format_##id_ = {__VA_ARGS__}; \ 60 | __attribute__((constructor)) \ 61 | static void GOX_register_format_##id_(void) { \ 62 | file_format_register(&GOX_format_##id_); \ 63 | } 64 | 65 | #endif // FILE_FORMAT_H 66 | -------------------------------------------------------------------------------- /src/filters.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2024 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 16 | * with goxel. If not, see . 17 | */ 18 | 19 | #include "goxel.h" 20 | #include "../ext_src/stb/stb_ds.h" 21 | 22 | // stb array of registered filters. 23 | static filter_t **g_filters = NULL; 24 | 25 | static void a_filter_toggle(void *data) 26 | { 27 | filter_t *filter = data; 28 | LOG_D("Toggle filter %s", filter->name); 29 | filter->is_open = !filter->is_open; 30 | 31 | if (filter->is_open && filter->on_open) { 32 | filter->on_open(filter); 33 | } 34 | 35 | if (!filter->is_open && filter->on_close) { 36 | filter->on_close(filter); 37 | } 38 | } 39 | 40 | void filter_register_(filter_t *filter) 41 | { 42 | action_t action; 43 | action = (action_t) { 44 | .id = filter->action_id, 45 | .default_shortcut = filter->default_shortcut, 46 | .cfunc_data = a_filter_toggle, 47 | .data = (void*)filter, 48 | .flags = ACTION_CAN_EDIT_SHORTCUT, 49 | }; 50 | action_register(&action, 0); 51 | arrput(g_filters, filter); 52 | } 53 | 54 | 55 | void filters_iter_all( 56 | void *arg, void (*f)(void *arg, filter_t *filter)) 57 | { 58 | int i; 59 | for (i = 0; i < arrlen(g_filters); i++) { 60 | f(arg, g_filters[i]); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/filters.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2024 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 FILTERS_H 20 | #define FILTERS_H 21 | 22 | #include 23 | 24 | typedef struct filter filter_t; 25 | 26 | struct filter { 27 | int (*gui_fn)(filter_t *filter); 28 | void (*on_open)(filter_t *filter); 29 | void (*on_close)(filter_t *filter); 30 | const char *name; 31 | const char *action_id; 32 | const char *default_shortcut; 33 | bool is_open; 34 | }; 35 | 36 | #define FILTER_REGISTER(id_, klass_, ...) \ 37 | static klass_ GOX_filter_##id_ = {\ 38 | .filter = { \ 39 | .action_id = "filter_open_" #id_, __VA_ARGS__ \ 40 | } \ 41 | }; \ 42 | __attribute__((constructor)) \ 43 | static void GOX_register_filter_##id_(void) { \ 44 | filter_register_(&GOX_filter_##id_.filter); \ 45 | } 46 | 47 | void filter_register_(filter_t *filter); 48 | 49 | /** 50 | * Iter all the registered filters 51 | */ 52 | void filters_iter_all( 53 | void *arg, void (*f)(void *arg, filter_t *filter)); 54 | 55 | #endif // FILTERS_H 56 | -------------------------------------------------------------------------------- /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 | if (!goxel.graphics_initialized) { 26 | goxel_create_graphics(); 27 | } 28 | 29 | uint8_t *buf; 30 | int bpp = img->export_transparent_background ? 4 : 3; 31 | if (!path) return -1; 32 | LOG_I("Exporting to file %s", path); 33 | buf = calloc(w * h, bpp); 34 | goxel_render_to_buf(buf, w, h, bpp); 35 | img_write(buf, w, h, bpp, path); 36 | free(buf); 37 | return 0; 38 | } 39 | 40 | static void export_gui(file_format_t *format) 41 | { 42 | int maxsize, i; 43 | 44 | GL(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize)); 45 | maxsize /= 2; // Because png export already double it. 46 | goxel.show_export_viewport = true; 47 | gui_group_begin(NULL); 48 | gui_checkbox(_("Size"), &goxel.image->export_custom_size, NULL); 49 | if (!goxel.image->export_custom_size) { 50 | goxel.image->export_width = goxel.gui.viewport[2]; 51 | goxel.image->export_height = goxel.gui.viewport[3]; 52 | } 53 | 54 | gui_enabled_begin(goxel.image->export_custom_size); 55 | i = goxel.image->export_width; 56 | if (gui_input_int("w", &i, 1, maxsize)) 57 | goxel.image->export_width = clamp(i, 1, maxsize); 58 | i = goxel.image->export_height; 59 | if (gui_input_int("h", &i, 1, maxsize)) 60 | goxel.image->export_height = clamp(i, 1, maxsize); 61 | gui_enabled_end(); 62 | gui_group_end(); 63 | 64 | gui_checkbox(_("Transparent Background"), 65 | &goxel.image->export_transparent_background, 66 | NULL); 67 | } 68 | 69 | static int export_as_png(const file_format_t *format, const image_t *img, 70 | const char *path) 71 | { 72 | png_export(img, path, img->export_width, img->export_height); 73 | return 0; 74 | } 75 | 76 | FILE_FORMAT_REGISTER(png, 77 | .name = "png", 78 | .exts = {"*.png"}, 79 | .exts_desc = "png", 80 | .export_gui = export_gui, 81 | .export_func = export_as_png, 82 | .priority = 90, 83 | ) 84 | -------------------------------------------------------------------------------- /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 file_format_t *format, 23 | const image_t *image, const char *path) 24 | { 25 | float box[4][4]; 26 | const volume_t *volume; 27 | int x, y, z, w, h, d, pos[3], start_pos[3]; 28 | uint8_t c[4]; 29 | uint8_t *img; 30 | volume_iterator_t iter = {0}; 31 | 32 | volume = goxel_get_layers_volume(image); 33 | mat4_copy(image->box, box); 34 | if (box_is_null(box)) volume_get_box(volume, true, box); 35 | w = box[0][0] * 2; 36 | h = box[1][1] * 2; 37 | d = box[2][2] * 2; 38 | start_pos[0] = box[3][0] - box[0][0]; 39 | start_pos[1] = box[3][1] - box[1][1]; 40 | start_pos[2] = box[3][2] - box[2][2]; 41 | img = calloc(w * h * d, 4); 42 | for (z = 0; z < d; z++) 43 | for (y = 0; y < h; y++) 44 | for (x = 0; x < w; x++) { 45 | pos[0] = x + start_pos[0]; 46 | pos[1] = y + start_pos[1]; 47 | pos[2] = z + start_pos[2]; 48 | volume_get_at(volume, &iter, pos, c); 49 | img[(y * w * d + z * w + x) * 4 + 0] = c[0]; 50 | img[(y * w * d + z * w + x) * 4 + 1] = c[1]; 51 | img[(y * w * d + z * w + x) * 4 + 2] = c[2]; 52 | img[(y * w * d + z * w + x) * 4 + 3] = c[3]; 53 | } 54 | img_write(img, w * d, h, 4, path); 55 | free(img); 56 | return 0; 57 | } 58 | 59 | FILE_FORMAT_REGISTER(png_slices, 60 | .name = "png slices", 61 | .exts = {"*.png"}, 62 | .exts_desc = "png", 63 | .export_func = export_as_png_slices, 64 | ) 65 | -------------------------------------------------------------------------------- /src/gizmos.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2024-present 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 GIZMOS_H 20 | #define GIZMOS_H 21 | 22 | enum { 23 | GIZMO_TRANSLATION = 1 << 0, 24 | GIZMO_GROW = 1 << 1, 25 | }; 26 | 27 | /* 28 | * box_edit 29 | * Render a box that can be edited with the mouse. 30 | * 31 | * This is used for the move and selection tools. 32 | * Still a bit experimental. 33 | * 34 | * Parameters: 35 | * box - The box we want to edit. 36 | * flags - GIZMO_ enum union. 37 | * transf - Receive the output transformation. 38 | * first - Set to true if the edit is the first one. 39 | * 40 | * Return on of: 41 | * 0 (no action) 42 | * GESTURE3D_BEGIN 43 | * GESTURE3D_UPDATE 44 | * GESTURE3D_END 45 | */ 46 | int box_edit(const float box[4][4], int flags, float transf[4][4]); 47 | 48 | bool box_edit_is_active(void); 49 | 50 | 51 | #endif // GIZMOS_H 52 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | volume_global_stats_t stats; 24 | 25 | gui_text("FPS: %d", (int)round(goxel.fps)); 26 | volume_get_global_stats(&stats); 27 | gui_text("Nb volumes: %d", stats.nb_volumes); 28 | gui_text("Nb tiles: %d", stats.nb_tiles); 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/edit_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2024-present 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_edit_panel(void) 22 | { 23 | image_t *img = goxel.image; 24 | 25 | gui_group_begin(NULL); 26 | gui_enabled_begin(!box_is_null(img->selection_box)); 27 | gui_action_button(ACTION_fill_selection_box, _("Fill"), 1.0); 28 | gui_group_end(); 29 | gui_enabled_end(); 30 | 31 | gui_group_begin(NULL); 32 | gui_enabled_begin(!volume_is_empty(goxel.image->selection_mask)); 33 | gui_action_button(ACTION_layer_clear, _("Clear"), 1.0); 34 | gui_action_button(ACTION_paint_selection, _("Paint"), 1.0); 35 | gui_action_button(ACTION_cut_as_new_layer, _("Cut as new layer"), 1.0); 36 | gui_enabled_end(); 37 | gui_group_end(); 38 | 39 | gui_group_begin(NULL); 40 | gui_enabled_begin(!volume_is_empty(goxel.image->selection_mask)); 41 | gui_action_button(ACTION_copy, _("Copy"), 1.0); 42 | gui_enabled_end(); 43 | gui_enabled_begin(!volume_is_empty(goxel.clipboard.volume)); 44 | gui_action_button(ACTION_paste, _("Paste"), 1.0); 45 | gui_enabled_end(); 46 | gui_group_end(); 47 | } 48 | -------------------------------------------------------------------------------- /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 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->exts[0] + 1; 46 | snprintf(buf, len, "%s (%s)", f->name, ext); 47 | return buf; 48 | } 49 | 50 | static void on_format(void *user, 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(_("Format")); 63 | if (!g_current) g_current = file_formats; // First one. 64 | 65 | make_label(g_current, label, sizeof(label)); 66 | if (gui_combo_begin("#Format", 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(g_current); 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/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, _("Fit to Content"), -1); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /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 | char buf[256]; 25 | 26 | gui_group_begin(NULL); 27 | snprintf(buf, sizeof(buf), "%s: X", _("Angle")); 28 | gui_angle(buf, &goxel.rend.light.pitch, -90, +90); 29 | gui_angle("Z", &goxel.rend.light.yaw, 0, 360); 30 | gui_group_end(); 31 | gui_input_float(_("Intensity"), &goxel.rend.light.intensity, 32 | 0.1, 0, 10, NULL); 33 | gui_checkbox(_("Fixed"), &goxel.rend.light.fixed, NULL); 34 | 35 | if (!DEFINED(GOXEL_NO_SHADOW)) { 36 | v = goxel.rend.settings.shadow; 37 | if (gui_input_float(_("Shadow"), &v, 0.1, 0, 0, NULL)) { 38 | goxel.rend.settings.shadow = clamp(v, 0, 1); 39 | } 40 | } 41 | 42 | v = goxel.rend.settings.ambient; 43 | if (gui_input_float(_("Environment"), &v, 0.1, 0, 1, NULL)) { 44 | v = clamp(v, 0, 1); 45 | goxel.rend.settings.ambient = v; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /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 | static bool render_material_item(void *item, int idx, bool is_current) 22 | { 23 | material_t *mat = item; 24 | return gui_layer_item(idx, 0, NULL, NULL, &is_current, mat->name, 25 | sizeof(mat->name)); 26 | } 27 | 28 | void gui_material_panel(void) 29 | { 30 | material_t *mat = NULL; 31 | float base_color_e, emission_e, emission; 32 | 33 | gui_list(&(gui_list_t) { 34 | .items = (void**)&goxel.image->materials, 35 | .current = (void**)&goxel.image->active_material, 36 | .render = render_material_item, 37 | .can_be_null = true, 38 | }); 39 | 40 | gui_row_begin(0); 41 | gui_action_button(ACTION_img_new_material, NULL, 0); 42 | gui_action_button(ACTION_img_del_material, NULL, 0); 43 | gui_row_end(); 44 | 45 | mat = goxel.image->active_material; 46 | if (!mat) return; 47 | 48 | gui_group_begin(NULL); 49 | gui_input_float("Metallic", &mat->metallic, 0.1, 0, 1, NULL); 50 | gui_input_float("Roughness", &mat->roughness, 0.1, 0, 1, NULL); 51 | gui_group_end(); 52 | 53 | // Internally the material has an emission color independant of the 54 | // base color, but for the moment the gui only allow to set a factor from 55 | // the base color to keep is simple. 56 | base_color_e = max3(mat->base_color[0], 57 | mat->base_color[1], 58 | mat->base_color[2]); 59 | emission_e = max3(mat->emission[0], mat->emission[1], mat->emission[2]); 60 | emission = base_color_e ? emission_e / base_color_e : 0; 61 | 62 | if (gui_color_small_f3("Color", mat->base_color)) { 63 | vec3_mul(mat->base_color, emission, mat->emission); 64 | } 65 | 66 | if (gui_input_float("Emission", &emission, 0.1, 0, 10, NULL)) { 67 | vec3_mul(mat->base_color, emission, mat->emission); 68 | } 69 | 70 | gui_input_float("Opacity", &mat->base_color[3], 0.1, 0, 1, NULL); 71 | } 72 | -------------------------------------------------------------------------------- /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 | void gui_palette_panel(void) 22 | { 23 | int nb, i, current = -1; 24 | const palette_t *p; 25 | const char **names; 26 | gui_icon_info_t *grid; 27 | 28 | DL_COUNT(goxel.palettes, p, nb); 29 | names = (const char**)calloc(nb, sizeof(*names)); 30 | 31 | i = 0; 32 | DL_FOREACH(goxel.palettes, p) { 33 | if (p == goxel.palette) current = i; 34 | names[i++] = p->name; 35 | } 36 | if (gui_combo("##palettes", ¤t, names, nb)) { 37 | goxel.palette = goxel.palettes; 38 | for (i = 0; i < current; i++) goxel.palette = goxel.palette->next; 39 | } 40 | free(names); 41 | 42 | p = goxel.palette; 43 | grid = calloc(p->size, sizeof(*grid)); 44 | for (i = 0; i < p->size; i++) { 45 | grid[i] = (gui_icon_info_t) { 46 | .label = p->entries[i].name, 47 | .icon = 0, 48 | .color = {VEC4_SPLIT(p->entries[i].color)}, 49 | }; 50 | if (memcmp(goxel.painter.color, p->entries[i].color, 4) == 0) 51 | current = i; 52 | } 53 | if (gui_icons_grid(p->size, grid, ¤t)) { 54 | memcpy(goxel.painter.color, p->entries[current].color, 4); 55 | } 56 | free(grid); 57 | } 58 | -------------------------------------------------------------------------------- /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 | int ret = 0; 24 | gui_text(_("File Has Unsaved Changes")); 25 | 26 | gui_row_begin(0); 27 | if (gui_button(_("Quit"), 0, 0)) { 28 | goxel.quit = true; 29 | ret = 1; 30 | } 31 | if (gui_button(_("Cancel"), 0, 0)) { 32 | ret = 2; 33 | } 34 | gui_row_end(); 35 | return ret; 36 | } 37 | 38 | void gui_query_quit(void) 39 | { 40 | if (image_get_key(goxel.image) == goxel.image->saved_key) { 41 | goxel.quit = true; 42 | return; 43 | } 44 | gui_open_popup("##Quit", GUI_POPUP_RESIZE, NULL, gui_quit_popup); 45 | } 46 | -------------------------------------------------------------------------------- /src/gui/snap_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2024-present 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 bool snap_button(const char *label, int s) 22 | { 23 | bool v = goxel.snap_mask & s; 24 | if (gui_selectable(label, &v, NULL, -1)) { 25 | set_flag(&goxel.snap_mask, s, v); 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | void gui_snap_panel(void) 32 | { 33 | float v; 34 | gui_group_begin(NULL); 35 | gui_row_begin(2); 36 | snap_button(_("Volume"), SNAP_VOLUME); 37 | snap_button(_("Plane"), SNAP_PLANE); 38 | gui_row_end(); 39 | if (!box_is_null(goxel.image->selection_box)) { 40 | snap_button(_("Selection (In)"), SNAP_SELECTION_IN); 41 | snap_button(_("Selection (Out)"), SNAP_SELECTION_OUT); 42 | } 43 | if (!box_is_null(goxel.image->box)) { 44 | snap_button(_("Box"), SNAP_IMAGE_BOX); 45 | } 46 | gui_group_end(); 47 | 48 | v = goxel.snap_offset; 49 | if (gui_input_float(_("Offset"), &v, 0.1, -1, +1, "%.1f")) 50 | goxel.snap_offset = clamp(v, -1, +1); 51 | } 52 | -------------------------------------------------------------------------------- /src/gui/symmetry_panel.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2024-present 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 void recenter(int mode) 22 | { 23 | int bbox[2][3]; 24 | int i; 25 | float v; 26 | 27 | if (mode == 2 && box_is_null(goxel.image->box)) mode = 1; 28 | if (mode == 1 && box_is_null(goxel.image->active_layer->box)) mode = 0; 29 | 30 | switch (mode) { 31 | case 0: // Volume. 32 | volume_get_bbox(goxel.image->active_layer->volume, bbox, true); 33 | break; 34 | case 1: // Layer. 35 | bbox_to_aabb(goxel.image->active_layer->box, bbox); 36 | break; 37 | case 2: // Image. 38 | bbox_to_aabb(goxel.image->box, bbox); 39 | break; 40 | } 41 | 42 | for (i = 0; i < 3; i++) { 43 | if (!(goxel.painter.symmetry & (1 << i))) continue; 44 | v = round(bbox[0][i] + bbox[1][i] - 1) / 2.0; 45 | goxel.painter.symmetry_origin[i] = v; 46 | } 47 | } 48 | 49 | void gui_symmetry_panel(void) 50 | { 51 | int i; 52 | bool v; 53 | const char *labels_u[] = {"X", "Y", "Z"}; 54 | const char *labels_l[] = {"x", "y", "z"}; 55 | gui_group_begin("##Axis"); 56 | gui_row_begin(3); 57 | for (i = 0; i < 3; i++) { 58 | v = (goxel.painter.symmetry >> i) & 0x1; 59 | if (gui_selectable(labels_u[i], &v, NULL, 0)) 60 | set_flag(&goxel.painter.symmetry, 1 << i, v); 61 | } 62 | gui_row_end(); 63 | gui_group_end(); 64 | for (i = 0; i < 3; i++) { 65 | gui_input_float(labels_l[i], &goxel.painter.symmetry_origin[i], 0.5, 0, 66 | 0, "%.1f"); 67 | } 68 | 69 | if (gui_section_begin(_("Recenter"), GUI_SECTION_COLLAPSABLE_CLOSED)) { 70 | if (gui_button(_("Volume"), -1, 0)) recenter(0); 71 | if (gui_button(_("Layer"), -1, 0)) recenter(1); 72 | if (gui_button(_("Image"), -1, 0)) recenter(2); 73 | } gui_section_end(); 74 | } 75 | -------------------------------------------------------------------------------- /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 | void gui_tools_panel(void) 22 | { 23 | // XXX: cleanup this. 24 | const struct { 25 | int tool; 26 | int action; 27 | int icon; 28 | } values[] = { 29 | {TOOL_BRUSH, ACTION_tool_set_brush, ICON_TOOL_BRUSH}, 30 | {TOOL_SHAPE, ACTION_tool_set_shape, ICON_TOOL_SHAPE}, 31 | {TOOL_LASER, ACTION_tool_set_laser, ICON_TOOL_LASER}, 32 | {TOOL_SET_PLANE, ACTION_tool_set_plane, ICON_TOOL_PLANE}, 33 | {TOOL_MOVE, ACTION_tool_set_move, ICON_TOOL_MOVE}, 34 | {TOOL_PICK_COLOR, ACTION_tool_set_pick_color, ICON_TOOL_PICK}, 35 | {TOOL_SELECTION, ACTION_tool_set_selection, ICON_TOOL_SELECTION}, 36 | {TOOL_FUZZY_SELECT, ACTION_tool_set_fuzzy_select, ICON_TOOL_FUZZY_SELECT}, 37 | {TOOL_RECT_SELECT, ACTION_tool_set_rect_select, ICON_TOOL_RECT_SELECTION}, 38 | {TOOL_EXTRUDE, ACTION_tool_set_extrude, ICON_TOOL_EXTRUDE}, 39 | {TOOL_LINE, ACTION_tool_set_line, ICON_TOOL_LINE}, 40 | }; 41 | 42 | const int nb = ARRAY_SIZE(values); 43 | int i; 44 | const action_t *action = NULL; 45 | const tool_t *tool; 46 | int current = 0; 47 | gui_icon_info_t grid[64] = {}; 48 | 49 | for (i = 0; i < nb; i++) { 50 | tool = tool_get(values[i].tool); 51 | action = action_get(values[i].action, true); 52 | assert(action); 53 | if (goxel.tool->id == values[i].tool) current = i; 54 | grid[i] = (gui_icon_info_t) { 55 | .label = tr(tool->name), 56 | .sublabel = action->shortcut, 57 | .icon = values[i].icon, 58 | }; 59 | } 60 | 61 | gui_section_begin("##Tools", false); 62 | if (gui_icons_grid(nb, grid, ¤t)) { 63 | action = action_get(values[current].action, true); 64 | action_exec(action); 65 | } 66 | gui_section_end(); 67 | 68 | if (gui_collapsing_header(tr(goxel.tool->name), true)) 69 | tool_gui(goxel.tool); 70 | } 71 | 72 | -------------------------------------------------------------------------------- /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 | bool v; 26 | char label[64]; 27 | const action_t *action = NULL; 28 | int i; 29 | const struct { 30 | int mode; 31 | const char *label; 32 | int action; 33 | int icon; 34 | } values[] = { 35 | {MODE_OVER, _("Add"), ACTION_set_mode_add, ICON_MODE_ADD}, 36 | {MODE_SUB, _("Sub"), ACTION_set_mode_sub, ICON_MODE_SUB}, 37 | {MODE_PAINT, _("Paint"), ACTION_set_mode_paint, ICON_MODE_PAINT}, 38 | }; 39 | // XXX: almost the same as in tools_panel. 40 | gui_group_begin(NULL); 41 | gui_row_begin(0); 42 | for (i = 0; i < ARRAY_SIZE(values); i++) { 43 | v = goxel.painter.mode == values[i].mode; 44 | action = action_get(values[i].action, true); 45 | sprintf(label, "%s (%s)", values[i].label, action->shortcut); 46 | if (gui_selectable_icon(label, &v, values[i].icon)) { 47 | action_exec(action); 48 | } 49 | } 50 | gui_row_end(); 51 | gui_group_end(); 52 | return 0; 53 | } 54 | 55 | void gui_top_bar(void) 56 | { 57 | gui_row_begin(0); { 58 | gui_group_begin(NULL); { 59 | gui_row_begin(0); { 60 | gui_action_button(ACTION_undo, NULL, 0); 61 | gui_action_button(ACTION_redo, NULL, 0); 62 | } gui_row_end(); 63 | } gui_group_end(); 64 | gui_row_begin(0); { 65 | gui_action_button(ACTION_layer_clear, NULL, 0); 66 | gui_mode_select(); 67 | gui_color("##color", goxel.painter.color); 68 | } gui_row_end(); 69 | } gui_row_end(); 70 | } 71 | 72 | #endif // GUI_CUSTOM_TOPBAR 73 | -------------------------------------------------------------------------------- /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, _("Background")}, 29 | {goxel.grid_color, _("Grid")}, 30 | {goxel.image_box_color, _("Box")}, 31 | }; 32 | int i; 33 | 34 | gui_text(_("Colors")); 35 | for (i = 0; i < (int)ARRAY_SIZE(COLORS); i++) { 36 | gui_color_small(tr(COLORS[i].label), COLORS[i].color); 37 | } 38 | gui_checkbox(_("Hide Box"), &goxel.hide_box, NULL); 39 | 40 | gui_text(_("Effects")); 41 | 42 | if (gui_input_float(_("Occlusion"), &goxel.rend.settings.occlusion_strength, 43 | 0.1, 0, 1, NULL)) { 44 | goxel.rend.settings.occlusion_strength = 45 | clamp(goxel.rend.settings.occlusion_strength, 0, 1); 46 | } 47 | if (gui_input_float(_("Smoothness"), &goxel.rend.settings.smoothness, 48 | 0.1, 0, 1, NULL)) { 49 | goxel.rend.settings.smoothness = 50 | clamp(goxel.rend.settings.smoothness, 0, 1); 51 | } 52 | 53 | gui_checkbox_flag(_("Grid"), &goxel.view_effects, EFFECT_GRID, NULL); 54 | gui_checkbox_flag(_("Edges"), &goxel.view_effects, EFFECT_EDGES, NULL); 55 | gui_checkbox_flag(_("Shadeless"), 56 | &goxel.rend.settings.effects, EFFECT_UNLIT, NULL); 57 | gui_checkbox_flag(_("Border"), 58 | &goxel.rend.settings.effects, EFFECT_BORDERS, NULL); 59 | gui_checkbox_flag(_("Transparent"), 60 | &goxel.rend.settings.effects, EFFECT_SEE_BACK, NULL); 61 | gui_checkbox_flag(_("Marching Cubes"), 62 | &goxel.rend.settings.effects, EFFECT_MARCHING_CUBES, NULL); 63 | 64 | if (goxel.rend.settings.effects & EFFECT_MARCHING_CUBES) { 65 | gui_checkbox_flag(_("Smooth"), &goxel.rend.settings.effects, 66 | EFFECT_MC_SMOOTH, NULL); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/i18n.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2015-present 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 "i18n.h" 20 | 21 | #include "goxel.h" 22 | #include "utils/mo_reader.h" 23 | 24 | static const tr_lang_t LANGUAGES[] = { 25 | { "en", "English" }, 26 | { "fr", "Français" }, 27 | {}, 28 | }; 29 | 30 | static int current_lang_idx = 0; 31 | static mo_file_t *mo_file = NULL; 32 | 33 | const tr_lang_t *tr_get_supported_languages(void) 34 | { 35 | return LANGUAGES; 36 | } 37 | 38 | void tr_set_language(const char *id) 39 | { 40 | int i, size; 41 | const void *data; 42 | char uri[128]; 43 | 44 | if (strcmp(LANGUAGES[current_lang_idx].id, id) == 0) return; 45 | for (i = 0; i < ARRAY_SIZE(LANGUAGES); i++) { 46 | if (strcmp(LANGUAGES[i].id, id) == 0) { 47 | LOG_D("Set lang '%s'", LANGUAGES[i].id); 48 | mo_close(mo_file); 49 | mo_file = NULL; 50 | current_lang_idx = i; 51 | if (i == 0) { // English: no need for mo file. 52 | break; 53 | } 54 | snprintf(uri, sizeof(uri), "asset://data/locale/%s.mo", 55 | LANGUAGES[i].id); 56 | data = assets_get(uri, &size); 57 | assert(data); 58 | mo_file = mo_open_from_data((void *)data, size, false); 59 | break; 60 | } 61 | } 62 | } 63 | 64 | const tr_lang_t *tr_get_language(void) 65 | { 66 | return &LANGUAGES[current_lang_idx]; 67 | } 68 | 69 | const char *tr(const char *str) 70 | { 71 | if (mo_file == NULL) { 72 | return str; 73 | } 74 | return mo_get(mo_file, str) ?: str; 75 | } 76 | -------------------------------------------------------------------------------- /src/i18n.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2015-present 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 once 20 | 21 | #define _(x) tr(x) 22 | #define N_(x) x 23 | 24 | typedef struct { 25 | const char *id; 26 | const char *name; 27 | } tr_lang_t; 28 | 29 | void tr_set_language(const char *id); 30 | const tr_lang_t *tr_get_language(void); 31 | const tr_lang_t *tr_get_supported_languages(void); 32 | const char *tr(const char *str); 33 | -------------------------------------------------------------------------------- /src/imgui.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 | * Just include the imgui cpp files, so that we don't have to handle them 21 | * in the Scons file. 22 | */ 23 | 24 | // Prevent warnings with gcc. 25 | #ifndef __clang__ 26 | #pragma GCC diagnostic push 27 | #if __GNUC__ >= 8 28 | #pragma GCC diagnostic ignored "-Wclass-memaccess" 29 | #pragma GCC diagnostic ignored "-Wstringop-truncation" 30 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 31 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" 32 | #endif 33 | #endif 34 | 35 | #define IMGUI_DEFINE_MATH_OPERATORS 36 | // #define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 37 | 38 | #include "../ext_src/imgui/imgui.cpp" 39 | #include "../ext_src/imgui/imgui_draw.cpp" 40 | #include "../ext_src/imgui/imgui_widgets.cpp" 41 | #include "../ext_src/imgui/imgui_tables.cpp" 42 | 43 | #include "../ext_src/imgui/ImGuizmo.cpp" 44 | 45 | #ifdef __clang__ 46 | #pragma GCC diagnostic pop 47 | #endif 48 | -------------------------------------------------------------------------------- /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_LEFT_CONTROL = 341, 42 | KEY_LEFT_ALT = 342, 43 | KEY_RIGHT_SHIFT = 344, 44 | KEY_RIGHT_CONTROL = 345, 45 | }; 46 | 47 | // A finger touch or mouse click state. 48 | // `down` represent each button in the mouse. For touch events only the 49 | // first element is set. 50 | typedef struct { 51 | float pos[2]; 52 | bool down[3]; 53 | } touch_t; 54 | 55 | typedef struct { 56 | int top; 57 | int bottom; 58 | int left; 59 | int right; 60 | } margins_t; 61 | 62 | typedef struct inputs 63 | { 64 | int window_size[2]; 65 | float scale; 66 | bool keys[512]; // Table of all the pressed keys. 67 | uint32_t chars[16]; 68 | touch_t touches[4]; 69 | float mouse_wheel; 70 | int framebuffer; // Screen framebuffer 71 | 72 | // Screen safe margins, used for iOS only. 73 | margins_t safe_margins; 74 | 75 | } inputs_t; 76 | 77 | // Conveniance function to add a char in the inputs. 78 | void inputs_insert_char(inputs_t *inputs, uint32_t c); 79 | 80 | #endif // INPUTS_H 81 | -------------------------------------------------------------------------------- /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 "volume.h" 24 | #include "shape.h" 25 | #include "utils/texture.h" 26 | 27 | typedef struct layer layer_t; 28 | 29 | struct layer { 30 | int ref; 31 | layer_t *next, *prev; 32 | volume_t *volume; 33 | const material_t *material; 34 | int id; // Uniq id in the image (for clones). 35 | bool visible; 36 | char name[256]; // 256 chars max. 37 | float box[4][4]; // Bounding box. 38 | float mat[4][4]; 39 | int mode; // Volume 'blending' mode (from volume_utils.h). 40 | // For 2d image layers. 41 | texture_t *image; 42 | // For clone layers: 43 | int base_id; 44 | uint64_t base_volume_key; 45 | // For shape layers. 46 | const shape_t *shape; 47 | uint32_t shape_key; 48 | uint8_t color[4]; 49 | }; 50 | 51 | layer_t *layer_new(const char *name); 52 | void layer_delete(layer_t *layer); 53 | uint32_t layer_get_key(const layer_t *layer); 54 | layer_t *layer_copy(layer_t *other); 55 | 56 | /* 57 | * Function: layer_get_bounding_box 58 | * Return the layer box if set, otherwise the bounding box of the layer 59 | * volume. 60 | */ 61 | void layer_get_bounding_box(const layer_t *layer, float box[4][4]); 62 | 63 | #endif // LAYER_H 64 | -------------------------------------------------------------------------------- /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/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 | 20 | #include "material.h" 21 | #include "xxhash.h" 22 | 23 | #include 24 | #include 25 | 26 | 27 | material_t *material_new(const char *name) 28 | { 29 | material_t *m = calloc(1, sizeof(*m)); 30 | *m = MATERIAL_DEFAULT; 31 | if (name) snprintf(m->name, sizeof(m->name), "%s", name); 32 | return m; 33 | } 34 | 35 | void material_delete(material_t *m) 36 | { 37 | if (!m) return; 38 | if (--m->ref > 0) return; 39 | free(m); 40 | } 41 | 42 | material_t *material_copy(const material_t *other) 43 | { 44 | material_t *m = malloc(sizeof(*m)); 45 | *m = *other; 46 | m->ref = 1; 47 | m->next = m->prev = NULL; 48 | return m; 49 | } 50 | 51 | uint32_t material_get_hash(const material_t *m) 52 | { 53 | uint32_t ret = 0; 54 | ret = XXH32(&m->metallic, sizeof(m->metallic), ret); 55 | ret = XXH32(&m->roughness, sizeof(m->roughness), ret); 56 | ret = XXH32(&m->base_color, sizeof(m->base_color), ret); 57 | return ret; 58 | } 59 | -------------------------------------------------------------------------------- /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 | int ref; 27 | material_t *next, *prev; // List of materials in an image. 28 | char name[128]; // 127 chars max. 29 | float metallic; 30 | float roughness; 31 | float base_color[4]; // Linear color. 32 | float emission[3]; 33 | }; 34 | 35 | #define MATERIAL_DEFAULT (material_t){ \ 36 | .ref = 1, \ 37 | .name = {}, \ 38 | .metallic = 0.2, \ 39 | .roughness = 0.5, \ 40 | .base_color = {1, 1, 1, 1}} 41 | 42 | material_t *material_new(const char *name); 43 | void material_delete(material_t *m); 44 | material_t *material_copy(const material_t *mat); 45 | uint32_t material_get_hash(const material_t *m); 46 | 47 | #endif // MATERIAL_H 48 | -------------------------------------------------------------------------------- /src/meshoptimizer.cpp: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2023-present 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 "../ext_src/meshoptimizer/meshoptimizer.h" 20 | #include "../ext_src/meshoptimizer/allocator.cpp" 21 | #include "../ext_src/meshoptimizer/clusterizer.cpp" 22 | #include "../ext_src/meshoptimizer/indexcodec.cpp" 23 | #include "../ext_src/meshoptimizer/indexgenerator.cpp" 24 | #include "../ext_src/meshoptimizer/overdrawanalyzer.cpp" 25 | #include "../ext_src/meshoptimizer/overdrawoptimizer.cpp" 26 | #include "../ext_src/meshoptimizer/simplifier.cpp" 27 | #include "../ext_src/meshoptimizer/spatialorder.cpp" 28 | #include "../ext_src/meshoptimizer/stripifier.cpp" 29 | #include "../ext_src/meshoptimizer/vcacheanalyzer.cpp" 30 | #include "../ext_src/meshoptimizer/vcacheoptimizer.cpp" 31 | #include "../ext_src/meshoptimizer/vertexcodec.cpp" 32 | #include "../ext_src/meshoptimizer/vertexfilter.cpp" 33 | #include "../ext_src/meshoptimizer/vfetchanalyzer.cpp" 34 | #include "../ext_src/meshoptimizer/vfetchoptimizer.cpp" 35 | -------------------------------------------------------------------------------- /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 | #ifndef PALETTE_H 22 | #define PALETTE_H 23 | 24 | #include 25 | #include 26 | 27 | typedef struct { 28 | uint8_t color[4]; 29 | char name[256]; 30 | } palette_entry_t; 31 | 32 | typedef struct palette palette_t; 33 | struct palette { 34 | palette_t *next, *prev; // For the global list of palettes. 35 | char name[128]; 36 | int columns; 37 | int size; 38 | int allocated; 39 | palette_entry_t *entries; 40 | }; 41 | 42 | // Load all the available palettes into a list. 43 | void palette_load_all(palette_t **list); 44 | 45 | /* 46 | * Function: palette_search 47 | * Search a given color in a palette 48 | * 49 | * Parameters: 50 | * palette - A palette. 51 | * col - The color we are looking for. 52 | * exact - If set to true, return -1 if no color is found, else 53 | * return the closest color. 54 | * 55 | * Return: 56 | * The index of the color in the palette. 57 | */ 58 | int palette_search(const palette_t *palette, const uint8_t col[4], 59 | bool exact); 60 | 61 | void palette_insert(palette_t *p, const uint8_t col[4], const char *name); 62 | 63 | #endif // PALETTE_H 64 | -------------------------------------------------------------------------------- /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 | bool force_restart; 46 | texture_t *texture; 47 | pathtracer_internal_t *p; 48 | int num_samples; 49 | int 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/quickjs.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2022-present 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 ignored "-Wunused-variable" 20 | #pragma GCC diagnostic ignored "-Wunused-but-set-variable" 21 | #pragma GCC diagnostic ignored "-Wimplicit-const-int-float-conversion" 22 | 23 | #define CONFIG_VERSION "2021-03-27" 24 | 25 | #include "../ext_src/quickjs/cutils.c" 26 | #include "../ext_src/quickjs/libregexp.c" 27 | #include "../ext_src/quickjs/libunicode.c" 28 | #include "../ext_src/quickjs/quickjs-libc.c" 29 | #include "../ext_src/quickjs/repl.c" 30 | #define is_digit is_digit2 31 | #define compute_stack_size compute_stack_size2 32 | #include "../ext_src/quickjs/quickjs.c" 33 | -------------------------------------------------------------------------------- /src/script.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2023-present 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 SCRIPT_H 20 | #define SCRIPT_H 21 | 22 | /* 23 | * Function: script_run 24 | * Run a lua script from a file. 25 | */ 26 | int script_run_from_file(const char *filename, int argc, const char **argv); 27 | 28 | void script_init(void); 29 | 30 | /* 31 | * List all the registered scripts to show in the script menu. 32 | */ 33 | void script_iter_all(void *user, void (*f)(void *user, const char *name)); 34 | 35 | /* 36 | * Execute a registered script. 37 | */ 38 | int script_execute(const char *name); 39 | 40 | 41 | #endif // SCRIPT_H 42 | -------------------------------------------------------------------------------- /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 | 20 | #include "goxel.h" 21 | 22 | #include "shader_cache.h" 23 | 24 | typedef struct { 25 | char key[256]; 26 | gl_shader_t *shader; 27 | } shader_t; 28 | 29 | static shader_t g_shaders[16] = {}; 30 | 31 | gl_shader_t *shader_get(const char *name, const shader_define_t *defines, 32 | const char **attr_names, 33 | void (*on_created)(gl_shader_t *s)) 34 | { 35 | int i; 36 | shader_t *s = NULL; 37 | const char *code; 38 | char key[256]; 39 | char path[128]; 40 | char pre[256] = {}; 41 | const shader_define_t *define; 42 | 43 | 44 | // Create the key of the form: 45 | // _define1_define2 46 | strcpy(key, name); 47 | for (define = defines; define && define->name; define++) { 48 | if (define->set) { 49 | strcat(key, "_"); 50 | strcat(key, define->name); 51 | } 52 | } 53 | 54 | for (i = 0; i < ARRAY_SIZE(g_shaders); i++) { 55 | s = &g_shaders[i]; 56 | if (!*s->key) break; 57 | if (strcmp(s->key, key) == 0) 58 | return s->shader; 59 | } 60 | assert(i < ARRAY_SIZE(g_shaders)); 61 | strcpy(s->key, key); 62 | 63 | sprintf(path, "asset://data/shaders/%s.glsl", name); 64 | code = assets_get(path, NULL); 65 | assert(code); 66 | 67 | for (define = defines; define && define->name; define++) { 68 | if (define->set) 69 | sprintf(pre + strlen(pre), "#define %s\n", define->name); 70 | } 71 | s->shader = gl_shader_create(code, code, pre, attr_names); 72 | if (on_created) on_created(s->shader); 73 | return s->shader; 74 | } 75 | 76 | /* 77 | * Function: shaders_release_all 78 | * Remove all the shaders from the cache. 79 | */ 80 | void shaders_release_all(void) 81 | { 82 | int i; 83 | shader_t *s = NULL; 84 | for (i = 0; i < ARRAY_SIZE(g_shaders); i++) { 85 | s = &g_shaders[i]; 86 | if (!*s->key) break; 87 | gl_shader_delete(s->shader); 88 | memset(s, 0, sizeof(*s)); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 "volume_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 | TOOL_RECT_SELECT, 39 | 40 | TOOL_COUNT 41 | }; 42 | 43 | enum { 44 | // Tools flags. 45 | TOOL_REQUIRE_CAN_EDIT = 1 << 0, // Set to tools that can edit the layer. 46 | TOOL_REQUIRE_CAN_MOVE = 1 << 1, // Set to tools that can move the layer. 47 | TOOL_ALLOW_PICK_COLOR = 1 << 2, // Ctrl switches to pick color tool. 48 | TOOL_SHOW_MASK = 1 << 3, 49 | TOOL_SHOW_SELECTION_BOX = 1 << 4, 50 | }; 51 | 52 | // Tools 53 | typedef struct tool tool_t; 54 | struct tool { 55 | int id; 56 | const char *action_id; 57 | int action_idx; 58 | void (*init_fn)(tool_t *tool); 59 | int (*iter_fn)(tool_t *tool, const painter_t *painter, 60 | const float viewport[4]); 61 | int (*gui_fn)(tool_t *tool); 62 | const char *default_shortcut; 63 | int state; // XXX: to be removed I guess. 64 | int flags; 65 | const char *name; 66 | }; 67 | 68 | #define TOOL_REGISTER(id_, name_, klass_, ...) \ 69 | static klass_ GOX_tool_##id_ = {\ 70 | .tool = { \ 71 | .action_idx = ACTION_tool_set_##name_, \ 72 | .id = id_, .action_id = "tool_set_" #name_, __VA_ARGS__ \ 73 | } \ 74 | }; \ 75 | static void GOX_register_tool_##tool_(void) __attribute__((constructor)); \ 76 | static void GOX_register_tool_##tool_(void) { \ 77 | tool_register_(&GOX_tool_##id_.tool); \ 78 | } 79 | 80 | void tool_register_(tool_t *tool); 81 | const tool_t *tool_get(int id); 82 | 83 | int tool_iter(tool_t *tool, const painter_t *painter, const float viewport[4]); 84 | int tool_gui(tool_t *tool); 85 | 86 | int tool_gui_mask_mode(int *value); 87 | int tool_gui_shape(const shape_t **shape); 88 | int tool_gui_radius(void); 89 | int tool_gui_smoothness(void); 90 | int tool_gui_color(void); 91 | 92 | #endif // TOOLS_H 93 | -------------------------------------------------------------------------------- /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 | return 0; 31 | } 32 | 33 | static int gui(tool_t *tool) 34 | { 35 | tool_gui_color(); 36 | return 0; 37 | } 38 | 39 | TOOL_REGISTER(TOOL_PICK_COLOR, pick_color, tool_pick_color_t, 40 | .name = N_("Color Picker"), 41 | .iter_fn = tool_color_picker_iter, 42 | .gui_fn = gui, 43 | .default_shortcut = "C", 44 | .flags = TOOL_ALLOW_PICK_COLOR, 45 | ) 46 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | * Parameters: 32 | * name - A global static string used for debugging only. 33 | * size - The max size of the cache. 34 | */ 35 | cache_t *cache_create(const char *name, int size); 36 | 37 | /* 38 | * Function: cache_add 39 | * Add an item into the cache. 40 | * 41 | * Parameters: 42 | * cache - A cache_t instance. 43 | * key - Unique key data for the cache item. 44 | * keylen - Size of the key data. 45 | * data - Pointer to the item data. The cache takes ownership. 46 | * cost - Cost of the data used to compute the cache usage. 47 | * It doesn't have to be the size. 48 | * delfunc - Function that the cache can use to free the data. 49 | */ 50 | void cache_add(cache_t *cache, const void *key, int keylen, void *data, 51 | int cost, int (*delfunc)(void *data)); 52 | 53 | /* 54 | * Function: cache_get 55 | * Retreive an item from the cache. 56 | * 57 | * Parameters: 58 | * cache - A cache_t instance. 59 | * key - Unique key data for the item. 60 | * keylen - Sizeo of the key data. 61 | * 62 | * Returns: 63 | * The data owned by the cache, or NULL if no item with this key is in 64 | * the cache. 65 | */ 66 | void *cache_get(cache_t *cache, const void *key, int keylen); 67 | 68 | /* 69 | * Function: cache_clear 70 | * Delete all the cached items. 71 | */ 72 | void cache_clear(cache_t *cache); 73 | 74 | /* 75 | * Function: cache_delete 76 | * Delete a cache. 77 | */ 78 | void cache_delete(cache_t *cache); 79 | 80 | 81 | #endif // CACHE_H 82 | -------------------------------------------------------------------------------- /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 | 23 | void srgb8_to_rgb(const uint8_t srgb[3], float rgb[3]) 24 | { 25 | // https://en.wikipedia.org/wiki/SRGB 26 | float c; 27 | int i; 28 | for (i = 0; i < 3; i++) { 29 | c = srgb[i] / 255.f; 30 | c = (c <= 0.04045f) ? (c / 12.92f) : pow((c + 0.055) / 1.055, 2.4); 31 | rgb[i] = c; 32 | } 33 | } 34 | 35 | void rgb_to_srgb8(const float rgb[3], uint8_t srgb[3]) 36 | { 37 | // https://en.wikipedia.org/wiki/SRGB 38 | float c; 39 | int i, b; 40 | for (i = 0; i < 3; i++) { 41 | c = rgb[i]; 42 | c = (c <= 0.0031308f) ? 12.92f * c 43 | : (1.055f) * pow(c, 1 / 2.4f) - 0.055f; 44 | b = c * 255 + 0.5; 45 | if (b < 0) b = 0; 46 | if (b > 255) b = 255; 47 | srgb[i] = b; 48 | } 49 | } 50 | 51 | void srgba8_to_rgba(const uint8_t srgba[4], float rgba[4]) 52 | { 53 | srgb8_to_rgb(srgba, rgba); 54 | rgba[3] = srgba[3] / 255.f; 55 | } 56 | -------------------------------------------------------------------------------- /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 | /* 25 | * Convert from sRGB uint8 to linear RGB float. 26 | */ 27 | void srgb8_to_rgb(const uint8_t srgba[3], float rgba[3]); 28 | 29 | /* 30 | * Convert from linear RGB float to sRGB uint8. 31 | */ 32 | void rgb_to_srgb8(const float rgb[3], uint8_t srgb[3]); 33 | 34 | /* 35 | * Convert from sRGBA uint8 to linear RGBA float. 36 | */ 37 | void srgba8_to_rgba(const uint8_t srgba[4], float rgba[4]); 38 | 39 | #endif // COLOR_H 40 | -------------------------------------------------------------------------------- /src/utils/geometry.c: -------------------------------------------------------------------------------- 1 | 2 | /* Goxel 3D voxels editor 3 | * 4 | * copyright (c) 2024-present Guillaume Chereau 5 | * 6 | * Goxel is free software: you can redistribute it and/or modify it under the 7 | * terms of the GNU General Public License as published by the Free Software 8 | * Foundation, either version 3 of the License, or (at your option) any later 9 | * version. 10 | 11 | * Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | 16 | * You should have received a copy of the GNU General Public License along with 17 | * goxel. If not, see . 18 | */ 19 | 20 | #include "geometry.h" 21 | 22 | #include 23 | #include 24 | 25 | static float dot(const float a[3], const float b[3]) 26 | { 27 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; 28 | } 29 | 30 | /* 31 | * Function to compute the distance between two rays and find the closest 32 | * points 33 | */ 34 | float rays_distance(const float o1[3], const float d1[3], 35 | const float o2[3], const float d2[3], 36 | float *t1, float *t2) 37 | { 38 | float u[3], v[3], w[3]; 39 | float a, b, c, d, e, det, sc, tc; 40 | float dp[3]; 41 | float p1[3], p2[3]; 42 | 43 | u[0] = d1[0]; 44 | u[1] = d1[1]; 45 | u[2] = d1[2]; 46 | 47 | v[0] = d2[0]; 48 | v[1] = d2[1]; 49 | v[2] = d2[2]; 50 | 51 | w[0] = o1[0] - o2[0]; 52 | w[1] = o1[1] - o2[1]; 53 | w[2] = o1[2] - o2[2]; 54 | 55 | a = dot(u, u); 56 | b = dot(u, v); 57 | c = dot(v, v); 58 | d = dot(u, w); 59 | e = dot(v, w); 60 | 61 | det = a * c - b * b; 62 | 63 | if (det < 1e-8) { 64 | sc = 0.0; 65 | tc = (b > c ? d / b : e / c); 66 | } else { 67 | sc = (b * e - c * d) / det; 68 | tc = (a * e - b * d) / det; 69 | } 70 | 71 | if (t1) *t1 = sc; 72 | if (t2) *t2 = tc; 73 | 74 | p1[0] = o1[0] + sc * u[0]; 75 | p1[1] = o1[1] + sc * u[1]; 76 | p1[2] = o1[2] + sc * u[2]; 77 | 78 | p2[0] = o2[0] + tc * v[0]; 79 | p2[1] = o2[1] + tc * v[1]; 80 | p2[2] = o2[2] + tc * v[2]; 81 | 82 | dp[0] = p1[0] - p2[0]; 83 | dp[1] = p1[1] - p2[1]; 84 | dp[2] = p1[2] - p2[2]; 85 | return sqrt(dot(dp, dp)); 86 | } 87 | -------------------------------------------------------------------------------- /src/utils/geometry.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2024-present 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 to compute the distance between two rays and find the closest 21 | * points 22 | */ 23 | float rays_distance(const float o1[3], const float d1[3], 24 | const float o2[3], const float d2[3], 25 | float *t1, float *t2); 26 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 "../../ext_src/inih/ini.c" 24 | 25 | #pragma GCC diagnostic pop 26 | -------------------------------------------------------------------------------- /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 "../../ext_src/inih/ini.h" 23 | -------------------------------------------------------------------------------- /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 "../../ext_src/json/json.h" 23 | #include "../../ext_src/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 | -------------------------------------------------------------------------------- /src/utils/mo_reader.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2024-Present 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 "mo_reader.h" 20 | #include "../../ext_src/stb/stb_ds.h" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | typedef struct { 27 | char *key; 28 | char *value; 29 | } entry_t; 30 | 31 | struct mo_file { 32 | void *data; 33 | entry_t *entries; 34 | bool free_data; 35 | }; 36 | 37 | typedef struct { 38 | int32_t magic; 39 | int32_t version; 40 | int32_t count; 41 | int32_t offset_original; 42 | int32_t offset_translation; 43 | int32_t hashtable_size; 44 | int32_t offset_hashtable; 45 | } header_t; 46 | 47 | mo_file_t *mo_open_from_data(void *data, int size, bool free_data) 48 | { 49 | 50 | mo_file_t *mo; 51 | header_t *header; 52 | int i, or_len, or_ofs, tr_len, tr_ofs; 53 | 54 | mo = calloc(1, sizeof(*mo)); 55 | mo->data = data; 56 | mo->free_data = free_data; 57 | if (!data) return mo; 58 | 59 | header = data; 60 | assert(header->magic == 0x950412DE); 61 | 62 | (void)or_len; 63 | (void)tr_len; 64 | for (i = 0; i < header->count; i++) { 65 | or_len = *(uint32_t *)(data + header->offset_original + i * 8 + 0); 66 | or_ofs = *(uint32_t *)(data + header->offset_original + i * 8 + 4); 67 | tr_len = *(uint32_t *)(data + header->offset_translation + i * 8 + 0); 68 | tr_ofs = *(uint32_t *)(data + header->offset_translation + i * 8 + 4); 69 | if (tr_len == 0) continue; 70 | assert(*((char *)(data + or_ofs + or_len)) == '\0'); 71 | assert(*((char *)(data + tr_ofs + tr_len)) == '\0'); 72 | shput(mo->entries, (char *)data + or_ofs, (char *)data + tr_ofs); 73 | } 74 | 75 | return mo; 76 | } 77 | 78 | void mo_close(mo_file_t *mo) 79 | { 80 | if (!mo) return; 81 | shfree(mo->entries); 82 | if (mo->free_data) { 83 | free(mo->data); 84 | } 85 | free(mo); 86 | } 87 | 88 | const char *mo_get(mo_file_t *mo, const char *str) 89 | { 90 | if (!mo->data) return NULL; 91 | return shget(mo->entries, str); 92 | } 93 | -------------------------------------------------------------------------------- /src/utils/mo_reader.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2024-Present 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 | * Simple interface to read gettext mo files. 21 | */ 22 | 23 | #include 24 | 25 | typedef struct mo_file mo_file_t; 26 | 27 | mo_file_t *mo_open_from_data(void *data, int size, bool free_data); 28 | 29 | void mo_close(mo_file_t *mo); 30 | 31 | const char *mo_get(mo_file_t *mo, const char *str); 32 | -------------------------------------------------------------------------------- /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/utils/path.c: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2024-present 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 "path.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | char *path_dirname(const char *path, char *out, size_t size) 26 | { 27 | char *sep; 28 | int len; 29 | 30 | assert(path); 31 | assert(path != out); 32 | sep = strrchr(path, '/'); 33 | #ifdef WIN32 34 | if (!sep) { 35 | sep = strrchr(path, '\\'); 36 | } 37 | #endif 38 | if (sep == NULL) { 39 | out[0] = '\0'; 40 | return NULL; 41 | } 42 | len = (int)(sep - path); 43 | snprintf(out, size, "%.*s", len, path); 44 | return out; 45 | } 46 | 47 | char *path_basename(const char *path, char *out, size_t size) 48 | { 49 | char *sep; 50 | int len; 51 | 52 | assert(path); 53 | assert(path != out); 54 | sep = strrchr(path, '/'); 55 | #ifdef WIN32 56 | if (!sep) { 57 | sep = strrchr(path, '\\'); 58 | } 59 | #endif 60 | if (sep == NULL) { 61 | snprintf(out, size, "%s", path); 62 | return out; 63 | } 64 | len = (int)(sep - path); 65 | snprintf(out, size, "%s", path + len + 1); 66 | return out; 67 | } 68 | 69 | bool path_normalize(char *path) 70 | { 71 | int i; 72 | for (i = 0; i < strlen(path); i++) { 73 | if (path[i] == '\\') path[i] = '/'; 74 | } 75 | return true; 76 | } 77 | -------------------------------------------------------------------------------- /src/utils/path.h: -------------------------------------------------------------------------------- 1 | /* Goxel 3D voxels editor 2 | * 3 | * copyright (c) 2024-present 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 | * Some utils functions to manipulate paths. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | char *path_dirname(const char *path, char *out, size_t size); 27 | 28 | char *path_basename(const char *path, char *out, size_t size); 29 | 30 | bool path_normalize(char *path); 31 | -------------------------------------------------------------------------------- /src/utils/sound.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 20 | 21 | void sound_init(void); 22 | void sound_register(const char *name, const char *wav_data); 23 | void sound_play(const char *name, float volume, float pitch); 24 | void sound_iter(void); 25 | 26 | bool sound_is_enabled(void); 27 | void sound_set_enabled(bool v); 28 | -------------------------------------------------------------------------------- /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/xxhash.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 | #define XXH_NO_LONG_LONG 20 | #include "../ext_src/xxhash/xxhash.c" 21 | -------------------------------------------------------------------------------- /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 "-Wunknown-warning-option" 32 | #pragma GCC diagnostic ignored "-Wunused-function" 33 | #pragma GCC diagnostic ignored "-Wunused-variable" 34 | #pragma GCC diagnostic ignored "-Wcomma" 35 | #pragma GCC diagnostic ignored "-Wunused-but-set-variable" 36 | 37 | #ifndef __clang__ 38 | #pragma GCC diagnostic ignored "-Wsign-compare" 39 | #pragma GCC diagnostic ignored "-Wparentheses" 40 | #pragma GCC diagnostic ignored "-Wreturn-type" 41 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 42 | #endif 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | #define STB_IMAGE_STATIC 49 | #define STB_IMAGE_WRITE_STATIC 50 | 51 | // Fix compilation on Windows. 52 | #ifdef NOMINMAX 53 | #undef NOMINMAX 54 | #endif 55 | 56 | 57 | #include "../ext_src/yocto/yocto_bvh.cpp" 58 | #include "../ext_src/yocto/yocto_image.cpp" 59 | #include "../ext_src/yocto/yocto_scene.cpp" 60 | #define split_middle split_middle_ 61 | #define bvh_max_prims bvh_max_prims_ 62 | #include "../ext_src/yocto/yocto_shape.cpp" 63 | #include "../ext_src/yocto/yocto_trace.cpp" 64 | 65 | #pragma GCC diagnostic pop 66 | 67 | #define STB_IMAGE_RESIZE_IMPLEMENTATION 68 | #include "../ext_src/stb/stb_image_resize.h" 69 | 70 | #endif // YOCTO 71 | -------------------------------------------------------------------------------- /svg/glyphs/mouse_lmb.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 36 | 41 | 42 | 44 | 48 | 56 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /svg/glyphs/mouse_mmb.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 36 | 41 | 42 | 44 | 48 | 56 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /svg/glyphs/mouse_rmb.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 36 | 41 | 42 | 44 | 48 | 56 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /tools/create_font.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | # Goxel 3D voxels editor 4 | # 5 | # copyright (c) 2024-present Guillaume Chereau 6 | # 7 | # Goxel is free software: you can redistribute it and/or modify it under the 8 | # terms of the GNU General Public License as published by the Free Software 9 | # Foundation, either version 3 of the License, or (at your option) any later 10 | # version. 11 | # 12 | # Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | # details. 16 | # 17 | # You should have received a copy of the GNU General Public License along with 18 | # goxel. If not, see . 19 | 20 | # Script that generates a font file from the svg images in svg/font/ 21 | 22 | import fontforge 23 | import glob 24 | import sys, os, re 25 | 26 | START_CODE = 0xE660 27 | 28 | def make_font_from_svgs(sources, output): 29 | font = fontforge.font() 30 | font.encoding = "UnicodeFull" 31 | font.fontname = "Goxel" 32 | font.familyname = "Goxel" 33 | font.fullname = "Goxel" 34 | font.version = "1.0.0" 35 | font.weight = "Regular" 36 | font.upos = -100 37 | font.uwidth = 50 38 | font.ascent = 850 39 | font.descent = 150 40 | font.em = 1000 41 | for idx, file in enumerate(sorted(sources)): 42 | assert file.endswith(".svg") 43 | code = START_CODE + idx 44 | glyph_name = file.replace(".svg", "") 45 | glyph = font.createChar(code, glyph_name) 46 | glyph.importOutlines(file) 47 | glyph.width = 1000 48 | font.generate(output) 49 | 50 | sources = glob.glob('svg/glyphs/*.svg') 51 | make_font_from_svgs(sources, "data/fonts/goxel-font.ttf") 52 | -------------------------------------------------------------------------------- /tools/create_icons.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | # Goxel 3D voxels editor 4 | # 5 | # copyright (c) 2018 Guillaume Chereau 6 | # 7 | # Goxel is free software: you can redistribute it and/or modify it under the 8 | # terms of the GNU General Public License as published by the Free Software 9 | # Foundation, either version 3 of the License, or (at your option) any later 10 | # version. 11 | # 12 | # Goxel is distributed in the hope that it will be useful, but WITHOUT ANY 13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | # details. 16 | # 17 | # You should have received a copy of the GNU General Public License along with 18 | # goxel. If not, see . 19 | 20 | # ************************************************************************ 21 | # Create the icon atlas image from all the icons svg files 22 | 23 | import cairosvg 24 | import itertools 25 | import PIL.Image 26 | from shutil import copyfile 27 | import os 28 | import subprocess 29 | import re 30 | 31 | # Convert the svg into one big png file. 32 | cairosvg.svg2png(url='./svg/icons.svg', write_to='/tmp/icons.png', 33 | output_width=370, output_height=352) 34 | 35 | src_img = PIL.Image.open('/tmp/icons.png') 36 | ret_img = PIL.Image.new('RGBA', (512, 512)) 37 | 38 | for x, y in itertools.product(range(8), range(8)): 39 | img = src_img.crop((x * 46 + 2, y * 46 + 2, x * 46 + 46, y * 46 + 46)) 40 | # Make the image white in the special range. 41 | if y >= 2 and y < 5: 42 | tmp = PIL.Image.new('RGBA', (44, 44), (255, 255, 255, 255)) 43 | tmp.putalpha(img.split()[3]) 44 | img = tmp 45 | ret_img.paste(img, (64 * x + 10, 64 * y + 10)) 46 | 47 | ret_img.save('data/images/icons.png') 48 | 49 | # Also create the application icons (in data/icons) 50 | if not os.path.exists('data/icons'): os.makedirs('data/icons') 51 | base = PIL.Image.open('icon.png').convert('RGBA') 52 | 53 | for size in [16, 24, 32, 48, 64, 128, 256]: 54 | img = base.resize((size, size), PIL.Image.BILINEAR) 55 | img.save('data/icons/icon%d.png' % size) 56 | -------------------------------------------------------------------------------- /tools/update-i18n.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Stellarium Web Engine - Copyright (c) 2024-present - Stellarium Labs SRL 4 | # All rights reserved. 5 | 6 | # Generate the mo files from the source po files. 7 | 8 | import json 9 | import contextlib 10 | import glob 11 | import subprocess 12 | import os 13 | 14 | def ensure_dir(file_path): 15 | '''Create a directory for a path if it doesn't exists yet''' 16 | directory = os.path.dirname(file_path) 17 | if not os.path.exists(directory): 18 | os.makedirs(directory) 19 | 20 | def write_pot(values, path): 21 | '''Write a pot file from an array of strings''' 22 | file = open(path, 'w') 23 | file.write('msgid ""\n') 24 | file.write('msgstr ""\n') 25 | file.write('"Content-Type: text/plain; charset=UTF-8\\n"\n') 26 | file.write('"Content-Transfer-Encoding: 8bit\\n"\n') 27 | file.write('"Project-Id-Version: \\n"\n\n') 28 | for value in values: 29 | value = value.replace('"', '\\"') 30 | file.write(f'msgid "{value}"\n') 31 | file.write(f'msgstr ""\n\n') 32 | 33 | 34 | def update_po_files(): 35 | sources = glob.glob('src/**/*.c', recursive=True); 36 | subprocess.check_call([ 37 | 'xgettext', '-k_', '-kN_', '-c', '--from-code=utf-8', 38 | '-o', '/tmp/goxel.pot', *sources]) 39 | for po_file in glob.glob('po/*.po'): 40 | subprocess.check_call([ 41 | 'msgmerge', '--update', po_file, '/tmp/goxel.pot']) 42 | 43 | 44 | def generate_mo_files(): 45 | mo_dir = 'data/locale' 46 | for po_file in glob.glob('po/*.po'): 47 | filename = os.path.basename(po_file).rsplit('.', 1)[0] 48 | mo_file = os.path.join(mo_dir, f'{filename}.mo') 49 | ensure_dir(mo_file) 50 | subprocess.check_call(['msgfmt', po_file, '-o', mo_file, '-c']) 51 | 52 | 53 | def run(): 54 | update_po_files() 55 | generate_mo_files() 56 | 57 | if __name__ == '__main__': 58 | with contextlib.chdir(os.path.join(os.path.dirname(__file__), '../')): 59 | run() 60 | --------------------------------------------------------------------------------