|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +Copyright (c) 2018 Doyub Kim |
| 5 | +
|
| 6 | +I am making my contributions/submissions to this project solely in my personal |
| 7 | +capacity and am not conveying any rights to any intellectual property of any |
| 8 | +third parties. |
| 9 | +""" |
| 10 | + |
| 11 | +from pyjet import * |
| 12 | +import numpy as np |
| 13 | +import os |
| 14 | + |
| 15 | +ANIM_NUM_FRAMES = 360 |
| 16 | +ANIM_FPS = 60 |
| 17 | + |
| 18 | + |
| 19 | +def main(): |
| 20 | + # Create APIC solver |
| 21 | + resX = 100 |
| 22 | + solver = ApicSolver3(resolution=(resX, resX, resX), domainSizeX=1.0) |
| 23 | + solver.useCompressedLinearSystem = True |
| 24 | + |
| 25 | + # Setup emitter |
| 26 | + bunny_filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../resources/bunny.obj') |
| 27 | + bunny_mesh = TriangleMesh3() |
| 28 | + bunny_mesh.readObj(bunny_filename) |
| 29 | + bunny_sdf = ImplicitTriangleMesh3(mesh=bunny_mesh, resolutionX=64, margin=0) |
| 30 | + emitter = VolumeParticleEmitter3(implicitSurface=bunny_sdf, spacing=1.0 / (2 * resX), isOneShot=False) |
| 31 | + solver.particleEmitter = emitter |
| 32 | + |
| 33 | + # Convert to surface |
| 34 | + grid_size = 1.0 / resX |
| 35 | + grid = CellCenteredScalarGrid3((resX, resX, resX), (grid_size, grid_size, grid_size)) |
| 36 | + |
| 37 | + def write_surface(frame_cnt, pos): |
| 38 | + converter = SphPointsToImplicit3(2.0 * grid_size, 0.5) |
| 39 | + converter.convert(pos.tolist(), grid) |
| 40 | + surface_mesh = marchingCubes(grid, (grid_size, grid_size, grid_size), (0, 0, 0), 0.0, DIRECTION_ALL) |
| 41 | + surface_mesh.writeObj('frame_{:06d}.obj'.format(frame_cnt)) |
| 42 | + |
| 43 | + # Make first frame |
| 44 | + frame = Frame(0, 1.0 / ANIM_FPS) |
| 45 | + |
| 46 | + for i in range(ANIM_NUM_FRAMES): |
| 47 | + print('Frame {:d}'.format(i)) |
| 48 | + solver.update(frame) |
| 49 | + pos = np.array(solver.particleSystemData.positions, copy=False) |
| 50 | + write_surface(i, pos) |
| 51 | + frame.advance() |
| 52 | + |
| 53 | + |
| 54 | +if __name__ == '__main__': |
| 55 | + Logging.mute() |
| 56 | + main() |
0 commit comments