diff --git a/ScriptEngine/Effects/Base/BaseEvent.as b/ScriptEngine/Effects/Base/BaseEvent.as index 3eaa920..7f31d37 100644 --- a/ScriptEngine/Effects/Base/BaseEvent.as +++ b/ScriptEngine/Effects/Base/BaseEvent.as @@ -10,7 +10,7 @@ class BaseEvent : BaseEffectImpl // Initialise with JSONValue with some BaseAction bool Init(const JSONValue& effect_desc, BaseEffect@ parent) override { - if (!BaseEffectImpl::Init(effect_desc, parent)) + if (effect_desc.valueType == JSON_NULL || !BaseEffectImpl::Init(effect_desc, parent)) return false; if (effect_desc.isString) @@ -19,10 +19,10 @@ class BaseEvent : BaseEffectImpl BaseEffect@ action = AddChildEffect(actionName); // Adopt action to creator parent, not to event! - // But action is also among `_childern` of event... + // But action is also among the `_childern` of event... if (!action.Init(parent)) { - log.Error("BaseEvent: Cannot init " + actionName + " for patch"); + log.Error("BaseEvent: Cannot init " + actionName + " for " + parent.GetName()); return false; } @@ -36,7 +36,7 @@ class BaseEvent : BaseEffectImpl BaseEffect@ action = AddChildEffect(actionName); if (!action.Init(effect_desc, parent)) { - log.Error("BaseEvent: Cannot init " + actionName + " for patch"); + log.Error("BaseEvent: Cannot init " + actionName + " for " + parent.GetName()); return false; } } diff --git a/ScriptEngine/Effects/model3d.as b/ScriptEngine/Effects/model3d.as index 7a69f91..b501fe9 100644 --- a/ScriptEngine/Effects/model3d.as +++ b/ScriptEngine/Effects/model3d.as @@ -21,8 +21,8 @@ class model_texture_animation String texture_resource; // From artist's settings in 'mask.json' - String trigger_start; - String trigger_stop; + String trigger_start = ""; + String trigger_stop = ""; float fps = 30.0; // Runtime variables @@ -72,9 +72,21 @@ class model_texture_animation if (trigger_start == "face_found" || trigger_stop == "face_lost") SubscribeToEvent("UpdateFaceDetected", "HandleFaceDetected"); + if (trigger_start == "mouth_open") + SubscribeToEvent("MouthTrigger", "HandleMouthTrigger"); + SubscribeToEvent("Update", "HandleUpdate"); } + private void HandleMouthTrigger(StringHash eventType, VariantMap& eventData) + { + if (eventData["NFace"].GetUInt() != 0 || !eventData["Opened"].GetBool()) + return; + + if (!running) + start(); + } + private bool parse_description(JSONValue& texture_desc) { if (texture_desc.Contains("texture")) @@ -276,7 +288,7 @@ class model_texture_animation if (animation_type == "once" && elapsedTime >= duration) // if (animation_type == "once" && frame >= texturePaths.length) { - stop(trigger_start == "tap"); + stop(trigger_start == "tap" || trigger_start == "mouth_open"); return; } @@ -387,11 +399,15 @@ class model3d : BaseEffectImpl } // Visibility Triggers - if (effect_desc.Get("visible").GetString() == "mouth_open") + String visibleTrigger = effect_desc.Get("visible").GetString(); + if (visibleTrigger == "mouth_open" || visibleTrigger == "mouth_close") { Array events = { "mouth_open" , "mouth_close" }; Array actions = { "show_action" , "hide_action" }; Array delayParam = { "show_delay" , "hide_delay" }; + + if (visibleTrigger == "mouth_close") + events.Reverse(); for (uint i = 0; i < events.length; i++) { @@ -400,28 +416,28 @@ class model3d : BaseEffectImpl if (mouthOpen is null) { - log.Error("Cannot create mouthOpen for patch"); + log.Error("Cannot init mouth_open for model3d"); return false; } String json; if (effect_desc.Contains(delayParam[i])) - json = "{ \"name\" : \"" + actions[i] + "\"," + + json = "{ \"name\": \"" + actions[i] + "\"," + "\"delay\":" + effect_desc.Get(delayParam[i]).GetFloat() + "}"; else - json = actions[i]; + json = "{ \"name\": \"" + actions[i] + "\" }"; JSONFile@ jsonFile = JSONFile(); jsonFile.FromString(json); if (!mouthOpen.Init(jsonFile.GetRoot(), this)) { - log.Error("Cannot init mouthOpen for patch"); + log.Error("Cannot init mouth_open for model3d"); return false; } } - _visible = false; + _visible = visibleTrigger == "mouth_close"; } // Init position / rotation / scale @@ -954,6 +970,13 @@ class model3d : BaseEffectImpl return materials; } + Material@ GetMaterial() override + { + if (!materials.empty) + return materials[0]; + return null; + } + BaseAnimation@ GetAnimation() override { return baseAnimation;