Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tizen.AIAvatar] Refactor AIAvatar #6146

Merged
merged 9 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(c) 2023 Samsung Electronics Co., Ltd.
* Copyright(c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,19 +14,35 @@
* limitations under the License.
*
*/

using System.ComponentModel;
using Tizen.NUI.Scene3D;

namespace Tizen.AIAvatar
{
/// <summary>
/// The AnimationInfo class manages animation data for an Avatar, including motion data and names. It is not meant to be directly edited by users or editors.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class AnimationInfo
{
/// <summary>
/// Gets the motion data associated with this animation.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public MotionData MotionData { get; internal set; }
public MotionData MotionData { get; private set; }

/// <summary>
/// Gets the name of this animation.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string MotionName { get; internal set; }
public string MotionName { get; private set; }

/// <summary>
/// Initializes a new instance of the AnimationInfo class with the specified motion data and name.
/// </summary>
/// <param name="motionData">TheThe motion data associated with this animation.</param>
/// <param name="motionName">The name of this animation.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public AnimationInfo(MotionData motionData, string motionName)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(c) 2023 Samsung Electronics Co., Ltd.
* Copyright(c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,12 +20,19 @@

namespace Tizen.AIAvatar
{
/// <summary>
///
/// </summary>
/// <summary>
/// This class provides arguments for handling avatar motion change events.
/// <member name = "Previous" > The previous state of the avatar's motion.</member>
/// <member name = "Current" > The current state of the avatar's motion.</member>
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class AvatarMotionChangedEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the AvatarMotionChangedEventArgs class with the specified previous and current states.
/// </summary>
/// <param name="previous">The previous state of the avatar's motion.</param>
/// <param name="current">The current state of the avatar's motion.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public AvatarMotionChangedEventArgs(AvatarMotionState previous, AvatarMotionState current)
{
Expand All @@ -36,7 +43,6 @@ public AvatarMotionChangedEventArgs(AvatarMotionState previous, AvatarMotionStat
/// <summary>
/// The previous state.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public AvatarMotionState Previous
{
Expand All @@ -47,7 +53,6 @@ public AvatarMotionState Previous
/// <summary>
/// The current state.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public AvatarMotionState Current
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(c) 2023 Samsung Electronics Co., Ltd.
* Copyright(c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,6 @@ namespace Tizen.AIAvatar
/// <summary>
/// Enumeration for the states.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public enum AvatarMotionState
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(c) 2023 Samsung Electronics Co., Ltd.
* Copyright(c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,17 +16,19 @@
*/

using System;
using System.ComponentModel;
using Tizen.NUI;
using Tizen.NUI.Scene3D;

using static Tizen.AIAvatar.AIAvatar;

namespace Tizen.AIAvatar
{
[EditorBrowsable(EditorBrowsableState.Never)]
internal class EyeBlinker : AnimationModule
internal class EyeBlinker : IBlendShapeModule, IDisposable
{
private AvatarMotionState currentMotionState = AvatarMotionState.Unavailable;

private readonly Object motionChangedLock = new Object();
private event EventHandler<AvatarMotionChangedEventArgs> motionChanged;

private const int blinkIntervalMinimum = 800;
private const int blinkIntervalMaximum = 3000;
private Animation eyeAnimation;
Expand All @@ -36,39 +38,84 @@ internal class EyeBlinker : AnimationModule
private bool isPlaying = false;
private const int blinkDuration = 200;

[EditorBrowsable(EditorBrowsableState.Never)]
internal EyeBlinker()
public AvatarMotionState CurrentMotionState
{
get
{
return currentMotionState;
}
set
{
if (currentMotionState == value)
{
return;
}
var preState = currentMotionState;
currentMotionState = value;
if (motionChanged != null)
{
motionChanged?.Invoke(this, new AvatarMotionChangedEventArgs(preState, currentMotionState));
}
}
}

public event EventHandler<AvatarMotionChangedEventArgs> MotionStateChanged
{
add
{
lock (motionChangedLock)
{
motionChanged += value;
}

}

remove
{
lock (motionChangedLock)
{
if (motionChanged == null)
{
Log.Error(LogTag, "Remove StateChanged Failed : motionChanged is null");
return;
}
motionChanged -= value;
}
}
}

public EyeBlinker()
{

}

[EditorBrowsable(EditorBrowsableState.Never)]
public override void Init(Animation eyeAnimation)
public void Dispose()
{
DestroyAnimation();
}

public void Init(Animation eyeAnimation)
{
this.eyeAnimation = eyeAnimation;
}

[EditorBrowsable(EditorBrowsableState.Never)]
public override void Play(IAnimationModuleData data)
public void Play()
{
//data
StartEyeBlink();
}

[EditorBrowsable(EditorBrowsableState.Never)]
public override void Stop()
public void Stop()
{
StopEyeBlink();
}

[EditorBrowsable(EditorBrowsableState.Never)]
public override void Pause()
public void Pause()
{
eyeAnimation?.Pause();
}

[EditorBrowsable(EditorBrowsableState.Never)]
public override void Destroy()
public void Destroy()
{
DestroyAnimation();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(c) 2023 Samsung Electronics Co., Ltd.
* Copyright(c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,14 +15,21 @@
*
*/

using System.ComponentModel;
using Tizen.NUI;

namespace Tizen.AIAvatar
{
internal class BlendShapeValue
internal interface IBlendShapeModule
{
internal string nodeName;
internal BlendShapeType blendIndex;
internal float blendValue;
public void Init(Animation animation);

public void Play();

public void Stop();

public void Pause();

public void Destroy();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,26 @@
*
*/

using System.ComponentModel;
using Tizen.NUI;
using Tizen.NUI.Scene3D;

using static Tizen.AIAvatar.AIAvatar;

namespace Tizen.AIAvatar
{
internal class MotionPlayer
{
private Animation motionAnimation;
private EyeBlinker eyeBlinker;

internal Animation MotionAnimation { get => motionAnimation; private set => motionAnimation = value; }

internal MotionPlayer()
{
eyeBlinker = new EyeBlinker();


}

/// <summary>
/// Play avatar animation by AnimationInfo
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal void PlayAnimation(Animation motionAnimation, int duration = 3000, bool isLooping = false, int loopCount = 1)
{
ResetAnimations();
Expand All @@ -51,24 +49,42 @@ internal void PlayAnimation(Animation motionAnimation, int duration = 3000, bool
}
}

/// <summary>
/// Pause avatar animation
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal void PauseMotionAnimation()
{
MotionAnimation?.Pause();
}

/// <summary>
/// Stop avatar animation
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal void StopMotionAnimation()
{
MotionAnimation?.Stop();
}

internal void SetBlinkAnimation(Animation blinkerAnimation)
{
eyeBlinker?.Init(blinkerAnimation);
}

internal void StartEyeBlink()
{
eyeBlinker?.Play();
}

internal void PauseEyeBlink()
{
eyeBlinker?.Pause();
}


internal void StopEyeBlink()
{
eyeBlinker?.Stop();
}

internal void DestroyAnimations()
{
eyeBlinker?.Destroy();
}

private void ResetAnimations()
{
if (MotionAnimation != null)
Expand All @@ -78,5 +94,6 @@ private void ResetAnimations()
MotionAnimation = null;
}
}

}
}
Loading
Loading