basilisk-engine 0.1.29__py3-none-any.whl → 0.1.31__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/engine.py CHANGED
@@ -163,8 +163,4 @@ class Engine():
163
163
 
164
164
 
165
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()
166
+ def shader(self): return self._shader
File without changes
@@ -0,0 +1,62 @@
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 ADDED
@@ -0,0 +1,14 @@
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'
basilisk/nodes/node.py CHANGED
@@ -19,11 +19,11 @@ class Node():
19
19
  """The scale of the node in meters in each direction"""
20
20
  rotation: Quat
21
21
  """The rotation of the node"""
22
- position_relative: bool
22
+ relative_position: bool
23
23
  """The position of this node relative to the parent node"""
24
- scale_relative: bool
24
+ relative_scale: bool
25
25
  """The scale of this node relative to the parent node"""
26
- rotation_relative: bool
26
+ relative_rotation: bool
27
27
  """The rotation of this node relative to the parent node"""
28
28
  forward: glm.vec3
29
29
  """The forward facing vector of the node"""
@@ -239,9 +239,9 @@ class Node():
239
239
  if self.relative_scale: transform = glm.scale(transform, self.parent.scale.data)
240
240
 
241
241
  # set this node's transforms based on the parent
242
- self.position = transform * self.relative_position
243
- self.scale = self.relative_scale * self.parent.scale.data
244
- self.rotation = self.relative_rotation * self.parent.rotation.data
242
+ if self.relative_position: self.position = transform * self.relative_position
243
+ if self.relative_scale: self.scale = self.relative_scale * self.parent.scale.data
244
+ if self.relative_rotation: self.rotation = self.relative_rotation * self.parent.rotation.data
245
245
 
246
246
  for child in self.children: child.sync_data()
247
247
 
@@ -287,12 +287,22 @@ class Node():
287
287
  """
288
288
  Adopts a node as a child. Relative transforms can be changed, if left bank they will not be chnaged from the current child nodes settings.
289
289
  """
290
- if child in self.children: return
290
+ if child in self.children or child is self: return
291
+ assert isinstance(child, Node), 'Nodes can only accept other Nodes as children.'
292
+
293
+ relative = glm.inverse(self.model_matrix) * child.model_matrix
294
+ position = glm.vec3(relative[3])
295
+ scale = glm.vec3([glm.length(relative[i]) for i in range(3)])
296
+ rotation = glm.quat_cast(glm.mat3x3(*[glm.vec3(relative[i]) / scale[i] for i in range(3)])) # TODO ensure that these are the correct calculations
291
297
 
292
298
  # compute relative transformations
293
- if relative_position or (relative_position is None and child.relative_position): child.relative_position = child.position.data - self.position.data
294
- if relative_scale or (relative_scale is None and child.relative_scale): child.relative_scale = child.scale.data / self.scale.data
295
- if relative_rotation or (relative_rotation is None and child.relative_rotation): child.relative_rotation = child.rotation.data * glm.inverse(self.rotation.data)
299
+ if relative_position or (relative_position is None and child.relative_position): child.relative_position = position
300
+ if relative_scale or (relative_scale is None and child.relative_scale): child.relative_scale = scale
301
+ if relative_rotation or (relative_rotation is None and child.relative_rotation): child.relative_rotation = rotation
302
+
303
+ print(child.relative_position)
304
+ print(child.relative_scale)
305
+ print(child.relative_rotation)
296
306
 
297
307
  # add as a child to by synchronized and controlled
298
308
  if self.node_handler: self.node_handler.add(child)
basilisk/render/chunk.py CHANGED
@@ -87,7 +87,7 @@ class Chunk():
87
87
  shader = self.shader
88
88
 
89
89
  if shader: return shader
90
- return self.chunk_handler.engine.shader
90
+ return self.chunk_handler.scene.shader
91
91
 
92
92
  def swap_shader(self, shader):
93
93
  """
@@ -166,9 +166,18 @@ class Framebuffer:
166
166
  def show(self, value: int) -> None:
167
167
  value = validate_int("Framebuffer", "show", value)
168
168
  if value == self._show: return
169
+
170
+ # Verify the range
171
+ if value < 0 or value > len(self.color_attachments): raise ValueError(f'Framebuffer.show: invalid color attachement to show, {value} is out of range')
172
+ elif value == len(self.color_attachments): src = self.depth
173
+ else: src = self.color_attachments[value]
174
+
175
+ # Update value
169
176
  self._show = value
177
+
178
+ # Bind the correct texture
170
179
  self.shader.program['screenTexture'] = value+1
171
- self.color_attachments[value].use(location=value+1)
180
+ src.use(location=value+1)
172
181
 
173
182
  def __repr__(self) -> str:
174
183
  return f'<bsk.Framebuffer | size: {self.size}>'
basilisk/render/shader.py CHANGED
@@ -98,13 +98,13 @@ class Shader:
98
98
  # Create a program with shaders
99
99
  self.program = self.ctx.program(vertex_shader=self.vertex_shader, fragment_shader=self.fragment_shader)
100
100
 
101
- def set_main(self):
101
+ def set_main(self, scene):
102
102
  """
103
103
  Selects a shader for use
104
104
  """
105
105
 
106
106
  self.engine.shader_handler.add(self)
107
- self.engine.scene.node_handler.chunk_handler.swap_default(self)
107
+ if scene.node_handler: scene.node_handler.chunk_handler.swap_default(self)
108
108
 
109
109
  def write(self, name: str, value) -> None:
110
110
  """
@@ -28,7 +28,7 @@ class ShaderHandler:
28
28
  self.shaders = set()
29
29
 
30
30
  # Load a default shader
31
- self.default_shader = Shader(self, self.engine.root + '/shaders/batch.vert', self.engine.root + '/shaders/batch.frag')
31
+ self.default_shader = Shader(self.engine, self.engine.root + '/shaders/batch.vert', self.engine.root + '/shaders/batch.frag')
32
32
  self.default_shader.hash = self.default_shader.hash + hash('engine_shader')
33
33
  self.add(self.default_shader)
34
34
  setattr(self.engine, "_shader", self.default_shader)
basilisk/scene.py CHANGED
@@ -4,8 +4,7 @@ import pygame as pg
4
4
 
5
5
  from .mesh.mesh import Mesh
6
6
  from .render.material import Material
7
- from .render.shader_handler import ShaderHandler
8
- from .render.material_handler import MaterialHandler
7
+ from .render.shader import Shader
9
8
  from .render.light_handler import LightHandler
10
9
  from .render.camera import Camera, FreeCamera
11
10
  from .nodes.node_handler import NodeHandler
@@ -34,13 +33,14 @@ class Scene():
34
33
  node_handler: NodeHandler=None
35
34
  """"""
36
35
 
37
- def __init__(self, engine: ...) -> None:
36
+ def __init__(self, engine: ..., shader: Shader=None) -> None:
38
37
  """
39
38
  Basilisk scene object. Contains all nodes for the scene
40
39
  """
41
40
 
42
41
  self.engine = engine
43
42
  self.ctx = engine.ctx
43
+ self.shader = shader if shader else engine.shader
44
44
  self.camera = FreeCamera()
45
45
  self.light_handler = LightHandler(self)
46
46
  self.physics_engine = PhysicsEngine()
@@ -69,7 +69,11 @@ class Scene():
69
69
  self.collider_handler.resolve_collisions()
70
70
 
71
71
  # Render by default to the engine frame
72
- if render: self.render()
72
+ if not render: return
73
+
74
+ # Check if the user is giving a destination
75
+ if not isinstance(render, bool): self.render(renders)
76
+ else: self.render()
73
77
 
74
78
  def render(self, render_target: Framebuffer|Frame=None) -> None:
75
79
  """
@@ -92,7 +96,6 @@ class Scene():
92
96
  if self.engine.headless or not show: return
93
97
 
94
98
 
95
-
96
99
  def add(self, *objects: Node | None) -> None | Node | list:
97
100
  """
98
101
  Adds the given object(s) to the scene. Can pass in any scene objects:
@@ -263,6 +266,8 @@ class Scene():
263
266
  def sky(self): return self._sky
264
267
  @property
265
268
  def nodes(self): return self.node_handler.nodes
269
+ @property
270
+ def shader(self): return self._shader
266
271
 
267
272
  @camera.setter
268
273
  def camera(self, value: Camera):
@@ -277,4 +282,9 @@ class Scene():
277
282
  if not isinstance(value, Sky) and not isinstance(value, type(None)):
278
283
  raise TypeError(f'Scene: Invalid sky type: {type(value)}. Expected type bsk.Sky or None')
279
284
  self._sky = value
280
- if value: self._sky.write()
285
+ if value: self._sky.write()
286
+
287
+ @shader.setter
288
+ def shader(self, value):
289
+ self._shader = value
290
+ value.set_main(self)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: basilisk-engine
3
- Version: 0.1.29
3
+ Version: 0.1.31
4
4
  Summary: Python 3D Framework
5
5
  Home-page: https://basilisk-website.vercel.app/
6
6
  Author: Name
@@ -1,7 +1,7 @@
1
1
  basilisk/__init__.py,sha256=JclirSjufIEfEPaQhOhf5NzWoUkO60Ay4dacNeUSGRw,600
2
2
  basilisk/config.py,sha256=FC0tTQy8jcSZSlriro1SFN2sLw-KLfYQM63Jq6YPHjk,109
3
- basilisk/engine.py,sha256=rrMrQutN_mJEJyzG_w86TUTEYbE8cu9kncMjXMZjiLo,5820
4
- basilisk/scene.py,sha256=FVKm6MDmGYxf5OElbDlMMqagsGTnLDbj5UHrdcGtuW4,11888
3
+ basilisk/engine.py,sha256=1YERzyCkVJTgntZQPDbJ1_qy6CZEaov6Y9rojHpm_O0,5718
4
+ basilisk/scene.py,sha256=51nrk6pnorHQgyiY2veW90uXsPfdHQyDKbJNtXx44w4,12197
5
5
  basilisk/audio/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  basilisk/audio/sound.py,sha256=h2dQ3IKb_SRKNZqNuk-fdNg_Xfz0P7sqEXA33qiBXG4,692
7
7
  basilisk/bsk_assets/Roboto-Regular.ttf,sha256=kqYnZjMRQMpbyLulIChCLSdgYa1XF8GsUIoRi2Gcauw,168260
@@ -41,6 +41,9 @@ 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
44
47
  basilisk/input_output/IO_handler.py,sha256=DDQEjmIHzWo99rk1riT_QJKGQ5F8-lOilmchRXeQuYI,2822
45
48
  basilisk/input_output/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
49
  basilisk/input_output/clock.py,sha256=GHTagpPyPlLjWyonaHV8M-nPCcdHcHL4JobbuUOxYf0,1462
@@ -57,7 +60,7 @@ basilisk/mesh/narrow_bvh.py,sha256=29VLfEKa6BE6UDY1HJWlcM5TMR7ayg4loZ6S61PpLJM,4
57
60
  basilisk/mesh/narrow_primative.py,sha256=Dlw0jnFewPwAvT0Ap9IxAh05tgjZAdjAyuiRy1DXOm4,930
58
61
  basilisk/nodes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
59
62
  basilisk/nodes/helper.py,sha256=GZ2-TY_4PDEfxBGp7ddktYoDDMOogPMbDeRPqsrPu1A,2069
60
- basilisk/nodes/node.py,sha256=6RoDC0YxBJiOolfRdOad3VpnTxTIelv_wTZweu8kJMI,32168
63
+ basilisk/nodes/node.py,sha256=Hs-x7jpSpl1lKmGFs4UJnh72E2S1cDOyuTctSytIRDU,32717
61
64
  basilisk/nodes/node_handler.py,sha256=IFEcEefVzlMbYR0O6OtM2qPcoZFrLYugiwAqEQMoTqo,4106
62
65
  basilisk/particles/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
63
66
  basilisk/particles/particle_handler.py,sha256=PtWn8-qwfkD0r8CXcATvDEFstrKG86KVBH0j1ybEv58,2928
@@ -69,10 +72,10 @@ basilisk/physics/physics_engine.py,sha256=C30oGb8rODdXORJJWjOWBPwlScnTHrp6CTPHSN
69
72
  basilisk/render/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
70
73
  basilisk/render/batch.py,sha256=1ULXwzcs7v9ze1IDZDJXcaydRjwdgHH9TkyXxcadNiM,3396
71
74
  basilisk/render/camera.py,sha256=pOM5sVSHl_joHwsBLd8Y7CzLUL-16XBBQfgsnM8jc6Q,9649
72
- basilisk/render/chunk.py,sha256=Yyyh6jEEG_JQIk02hEDs1L-UbmKDZQcAHtGV4pxSJ7U,2715
75
+ basilisk/render/chunk.py,sha256=yE7P48cqpF-Ucdqip41SsfBuotHMBj1L6I49HiWuUjc,2714
73
76
  basilisk/render/chunk_handler.py,sha256=PJNGWv3DURm8rYKb3WlGVx6CJ5arbaIiMwA1UN-G480,6332
74
77
  basilisk/render/frame.py,sha256=v7EuQ7FRXzxyeS7QFlqyz-jzveAkQkglxhHVjv6zAFY,2917
75
- basilisk/render/framebuffer.py,sha256=28_oqR_eLNytyTS_2kNIHIY30T5ICoOK80jRnTZdtQ8,6222
78
+ basilisk/render/framebuffer.py,sha256=i1lRzAActlu_qIPDDUmTbFrTd_EzM1YMLT5vMbARz78,6561
76
79
  basilisk/render/image.py,sha256=d-5RGr-TlsGqvI-GQ8_pV-FNdmTzD0mlk2K3K4XNuwQ,3984
77
80
  basilisk/render/image_handler.py,sha256=DNb-AiouziLVQu3NkoG1F90YZTHHWyhFYhaWJ9uiUOU,4175
78
81
  basilisk/render/light.py,sha256=SOOh5zAGUCgQdJjWb5MlJgtvdxkEV8AWqQ4P93bJj2g,3783
@@ -80,8 +83,8 @@ basilisk/render/light_handler.py,sha256=gvg4OhDMy8dZg5XNcOZB4_1G2uE1gBFRxlBeoG3l
80
83
  basilisk/render/material.py,sha256=MYcNbhNyVJ3DeAB8cq-aMYRPJfWxBA1c1xpODXJqbsY,9510
81
84
  basilisk/render/material_handler.py,sha256=b5K-Y3uzCqb1G9WMyvbonuh4GAOQnu5IkeNCq09PKBs,4065
82
85
  basilisk/render/post_process.py,sha256=iDQ05SUXUUmVcCq4m6c16m0yfWxQjM3NB9vciorJnV0,4959
83
- basilisk/render/shader.py,sha256=q5eSvWTEP55oNoM7kepEizSOQyjDkDLV2RrFiySaKOI,4799
84
- basilisk/render/shader_handler.py,sha256=w1bGwVXm61_dDVlX9WgU8CKOMdqTjcooNlMsdN9lVnc,2738
86
+ basilisk/render/shader.py,sha256=lQv2crDrD9hpqF6pbynBXeWLX1fNKat59udOx95mZsM,4817
87
+ basilisk/render/shader_handler.py,sha256=WkP5krze4EDV4smc1Rnx4rw5KojZvw_nSMuRDvhuI2E,2745
85
88
  basilisk/render/sky.py,sha256=orTtgkU35AHZTUGk9IevSXwVs6tktoDP52yEUM5Rg0E,4768
86
89
  basilisk/shaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
87
90
  basilisk/shaders/batch.frag,sha256=L1NuzZxq7xcjoKgW70p_tUG8g_GuQndWtmxbKMUwe3s,9063
@@ -100,7 +103,7 @@ basilisk/shaders/particle.frag,sha256=JXhPDvgd7JDw0-PCZtCOjHTTw2DMeeSaBvTr5fHuIy
100
103
  basilisk/shaders/particle.vert,sha256=bJv3hsWjWYb-g0mgdCV9eH-TVRwpCzhA3wsgSUI3WEM,2943
101
104
  basilisk/shaders/sky.frag,sha256=KG8ablNdaJ5E2Gf1ZpfP3ih252fY8ZNjign_fwjN6V4,169
102
105
  basilisk/shaders/sky.vert,sha256=oAnrknEgsd9MawE_zx8P0u9nUSFEBYBg5ykBmWpqZ_g,332
103
- basilisk_engine-0.1.29.dist-info/METADATA,sha256=DM9gt-GfjI8qpzUT8wYD_OFbyd5kcYaPIq9e7UuwvQ4,1261
104
- basilisk_engine-0.1.29.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
105
- basilisk_engine-0.1.29.dist-info/top_level.txt,sha256=enlSYSf7CUyAly1jmUCNNGInTbaFUjGk4SKwyckZQkw,9
106
- basilisk_engine-0.1.29.dist-info/RECORD,,
106
+ basilisk_engine-0.1.31.dist-info/METADATA,sha256=3wnyvwda50LHbVl5j7qEnHI41KdwgRM12U96Iz01uGM,1261
107
+ basilisk_engine-0.1.31.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
108
+ basilisk_engine-0.1.31.dist-info/top_level.txt,sha256=enlSYSf7CUyAly1jmUCNNGInTbaFUjGk4SKwyckZQkw,9
109
+ basilisk_engine-0.1.31.dist-info/RECORD,,