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

Particle rendering bug in 3D scenes #8637

Open
zxh0916 opened this issue Feb 14, 2025 · 0 comments
Open

Particle rendering bug in 3D scenes #8637

zxh0916 opened this issue Feb 14, 2025 · 0 comments

Comments

@zxh0916
Copy link

zxh0916 commented Feb 14, 2025

Describe the bug
The particles seem to be changing their positions and radius when the camera moving in a 3D scene.

To Reproduce

from math import sin, cos
import numpy as np
import taichi as ti

ti.init(arch=ti.cpu)

faces = np.array([
    [0, 1, 2, 3],  # front
    [4, 5, 6, 7],  # back
    [0, 1, 5, 4],  # bottom
    [2, 3, 7, 6],  # top
    [1, 2, 6, 5],  # right
    [0, 3, 7, 4],  # left
], dtype = np.int32)

indices_array = np.stack([
    faces[:, [0, 1, 2]],
    faces[:, [2, 3, 0]],
], axis=-2).reshape(-1)

# create a box with the given center coordinates and length, width, height
def box_vertices(xyz: np.ndarray, lwh: np.ndarray) -> np.ndarray:
    l, w, h = lwh[..., 0], lwh[..., 1], lwh[..., 2]
    centered_vertices_array = np.stack([
        np.stack([-l/2, -w/2, -h/2], axis=-1),
        np.stack([+l/2, -w/2, -h/2], axis=-1),
        np.stack([+l/2, +w/2, -h/2], axis=-1),
        np.stack([-l/2, +w/2, -h/2], axis=-1),
        np.stack([-l/2, -w/2, +h/2], axis=-1),
        np.stack([+l/2, -w/2, +h/2], axis=-1),
        np.stack([+l/2, +w/2, +h/2], axis=-1),
        np.stack([-l/2, +w/2, +h/2], axis=-1),
    ], axis=-2)
    return centered_vertices_array + np.expand_dims(xyz, -2)

n_boxes = 1

vertices = ti.Vector.field(3, ti.f32, shape=(8*n_boxes, ))
indices  = ti.field(ti.i32, shape=(36*n_boxes, ))
center = ti.Vector.field(3, ti.f32, shape=(1, ))

xyz = np.array([[0.0, 0.0, 0.0]], dtype=np.float32)
lwh = np.array([[1.0, 1.0, 1.0]], dtype=np.float32) # length, width, height along x, y, and z

vertices.from_numpy(box_vertices(xyz, lwh).reshape(-1, 3))
indices.from_numpy(indices_array)
center.from_numpy(np.array([[0.0, 0.0, 0.0]], dtype=np.float32).T)

window = ti.ui.Window("Display Mesh", (640, 640), fps_limit=30)
camera = ti.ui.make_camera()
scene = window.get_scene()
canvas = window.get_canvas()

i = 0

while window.running:
    i = i + 1
    
    cam_pos = np.array([sin(i/60), cos(i/60), 1], dtype=np.float32)
    cam_pos *= (4 + 2*sin(i/30))
    camera.position(*cam_pos)
    camera.lookat(0, 0, 0)
    camera.up(0, 0, 1)
    
    scene.particles(center, radius=0.73, color=(0.8, 0.6, 0.2)) # note that the radius is a constant value
    scene.mesh(vertices, indices, color=(0.8, 0.2, 0.6))
    scene.point_light(pos=(0, 0, 10), color=(1., 1., 1.))
    scene.set_camera(camera)
    canvas.scene(scene)
    window.show()

Log/Screenshots
If you look closely at the overlapping boxes and spheres in the GIF, you'll see that the intersection lines seem to move with the camera's movements.

Image

Image

Additional comments
None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Untriaged
Development

No branches or pull requests

1 participant