示例#1
0
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_)

@ti.kernel
def substep(bx: float, bz: float):
示例#2
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))
示例#3
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)