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

Bugfix/sword in hand #342

Merged
merged 5 commits into from
Apr 20, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using GVR.Npc.Actions.AnimationActions;
using UnityEngine;

namespace GVR.GothicVR_Lab.Scripts.AnimationActionMocks
namespace GVR.Lab.AnimationActionMocks
{
/// <summary>
/// Gothic has two types of External calls:
Expand All @@ -12,9 +12,9 @@ namespace GVR.GothicVR_Lab.Scripts.AnimationActionMocks
/// We need to create a mechanism to handle immediate actions as if they would've been called by Daedalus.
/// These mock classes help implementing it where needed in the Lab.
/// </summary>
public abstract class LabImmediateAnimationAction : AbstractAnimationAction
public abstract class AbstractLabAnimationAction : AbstractAnimationAction
{
protected LabImmediateAnimationAction(AnimationAction action, GameObject npcGo) : base(action, npcGo)
protected AbstractLabAnimationAction(AnimationAction action, GameObject npcGo) : base(action, npcGo)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
using GVR.Npc.Actions;
using GVR.Vm;
using UnityEngine;
using ZenKit.Daedalus;

namespace GVR.GothicVR_Lab.Scripts.AnimationActionMocks
namespace GVR.Lab.AnimationActionMocks
{
public class LabCreateInventoryItem : LabImmediateAnimationAction
public class LabCreateInventoryItem : AbstractLabAnimationAction
{
public LabCreateInventoryItem(AnimationAction action, GameObject npcGo) : base(action, npcGo)
{
Expand All @@ -15,12 +14,9 @@ public LabCreateInventoryItem(AnimationAction action, GameObject npcGo) : base(a
public override void Start()
{
var itemSymbol = GameData.GothicVm.GetSymbolByName(Action.String0);
// GameData.GothicVm.AllocInstance<ItemInstance>(itemSymbol!);
// GameData.GothicVm.InitInstance<ItemInstance>(itemSymbol!);

VmGothicExternals.CreateInvItem(Props.npcInstance, itemSymbol!.Index);


base.Start();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using GVR.Npc.Actions.AnimationActions;
using UnityEngine;

namespace GVR.GothicVR_Lab.Scripts.AnimationActionMocks
namespace GVR.Lab.AnimationActionMocks
{
public class LabUseItemToState : UseItemToState
{
Expand Down
25 changes: 20 additions & 5 deletions Assets/GothicVR-Lab/Scripts/Handler/LabNpcAnimationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using GVR.Creator.Meshes.V2;
using GVR.Extensions;
using GVR.Globals;
using GVR.GothicVR_Lab.Scripts.AnimationActionMocks;
using GVR.Lab.AnimationActionMocks;
using GVR.Npc.Actions;
using GVR.Npc.Actions.AnimationActions;
using GVR.Properties;
Expand All @@ -23,15 +23,22 @@ public class LabNpcAnimationHandler : MonoBehaviour, ILabHandler
public GameObject npcSlotGo;


private Dictionary<string, (string Name, string MdhMds, string Mdm, int BodyTexNr, int BodyTexColor, string Head, int HeadTexNr, int TeethTexNr)> npcs = new()
private Dictionary<string, (string Name, string MdhMds, string Mdm, int BodyTexNr, int BodyTexColor, string Head, int HeadTexNr, int TeethTexNr, string sword)> npcs = new()
{
{"GRD_233_Bloodwyn", (Name: "Bloodwyn", MdhMds: "Humans_Militia.mds", Mdm: "Hum_GRDM_ARMOR", BodyTexNr: 0, BodyTexColor: 1, Head: "Hum_Head_Bald", HeadTexNr: 18, TeethTexNr: 1)},
{"EBR_110_Seraphia", (Name: "Seraphia", MdhMds: "Babe.mds", Mdm: "Bab_body_Naked0", BodyTexNr: 2, BodyTexColor: 1, Head: "Bab_Head_Hair1", HeadTexNr: 2, TeethTexNr: 0)},
{"VLK_554_Buddler", (Name: "Buddler", MdhMds: "Humans_Tired.mds", Mdm: "Hum_VLKL_ARMOR", BodyTexNr: 3, BodyTexColor: 1, Head: "Hum_Head_Pony", HeadTexNr: 0, TeethTexNr: 2)}
{"GRD_233_Bloodwyn", (Name: "Bloodwyn", MdhMds: "Humans_Militia.mds", Mdm: "Hum_GRDM_ARMOR", BodyTexNr: 0, BodyTexColor: 1, Head: "Hum_Head_Bald", HeadTexNr: 18, TeethTexNr: 1, sword: "ItMw_1H_Sword_04")},
{"EBR_110_Seraphia", (Name: "Seraphia", MdhMds: "Babe.mds", Mdm: "Bab_body_Naked0", BodyTexNr: 2, BodyTexColor: 1, Head: "Bab_Head_Hair1", HeadTexNr: 2, TeethTexNr: 0, sword: null)},
{"VLK_554_Buddler", (Name: "Buddler", MdhMds: "Humans_Tired.mds", Mdm: "Hum_VLKL_ARMOR", BodyTexNr: 3, BodyTexColor: 1, Head: "Hum_Head_Pony", HeadTexNr: 0, TeethTexNr: 2, sword: null)}
};

private Dictionary<string, List<(Type, AnimationAction)>> animations = new()
{
{
"Human - Sword training", new()
{
(typeof(DrawWeapon), new()),
(typeof(PlayAni), new("T_1HSFREE"))
}
},
{"Human - Eat Apple", new()
{
(typeof(LabCreateInventoryItem), new(string0: "ItFoApple") ),
Expand Down Expand Up @@ -109,6 +116,14 @@ public void LoadNpcClicked()
};

MeshFactory.CreateNpc(newNpc.name, npcData.Mdm, npcData.MdhMds, body, newNpc);

if (npcData.sword != null)
{
var swordIndex = GameData.GothicVm.GetSymbolByName(npcData.sword)!.Index;
var sword = AssetCache.TryGetItemData(swordIndex);

MeshFactory.CreateNpcWeapon(newNpc, sword, (VmGothicEnums.ItemFlags)sword.MainFlag, (VmGothicEnums.ItemFlags)sword.Flags);
}
}

public void LoadAnimationClicked()
Expand Down
5 changes: 3 additions & 2 deletions Assets/GothicVR/Scripts/Creator/AnimationCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ private static bool TryPlayAnimation(string mdsName, string animationName, GameO
{
clip = LoadAnimationClip(modelAnimation, mdh, go, repeat, mdsAnimationKeyName);
LookupCache.AnimationClipCache[mdsAnimationKeyName] = clip;

AddClipEvents(clip, modelAnimation, anim);
AddClipEndEvent(clip);
}

if (animationComp[mdsAnimationKeyName] == null)
{
AddClipEvents(clip, modelAnimation, anim);
AddClipEndEvent(clip);
animationComp.AddClip(clip, mdsAnimationKeyName);
animationComp[mdsAnimationKeyName]!.layer = modelAnimation.Layer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public abstract class AbstractMeshBuilder
{
protected GameObject RootGo;
protected GameObject ParentGo;
protected string ObjectName;
protected bool HasMeshCollider = true;
protected bool UseTextureArray;

Expand All @@ -42,7 +41,7 @@ public void SetGameObject([CanBeNull] GameObject rootGo, string name = null)

if (name != null)
{
ObjectName = name;
RootGo.name = name;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override GameObject Build()

if (headGo == null)
{
Debug.LogWarning($"No NPC head found for {ObjectName}");
Debug.LogWarning($"No NPC head found for {RootGo.name}");
return RootGo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@ private GameObject EquipMeleeWeapon()
break;
}

var weaponGo = npcGo.FindChildRecursively(slotName);
if (weaponGo == null)
var weaponSlotGo = npcGo.FindChildRecursively(slotName);
if (weaponSlotGo == null)
return null;

GameObject weaponGo;
if (weaponSlotGo.transform.childCount == 0)
{
weaponGo = new GameObject(itemData.Visual);
weaponGo.SetParent(weaponSlotGo, true, true);
}
else
{
weaponGo = weaponSlotGo.transform.GetChild(0).gameObject;
}

// Bugfix: e.g. there's a Buddler who has a NailMace and Club equipped at the same time.
// Therefore we need to check if the Components are already there.
if (!weaponGo.TryGetComponent<MeshFilter>(out var meshFilter))
Expand All @@ -78,18 +89,27 @@ private GameObject EquipRangeWeapon()
break;
}

var weaponGo = npcGo.FindChildRecursively(slotName);
if (weaponGo == null)
var weaponSlotGo = npcGo.FindChildRecursively(slotName);
if (weaponSlotGo == null)
return null;

GameObject weaponGo;
if (weaponSlotGo.transform.childCount == 0)
{
weaponGo = new GameObject(itemData.Visual);
weaponGo.SetParent(weaponSlotGo, true, true);
}
else
{
weaponGo = weaponSlotGo.transform.GetChild(0).gameObject;
}

var meshFilter = weaponGo.AddComponent<MeshFilter>();
var meshRenderer = weaponGo.AddComponent<MeshRenderer>();

// FIXME - We don't handle bow morphs as of now. Neet to do once fighting is implemented.
PrepareMeshFilter(meshFilter, Mmb.Mesh, meshRenderer);
PrepareMeshRenderer(meshRenderer, Mmb.Mesh);


return weaponGo;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/GothicVR/Scripts/Creator/VobCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,10 +796,10 @@ private static GameObject CreateItemMesh(Item vob, ItemInstance item, GameObject
true, parent ?? parentGosNonTeleport[vob.Type], go, useTextureArray: false);
}

private static GameObject CreateItemMesh(ItemInstance item, GameObject go, UnityEngine.Vector3 position = default)
private static GameObject CreateItemMesh(ItemInstance item, GameObject parentGo, UnityEngine.Vector3 position = default)
{
var mrm = AssetCache.TryGetMrm(item.Visual);
return MeshFactory.CreateVob(item.Visual, mrm, position, default, false, parent: go, useTextureArray: false);
return MeshFactory.CreateVob(item.Visual, mrm, position, default, false, parent: parentGo, useTextureArray: false);
}

private static GameObject CreateDecal(IVirtualObject vob, GameObject parent = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ public override void AnimationEventCallback(SerializableEventTag data)
private void SyncZSlots()
{
var rightHand = NpcGo.FindChildRecursively("ZS_RIGHTHAND");
var weapon1h = NpcGo.FindChildRecursively("ZS_SWORD");
var weapon1HSlot = NpcGo.FindChildRecursively("ZS_SWORD");

weapon1h.SetParent(rightHand, true, true);
// No weapon equipped in slot.
if (weapon1HSlot.transform.childCount == 0)
return;

var weaponGo = weapon1HSlot.transform.GetChild(0).gameObject;

weaponGo.SetParent(rightHand, true, true);
}
}
}
2 changes: 1 addition & 1 deletion Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"dependencies": {
"com.unity.collab-proxy": "2.2.0",
"com.unity.feature.development": "1.0.1",
"com.unity.ide.rider": "3.0.27",
"com.unity.ide.rider": "3.0.28",
"com.unity.mobile.android-logcat": "1.3.2",
"com.unity.render-pipelines.universal": "14.0.9",
"com.unity.textmeshpro": "3.2.0-pre.6",
Expand Down
2 changes: 1 addition & 1 deletion Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
}
},
"com.unity.ide.rider": {
"version": "3.0.27",
"version": "3.0.28",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down