Last active
July 4, 2019 01:36
-
-
Save umaruru/4ba55d52778dbab7feef48cde86c93fa to your computer and use it in GitHub Desktop.
Mesh trail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Spatial | |
# materials have to be set as transparent | |
# change depth draw mode | |
# change render priority | |
# probably won't work on GLES2 due to this | |
export var mesh_amount : int = 8 | |
var mesh_trail = [] | |
onready var Anim = $AnimationPlayer | |
onready var mesh = $Skeleton/Beta_Surface | |
onready var skeleton = $Skeleton | |
onready var Trail = $Trail | |
func _ready() -> void: | |
# trail object won't update position with nodes | |
Trail.set_as_toplevel(true) | |
$TimerTrail.connect("timeout", self, "_on_TimerTrail_timeout") | |
func _on_TimerTrail_timeout() -> void: | |
# duplicate skeleton | |
var ns = skeleton.duplicate() | |
ns.global_transform = skeleton.global_transform | |
# apply material to meshes of skeleton | |
for node in ns.get_children(): | |
if node is MeshInstance: | |
node.set_surface_material(0, preload("res://tests/mesh trail/trail_mat.tres")) | |
# duplicate anim player | |
var na = Anim.duplicate() | |
# create new trail obj | |
var nt = Spatial.new() | |
nt.name = "trail_" | |
# add skeleton and animation player | |
nt.add_child(ns) | |
nt.add_child(na) | |
na.autoplay = "" | |
# add trail to array | |
mesh_trail.append(nt) | |
if mesh_trail.size() > mesh_amount: | |
var t = mesh_trail.pop_front() | |
t.queue_free() | |
# add trail to scene | |
Trail.add_child(nt) | |
# setup na | |
if Anim.is_playing(): | |
na.current_animation = Anim.current_animation | |
na.stop() | |
na.seek(Anim.current_animation_position, true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment