diff --git a/Assets/Gothic-Core/Scripts/Domain/Vobs/VobInitializerDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Vobs/VobInitializerDomain.cs index beb1ff979..4fad0242a 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Vobs/VobInitializerDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Vobs/VobInitializerDomain.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Gothic.Core.Adapters.Properties; using Gothic.Core.Adapters.Vob; @@ -53,6 +54,8 @@ public class VobInitializerDomain // Ids of logic VOBs below lazily loaded VOBs that were created with the world (MarkCreatedEarly). private readonly HashSet _createdEarlyVobIds = new(); + private readonly HashSet _loggedHelperMobs = new(); + private readonly HashSet _loggedNoHierarchyMobs = new(); /// @@ -1045,29 +1048,51 @@ private GameObject CreateDefaultMesh(IVirtualObject vob, GameObject parent) { var go = BuildDefaultMesh(vob, parent); if (go != null && !vob.ShowVisual) - HideVisual(vob, go); + HideVisual(go, vob is IInteractiveObject); return go; } /// + /// Draws nothing: the renderers stay enabled with forceRenderingOff, so their bounds still work (focus, dig + /// spots). Colliders are switched off unless keepColliders is set. /// showVisual=FALSE (Spacer): like in the engine (OpenGothic ObjVisual::setVisual) the mesh isn't drawn and a /// plain vob doesn't collide. Mods place such vobs as interaction anchors on world geometry (DoM: ore piles, - /// dig spots, campfires) - a mob stays usable: it keeps its colliders (focus, grab, use) and its nodes. The - /// renderers stay enabled, only drawing is off, so their bounds still work (focus, dig spots). + /// dig spots, campfires) - a mob stays usable: it keeps its colliders (focus, grab, use) and its nodes. + /// A helper mob (only its slots count) loses its colliders too: the hero can't focus or grab it (the helper + /// mesh would be an invisible plank on the wall). /// - private static void HideVisual(IVirtualObject vob, GameObject go) + private static void HideVisual(GameObject go, bool keepColliders) { foreach (var renderer in go.GetComponentsInChildren(true)) renderer.forceRenderingOff = true; - if (vob is IInteractiveObject) + if (keepColliders) return; foreach (var collider in go.GetComponentsInChildren(true)) collider.enabled = false; } + /// + /// Slot nodes (ZS_POS0, ...) are where an NPC stands or uses the mob. + /// + private bool HasSlotNodes(ZenKit.IModel mdl, string meshName) + { + var nodes = mdl.Hierarchy?.Nodes; + if (nodes == null) + { + // Broken or modded models: no hierarchy, so no slots. Warn once per visual, don't fail the world load. + if (_loggedNoHierarchyMobs.Add(meshName)) + Logger.LogWarning($"[VobInitializer] Model {meshName} has no hierarchy - no slot nodes.", + LogCat.Vob); + return false; + } + + return nodes.Any(node => node?.Name != null + && node.Name.StartsWith("ZS_", StringComparison.OrdinalIgnoreCase)); + } + private GameObject BuildDefaultMesh(IVirtualObject vob, GameObject parent) { var go = GetPrefab(vob); @@ -1088,14 +1113,28 @@ private GameObject BuildDefaultMesh(IVirtualObject vob, GameObject parent) // those on purpose (G1's empty harp or WASH_SLOT), but the X needs its mesh to be diggable. Where the // world hides it (showVisual=FALSE, Newworld's spots) it isn't drawn, like in the original. var isDigSpot = _vmCacheService.IsDigSpot(vob); + // A mob whose model is only an untextured helper (G1/G2 REPAIR_PLANK: ZM_REP_HIDDEN and the slot + // ZS_POS0) is invisible in the original, but its slots are where the NPC stands. Without them + // Wld_IsMobAvailable said no, so Fellan in Khorinis' harbour never hammered at his hut. + // Only models with slot nodes: G1's empty harp, flute and WASH_SLOT stay skipped on purpose. + var isHiddenMob = !isDigSpot && vob is IInteractiveObject && !MeshService.HasTexturedMeshes(mdl.Mesh) + && HasSlotNodes(mdl, meshName); + var isUntextured = isDigSpot || isHiddenMob; var ret = _meshService.CreateVob(meshName, mdl, parent: parent, rootGo: go, - useTextureArray: !isDigSpot, allowUntextured: isDigSpot); + useTextureArray: !isUntextured, allowUntextured: isUntextured); // A few objects are broken and have no meshes. We need to destroy them immediately again. if (ret == null) Object.Destroy(go); else if (isDigSpot) SnapDigSpotToLoader(ret); + else if (isHiddenMob) + { + HideVisual(ret, keepColliders: false); + if (_loggedHelperMobs.Add(meshName)) + Logger.LogEditor($"[VobInitializer] Hidden helper mob {meshName} built for its slots.", + LogCat.Vob); + } return ret; } diff --git a/Assets/Gothic-Core/Scripts/Services/Meshes/MeshService.cs b/Assets/Gothic-Core/Scripts/Services/Meshes/MeshService.cs index 96562553f..fb61c1a62 100644 --- a/Assets/Gothic-Core/Scripts/Services/Meshes/MeshService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Meshes/MeshService.cs @@ -128,7 +128,7 @@ public GameObject CreateVob(string objectName, IModel mdl, GameObject parent = null, GameObject rootGo = null, bool useTextureArray = true, bool allowUntextured = false) { - if (!allowUntextured && !HasMeshes(mdl.Mesh)) + if (!allowUntextured && !HasTexturedMeshes(mdl.Mesh)) { return null; } @@ -168,7 +168,7 @@ public GameObject CreateVob(string objectName, IModelMesh mdm, IModelHierarchy m Vector3 position = default, Quaternion rotation = default, GameObject parent = null, GameObject rootGo = null, bool useTextureArray = true) { - if (!HasMeshes(mdm)) + if (!HasTexturedMeshes(mdm)) { return null; } @@ -192,7 +192,10 @@ private static bool HasTextures(IMultiResolutionMesh mrm) return !mrm.Materials.All(m => m.Texture.IsEmpty()); } - private static bool HasMeshes(IModelMesh mdm) + /// + /// The model has something to draw: at least one textured mesh or attachment. + /// + public static bool HasTexturedMeshes(IModelMesh mdm) { // Check if there are completely empty elements without any texture. // G1: e.g. Harp, Flute, and WASH_SLOT (usage moved to a FreePoint within daedalus functions)