Skip to content

Commit

Permalink
feat: refactor and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
rYuuk committed Nov 7, 2023
1 parent 9068a54 commit c71e31e
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 1,019 deletions.
34 changes: 3 additions & 31 deletions Runtime/Data/AvatarRenderSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,6 @@

namespace ReadyPlayerMe.Core
{
public enum Expression
{
None,
Happy,
Lol,
Sad,
Scared,
Rage,
}

public enum RenderPose
{
Relaxed,
PowerStance,
Standing,
ThumbsUp,
}

public enum RenderCamera
{
Portrait,
FullBody
}

[System.Serializable]
public struct BlendShape
{
Expand Down Expand Up @@ -63,7 +39,7 @@ public string GetParametersAsString()
queryBuilder.AddKeyValue(nameof(Core.Expression).ToCamelCase(), Expression.ToString().ToCamelCase());
}

queryBuilder.AddKeyValue(nameof(Pose).ToCamelCase(), RenderSceneHelper.RenderPoseMap[Pose]);
queryBuilder.AddKeyValue(nameof(Pose).ToCamelCase(), RenderSettingsHelper.RenderPoseMap[Pose]);

foreach (var blendShape in BlendShapes)
{
Expand All @@ -90,15 +66,11 @@ public string GetParametersAsString()

if (!IsTransparent)
{
queryBuilder.AddKeyValue(nameof(Background).ToCamelCase(), FloatToRGB(Background));
queryBuilder.AddKeyValue(nameof(Background).ToCamelCase(), RenderSettingsHelper.FloatToRGBString(Background));
}

return queryBuilder.Query;
}

public static string FloatToRGB(Color color)
{
return $"{(int) (color.r * 255)},{(int) (color.g * 255)},{(int) (color.b * 255)}";
}

}
}
36 changes: 24 additions & 12 deletions Runtime/Data/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ public enum MeshType
TeethMesh
}

/// <summary>
/// This enumeration describes the different render scene options.
/// </summary>
public enum AvatarRenderScene
{
[Description("Upper body render")] FullbodyPortrait,
[Description("Upper body render")] HalfbodyPortrait,
[Description("Upper body render with transparent background")] FullbodyPortraitTransparent,
[Description("Upper body render with transparent background")] HalfbodyPortraitTransparent,
[Description("Posed full body render with transparent background")] FullBodyPostureTransparent
}

/// <summary>
/// This enumeration describes the pose options for the avatar skeleton.
/// </summary>
Expand Down Expand Up @@ -111,5 +99,29 @@ public enum FailureType
AvatarRenderError,
OperationCancelled
}

public enum Expression
{
None,
Happy,
Lol,
Sad,
Scared,
Rage,
}

public enum RenderPose
{
Relaxed,
PowerStance,
Standing,
ThumbsUp,
}

public enum RenderCamera
{
Portrait,
FullBody
}

}
39 changes: 0 additions & 39 deletions Runtime/Utils/RenderSceneHelper.cs

This file was deleted.

31 changes: 31 additions & 0 deletions Runtime/Utils/RenderSettingsHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using UnityEngine;

namespace ReadyPlayerMe.Core
{
public static class RenderSettingsHelper
{
public static string ToCamelCase(this string str)
{
if (string.IsNullOrEmpty(str))
return string.Empty;

var letters = str.ToCharArray();
letters[0] = char.ToLower(letters[0]);
return new string(letters);
}

public static Dictionary<RenderPose, string> RenderPoseMap = new Dictionary<RenderPose, string>()
{
{ RenderPose.PowerStance, "power-stance" },
{ RenderPose.Relaxed, "relaxed" },
{ RenderPose.Standing, "standing" },
{ RenderPose.ThumbsUp, "thumbs-up" }
};

public static string FloatToRGBString(Color color)
{
return $"{(int) (color.r * 255)},{(int) (color.g * 255)},{(int) (color.b * 255)}";
}
}
}
File renamed without changes.

This file was deleted.

This file was deleted.

12 changes: 1 addition & 11 deletions Samples~/AvatarRenderSamples/MultipleRenders/RenderPanel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Linq;
using ReadyPlayerMe.Core;
using UnityEngine;
using UnityEngine.UI;
Expand All @@ -11,27 +10,18 @@ public class RenderPanel : MonoBehaviour
[SerializeField] private AvatarRenderSettings renderSettings;
[SerializeField] private Image image;

public Text heading;

private void Start()
{
var avatarRenderLoader = new AvatarRenderLoader();
avatarRenderLoader.OnCompleted = SetImage;
avatarRenderLoader.LoadRender(url, renderSettings);
}

public void SetHeading(string text)
{
var headingText = string.Concat(text.Select(x => char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
heading.text = headingText;
}

public void SetImage(Texture2D texture)
private void SetImage(Texture2D texture)
{
var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(.5f, .5f));
image.sprite = sprite;
image.preserveAspect = true;
}

}
}
8 changes: 0 additions & 8 deletions Samples~/AvatarRenderSamples/SingleRender.meta

This file was deleted.

59 changes: 0 additions & 59 deletions Samples~/AvatarRenderSamples/SingleRender/AvatarRenderExample.cs

This file was deleted.

This file was deleted.

Loading

0 comments on commit c71e31e

Please sign in to comment.