Skip to content

Commit

Permalink
Merge pull request #108 from Ashadow700/implement-scenes
Browse files Browse the repository at this point in the history
BrioScenes V1
  • Loading branch information
Minmoose authored Jan 10, 2025
2 parents 3df5b0b + ab0ebb3 commit 8cb515d
Show file tree
Hide file tree
Showing 32 changed files with 693 additions and 48 deletions.
5 changes: 4 additions & 1 deletion Brio/Brio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Diagnostics;
using Brio.Game.Scene;

namespace Brio;

Expand Down Expand Up @@ -113,6 +114,7 @@ private static ServiceCollection SetupServices(DalamudServices dalamudServices)
serviceCollection.AddSingleton<GameDataProvider>();
serviceCollection.AddSingleton<WelcomeService>();
serviceCollection.AddSingleton<InputService>();
serviceCollection.AddSingleton<SceneService>();

// IPC
serviceCollection.AddSingleton<BrioIPCService>();
Expand Down Expand Up @@ -155,8 +157,9 @@ private static ServiceCollection SetupServices(DalamudServices dalamudServices)
serviceCollection.AddSingleton<FileTypeInfoBase, CMToolPoseFileInfo>();
serviceCollection.AddSingleton<FileTypeInfoBase, PoseFileInfo>();
serviceCollection.AddSingleton<FileTypeInfoBase, MareCharacterDataFileInfo>();
serviceCollection.AddSingleton<FileTypeInfoBase, SceneFileInfo>();
serviceCollection.AddSingleton<FileService>();

serviceCollection.AddSingleton<SourceBase, GameDataNpcSource>();
serviceCollection.AddSingleton<SourceBase, GameDataMountSource>();
serviceCollection.AddSingleton<SourceBase, GameDataOrnamentSource>();
Expand Down
14 changes: 14 additions & 0 deletions Brio/Capabilities/Actor/ActorAppearanceCapability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ public Task ToggleHide()
return SetAppearance(appearance, AppearanceImportOptions.ExtendedAppearance);
}

public Task Hide()
{
var appearance = _actorAppearanceService.GetActorAppearance(Character);
appearance.ExtendedAppearance.Transparency = 1f;
return SetAppearance(appearance, AppearanceImportOptions.ExtendedAppearance);
}

public Task Show()
{
var appearance = _actorAppearanceService.GetActorAppearance(Character);
appearance.ExtendedAppearance.Transparency = 0f;
return SetAppearance(appearance, AppearanceImportOptions.ExtendedAppearance);
}

public Task ApplyEmperors()
{
var appearance = _actorAppearanceService.GetActorAppearance(Character);
Expand Down
12 changes: 9 additions & 3 deletions Brio/Capabilities/Actor/ActorContainerCapability.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Brio.Capabilities.Core;
using System;
using Brio.Capabilities.Core;
using Brio.Entities;
using Brio.Entities.Actor;
using Brio.Entities.Core;
using Brio.Game.Actor;
using Brio.Game.Core;
using Brio.Game.GPose;
Expand Down Expand Up @@ -32,19 +34,23 @@ public void SelectActorInHierarchy(ActorEntity entity)
_entityManager.SetSelectedEntity(entity);
}

public void CreateCharacter(bool enableAttachments, bool targetNewInHierarchy, bool forceSpawnActorWithoutCompanion = false)
public (EntityId, ICharacter) CreateCharacter(bool enableAttachments, bool targetNewInHierarchy, bool forceSpawnActorWithoutCompanion = false)
{
SpawnFlags flags = SpawnFlags.Default;
if(enableAttachments)
flags |= SpawnFlags.ReserveCompanionSlot;

if(_actorSpawnService.CreateCharacter(out var chara, flags, disableSpawnCompanion: forceSpawnActorWithoutCompanion))
{
EntityId characterId = new EntityId(chara);
if(targetNewInHierarchy)
{
_entityManager.SetSelectedEntity(chara);
_entityManager.SetSelectedEntity(characterId);
}
return (characterId, chara);
}

throw new Exception("Failed to create character");
}

public void DestroyCharacter(ActorEntity entity)
Expand Down
23 changes: 19 additions & 4 deletions Brio/Capabilities/Actor/CompanionCapability.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Brio.Entities.Actor;
using Brio.Entities;
using Brio.Entities.Actor;
using Brio.Game.Actor;
using Brio.Game.Actor.Extensions;
using Brio.Game.Types;
Expand All @@ -14,13 +15,14 @@ internal unsafe class CompanionCapability : ActorCharacterCapability
public ModeType Mode { get; }

private readonly ActorSpawnService _actorSpawnService;
private readonly EntityManager _entityManager;


public CompanionCapability(ActorEntity parent, ModeType mode, ActorSpawnService actorSpawnService) : base(parent)
public CompanionCapability(ActorEntity parent, ModeType mode, ActorSpawnService actorSpawnService, EntityManager entityManager) : base(parent)
{
Mode = mode;
_actorSpawnService = actorSpawnService;
_entityManager = entityManager;

Mode = mode;
Widget = new CompanionWidget(this);
}

Expand All @@ -34,6 +36,19 @@ public void SetCompanion(CompanionContainer container)
_actorSpawnService.CreateCompanion(Character, container);
}

public unsafe Entities.Core.Entity? GetCompanionAsEntity()
{
if(Character.HasSpawnedCompanion())
{
if(_entityManager.TryGetEntity(&Character.Native()->CompanionObject->Character.GameObject, out Entities.Core.Entity? actor))
{
return actor;
}
}

return null;
}

public static CompanionCapability? CreateIfEligible(IServiceProvider provider, ActorEntity entity)
{
if(entity.GameObject is ICharacter character && character.HasCompanionSlot())
Expand Down
5 changes: 3 additions & 2 deletions Brio/Capabilities/Debug/DebugCapability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Brio.Entities.Core;
using Brio.Game.GPose;
using Brio.UI.Widgets.Debug;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.Game.Control;
using FFXIVClientStructs.FFXIV.Client.Game.Event;
Expand All @@ -16,10 +17,10 @@ internal unsafe class DebugCapability : Capability
{
private readonly GPoseService _gPoseService;

public DebugCapability(Entity parent, GPoseService gPoseService) : base(parent)
public DebugCapability(IClientState clientState, Entity parent, GPoseService gPoseService) : base(parent)
{
_gPoseService = gPoseService;
Widget = new DebugWidget(this);
Widget = new DebugWidget(this, clientState);
}

public void EnterGPose()
Expand Down
45 changes: 42 additions & 3 deletions Brio/Capabilities/Posing/ModelPosingCapability.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Brio.Capabilities.Actor;
using Brio.Config;
using Brio.Core;
using Brio.Entities.Actor;
using Brio.Files;
using Brio.Game.Posing;
using System.Numerics;

namespace Brio.Capabilities.Posing;

Expand Down Expand Up @@ -40,7 +42,6 @@ public unsafe Transform OriginalTransform

public Transform? OverrideTransform => _transformOverride;


private Transform? _transformOverride = null;
private Transform? _originalTransform = null;

Expand All @@ -66,15 +67,53 @@ public override void Dispose()
ResetTransform();
}

public void ImportModelPose(PoseFile poseFile, PoseImporterOptions options)
public void ImportModelPose(PoseFile poseFile, PoseImporterOptions options, bool isLoadingAsScene)
{
if(options.ApplyModelTransform)
Transform += poseFile.ModelDifference;
{
if(isLoadingAsScene)
{
Transform = new Transform
{
Position = ConfigurationService.Instance.Configuration.Import.PositionTransformType switch
{
ScenePoseTransformType.Difference => Transform.Position + poseFile.ModelDifference.Position,
ScenePoseTransformType.Absolute => poseFile.ModelAbsoluteValues.Position,
_ => Transform.Position
},
Rotation = ConfigurationService.Instance.Configuration.Import.RotationTransformType switch
{
ScenePoseTransformType.Difference => Quaternion.Normalize(Transform.Rotation * poseFile.ModelDifference.Rotation),
ScenePoseTransformType.Absolute => poseFile.ModelAbsoluteValues.Rotation,
_ => Transform.Rotation
},
Scale = ConfigurationService.Instance.Configuration.Import.ScaleTransformType switch
{
ScenePoseTransformType.Difference => Transform.Scale + poseFile.ModelDifference.Scale,
ScenePoseTransformType.Absolute => poseFile.ModelAbsoluteValues.Scale,
_ => Transform.Scale
}
};
}
else
{
Transform += poseFile.ModelDifference;
}
}
}

public void ExportModelPose(PoseFile poseFile)
{
if(_originalTransform.HasValue)
{
poseFile.ModelDifference = Transform.CalculateDiff(_originalTransform.Value);
}

poseFile.ModelAbsoluteValues = Transform;

// For better support for other pose tools
poseFile.Position = Transform.Position;
poseFile.Rotation = Transform.Rotation;
poseFile.Scale = Transform.Scale;
}
}
8 changes: 4 additions & 4 deletions Brio/Capabilities/Posing/PosingCapability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Brio.Config;
using Brio.Core;
using Brio.Entities.Actor;
using Brio.Entities.Core;
using Brio.Files;
using Brio.Game.Posing;
using Brio.Input;
Expand Down Expand Up @@ -180,6 +179,8 @@ internal void ImportPose_internal(OneOf<PoseFile, CMToolPoseFile> rawPoseFile, P
else if(asScene)
{
options = _posingService.SceneImporterOptions;

options.ApplyModelTransform = ConfigurationService.Instance.Configuration.Import.ApplyModelTransform;
}
else if(asIPCpose)
{
Expand All @@ -196,7 +197,7 @@ internal void ImportPose_internal(OneOf<PoseFile, CMToolPoseFile> rawPoseFile, P
SkeletonPosing.ImportSkeletonPose(poseFile, options, expressionPhase2);

if(asExpression == false)
ModelPosing.ImportModelPose(poseFile, options);
ModelPosing.ImportModelPose(poseFile, options, asScene);

if(generateSnapshot)
_framework.RunOnTick(() => Snapshot(reset, reconcile, asExpression: asExpression), delayTicks: 4);
Expand Down Expand Up @@ -295,8 +296,7 @@ private void Reconcile(bool reset = true, bool generateSnapshot = true)
ImportPose_internal(poseFile, options: all, generateSnapshot: false);
}, delayTicks: 2);
}

private PoseFile GeneratePoseFile()
public PoseFile GeneratePoseFile()
{
var poseFile = new PoseFile();
SkeletonPosing.ExportSkeletonPose(poseFile);
Expand Down
6 changes: 6 additions & 0 deletions Brio/Config/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ internal class Configuration : IPluginConfiguration

// Environment
public EnvironmentConfiguration Environment { get; set; } = new EnvironmentConfiguration();

public SceneImportConfiguration Import { get; set; } = new SceneImportConfiguration();

// Library
public LibraryConfiguration Library { get; set; } = new LibraryConfiguration();

public string LastMCDFPath { get; set; } = string.Empty;
public string LastExportPath { get; set; } = string.Empty;
public string LastXATPath { get; set; } = string.Empty;

public string LastScenePath { get; set; } = string.Empty;

public bool UseLibraryWhenImporting { get; set; } = true;

public bool SceneDestoryActorsBeforeImport { get; set; } = false;

// Input
public InputConfiguration Input { get; set; } = new InputConfiguration();

Expand Down
17 changes: 17 additions & 0 deletions Brio/Config/SceneImportConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Brio.Config;

internal class SceneImportConfiguration
{
public bool ApplyModelTransform { get; set; } = true;

public ScenePoseTransformType PositionTransformType { get; set; } = ScenePoseTransformType.Difference;
public ScenePoseTransformType RotationTransformType { get; set; } = ScenePoseTransformType.Absolute;
public ScenePoseTransformType ScaleTransformType { get; set; } = ScenePoseTransformType.Absolute;
}

internal enum ScenePoseTransformType
{
Ignore,
Difference,
Absolute
}
2 changes: 1 addition & 1 deletion Brio/Entities/Actor/ActorContainerEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override void OnAttached()

public override void OnChildAttached() => SortChildren();
public override void OnChildDetached() => SortChildren();


private void SortChildren()
{
Expand Down
8 changes: 4 additions & 4 deletions Brio/Entities/Actor/ActorEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ internal class ActorEntity(IGameObject gameObject, IServiceProvider provider) :

private readonly ConfigurationService _configService = provider.GetRequiredService<ConfigurationService>();

string name = "";
public string RawName = "";
public override string FriendlyName
{
get
{
if(string.IsNullOrEmpty(name))
if(string.IsNullOrEmpty(RawName))
{
return _configService.Configuration.Interface.CensorActorNames ? GameObject.GetCensoredName() : GameObject.GetFriendlyName();
}

return GameObject.GetAsCustomName(name);
return GameObject.GetAsCustomName(RawName);
}
set
{
name = value;
RawName = value;
}
}
public override FontAwesomeIcon Icon => IsProp ? FontAwesomeIcon.Cube : GameObject.GetFriendlyIcon();
Expand Down
11 changes: 11 additions & 0 deletions Brio/Entities/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ public bool TryGetEntity<T>(EntityId id, [MaybeNullWhen(false)] out T entity) wh
_entityMap.TryGetValue(id, out var entity);
return entity;
}

public T? GetEntity<T>(EntityId id) where T : Entity
{
_entityMap.TryGetValue(id, out var entity);

if(entity is T t)
{
return t;
}
return null;
}

public bool EntityExists(EntityId id)
{
Expand Down
Loading

0 comments on commit 8cb515d

Please sign in to comment.