forgot to push

This commit is contained in:
2024-01-26 00:45:23 +01:00
parent bb763ea4e2
commit 3ce02c2147
28 changed files with 4037 additions and 262 deletions

View File

@@ -1,100 +0,0 @@
# SPDX-FileCopyrightText: 2023 Jummit
#
# SPDX-License-Identifier: MIT
@tool
@icon("destruction_icon.svg")
class_name Destruction
extends Node
## Handles destruction of the parent node.
##
## When [method destroy] is called, the parent node is freed and shards
## are added to the [member shard_container].
## A scene of the fragmented mesh containing multiple [MeshInstance3D]s.
@export var fragmented: PackedScene: set = set_fragmented
## The node where created shards are added to.
@onready @export var shard_container := get_node("../../")
@export_group("Animation")
## How many seconds until the shards fade away. Set to -1 to disable fading.
@export var fade_delay := 2.0
## How many seconds until the shards shrink. Set to -1 to disable shrinking.
@export var shrink_delay := 2.0
## How long the animation lasts before the shard is removed.
@export var animation_length := 2.0
@export_group("Collision")
## The [member RigidBody3D.collision_layer] set on the created shards.
@export_flags_3d_physics var collision_layer = 1
## The [member RigidBody3D.collision_mask] set on the created shards.
@export_flags_3d_physics var collision_mask = 1
## Cached shard meshes (instantiated from [member fragmented]).
static var cached_meshes := {}
## Cached collision shapes.
static var cached_shapes := {}
## Remove the parent node and add shards to the shard container.
func destroy(explosion_power := 1.0) -> void:
if not fragmented in cached_meshes:
cached_meshes[fragmented] = fragmented.instantiate()
for shard_mesh in cached_meshes[fragmented].get_children():
cached_shapes[shard_mesh] = shard_mesh.mesh.create_convex_shape()
var original_meshes = cached_meshes[fragmented]
for original in original_meshes.get_children():
if original is MeshInstance3D:
_add_shard(original, explosion_power)
get_parent().queue_free()
func _add_shard(original: MeshInstance3D, explosion_power: float) -> void:
var body := RigidBody3D.new()
var mesh := MeshInstance3D.new()
var shape := CollisionShape3D.new()
body.add_child(mesh)
body.add_child(shape)
shard_container.add_child(body, true)
body.global_position = get_parent().global_transform.origin + original.position
body.collision_layer = collision_layer
body.collision_mask = collision_mask
shape.shape = cached_shapes[original]
mesh.mesh = original.mesh
if fade_delay >= 0:
var material = original.mesh.surface_get_material(0)
if material is StandardMaterial3D:
material = material.duplicate()
material.flags_transparent = true
get_tree().create_tween().tween_property(material, "albedo_color",
Color(1, 1, 1, 0), animation_length)\
.set_delay(fade_delay)\
.set_trans(Tween.TRANS_EXPO)\
.set_ease(Tween.EASE_OUT)
mesh.material_override = material
else:
push_warning("Shard doesn't use a StandardMaterial3D, can't add transparency.")
body.apply_impulse(_random_direction() * explosion_power,
-original.position.normalized())
if shrink_delay < 0 and fade_delay < 0:
get_tree().create_timer(animation_length)\
.timeout.connect(func(): body.queue_free())
elif shrink_delay >= 0:
var tween := get_tree().create_tween()
tween.tween_property(mesh, "scale", Vector3.ZERO, animation_length)\
.set_delay(shrink_delay)
tween.finished.connect(func(): body.queue_free())
func set_fragmented(to: PackedScene) -> void:
fragmented = to
if is_inside_tree():
get_tree().node_configuration_warning_changed.emit(self)
func _get_configuration_warnings() -> PackedStringArray:
return ["No fragmented version set"] if not fragmented else []
static func _random_direction() -> Vector3:
return (Vector3(randf(), randf(), randf()) - Vector3.ONE / 2.0).normalized() * 2.0

View File

@@ -1,94 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 16 16"
version="1.1"
id="svg6"
sodipodi:docname="destruction_icon.svg"
width="16"
height="16"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<metadata
id="metadata12">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs10" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1131"
id="namedview8"
showgrid="false"
inkscape:zoom="22.627417"
inkscape:cx="11.645165"
inkscape:cy="3.2924659"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="g833"
inkscape:snap-global="false"
inkscape:showpageshadow="0"
inkscape:pagecheckerboard="1"
inkscape:deskcolor="#d1d1d1" />
<g
id="g833">
<path
style="fill:#fc7f7f;fill-opacity:1;stroke-width:0.0434868"
d="M 6.1124514,0.21990751 5.3179785,4.9274647 7.539946,5.6402636 9.1601633,3.7724775 6.1123592,0.21993901 Z"
id="path934"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
style="fill:#fc7f7f;fill-opacity:1;stroke-width:0.0504769"
d="M 11.609494,6.2543511 10.546935,7.2961746 11.599644,9.6605288 15.569415,8.1031384 11.609544,6.2543186 Z"
id="path932"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
style="fill:#fc7f7f;fill-opacity:1;stroke-width:0.0425204"
d="M 0.35089167,5.7394229 3.7991292,8.9407222 5.0837143,6.8823657 4.9404114,4.9535918 0.35084477,5.7395054 Z"
id="path928"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
style="fill:#fc7f7f;fill-opacity:1;stroke-width:0.064974"
d="M 3.9865178,9.5278182 0.84397687,15.149556 7.0836262,12.29648 6.8710224,10.228417 3.9865809,9.5279402 Z"
id="path926"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
style="fill:#fc7f7f;fill-opacity:1;stroke-width:0.0595588"
d="M 14.18702,0.87714727 9.6322453,3.0261429 10.097515,5.3436305 12.605668,5.5752977 14.187044,0.87722377 Z"
id="path2"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
inkscape:connector-curvature="0"
id="path936"
d="M 12.202851,10.748434 9.3093393,9.4420942 8.6059995,12.371114 14.224963,15.307286 12.202739,10.748503 Z"
style="fill:#fc7f7f;fill-opacity:1;stroke-width:0.0621997"
sodipodi:nodetypes="cccccc" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 3.3 KiB

View File

@@ -1,37 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://co3om28rgeos3"
path="res://.godot/imported/destruction_icon.svg-716fc5b182e74f5a75cf299975d03542.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/destruction/destruction_icon.svg"
dest_files=["res://.godot/imported/destruction_icon.svg-716fc5b182e74f5a75cf299975d03542.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View File

@@ -1,4 +0,0 @@
SPDX-FileCopyrightText: 2023 Jummit
SPDX-FileContributor: Jummit
SPDX-License-Identifier: CC0-1.0

View File

@@ -1,4 +0,0 @@
SPDX-FileCopyrightText: 2023 Jummit
SPDX-FileContributor: Jummit
SPDX-License-Identifier: CC0-1.0

View File

@@ -1,11 +0,0 @@
; SPDX-FileCopyrightText: 2023 Jummit
;
; SPDX-License-Identifier: MIT
[plugin]
name="Destruction"
description="Destroy 3D objects."
author="Jummit"
version="7.0"
script="plugin.gd"

View File

@@ -1,6 +0,0 @@
# SPDX-FileCopyrightText: 2023 Jummit
#
# SPDX-License-Identifier: MIT
@tool
extends EditorPlugin

View File

@@ -1,3 +0,0 @@
# SPDX-FileCopyrightText: 2023 Jummit
#
# SPDX-License-Identifier: MIT