[flame_3d] Child components do not observe parent transformations
What happened?
Child components have their transformations set with respect to global space. We need to pre-multiply the transform of parent components up the chain, ideally avoiding repeated calculations.
What do you expect?
A child 3d-object inside a parent 3d-object should have its coordinate system wrt to the parent's transform.
How can we reproduce this?
Just created a nested component within the flame_3d playground.
Affected platforms
All
Hi @luanpotter I am interested in solving this bug !! could you assign this to me
Hi @spydon , I was going through the codebase and I had a doubt the parent/child transform composition should happens in transform_3d.dart , component_3d.dart ? Is there any other file that I have to look into
@harshithsaiv this is better to ask @luanpotter , I've barely been involved in flame_3d.
@harshithsaiv I actually haven't taken a look at this and thought about how/where it should work; do you have thoughts / preferences / proposals?
btw - thank you so much for tackling this! I love to see other people interested in expanding flame_3d :)
Thank you @luanpotter , This is a very interesting task to work on
This is the current implementation :
final parent = MeshComponent(
mesh: CubeMesh(),
position: Vector3(10, 0, 0), // Parent at x=10
);
final child = MeshComponent(
mesh: CubeMesh(),
position: Vector3(5, 0, 0), // Child at x=5
);
parent.add(child);
world.add(parent);
- Planning to add a cached world that transforms that compose parent transforms automatically using lazy evaluation. When our transform changes → mark dirty → notify children When parent changes → we get notified → mark dirty → notify children Lazy evaluation: only recalculates when accessed AND dirty
- And also update the rendering to use this cached world transformation .
- Would also write test cases
Amazing! Plan looks solid to me @harshithsaiv , thanks for taking this on! Would the cache live on the Component level? Because we would need one per component. Also need to make sure to include a test of deeply nested component hierarchies as well.