Skip to content

Commit

Permalink
better viewport handling
Browse files Browse the repository at this point in the history
  • Loading branch information
emperorofmars committed Dec 11, 2024
1 parent 85da641 commit ba6135d
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 24 deletions.
35 changes: 26 additions & 9 deletions AVA/UNIVRM0/Editor/Processors/AVA_Avatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#if NNA_AVA_UNIVRM0_FOUND

using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;
using nna.processors;
using UnityEditor;
Expand Down Expand Up @@ -57,15 +58,6 @@ public static VRMMeta InitAvatarDescriptor(NNAContext Context)
}
Context.AddObjectToAsset(vrmMeta.name, vrmMeta);

// set viewport
if(Context.Root.transform.GetComponentsInChildren<Transform>().FirstOrDefault(t => t.name == "$ViewportFirstPerson") is var viewportNode && viewportNode != null)
{
var vrmFirstPerson = Context.Root.AddComponent<VRMFirstPerson>();
vrmFirstPerson.FirstPersonBone = viewportNode.parent;
vrmFirstPerson.FirstPersonOffset = viewportNode.transform.position;
Context.AddTrash(viewportNode);
}

var vrmBlendshapeProxy = Context.Root.AddComponent<VRMBlendShapeProxy>();
var vrmBlendShapeAvatar = ScriptableObject.CreateInstance<BlendShapeAvatar>();
vrmBlendShapeAvatar.name = "VRM_BlendshapeAvatar";
Expand Down Expand Up @@ -97,6 +89,31 @@ public static Animator GetOrInitAnimator(NNAContext Context)
}
}


public class AVA_ViewportFirstPerson_VRC_Processor : INameProcessor
{
public const string MatchViewport = @"(?i)\$ViewportFirstPerson$";

public const string _Type = "ava.viewport.first_person";
public string Type => _Type;
public uint Order => AVA_Avatar_UNIVRM0Processor._Order + 1;

public int CanProcessName(NNAContext Context, string NameDefinition)
{
var match = Regex.Match(NameDefinition, MatchViewport);
return match.Success ? match.Index : -1;
}

public void Process(NNAContext Context, Transform Node, string NameDefinition)
{
var vrmFirstPerson = Context.Root.AddComponent<VRMFirstPerson>();
vrmFirstPerson.FirstPersonBone = Node.parent;
vrmFirstPerson.FirstPersonOffset = Node.localPosition;
Context.AddTrash(Node);
}
}


[InitializeOnLoad]
public class Register_AVA_Avatar_UniVRM0
{
Expand Down
39 changes: 29 additions & 10 deletions AVA/VRChat/Editor/Processors/AVA_Avatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
using System.Linq;
using UnityEditor;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;

namespace nna.ava.vrchat
{
public class AVA_Avatar_VRCProcessor : IGlobalProcessor
public class AVA_Avatar_VRC_Processor : IGlobalProcessor
{
public const string _Type = "ava.avatar";
public string Type => _Type;
Expand All @@ -37,14 +38,6 @@ public static class AVAVRCUtils
public static VRCAvatarDescriptor InitAvatarDescriptor(NNAContext Context)
{
var avatar = Context.Root.AddComponent<VRCAvatarDescriptor>();

// set viewport
if(Context.Root.transform.GetComponentsInChildren<Transform>().FirstOrDefault(t => t.name == "$ViewportFirstPerson") is var viewportNode && viewportNode != null)
{
avatar.ViewPosition = viewportNode.transform.position - Context.Root.transform.position;
Context.AddTrash(viewportNode);
}

return avatar;
}

Expand All @@ -62,12 +55,38 @@ public static Animator GetOrInitAnimator(NNAContext Context)
}
}

public class AVA_ViewportFirstPerson_VRC_Processor : INameProcessor
{
public const string MatchViewport = @"(?i)\$ViewportFirstPerson$";

public const string _Type = "ava.viewport.first_person";
public string Type => _Type;
public uint Order => AVA_Avatar_VRC_Processor._Order + 1;

public int CanProcessName(NNAContext Context, string NameDefinition)
{
var match = Regex.Match(NameDefinition, MatchViewport);
return match.Success ? match.Index : -1;
}

public void Process(NNAContext Context, Transform Node, string NameDefinition)
{
var avatar = Context.Root.GetComponent<VRCAvatarDescriptor>();
if(!avatar) throw new NNAException("No Avatar Component created!", _Type);

avatar.ViewPosition = Node.position - Context.Root.transform.position;
Context.AddTrash(Node);
}
}


[InitializeOnLoad]
public class Register_AVA_Avatar_VRC
{
static Register_AVA_Avatar_VRC()
{
NNARegistry.RegisterGlobalProcessor(new AVA_Avatar_VRCProcessor(), DetectorVRC.NNA_VRC_AVATAR_CONTEXT, true);
NNARegistry.RegisterGlobalProcessor(new AVA_Avatar_VRC_Processor(), DetectorVRC.NNA_VRC_AVATAR_CONTEXT, true);
NNARegistry.RegisterNameProcessor(new AVA_ViewportFirstPerson_VRC_Processor(), DetectorVRC.NNA_VRC_AVATAR_CONTEXT);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion AVA/VRChat/Editor/Processors/AVA_EyeTrackingBoneLimits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class AVA_EyeTrackingBoneLimits_VRC_Processor : IGlobalProcessor
{
public const string _Type = EyeTrackingBoneLimits._Type;
public string Type => _Type;
public uint Order => AVA_Avatar_VRCProcessor._Order + 1;
public uint Order => AVA_Avatar_VRC_Processor._Order + 1;

public void Process(NNAContext Context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AVA_EyelidTrackingBlendshape_VRCProcessor : IGlobalProcessor
{
public const string _Type = "ava.eyelidtracking_blendshape";
public string Type => _Type;
public uint Order => AVA_Avatar_VRCProcessor._Order + 1;
public uint Order => AVA_Avatar_VRC_Processor._Order + 1;

public void Process(NNAContext Context)
{
Expand Down
2 changes: 1 addition & 1 deletion AVA/VRChat/Editor/Processors/AVA_VisemesBlendshape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AVA_VisemesBlendshape_VRCProcessor : IGlobalProcessor
{
public const string _Type = "ava.voice_visemes_blendshape";
public string Type => _Type;
public uint Order => AVA_Avatar_VRCProcessor._Order + 1;
public uint Order => AVA_Avatar_VRC_Processor._Order + 1;
public int Priority => 0;

public void Process(NNAContext Context)
Expand Down
2 changes: 1 addition & 1 deletion AVA/VRChat/Editor/Processors/VRC_AvatarColliders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class VRC_AvatarColliders_VRCJsonProcessor : IJsonProcessor
{
public const string _Type = "vrc.avatar_colliders";
public string Type => _Type;
public uint Order => AVA_Avatar_VRCProcessor._Order + 1;
public uint Order => AVA_Avatar_VRC_Processor._Order + 1;
public int Priority => int.MaxValue;

public void Process(NNAContext Context, Transform Node, JObject Json)
Expand Down
2 changes: 1 addition & 1 deletion AVA/VRChat/Editor/Processors/VRC_ControllerMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class VRC_ControllerMapping_VRCJsonProcessor : IJsonProcessor
{
public const string _Type = "vrc.controller_mapping";
public string Type => _Type;
public uint Order => AVA_Avatar_VRCProcessor._Order + 1;
public uint Order => AVA_Avatar_VRC_Processor._Order + 1;
public int Priority => int.MaxValue;

public void Process(NNAContext Context, Transform Node, JObject Json)
Expand Down

0 comments on commit ba6135d

Please sign in to comment.