Created
March 16, 2023 10:08
-
-
Save jarmitage/be406ab7b9b949ceef2c58ef389fea06 to your computer and use it in GitHub Desktop.
Sparse particle field in Taichi using Pointers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import taichi as ti | |
ti.init(arch=ti.cuda) # not supported on vulkan | |
@ti.dataclass | |
class Particle: | |
position: ti.math.vec2 | |
velocity: ti.math.vec2 | |
@ti.data_oriented | |
class Particles: | |
def __init__(self, n=32): | |
self.n = n | |
self.field = Particle.field() | |
self.pointer = ti.root.pointer(ti.i, self.n).place(self.field) | |
@ti.kernel | |
def activate(self, i: int): | |
ti.activate(self.pointer, [i]) | |
@ti.kernel | |
def deactivate(self, i: int): | |
ti.deactivate(self.pointer, [i]) | |
particles = Particles(32) | |
particles.field[0] = Particle(position=[0.5,0.5],velocity=[0.5,0.5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment