basilisk-engine 0.1.22__tar.gz → 0.1.24__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of basilisk-engine might be problematic. Click here for more details.

Files changed (151) hide show
  1. {basilisk_engine-0.1.22/basilisk_engine.egg-info → basilisk_engine-0.1.24}/PKG-INFO +1 -1
  2. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/__init__.py +1 -1
  3. basilisk_engine-0.1.24/basilisk/config.py +4 -0
  4. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/draw/draw.py +6 -6
  5. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/draw/draw_handler.py +4 -8
  6. basilisk_engine-0.1.24/basilisk/engine.py +170 -0
  7. basilisk_engine-0.1.24/basilisk/input_output/IO_handler.py +92 -0
  8. basilisk_engine-0.1.24/basilisk/input_output/clock.py +50 -0
  9. basilisk_engine-0.1.24/basilisk/input_output/keys.py +44 -0
  10. basilisk_engine-0.1.24/basilisk/input_output/mouse.py +90 -0
  11. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/nodes/node.py +12 -10
  12. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/nodes/node_handler.py +4 -3
  13. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/particles/particle_handler.py +1 -1
  14. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/particles/particle_renderer.py +1 -1
  15. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/camera.py +84 -48
  16. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/frame.py +8 -14
  17. basilisk_engine-0.1.24/basilisk/render/framebuffer.py +289 -0
  18. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/image_handler.py +7 -9
  19. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/light_handler.py +1 -1
  20. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/material_handler.py +8 -12
  21. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/shader.py +1 -2
  22. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/shader_handler.py +18 -15
  23. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/sky.py +4 -4
  24. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/scene.py +40 -37
  25. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24/basilisk_engine.egg-info}/PKG-INFO +1 -1
  26. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk_engine.egg-info/SOURCES.txt +6 -3
  27. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/setup.py +1 -1
  28. basilisk_engine-0.1.22/basilisk/config.py +0 -3
  29. basilisk_engine-0.1.22/basilisk/engine.py +0 -217
  30. basilisk_engine-0.1.22/basilisk/input/mouse.py +0 -62
  31. basilisk_engine-0.1.22/basilisk/render/framebuffer.py +0 -131
  32. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/MANIFEST.in +0 -0
  33. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/README.md +0 -0
  34. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/audio/__init__.py +0 -0
  35. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/audio/sound.py +0 -0
  36. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/bsk_assets/Roboto-Regular.ttf +0 -0
  37. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/bsk_assets/__init__.py +0 -0
  38. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/bsk_assets/basilisk.png +0 -0
  39. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/bsk_assets/cube.obj +0 -0
  40. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/bsk_assets/skybox.png +0 -0
  41. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/__init__.py +0 -0
  42. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/broad/__init__.py +0 -0
  43. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/broad/broad_aabb.py +0 -0
  44. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/broad/broad_bvh.py +0 -0
  45. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/collider.py +0 -0
  46. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/collider_handler.py +0 -0
  47. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/narrow/__init__.py +0 -0
  48. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/narrow/contact_manifold.py +0 -0
  49. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/narrow/dataclasses.py +0 -0
  50. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/narrow/deprecated.py +0 -0
  51. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/narrow/epa.py +0 -0
  52. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/narrow/gjk.py +0 -0
  53. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/narrow/graham_scan.py +0 -0
  54. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/narrow/helper.py +0 -0
  55. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/narrow/line_intersections.py +0 -0
  56. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/collisions/narrow/sutherland_hodgman.py +0 -0
  57. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/draw/__init__.py +0 -0
  58. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/draw/font_renderer.py +0 -0
  59. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/__init__.py +0 -0
  60. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/abstract_bvh.py +0 -0
  61. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/abstract_custom.py +0 -0
  62. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/collisions.py +0 -0
  63. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/input_validation.py +0 -0
  64. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/math.py +0 -0
  65. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/matrices.py +0 -0
  66. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/meshes.py +0 -0
  67. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/quat.py +0 -0
  68. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/quat_methods.py +0 -0
  69. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/raycast_result.py +0 -0
  70. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/generic/vec3.py +0 -0
  71. {basilisk_engine-0.1.22/basilisk/input → basilisk_engine-0.1.24/basilisk/input_output}/__init__.py +0 -0
  72. {basilisk_engine-0.1.22/basilisk/input → basilisk_engine-0.1.24/basilisk/input_output}/path.py +0 -0
  73. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/mesh/__init__.py +0 -0
  74. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/mesh/cube.py +0 -0
  75. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/mesh/mesh.py +0 -0
  76. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/mesh/mesh_from_data.py +0 -0
  77. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/mesh/model.py +0 -0
  78. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/mesh/narrow_aabb.py +0 -0
  79. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/mesh/narrow_bvh.py +0 -0
  80. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/mesh/narrow_primative.py +0 -0
  81. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/nodes/__init__.py +0 -0
  82. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/nodes/helper.py +0 -0
  83. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/particles/__init__.py +0 -0
  84. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/physics/__init__.py +0 -0
  85. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/physics/impulse.py +0 -0
  86. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/physics/physics_body.py +0 -0
  87. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/physics/physics_engine.py +0 -0
  88. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/__init__.py +0 -0
  89. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/batch.py +0 -0
  90. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/chunk.py +0 -0
  91. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/chunk_handler.py +0 -0
  92. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/image.py +0 -0
  93. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/light.py +0 -0
  94. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/material.py +0 -0
  95. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/render/post_process.py +0 -0
  96. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/__init__.py +0 -0
  97. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/batch.frag +0 -0
  98. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/batch.vert +0 -0
  99. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/crt.frag +0 -0
  100. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/draw.frag +0 -0
  101. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/draw.vert +0 -0
  102. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/filter.frag +0 -0
  103. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/frame.frag +0 -0
  104. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/frame.vert +0 -0
  105. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/geometry.frag +0 -0
  106. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/geometry.vert +0 -0
  107. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/normal.frag +0 -0
  108. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/normal.vert +0 -0
  109. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/particle.frag +0 -0
  110. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/particle.vert +0 -0
  111. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/sky.frag +0 -0
  112. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk/shaders/sky.vert +0 -0
  113. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk_engine.egg-info/dependency_links.txt +0 -0
  114. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk_engine.egg-info/requires.txt +0 -0
  115. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/basilisk_engine.egg-info/top_level.txt +0 -0
  116. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/docs/images/0_boilerplate.png +0 -0
  117. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/images/cloth.png +0 -0
  118. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/images/floor.png +0 -0
  119. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/images/foil.png +0 -0
  120. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/images/mud.png +0 -0
  121. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/setup.cfg +0 -0
  122. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/SkySkybox.png +0 -0
  123. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/brick.png +0 -0
  124. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/brick_normal.png +0 -0
  125. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/bunny.obj +0 -0
  126. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/closet_001.obj +0 -0
  127. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/cloth_albedo.png +0 -0
  128. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/cloth_normal.png +0 -0
  129. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/cube.obj +0 -0
  130. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/cubemaps_skybox.png +0 -0
  131. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/cylinder.obj +0 -0
  132. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/demo_sphere.obj +0 -0
  133. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/dirt.png +0 -0
  134. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/floor_albedo.png +0 -0
  135. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/floor_normal.png +0 -0
  136. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/foil_normal.png +0 -0
  137. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/fridge_001.obj +0 -0
  138. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/grass.jpg +0 -0
  139. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/grass_ao.jpg +0 -0
  140. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/grass_block_side.png +0 -0
  141. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/grass_block_top.png +0 -0
  142. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/grass_normal.png +0 -0
  143. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/grass_roughness.jpg +0 -0
  144. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/image.png +0 -0
  145. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/lucy.obj +0 -0
  146. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/monkey.obj +0 -0
  147. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/mud.png +0 -0
  148. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/mud_normal.png +0 -0
  149. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/oak_tree.obj +0 -0
  150. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/skybox.png +0 -0
  151. {basilisk_engine-0.1.22 → basilisk_engine-0.1.24}/tests/sphere.obj +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: basilisk-engine
3
- Version: 0.1.22
3
+ Version: 0.1.24
4
4
  Summary: Python 3D Framework
5
5
  Home-page: https://basilisk-website.vercel.app/
6
6
  Author: Name
@@ -8,7 +8,7 @@ from .render.material import Material
8
8
  from .render.shader import Shader
9
9
  from .render.shader_handler import ShaderHandler
10
10
  from .draw import draw
11
- from .render.camera import FreeCamera, StaticCamera, FollowCamera, OrbitCamera
11
+ from .render.camera import FreeCamera, StaticCamera, FollowCamera, OrbitCamera, FixedCamera
12
12
  from .render.sky import Sky
13
13
  from .render.post_process import PostProcess
14
14
  from .particles.particle_handler import ParticleHandler
@@ -0,0 +1,4 @@
1
+ class Config():
2
+ def __init__(self) -> None:
3
+ self.chunk_size = 40
4
+ self.render_distance = 5
@@ -14,7 +14,7 @@ def rect(engine: Engine, color: tuple, rect: tuple) -> None:
14
14
  """
15
15
 
16
16
  # Get the draw handler from the engine
17
- draw_handler = engine.scene.draw_handler
17
+ draw_handler = engine.draw_handler
18
18
  if not draw_handler: return
19
19
 
20
20
  # Draw the rect
@@ -36,7 +36,7 @@ def circle(engine: Engine, color: tuple, center: tuple, radius: int, resolution:
36
36
  """
37
37
 
38
38
  # Get the draw handler from the engine
39
- draw_handler = engine.scene.draw_handler
39
+ draw_handler = engine.draw_handler
40
40
  if not draw_handler: return
41
41
 
42
42
  # Draw the circle
@@ -57,7 +57,7 @@ def line(engine: Engine, color: tuple, p1: tuple, p2: tuple, thickness: int=1) -
57
57
  """
58
58
 
59
59
  # Get the draw handler from the engine
60
- draw_handler = engine.scene.draw_handler
60
+ draw_handler = engine.draw_handler
61
61
  if not draw_handler: return
62
62
 
63
63
  # Draw the line
@@ -74,10 +74,10 @@ def blit(engine: Engine, image: Image, rect: tuple, alpha: float=1.0):
74
74
  """
75
75
 
76
76
  # Get the draw handler from the engine
77
- draw_handler = engine.scene.draw_handler
77
+ draw_handler = engine.draw_handler
78
78
  if not draw_handler: return
79
79
 
80
- engine.scene.material_handler.image_handler.add(image)
80
+ engine.material_handler.image_handler.add(image)
81
81
 
82
82
  # Blit the image
83
83
  draw_handler.blit(image, rect, alpha)
@@ -88,7 +88,7 @@ def text(engine: Engine, text: str, position: tuple, scale: float=1.0):
88
88
  USE SPARINGLY, INEFFICIENT IMPLAMENTATION
89
89
  """
90
90
 
91
- font_renderer = engine.scene.draw_handler.font_renderer
91
+ font_renderer = engine.draw_handler.font_renderer
92
92
 
93
93
  # Render the text if it has not been cached
94
94
  if text not in font_renderer.text_renders:
@@ -9,9 +9,6 @@ from ..generic.input_validation import validate_color, validate_rect, validate_p
9
9
 
10
10
  class DrawHandler():
11
11
  engine: ...
12
- """Back reference to the parent engine"""
13
- scene: ...
14
- """Back reference to the parent scene"""
15
12
  ctx: mgl.Context
16
13
  """Back reference to the parent context"""
17
14
  program: mgl.Program
@@ -23,15 +20,14 @@ class DrawHandler():
23
20
  vao: mgl.VertexArray=None
24
21
  """VAO for rendering all 2D draw calls"""
25
22
 
26
- def __init__(self, scene) -> None:
23
+ def __init__(self, engine) -> None:
27
24
  # Back references
28
- self.scene = scene
29
- self.engine = scene.engine
30
- self.ctx = scene.engine.ctx
25
+ self.engine = engine
26
+ self.ctx = engine.ctx
31
27
 
32
28
  # Get the shader
33
29
  root = self.engine.root
34
- self.shader = self.scene.shader_handler.add(Shader(self.engine, root + '/shaders/draw.vert', root + '/shaders/draw.frag'))
30
+ self.shader = self.engine.shader_handler.add(Shader(self.engine, root + '/shaders/draw.vert', root + '/shaders/draw.frag'))
35
31
 
36
32
  # Initialize draw data as blank
37
33
  self.draw_data = []
@@ -0,0 +1,170 @@
1
+ import os
2
+ from sys import platform
3
+ os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
4
+ import pygame as pg
5
+ import moderngl as mgl
6
+ import glcontext # For packaging (so it isnt a hidden import)
7
+ from .render.shader_handler import ShaderHandler
8
+ from .render.material_handler import MaterialHandler
9
+ from .render.frame import Frame
10
+ from .draw.draw_handler import DrawHandler
11
+ from .config import Config
12
+ from .input_output.mouse import Mouse
13
+ from .input_output.clock import Clock
14
+ from .input_output.IO_handler import IO
15
+ from .mesh.cube import Cube
16
+
17
+ class Engine():
18
+ win_size: tuple
19
+ """Size of the engine window in pixels"""
20
+ ctx: mgl.Context
21
+ """ModernGL context used by the engine"""
22
+ clock: Clock
23
+ """Basilisk clock used to keep track of time"""
24
+ shader_handler: ShaderHandler=None
25
+ """Handler for all shaders used in all scenes of the engine"""
26
+ material_handler: MaterialHandler=None
27
+ """Handler for all materials and images in all scenes"""
28
+ frame: Frame=None
29
+ """Default render target for all locations. Rendered to the screen at the end of the frame"""
30
+ config: Config
31
+ """Object containing all global attributes"""
32
+ delta_time: float
33
+ """Time in seconds that passed between the last frame"""
34
+ time: float
35
+ """Total time the engine has been running"""
36
+ running: bool=True
37
+ """True if the engine is still running"""
38
+ mouse: Mouse
39
+ """Object containing information about the user's mouse"""
40
+ root: str
41
+ """Path to the root directory containing internal data"""
42
+ current_frame_updated: bool=False
43
+ """Flag for if the engine has been updated this frame"""
44
+ keys: list[bool]
45
+ """List of all keyboard inputs as booleans"""
46
+ previous_keys: list[bool]
47
+ """List of all keyoard inputs from the last frame as booleans"""
48
+
49
+ def __init__(self, win_size=(800, 800), title="Basilisk Engine", vsync=None, max_fps=None, grab_mouse=True, headless=False, resizable=True) -> None:
50
+ """
51
+ Basilisk Engine Class. Sets up the engine enviornment and allows the user to interact with Basilisk
52
+ Args:
53
+ win_size: tuple
54
+ The initial window size of the engine
55
+ title: str
56
+ The title of the engine window
57
+ vsync: bool
58
+ Flag for running engine with vsync enabled
59
+ headless: bool
60
+ Flag for headless rendering
61
+ """
62
+
63
+ # Save the window size
64
+ self.win_size = win_size
65
+
66
+ # Initialize pygame and set OpenGL attributes
67
+ pg.init()
68
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_MAJOR_VERSION, 3)
69
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_MINOR_VERSION, 3)
70
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_PROFILE_MASK, pg.GL_CONTEXT_PROFILE_CORE)
71
+
72
+ # Platform settings
73
+ if platform == 'win32' : self.platform = 'windows'
74
+ elif platform == 'darwin': self.platform = 'mac'
75
+ else: self.platform = 'linux'
76
+ if vsync == None: vsync = True if self.platform == 'linux' else False
77
+
78
+ # Initializae the pygame display
79
+ self.headless = headless
80
+ if headless:
81
+ pg.display.set_mode((300, 50), vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF)
82
+ pg.display.iconify()
83
+ else:
84
+ if resizable: pg.display.set_mode(self.win_size, vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF | pg.RESIZABLE)
85
+ else: pg.display.set_mode(self.win_size, vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF)
86
+
87
+ # Initalize pygame sound moduel sound
88
+ pg.mixer.pre_init(44100, -16, 2, 512)
89
+ pg.mixer.init()
90
+ pg.mixer.set_num_channels(64)
91
+ pg.mixer.music.set_volume(100/100)
92
+
93
+ # MGL context setup
94
+ self.ctx = mgl.create_context()
95
+ self.ctx.enable(flags=mgl.DEPTH_TEST | mgl.CULL_FACE | mgl.BLEND)
96
+
97
+ # Global attributes referenced by the handlers
98
+ self.config = Config()
99
+ self.root = os.path.dirname(__file__)
100
+ self.cube = Cube(self)
101
+ self.fbos = []
102
+
103
+ # Handlers
104
+ self.clock = Clock(self, max_fps)
105
+ self.IO = IO(self, grab_mouse=grab_mouse, caption=title)
106
+ self.material_handler = MaterialHandler(self)
107
+ self.shader_handler = ShaderHandler(self)
108
+ self.draw_handler = DrawHandler(self)
109
+ self.frame = Frame(self)
110
+ self.material_handler.set_base()
111
+
112
+ def _update(self) -> None:
113
+ """
114
+ Internal engine update.
115
+ Updates all input, physics, and time variables. Clears the frame.
116
+ """
117
+
118
+ if self.current_frame_updated: return
119
+
120
+ for fbo in self.fbos: fbo.clear()
121
+ self.clock.update()
122
+ self.IO.update()
123
+
124
+ self.current_frame_updated = True
125
+
126
+
127
+ def update(self) -> None:
128
+ """
129
+ Calls internal update if needed
130
+ Renders the draw handler
131
+ Renders the engine's frame to the screen.
132
+ """
133
+
134
+
135
+ # Must update the frame
136
+ if not self.current_frame_updated: self._update()
137
+ if not self.running: return
138
+
139
+ # Render all draw calls from the past frame
140
+ self.frame.use()
141
+ self.draw_handler.render()
142
+
143
+ # Clear the screen and render the frame
144
+ self.ctx.screen.use()
145
+ self.ctx.clear()
146
+ self.frame.render()
147
+ pg.display.flip()
148
+
149
+ self.frame.clear()
150
+
151
+
152
+ # Allow for the engine to take in input again
153
+ self.current_frame_updated = False
154
+
155
+ def quit(self) -> None:
156
+ """
157
+ Stops the engine and releases all memory
158
+ """
159
+
160
+ pg.quit()
161
+ self.ctx.release()
162
+ self.running = False
163
+
164
+
165
+ @property
166
+ def shader(self): return self._shader
167
+ @shader.setter
168
+ def shader(self, value):
169
+ self._shader = value
170
+ value.set_main()
@@ -0,0 +1,92 @@
1
+ import pygame as pg
2
+ from .keys import Keys
3
+ from .mouse import Mouse
4
+
5
+
6
+ class IO:
7
+ keys: Keys=None
8
+ """Handler for all keyboard inputs"""
9
+ mouse: Mouse=None
10
+ """Handler for all mouse inputs and mouse settings"""
11
+ events: list=[]
12
+ """List of all the events in the frame"""
13
+ event_resize: bool=False
14
+ """Bool for if a resize event has occured this frame"""
15
+
16
+ def __init__(self, engine: ..., grab_mouse: bool=True, caption: bool|None="Basilisk") -> None:
17
+ """
18
+ Class to handle all inputs and outputs for the engine.
19
+ """
20
+
21
+ # Reference to parent engine
22
+ self.engine = engine
23
+
24
+ # Caption attrib
25
+ self.caption = caption
26
+ self.update_caption()
27
+
28
+ # Handlers for key and mouse input
29
+ self.keys = Keys(engine)
30
+ self.mouse = Mouse(grab=grab_mouse)
31
+
32
+ # Expose the mouse on the engine level
33
+ setattr(self.engine, "mouse", self.mouse)
34
+
35
+ # Fill in default values for engine attributes
36
+ self.set_engine_attribiutes()
37
+
38
+ # Update the icon for the window
39
+ pg.display.set_icon(pg.image.load(self.engine.root + '/bsk_assets/basilisk.png'))
40
+
41
+ def update(self) -> None:
42
+ """
43
+ Update all inputs and check for events
44
+ """
45
+
46
+ # Get events
47
+ self.events = pg.event.get()
48
+
49
+ # Update the keys and the mouse
50
+ self.keys.update()
51
+ self.mouse.update(self.events)
52
+
53
+ # Handle events and update attributes
54
+ self.get_events()
55
+ self.set_engine_attribiutes()
56
+ self.update_caption()
57
+
58
+ def get_events(self) -> None:
59
+ """
60
+ Loop through all pygame events and make updates as needed
61
+ """
62
+
63
+ # Clear global events
64
+ self.event_resize = False
65
+
66
+
67
+ for event in self.events:
68
+ if event.type == pg.QUIT: # Quit the engine
69
+ self.engine.quit()
70
+ return
71
+ if event.type == pg.VIDEORESIZE:
72
+ # Updates the viewport
73
+ self.event_resize = True
74
+ self.engine.win_size = (event.w, event.h)
75
+ self.engine.ctx.viewport = (0, 0, event.w, event.h)
76
+ for fbo in self.engine.fbos: fbo.resize()
77
+
78
+ def update_caption(self) -> None:
79
+ """
80
+ Updates the window caption with either the fps or the window name. Set to 'Basilisk Engine' by default
81
+ """
82
+
83
+ caption = self.caption if self.caption else f"FPS: {round(self.engine.clock.fps)}"
84
+ pg.display.set_caption(caption)
85
+
86
+ def set_engine_attribiutes(self) -> None:
87
+ """
88
+ Updates engine attributes with this instance's attributes for ease of use
89
+ """
90
+
91
+ setattr(self.engine, "events", self.events)
92
+ setattr(self.engine, "event_resize", self.event_resize)
@@ -0,0 +1,50 @@
1
+ import pygame as pg
2
+
3
+
4
+ class Clock:
5
+ delta_time: float=0
6
+ """The amount of time that passed between the last and current frame"""
7
+ time: float=0
8
+ """Total time that has passed since the start of the program"""
9
+
10
+ def __init__(self, engine, max_fps=None) -> None:
11
+ """
12
+ Class to keep track of all time and delta time in the program
13
+ """
14
+
15
+ # Reference to the parent engine
16
+ self.engine = engine
17
+
18
+ # Create a pygame clock
19
+ self.clock = pg.Clock()
20
+ self.max_fps = max_fps
21
+
22
+ # Default values for attributes
23
+ self.set_engine_attribiutes()
24
+
25
+ def update(self) -> None:
26
+ """Ticks the clock"""
27
+
28
+ # Tick the clock and get delta time in seconds
29
+ if self.max_fps: self.delta_time = self.clock.tick(self.max_fps) / 1000
30
+ else: self.delta_time = self.clock.tick() / 1000
31
+
32
+ # Increment the total time by time since last frame
33
+ self.time += self.delta_time
34
+
35
+ self.set_engine_attribiutes()
36
+
37
+ def set_engine_attribiutes(self) -> None:
38
+ """
39
+ Updates engine attributes with this instance's attributes for ease of use
40
+ """
41
+
42
+ setattr(self.engine, "delta_time", self.delta_time)
43
+ setattr(self.engine, "dt", self.delta_time)
44
+ setattr(self.engine, "time", self.time)
45
+ setattr(self.engine, "fps", self.fps)
46
+
47
+
48
+ @property
49
+ def fps(self) -> float:
50
+ return self.clock.get_fps()
@@ -0,0 +1,44 @@
1
+ import pygame as pg
2
+
3
+
4
+ class Keys:
5
+ current_keys: list[bool]
6
+ """The keys pressed during the current frame"""
7
+ previous_keys: list[bool]
8
+ """The keys pressed in the last frame"""
9
+
10
+ def __init__(self, engine: ...) -> None:
11
+ """
12
+ Handler for all keyboard inputs. Stores data from current and previous frames
13
+ """
14
+
15
+ # Reference to the parent engine
16
+ self.engine = engine
17
+
18
+ # Fill in default values for current and previous keys to aviod startup errors
19
+ self.current_keys = pg.key.get_pressed()
20
+ self.previous_keys = self.current_keys
21
+ self.set_engine_attribiutes()
22
+
23
+
24
+ def update(self) -> None:
25
+ """
26
+ Gets all keyboard inputs and propogates last frame inputs
27
+ """
28
+
29
+ # Get keyboard input
30
+ self.previous_keys = self.current_keys
31
+ # Propogate input to the last frame
32
+ self.current_keys = pg.key.get_pressed()
33
+
34
+ # Expose the attributes on the engine level
35
+ self.set_engine_attribiutes()
36
+
37
+ def set_engine_attribiutes(self) -> None:
38
+ """
39
+ Updates engine attributes with this instance's attributes for ease of use
40
+ """
41
+
42
+ setattr(self.engine, "keys", self.current_keys)
43
+ setattr(self.engine, "previous_keys", self.previous_keys)
44
+ setattr(self.engine, "prev_keys", self.previous_keys)
@@ -0,0 +1,90 @@
1
+ import pygame as pg
2
+
3
+
4
+ class Mouse():
5
+ def __init__(self, grab=True):
6
+ self._position = list(pg.mouse.get_pos())
7
+ self._relative = [0, 0]
8
+ self.buttons = pg.mouse.get_pressed()
9
+ self.previous_buttons = pg.mouse.get_pressed()
10
+ self.grab = grab
11
+ self.visible = not self.grab
12
+
13
+ def update(self, events):
14
+ """
15
+ Updates all mouse state variables.
16
+ Checks for mouse-related events.
17
+ """
18
+
19
+ self._position = list(pg.mouse.get_pos())
20
+ self._relative = list(pg.mouse.get_rel())
21
+ self.previous_buttons = self.buttons
22
+ self.buttons = pg.mouse.get_pressed()
23
+
24
+ for event in events:
25
+ if event.type == pg.KEYUP:
26
+ if event.key == pg.K_ESCAPE and self.grab:
27
+ # Unlock mouse
28
+ self.grab = False
29
+ self.visible = True
30
+ if event.type == pg.MOUSEBUTTONUP and not self.grab:
31
+ # Lock mouse
32
+ self.grab = True
33
+ self.visible = False
34
+
35
+ @property
36
+ def position(self): return self._position
37
+ @property
38
+ def x(self): return self._position[0]
39
+ @property
40
+ def y(self): return self._position[1]
41
+ @property
42
+ def relative(self): return self._relative
43
+ @property
44
+ def relative_x(self): return self._relative[0]
45
+ @property
46
+ def relative_y(self): return self._relative[1]
47
+ @property
48
+ def click(self): return self.buttons[0] and not self.previous_buttons[0]
49
+ @property
50
+ def left_click(self): return self.buttons[0] and not self.previous_buttons[0]
51
+ @property
52
+ def middle_click(self): return self.buttons[1] and not self.previous_buttons[1]
53
+ @property
54
+ def right_click(self): return self.buttons[2] and not self.previous_buttons[2]
55
+ @property
56
+ def left_down(self): return self.buttons[0]
57
+ @property
58
+ def middle_down(self): return self.buttons[1]
59
+ @property
60
+ def right_down(self): return self.buttons[2]
61
+ @property
62
+ def grab(self): return self._grab
63
+ @property
64
+ def visible(self): return self._visable
65
+
66
+ @position.setter
67
+ def position(self, value: tuple[int]) -> tuple[int]:
68
+ self._position = value
69
+ pg.mouse.set_pos(self._position)
70
+ return self._position
71
+ @x.setter
72
+ def x(self, value: int) -> int:
73
+ self._position[0] = value
74
+ pg.mouse.set_pos(self._position)
75
+ return self._position
76
+ @y.setter
77
+ def y(self, value: int) -> int:
78
+ self._position[1] = value
79
+ pg.mouse.set_pos(self._position)
80
+ return self._position
81
+ @grab.setter
82
+ def grab(self, value) -> bool:
83
+ self._grab = value
84
+ pg.event.set_grab(self._grab)
85
+ return self._grab
86
+ @visible.setter
87
+ def visible(self, value) -> bool:
88
+ self._visible = value
89
+ pg.mouse.set_visible(self._visible)
90
+ return self._visible
@@ -97,9 +97,10 @@ class Node():
97
97
 
98
98
  # parents
99
99
  self.node_handler = None
100
- self.scene = None
101
- self.chunk = None
102
- self.parent = None
100
+ self.scene = None
101
+ self.engine = None
102
+ self.chunk = None
103
+ self.parent = None
103
104
 
104
105
  # lazy update variables
105
106
  self.needs_geometric_center = True # pos
@@ -194,18 +195,19 @@ class Node():
194
195
  self.internal_scale.callback = scale_callback
195
196
  self.internal_rotation.callback = rotation_callback
196
197
 
197
- def init_scene(self, scene):
198
+ def init_scene(self, scene: ...) -> None:
198
199
  """
199
200
  Updates the scene of the node
200
201
  """
201
202
  self.scene = scene
203
+ self.engine = scene.engine
202
204
  self.node_handler = scene.node_handler
203
205
 
204
206
  # Update materials
205
207
  self.write_materials()
206
208
 
207
209
  # Update the mesh
208
- self.mesh = self.mesh if self.mesh else self.scene.engine.cube
210
+ self.mesh = self.mesh if self.mesh else self.engine.cube
209
211
 
210
212
  # Update physics and collider
211
213
  if self.physics_body: self.physics_body.physics_engine = scene.physics_engine
@@ -387,14 +389,14 @@ class Node():
387
389
  if isinstance(self.material, list):
388
390
  mtl_index_list = []
389
391
  for mtl in self._mtl_list:
390
- self.node_handler.scene.material_handler.add(mtl)
392
+ self.engine.material_handler.add(mtl)
391
393
  mtl_index_list.append(mtl.index)
392
394
  mtl_index_list.append(mtl.index)
393
395
  mtl_index_list.append(mtl.index)
394
396
  self._material = mtl_index_list
395
397
 
396
398
  if isinstance(self.material, type(None)):
397
- self.material = self.scene.material_handler.base
399
+ self.material = self.engine.material_handler.base
398
400
 
399
401
 
400
402
  def __repr__(self) -> str:
@@ -555,16 +557,16 @@ class Node():
555
557
  else:
556
558
  mtl_index_list = []
557
559
  for mtl in self._mtl_list:
558
- self.node_handler.scene.material_handler.add(mtl)
560
+ self.engine.material_handler.add(mtl)
559
561
  mtl_index_list.append(mtl.index)
560
562
  mtl_index_list.append(mtl.index)
561
563
  mtl_index_list.append(mtl.index)
562
564
  self._material = mtl_index_list
563
565
  elif isinstance(value, Material):
564
566
  self._material = value
565
- if self.node_handler: self.node_handler.scene.material_handler.add(value)
567
+ if self.node_handler: self.engine.material_handler.add(value)
566
568
  elif isinstance(value, type(None)):
567
- if self.scene: self._material = self.scene.material_handler.base
569
+ if self.engine: self._material = self.engine.material_handler.base
568
570
  else: self._material = None
569
571
 
570
572
  else: raise TypeError(f'Node: Invalid material value type {type(value)}')
@@ -19,6 +19,7 @@ class NodeHandler():
19
19
  """
20
20
 
21
21
  self.scene = scene
22
+ self.engine = scene.engine
22
23
  self.nodes = []
23
24
  self.chunk_handler = ChunkHandler(scene)
24
25
 
@@ -49,9 +50,9 @@ class NodeHandler():
49
50
  for n in node.get_all(): # gets all nodes including the node to be added
50
51
 
51
52
  # Update scene Handlers
52
- self.scene.shader_handler.add(n.shader)
53
- if not n.material: n.material = self.scene.material_handler.base
54
- self.scene.material_handler.add(n.material)
53
+ self.engine.shader_handler.add(n.shader)
54
+ if not n.material: n.material = self.engine.material_handler.base
55
+ self.engine.material_handler.add(n.material)
55
56
 
56
57
  # Update the node attributes
57
58
  n.init_scene(self.scene)
@@ -43,7 +43,7 @@ class ParticleHandler:
43
43
  # Get material ID
44
44
  if material == None: material_index = 0
45
45
  elif isinstance(material, Material):
46
- self.scene.material_handler.add(material)
46
+ self.scene.engine.material_handler.add(material)
47
47
  material_index = material.index
48
48
  else: raise ValueError(f'particle_handler.add: Invalid particle material type: {type(material)}')
49
49
 
@@ -31,7 +31,7 @@ class ParticleRenderer:
31
31
  root = scene.engine.root
32
32
  if shader: self.shader = shader
33
33
  else: self.shader = Shader(scene.engine, vert=root + '/shaders/particle.vert', frag=root + '/shaders/particle.frag')
34
- scene.shader_handler.add(self.shader)
34
+ scene.engine.shader_handler.add(self.shader)
35
35
 
36
36
  self.particle_cube_size = 25
37
37