Example #1
0
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 != None
    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 emitter.isOneShot == False
    assert emitter.allowOverlapping == True

    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=30,
                                            jitter=0.01,
                                            isOneShot=False,
                                            allowOverlapping=True,
                                            seed=42)

    assert emitter2.surface != None
    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 == 30
    assert emitter2.jitter == 0.01
    assert emitter2.isOneShot == False
    assert emitter2.allowOverlapping == True
def test_bounding_box3d_init():
    a = pyjet.BoundingBox3D()
    assert a.lowerCorner.x > a.upperCorner.x
    assert a.lowerCorner.y > a.upperCorner.y
    assert a.lowerCorner.z > a.upperCorner.z

    b = pyjet.BoundingBox3D((-1, -2, -3), (4, 2, 5))
    assert b.lowerCorner.x == -1.0
    assert b.lowerCorner.y == -2.0
    assert b.lowerCorner.z == -3.0
    assert b.upperCorner.x == 4.0
    assert b.upperCorner.y == 2.0
    assert b.upperCorner.z == 5.0

    l, c = pyjet.Vector3D(-1, -2, -3), pyjet.Vector3D(4, 2, 5)
    c = pyjet.BoundingBox3D(l, c)
    assert c.lowerCorner.x == -1.0
    assert c.lowerCorner.y == -2.0
    assert c.lowerCorner.z == -3.0
    assert c.upperCorner.x == 4.0
    assert c.upperCorner.y == 2.0
    assert c.upperCorner.z == 5.0
 def testIsEmpty(self):
     a = pyjet.BoundingBox3D((-2.0, -2.0, 1.0), (4.0, 3.0, 5.0))
     self.assertFalse(a.isEmpty())
def test_bounding_box3d_is_empty():
    a = pyjet.BoundingBox3D((-2.0, -2.0, 1.0), (4.0, 3.0, 5.0))
    assert not a.isEmpty()
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