Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ScriptEngine/Effects/Base/BaseEvent.as
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand Down
41 changes: 32 additions & 9 deletions ScriptEngine/Effects/model3d.as
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<String> events = { "mouth_open" , "mouth_close" };
Array<String> actions = { "show_action" , "hide_action" };
Array<String> delayParam = { "show_delay" , "hide_delay" };

if (visibleTrigger == "mouth_close")
events.Reverse();

for (uint i = 0; i < events.length; i++)
{
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down