Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in multiple object animation #405

Open
nikhilmishra000 opened this issue Aug 2, 2023 · 0 comments
Open

bug in multiple object animation #405

nikhilmishra000 opened this issue Aug 2, 2023 · 0 comments

Comments

@nikhilmishra000
Copy link

I have a scene where two leaf bodies have the same name (and they have different parents).

scene/
      -- sphere/
                -- child
      -- box/
             -- child

I cannot animate both child bodies at the same time. It seems that only the one that was added to the scene first can be animated.

In the following example, I specify the track name to be scene/box/child.position, but it seems to animate sphere/child instead!

  • I tried a few variations like /box/child.position (does not animate anything), and box/child.position (also animates the sphere).
  • If I switch the order in which the nodes are added to the tree (scene.add(box) before scene.add(sphere), then any tracks that reference child will always affect box/child instead of scene/child.
import pythreejs 
import ipywidgets
import numpy as np

camera = pythreejs.PerspectiveCamera(fov=90, aspect=1.0, position=[1, 0, 0], up=[0, 0, 1])
orbit_controls = pythreejs.OrbitControls(controlling=camera)
scene = pythreejs.Scene(
    children=[camera, orbit_controls, pythreejs.AmbientLight(color="#FFFFFF")], background="black",
)
renderer = pythreejs.Renderer(scene=scene, camera=camera, controls=[orbit_controls], width=256, height=256)
renderer.camera.add(pythreejs.HemisphereLight())

box = pythreejs.Mesh(
    name="box",
    position=[0, 0.5, 0],
    geometry=pythreejs.BoxGeometry(0.1, 0.1, 0.1),
    material=pythreejs.MeshPhysicalMaterial(color='orange')
)
box.add(
    pythreejs.Mesh(
        name="child",
        position=[0, 0.25, 0],
        geometry=pythreejs.BoxGeometry(0.1, 0.1, 0.1),
        material=pythreejs.MeshPhysicalMaterial(color='cyan')
    ),
)

sphere = pythreejs.Mesh(
    name="sphere",
    position=[0.5, 0, 0],
    geometry=pythreejs.SphereGeometry(radius=0.1, widthSegments=32, heightSegments=32),
    material=pythreejs.MeshPhysicalMaterial(color='red')
)
sphere.add(
    pythreejs.Mesh(
        name="child",
        position=[0.25, 0, 0],
        geometry=pythreejs.SphereGeometry(radius=0.1, widthSegments=32, heightSegments=32),
        material=pythreejs.MeshPhysicalMaterial(color='lime')
    ),
)

scene.add(sphere)
scene.add(box)

t = np.linspace(0, 2 * np.pi, 16)
track = pythreejs.VectorKeyframeTrack(
    name='scene/box/child.position',
    times=t,
    values=np.stack([0.25 * np.cos(t), 0.25 * np.sin(t), np.zeros_like(t)], axis=-1)
)

clip = pythreejs.AnimationClip(tracks=[track])
mixer = pythreejs.AnimationMixer(scene)
action = pythreejs.AnimationAction(mixer, clip, scene)

display(ipywidgets.VBox([renderer, action]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant