diff --git a/client/BodyRenderer.cs b/client/BodyRenderer.cs index 0a60f66..2c57a70 100644 --- a/client/BodyRenderer.cs +++ b/client/BodyRenderer.cs @@ -17,7 +17,8 @@ public partial class BodyRenderer : Node3D /// Bodies drawn, static and dynamic. public int BodyCount => _puppet.BodyCount + _scenery.Count; - public BaseMaterial3D PuppetMaterial => _puppet.Material; + /// The colour the puppet is drawn in. + public Color PuppetColor => _puppet.Color; public BaseMaterial3D SceneryMaterial => _material; /// Where body is drawn now, or null if it is not drawn. diff --git a/client/Puppet.cs b/client/Puppet.cs index 056e14e..67bb03f 100644 --- a/client/Puppet.cs +++ b/client/Puppet.cs @@ -5,20 +5,18 @@ using Ymir.Box3D; namespace BadDay.Client; /// -/// The puppet's mesh: made from the shape lanes (Kind and Size) and the body transforms (the pose lanes) of every -/// dynamic body, one MeshInstance3D per StableId with flat-shaded low-poly limbs. This class is the only owner of -/// "the puppet's mesh from the lanes"; a different model (the SDF isosurface) replaces it and nothing else. +/// The puppet: one pose carrier per dynamic body, posed from the lanes, so physics interpolation has a node to +/// interpolate. This commit draws nothing; the next gives it the one skinned SDF mesh. /// public partial class Puppet : Node3D { - private readonly Dictionary _nodes = new(); + private readonly Dictionary _nodes = new(); private readonly HashSet _seen = new(); - private readonly StandardMaterial3D _dynamic = Look.Matte(Look.Figure); public int BodyCount => _nodes.Count; - /// The material the puppet is drawn in. - public BaseMaterial3D Material => _dynamic; + /// The colour the puppet is drawn in. + public Color Color => Look.Figure; /// Where the puppet draws body now (world), or null if it draws no such body. public Transform3D? PoseOf(ulong stableId) => _nodes.TryGetValue(stableId, out var n) ? n.Transform : null; @@ -26,7 +24,7 @@ public partial class Puppet : Node3D /// The same pose as it is rendered this frame, between the last two ticks. public Transform3D? InterpolatedPoseOf(ulong stableId) => _nodes.TryGetValue(stableId, out var n) ? n.GetGlobalTransformInterpolated() : null; - /// Makes the nodes match the lanes: creates the missing, frees the gone, then poses every node. skips the interpolation from the previous pose. + /// Makes the carriers match the lanes: creates the missing, frees the gone, then poses every one. skips the interpolation from the previous pose. public void Sync(in Box3DSoaView view, bool teleport = false) { var ids = view.StableId; @@ -44,8 +42,7 @@ public partial class Puppet : Node3D for (int i = 0; i < ids.Length; i++) { if (!IsPuppet(kind[i]) || _nodes.ContainsKey(ids[i])) continue; - var node = new MeshInstance3D { Name = $"Body{ids[i]}", Mesh = MeshFor((Box3DSoaKind)kind[i], view.Size0[i], view.Size1[i], view.Size2[i]) }; - node.MaterialOverride = _dynamic; + var node = new Node3D { Name = $"Body{ids[i]}" }; AddChild(node); _nodes[ids[i]] = node; teleport = true; @@ -77,27 +74,4 @@ public partial class Puppet : Node3D for (int i = 0; i < ids.Length; i++) if (IsPuppet(kind[i]) && !_nodes.ContainsKey(ids[i])) return false; return true; } - - /// The mesh for a body: sphere radius Size0; capsule radius Size0 and half-length Size1 along Y (Godot's height counts the caps); box half-extents Size0..2. - public static Mesh MeshFor(Box3DSoaKind kind, float size0, float size1, float size2) => kind switch - { - Box3DSoaKind.Sphere => FlatShaded(new SphereMesh { Radius = size0, Height = 2f * size0, RadialSegments = 8, Rings = 5 }), - Box3DSoaKind.Capsule => FlatShaded(new CapsuleMesh { Radius = size0, Height = 2f * (size1 + size0), RadialSegments = 8, Rings = 2 }), - _ => FlatShaded(new BoxMesh { Size = new Vector3(2f * size0, 2f * size1, 2f * size2) }), - }; - - /// The same triangles with one normal per face. - private static ArrayMesh FlatShaded(PrimitiveMesh source) - { - var arrays = source.GetMeshArrays(); - var vertices = arrays[(int)Mesh.ArrayType.Vertex].AsVector3Array(); - var indices = arrays[(int)Mesh.ArrayType.Index].AsInt32Array(); - var st = new SurfaceTool(); - st.Begin(Mesh.PrimitiveType.Triangles); - st.SetSmoothGroup(uint.MaxValue); - foreach (int i in indices) st.AddVertex(vertices[i]); - st.GenerateNormals(); - return st.Commit(); - } - } diff --git a/client/tests/Smoke.cs b/client/tests/Smoke.cs index 86c61f7..bb5149b 100644 --- a/client/tests/Smoke.cs +++ b/client/tests/Smoke.cs @@ -157,7 +157,7 @@ public partial class Smoke : Node Check(_main.Seed == Seed, "Main did not start from the smoke's seed"); // The look: white on dark grey, flat. - var puppet = _main.Bodies.PuppetMaterial.AlbedoColor; + var puppet = _main.Bodies.PuppetColor; Check(puppet.Luminance > 0.7f && puppet.S < 0.1f, $"the puppet is {puppet}, not white"); Check(_main.Bodies.SceneryMaterial.AlbedoColor.Luminance < 0.3f, "the floor is not dark"); var glow = _main.Chamber.Material.AlbedoColor;