Skip to content

Commit e7741ab

Browse files
authored
Merge pull request #3 from SoloByte/point-fracture
Point fracture
2 parents 3196cb6 + 9de2aad commit e7741ab

20 files changed

+980
-491
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Dave G
3+
Copyright (c) 2021 David Grueneis
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

demo/src/Arrow.tscn

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[gd_scene format=2]
2+
3+
[node name="Arrow" type="Polygon2D"]
4+
color = Color( 1, 1, 1, 0.392157 )
5+
polygon = PoolVector2Array( 0, 0, 0, -32, 96, 0, 0, 32 )
6+
7+
[node name="Line2D" type="Line2D" parent="."]
8+
points = PoolVector2Array( 0, -32, 96, 0, 0, 32, 0, -32 )
9+
default_color = Color( 1, 1, 1, 1 )
10+
joint_mode = 2
11+
begin_cap_mode = 2
12+
end_cap_mode = 2

demo/src/CutFracture.gd

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@ extends Node2D
33

44

55

6+
# MIT License
7+
# -----------------------------------------------------------------------
8+
# This file is part of:
9+
# GODOT Polygon 2D Fracture
10+
# https://github.com/SoloByte/godot-polygon2d-fracture
11+
# -----------------------------------------------------------------------
12+
# Copyright (c) 2021 David Grueneis
13+
#
14+
# Permission is hereby granted, free of charge, to any person obtaining a copy
15+
# of this software and associated documentation files (the "Software"), to deal
16+
# in the Software without restriction, including without limitation the rights
17+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18+
# copies of the Software, and to permit persons to whom the Software is
19+
# furnished to do so, subject to the following conditions:
20+
#
21+
# The above copyright notice and this permission notice shall be included in all
22+
# copies or substantial portions of the Software.
23+
#
24+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
# SOFTWARE.
31+
32+
33+
34+
635
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)
736
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
837
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)
@@ -24,7 +53,6 @@ onready var polyFracture := PolygonFracture.new()
2453
onready var _source_polygon_parent := $SourcePolygons
2554
onready var _rng := RandomNumberGenerator.new()
2655
onready var _cut_shape : PoolVector2Array = PolygonLib.createCirclePolygon(100.0, 1)
27-
onready var _slowmo_timer := $SlowMoTimer
2856
onready var _cut_line := $CutLine
2957
onready var _pool_cut_visualizer := $Pool_CutVisualizer
3058
onready var _pool_fracture_shards := $Pool_FractureShards
@@ -95,11 +123,6 @@ func _input(event: InputEvent) -> void:
95123
_cut_line_enabled = true
96124

97125

98-
#func _exit_tree() -> void:
99-
# _pool_cut_visualizer.clearPoolInstant()
100-
# _pool_fracture_shards.clearPoolInstant()
101-
102-
103126

104127

105128

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

187210

188211
func cutSourcePolygons(cut_pos : Vector2, cut_shape : PoolVector2Array, cut_rot : float, cut_force : float = 0.0, fade_speed : float = 2.0) -> void:
189-
# var instance = _pool_cut_visualizer.getInstance()
190-
# instance.spawn(cut_pos, fade_speed)
191-
# instance.setPolygon(cut_shape)
212+
var instance = _pool_cut_visualizer.getInstance()
213+
instance.spawn(cut_pos, fade_speed)
214+
instance.setPolygon(cut_shape)
192215

193216
for source in _source_polygon_parent.get_children():
194217
var source_polygon : PoolVector2Array = source.get_polygon()
@@ -238,7 +261,7 @@ func spawnRigibody2d(shape_info : Dictionary, color : Color, lin_vel : Vector2,
238261
instance.global_rotation = shape_info.spawn_rot
239262
instance.set_polygon(shape_info.centered_shape)
240263
instance.modulate = color
241-
instance.linear_velocity = lin_vel# + (spawn_pos - cut_pos).normalized() * 50
264+
instance.linear_velocity = lin_vel
242265
instance.angular_velocity = ang_vel
243266
instance.mass = mass
244267
instance.setTexture(PolygonLib.setTextureOffset(texture_info, shape_info.centroid))
@@ -257,26 +280,3 @@ func spawnFractureBody(fracture_shard : Dictionary, texture_info : Dictionary, n
257280
instance.setMass(new_mass)
258281
instance.addForce(dir * 500.0)
259282
instance.addTorque(_rng.randf_range(-2, 2))
260-
261-
262-
#fracture body variant
263-
# instance.spawn(fracture_shard.spawn_pos)
264-
# instance.global_rotation = fracture_shard.spawn_rot
265-
#
266-
# if instance.has_method("setPolygon"):
267-
# var s : Vector2 = fracture_shard.source_global_trans.get_scale()
268-
# instance.setPolygon(fracture_shard.centered_shape, s)
269-
#
270-
# instance.setColor(_cur_fracture_color)
271-
#
272-
# var dir : Vector2 = (fracture_shard.spawn_pos - fracture_shard.source_global_trans.get_origin()).normalized()
273-
# instance.linear_velocity = dir * _rng.randf_range(300, 500)
274-
# instance.angular_velocity = _rng.randf_range(-1, 1)
275-
#
276-
# instance.setTexture(PolygonLib.setTextureOffset(texture_info, fracture_shard.centroid))
277-
278-
279-
280-
281-
func _on_SlowMoTimer_timeout() -> void:
282-
Engine.time_scale = 1.0

demo/src/CutShapeVisualizer.gd

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,33 @@ extends Polygon2D
33

44

55

6+
# MIT License
7+
# -----------------------------------------------------------------------
8+
# This file is part of:
9+
# GODOT Polygon 2D Fracture
10+
# https://github.com/SoloByte/godot-polygon2d-fracture
11+
# -----------------------------------------------------------------------
12+
# Copyright (c) 2021 David Grueneis
13+
#
14+
# Permission is hereby granted, free of charge, to any person obtaining a copy
15+
# of this software and associated documentation files (the "Software"), to deal
16+
# in the Software without restriction, including without limitation the rights
17+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18+
# copies of the Software, and to permit persons to whom the Software is
19+
# furnished to do so, subject to the following conditions:
20+
#
21+
# The above copyright notice and this permission notice shall be included in all
22+
# copies or substantial portions of the Software.
23+
#
24+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
# SOFTWARE.
31+
32+
633

734

835
signal Despawn(ref)

0 commit comments

Comments
 (0)