"""Example for object and children transformation.

All children A, A1 and B are in the same model with the coordinate system 'obj'.
All transformations applied to 'obj' do also influence A, A1 and B.
A1 is linked to A such that A is the parent of A1.
"""

from math import radians
from pathlib import Path

from animation import Animation

from voraus_3d_visu import Visu

visu = Visu("http://voraus-3d-visu/", clear_all=True)
model = Path(__file__).parent / "transforms.glb"


if __name__ == "__main__":
    with visu.connection():
        obj = visu.add_model(model)
        # Move the object
        input("Press enter to move the object with all children.")
        for step in Animation(0, -1, duration=1):
            visu.update(obj.position.y(step))
        # Rotate the object
        input("Press enter to rotate the object with all children")
        for step in Animation(0, radians(25), duration=1):
            visu.update(obj.rotation.z(step))
        # Reload object with initial transforms
        input("Press enter to reload model with initial transforms.")
        visu.client.clear()
        obj = visu.add_model(
            model,
            position=[-0.5, -0.5, 0],
            rotation=[0, 0, radians(26)],
        )
        # Rotate B
        input("Press enter to rotate B in obj CS.")
        for step in Animation(0, radians(90), duration=1):
            visu.update(obj.child("B").rotation.x(step))
        # Move B
        input("Press enter to move B in obj CS.")
        for step in Animation(0, 1.0, duration=1):
            visu.update(obj.child("B").position.y(step))
        # Rotate A
        input("Press enter to rotate A in obj CS.")
        for step in Animation(0, radians(-20), duration=1):
            visu.update(obj.child("A").rotation.y(step))
        # Move A1
        input("Press enter to move A1 in A CS.")
        for step in Animation(1.0, 0, duration=1):
            visu.update(obj.child("A1").position.x(step))
