Skip to content

Commit

Permalink
added mouse wheel down selection. Added blend file support for Godot …
Browse files Browse the repository at this point in the history
…object placer.
  • Loading branch information
Fleischkuechle committed Jan 22, 2024
1 parent 6ce8323 commit 5b5424d
Show file tree
Hide file tree
Showing 11 changed files with 1,724 additions and 38 deletions.
74 changes: 46 additions & 28 deletions addons/object_placer/object_placer_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,19 @@ extends EditorPlugin
@onready var marker_node_3d:Node3D
@onready var ray_cast = RayCast3D.new()
@onready var new_click_location: Vector2 = Vector2.INF
@onready var the_cube = preload("res://addons/object_placer/objects/the_cube.tscn")
@onready var new_intersection_result_dict:Dictionary={}
@onready var is_mouse_pressed=false
##var editorAddon=preload("res://addons/testplugin/objectPlacer.tscn")
#var dockedScene
@onready var list_of_Resources:ItemList
@onready var directoryPath = "res://addons/object_placer/objects/"
@onready var extension = "tscn"
@onready var foundPaths=[]
@onready var extension_tscn = "tscn"
@onready var extension_blend= "blend"
@onready var sceens_tscn=[]
var enteredTree=false
@onready var last_selected_index:int
@onready var do_we_have_scenes_available=true
@onready var process_mouse_wheel_event=false
#@onready var timer:Timer
#func dir_contents(path):
#var dir = DirAccess.open(path)
#if dir:
#dir.list_dir_begin()
#var file_name:String = dir.get_next()
#while file_name != "":
#if dir.current_is_dir():
#print("Found directory: " + file_name)
#else:
#print("Found file: " + file_name)
#file_name = dir.get_next()
#else:
#print("An error occurred when trying to access the path.")
@onready var process_mouse_wheel_event=false #helper to prevent catching too many mouse wheel events


func getFilePathsByExtension(directoryPath: String, extension: String, recursive: bool = true) -> Array:
Expand Down Expand Up @@ -96,7 +81,6 @@ func preload_sceens(directoryPath: String, extension: String, recursive: bool =
print('no dir ')
return sceens_tscn


func turn_off_collider(in_node):
var Child_nodes_list=[]
Child_nodes_list= get_all_children(in_node,Child_nodes_list)
Expand All @@ -106,7 +90,6 @@ func turn_off_collider(in_node):

#disabling area2d code


func get_all_children(in_node,arr=[]):
arr.push_back(in_node)
for child in in_node.get_children():
Expand All @@ -130,7 +113,11 @@ func _ready() -> void:
if enteredTree==true:

enteredTree=false
sceens_tscn =preload_sceens(directoryPath, extension)
var sceens_blend=preload_sceens(directoryPath,extension_blend)
sceens_tscn =preload_sceens(directoryPath, extension_tscn)
if len(sceens_blend)>0:
sceens_tscn.append_array(sceens_blend)

print(sceens_tscn)
ray_cast.set_collision_mask_value(1, true)
add_child(ray_cast)
Expand All @@ -148,7 +135,7 @@ func _ready() -> void:

add_child(marker_node_3d)
marker_node_3d.hide()

print('on ready geht')
## The line below is required to make the node visible in the Scene tree dock
## and persist changes made by the tool script to the saved scene file.
#node.owner = get_tree().edited_scene_root
Expand All @@ -173,21 +160,26 @@ func _forward_3d_gui_input(camera: Camera3D, event: InputEvent) -> int:
is_mouse_pressed=false
print('maus released')
pass
#mouse wheel up with right mouse button pressed
if event is InputEventMouseButton and Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)==false and event.button_index == 4 and Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT): #● MOUSE_BUTTON_WHEEL_UP = 4
#is_mouse_pressed=false

print('mouse wheel up')
if process_mouse_wheel_event==false:
#process_mouse_wheel_event=true
run_timer()
select_scene_up()

else:
print('skipped one mouse wheel up event because of process_mouse_wheel_event =true')
#
#pass

if event is InputEventMouseButton and Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)==false and event.button_index == 5 and Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):#● MOUSE_BUTTON_WHEEL_DOWN = 5 ● MOUSE_BUTTON_RIGHT = 2
#is_mouse_pressed=false
print('mouse wheel down')
if process_mouse_wheel_event==false:
run_timer()
select_scene_down()
print('mouse wheel down')
else:
print('skipped one mouse wheel down event because of process_mouse_wheel_event =true')

pass


Expand Down Expand Up @@ -222,7 +214,7 @@ func select_scene_up():

if is_instance_valid(marker_node_3d):
marker_node_3d.queue_free()
print('bis hier')
#print('bis hier')

marker_tscn=sceens_tscn[new_index]
marker_node_3d=marker_tscn.instantiate()
Expand All @@ -233,7 +225,33 @@ func select_scene_up():
last_selected_index=new_index
print('new index: ',last_selected_index)

func select_scene_down():

var new_index:int=-1
#Checking if we are at the end of the list (array)
if last_selected_index==0:
new_index=len(sceens_tscn)-1
else :
new_index=last_selected_index-1

#Creating the new marker
if new_index !=-1:
var temp_position=marker_node_3d.position
var temp_rotation=marker_node_3d.rotation

if is_instance_valid(marker_node_3d):
marker_node_3d.queue_free()
#print('bis hier')

marker_tscn=sceens_tscn[new_index]
marker_node_3d=marker_tscn.instantiate()
turn_off_collider(marker_node_3d)
add_child(marker_node_3d)
marker_node_3d.position=temp_position
marker_node_3d.rotation =temp_rotation
last_selected_index=new_index
print('new index: ',last_selected_index)

func doTheRaycast(camera: Camera3D):
if Engine.is_editor_hint():
marker_node_3d.hide()
Expand Down
Binary file added addons/object_placer/objects/Tree.blend
Binary file not shown.
50 changes: 50 additions & 0 deletions addons/object_placer/objects/Tree.blend.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[remap]

importer="scene"
importer_version=1
type="PackedScene"
uid="uid://cpix4kgjyd3t"
path="res://.godot/imported/Tree.blend-bb598b6fcd7060b133cad4a6b691838c.scn"

[deps]

source_file="res://addons/object_placer/objects/Tree.blend"
dest_files=["res://.godot/imported/Tree.blend-bb598b6fcd7060b133cad4a6b691838c.scn"]

[params]

nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1
blender/nodes/visible=0
blender/nodes/punctual_lights=true
blender/nodes/cameras=true
blender/nodes/custom_properties=true
blender/nodes/modifiers=1
blender/meshes/colors=false
blender/meshes/uvs=true
blender/meshes/normals=true
blender/meshes/tangents=true
blender/meshes/skins=2
blender/meshes/export_bones_deforming_mesh_only=false
blender/materials/unpack_enabled=true
blender/materials/export_materials=1
blender/animation/limit_playback=true
blender/animation/always_sample=true
blender/animation/group_tracks=true
8 changes: 0 additions & 8 deletions addons/object_placer/objects/test.tscn

This file was deleted.

4 changes: 2 additions & 2 deletions addons/object_placer/plugin.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[plugin]

name="testPlugin"
name="Object_Placer"
description=""
author="Ich"
version=""
script="testplugin.gd"
script="object_placer_plugin.gd"
Binary file added assets/blender/Terrain.blend
Binary file not shown.
50 changes: 50 additions & 0 deletions assets/blender/Terrain.blend.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[remap]

importer="scene"
importer_version=1
type="PackedScene"
uid="uid://ldrc1dffrinq"
path="res://.godot/imported/Terrain.blend-7471fcc31cc5fb0baa9bdf3fe2eaed60.scn"

[deps]

source_file="res://assets/blender/Terrain.blend"
dest_files=["res://.godot/imported/Terrain.blend-7471fcc31cc5fb0baa9bdf3fe2eaed60.scn"]

[params]

nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1
blender/nodes/visible=0
blender/nodes/punctual_lights=true
blender/nodes/cameras=true
blender/nodes/custom_properties=true
blender/nodes/modifiers=1
blender/meshes/colors=false
blender/meshes/uvs=true
blender/meshes/normals=true
blender/meshes/tangents=true
blender/meshes/skins=2
blender/meshes/export_bones_deforming_mesh_only=false
blender/materials/unpack_enabled=true
blender/materials/export_materials=1
blender/animation/limit_playback=true
blender/animation/always_sample=true
blender/animation/group_tracks=true
Binary file added assets/blender/Terrain.blend1
Binary file not shown.
Binary file added assets/blender/Tree.blend1
Binary file not shown.
Loading

0 comments on commit 5b5424d

Please sign in to comment.