hierachy and parent child system updates

- started working on an editor hierarchy window
- testing filters
- testing parent child relations without system
- testing root component
- thinking about how to get all entities that are not a child, but also don't have an other identifying component
This commit is contained in:
max
2024-10-15 00:41:45 +02:00
parent 0d14a32726
commit 91b4f5fafb
8 changed files with 215 additions and 77 deletions
+12 -8
View File
@@ -2,6 +2,7 @@
using Nerfed.Runtime.Components;
using Nerfed.Runtime.Util;
using System.Numerics;
using static System.Runtime.InteropServices.JavaScript.JSType;
// TODO:
// Explore if having a WorldTransform and LocalTransfom component each holding position, rotation, scale values and the matricies is useful.
@@ -19,7 +20,7 @@ namespace Nerfed.Runtime.Systems
public LocalToWorldSystem(World world) : base(world)
{
rootEntitiesFilter = FilterBuilder.Include<LocalTransform>().Exclude<Parent>().Build();
rootEntitiesFilter = FilterBuilder.Include<LocalTransform>().Exclude<Child>().Build();
}
public override void Update(TimeSpan delta)
@@ -32,20 +33,23 @@ namespace Nerfed.Runtime.Systems
}
}
private void UpdateWorldTransform(in Entity entity, in Matrix4x4 parentLocalToWorld)
private void UpdateWorldTransform(in Entity entity, Matrix4x4 localToWorldMatrix)
{
// TODO: Only update dirty transforms.
// If a parent is dirty all the children need to update their localToWorld matrix.
// How do we check if something is dirty? How do we know if a LocalTransform has been changed?
LocalTransform localTransform = Get<LocalTransform>(entity);
Matrix4x4 localToWorldMatrix = Matrix4x4.Multiply(parentLocalToWorld, localTransform.TRS());
LocalToWorld localToWorld = new(localToWorldMatrix);
Set(entity, localToWorld);
if (Has<LocalTransform>(entity))
{
LocalTransform localTransform = Get<LocalTransform>(entity);
localToWorldMatrix = Matrix4x4.Multiply(localToWorldMatrix, localTransform.TRS());
LocalToWorld localToWorld = new(localToWorldMatrix);
Set(entity, localToWorld);
Log.Info($"Entity {entity} | local position {localTransform.position} | world position {localToWorldMatrix.Translation}");
Log.Info($"Entity {entity} | local position {localTransform.position} | world position {localToWorldMatrix.Translation}");
}
ReverseSpanEnumerator<Entity> childEntities = World.OutRelations<ChildRelation>(entity);
ReverseSpanEnumerator<Entity> childEntities = World.OutRelations<ChildParentRelation>(entity);
foreach (Entity childEntity in childEntities)
{
UpdateWorldTransform(childEntity, localToWorldMatrix);