basilisk-engine 0.1.23__py3-none-any.whl → 0.1.25__py3-none-any.whl

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.

basilisk/__init__.py CHANGED
@@ -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
basilisk/engine.py CHANGED
@@ -41,6 +41,10 @@ class Engine():
41
41
  """Path to the root directory containing internal data"""
42
42
  current_frame_updated: bool=False
43
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"""
44
48
 
45
49
  def __init__(self, win_size=(800, 800), title="Basilisk Engine", vsync=None, max_fps=None, grab_mouse=True, headless=False, resizable=True) -> None:
46
50
  """
@@ -113,6 +117,7 @@ class Engine():
113
117
 
114
118
  if self.current_frame_updated: return
115
119
 
120
+ for fbo in self.fbos: fbo.clear()
116
121
  self.clock.update()
117
122
  self.IO.update()
118
123
 
@@ -73,8 +73,7 @@ class IO:
73
73
  self.event_resize = True
74
74
  self.engine.win_size = (event.w, event.h)
75
75
  self.engine.ctx.viewport = (0, 0, event.w, event.h)
76
- self.engine.frame.resize((event.w, event.h))
77
- # for fbo in self.fbos: fbo.resize()
76
+ for fbo in self.engine.fbos: fbo.resize()
78
77
 
79
78
  def update_caption(self) -> None:
80
79
  """
@@ -3,10 +3,12 @@ import pygame as pg
3
3
 
4
4
  class Mouse():
5
5
  def __init__(self, grab=True):
6
- self.x, self.y = pg.mouse.get_pos()
6
+ self._position = list(pg.mouse.get_pos())
7
+ self._relative = [0, 0]
7
8
  self.buttons = pg.mouse.get_pressed()
8
9
  self.previous_buttons = pg.mouse.get_pressed()
9
10
  self.grab = grab
11
+ self.visible = not self.grab
10
12
 
11
13
  def update(self, events):
12
14
  """
@@ -14,7 +16,8 @@ class Mouse():
14
16
  Checks for mouse-related events.
15
17
  """
16
18
 
17
- self.x, self.y = pg.mouse.get_pos()
19
+ self._position = list(pg.mouse.get_pos())
20
+ self._relative = list(pg.mouse.get_rel())
18
21
  self.previous_buttons = self.buttons
19
22
  self.buttons = pg.mouse.get_pressed()
20
23
 
@@ -22,17 +25,25 @@ class Mouse():
22
25
  if event.type == pg.KEYUP:
23
26
  if event.key == pg.K_ESCAPE and self.grab:
24
27
  # Unlock mouse
25
- pg.event.set_grab(False)
26
- pg.mouse.set_visible(True)
27
- if event.type == pg.MOUSEBUTTONUP and self.grab:
28
+ self.grab = False
29
+ self.visible = True
30
+ if event.type == pg.MOUSEBUTTONUP and not self.grab:
28
31
  # Lock mouse
29
- pg.event.set_grab(True)
30
- pg.mouse.set_visible(False)
31
-
32
- def set_pos(self, x, y):
33
- """Set the mouse position"""
34
- pg.mouse.set_pos(x, y)
32
+ self.grab = True
33
+ self.visible = False
35
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]
36
47
  @property
37
48
  def click(self): return self.buttons[0] and not self.previous_buttons[0]
38
49
  @property
@@ -47,16 +58,33 @@ class Mouse():
47
58
  def middle_down(self): return self.buttons[1]
48
59
  @property
49
60
  def right_down(self): return self.buttons[2]
50
-
51
61
  @property
52
62
  def grab(self): return self._grab
63
+ @property
64
+ def visible(self): return self._visable
53
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
54
81
  @grab.setter
55
- def grab(self, value):
82
+ def grab(self, value) -> bool:
56
83
  self._grab = value
57
- if self._grab:
58
- pg.event.set_grab(True)
59
- pg.mouse.set_visible(False)
60
- else:
61
- pg.event.set_grab(False)
62
- pg.mouse.set_visible(True)
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
basilisk/mesh/mesh.py CHANGED
@@ -30,12 +30,14 @@ class Mesh():
30
30
  bvh: NarrowBVH
31
31
  """BVH for accessing triangle intersections with a line"""
32
32
 
33
- def __init__(self, data: str | os.PathLike | np.ndarray) -> None:
33
+ def __init__(self, data: str | os.PathLike | np.ndarray, custom_format:bool=False) -> None:
34
34
  """
35
35
  Mesh object containing all the data needed to render an object and perform physics/collisions on it
36
36
  Args:
37
37
  data: str
38
38
  path to the .obj file of the model or an array of the mesh data
39
+ custom_format: bool
40
+ makes expected changes to the given data if false. Leaves data as given if true
39
41
  """
40
42
 
41
43
  # Verify the path type
@@ -59,7 +61,7 @@ class Mesh():
59
61
  self.data = np.hstack([self.data, tangents])
60
62
 
61
63
  elif isinstance(data, np.ndarray):
62
- model = from_data(data)
64
+ model = from_data(data, custom_format)
63
65
  self.data = model.vertex_data
64
66
 
65
67
  else: # Invalid data type
@@ -70,6 +72,7 @@ class Mesh():
70
72
  self.indices = model.point_indices.copy()
71
73
 
72
74
  self.hash = hash(str(self.data))
75
+ self.custom = custom_format
73
76
 
74
77
  # generate edges from faces
75
78
  edges = [set() for _ in range(len(self.points))]
@@ -2,14 +2,20 @@ import numpy as np
2
2
  from .model import Model
3
3
  import glm
4
4
 
5
- def from_data(data: np.ndarray) -> Model:
5
+ def from_data(data: np.ndarray, custom_format:bool=False) -> Model:
6
6
  """
7
7
  Converts data given to a format compatable with basilisk models
8
+ Args:
9
+ data: np.ndarray
10
+ array of the mesh data
11
+ custom_format: bool
12
+ makes expected changes to the given data if false. Leaves data as given if true
8
13
  """
9
14
 
15
+ if custom_format: return format_raw(data)
16
+
10
17
  # Create an empty model
11
18
  model = Model()
12
- # Get the shape of the given data
13
19
 
14
20
  # Get the shape of the given data and check for a valid shape
15
21
  shape = data.shape
@@ -128,4 +134,18 @@ def get_points_and_indices(positions: np.ndarray) -> tuple[np.ndarray]:
128
134
  for triangle in index_mapping:
129
135
  indices[triangle].append(i)
130
136
 
131
- return np.array(list(points.keys()), dtype='f4'), np.array(indices, dtype='i')
137
+ return np.array(list(points.keys()), dtype='f4'), np.array(indices, dtype='i')
138
+
139
+ def format_raw(data: np.ndarray) -> np.ndarray:
140
+ # Create an empty model
141
+ model = Model()
142
+
143
+ # Get the needed data (assume position is in the first three positions)
144
+ model.vertex_data = np.array(data, dtype='f4')
145
+ if model.vertex_data.shape[1] >= 3:
146
+ model.vertex_points, model.point_indices = get_points_and_indices(model.vertex_data[:,:3])
147
+ else:
148
+ model.vertex_points = np.zeros(shape=(1, model.vertex_data.shape[1]))
149
+ model.point_indices = np.zeros(shape=(1, 3))
150
+
151
+ return model
basilisk/nodes/node.py CHANGED
@@ -371,13 +371,16 @@ class Node():
371
371
  if not per_vertex_mtl: node_data[-1] = self.material.index
372
372
 
373
373
  # Create an array to hold the node's data
374
- data = np.zeros(shape=(mesh_data.shape[0], 25), dtype='f4')
374
+ width = 25 if not self.mesh.custom else 11 + mesh_data.shape[1]
375
+ data = np.zeros(shape=(mesh_data.shape[0], width), dtype='f4')
375
376
 
376
377
 
377
- data[:,:14] = mesh_data
378
- data[:,14:] = node_data
378
+ data[:,:mesh_data.shape[1]] = mesh_data
379
+ data[:,mesh_data.shape[1]:] = node_data
379
380
 
380
- if per_vertex_mtl: data[:,24] = self.material
381
+ if per_vertex_mtl: data[:,-1] = self.material
382
+
383
+ if self.shader and not self.mesh.custom: data = np.take(data, self.shader.attribute_indices, axis=1)
381
384
 
382
385
  return data
383
386
 
basilisk/render/batch.py CHANGED
@@ -1,14 +1,14 @@
1
1
  import numpy as np
2
2
  import moderngl as mgl
3
-
3
+ from .shader import Shader
4
4
 
5
5
  class Batch():
6
6
  chunk: ...
7
7
  """Reference to the parent chunk of the batch"""
8
8
  ctx: mgl.Context
9
9
  """Reference to the context of the parent engine"""
10
- program: mgl.Program
11
- """Reference to the program used by batches"""
10
+ shader: Shader
11
+ """Reference to the bsk.Shader used by batches"""
12
12
  vao: mgl.VertexArray
13
13
  """The vertex array of the batch. Used for rendering"""
14
14
  vbo: mgl.Buffer
@@ -23,7 +23,7 @@ class Batch():
23
23
  # Back references
24
24
  self.chunk = chunk
25
25
  self.ctx = chunk.chunk_handler.engine.ctx
26
- self.program = self.chunk.get_program()
26
+ self.shader = self.chunk.get_shader()
27
27
 
28
28
  # Set intial values
29
29
  self.vbo = None
@@ -35,7 +35,7 @@ class Batch():
35
35
  Returns True if batch was successful.
36
36
  """
37
37
 
38
- self.program = self.chunk.get_program()
38
+ self.shader = self.chunk.get_shader()
39
39
 
40
40
  # Empty list to contain all vertex data of models in the chunk
41
41
  batch_data = []
@@ -68,11 +68,9 @@ class Batch():
68
68
 
69
69
  # Create the vbo and the vao from mesh data
70
70
  self.vbo = self.ctx.buffer(batch_data)
71
- self.vao = self.ctx.vertex_array(self.program, [(self.vbo,
72
- '3f 2f 3f 3f 3f 3f 4f 3f 1f',
73
- *['in_position', 'in_uv', 'in_normal', 'in_tangent', 'in_bitangent', 'obj_position', 'obj_rotation', 'obj_scale', 'obj_material'])],
74
- skip_errors=True)
75
-
71
+ self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, self.shader.fmt, *self.shader.attributes)], skip_errors=True)
72
+
73
+
76
74
  return True
77
75
 
78
76
  def swap_shader(self, shader):
basilisk/render/camera.py CHANGED
@@ -24,7 +24,7 @@ class Camera:
24
24
  position: glm.vec3
25
25
  """Location of the camera (maters)"""
26
26
 
27
- def __init__(self, position=(0, 0, 20), rotation=(1, 0, 0, 0), yaw=-90, pitch=0) -> None:
27
+ def __init__(self, position=(0, 0, 20), rotation=(1, 0, 0, 0)) -> None:
28
28
  """
29
29
  Camera object to get view and projection matricies. Movement built in
30
30
  """
@@ -52,20 +52,6 @@ class Camera:
52
52
  # self.update_camera_vectors()
53
53
  self.m_view = self.get_view_matrix()
54
54
 
55
- # def update_camera_vectors(self) -> None:
56
- # """
57
- # Computes the forward vector based on the pitch and yaw. Computes horizontal and vertical vectors with cross product.
58
- # """
59
- # yaw, pitch = glm.radians(self.yaw), glm.radians(self.pitch)
60
-
61
- # self.forward.x = glm.cos(yaw) * glm.cos(pitch)
62
- # self.forward.y = glm.sin(pitch)
63
- # self.forward.z = glm.sin(yaw) * glm.cos(pitch)
64
-
65
- # self.forward = glm.normalize(self.forward)
66
- # self.right = glm.normalize(glm.cross(self.forward, self.UP))
67
- # self.up = glm.normalize(glm.cross(self.right, self.forward))
68
-
69
55
  def use(self):
70
56
  # Updated aspect ratio of the screen
71
57
  self.aspect_ratio = self.engine.win_size[0] / self.engine.win_size[1]
@@ -186,8 +172,8 @@ class Camera:
186
172
 
187
173
 
188
174
  class FreeCamera(Camera):
189
- def __init__(self, position=(0, 0, 20), rotation=(1, 0, 0, 0), yaw=-90, pitch=0):
190
- super().__init__(position, rotation, yaw, pitch)
175
+ def __init__(self, position=(0, 0, 20), rotation=(1, 0, 0, 0)):
176
+ super().__init__(position, rotation)
191
177
 
192
178
  def update(self) -> None:
193
179
  """
@@ -203,7 +189,7 @@ class FreeCamera(Camera):
203
189
  """
204
190
  Rotates the camera based on the amount of mouse movement.
205
191
  """
206
- rel_x, rel_y = pg.mouse.get_rel()
192
+ rel_x, rel_y = self.engine.mouse.relative
207
193
 
208
194
  yaw_rotation = glm.angleAxis(SENSITIVITY * rel_x, -self.UP)
209
195
  pitch_rotation = glm.angleAxis(SENSITIVITY * rel_y, -self.right)
@@ -231,11 +217,16 @@ class FreeCamera(Camera):
231
217
  self.position += self.UP * velocity
232
218
  if keys[pg.K_LSHIFT]:
233
219
  self.position -= self.UP * velocity
220
+
221
+ class FixedCamera(FreeCamera):
222
+ def __init__(self, position=(0, 0, 20), rotation=(1, 0, 0, 0)):
223
+ super().__init__(position, rotation)
234
224
 
225
+ def move(self): pass
235
226
 
236
227
  class FollowCamera(FreeCamera):
237
- def __init__(self, parent, position=(0, 0, 20), rotation=(1, 0, 0, 0), yaw=-90, pitch=0, offset=(0, 0, 0)):
238
- super().__init__(position, rotation, yaw, pitch)
228
+ def __init__(self, parent, position=(0, 0, 20), rotation=(1, 0, 0, 0), offset=(0, 0, 0)):
229
+ super().__init__(position, rotation)
239
230
  self.parent = parent
240
231
  self.offest = glm.vec3(offset)
241
232
 
@@ -247,11 +238,11 @@ class FollowCamera(FreeCamera):
247
238
  self.position = self.parent.position + self.offest
248
239
 
249
240
  class OrbitCamera(FreeCamera):
250
- def __init__(self, parent, position=(0, 0, 20), rotation=(1, 0, 0, 0), yaw=-90, pitch=0, distance=5, offset=(0, 0)):
241
+ def __init__(self, parent, position=(0, 0, 20), rotation=(1, 0, 0, 0), distance=5, offset=(0, 0)):
251
242
  self.parent = parent
252
243
  self.distance = distance
253
244
  self.offset = glm.vec2(offset)
254
- super().__init__(position, rotation, yaw, pitch)
245
+ super().__init__(position, rotation)
255
246
 
256
247
  def get_view_matrix(self) -> glm.mat4x4:
257
248
  return glm.lookAt(self.position, self.parent.position, self.up)
@@ -263,5 +254,5 @@ class OrbitCamera(FreeCamera):
263
254
  self.position = self.parent.position - glm.normalize(self.forward) * self.distance
264
255
 
265
256
  class StaticCamera(Camera):
266
- def __init__(self, position=(0, 0, 20), rotation=(1, 0, 0, 0), yaw=-90, pitch=0):
267
- super().__init__(position, rotation, yaw, pitch)
257
+ def __init__(self, position=(0, 0, 20), rotation=(1, 0, 0, 0)):
258
+ super().__init__(position, rotation)
basilisk/render/chunk.py CHANGED
@@ -79,15 +79,15 @@ class Chunk():
79
79
 
80
80
  return node
81
81
 
82
- def get_program(self):
82
+ def get_shader(self):
83
83
  """
84
- Gets the program of the chunks nodes' shader
84
+ Gets the bsk.Shader of the chunks nodes' shader
85
85
  """
86
86
 
87
87
  shader = self.shader
88
88
 
89
- if shader: return shader.program
90
- return self.chunk_handler.engine.shader.program
89
+ if shader: return shader
90
+ return self.chunk_handler.engine.shader
91
91
 
92
92
  def swap_shader(self, shader):
93
93
  """
basilisk/render/frame.py CHANGED
@@ -11,7 +11,7 @@ class Frame:
11
11
  vao: mgl.VertexArray=None
12
12
  framebuffer: mgl.Framebuffer=None
13
13
 
14
- def __init__(self, engine, resolution=1, filter=(mgl.LINEAR, mgl.LINEAR)) -> None:
14
+ def __init__(self, engine, scale: float=1.0, linear_filter: bool=False) -> None:
15
15
  """
16
16
  Basilisk render destination.
17
17
  Can be used to render to the screen or for headless rendering
@@ -21,11 +21,8 @@ class Frame:
21
21
  self.ctx = engine.ctx
22
22
 
23
23
  # Load framebuffer
24
- self.resolution = resolution
25
- self.filter = filter
26
- size = tuple(map(lambda x: int(x * self.resolution), self.engine.win_size))
27
- self.framebuffer = Framebuffer(self.engine, size=size, filter=self.filter)
28
- self.ping_pong_buffer = Framebuffer(self.engine, size=size, filter=self.filter)
24
+ self.framebuffer = Framebuffer(self.engine, scale=scale, linear_filter=linear_filter)
25
+ self.ping_pong_buffer = Framebuffer(self.engine, scale=scale, linear_filter=linear_filter)
29
26
 
30
27
  # Load Shaders
31
28
  self.shader = Shader(self.engine, self.engine.root + '/shaders/frame.vert', self.engine.root + '/shaders/frame.frag')
@@ -87,9 +84,8 @@ class Frame:
87
84
  Resize the frame to the given size. None for window size
88
85
  """
89
86
 
90
- size = tuple(map(lambda x: int(x * self.resolution), self.engine.win_size))
91
- self.framebuffer.resize(size)
92
- self.ping_pong_buffer.resize(size)
87
+ self.framebuffer.resize()
88
+ self.ping_pong_buffer.resize()
93
89
 
94
90
  def __del__(self) -> None:
95
91
  """
@@ -7,40 +7,76 @@ from ..render.shader import Shader
7
7
  class Framebuffer:
8
8
  engine: ...
9
9
  """Reference to the parent engine"""
10
- fbo: mgl.Framebuffer = None
10
+ size: tuple[int] | None=None
11
+ """The dimensions of the framebuffer (x, y). Defaults to window size if None"""
12
+ scale: float=1.0
13
+ """Scaling factor applied to the size. Best for use with default size"""
14
+ texture_filter: tuple[int]=(mgl.NEAREST, mgl.NEAREST)
15
+ """The filter applied to the texture when rendering"""
16
+ fbo: mgl.Framebuffer=None
11
17
  """The core framebuffer the object provides abstraction for."""
12
- texture: mgl.Texture = None
18
+ texture: mgl.Texture=None
13
19
  """The color texture of the framebuffer"""
14
- depth: mgl.Texture = None
20
+ depth: mgl.Texture=None
15
21
  """The depth texture of the framebuffer"""
16
- size: tuple[int]
17
- """The dimensions of the framebuffer (x, y)"""
22
+ _color_attachments = None
23
+ """"""
24
+ _depth_attachment = None
25
+ """"""
18
26
 
19
- def __init__(self, engine, size: tuple[int]=None, resolution_scale: float=1.0, components: int=4, filter=(mgl.LINEAR, mgl.LINEAR)) -> None:
27
+ def __init__(self, engine: ..., size: tuple[int]=None, n_color_attachments: int=1, scale: float=1.0, linear_filter: bool=True) -> None:
20
28
  """
21
- Abstraction to the mgl framebuffer
22
- Args:
23
- engine: mgl.Engine:
24
- The parent engine
25
- size: tuple[int]:
26
- The dimensions of the framebuffer (x, y)
29
+ Abstraction of the MGL framebuffer.
30
+ Has the given number of color attachements (4-component) and 1 depth attachment.
31
+ All textures are of uniform size.
32
+ """
33
+
34
+ self.engine = engine
35
+ self.ctx = engine.ctx
36
+ self._size = size
37
+ self.scale = scale
38
+ self.texture_filter = (mgl.LINEAR, mgl.LINEAR) if linear_filter else (mgl.NEAREST, mgl.NEAREST)
39
+ self.attachments = n_color_attachments
40
+
41
+ self.load_pipeline()
42
+ self.generate_fbo()
43
+
44
+ self.engine.fbos.append(self)
45
+
46
+ def generate_fbo(self):
47
+ """
48
+ Generates fresh depth texture and color textures and creates an FBO
49
+ """
50
+
51
+ # Release existing memory
52
+ self.__del__()
53
+
54
+ # Create textures
55
+ self._color_attachments = [self.ctx.texture(self.size, components=4)]
56
+ for tex in self._color_attachments: tex.filter = self.texture_filter
57
+ self._depth_attachment = self.ctx.depth_texture(self.size)
58
+
59
+ # Create the internal fbo
60
+ self.fbo = self.ctx.framebuffer(self._color_attachments, self._depth_attachment)
61
+
62
+ def resize(self, new_size: tuple[int]=None) -> None:
63
+ """
64
+ Update set size framebuffers with the given size.
27
65
  """
28
66
 
29
- # Set attributes
30
- self.engine = engine
31
- self.ctx = engine.ctx
32
- self.components = components
33
-
34
- # Set the size
35
- self.resolution_scale = resolution_scale
36
- self._size = size
37
- self.size = self._size if self._size else self.engine.win_size
38
- self.size = (int(self.size[0] * resolution_scale), int(self.size[1] * resolution_scale))
39
-
40
- # Create the fbo
41
- self.texture = self.ctx.texture(self.size, components=self.components)
42
- self.depth = self.ctx.depth_texture(self.size)
43
- self.fbo = self.ctx.framebuffer([self.texture], self.depth)
67
+ # Check that we are not updating the size to the existing size and
68
+ if self._size and self._size == new_size: return
69
+
70
+ # If we have a set size, update with the given size
71
+ if self._size and new_size: self._size = new_size
72
+
73
+ # Update the textures and fbo
74
+ self.generate_fbo()
75
+
76
+ def load_pipeline(self) -> None:
77
+ """
78
+ Loads the shader, vbo, and vao used to display the fbo
79
+ """
44
80
 
45
81
  # Load Shaders
46
82
  self.shader = Shader(self.engine, self.engine.root + '/shaders/frame.vert', self.engine.root + '/shaders/frame.frag')
@@ -50,13 +86,11 @@ class Framebuffer:
50
86
  self.vbo = self.ctx.buffer(np.array([[-1, -1, 0, 0, 0], [1, -1, 0, 1, 0], [1, 1, 0, 1, 1], [-1, 1, 0, 0, 1], [-1, -1, 0, 0, 0], [1, 1, 0, 1, 1]], dtype='f4'))
51
87
  self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '3f 2f', 'in_position', 'in_uv')], skip_errors=True)
52
88
 
53
- # Save the filter
54
- self.filter = filter
89
+ def render(self, render_target=None) -> None:
55
90
 
56
- # Add to the engine for updates
57
- self.engine.fbos.append(self)
91
+ target = render_target if render_target else self.engine.frame
58
92
 
59
- def render(self) -> None:
93
+ target.use()
60
94
  self.shader.program['screenTexture'] = 0
61
95
  self.texture.use(location=0)
62
96
  self.vao.render()
@@ -86,47 +120,170 @@ class Framebuffer:
86
120
  img = Image.frombytes('RGB', self.size, data).transpose(Image.FLIP_TOP_BOTTOM)
87
121
  img.save(f'{path}.png')
88
122
 
89
- def resize(self, size: tuple[int]=None) -> None:
123
+
124
+ @property
125
+ def size(self) -> tuple[int]:
126
+ """Size of the textures in the fbo in pixels (x: int, y: int)"""
127
+ size = self._size if self._size else self.engine.win_size
128
+ size = tuple(map((lambda x: int(x * self.scale)), size))
129
+ return size
130
+ @property
131
+ def texture(self) -> mgl.Texture:
132
+ """First color attachment in the fbo"""
133
+ return self._color_attachments[0]
134
+ @property
135
+ def color_attachments(self) -> ...:
136
+ """List of all color attachments in the fbo"""
137
+ return self._color_attachments
138
+ @property
139
+ def depth(self) -> mgl.Texture:
140
+ """Depth attachment of the fbo"""
141
+ return self._depth_attachment
142
+ @property
143
+ def data(self) -> bytes:
144
+ """Reads the data from the fbo"""
145
+ return self.fbo.read()
146
+
147
+
148
+ @size.setter
149
+ def size(self, value: tuple[int]=None) -> tuple[int]:
150
+ self.resize(value)
151
+ return self.size
152
+
153
+ def __repr__(self) -> str:
154
+ return f'<bsk.Framebuffer | size: {self.size}>'
155
+
156
+ def __del__(self) -> None:
90
157
  """
91
- Resize the buffer to the given size. None for window size
158
+ Releases all memory used by the fbo
92
159
  """
93
160
 
94
- # Release old memory
95
- self.__del__()
161
+ if self._color_attachments: [tex.release() for tex in self._color_attachments]
162
+ if self._depth_attachment: self._depth_attachment.release()
163
+ if self.fbo: self.fbo.release()
96
164
 
97
- # Set/get size attribute
98
- if size:
99
- self.size = size
100
- else:
101
- self.size = self._size if self._size else self.engine.win_size
102
- self.size = (int(self.size[0] * self.resolution_scale), int(self.size[1] * self.resolution_scale))
165
+ # class Framebuffer:
166
+ # engine: ...
167
+ # """Reference to the parent engine"""
168
+ # fbo: mgl.Framebuffer = None
169
+ # """The core framebuffer the object provides abstraction for."""
170
+ # texture: mgl.Texture = None
171
+ # """The color texture of the framebuffer"""
172
+ # depth: mgl.Texture = None
173
+ # """The depth texture of the framebuffer"""
174
+ # size: tuple[int]
175
+ # """The dimensions of the framebuffer (x, y)"""
103
176
 
104
- # Create the fbo
105
- print(self.size)
106
- self.texture = self.ctx.texture(self.size, components=self.components)
107
- self.depth = self.ctx.depth_texture(self.size)
108
- self.fbo = self.ctx.framebuffer([self.texture], self.depth)
177
+ # def __init__(self, engine, size: tuple[int]=None, resolution_scale: float=1.0, components: int=4, filter=(mgl.LINEAR, mgl.LINEAR)) -> None:
178
+ # """
179
+ # Abstraction to the mgl framebuffer
180
+ # Args:
181
+ # engine: mgl.Engine:
182
+ # The parent engine
183
+ # size: tuple[int]:
184
+ # The dimensions of the framebuffer (x, y)
185
+ # """
186
+
187
+ # # Set attributes
188
+ # self.engine = engine
189
+ # self.ctx = engine.ctx
190
+ # self.components = components
109
191
 
110
- self.filter = self._filter
192
+ # # Set the size
193
+ # self.resolution_scale = resolution_scale
194
+ # self._size = size
195
+ # self.size = self._size if self._size else self.engine.win_size
196
+ # self.size = (int(self.size[0] * resolution_scale), int(self.size[1] * resolution_scale))
197
+
198
+ # # Create the fbo
199
+ # self.texture = self.ctx.texture(self.size, components=self.components)
200
+ # self.depth = self.ctx.depth_texture(self.size)
201
+ # self.fbo = self.ctx.framebuffer([self.texture], self.depth)
111
202
 
112
- @property
113
- def data(self):
114
- return self.fbo.read(components=3, alignment=1)
203
+ # # Load Shaders
204
+ # self.shader = Shader(self.engine, self.engine.root + '/shaders/frame.vert', self.engine.root + '/shaders/frame.frag')
205
+ # self.engine.shader_handler.add(self.shader)
115
206
 
116
- @property
117
- def filter(self):
118
- return self.texture.filter
207
+ # # Load VAO
208
+ # self.vbo = self.ctx.buffer(np.array([[-1, -1, 0, 0, 0], [1, -1, 0, 1, 0], [1, 1, 0, 1, 1], [-1, 1, 0, 0, 1], [-1, -1, 0, 0, 0], [1, 1, 0, 1, 1]], dtype='f4'))
209
+ # self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '3f 2f', 'in_position', 'in_uv')], skip_errors=True)
210
+
211
+ # # Save the filter
212
+ # self.filter = filter
213
+
214
+ # # Add to the engine for updates
215
+ # self.engine.fbos.append(self)
216
+
217
+ # def render(self) -> None:
218
+ # self.shader.program['screenTexture'] = 0
219
+ # self.texture.use(location=0)
220
+ # self.vao.render()
221
+
222
+ # def use(self) -> None:
223
+ # """
224
+ # Select this framebuffer for use
225
+ # """
226
+
227
+ # self.fbo.use()
228
+
229
+ # def clear(self) -> None:
230
+ # """
231
+ # Clear all data currently in the textures (set to black)
232
+ # """
233
+
234
+ # self.fbo.clear()
235
+
236
+ # def save(self, destination: str=None) -> None:
237
+ # """
238
+ # Saves the frame as an image to the given file destination
239
+ # """
240
+
241
+ # path = destination if destination else 'screenshot'
242
+
243
+ # data = self.fbo.read(components=3, alignment=1)
244
+ # img = Image.frombytes('RGB', self.size, data).transpose(Image.FLIP_TOP_BOTTOM)
245
+ # img.save(f'{path}.png')
246
+
247
+ # def resize(self, size: tuple[int]=None) -> None:
248
+ # """
249
+ # Resize the buffer to the given size. None for window size
250
+ # """
251
+
252
+ # # Release old memory
253
+ # self.__del__()
254
+
255
+ # # Set/get size attribute
256
+ # if size:
257
+ # self.size = size
258
+ # else:
259
+ # self.size = self._size if self._size else self.engine.win_size
260
+ # self.size = (int(self.size[0] * self.resolution_scale), int(self.size[1] * self.resolution_scale))
261
+
262
+ # # Create the fbo
263
+ # self.texture = self.ctx.texture(self.size, components=self.components)
264
+ # self.depth = self.ctx.depth_texture(self.size)
265
+ # self.fbo = self.ctx.framebuffer([self.texture], self.depth)
266
+
267
+ # self.filter = self._filter
268
+
269
+ # @property
270
+ # def data(self):
271
+ # return self.fbo.read(components=3, alignment=1)
272
+
273
+ # @property
274
+ # def filter(self):
275
+ # return self.texture.filter
119
276
 
120
- @filter.setter
121
- def filter(self, value):
122
- self._filter = value
123
- self.texture.filter = value
277
+ # @filter.setter
278
+ # def filter(self, value):
279
+ # self._filter = value
280
+ # self.texture.filter = value
124
281
 
125
- def __repr__(self) -> str:
126
- return f'<bsk.Framebuffer | size: {self.size}>'
282
+ # def __repr__(self) -> str:
283
+ # return f'<bsk.Framebuffer | size: {self.size}>'
127
284
 
128
- def __del__(self) -> None:
129
- # Release any existing memory in case of a resize
130
- if self.texture: self.texture.release()
131
- if self.depth: self.depth.release()
132
- if self.fbo: self.fbo.release()
285
+ # def __del__(self) -> None:
286
+ # # Release any existing memory in case of a resize
287
+ # if self.texture: self.texture.release()
288
+ # if self.depth: self.depth.release()
289
+ # if self.fbo: self.fbo.release()
basilisk/render/shader.py CHANGED
@@ -80,10 +80,19 @@ class Shader:
80
80
  if tokens[0] == 'layout' and len(tokens) > 2 and 'in' in line:
81
81
  self.attributes.append(tokens[-1][:-1])
82
82
 
83
- if tokens[-1][:-1] not in attribute_mappings: continue
84
- indices = attribute_mappings[tokens[-1][:-1]]
83
+ # Get the number of flots the attribute takes
84
+ if any(list(map(lambda x: x in tokens, ['float', 'int']))): n = 1
85
+ elif any(list(map(lambda x: x in tokens, ['vec2']))): n = 2
86
+ elif any(list(map(lambda x: x in tokens, ['vec3']))): n = 3
87
+ elif any(list(map(lambda x: x in tokens, ['vec4']))): n = 4
88
+ else: n = 1
89
+ self.fmt += f'{n}f '
90
+
91
+ if tokens[-1][:-1] in attribute_mappings:
92
+ indices = attribute_mappings[tokens[-1][:-1]]
93
+ else:
94
+ indices = [0 for i in range(n)]
85
95
  self.attribute_indices.extend(indices)
86
- self.fmt += f'{len(indices)}f '
87
96
 
88
97
  # Create a program with shaders
89
98
  self.program = self.ctx.program(vertex_shader=self.vertex_shader, fragment_shader=self.fragment_shader)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: basilisk-engine
3
- Version: 0.1.23
3
+ Version: 0.1.25
4
4
  Summary: Python 3D Framework
5
5
  Home-page: https://basilisk-website.vercel.app/
6
6
  Author: Name
@@ -1,6 +1,6 @@
1
- basilisk/__init__.py,sha256=ayBAMFHfcEYSmXpAYNCfcSPKrsq-phXY8AAESlZiLfI,587
1
+ basilisk/__init__.py,sha256=JclirSjufIEfEPaQhOhf5NzWoUkO60Ay4dacNeUSGRw,600
2
2
  basilisk/config.py,sha256=FC0tTQy8jcSZSlriro1SFN2sLw-KLfYQM63Jq6YPHjk,109
3
- basilisk/engine.py,sha256=JJLNombtFEGg68gefpBImWjIOPVo9fgipwsaCpJ9YJc,5608
3
+ basilisk/engine.py,sha256=rrMrQutN_mJEJyzG_w86TUTEYbE8cu9kncMjXMZjiLo,5820
4
4
  basilisk/scene.py,sha256=FVKm6MDmGYxf5OElbDlMMqagsGTnLDbj5UHrdcGtuW4,11888
5
5
  basilisk/audio/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  basilisk/audio/sound.py,sha256=h2dQ3IKb_SRKNZqNuk-fdNg_Xfz0P7sqEXA33qiBXG4,692
@@ -41,26 +41,23 @@ basilisk/generic/quat.py,sha256=gEqvQvNwx5K7e0zqY0TFTAFtNFSkOatleoP9HQQ-xyk,5102
41
41
  basilisk/generic/quat_methods.py,sha256=SO18ush7pfeGUmncPy4i5nsab1e_zkQkY6zT1bAsSDY,234
42
42
  basilisk/generic/raycast_result.py,sha256=waVmS9fYhLoz_G_DU2Mj7896rF0Xy_59JVGALq-kD7g,783
43
43
  basilisk/generic/vec3.py,sha256=AtPSz2S1ZqAm-sZUz4phB09hgFxMIsJnQdU1wmxiOBw,5137
44
- basilisk/input/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
- basilisk/input/mouse.py,sha256=waXJLIyka4IVe3W2WH5SNNxiOQRouYo3NxafP3fg0qg,1937
46
- basilisk/input/path.py,sha256=GpFYe3Uu6VZAuKh9Q2nQM1H8immiCp_snznLG9FKcvU,441
47
- basilisk/input_output/IO_handler.py,sha256=f20Z3Uf48WSTN7A_DaSXGfil1AuBR-recVFCQNNHwB8,2878
44
+ basilisk/input_output/IO_handler.py,sha256=DDQEjmIHzWo99rk1riT_QJKGQ5F8-lOilmchRXeQuYI,2822
48
45
  basilisk/input_output/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
46
  basilisk/input_output/clock.py,sha256=GHTagpPyPlLjWyonaHV8M-nPCcdHcHL4JobbuUOxYf0,1462
50
47
  basilisk/input_output/keys.py,sha256=rMTqYnp3yST6YKSGeP7WFzIlJAwDMhCoBqeWxoOocJw,1368
51
- basilisk/input_output/mouse.py,sha256=waXJLIyka4IVe3W2WH5SNNxiOQRouYo3NxafP3fg0qg,1937
48
+ basilisk/input_output/mouse.py,sha256=gE--Uhk8bhuQzEkC-LdVsTUexx9TrYo6psGnsCjFNrI,2899
52
49
  basilisk/input_output/path.py,sha256=GpFYe3Uu6VZAuKh9Q2nQM1H8immiCp_snznLG9FKcvU,441
53
50
  basilisk/mesh/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
51
  basilisk/mesh/cube.py,sha256=PN6JvW3T8LzPYRnaGo6wsisRK0QI-ZbvMYDT9xs7iN8,1044
55
- basilisk/mesh/mesh.py,sha256=h646NvI8GTnIJ908znoezhq46t4i1lAfJ-jHtNlz4bo,9552
56
- basilisk/mesh/mesh_from_data.py,sha256=NEYCWgJVmF5d0i-_8g94ezWF6q8skLDZiK6Y51vFC7Q,4240
52
+ basilisk/mesh/mesh.py,sha256=eEBCOSl8fn_VAHowojlkwzckZ7qAyDdneYSJHa2Lk48,9757
53
+ basilisk/mesh/mesh_from_data.py,sha256=puRa8ycBjX2LbQB-ZOjJiXuNHh16laWgSqbgjHdlhcQ,4988
57
54
  basilisk/mesh/model.py,sha256=qm1lo23nBjkR-JxXvHzIO3DLa2bNWsMRX4Ilm_5uemY,11722
58
55
  basilisk/mesh/narrow_aabb.py,sha256=oMB_djlWOxpLAsuxeA8_KQafSOcRkDMCu5okvPYuLMQ,3779
59
56
  basilisk/mesh/narrow_bvh.py,sha256=29VLfEKa6BE6UDY1HJWlcM5TMR7ayg4loZ6S61PpLJM,4260
60
57
  basilisk/mesh/narrow_primative.py,sha256=Dlw0jnFewPwAvT0Ap9IxAh05tgjZAdjAyuiRy1DXOm4,930
61
58
  basilisk/nodes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
62
59
  basilisk/nodes/helper.py,sha256=GZ2-TY_4PDEfxBGp7ddktYoDDMOogPMbDeRPqsrPu1A,2069
63
- basilisk/nodes/node.py,sha256=yldg6kemDLx8ei7aiiLVCK-5VMSmWIsFWxN1lNNmpDo,31951
60
+ basilisk/nodes/node.py,sha256=6RoDC0YxBJiOolfRdOad3VpnTxTIelv_wTZweu8kJMI,32168
64
61
  basilisk/nodes/node_handler.py,sha256=IFEcEefVzlMbYR0O6OtM2qPcoZFrLYugiwAqEQMoTqo,4106
65
62
  basilisk/particles/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
66
63
  basilisk/particles/particle_handler.py,sha256=PtWn8-qwfkD0r8CXcATvDEFstrKG86KVBH0j1ybEv58,2928
@@ -70,12 +67,12 @@ basilisk/physics/impulse.py,sha256=a_Ks-4LrjaN3siMmVwGp92_iyr9a-G1lb5Q-J7g6ipA,5
70
67
  basilisk/physics/physics_body.py,sha256=-iqo3YyCfMzpBVNA2I34JbfN7Z6phj5nnGHN-S8lBgs,1465
71
68
  basilisk/physics/physics_engine.py,sha256=C30oGb8rODdXORJJWjOWBPwlScnTHrp6CTPHSNcbgp0,1700
72
69
  basilisk/render/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
73
- basilisk/render/batch.py,sha256=dmE7aGVxJBSBFL1_mQgJDDLQm-EnWWzxRqxLuUPoh2c,3670
74
- basilisk/render/camera.py,sha256=dRhvDy-TaDxFL8f_VyVb_voOFEenrNOh7MX_X7uFi2I,9985
75
- basilisk/render/chunk.py,sha256=YvvlKFLD3RUUu2wcROeOQsgnKWpDRpaO4LGKKnmoJU8,2718
70
+ basilisk/render/batch.py,sha256=1ULXwzcs7v9ze1IDZDJXcaydRjwdgHH9TkyXxcadNiM,3396
71
+ basilisk/render/camera.py,sha256=9yxgie-RYmgEzSLySI3SeUKTRX77nmt5II2nS2Gp9Qk,9411
72
+ basilisk/render/chunk.py,sha256=4_jZ-nw0q5XMgyfxSgAMR7KzzEo0nKPwvyDLB4oqUsI,2704
76
73
  basilisk/render/chunk_handler.py,sha256=PJNGWv3DURm8rYKb3WlGVx6CJ5arbaIiMwA1UN-G480,6332
77
- basilisk/render/frame.py,sha256=PTIoDPn2w42sRYH9FlNvr1VYf5nSqBLskC2vw64whmU,3139
78
- basilisk/render/framebuffer.py,sha256=agG2nbM3mXYNYYCAp7uSo3AutJb4o6njly1za-N6210,4319
74
+ basilisk/render/frame.py,sha256=v7EuQ7FRXzxyeS7QFlqyz-jzveAkQkglxhHVjv6zAFY,2917
75
+ basilisk/render/framebuffer.py,sha256=JXBKmnujDraAl5swG2NgAyegUKHsIumQG3-RfpgVwiE,9884
79
76
  basilisk/render/image.py,sha256=HotYV1bUCJ71bJLfdertz2AKKh0q5k268Ph_tbzP9ss,2873
80
77
  basilisk/render/image_handler.py,sha256=DNb-AiouziLVQu3NkoG1F90YZTHHWyhFYhaWJ9uiUOU,4175
81
78
  basilisk/render/light.py,sha256=SOOh5zAGUCgQdJjWb5MlJgtvdxkEV8AWqQ4P93bJj2g,3783
@@ -83,7 +80,7 @@ basilisk/render/light_handler.py,sha256=gvg4OhDMy8dZg5XNcOZB4_1G2uE1gBFRxlBeoG3l
83
80
  basilisk/render/material.py,sha256=RdZDy-pqxlpBW8n8JOsxETmd5XjXu6cxrCd5_6_DOww,9436
84
81
  basilisk/render/material_handler.py,sha256=CG_a_cV4V_1iYdhCjn7etFxIbAXyRgVicR135rim0oA,3983
85
82
  basilisk/render/post_process.py,sha256=iDQ05SUXUUmVcCq4m6c16m0yfWxQjM3NB9vciorJnV0,4959
86
- basilisk/render/shader.py,sha256=cx2CiIECK4Y3G1Rv6HYX782yMqiO4FDNvj2PhI6CEYc,3804
83
+ basilisk/render/shader.py,sha256=PQ0XwE4ZtekQBdVUKwLsXbbTlsI_yuUVsJM1Iy4MPsc,4259
87
84
  basilisk/render/shader_handler.py,sha256=w1bGwVXm61_dDVlX9WgU8CKOMdqTjcooNlMsdN9lVnc,2738
88
85
  basilisk/render/sky.py,sha256=orTtgkU35AHZTUGk9IevSXwVs6tktoDP52yEUM5Rg0E,4768
89
86
  basilisk/shaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -103,7 +100,7 @@ basilisk/shaders/particle.frag,sha256=JXhPDvgd7JDw0-PCZtCOjHTTw2DMeeSaBvTr5fHuIy
103
100
  basilisk/shaders/particle.vert,sha256=bJv3hsWjWYb-g0mgdCV9eH-TVRwpCzhA3wsgSUI3WEM,2943
104
101
  basilisk/shaders/sky.frag,sha256=KG8ablNdaJ5E2Gf1ZpfP3ih252fY8ZNjign_fwjN6V4,169
105
102
  basilisk/shaders/sky.vert,sha256=oAnrknEgsd9MawE_zx8P0u9nUSFEBYBg5ykBmWpqZ_g,332
106
- basilisk_engine-0.1.23.dist-info/METADATA,sha256=5D17pbGYywQa3FGIekT2OIM7BI_-TKw48fhXDyh-cbw,1261
107
- basilisk_engine-0.1.23.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
108
- basilisk_engine-0.1.23.dist-info/top_level.txt,sha256=enlSYSf7CUyAly1jmUCNNGInTbaFUjGk4SKwyckZQkw,9
109
- basilisk_engine-0.1.23.dist-info/RECORD,,
103
+ basilisk_engine-0.1.25.dist-info/METADATA,sha256=wi8e1bEHIgaea5pF5GyK8VsQvvUttrC645vv54H7mt4,1261
104
+ basilisk_engine-0.1.25.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
105
+ basilisk_engine-0.1.25.dist-info/top_level.txt,sha256=enlSYSf7CUyAly1jmUCNNGInTbaFUjGk4SKwyckZQkw,9
106
+ basilisk_engine-0.1.25.dist-info/RECORD,,
File without changes
basilisk/input/mouse.py DELETED
@@ -1,62 +0,0 @@
1
- import pygame as pg
2
-
3
-
4
- class Mouse():
5
- def __init__(self, grab=True):
6
- self.x, self.y = pg.mouse.get_pos()
7
- self.buttons = pg.mouse.get_pressed()
8
- self.previous_buttons = pg.mouse.get_pressed()
9
- self.grab = grab
10
-
11
- def update(self, events):
12
- """
13
- Updates all mouse state variables.
14
- Checks for mouse-related events.
15
- """
16
-
17
- self.x, self.y = pg.mouse.get_pos()
18
- self.previous_buttons = self.buttons
19
- self.buttons = pg.mouse.get_pressed()
20
-
21
- for event in events:
22
- if event.type == pg.KEYUP:
23
- if event.key == pg.K_ESCAPE and self.grab:
24
- # Unlock mouse
25
- pg.event.set_grab(False)
26
- pg.mouse.set_visible(True)
27
- if event.type == pg.MOUSEBUTTONUP and self.grab:
28
- # Lock mouse
29
- pg.event.set_grab(True)
30
- pg.mouse.set_visible(False)
31
-
32
- def set_pos(self, x, y):
33
- """Set the mouse position"""
34
- pg.mouse.set_pos(x, y)
35
-
36
- @property
37
- def click(self): return self.buttons[0] and not self.previous_buttons[0]
38
- @property
39
- def left_click(self): return self.buttons[0] and not self.previous_buttons[0]
40
- @property
41
- def middle_click(self): return self.buttons[1] and not self.previous_buttons[1]
42
- @property
43
- def right_click(self): return self.buttons[2] and not self.previous_buttons[2]
44
- @property
45
- def left_down(self): return self.buttons[0]
46
- @property
47
- def middle_down(self): return self.buttons[1]
48
- @property
49
- def right_down(self): return self.buttons[2]
50
-
51
- @property
52
- def grab(self): return self._grab
53
-
54
- @grab.setter
55
- def grab(self, value):
56
- self._grab = value
57
- if self._grab:
58
- pg.event.set_grab(True)
59
- pg.mouse.set_visible(False)
60
- else:
61
- pg.event.set_grab(False)
62
- pg.mouse.set_visible(True)
basilisk/input/path.py DELETED
@@ -1,14 +0,0 @@
1
- import os
2
- import sys
3
-
4
-
5
- # Credit for function: https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile
6
- def get_root():
7
- """ Get absolute path to resource, works for dev and for PyInstaller """
8
- try:
9
- # PyInstaller creates a temp folder and stores path in _MEIPASS
10
- base_path = sys._MEIPASS
11
- except Exception:
12
- base_path = os.path.abspath(".")
13
-
14
- return base_path + '/basilisk'