Skip to content

Commit

Permalink
Merge pull request #3 from SoloByte/point-fracture
Browse files Browse the repository at this point in the history
Point fracture
  • Loading branch information
SoloByte authored Apr 15, 2021
2 parents 3196cb6 + 9de2aad commit e7741ab
Show file tree
Hide file tree
Showing 20 changed files with 980 additions and 491 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Dave G
Copyright (c) 2021 David Grueneis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 12 additions & 0 deletions demo/src/Arrow.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gd_scene format=2]

[node name="Arrow" type="Polygon2D"]
color = Color( 1, 1, 1, 0.392157 )
polygon = PoolVector2Array( 0, 0, 0, -32, 96, 0, 0, 32 )

[node name="Line2D" type="Line2D" parent="."]
points = PoolVector2Array( 0, -32, 96, 0, 0, 32, 0, -32 )
default_color = Color( 1, 1, 1, 1 )
joint_mode = 2
begin_cap_mode = 2
end_cap_mode = 2
66 changes: 33 additions & 33 deletions demo/src/CutFracture.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@ extends Node2D



# MIT License
# -----------------------------------------------------------------------
# This file is part of:
# GODOT Polygon 2D Fracture
# https://github.com/SoloByte/godot-polygon2d-fracture
# -----------------------------------------------------------------------
# Copyright (c) 2021 David Grueneis
#
# 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.




const CUT_LINE_POINT_MIN_DISTANCE : float = 40.0 #distance before new point is added (the smaller the more detailed is the visual line (not the cut line)
const CUT_LINE_STATIONARY_DELAY : float = 0.1 #after that amount of seconds remaining stationary will end the cut line process and cut the sources
const CUT_LINE_DIRECTION_THRESHOLD : float = -0.7 #smaller than treshold will end the cut line process and cut the sources (start_dir.dot(cur_dir) < threshold = endLine)
Expand All @@ -24,7 +53,6 @@ onready var polyFracture := PolygonFracture.new()
onready var _source_polygon_parent := $SourcePolygons
onready var _rng := RandomNumberGenerator.new()
onready var _cut_shape : PoolVector2Array = PolygonLib.createCirclePolygon(100.0, 1)
onready var _slowmo_timer := $SlowMoTimer
onready var _cut_line := $CutLine
onready var _pool_cut_visualizer := $Pool_CutVisualizer
onready var _pool_fracture_shards := $Pool_FractureShards
Expand Down Expand Up @@ -95,11 +123,6 @@ func _input(event: InputEvent) -> void:
_cut_line_enabled = true


#func _exit_tree() -> void:
# _pool_cut_visualizer.clearPoolInstant()
# _pool_fracture_shards.clearPoolInstant()





Expand Down Expand Up @@ -186,9 +209,9 @@ func simpleCut(pos : Vector2) -> void:


func cutSourcePolygons(cut_pos : Vector2, cut_shape : PoolVector2Array, cut_rot : float, cut_force : float = 0.0, fade_speed : float = 2.0) -> void:
# var instance = _pool_cut_visualizer.getInstance()
# instance.spawn(cut_pos, fade_speed)
# instance.setPolygon(cut_shape)
var instance = _pool_cut_visualizer.getInstance()
instance.spawn(cut_pos, fade_speed)
instance.setPolygon(cut_shape)

for source in _source_polygon_parent.get_children():
var source_polygon : PoolVector2Array = source.get_polygon()
Expand Down Expand Up @@ -238,7 +261,7 @@ func spawnRigibody2d(shape_info : Dictionary, color : Color, lin_vel : Vector2,
instance.global_rotation = shape_info.spawn_rot
instance.set_polygon(shape_info.centered_shape)
instance.modulate = color
instance.linear_velocity = lin_vel# + (spawn_pos - cut_pos).normalized() * 50
instance.linear_velocity = lin_vel
instance.angular_velocity = ang_vel
instance.mass = mass
instance.setTexture(PolygonLib.setTextureOffset(texture_info, shape_info.centroid))
Expand All @@ -257,26 +280,3 @@ func spawnFractureBody(fracture_shard : Dictionary, texture_info : Dictionary, n
instance.setMass(new_mass)
instance.addForce(dir * 500.0)
instance.addTorque(_rng.randf_range(-2, 2))


#fracture body variant
# instance.spawn(fracture_shard.spawn_pos)
# instance.global_rotation = fracture_shard.spawn_rot
#
# if instance.has_method("setPolygon"):
# var s : Vector2 = fracture_shard.source_global_trans.get_scale()
# instance.setPolygon(fracture_shard.centered_shape, s)
#
# instance.setColor(_cur_fracture_color)
#
# var dir : Vector2 = (fracture_shard.spawn_pos - fracture_shard.source_global_trans.get_origin()).normalized()
# instance.linear_velocity = dir * _rng.randf_range(300, 500)
# instance.angular_velocity = _rng.randf_range(-1, 1)
#
# instance.setTexture(PolygonLib.setTextureOffset(texture_info, fracture_shard.centroid))




func _on_SlowMoTimer_timeout() -> void:
Engine.time_scale = 1.0
27 changes: 27 additions & 0 deletions demo/src/CutShapeVisualizer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@ extends Polygon2D



# MIT License
# -----------------------------------------------------------------------
# This file is part of:
# GODOT Polygon 2D Fracture
# https://github.com/SoloByte/godot-polygon2d-fracture
# -----------------------------------------------------------------------
# Copyright (c) 2021 David Grueneis
#
# 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.




signal Despawn(ref)
Expand Down
Loading

0 comments on commit e7741ab

Please sign in to comment.