Create an example of scene with dissovle apply for 3 meshes

This commit is contained in:
VAILLANT Jeremy
2021-05-12 13:01:47 +02:00
parent b13a850150
commit cf280f88b0
6 changed files with 94 additions and 29 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+47 -21
View File
@@ -1,28 +1,54 @@
extends Spatial extends Spatial
var dissolve = null const time_max = 3000 # msec
var time_max = 2000 # msec
var tick_reference = null
var value = 0.1
func _on_Area_input_event(_camera, event, _click_position, _click_normal, _shape_idx): onready var meshes = {
if event is InputEventMouseButton or event is InputEventScreenTouch: "dagger": {
dissolve = true "mesh": $dagger,
"value": 0.0,
"label": "Dagger",
"lock": false,
"tick_reference": null
},
"coin": {
"mesh": $coin,
"value": 0.0,
"label": "Coin",
"lock": false,
"tick_reference": null
},
"book": {
"mesh": $book,
"value": 0.0,
"label": "Book",
"lock": false,
"tick_reference": null
}
}
func _on_Dagger_Area_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("dagger", event)
func _on_Coin_Area_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("coin", event)
func _on_Book_Area_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("book", event)
func _initialize_mesh_ref(meshInstance, event):
if meshes[meshInstance]["lock"] == false and (event is InputEventMouseButton or event is InputEventScreenTouch):
meshes[meshInstance]["lock"] = true
func _process(_delta): func _process(_delta):
if dissolve == true: for mesh in meshes:
if tick_reference == null: if meshes[mesh]["lock"] == true and meshes[mesh]["mesh"] != null:
tick_reference = OS.get_ticks_msec()
print("[Dagger#_process] Reference tick to " + String(tick_reference))
var tick = OS.get_ticks_msec() if meshes[mesh]["tick_reference"] == null:
meshes[mesh]["tick_reference"] = OS.get_ticks_msec()
print("[Dagger#_process] Dissolve ... " + String(tick) + " < " + String(tick_reference + time_max)) if OS.get_ticks_msec() < meshes[mesh]["tick_reference"] + time_max:
meshes[mesh]["value"] += 0.01
if tick < tick_reference + time_max: meshes[mesh]["mesh"].get_surface_material(0).set("shader_param/dissolve_amount", meshes[mesh]["value"])
print("[Dagger#_process] Apply value to "+ String(value)) else:
value += 0.01 meshes[mesh]["mesh"].call_deferred("free")
$dagger.mesh.surface_get_material(0).set("shader_param/dissolve_amount", value) meshes[mesh]["mesh"] = null
else:
print("[Dagger#_process] animation ending !!")
dissolve = null
File diff suppressed because one or more lines are too long