diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..83658e1
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,50 @@
+AccessModifierOffset: -1
+AlignAfterOpenBracket: AlwaysBreak
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: true
+AlignOperands: false
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: Inline
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: false
+BinPackParameters: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Allman
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: true
+BreakStringLiterals: true
+ColumnLimit: 100
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DisableFormat: false
+FixNamespaceComments: true
+IncludeCategories:
+ - Regex: '^<'
+ Priority: 1
+ - Regex: '^"'
+ Priority: 2
+IndentCaseLabels: true
+IndentWidth: 2
+KeepEmptyLinesAtTheStartOfBlocks: false
+Language: Cpp
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+PenaltyReturnTypeOnItsOwnLine: 5000
+PointerAlignment: Left
+SortIncludes: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+Standard: Cpp11
+TabWidth: 2
+UseTab: Never
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..e921a8c
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,13 @@
+# Exclude all top-level files and directories (except addons) from zip downloads.
+# This makes installing through the AssetLib easier, because no files and folders
+# need to be unchecked.
+
+/.gitattributes export-ignore
+/.gitignore export-ignore
+/.gitmodules export-ignore
+/.github export-ignore
+/CHANGELOG.md export-ignore
+/README.md export-ignore
+/icon.png export-ignore
+/icon.png.import export-ignore
+/project.godot export-ignore
diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml
new file mode 100644
index 0000000..c2339dd
--- /dev/null
+++ b/.github/dependabot.yaml
@@ -0,0 +1,13 @@
+version: 2
+
+updates:
+- package-ecosystem: github-actions
+ directory: "/"
+ schedule:
+ interval: daily
+ time: '00:00'
+ timezone: UTC
+ open-pull-requests-limit: 10
+ commit-message:
+ prefix: "chore"
+ include: "scope"
diff --git a/.github/worklfows/pre-commit.yaml b/.github/worklfows/pre-commit.yaml
new file mode 100644
index 0000000..3f4f4eb
--- /dev/null
+++ b/.github/worklfows/pre-commit.yaml
@@ -0,0 +1,21 @@
+name: Pre-commit
+
+on:
+ pull_request:
+ push:
+ workflow_dispatch:
+
+jobs:
+ pre-commit:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ - name: Set up Python
+ uses: actions/setup-python@v4
+ with:
+ python-version: 3.8
+ - name: Install GDScript Toolkit
+ run: pip3 install 'gdtoolkit==3.*'
+ - name: Run pre-commit hooks
+ uses: pre-commit/action@v3.0.0
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d8e966d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,10 @@
+# Godot-specific ignores
+.import/
+export.cfg
+
+# Imported translations (automatically generated from CSV files)
+*.translation
+
+# Mono-specific ignores
+.mono/
+data_*/
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..34c51f3
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,35 @@
+repos:
+- repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: v4.3.0
+ hooks:
+ - id: fix-byte-order-marker # Prevents weird UTF-8 encoding edge cases
+ - id: check-case-conflict # Check if case-insensitive filesystems would bork
+ - id: check-docstring-first # Check for if docstring was misplaced
+ - id: check-executables-have-shebangs
+ - id: check-json # Checks for valid json
+ - id: check-merge-conflict # Checks strings that look like a committed merge conflict
+ - id: check-xml # Checks for valid xml
+ - id: check-yaml # Checks for valid yaml
+ - id: end-of-file-fixer # Checks for ending with a newline
+ - id: mixed-line-ending # Consistent LF or CRLF
+ - id: trailing-whitespace # No trailing whitespace
+- repo: local
+ hooks:
+ - id: check-gdscript
+ name: check gdscript
+ entry: gdformat
+ language: system
+ files: \.gd$
+ - id: check-shaders
+ name: check shaders
+ entry: clang-format
+ args:
+ - --style=file
+ - -Werror
+ language: system
+ files: \.shader$
+ - id: lint-gdscript
+ name: lint gdscript
+ entry: gdlint
+ language: system
+ files: \.gd$
\ No newline at end of file
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..14a16b7
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,8 @@
+
+Copyright © 2022 Florian Vazelle
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7c953f5
--- /dev/null
+++ b/README.md
@@ -0,0 +1,24 @@
+
+
+# 🖌️ Brush Addon
+
+![Godot Badge](https://img.shields.io/badge/godot-3.5-blue?logo=Godot-Engine&logoColor=white) ![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white) ![license](https://img.shields.io/badge/license-MIT-green?logo=open-source-initiative&logoColor=white)
+
+A brush tool to quickly place 3D objects for [Godot Engine](https://godotengine.org/).
+
+
+
+## How does it work?
+
+Firstly, switch to brush mode, using the "Brush" button in the toolbar above the viewport.
+
+Select an object (scene, models ...) in your filesystem dock, and move your mouse to place it.
+
+You can :
+- scale it by scrolling
+- rotate it by moving the mouse while holding Shift
+- undo and redo actions
+
+## References
+
+- [godotplacer](https://github.com/mnemoli/godotplacer/) by [mnemoli](https://github.com/mnemoli/)
diff --git a/addons/brush/assets/icons/icon_dark.svg b/addons/brush/assets/icons/icon_dark.svg
new file mode 100644
index 0000000..defb720
--- /dev/null
+++ b/addons/brush/assets/icons/icon_dark.svg
@@ -0,0 +1,22 @@
+
+
+
+
diff --git a/addons/brush/assets/icons/icon_dark.svg.import b/addons/brush/assets/icons/icon_dark.svg.import
new file mode 100644
index 0000000..047a469
--- /dev/null
+++ b/addons/brush/assets/icons/icon_dark.svg.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/icon_dark.svg-e7048a6c98a4dcbf32064bb3a837e4ff.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://addons/brush/assets/icons/icon_dark.svg"
+dest_files=[ "res://.import/icon_dark.svg-e7048a6c98a4dcbf32064bb3a837e4ff.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=true
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+process/normal_map_invert_y=false
+stream=false
+size_limit=0
+detect_3d=true
+svg/scale=1.0
diff --git a/addons/brush/assets/icons/icon_light.svg b/addons/brush/assets/icons/icon_light.svg
new file mode 100644
index 0000000..daa0d99
--- /dev/null
+++ b/addons/brush/assets/icons/icon_light.svg
@@ -0,0 +1,21 @@
+
+
+
+
diff --git a/addons/brush/assets/icons/icon_light.svg.import b/addons/brush/assets/icons/icon_light.svg.import
new file mode 100644
index 0000000..09b765c
--- /dev/null
+++ b/addons/brush/assets/icons/icon_light.svg.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/icon_light.svg-3ba0408cf4dfbbae849f48425382700d.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://addons/brush/assets/icons/icon_light.svg"
+dest_files=[ "res://.import/icon_light.svg-3ba0408cf4dfbbae849f48425382700d.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=true
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+process/normal_map_invert_y=false
+stream=false
+size_limit=0
+detect_3d=true
+svg/scale=1.0
diff --git a/addons/brush/editor_brush_plugin.gd b/addons/brush/editor_brush_plugin.gd
new file mode 100644
index 0000000..e43b564
--- /dev/null
+++ b/addons/brush/editor_brush_plugin.gd
@@ -0,0 +1,207 @@
+tool
+extends EditorPlugin
+
+var PaintButton = preload("res://addons/brush/scenes/paint_button.tscn")
+var TempObjectMat = preload("res://addons/brush/resources/temp_object_mat.tres")
+
+var painting := false
+var placing := false
+
+var _dock: Control = null
+var _resource: PackedScene = null
+var _current_item: Spatial = null
+var _tree: Tree = null
+var _parent_node: Node = null
+
+
+func _enter_tree():
+ _dock = PaintButton.instance() as Control
+ add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, _dock)
+
+ var button := _dock.get_node("Button") as Button
+ button.connect("pressed", self, "toggle_painting")
+ button.set_button_icon(get_plugin_icon())
+
+ var vsplit = get_editor_interface().get_file_system_dock().get_child(3)
+ for c in vsplit.get_children():
+ if c is Tree:
+ _tree = c
+ _tree.connect("cell_selected", self, "file_picked")
+ break
+
+ change_parent_node()
+ get_editor_interface().get_selection().connect("selection_changed", self, "change_parent_node")
+
+
+func _exit_tree():
+ _tree.disconnect("cell_selected", self, "file_picked")
+
+ if _current_item != null and is_instance_valid(_current_item):
+ _current_item.free()
+ _current_item = null
+
+ if _dock != null and is_instance_valid(_dock):
+ remove_control_from_container(CONTAINER_SPATIAL_EDITOR_MENU, _dock)
+
+ var button := _dock.get_node("Button") as Button
+ button.disconnect("pressed", self, "toggle_painting")
+
+ _dock.free()
+ _dock = null
+
+ get_editor_interface().get_selection().disconnect(
+ "selection_changed", self, "change_parent_node"
+ )
+
+
+func get_plugin_icon() -> Texture:
+ var base_color = get_editor_interface().get_editor_settings().get_setting(
+ "interface/theme/base_color"
+ )
+ var theme = "light" if base_color.v > 0.5 else "dark"
+ var base_icon = load("res://addons/brush/assets/icons/icon_%s.svg" % [theme]) as Texture
+
+ var size = get_editor_interface().get_editor_viewport().get_icon("Godot", "EditorIcons").get_size()
+ var image: Image = base_icon.get_data()
+ image.resize(size.x, size.y, Image.INTERPOLATE_TRILINEAR)
+ var texture = ImageTexture.new()
+ texture.create_from_image(image)
+ return texture
+
+
+func change_parent_node():
+ var parent_nodes = get_editor_interface().get_selection().get_selected_nodes()
+ if !parent_nodes.empty():
+ _parent_node = parent_nodes[0]
+ else:
+ _parent_node = get_editor_interface().get_edited_scene_root()
+
+
+func toggle_painting():
+ var button := _dock.get_node("Button") as Button
+ painting = !painting
+ if !painting:
+ if _current_item != null and is_instance_valid(_current_item):
+ _current_item.free()
+ _current_item = null
+ button.pressed = false
+ else:
+ set_up_temp_object()
+ button.pressed = true
+
+
+func forward_spatial_gui_input(camera: Camera, event: InputEvent):
+ if !painting or _current_item == null or not is_instance_valid(_current_item):
+ return false
+
+ if event is InputEventMouseMotion:
+ if Input.is_physical_key_pressed(KEY_SHIFT):
+ _current_item.rotate_object_local(Vector3(0, 1, 0), event.relative.x / 10)
+ return true
+
+ if !placing:
+ var ray_origin := camera.project_ray_origin(event.position)
+ var ray_dir := camera.project_ray_normal(event.position)
+ var ray_distance := camera.far
+ var space_state := get_viewport().world.direct_space_state
+ var hit := space_state.intersect_ray(ray_origin, ray_origin + ray_dir * ray_distance)
+ if !hit.empty() and hit.has("position"):
+ _current_item.global_transform.origin = hit.get("position") as Vector3
+ return false
+
+ elif (
+ event is InputEventMouseButton
+ and event.pressed == true
+ and event.button_index == BUTTON_LEFT
+ ):
+ placing = true
+
+ elif (
+ event is InputEventMouseButton
+ and event.pressed == false
+ and event.button_index == BUTTON_LEFT
+ ):
+ placing = false
+ var undo_redo := get_undo_redo()
+ undo_redo.create_action("Add object")
+
+ var new_item := _resource.instance() as Spatial
+ undo_redo.add_do_method(
+ self, "redo_paint", new_item, _current_item.global_transform, _parent_node
+ )
+ undo_redo.add_do_reference(new_item)
+ undo_redo.add_undo_method(_parent_node, "remove_child", new_item)
+ undo_redo.commit_action()
+ return true
+
+ elif event is InputEventMouse and event.button_index == BUTTON_WHEEL_DOWN:
+ if Input.is_physical_key_pressed(KEY_SHIFT):
+ return false
+
+ _current_item.scale = _current_item.scale * 0.9
+ return true
+
+ elif event is InputEventMouse and event.button_index == BUTTON_WHEEL_UP:
+ if Input.is_physical_key_pressed(KEY_SHIFT):
+ return false
+
+ _current_item.scale = _current_item.scale * 1.1
+ return true
+
+ return false
+
+
+func handles(_object):
+ return true
+
+
+func file_picked():
+ if _current_item != null and is_instance_valid(_current_item):
+ _current_item.free()
+ _current_item = null
+
+ if !painting:
+ return
+
+ set_up_temp_object()
+
+
+func set_up_temp_object() -> void:
+ if _tree == null:
+ var vsplit = get_editor_interface().get_file_system_dock().get_child(3)
+ for c in vsplit.get_children():
+ if c is Tree:
+ _tree = c
+ break
+
+ # get_editor_interface().get_current_path() returns the wrong path at this point
+ # i.e. the previously selected node
+ # So we must get the file tree selected item instead
+ var path := _tree.get_selected().get_metadata(0) as String
+
+ if ResourceLoader.exists(path):
+ _resource = load(path) as PackedScene
+ if _resource != null:
+ _current_item = add_temp_item(_resource)
+ _current_item.set_name("TEMPORARY OBJECT")
+
+
+func add_temp_item(resource: PackedScene) -> Spatial:
+ var new_item := resource.instance() as Spatial
+ get_editor_interface().get_edited_scene_root().add_child(new_item)
+ if new_item is MeshInstance:
+ new_item.material_override = TempObjectMat
+ else:
+ for c in new_item.get_children():
+ if c is MeshInstance:
+ c.material_override = TempObjectMat
+ return new_item
+
+
+func redo_paint(new_item: Spatial, transform: Transform, parent_node: Node):
+ if parent_node == null:
+ parent_node = get_editor_interface().get_edited_scene_root()
+ parent_node.add_child(new_item)
+ new_item.owner = get_editor_interface().get_edited_scene_root()
+ new_item.global_transform.origin = transform.origin
+ new_item.global_transform.basis = transform.basis
diff --git a/addons/brush/plugin.cfg b/addons/brush/plugin.cfg
new file mode 100644
index 0000000..c45d39b
--- /dev/null
+++ b/addons/brush/plugin.cfg
@@ -0,0 +1,7 @@
+[plugin]
+
+name="Brush"
+description="A tool to quickly place 3D objects."
+author="florianvazelle"
+version="0.1.0"
+script="editor_brush_plugin.gd"
diff --git a/addons/brush/resources/temp_object_mat.tres b/addons/brush/resources/temp_object_mat.tres
new file mode 100644
index 0000000..c5b3b0b
--- /dev/null
+++ b/addons/brush/resources/temp_object_mat.tres
@@ -0,0 +1,5 @@
+[gd_resource type="SpatialMaterial" format=2]
+
+[resource]
+flags_transparent = true
+albedo_color = Color( 1, 1, 1, 0.282353 )
diff --git a/addons/brush/scenes/paint_button.tscn b/addons/brush/scenes/paint_button.tscn
new file mode 100644
index 0000000..5e6b0b0
--- /dev/null
+++ b/addons/brush/scenes/paint_button.tscn
@@ -0,0 +1,14 @@
+[gd_scene format=2]
+
+[node name="Control" type="HBoxContainer"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+margin_right = -834.0
+margin_bottom = -560.0
+
+[node name="Button" type="Button" parent="."]
+margin_right = 12.0
+margin_bottom = 40.0
+hint_tooltip = "Brush mode, allowing to place 3D objects quickly"
+toggle_mode = true
+flat = true