def testAnimation(self): a = pyCubbyFlow.FLIPSolver3() f = pyCubbyFlow.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 = pyCubbyFlow.Frame(index=3, timeIntervalInSeconds=0.1) anim.Update(f) self.assertEqual(anim.initData, 1) self.assertEqual(anim.advData, 20)
def test_inheritance(): anim = MyPhysicsAnimation() anim.isUsingFixedSubTimeSteps = False f = pyCubbyFlow.Frame(index=3, timeIntervalInSeconds=0.1) anim.Update(f) assert anim.init_data == 1 assert anim.adv_data == 20
def test_flip_solver3_animation(): a = pyCubbyFlow.FLIPSolver3() f = pyCubbyFlow.Frame() a.Update(f) assert a.currentFrame.index == 0 f.Advance() a.Update(f) assert a.currentFrame.index == 1
def test_volume_particle_emitter2(): # Basic ctor test sphere = pyCubbyFlow.Sphere2() emitter = pyCubbyFlow.VolumeParticleEmitter2( sphere, pyCubbyFlow.BoundingBox2D((-1, -2), (4, 2)), 0.1, (-1, 0.5), (3, 4), 5.0, 30, 0.01, False, True, 42) assert emitter.surface assert_bounding_box_similar(emitter.maxRegion, pyCubbyFlow.BoundingBox2D((-1, -2), (4, 2))) assert emitter.spacing == 0.1 assert_vector_similar(emitter.initialVelocity, (-1, 0.5)) assert_vector_similar(emitter.linearVelocity, (3, 4)) assert emitter.angularVelocity == 5.0 assert emitter.maxNumberOfParticles == 30 assert emitter.jitter == 0.01 assert not emitter.isOneShot assert emitter.allowOverlapping assert emitter.isEnabled # Another basic ctor test emitter2 = pyCubbyFlow.VolumeParticleEmitter2( implicitSurface=sphere, maxRegion=pyCubbyFlow.BoundingBox2D((-1, -2), (4, 2)), spacing=0.1, initialVelocity=(-1, 0.5), linearVelocity=(3, 4), angularVelocity=5.0, maxNumberOfParticles=3000, jitter=0.01, isOneShot=False, allowOverlapping=True, seed=42) assert emitter2.surface assert_bounding_box_similar(emitter2.maxRegion, pyCubbyFlow.BoundingBox2D((-1, -2), (4, 2))) assert emitter2.spacing == 0.1 assert_vector_similar(emitter2.initialVelocity, (-1, 0.5)) assert_vector_similar(emitter2.linearVelocity, (3, 4)) assert emitter2.angularVelocity == 5.0 assert emitter2.maxNumberOfParticles == 3000 assert emitter2.jitter == 0.01 assert not emitter2.isOneShot assert emitter2.allowOverlapping assert emitter2.isEnabled # Emit some particles frame = pyCubbyFlow.Frame() solver = pyCubbyFlow.ParticleSystemSolver2() 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 = pyCubbyFlow.VolumeParticleEmitter2( implicitSurface=sphere, maxRegion=pyCubbyFlow.BoundingBox2D((-1, -2), (4, 2)), spacing=0.1, initialVelocity=(-1, 0.5), linearVelocity=(3, 4), angularVelocity=5.0, maxNumberOfParticles=3000, jitter=0.01, isOneShot=True, allowOverlapping=True, seed=42) # Emit some particles frame = pyCubbyFlow.Frame() solver = pyCubbyFlow.ParticleSystemSolver2() 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
def testInheritance(self): anim = MyAnimation() f = pyCubbyFlow.Frame(3, 0.02) anim.Update(f) self.assertEqual(anim.lastFrame.index, 3) self.assertEqual(anim.lastFrame.timeIntervalInSeconds, 0.02)
def test_volume_grid_emitter3(): # Basic ctor test sphere = pyCubbyFlow.Sphere3(center=(0.5, 0.5, 0.5), radius=0.15) emitter = pyCubbyFlow.VolumeGridEmitter3(sphere, False) assert emitter.sourceRegion assert not emitter.isOneShot assert emitter.isEnabled # Another basic ctor test emitter2 = pyCubbyFlow.VolumeGridEmitter3(sourceRegion=sphere, isOneShot=False) assert emitter2.sourceRegion assert not emitter2.isOneShot assert emitter2.isEnabled # One-shot emitter emitter3 = pyCubbyFlow.VolumeGridEmitter3(sourceRegion=sphere, isOneShot=True) assert emitter3.isOneShot frame = pyCubbyFlow.Frame() solver = pyCubbyFlow.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.DataView(), copy=True) solver.Update(frame) frame.Advance() new_den = np.array(solver.smokeDensity.DataView(), 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.DataView(), copy=True) emitter3.Update(0, 0) new_den = np.array(solver.smokeDensity.DataView(), 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.DataView(), copy=True) solver.Update(frame) frame.Advance() new_den = np.array(solver.smokeDensity.DataView(), 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.DataView(), copy=True) emitter3.Update(0, 0) new_den = np.array(solver.smokeDensity.DataView(), copy=True) diff = np.linalg.norm(old_den - new_den) assert diff < 1e-20
def test_inheritance(): anim = MyAnimation() f = pyCubbyFlow.Frame(3, 0.02) anim.Update(f) assert anim.lastFrame.index == 3 assert anim.lastFrame.timeIntervalInSeconds == 0.02