Exemplo n.º 1
0
 def main():
     init()
     for frame in range(250):
         substep()
         mciso.clear()
         voxel.voxelize(mciso.m, pos, 8)
         mciso.march()
         vs, fs = mciso.get_mesh()
         nb.delete_object(f'mciso_output_{frame}')
         mesh = nb.new_mesh(f'mciso_output_{frame}', vs, [], fs)
         yield nb.object_mesh_update(object, mesh)
Exemplo n.º 2
0
        x[i] += v[i] * dt
        u[i] = v[i]
        for j in range(N):
            if i == j: continue
            r = x[i] - x[j]
            if r.norm_sqr() <= (radius * 2)**2 and r.dot(v[i] - v[j]) < 0:
                u[i], _ = tl.momentumExchange(u[i], v[j], r.normalized(), 1.0,
                                              1.0, 0.9)
    for i in x:
        v[i] = u[i]
        v[i].z -= gravity * dt
        v[i] = tl.boundReflect(x[i], v[i], radius - bound, bound - radius,
                               0.87, 0.92)


nb.delete_object('boundary')
for i in range(N):
    nb.delete_object(f'ball_{i}')

bpy.ops.mesh.primitive_cube_add(size=6)
bpy.context.object.name = f'boundary'
bpy.ops.object.modifier_add(type='WIREFRAME')
bpy.ops.object.modifier_apply(apply_as='DATA')

objects = []

for i in range(N):
    bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=3, radius=0.5)
    bpy.ops.object.shade_smooth()
    bpy.context.object.name = f'ball_{i}'
    objects.append(bpy.context.object)
Exemplo n.º 3
0
N = 16

pos = ti.Vector.field(3, float, (N, N))


@ti.kernel
def init():
    for i, j in pos:
        pos[i, j] = ti.Vector([i - N / 2, j - N / 2, 0])


@ti.kernel
def update(t: float):
    for i, j in pos:
        pos[i, j].z = ti.sin(pos[i, j].xy.norm() * 0.5 - t * 2)


verts, edges, faces, uv = nb.meshgrid(N)
nb.delete_mesh('point_cloud')
nb.delete_object('point_cloud')
mesh = nb.new_mesh('point_cloud', verts, edges, faces, uv)
nb.new_object('point_cloud', mesh)


@nb.add_animation
def main():
    init()
    for frame in range(250):
        update(frame * 0.03)
        yield nb.mesh_update(mesh, pos=pos.to_numpy().reshape(N**2, 3))
Exemplo n.º 4
0
            if i == j: continue
            r = x[i] - x[j]
            if r.norm_sqr() <= (radius * 2)**2 and r.dot(v[i] - v[j]) < 0:
                u[i], _ = tl.momentumExchange(u[i], v[j], r.normalized(), 1.0,
                                              1.0, 0.9)
    for i in x:
        v[i] = u[i]
        v[i].z -= gravity * dt
        v[i] = tl.boundReflect(x[i], v[i], radius - bound, bound - radius,
                               0.87, 0.92)


objects = []

for i in range(N):
    nb.delete_object(f'ball_{i}')
    bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=3, radius=0.5)
    bpy.ops.object.shade_smooth()
    bpy.context.object.name = f'ball_{i}'
    objects.append(bpy.context.object)


@nb.add_animation
def main():
    init()
    while True:
        for s in range(steps):
            substep()
        pos = x.to_numpy()
        ret = nb.AnimUpdate()
        for i in range(N):
Exemplo n.º 5
0
stiffness = 2000
damping = 1.6
dt = 5e-4
steps = 144
gravity = 9.8
wind = 0.1
ball_radius = 0.4

pos_, edges_, faces_, uv_ = nb.meshgrid(N, eight=True)
pos_[:, :2] = pos_[:, :2] * 2 - 1
pos_ = pos_[:, (2, 1, 0)]

rest_ = np.sqrt(np.sum((pos_[edges_[:, 0]] - pos_[edges_[:, 1]])**2, axis=1))

nb.delete_mesh('cloth')
nb.delete_object('cloth')
nb.delete_object('ball')
cloth_mesh = nb.new_mesh('cloth', pos_, nb.meshgrid(N)[1], faces_, uv_)
cloth_object = nb.new_object('cloth', cloth_mesh)

bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=3, radius=ball_radius)
ball_object = bpy.context.object
ball_object.name = 'ball'

pos = ti.Vector.field(3, float, pos_.shape[0])
vel = ti.Vector.field(3, float, pos_.shape[0])
edges = ti.Vector.field(2, int, edges_.shape[0])
rest = ti.field(float, rest_.shape[0])
pos.from_numpy(pos_)
edges.from_numpy(edges_)
rest.from_numpy(rest_)
Exemplo n.º 6
0
pos = ti.Vector.field(3, float, (N, N))


@ti.kernel
def init():
    for i, j in pos:
        pos[i, j] = ti.Vector([i - N / 2, j - N / 2, 0])


@ti.kernel
def update(t: float):
    for i, j in pos:
        pos[i, j].z = ti.sin(pos[i, j].xy.norm() * 0.5 - t * 2)


objects = []
for i in range(N**2):
    nb.delete_object(f'cube_{i}')
    bpy.ops.mesh.primitive_cube_add(size=1)
    bpy.context.object.name = f'cube_{i}'
    objects.append(bpy.context.object)


@nb.add_animation
def main():
    init()
    for frame in range(250):
        update(frame * 0.03)
        yield nb.objects_update(objects,
                                location=pos.to_numpy().reshape(N**2, 3))
Exemplo n.º 7
0
    def init():
        for i in pos:
            pos[i] = ti.Vector([ti.random() for t in range(3)]) * 0.2 + 0.4
            vel[i] = ti.Vector([ti.random() for t in range(3)]) * 2 - 1

    @ti.kernel
    def substep():
        for i in pos:
            pos[i] += vel[i] * dt

    import numblend as nb
    import bpy
    bpy.context.scene.frame_current = 0
    nb.init()

    nb.delete_object('mciso_output')
    nb.delete_mesh('mciso_output')
    object = nb.new_object('mciso_output', nb.new_mesh('mciso_output'))

    @nb.add_animation
    def main():
        init()
        for frame in range(250):
            substep()
            mciso.clear()
            voxel.voxelize(mciso.m, pos, 8)
            mciso.march()
            vs, fs = mciso.get_mesh()
            nb.delete_object(f'mciso_output_{frame}')
            mesh = nb.new_mesh(f'mciso_output_{frame}', vs, [], fs)
            yield nb.object_mesh_update(object, mesh)