Skip to content

Commit

Permalink
Merge pull request #13 from erayzesen/feature/improve_rendering_features
Browse files Browse the repository at this point in the history
 Rendering Features Improvements
  • Loading branch information
erayzesen authored Jan 17, 2025
2 parents 150fa02 + 4d8faec commit eee1973
Show file tree
Hide file tree
Showing 15 changed files with 456 additions and 138 deletions.
Binary file modified .sconsign.dblite
Binary file not shown.
39 changes: 37 additions & 2 deletions project/addons/quarkphysics/qmesh_editor/qmesh_editor_tool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ var lazyCheckBox:CheckBox
var operationOptionButton:OptionButton
var plugin:EditorPlugin

#Mesh Node Temp
var mesh_node_alpha_temp:float=1
var mesh_node_editing_alpha:float=0.3

#Helpers
var snapHelper:QMeshSnapHelper=QMeshSnapHelper.new()

Expand Down Expand Up @@ -45,7 +49,15 @@ func _lazy_checkbox_toggled(toggled_on:bool) :
func _radius_bar_changed(value:float) :
pass

func make_mesh_graphics_passive() :
make_mesh_graphics_active()
mesh_node_alpha_temp=meshNode.modulate.a
meshNode.modulate.a=mesh_node_editing_alpha

func make_mesh_graphics_active() :
meshNode.modulate.a=mesh_node_alpha_temp


func toScreen(point:Vector2) ->Vector2 :
var viewport_transform=EditorInterface.get_editor_viewport_2d().get_final_transform()*EditorInterface.get_base_control().get_canvas_transform()
return viewport_transform*point
Expand All @@ -58,7 +70,7 @@ func fromScreen(point:Vector2)->Vector2 :
func get_nearest_particle_index(targetMeshNode:QMeshNode,position:Vector2) ->int:
for i in range(targetMeshNode.data_particle_positions.size() ) :
var point=targetMeshNode.data_particle_positions[i].rotated(meshNode.global_rotation)
if ((point+targetMeshNode.global_position)-position).length()<5.0 :
if ((point+targetMeshNode.global_position)-position).length()<plugin.particle_select_range :
return i
return -1;

Expand Down Expand Up @@ -139,6 +151,7 @@ func is_particle_exist_in_uv(targetMeshNode:QMeshNode,particleIndex:int)->bool:

static func solve_faulty_particle_data_issues(targetMeshNode:QMeshNode) :
var particleCount=targetMeshNode.data_particle_positions.size()
# SOLVING MISSING FEATURES
#Check Particle Enabled Values
if targetMeshNode.data_particle_is_enabled.size()<particleCount :
var temp_collection=targetMeshNode.data_particle_is_enabled.duplicate()
Expand All @@ -165,4 +178,26 @@ static func solve_faulty_particle_data_issues(targetMeshNode:QMeshNode) :
for i in range(temp_collection.size(),particleCount) :
temp_collection.append(0.5)
targetMeshNode.data_particle_radius=temp_collection
pass

#SOLVING OVERAGE FEATURES
#Check Particle Enabled Values
while targetMeshNode.data_particle_is_enabled.size()>targetMeshNode.data_particle_positions.size() :
var temp=targetMeshNode.data_particle_is_enabled
temp.remove_at(temp.size()-1)
targetMeshNode.data_particle_is_enabled=temp
#Check Particle Radius Values
while targetMeshNode.data_particle_radius.size()>targetMeshNode.data_particle_positions.size() :
var temp=targetMeshNode.data_particle_radius
temp.remove_at(temp.size()-1)
targetMeshNode.data_particle_radius=temp
#Check Particle Internal Values
while targetMeshNode.data_particle_is_internal.size()>targetMeshNode.data_particle_positions.size() :
var temp=targetMeshNode.data_particle_is_internal
temp.remove_at(temp.size()-1)
targetMeshNode.data_particle_is_internal=temp
#Check Particle Lazy Values
while targetMeshNode.data_particle_is_lazy.size()>targetMeshNode.data_particle_positions.size() :
var temp=targetMeshNode.data_particle_is_lazy
temp.remove_at(temp.size()-1)
targetMeshNode.data_particle_is_lazy=temp

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func _handle_event(event:InputEvent)->bool:
#Add a new particle
var undo_redo=plugin.get_undo_redo()
undo_redo.create_action("Add a Particle to Position: "+str(mPos) )
undo_redo.add_do_method(self,"command_add_particle",plugin,meshNode,new_particle_local_pos,0.5,false )
undo_redo.add_do_method(self,"command_add_particle",plugin,meshNode,new_particle_local_pos,0.5,internalCheckBox.button_pressed )
undo_redo.add_undo_method(self,"command_remove_particle",plugin,meshNode,meshNode.data_particle_positions.size() )
undo_redo.commit_action(true)

Expand All @@ -39,11 +39,13 @@ func _handle_event(event:InputEvent)->bool:
var target_particle_position=meshNode.data_particle_positions[nearest_particle_index]
var target_particle_radius=meshNode.data_particle_radius[nearest_particle_index]
var target_particle_internal=meshNode.data_particle_is_internal[nearest_particle_index]
var target_particle_enabled=meshNode.data_particle_is_enabled[nearest_particle_index]
var target_particle_lazy=meshNode.data_particle_is_lazy[nearest_particle_index]
var undo_redo=plugin.get_undo_redo()

undo_redo.create_action("Remove Particle Indexed: "+str(nearest_particle_index) )
undo_redo.add_do_method(self,"command_remove_particle",plugin,meshNode,nearest_particle_index )
undo_redo.add_undo_method(self,"command_add_particle",plugin,meshNode,target_particle_position,target_particle_radius,target_particle_internal,nearest_particle_index, old_springs,old_internal_springs,old_polygon,old_uv_maps )
undo_redo.add_undo_method(self,"command_add_particle",plugin,meshNode,target_particle_position,target_particle_radius,target_particle_internal,target_particle_enabled,target_particle_lazy,nearest_particle_index, old_springs,old_internal_springs,old_polygon,old_uv_maps )
undo_redo.commit_action(true)
pass
pass
Expand Down Expand Up @@ -81,7 +83,7 @@ func _radius_bar_changed(value:float) :

#Commands

func command_add_particle(targetPlugin:EditorPlugin,targetMeshNode:QMeshNode, position:Vector2,radius:float,is_internal:bool,array_position:int=-1, setter_springs:Array=[], setter_internal_springs:Array=[],setter_polygon:PackedInt32Array=[],setter_uv_maps:Array=[]):
func command_add_particle(targetPlugin:EditorPlugin,targetMeshNode:QMeshNode, position:Vector2,radius:float,is_internal:bool=false,is_enabled:bool=true,is_lazy:bool=false,array_position:int=-1, setter_springs:Array=[], setter_internal_springs:Array=[],setter_polygon:PackedInt32Array=[],setter_uv_maps:Array=[]):
var particles=targetMeshNode.data_particle_positions.duplicate()
if array_position==-1 :
particles.push_back(position)
Expand Down Expand Up @@ -112,12 +114,35 @@ func command_add_particle(targetPlugin:EditorPlugin,targetMeshNode:QMeshNode, po
targetMeshNode.data_uv_maps[i][j]+=1

targetMeshNode.data_particle_positions=particles
#radius
var particle_radius=targetMeshNode.data_particle_radius
particle_radius.append(radius)
if array_position==-1 :
particle_radius.append(radius)
else :
particle_radius.insert(array_position,radius)
targetMeshNode.data_particle_radius=particle_radius
#internal
var particles_is_internal=targetMeshNode.data_particle_is_internal
particles_is_internal.push_back(is_internal)
if array_position==-1 :
particles_is_internal.append(is_internal)
else :
particles_is_internal.insert(array_position,is_internal)
targetMeshNode.data_particle_is_internal=particles_is_internal
#enabled
var particles_is_enabled=targetMeshNode.data_particle_is_enabled
if array_position==-1 :
particles_is_enabled.append(is_enabled)
else :
particles_is_enabled.insert(array_position,is_enabled)
targetMeshNode.data_particle_is_enabled=particles_is_enabled
#lazy
var particles_is_lazy=targetMeshNode.data_particle_is_lazy
if array_position==-1 :
particles_is_lazy.append(is_lazy)
else :
particles_is_lazy.insert(array_position,is_lazy)
targetMeshNode.data_particle_is_lazy=particles_is_lazy

if setter_springs.size()>0 :
targetMeshNode.data_springs=setter_springs
if setter_internal_springs.size()>0 :
Expand All @@ -126,7 +151,7 @@ func command_add_particle(targetPlugin:EditorPlugin,targetMeshNode:QMeshNode, po
targetMeshNode.data_polygon=setter_polygon
if setter_uv_maps.size()>0 :
targetMeshNode.data_uv_maps=setter_uv_maps

targetMeshNode.queue_redraw()
targetPlugin.update_overlays()
pass
Expand Down Expand Up @@ -226,16 +251,27 @@ func command_remove_particle(targetPlugin:EditorPlugin,targetMeshNode:QMeshNode,
targetMeshNode.queue_redraw()


#position
var particles=targetMeshNode.data_particle_positions
particles.remove_at(particle_index)
targetMeshNode.data_particle_positions=particles
#radius
var particle_radius=targetMeshNode.data_particle_radius
particle_radius.remove_at(particle_index)
targetMeshNode.data_particle_radius=particle_radius
#internal
var particles_is_internal=targetMeshNode.data_particle_is_internal
particles_is_internal.remove_at(particle_index)
targetMeshNode.data_particle_is_internal=particles_is_internal
#enabled
var particles_is_enabled=targetMeshNode.data_particle_is_enabled
particles_is_enabled.remove_at(particle_index)
targetMeshNode.data_particle_is_enabled=particles_is_enabled
#lazy
var particles_is_lazy=targetMeshNode.data_particle_is_lazy
particles_is_lazy.remove_at(particle_index)
targetMeshNode.data_particle_is_lazy=particles_is_lazy

targetMeshNode.queue_redraw()
targetPlugin.update_overlays()
pass
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func _handle_event(event:InputEvent)->bool:
var nearest_particle_index=get_nearest_particle_index(meshNode,mPos)
if nearest_particle_index==-1 :
selected_particle_indexes.clear()
meshNode.modulate.a=1.0
make_mesh_graphics_active()
plugin.update_overlays()
else :
var is_particle_exist=false
Expand All @@ -30,19 +30,19 @@ func _handle_event(event:InputEvent)->bool:
undo_redo.add_undo_method(self,"command_set_polygon",plugin,meshNode,meshNode.data_polygon )
undo_redo.add_do_method(self,"command_set_polygon",plugin,meshNode, new_polygon_indexes )
undo_redo.commit_action(true)
meshNode.modulate.a=1.0
make_mesh_graphics_active()
selected_particle_indexes.clear()
meshNode.queue_redraw()
plugin.update_overlays()
else :
if is_particle_exist==false:
selected_particle_indexes.push_back(nearest_particle_index)
meshNode.modulate.a=0.3
make_mesh_graphics_passive()
plugin.update_overlays()
else :
selected_particle_indexes.clear()
plugin.update_overlays()
meshNode.modulate.a=1.0
make_mesh_graphics_active()
last_mouse_pressed_position=mPos
last_mouse_motion_position=mPos
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func _handle_event(event:InputEvent)->bool:

if event is InputEventMouseMotion :
var mPos=fromScreen(event.position)



#Mouse drag mode handling
if mouse_drag_mode==true :
#There are selected particles and the repositioning mode is active
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ func _handle_event(event:InputEvent)->bool:
undo_redo.add_do_method(self,"command_add_spring",plugin,meshNode,first_selected_particle_index,nearest_particle_index,internalCheckBox.button_pressed )
undo_redo.add_undo_method(self,"command_remove_spring",plugin,meshNode,first_selected_particle_index,nearest_particle_index )
undo_redo.commit_action(true)
make_mesh_graphics_active()

first_selected_particle_index=-1
meshNode.modulate.a=1.0

else :
var nearest_particle_index=get_nearest_particle_index(meshNode, mPos)
first_selected_particle_index=nearest_particle_index
last_mouse_pressed_position=mPos
last_mouse_motion_position=mPos
meshNode.modulate.a=0.3
if nearest_particle_index!=-1 :
make_mesh_graphics_passive()
else :
make_mesh_graphics_active()

else :
var nearest_spring_index=get_nearest_spring_index(meshNode,mPos,internalCheckBox.button_pressed)
Expand All @@ -55,10 +60,6 @@ func _handle_event(event:InputEvent)->bool:
#Handling mouse left button released
if event.button_index==MOUSE_BUTTON_LEFT :
var mPos=fromScreen(event.position)




last_mouse_released_position=mPos


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func _handle_event(event:InputEvent)->bool:
var nearest_particle_index=get_nearest_particle_index(meshNode,mPos)
if nearest_particle_index==-1 :
selected_particle_indexes.clear()
meshNode.modulate.a=1.0
make_mesh_graphics_active()
plugin.update_overlays()
else :
var is_particle_exist=false
Expand All @@ -31,19 +31,19 @@ func _handle_event(event:InputEvent)->bool:
undo_redo.add_undo_method(self,"command_remove_uv_at",plugin,meshNode,uv_maps_size )
undo_redo.add_do_method(self,"command_add_uv",plugin,meshNode, new_uv_indexes )
undo_redo.commit_action(true)
meshNode.modulate.a=1.0
make_mesh_graphics_active()
selected_particle_indexes.clear()
meshNode.queue_redraw()
plugin.update_overlays()
else :
if is_particle_exist==false:
selected_particle_indexes.push_back(nearest_particle_index)
meshNode.modulate.a=0.3
make_mesh_graphics_passive()
plugin.update_overlays()
else :
selected_particle_indexes.clear()
plugin.update_overlays()
meshNode.modulate.a=1.0
make_mesh_graphics_active()
last_mouse_pressed_position=mPos
last_mouse_motion_position=mPos
pass
Expand Down
Loading

0 comments on commit eee1973

Please sign in to comment.