-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from MizunagiKB/update_v0_6_1
Update v0 6 1
- Loading branch information
Showing
20 changed files
with
728 additions
and
178 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# SPDX-License-Identifier: MIT | ||
# SPDX-FileCopyrightText: 2023 MizunagiKB <[email protected]> | ||
extends GDCubismEffectCustom | ||
|
||
|
||
@export var param_mouth_name: String = "ParamMouthA" | ||
@export var min_db: float = 60.0 | ||
@export var min_voice_freq: int = 0 | ||
@export var max_voice_freq: int = 3200 | ||
@export var history_size: int = 6 | ||
|
||
@export_category("Audio") | ||
@export var audio_bus_name: String = "Voice" | ||
@export var audio_efx_index: int = 0 | ||
|
||
var spectrum: AudioEffectSpectrumAnalyzerInstance | ||
var param_mouth: GDCubismParameter | ||
var ary_volume_history: Array | ||
var history_position: int = 0 | ||
var lipsync_ready: bool = false | ||
|
||
|
||
func array_rebuild(): | ||
if history_size != ary_volume_history.size(): | ||
ary_volume_history.resize(history_size) | ||
ary_volume_history.fill(0.0) | ||
|
||
|
||
func array_avg() -> float: | ||
var sum_v: float = 0.0 | ||
for v in ary_volume_history: | ||
sum_v += v | ||
return sum_v / ary_volume_history.size() | ||
|
||
|
||
func _on_cubism_init(model: GDCubismUserModel): | ||
param_mouth = null | ||
ary_volume_history.clear() | ||
history_position = 0 | ||
|
||
var ary_param = model.get_parameters() | ||
|
||
for param in ary_param: | ||
if param.id == param_mouth_name: | ||
param_mouth = param | ||
|
||
var bus_index = AudioServer.get_bus_index(audio_bus_name) | ||
spectrum = AudioServer.get_bus_effect_instance(bus_index, audio_efx_index) | ||
|
||
if spectrum == null: | ||
lipsync_ready = false | ||
else: | ||
lipsync_ready = true | ||
|
||
|
||
func _on_cubism_term(model: GDCubismUserModel): | ||
lipsync_ready = false | ||
param_mouth = null | ||
ary_volume_history.clear() | ||
history_position = 0 | ||
|
||
|
||
func _on_cubism_process(model: GDCubismUserModel, delta: float): | ||
if lipsync_ready == false: | ||
return | ||
|
||
array_rebuild() | ||
|
||
var m: float = spectrum.get_magnitude_for_frequency_range( | ||
min_voice_freq, | ||
max_voice_freq | ||
).length() | ||
var v = clamp((min_db + linear_to_db(m)) / min_db, 0.0, 1.0) | ||
|
||
ary_volume_history[history_position] = v | ||
history_position += 1 | ||
|
||
if history_position >= ary_volume_history.size(): | ||
history_position = 0 | ||
|
||
var avg_v: float = array_avg() | ||
|
||
if param_mouth != null: | ||
param_mouth.value = max(param_mouth.value - 0.2, 0.0) | ||
if avg_v > 0.1: | ||
param_mouth.value = 1.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
extends Node2D | ||
|
||
|
||
enum E_PARAM_MODE { | ||
PROCESS, | ||
SIGNAL | ||
} | ||
|
||
var param_valid: bool = false | ||
var param_mode: E_PARAM_MODE = E_PARAM_MODE.PROCESS | ||
var l_eye: GDCubismParameter | ||
var r_eye: GDCubismParameter | ||
|
||
|
||
func _ready(): | ||
pass | ||
|
||
|
||
func _process(delta): | ||
if param_mode == E_PARAM_MODE.PROCESS: | ||
var model: GDCubismUserModel = $Sprite2D/GDCubismUserModel | ||
|
||
for _o in model.get_parameters(): | ||
var o: GDCubismParameter = _o | ||
if o.id == "ParamEyeLOpen": | ||
o.value = 0.0 | ||
if o.id == "ParamEyeROpen": | ||
o.value = 0.0 | ||
|
||
|
||
func _on_gd_cubism_effect_custom_cubism_init(model: GDCubismUserModel): | ||
if param_mode == E_PARAM_MODE.SIGNAL: | ||
for _o in model.get_parameters(): | ||
var o: GDCubismParameter = _o | ||
if o.id == "ParamEyeLOpen": | ||
l_eye = o | ||
if o.id == "ParamEyeROpen": | ||
r_eye = o | ||
param_valid = true | ||
|
||
|
||
func _on_gd_cubism_effect_custom_cubism_term(model): | ||
if param_mode == E_PARAM_MODE.SIGNAL: | ||
param_valid = false | ||
|
||
|
||
func _on_gd_cubism_effect_custom_cubism_prologue(model, delta): | ||
pass # Replace with function body. | ||
|
||
|
||
func _on_gd_cubism_effect_custom_cubism_process(model: GDCubismUserModel, delta: float): | ||
if param_mode == E_PARAM_MODE.SIGNAL: | ||
if param_valid == true: | ||
l_eye.value = 0.0 | ||
r_eye.value = 0.0 | ||
|
||
|
||
func _on_gd_cubism_effect_custom_cubism_epilogue(model, delta): | ||
pass # Replace with function body. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://xk7rqvf532rj"] | ||
[gd_scene load_steps=3 format=3 uid="uid://drt0184vymus2"] | ||
|
||
[ext_resource type="Script" path="res://addons/gd_cubism/example/custom_efx_02.gd" id="1_ittjg"] | ||
[ext_resource type="Texture2D" uid="uid://c8o4yd28cp3jy" path="res://icon.svg" id="2_0d7x8"] | ||
|
||
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_w6cby"] | ||
blend_mode = 4 | ||
light_mode = 1 | ||
|
||
[node name="demo_effect_custom_02" type="Node2D"] | ||
[node name="demo_effect_custom_01" type="Node2D"] | ||
|
||
[node name="Sprite2D" type="Sprite2D" parent="."] | ||
material = SubResource("CanvasItemMaterial_w6cby") | ||
position = Vector2(256, 256) | ||
position = Vector2(640, 512) | ||
|
||
[node name="GDCubismUserModel" type="GDCubismUserModel" parent="Sprite2D"] | ||
disable_3d = true | ||
transparent_bg = true | ||
gui_disable_input = true | ||
size = Vector2i(1024, 1024) | ||
render_target_update_mode = 4 | ||
|
||
[node name="GDCubismEffectCustom" type="GDCubismEffectCustom" parent="Sprite2D/GDCubismUserModel"] | ||
script = ExtResource("1_ittjg") | ||
|
||
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."] | ||
autoplay = true | ||
bus = &"Voice" | ||
[node name="Sprite2D" type="Sprite2D" parent="Sprite2D/GDCubismUserModel/GDCubismEffectCustom"] | ||
z_index = 1024 | ||
scale = Vector2(0.5, 0.5) | ||
texture = ExtResource("2_0d7x8") | ||
|
||
[connection signal="cubism_init" from="Sprite2D/GDCubismUserModel/GDCubismEffectCustom" to="Sprite2D/GDCubismUserModel/GDCubismEffectCustom" method="_on_cubism_init"] | ||
[connection signal="cubism_process" from="Sprite2D/GDCubismUserModel/GDCubismEffectCustom" to="Sprite2D/GDCubismUserModel/GDCubismEffectCustom" method="_on_cubism_process"] | ||
[connection signal="cubism_term" from="Sprite2D/GDCubismUserModel/GDCubismEffectCustom" to="Sprite2D/GDCubismUserModel/GDCubismEffectCustom" method="_on_cubism_term"] |
Oops, something went wrong.