def test_volume_grid_emitter3():
    # Basic ctor test
    sphere = pyjet.Sphere3(center=(0.5, 0.5, 0.5), radius=0.15)
    emitter = pyjet.VolumeGridEmitter3(sphere, False)

    assert emitter.sourceRegion
    assert not emitter.isOneShot
    assert emitter.isEnabled

    # Another basic ctor test
    emitter2 = pyjet.VolumeGridEmitter3(sourceRegion=sphere, isOneShot=False)

    assert emitter2.sourceRegion
    assert not emitter2.isOneShot
    assert emitter2.isEnabled

    # One-shot emitter
    emitter3 = pyjet.VolumeGridEmitter3(sourceRegion=sphere, isOneShot=True)

    assert emitter3.isOneShot

    frame = pyjet.Frame()
    solver = pyjet.GridSmokeSolver3(resolution=(32, 32, 32), domainSizeX=1.0)
    solver.emitter = emitter3
    emitter3.addStepFunctionTarget(solver.smokeDensity, 0.0, 1.0)
    emitter3.addStepFunctionTarget(solver.temperature, 0.0, 1.0)

    # Emit some smoke
    old_den = np.array(solver.smokeDensity.dataAccessor(), copy=True)
    solver.update(frame)
    frame.advance()
    new_den = np.array(solver.smokeDensity.dataAccessor(), copy=True)
    diff = np.linalg.norm(old_den - new_den)
    assert diff > 0.0
    assert not emitter3.isEnabled

    # Should not emit more smoke
    old_den = np.array(solver.smokeDensity.dataAccessor(), copy=True)
    emitter3.update(0, 0)
    new_den = np.array(solver.smokeDensity.dataAccessor(), copy=True)
    diff = np.linalg.norm(old_den - new_den)
    assert diff < 1e-20

    # Re-enabling the emitter should make it emit one more time
    emitter3.isEnabled = True
    old_den = np.array(solver.smokeDensity.dataAccessor(), copy=True)
    solver.update(frame)
    frame.advance()
    new_den = np.array(solver.smokeDensity.dataAccessor(), copy=True)
    diff = np.linalg.norm(old_den - new_den)
    assert diff > 0.0
    assert not emitter3.isEnabled

    # ...and gets disabled again
    old_den = np.array(solver.smokeDensity.dataAccessor(), copy=True)
    emitter3.update(0, 0)
    new_den = np.array(solver.smokeDensity.dataAccessor(), copy=True)
    diff = np.linalg.norm(old_den - new_den)
    assert diff < 1e-20
예제 #2
0
def test_inheritance():
    anim = MyPhysicsAnimation()

    anim.isUsingFixedSubTimeSteps = False
    f = pyjet.Frame(index=3, timeIntervalInSeconds=0.1)
    anim.update(f)
    assert anim.init_data == 1
    assert anim.adv_data == 20
 def testAnimation(self):
     a = pyjet.FlipSolver3()
     f = pyjet.Frame()
     a.update(f)
     self.assertEqual(a.currentFrame.index, 0)
     f.advance()
     a.update(f)
     self.assertEqual(a.currentFrame.index, 1)
    def testInheritance(self):
        anim = MyPhysicsAnimation()

        anim.isUsingFixedSubTimeSteps = False
        f = pyjet.Frame(index=3, timeIntervalInSeconds=0.1)
        anim.update(f)
        self.assertEqual(anim.init_data, 1)
        self.assertEqual(anim.adv_data, 20)
예제 #5
0
def test_flip_solver3_animation():
    a = pyjet.FlipSolver3()
    f = pyjet.Frame()
    a.update(f)
    assert a.currentFrame.index == 0
    f.advance()
    a.update(f)
    assert a.currentFrame.index == 1
예제 #6
0
 def testInheritance(self):
     anim = MyAnimation()
     f = pyjet.Frame(3, 0.02)
     anim.update(f)
     self.assertEqual(anim.lastFrame.index, 3)
     self.assertEqual(anim.lastFrame.timeIntervalInSeconds, 0.02)
예제 #7
0
def test_inheritance():
    anim = MyAnimation()
    f = pyjet.Frame(3, 0.02)
    anim.update(f)
    assert anim.lastFrame.index == 3
    assert anim.lastFrame.timeIntervalInSeconds == 0.02
def test_volume_particle_emitter3():
    sphere = pyjet.Sphere3()
    emitter = pyjet.VolumeParticleEmitter3(
        sphere, pyjet.BoundingBox3D((-1, -2, -3), (4, 2, 9)), 0.1,
        (-1, 0.5, 2), (3, 4, 5), (6, 7, 8), 30, 0.01, False, True, 42)

    assert emitter.surface
    assert_bounding_box_similar(emitter.maxRegion,
                                pyjet.BoundingBox3D((-1, -2, -3), (4, 2, 9)))
    assert emitter.spacing == 0.1
    assert_vector_similar(emitter.initialVelocity, (-1, 0.5, 2))
    assert_vector_similar(emitter.linearVelocity, (3, 4, 5))
    assert_vector_similar(emitter.angularVelocity, (6, 7, 8))
    assert emitter.maxNumberOfParticles == 30
    assert emitter.jitter == 0.01
    assert not emitter.isOneShot
    assert emitter.allowOverlapping
    assert emitter.isEnabled

    emitter2 = pyjet.VolumeParticleEmitter3(implicitSurface=sphere,
                                            maxRegion=pyjet.BoundingBox3D(
                                                (-1, -2, -3), (4, 2, 9)),
                                            spacing=0.1,
                                            initialVelocity=(-1, 0.5, 2),
                                            linearVelocity=(3, 4, 5),
                                            angularVelocity=(6, 7, 8),
                                            maxNumberOfParticles=300000,
                                            jitter=0.01,
                                            isOneShot=False,
                                            allowOverlapping=True,
                                            seed=42)

    assert emitter2.surface
    assert_bounding_box_similar(emitter2.maxRegion,
                                pyjet.BoundingBox3D((-1, -2, -3), (4, 2, 9)))
    assert emitter2.spacing == 0.1
    assert_vector_similar(emitter2.initialVelocity, (-1, 0.5, 2))
    assert_vector_similar(emitter2.linearVelocity, (3, 4, 5))
    assert_vector_similar(emitter2.angularVelocity, (6, 7, 8))
    assert emitter2.maxNumberOfParticles == 300000
    assert emitter2.jitter == 0.01
    assert not emitter2.isOneShot
    assert emitter2.allowOverlapping
    assert emitter2.isEnabled

    # Emit some particles
    frame = pyjet.Frame()
    solver = pyjet.ParticleSystemSolver3()
    solver.emitter = emitter2
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles > 0

    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles > old_num_particles

    # Disabling emitter should stop emitting particles
    emitter2.isEnabled = False
    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles == old_num_particles

    # Re-enabling emitter should resume emission
    emitter2.isEnabled = True
    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles > old_num_particles

    # One-shot emitter
    emitter3 = pyjet.VolumeParticleEmitter3(implicitSurface=sphere,
                                            maxRegion=pyjet.BoundingBox3D(
                                                (-1, -2, -3), (4, 2, 9)),
                                            spacing=0.1,
                                            initialVelocity=(-1, 0.5, 2),
                                            linearVelocity=(3, 4, 5),
                                            angularVelocity=(6, 7, 8),
                                            maxNumberOfParticles=300000,
                                            jitter=0.01,
                                            isOneShot=True,
                                            allowOverlapping=True,
                                            seed=42)

    # Emit some particles
    frame = pyjet.Frame()
    solver = pyjet.ParticleSystemSolver3()
    solver.emitter = emitter3
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles > 0
    assert not emitter3.isEnabled

    # Should not emit more particles
    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles == old_num_particles

    # Re-enabling the emitter should make it emit one more time
    emitter3.isEnabled = True
    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles > old_num_particles

    # ...and gets disabled again
    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles == old_num_particles