test_lightattrib.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from panda3d import core
  2. # Some dummy lights we can use for our light attributes.
  3. spot = core.NodePath(core.Spotlight("spot"))
  4. point = core.NodePath(core.PointLight("point"))
  5. ambient = core.NodePath(core.AmbientLight("ambient"))
  6. def test_lightattrib_compose_add():
  7. # Tests a case in which a child node adds another light.
  8. lattr1 = core.LightAttrib.make()
  9. lattr1 = lattr1.add_on_light(spot)
  10. lattr2 = core.LightAttrib.make()
  11. lattr2 = lattr2.add_on_light(point)
  12. lattr3 = lattr1.compose(lattr2)
  13. assert lattr3.get_num_on_lights() == 2
  14. assert spot in lattr3.on_lights
  15. assert point in lattr3.on_lights
  16. def test_lightattrib_compose_subtract():
  17. # Tests a case in which a child node disables a light.
  18. lattr1 = core.LightAttrib.make()
  19. lattr1 = lattr1.add_on_light(spot)
  20. lattr1 = lattr1.add_on_light(point)
  21. lattr2 = core.LightAttrib.make()
  22. lattr2 = lattr2.add_off_light(ambient)
  23. lattr2 = lattr2.add_off_light(point)
  24. lattr3 = lattr1.compose(lattr2)
  25. assert lattr3.get_num_on_lights() == 1
  26. assert spot in lattr3.on_lights
  27. assert point not in lattr3.on_lights
  28. assert ambient not in lattr3.on_lights
  29. def test_lightattrib_compose_both():
  30. # Tests a case in which a child node both enables and disables a light.
  31. lattr1 = core.LightAttrib.make()
  32. lattr1 = lattr1.add_on_light(spot)
  33. lattr1 = lattr1.add_on_light(point)
  34. lattr2 = core.LightAttrib.make()
  35. lattr2 = lattr2.add_on_light(ambient)
  36. lattr2 = lattr2.add_on_light(spot)
  37. lattr2 = lattr2.add_off_light(point)
  38. lattr3 = lattr1.compose(lattr2)
  39. assert lattr3.get_num_on_lights() == 2
  40. assert spot in lattr3.on_lights
  41. assert point not in lattr3.on_lights
  42. assert ambient in lattr3.on_lights
  43. def test_lightattrib_compose_alloff():
  44. # Tests a case in which a child node disables all lights.
  45. lattr1 = core.LightAttrib.make()
  46. lattr1 = lattr1.add_on_light(spot)
  47. lattr1 = lattr1.add_on_light(point)
  48. assert lattr1.get_num_on_lights() == 2
  49. lattr2 = core.LightAttrib.make_all_off()
  50. assert lattr2.has_all_off()
  51. lattr3 = lattr1.compose(lattr2)
  52. assert lattr3.get_num_on_lights() == 0
  53. assert lattr3.get_num_off_lights() == 0
  54. assert lattr3.has_all_off()